示例#1
0
 private void CityBox_DropDownOpened(object sender, EventArgs e)
 {
     CityBox.SelectedIndex = -1;
     if (CountryBox.Text != "")
     {
         SqlManager sqlManager = new SqlManager();
         int        num        = sqlManager.ReturnNumber("SELECT Num_country FROM Countries WHERE Name_country = '" + CountryBox.Text + "'");
         if (num != -2)
         {
             CityBox.ItemsSource = null;
             CityBox             = DataManager.PushComboBox(CityBox, "Name_city", "SELECT Name_city FROM Cities WHERE Num_country = " + num);
             if (CityBox == null)
             {
                 PagesManager.ShowConnectionError();
             }
         }
         else if (num == -2)
         {
             PagesManager.ShowConnectionError();
         }
     }
     else
     {
         CityBox = DataManager.PushComboBox(CityBox, "Name_city", "SELECT Name_city FROM Cities");
         if (CityBox == null)
         {
             PagesManager.ShowConnectionError();
         }
     }
     System.GC.Collect();
 }
 private void InsertNewUserWithRight(string table, string num, int right, SqlManager connection)
 {
     flag = connection.Insert($"INSERT INTO {table}" +
                              "(Name, Last_name, Middle_name, Passport_series, Passport_number, Phone_number, DateBirth)" +
                              "VALUES ('" + name.Text + "','" + LastName.Text + "','" + MiddleName.Text + "'," + SeriaPass.Text +
                              "," + NumberPass.Text + ",'" + Phone.Text + "','" + DateBirth.Text + "')");
     if (flag != -2)
     {
         flag = connection.ReturnNumber($"SELECT {num} FROM {table} WHERE Passport_series = " + SeriaPass.Text + "AND Passport_number = " + NumberPass.Text);
         if (flag != -2)
         {
             int buf = flag;
             flag = connection.Insert($"INSERT INTO Accounts(login,password,access_right, {num})" +
                                      " VALUES ('" + DataManager.MakeHash(Login.Text) + "','" + DataManager.MakeHash(Password1.Password) + $"', {right}," + buf + ")");
             if (flag == -2)
             {
                 ShowConnectionError();
             }
         }
         else if (flag == -2)
         {
             ShowConnectionError();
         }
     }
     else if (flag == -2)
     {
         ShowConnectionError();
     }
 }
示例#3
0
        public PageTrips(List <string> list)
        {
            InitializeComponent();
            sqlManager = new SqlManager();
            int flag = 0;

            if (sqlManager.UpdateActualCountTripsInDB() != -2)
            {
                listParams = list;
                if (listParams.ElementAt(1) != "")
                {
                    Item.cityNum = sqlManager.ReturnNumber("SELECT Num_city FROM Cities WHERE Name_city = '" + listParams.ElementAt(1) + "'");
                    if (Item.cityNum == -2)
                    {
                        flag = -2;
                        PagesManager.ShowConnectionError();
                    }
                }
                if (flag != -2)
                {
                    UpdateListView();
                }
            }
            else
            {
                PagesManager.ShowConnectionError();
            }
        }
示例#4
0
        public static int CountTickets()
        {
            //получение количества купленных пользователем путевок
            SqlManager sqlManager = new SqlManager();
            int        flag       = sqlManager.ReturnNumber("SELECT COUNT(Num_trip) " +
                                                            "FROM Trips WHERE Num_tourist = " + id);

            return(flag);
        }
示例#5
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);
                }
            }
        }
示例#6
0
 private void Enter_Click(object sender, RoutedEventArgs e)
 {
     if (Login.Text.Length > 0 && Password.Password.Length > 0)
     {
         if (DataManager.CheckInputString(@"^(?=.{3,10}$)[A-Za-z0-9]*$", Login.Text))                   //предварительная проверка логина
         {
             if (DataManager.CheckInputString(@"^(?=.{5,20}$)[A-Za-z0-9!#$%^&*]*$", Password.Password)) //предварительная проверка пароля
             {
                 SqlManager connection = new SqlManager();
                 int        flag       = connection.ExistsAccount(Login.Text, Password.Password); //проверка на существование аккаунта
                 if (flag == 0)
                 {
                     //получение прав доступа
                     DataPerson.right = connection.ReturnNumber("SELECT access_right FROM Accounts " +
                                                                "WHERE login = '******'");
                     if (DataPerson.right != -2)
                     {
                         //получение номера аккаунта в зависимости от прав
                         if (DataPerson.right == 3)
                         {
                             DataPerson.id = connection.ReturnNumber("SELECT Num_tourist FROM Accounts " +
                                                                     "WHERE login = '******'");
                             if (DataPerson.id == -2)
                             {
                                 flag = -2;
                             }
                         }
                         else if (DataPerson.right == 2)
                         {
                             DataPerson.id = connection.ReturnNumber("SELECT Num_worker FROM Accounts " +
                                                                     "WHERE login = '******'");
                             if (DataPerson.id == -2)
                             {
                                 flag = -2;
                             }
                         }
                         if ((DataPerson.right == 2 || DataPerson.right == 3) && flag != -2)
                         {
                             TourismWindow tw = new TourismWindow();
                             tw.Show();
                             Close();
                         }
                         else if (DataPerson.right == 1 && flag != -2)
                         {
                             WindowAdmin wa = new WindowAdmin();
                             wa.Show();
                             Close();
                         }
                         else
                         {
                             ShowConnectionError();
                         }
                         System.GC.Collect();
                     }
                     else
                     {
                         ShowConnectionError();
                     }
                 }
                 else if (flag == -2)
                 {
                     ShowConnectionError();
                 }
                 else
                 {
                     ShowError();
                 }
             }
             else
             {
                 ShowError();
             }
         }
         else
         {
             ShowError();
         }
     }
     else
     {
         MessageBox.Show("Необходимо ввести пароль и логин.", "", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }