private void SaveButton_Click(object sender, EventArgs e) { if (Save()) { MyMsgBox.showInfo("Сохранено"); } }
private void button3_Click(object sender, EventArgs e) { pERSONCARDBindingSource.Clear(); var surname = SurNameTextBox.Text; var name = NameTextBox.Text; var midname = MidNameTextBox.Text; var tabNum = TabNumTextBox.Text; if (string.IsNullOrWhiteSpace(surname) && string.IsNullOrWhiteSpace(name) && string.IsNullOrWhiteSpace(midname) && string.IsNullOrWhiteSpace(tabNum)) { MyMsgBox.showError("Заполните хотя бы 1 поле"); return; } IQueryable <PERSONCARD> query = model.PERSONCARD; if (!string.IsNullOrWhiteSpace(surname)) { query = query.Where(worker => worker.SURNAME == surname); } if (!string.IsNullOrWhiteSpace(name)) { query = query.Where(worker => worker.NAME == name); } if (!string.IsNullOrWhiteSpace(midname)) { query = query.Where(worker => worker.MIDDLENAME == midname); } if (!string.IsNullOrWhiteSpace(tabNum)) { decimal tabNumInt; try { tabNumInt = Decimal.Parse(tabNum); Console.WriteLine(tabNumInt); }catch (Exception expr) { MyMsgBox.showError("Табельный номер должен содержать только числа"); Console.WriteLine(expr.Message); return; } query = query.Where(worker => worker.TABEL_NUM == tabNumInt); } if (query.Count() == 0) { MyMsgBox.showInfo("Ничего не найдено"); return; } result = new List <PERSONCARD>(query.Count()); foreach (PERSONCARD worker in query) { result.Add(worker); pERSONCARDBindingSource.Add(worker); } }
private void DeleteWorkerButton_Click(object sender, EventArgs e) { var rows = WorkersGridView.SelectedRows; if (rows.Count < 1) { MyMsgBox.showInfo("Вы не выделили строку"); return; } if (MyMsgBox.showAsk("Вы точно хотите удалить?") == false) { return; } for (int i = 0; i < rows.Count; i++) { WorkersGridView.Rows.Remove(rows[i]); } }
private void DeleteButton_Click(object sender, EventArgs e) { if (trip == null) { MyMsgBox.showError("Нельзя удалить ещё не добавленную командировку"); return; } else if (MyMsgBox.showAsk("Вы уверены, что хотите удалить командировку ?")) { model.UPDTRIP.Remove(trip); try { model.SaveChanges(); MyMsgBox.showInfo("Удалено!"); } catch (Exception exc) { Console.Error.WriteLine(exc); MyMsgBox.showError("Ошибка при удалении"); } } }
private void button1_Click(object sender, EventArgs e) { var rows = dataGridView1.SelectedRows; if (rows.Count == 0) { MyMsgBox.showError("Ничего не выделено"); return; } List <PERSONCARD> selected = new List <PERSONCARD>(); foreach (DataGridViewRow row in rows) { selected.Add(result[row.Index]); } komandirovkaForm.SetWorkers(selected); MyMsgBox.showInfo("Добавлено!"); this.Close(); komandirovkaForm.Show(); }
private void SaveButton_Click(object sender, EventArgs e) { var country = CountryComboBox.SelectedValue; if (country == null) { MyMsgBox.showError("Страна не выбрана!"); return; } var city = CityTextBox.Text; if (city == null) { MyMsgBox.showError("Введите город"); return; } var org = OrganizationTextBox.Text; if (string.IsNullOrEmpty(org)) { MyMsgBox.showError("Введите название организации"); return; } var places = model.PLACE_TRIP; //Вдруг такое уже есть PLACE_TRIP neededPlace = null; foreach (PLACE_TRIP place in places) { if (String.Compare(place.City, city, StringComparison.OrdinalIgnoreCase) == 0) { neededPlace = place; break; } } if (neededPlace == null) { PLACE_TRIP newPlace = new PLACE_TRIP(); string test = country as string; newPlace.Country = test; newPlace.City = city; newPlace.createName(); model.PLACE_TRIP.Add(newPlace); model.SaveChanges(); neededPlace = newPlace; Console.WriteLine($"id = {neededPlace.PK_PLACE_TRIP}"); //neededPlace = model.PLACE_TRIP.FirstOrDefault(place => place.NAME == newPlace.NAME); } TRIP_ORG trip_org = model.TRIP_ORG.Create(); trip_org.NAME = org; trip_org.PLACE_TRIP = neededPlace; model.TRIP_ORG.Add(trip_org); model.SaveChanges(); komandirovkaForm.UpdatePlaces(); Console.WriteLine($"id org = {trip_org.PK_TRIP_ORG}"); komandirovkaForm.AddOrgTrip(trip_org); MyMsgBox.showInfo("Добавлено!"); this.Close(); komandirovkaForm.Show(); }
private void ExportButton_Click(object sender, EventArgs e) { Application exApp; try { exApp = new Application(); } catch (Exception) { MyMsgBox.showError("Не удалось открыть Excel для заполения данных."); return; } string PATH_TO_T9 = "templates\\T-9.xls"; string PATH_TO_T9A = "templates\\T-9A.xls"; if (!Directory.Exists("templates")) { Directory.CreateDirectory("templates"); } // спешл фор Астахова ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; // try // { // // спешл фор 7 винда // //if(Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString().Contains("7")) // System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; // }catch(Exception){} try { if (!File.Exists(PATH_TO_T9)) { new WebClient().DownloadFile(new Uri("https://github.com/pi62/templates/raw/master/T-9.xls"), PATH_TO_T9); } if (!File.Exists(PATH_TO_T9A)) { new WebClient().DownloadFile(new Uri("https://github.com/pi62/templates/raw/master/T-9A.xls"), PATH_TO_T9A); } } catch (Exception) { MyMsgBox.showError("Не удалось скачать шаблоны для заполнения."); return; } var saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = Directory.GetCurrentDirectory(); saveFileDialog1.DefaultExt = "xls"; saveFileDialog1.ShowDialog(); var savePath = saveFileDialog1.FileName; if (String.IsNullOrWhiteSpace(savePath)) { return; } if (!Save() || trip == null) { MyMsgBox.showError("Не удалось сохранить командировку. Экспорт невозможен. Проверьте данные и попробуйте ещё раз"); return; } Workbook excelappworkbooks; try { if (trip.PERSONCARD_IN_TRIP.Count > 1) { excelappworkbooks = exApp.Workbooks.Open(Directory.GetCurrentDirectory() + "\\" + PATH_TO_T9A, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } else { excelappworkbooks = exApp.Workbooks.Open(Directory.GetCurrentDirectory() + "\\" + PATH_TO_T9, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } } catch (Exception except) { Console.Error.WriteLine(except.Message); MyMsgBox.showError("Не удалось открыть шаблон"); return; } if (excelappworkbooks == null) { MyMsgBox.showError("Не удалось открыть шаблон"); return; } try { if (trip.PERSONCARD_IN_TRIP.Count > 1) { Worksheet excelsheets = excelappworkbooks.Worksheets.Item[1]; OUR_ORG org = model.OUR_ORG.First <OUR_ORG>(); if (trip.PRIKAZ.ISPROJECT.Equals("1")) { excelsheets.Cells[9, 34].Value = "ПРОЕКТ ПРИКАЗА"; excelsheets.Cells[10, 34].Value = "(распоряжения)"; } else { excelsheets.Cells[9, 34].Value = "ПРИКАЗ"; excelsheets.Cells[10, 34].Value = "(распоряжение)"; } excelsheets.Cells[5, 1].Value = org.NAME; excelsheets.Cells[5, 93] = org.OKPO; excelsheets.Cells[9, 61] = trip.PRIKAZ.NUMDOC; if (trip.PRIKAZ.CREATEDATE != null) { excelsheets.Cells[9, 80] = trip.PRIKAZ.CREATEDATE.Value.ToString("dd.MM.yyyy"); } int i = 0; foreach (PERSONCARD_IN_TRIP person in trip.PERSONCARD_IN_TRIP) { if (i == 3) { MyMsgBox.showError("В одном приказе не больше 3х человек"); break; } excelsheets.Cells[15, 44 + 22 * i].Value = person.SURNAME + " " + person.NAME + " " + person.MIDDLENAME; excelsheets.Cells[16, 44 + 22 * i].Value = person.TABEL_NUM; if (person.PODRAZDELORG != null) { excelsheets.Cells[17, 44 + 22 * i].Value = person.PODRAZDELORG.NAME; } excelsheets.Cells[18, 44 + 22 * i].Value = person.JOB_POS.NAME; excelsheets.Cells[21, 44 + 22 * i].Value = person.STARTDATE.Value.ToString("dd.MM.yyyy"); excelsheets.Cells[22, 44 + 22 * i].Value = person.ENDDATE.Value.ToString("dd.MM.yyyy"); excelsheets.Cells[23, 44 + 22 * i].Value = (int)person.ENDDATE.Value.Subtract(person.STARTDATE.Value).TotalDays; excelsheets.Cells[24, 44 + 22 * i].Value = person.GOAL; excelsheets.Cells[25, 44 + 22 * i].Value = person.FINANCE; i++; } foreach (TRIP_ORG tripOrg in trip.TRIP_ORG) { excelsheets.Cells[19, 44].Value += tripOrg.PLACE_TRIP.NAME; excelsheets.Cells[19, 44].Value += ", " + tripOrg.NAME; excelsheets.Cells[19, 44].Value += "; "; } if (trip.OSNOVANIEDATE != null) { excelsheets.Cells[30, 36].Value = trip.OSNOVANIE + " от " + trip.OSNOVANIEDATE.Value.ToString("dd.MM.yyyy"); } else { excelsheets.Cells[30, 36].Value = trip.OSNOVANIE; } } else { Worksheet excelsheets = excelappworkbooks.Worksheets.Item[1]; OUR_ORG org = model.OUR_ORG.First(); if (trip.PRIKAZ.ISPROJECT.Equals("1")) { excelsheets.Cells[13, 19].Value = "ПРОЕКТ ПРИКАЗА"; excelsheets.Cells[14, 19].Value = "(распоряжения)"; } else { excelsheets.Cells[13, 19].Value = "ПРИКАЗ"; excelsheets.Cells[14, 19].Value = "(распоряжение)"; } excelsheets.Cells[7, 1].Value = org.NAME; excelsheets.Cells[7, 45] = org.OKPO; excelsheets.Cells[13, 35] = trip.PRIKAZ.NUMDOC; if (trip.PRIKAZ.CREATEDATE != null) { excelsheets.Cells[13, 48] = trip.PRIKAZ.CREATEDATE.Value.ToString("dd.MM.yyyy"); } PERSONCARD_IN_TRIP person = trip.PERSONCARD_IN_TRIP.First(); excelsheets.Cells[18, 1].Value = person.SURNAME + " " + person.NAME + " " + person.MIDDLENAME; excelsheets.Cells[18, 47].Value = person.TABEL_NUM; if (person.PODRAZDELORG != null) { excelsheets.Cells[20, 1].Value = person.PODRAZDELORG.NAME; } excelsheets.Cells[22, 1].Value = person.JOB_POS.NAME; int i = 0; foreach (TRIP_ORG tripOrg in trip.TRIP_ORG) { if (excelsheets.Cells[24 + i, 1].Text.Length > 100) { if (i == 0) { i += 2; } else { i++; } } excelsheets.Cells[24 + i, 1].Value += tripOrg.PLACE_TRIP.NAME; excelsheets.Cells[24 + i, 1].Value += ", " + tripOrg.NAME; excelsheets.Cells[24 + i, 1].Value += " ; "; } excelsheets.Cells[33, 3].Value = person.STARTDATE.Value.Day; excelsheets.Cells[33, 7].Value = person.STARTDATE.Value.ToString("MMMM"); excelsheets.Cells[33, 21].Value = person.STARTDATE.Value.ToString("yy"); excelsheets.Cells[33, 30].Value = person.ENDDATE.Value.Day; excelsheets.Cells[33, 34].Value = person.ENDDATE.Value.ToString("MMMM"); excelsheets.Cells[33, 48].Value = person.ENDDATE.Value.ToString("yy"); excelsheets.Cells[31, 8].Value = (int)person.ENDDATE.Value.Subtract(person.STARTDATE.Value).TotalDays; excelsheets.Cells[35, 6].Value = person.GOAL; excelsheets.Cells[38, 18].Value = person.FINANCE; if (trip.OSNOVANIEDATE != null) { excelsheets.Cells[42, 15].Value = trip.OSNOVANIE + " от " + trip.OSNOVANIEDATE.Value.ToString("dd.MM.yyyy"); } else { excelsheets.Cells[42, 15].Value = trip.OSNOVANIE; } } } catch (Exception except) { Console.Error.WriteLine(except.Message); } MyMsgBox.showInfo("Готово!"); excelappworkbooks.SaveAs(savePath); exApp.Quit(); }