예제 #1
0
 private void UpdateDataPerson(List <string> list)
 {
     flag = sqlManager.UpdatePerson(list);
     if (flag != -2)
     {
         ResetEdit();
         DataPerson.NewDataPerson();
         WriteDataPerson();
     }
     else if (flag == -2)
     {
         PagesManager.ShowConnectionError();
     }
 }
예제 #2
0
        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            DataPerson.id = -1;
            MainWindow mw = new MainWindow();

            mw.Show();
            PagesManager.CleanStates();
            DataPerson.Clear();
            if (Item.items != null)
            {
                Item.items.Clear();
            }
            Close();
            System.GC.Collect();
        }
예제 #3
0
 public void WriteDataPerson()
 {
     if (DataPerson.NamePerson == null)
     {
         if (DataPerson.NewDataPerson() == -1)
         {
             PagesManager.ShowConnectionError();
         }
     }
     name.Content       = DataPerson.NamePerson;
     Lastname.Content   = DataPerson.LastName;
     MiddleName.Content = DataPerson.MiddleName;
     SeriaPass.Content  = DataPerson.SeriaPass;
     NumberPass.Content = DataPerson.NumberPass;
     Phone.Content      = DataPerson.PhoneNumber;
 }
예제 #4
0
        private void MakeTicket(string[] param)
        {
            //создание билета
            SqlManager       sqlManager;
            MessageBoxResult res = MessageBox.Show("Вы хотите купить именно этот билет?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (res == MessageBoxResult.Yes)
            {
                Word.Document doc = null;
                try
                {
                    Item item;
                    sqlManager = new SqlManager();
                    if (sqlManager.UpdateActualCountTripsInDB() != -2)
                    {
                        DataTable dt = sqlManager.ReturnTable("SELECT ActualCount " +
                                                              "FROM Tours " +
                                                              "WHERE Name_tour = '" + (SelectedTrips.SelectedItem as Item).NameTour + "'");
                        if (dt != null)
                        {
                            if (Convert.ToInt32(dt.Rows[0].ItemArray[0]) != 0)
                            {
                                //создаем новый документ
                                Word.Application app = new Word.Application();
                                var location         = System.Reflection.Assembly.GetExecutingAssembly().Location;
                                doc = app.Documents.Open(Path.GetDirectoryName(location) + @"\Шаблон.docx");
                                doc.Activate();
                                //открываем шаблон и получаем список закладок
                                Word.Bookmarks       wBookmarks = doc.Bookmarks;
                                Word.Range           wRange; //положение закладки в документе
                                List <Word.Bookmark> bookmarks = new List <Word.Bookmark>();
                                foreach (Word.Bookmark mark in wBookmarks)
                                {
                                    bookmarks.Add(mark);
                                }
                                string[] mass = (DataPerson.right == 3) ? sqlManager.ReturnDataPerson() : param;
                                if (mass != null)
                                {
                                    string[] data = new string[13];
                                    for (int i = 0; i < 6; i++)
                                    {
                                        data[i] = mass[i];
                                    }
                                    item     = Item.items.Find(x => x.NameTour == (SelectedTrips.SelectedItem as Item).NameTour);
                                    data[6]  = item.NameTour;
                                    data[7]  = item.NameCountry;
                                    data[8]  = item.NameCity;
                                    data[9]  = item.DateBegin;
                                    data[10] = item.DateEnd;
                                    data[11] = item.Price.ToString();
                                    data[12] = DateTime.Today.ToShortDateString();
                                    for (int i = 0; i < 13; i++) //заполнение данных на месте закладок
                                    {
                                        wRange      = bookmarks.ElementAt(i).Range;
                                        wRange.Text = data[i];
                                    }
                                    Item.items.Remove(item);
                                    SelectedTrips.Items.Remove(SelectedTrips.SelectedItem);
                                    int flag = sqlManager.ReturnNumber("SELECT Num_Tour FROM Tours WHERE Name_tour = '" + data[6] + "'");
                                    if (flag != -2)
                                    {
                                        int buf = flag;
                                        if (sqlManager.Insert("INSERT INTO Trips(Num_tour, Num_tourist, DateOfBuy) VALUES(" + buf +
                                                              "," + DataPerson.id + ", '" + DateTime.Today.Date + "')") != -2)
                                        {
                                            if ((flag = DataPerson.CountTickets()) != -2)
                                            {
                                                doc.SaveAs(FileName: @"..\Desktop\Ticket" + DataPerson.id + "_" + flag + ".docx");
                                                doc.Close();
                                                doc = null;
                                                MessageBox.Show("Ваш билет готов и находится на рабочем столе", "", MessageBoxButton.OK, MessageBoxImage.Information);
                                                choiseDataGrid.ItemsSource = null;
                                                choiseDataGrid.Visibility  = Visibility.Hidden;
                                                label.Visibility           = Visibility.Hidden;
                                                SelectedTrips.Visibility   = Visibility.Visible;
                                            }
                                            else
                                            {
                                                PagesManager.ShowConnectionError();
                                            }
                                        }
                                        else
                                        {
                                            PagesManager.ShowConnectionError();
                                        }
                                    }
                                    else
                                    {
                                        PagesManager.ShowConnectionError();
                                    }
                                }
                                else
                                {
                                    PagesManager.ShowConnectionError();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Билеты закончились!", "", MessageBoxButton.OK, MessageBoxImage.Warning);
                                item = Item.items.Find(x => x.NameTour == (SelectedTrips.SelectedItem as Item).NameTour);
                                Item.items.Remove(item);
                                SelectedTrips.Items.Remove(SelectedTrips.SelectedItem);
                                choiseDataGrid.ItemsSource = null;
                                choiseDataGrid.Visibility  = Visibility.Hidden;
                                label.Visibility           = Visibility.Hidden;
                                SelectedTrips.Visibility   = Visibility.Visible;
                            }
                            System.GC.Collect();
                        }
                        else
                        {
                            PagesManager.ShowConnectionError();
                        }
                    }
                    else
                    {
                        PagesManager.ShowConnectionError();
                    }
                }
                catch (Exception ex)
                {
                    doc.Close();
                    doc = null;
                    Console.WriteLine("Во время выполнения произошла ошибка! " + ex.Message);
                }
            }
        }