123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using word = Microsoft.Office.Interop.Word;
- namespace WpfApp2
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- bool CheckVvod(string input)
- {
- return !string.IsNullOrEmpty(input)&&!Regex.IsMatch(input, @"[а-яА-Я]");
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
-
- try
- {
- string q1 = Kol1.Text;
- string q2 = Kol2.Text;
- string SumZa = SumZach.Text;
- int sum;
- int number1, number2;
- bool num1 = int.TryParse(q1, out number1);
- bool num2 = int.TryParse(q2, out number2);
- if (!CheckVvod(q1)&&!CheckVvod(q2)&&!CheckVvod(SumZa))
- {
- MessageBox.Show("Не все поля корректно заполнены!");
- }
- else
- {
- if (num1 && num2)
- {
- if (int.TryParse(SumZa, out sum))
- {
- int summa = number1 * 45 + number2 * 115;
- int sdacha = sum - summa;
- SumZak.Text = summa.ToString();
- if (sdacha < 0)
- {
- MessageBox.Show("Недостаточно средств!");
- }
- else
- {
- CashBack.Text = sdacha.ToString();
- }
- }
- }
- }
-
-
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
-
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- word.Document document = null;
- word.Application app = new word.Application();
- string putword = Environment.CurrentDirectory.ToString() + @"\Квитанция.docx";
- document = app.Documents.Add(putword);
- document.Activate();
- word.Bookmarks bookm = document.Bookmarks;
- word.Range range;
- string dateNow = DateTime.Now.ToString();
- string q1 = Kol1.Text;
- string q2 = Kol2.Text;
- string SumZa = SumZach.Text;
- string number = "1";
- string sumZakaz = SumZak.Text;
- string sdacha = CashBack.Text;
- string[] data = new string[7] { SumZa, dateNow, sumZakaz, number, q2, q1, sdacha };
- 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;
- }
- }
- }
|