private void btnSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbCodeMachine.Text)) { MessageBox.Show("Код станка не может быть пустым.", "Проверка"); return; } else { int num; bool isNum = int.TryParse(tbCodeMachine.Text, out num); if (!isNum) { MessageBox.Show("Введено не число! Пожалуйста, повторите ввод!", "Проверка"); return; } } if (string.IsNullOrEmpty(tbMark.Text)) { MessageBox.Show("Марка не может быть пустым", "Проверка"); return; } if (tbMark.Text.Length > 20) { MessageBox.Show("Название марки не может превышать более 20 символов.", "Проверка"); } if (string.IsNullOrEmpty(dpData.Text)) { MessageBox.Show("Дата выпуска не может быть пустым", "Проверка"); return; } if (Convert.ToInt32(dpData.Text) < 1980 && (Convert.ToInt32(dpData.Text) > 1999)) { MessageBox.Show("Станка данного года не обслуживается", "Проверка"); } TypeMachineDto mach = new TypeMachineDto(); mach.YearOfIssue = Convert.ToInt32(this.dpData.Text); mach.CodeMachine = Convert.ToInt32(this.tbCodeMachine.Text); mach.Mark = this.tbMark.Text; ITypeMachineProcess machProcess = ProcessFactory.GetTypeMachinProcess(); if (_id == 0) { machProcess.Add(mach); } else { mach.YearOfIssue = _id; machProcess.Update(mach); } this.Close(); }
public static TypeMachine Convert(TypeMachineDto typeMachine) { if (typeMachine == null) { return(null); } TypeMachine machine = new TypeMachine(); machine.CodeMachine = typeMachine.CodeMachine; machine.Mark = typeMachine.Mark; machine.YearOfIssue = typeMachine.YearOfIssue; return(machine); }
public void Load(TypeMachineDto rep) { if (rep == null) { return; } this._id = Convert.ToInt32(rep.YearOfIssue); tbCodeMachine.Text = rep.CodeMachine.ToString(); tbMark.Text = rep.Mark; dpData.Text = rep.YearOfIssue.ToString(); tbCodeMachine.IsEnabled = false; }
public static TypeMachineDto Convert(TypeMachine typeMachine) { if (typeMachine == null) { return(null); } TypeMachineDto typeMachineDto = new TypeMachineDto(); typeMachineDto.CodeMachine = typeMachine.CodeMachine; typeMachineDto.Mark = typeMachine.Mark; typeMachineDto.YearOfIssue = typeMachine.YearOfIssue; return(typeMachineDto); }
private void btnEdittM_Click(object sender, RoutedEventArgs e) { TypeMachineDto item = dgTypeMachine.SelectedItem as TypeMachineDto; if (item == null) { MessageBox.Show("Выберите запись для редактирования", "Редактирование"); return; } WinTypeMach window = new WinTypeMach(); window.Load(item); window.ShowDialog(); btnUpdatetM_Click(sender, e); }
private void btnDeletetM_Click(object sender, RoutedEventArgs e) { TypeMachineDto item = dgTypeMachine.SelectedItem as TypeMachineDto; if (item == null) { MessageBox.Show("Выберите запись для удаления", "Удаление вида станка"); return; } MessageBoxResult result = MessageBox.Show("Удалить " + item.CodeMachine + "?", "Удаление вида станка", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) { return; } ProcessFactory.GetTypeMachinProcess().Delete(item.CodeMachine); btnUpdatetM_Click(sender, e); }
public void fillExcelTableByType(IEnumerable <object> grid, string status, FileInfo xlsxFile) { try { if (grid != null) { ExcelPackage pck = new ExcelPackage(xlsxFile); var excel = pck.Workbook.Worksheets.Add(status); int x = 1; int y = 1; CultureInfo cultureInfo = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name); Thread.CurrentThread.CurrentCulture = cultureInfo; cultureInfo.NumberFormat.NumberDecimalSeparator = "."; excel.Cells["A1:Z1"].Style.Font.Bold = true; excel.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; excel.Cells.Style.Numberformat.Format = "General"; Object dtObj = new Object(); switch (status) { case "Country": dtObj = new CountryDto(); break; case "Enterprise": dtObj = new EnterpriseDto(); break; case "Repair": dtObj = new RepairDto(); break; case "Machine": dtObj = new MachineDto(); break; case "TypeMachine": dtObj = new TypeMachineDto(); break; case "TypeRepair": dtObj = new TypeRepairDto(); break; } foreach (var prop in dtObj.GetType().GetProperties()) { excel.Cells[y, x].Value = prop.Name.Trim(); x++; } foreach (var item in grid) { y++; Object itemObj = item; x = 1; foreach (var prop in itemObj.GetType().GetProperties()) { object t = prop.GetValue(itemObj, null); object val; if (t == null) { val = ""; } else { val = t.ToString(); if (t is CountryDto) { val = ((CountryDto)t).NameCountry; } if (t is MachineDto) { val = ((MachineDto)t).CodeMashine; } if (t is RepairDto) { val = ((RepairDto)t).StartDate; } if (t is EnterpriseDto) { val = ((EnterpriseDto)t).NameEnterprise; } if (t is TypeMachineDto) { val = ((TypeMachineDto)t).CodeMachine; } if (t is TypeRepairDto) { val = ((TypeRepairDto)t).NameRepair; } if (t is NameRepairDto) { val = ((NameRepairDto)t).NameTypeRepair; } } excel.Cells[y, x].Value = val; x++; } } excel.Cells.AutoFitColumns(); pck.Save(); } else { MessageBox.Show("Данные не загружены!"); } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } }
public void Update(TypeMachineDto artist) { _typeMachineDao.Update(DtoConvert.Convert(artist)); }
public void Add(TypeMachineDto artist) { _typeMachineDao.Add(DtoConvert.Convert(artist)); }