123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using Microsoft.Office.Interop.Word;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using word = Microsoft.Office.Interop.Word;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- public double RateNorm = 0.7;
- public double RateNorm2 = 0.3;
- public double ExcessTariff = 1.6;
- public int MinutesTariff1 = 200;
- public int MinutesTariff2=100;
- public Form1()
- {
- InitializeComponent();
- }
- private void Calculate_Click(object sender, EventArgs e)
- {
-
- try
- {
- string Minute1 = Minutes.Text;
- if (!ANGLTEXT(Minute1))
- {
- throw new Exception("Некорректное значение. Введите целое число.");
- }
- int Minute = Convert.ToInt32(Minutes.Text);
- if (Minute > 0 && Minute <= 4000)
- {
- if(radioButton1.Checked==true)
- {
- if (Minute > MinutesTariff1)
- {
- double MinuteFact = MinutesTariff1 * RateNorm + ((Minute- MinutesTariff1) * ExcessTariff);
- int MinuteUp = Minute - MinutesTariff1;
- Summ.Text = "Минут свверх установленной нормы: "+ MinuteUp;
- SummIt.Text = "К оплате: " + MinuteFact;
- Summ.Visible = true;
- }
- else
- {
- double MinuteFact = Minute * RateNorm;
- SummIt.Text = "К оплате: " + MinuteFact;
- }
- }
- if(radioButton2.Checked == true)
- {
- if (Minute > MinutesTariff2)
- {
- double MinuteFact = MinutesTariff2 * RateNorm2 + ((Minute - MinutesTariff2) * ExcessTariff);
- int MinuteUp = Minute - MinutesTariff2;
- Summ.Text = "Минут свверх установленной нормы: " + MinuteUp;
- SummIt.Text = "К оплате: " + MinuteFact;
- Summ.Visible = true;
- }
- else
- {
- double MinuteFact = Minute * RateNorm2;
- SummIt.Text = "К оплате: " + MinuteFact;
- }
- }
- else if(radioButton1.Checked == false&& radioButton2.Checked == true)
- {
- MessageBox.Show("Выберите тариф!");
- }
-
- }
- else
- {
- MessageBox.Show("Значение должно быть между 0 и 4000.");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- Close();
- }
- }
- public bool ANGLTEXT(string input)
- {
- return !string.IsNullOrEmpty(input)&& Regex.IsMatch(input,@"^\d+$")&&!Regex.IsMatch(input, @"[а-яА-Я]");
- }
-
-
- private void Minutes_KeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- DateTime Date1 = DateTime.Now;
- string Tariff = "";
- if (radioButton1.Checked == true)
- {
- Tariff = "Тариф 1";
- }
- if (radioButton2.Checked == true)
- {
- Tariff = "Тариф 2";
- }
- string summ = SummIt.Text;
- word.Document document = null;
- word.Application app = new word.Application();
- string putword = Environment.CurrentDirectory.ToString() + @"C:\Users\Евгений\source\repos\WindowsFormsApp1\WindowsFormsApp1\res\Шаблон.docx";
- document = app.Documents.Add(putword);
- document.Activate();
- word.Bookmarks bookm = document.Bookmarks;
- word.Range range;
- string[] data = new string[3] { Convert.ToString(Date1), Tariff, summ };
- int i = 0;
- foreach (word.Bookmark mark in bookm)
- {
- range = mark.Range;
- range.Text = data[i];
- i++;
- }
- document.SaveAs2(Environment.CurrentDirectory.ToString() + @"\Сертификат.docx");
- MessageBox.Show("Сертификат сохранен по пути: " + Environment.CurrentDirectory.ToString());
- document.Close();
- document = null;
- }
- }
- }
|