public PageHistory() { //получение истории пользователя InitializeComponent(); SqlManager sqlManager = new SqlManager(); DataTable dt = sqlManager.ReturnTable("SELECT Tours.Name_tour, Price, DateOfBuy " + "FROM Trips JOIN Tours ON Tours.Num_tour = Trips.Num_tour " + "WHERE Num_tourist = " + DataPerson.id); if (dt != null) { foreach (DataRow dr in dt.Rows) { HistoryGrid.Items.Add(new Item { NameTour = dr.ItemArray[0].ToString(), Price = Convert.ToInt32(dr.ItemArray[1]), DateBuy = dr.ItemArray[2].ToString().Remove(dr.ItemArray[2].ToString().Length - 8, 8) }); System.GC.Collect(); } } else { PagesManager.ShowConnectionError(); } }
public static ComboBox PushComboBox(ComboBox x, string column, string sql) { SqlManager sqlManager = new SqlManager(); DataTable dt; if ((dt = sqlManager.ReturnTable(sql)) != null) { x.ItemsSource = dt.AsDataView(); x.DisplayMemberPath = column; } else { x = null; } return(x); }
private void Buy_Click(object sender, RoutedEventArgs e) { SqlManager sqlManager; if (DataPerson.right == 3) //создание билета для обычного пользователя { MakeTicket(null); } else if (DataPerson.right == 2) //для сотрудника выбор пользователя из списка { SelectedTrips.Visibility = Visibility.Hidden; choiseDataGrid.Visibility = Visibility.Visible; label.Visibility = Visibility.Visible; sqlManager = new SqlManager(); DataTable dt = sqlManager.ReturnTable("SELECT * FROM Tourists"); if (dt != null) { foreach (DataRow dr in dt.Rows) { choiseDataGrid.Items.Add(new ManyPersons { NamePerson = dr.ItemArray[2].ToString(), LastName = dr.ItemArray[1].ToString(), MiddleName = (dr.ItemArray[3].ToString() == "") ? "Отсутствует" : dr.ItemArray[3].ToString(), SeriaPass = Convert.ToInt32(dr.ItemArray[5]), NumberPass = Convert.ToInt32(dr.ItemArray[6]), PhoneNumber = dr.ItemArray[7].ToString() }); } } else { PagesManager.ShowConnectionError(); } } }
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); } } }
private void datagrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { DataGridCellInfo cellInfo = datagrid.CurrentCell; if (datagrid.CurrentCell.Column != null) { numColumn = datagrid.CurrentCell.Column.DisplayIndex - 1; if ((cellInfo.Column.GetCellContent(cellInfo.Item) as TextBox) != null) { if ((cellInfo.Column.GetCellContent(cellInfo.Item) as TextBox).Text != "") { DataTable dt = sqlManager.ReturnTable("SELECT * FROM " + dataTable.TableName + " WHERE 1 = 2"); if (dt != null) { if (dt.Columns[numColumn].DataType.Name == "DateTime") { if (DataManager.CheckInputString(listRegexs.First(x => x.Key == "Date").Value, (cellInfo.Column.GetCellContent(cellInfo.Item) as TextBox).Text) == true) { e.Cancel = false; } else { MessageBox.Show("Изменения не зафиксированы, некорректный ввод!\nДата вводится по формату dd.mm.yyyy", "", MessageBoxButton.OK, MessageBoxImage.Error); e.Cancel = true; } } else if (DataManager.CheckInputString(listRegexs.First(x => x.Key == dataTable.Columns[numColumn].DataType.Name).Value, (cellInfo.Column.GetCellContent(cellInfo.Item) as TextBox).Text) == true) { if (dataTable.Columns[numColumn].DataType.Name == "Int32") { int res = sqlManager.CheckKey(dataTable.TableName, cellInfo.Column.Header.ToString(), Convert.ToInt32((cellInfo.Column.GetCellContent(cellInfo.Item) as TextBox).Text)); if (res == 0 || res == 1) { e.Cancel = false; } else if (res == -2) { ShowConnectionError(); } else { MessageBox.Show("Строка с таким номером не найдена!", "", MessageBoxButton.OK, MessageBoxImage.Error); e.Cancel = true; } } else { e.Cancel = false; } } else { MessageBox.Show("Изменения не зафиксированы, некорректный ввод!", "", MessageBoxButton.OK, MessageBoxImage.Error); e.Cancel = true; } } else { ShowConnectionError(); } } else if (dataTable.Columns[numColumn].AllowDBNull == true && (cellInfo.Column.GetCellContent(cellInfo.Item) as TextBox).Text == "") { if (dataTable.Columns[numColumn].DataType.Name == "Int32") { (cellInfo.Column.GetCellContent(cellInfo.Item) as TextBox).Text = "0"; } e.Cancel = false; } else { MessageBox.Show("Изменения не зафиксированы,\nв этом столбце запрещены значения NULL!", "", MessageBoxButton.OK, MessageBoxImage.Error); e.Cancel = true; } } } }