// Данный метод печатает "Свидетельство об окончании автошколы". void PrintDocumentEleventh(string medNumber) { DataBase DB = new DataBase(); if (!DB.openConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } MySqlCommand command = new MySqlCommand("SELECT driving_school_name, fullName_of_director, surname_chief_PTD FROM `information`", DB.getConnection()); DbDataReader reader = command.ExecuteReader(); reader.Read(); string schoolName = reader.GetString(0); string directorFullName = reader.GetString(1); string chiefSurname = reader.GetString(2); reader.Close(); command = new MySqlCommand("SELECT start_date, end_date FROM `groups` WHERE group_name='ИП-815'", DB.getConnection()); reader = command.ExecuteReader(); reader.Read(); string startDate = reader.GetString(0).Substring(0, 10); string endDate = reader.GetString(1).Substring(0, 10); reader.Close(); command = new MySqlCommand("SELECT student_fullName_dative, protocol_number, protocol_date, certificate_number, certificate_date, category" + " FROM `students` WHERE medical_certificate_number=@medNum", DB.getConnection()); command.Parameters.Add("@medNum", MySqlDbType.VarChar).Value = medNumber; reader = command.ExecuteReader(); reader.Read(); string studentFullNameDative = reader.GetString(0); string protocolNum = reader.GetString(1); string protocolDate = reader.GetString(2).Substring(0, 10); string category = reader.GetString(5); reader.Close(); string currDate = getCurrentDateDB(); if (!DB.closeConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } var wordApp = new Word.Application(); wordApp.Visible = false; try { var wordDocument = wordApp.Documents.Open(eleventhDocumentName); ReplaceWordStub("{studentName}", studentFullNameDative, wordDocument); ReplaceWordStub("{startDate}", startDate, wordDocument); ReplaceWordStub("{endDate}", endDate, wordDocument); ReplaceWordStub("{school}", schoolName, wordDocument); ReplaceWordStub("{category}", category, wordDocument); ReplaceWordStub("{director}", directorFullName, wordDocument); ReplaceWordStub("{proNum}", protocolNum, wordDocument); ReplaceWordStub("{proDate}", protocolDate, wordDocument); ReplaceWordStub("{currDate}", currDate, wordDocument); wordDocument.SaveAs2(@"R:\Final11.docx"); wordDocument.Activate(); wordDocument.PrintOut(Range: Word.WdPrintOutRange.wdPrintFromTo, From: "1", To: "1"); wordDocument.Close(); } catch { MessageBox.Show("Ошибка печати документа!"); } wordApp.Quit(); }
// Данный метод служит для печати "Экзаменационной карточки водителя". void PrintDocumentTenth(string medNumber) { DataBase DB = new DataBase(); if (!DB.openConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } MySqlCommand command = new MySqlCommand("SELECT driving_school_name FROM `information`", DB.getConnection()); DbDataReader reader = command.ExecuteReader(); reader.Read(); string schoolName = reader.GetString(0); reader.Close(); command = new MySqlCommand("SELECT * FROM `students` WHERE medical_certificate_number=@medNum", DB.getConnection()); command.Parameters.Add("@medNum", MySqlDbType.VarChar).Value = medNumber; reader = command.ExecuteReader(); reader.Read(); string studentFullName = reader.GetString(1); string studentAddress = reader.GetString(3); string passportData = reader.GetString(4); string medDate = reader.GetString(8).Substring(0, 10); string medOrg = reader.GetString(9); string protocolNum = reader.GetString(10); string protocolDate = reader.GetString(11).Substring(0, 10); string certificateNum = reader.GetString(12); string certificateDate = reader.GetString(13).Substring(0, 10); string category = reader.GetString(14); if (!DB.closeConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } var wordApp = new Word.Application(); wordApp.Visible = false; try { var wordDocument = wordApp.Documents.Open(tenthDocumentName); ReplaceWordStub("{school}", schoolName, wordDocument); ReplaceWordStub("{studentName}", studentFullName, wordDocument); ReplaceWordStub("{studentAddress}", studentAddress, wordDocument); ReplaceWordStub("{passport}", passportData, wordDocument); ReplaceWordStub("{medNum}", medNumber, wordDocument); ReplaceWordStub("{medDate}", medDate, wordDocument); ReplaceWordStub("{medOrg}", medOrg, wordDocument); ReplaceWordStub("{proNum}", protocolNum, wordDocument); ReplaceWordStub("{proDate}", protocolDate, wordDocument); ReplaceWordStub("{cerNum}", certificateNum, wordDocument); ReplaceWordStub("{cerDate}", certificateDate, wordDocument); ReplaceWordStub("{category}", category, wordDocument); wordDocument.SaveAs2(@"R:\Final10.docx"); wordDocument.Activate(); wordDocument.PrintOut(Range: Word.WdPrintOutRange.wdPrintFromTo, From: "1", To: "1"); wordDocument.Close(); } catch { MessageBox.Show("Ошибка печати документа!"); } wordApp.Quit(); }
// Данный метод печатает "Платёжное поручение за сдачу экзамена в ГИБДД". void PrintDocumentSixth(string medNumber) { DataBase DB = new DataBase(); if (!DB.openConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } MySqlCommand command = new MySqlCommand("SELECT requisites_PTD FROM `information`", DB.getConnection()); DbDataReader reader = command.ExecuteReader(); reader.Read(); string requisites = reader.GetString(0); reader.Close(); command = new MySqlCommand("SELECT student_fullName, student_address FROM `students` WHERE medical_certificate_number=@medNum", DB.getConnection()); command.Parameters.Add("@medNum", MySqlDbType.VarChar).Value = medNumber; reader = command.ExecuteReader(); reader.Read(); string studentFullName = reader.GetString(0); string studentAddress = reader.GetString(1); if (!DB.closeConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } string currDate = getCurrentDateDB(); var wordApp = new Word.Application(); wordApp.Visible = false; try { var wordDocument = wordApp.Documents.Open(sixthDocumentName); ReplaceWordStub("{requisites}", requisites, wordDocument); ReplaceWordStub("{studentName}", studentFullName, wordDocument); ReplaceWordStub("{studentAddress}", studentAddress, wordDocument); ReplaceWordStub("{currDate}", currDate, wordDocument); wordDocument.SaveAs2(@"R:\Final6.docx"); wordDocument.Activate(); wordDocument.PrintOut(Range: Word.WdPrintOutRange.wdPrintFromTo, From: "1", To: "1"); wordDocument.Close(); } catch { MessageBox.Show("Ошибка печати документа!"); } wordApp.Quit(); }
// Данный метод печатает "Экзаменационный протокол". void PrintDocumentEighth(string groupName) { DataBase DB = new DataBase(); if (!DB.openConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } MySqlCommand command = new MySqlCommand("SELECT student_fullName, protocol_number, protocol_date FROM `students` WHERE group_name=@gName", DB.getConnection()); command.Parameters.Add("@gName", MySqlDbType.VarChar).Value = groupName; DbDataReader reader = command.ExecuteReader(); if (reader.HasRows) { var wordApp = new Word.Application(); wordApp.Visible = false; try { var wordDocument = wordApp.Documents.Open(eighthDocumentName); int i = 1; while (reader.Read()) // В цикле перебираются все записи о студентах группы. { string studentFullName = reader.GetString(0); string protocolNum = reader.GetString(1); string protocolDate = reader.GetString(2).Substring(0, 10); ReplaceWordStub("{name" + i.ToString() + "}", studentFullName, wordDocument); ReplaceWordStub("{proNum" + i.ToString() + "}", protocolNum, wordDocument); ReplaceWordStub("{proDate" + i.ToString() + "}", protocolDate, wordDocument); i++; } var tempDocument = wordDocument; tempDocument.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; tempDocument.SaveAs2(@"R:\Final8.docx"); wordDocument.Activate(); wordDocument.PrintOut(Range: Word.WdPrintOutRange.wdPrintFromTo, From: "1", To: "1"); wordDocument.Close(); } catch { MessageBox.Show("Ошибка печати документа!"); } wordApp.Quit(); } else { MessageBox.Show("Группа пуста или не существует!"); } if (!DB.closeConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); return; } }
private void button_findStudent_Click(object sender, EventArgs e) { string fullName = textBox_fullName.Text; string protocolNum = textBox_protocolNum.Text; string certificateNum = textBox_certificateNum.Text; if (fullName == "") { MessageBox.Show("Заполните поле \"ФИО курсанта\"!"); return; } else if (protocolNum == "") { MessageBox.Show("Заполните поле \"Протокол №\"!"); return; } else if (certificateNum == "") { MessageBox.Show("Заполните поле \"Свидетельство №\"!"); return; } DataBase DB = new DataBase(); if (!DB.openConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); } // Задаём содержимое SQL-запроса и обращаемся с данным запросом к базе данных. MySqlCommand command = new MySqlCommand("SELECT * FROM students WHERE student_fullName=@fullName " + "AND protocol_number=@proNum AND certificate_number=@cerNum", DB.getConnection()); command.Parameters.Add("@fullName", MySqlDbType.VarChar).Value = fullName; command.Parameters.Add("@proNum", MySqlDbType.VarChar).Value = protocolNum; command.Parameters.Add("@cerNum", MySqlDbType.VarChar).Value = certificateNum; // Инициализирует DbDataReader, с помощью которого будем читать из таблиц записи, // и помещать их содержимое в элемент управления listBox_studentData. DbDataReader reader = command.ExecuteReader(); listBox_studentData.Items.Clear(); if (reader.HasRows) { reader.Read(); // Производим чтение записи. int someIndex = reader.GetOrdinal("group_name"); // Находим индекс нужного нам столбца, по его названию. string groupName = reader.GetString(someIndex); // Записываем в строковую переменную содержимое данной ячейки. someIndex = reader.GetOrdinal("student_fullName"); fullName = reader.GetString(someIndex); someIndex = reader.GetOrdinal("student_fullName_dative"); string fullNameDative = reader.GetString(someIndex); someIndex = reader.GetOrdinal("passport_data"); string passData = reader.GetString(someIndex); someIndex = reader.GetOrdinal("place_of_work"); string placeWork = reader.GetString(someIndex); someIndex = reader.GetOrdinal("address_of_work"); string workAddress = reader.GetString(someIndex); someIndex = reader.GetOrdinal("medical_certificate_number"); string medNum = reader.GetString(someIndex); someIndex = reader.GetOrdinal("medical_certificate_date"); string medDate = reader.GetString(someIndex).Substring(0, 10);; someIndex = reader.GetOrdinal("medical_certificate_organizationName"); string medOrganization = reader.GetString(someIndex); someIndex = reader.GetOrdinal("protocol_number"); protocolNum = reader.GetString(someIndex); someIndex = reader.GetOrdinal("protocol_date"); string protocolDate = reader.GetString(someIndex).Substring(0, 10); someIndex = reader.GetOrdinal("certificate_number"); certificateNum = reader.GetString(someIndex); someIndex = reader.GetOrdinal("certificate_date"); string certificateDate = reader.GetString(someIndex).Substring(0, 10); someIndex = reader.GetOrdinal("category"); string category = reader.GetString(someIndex); listBox_studentData.Items.Add("Название группы: " + groupName); // Заполняем listBox_studentData. listBox_studentData.Items.Add("ФИО курсанта: " + fullName); listBox_studentData.Items.Add("ФИО курсанта в дательном падеже: " + fullNameDative); listBox_studentData.Items.Add("Пасспортные данные: " + passData); listBox_studentData.Items.Add("Место работы: " + placeWork); listBox_studentData.Items.Add("Адрес места работы: " + workAddress); listBox_studentData.Items.Add("Номер медицинской справки: " + medNum); listBox_studentData.Items.Add("Дата выдачи медициской справки: " + medDate); listBox_studentData.Items.Add("Мед.учреждение, выдавшее справку: " + medOrganization); listBox_studentData.Items.Add("Номер протокола: " + protocolNum); listBox_studentData.Items.Add("Дата выдачи протокола: " + protocolDate); listBox_studentData.Items.Add("Номер свидетельства: " + certificateNum); listBox_studentData.Items.Add("Дата выдачи свидетельства: " + certificateDate); listBox_studentData.Items.Add("Категория: " + category); } else { MessageBox.Show("Данный курсант не найден!"); } if (!DB.closeConnection()) { MessageBox.Show("Нарушено соединение с базой данных!"); this.Close(); } }