private void btnSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbEnterprise.Text)) { MessageBox.Show("Название предприятия не должно быть пустым.", "Проверка"); return; } if (tbEnterprise.Text.Length > 30) { MessageBox.Show("Слишком длинное слово.", "Проверка"); return; } if ((!string.IsNullOrEmpty(tbEnterprise.Text))) { EnterpriseDto countr = new EnterpriseDto(); countr.NameEnterprise = tbEnterprise.Text; IEnterpriseProcess workProcess = ProcessFactory.GetEnterpriseProcess(); if (_id == 0) { workProcess.Add(countr); } else { countr.IDEnterprise = _id; workProcess.Add(countr); } Close(); } }
public void InsertEnterprise(EnterpriseDto enterprise) { var enterpriseEntity = TypeAdapter.Adapt <Enterprise>(enterprise); _context.Enterprises.Add(enterpriseEntity); _context.SaveChanges(); }
public void Load(EnterpriseDto enterp) { if (enterp == null) { return; } _id = enterp.IDEnterprise; tbEnterprise.Text = enterp.NameEnterprise; }
public static Enterprise Convert(EnterpriseDto enterpriseDto) { if (enterpriseDto == null) { return(null); } Enterprise enterprise = new Enterprise(); enterprise.IDEnterprise = enterpriseDto.IDEnterprise; enterprise.NameEnterprise = enterpriseDto.NameEnterprise; return(enterprise); }
public async Task <IActionResult> Post([FromBody] EnterpriseDto enterpriseDto) { if (!User.Identity.IsAuthenticated) { throw new AuthenticationException(); } var enterprise = _mapper.Map <Enterprise>(enterpriseDto); await _enterpriseService.InsertEnterprise(enterprise); enterpriseDto = _mapper.Map <EnterpriseDto>(enterprise); var response = new ApiResponse <EnterpriseDto>(enterpriseDto); return(Ok(response)); }
public async Task <IActionResult> Put(int id, EnterpriseDto enterpriseDto) { if (!User.Identity.IsAuthenticated) { throw new AuthenticationException(); } var enterprise = _mapper.Map <Enterprise>(enterpriseDto); enterprise.Id = id; var result = await _enterpriseService.UpdateEnterprise(enterprise); var response = new ApiResponse <bool>(result); return(Ok(response)); }
public ActionResult UpdateEnterprise(EnterpriseDto model) { var result = new StandardJsonResult <string>(); result.Try(() => { if (!ModelState.IsValid) { throw new KnownException(ModelState.GetFirstError()); } model.UpdateTime = DateTime.Now; bool f = _ieIEnterprise.UpdateEnterprise(model); result.Value = f.ToString(); }); return(result); }
private void btnEditE_Click(object sender, RoutedEventArgs e) { EnterpriseDto item = dgEnterprise.SelectedItem as EnterpriseDto; if (item == null) { MessageBox.Show("Выберите запись для редактирования", "Редактирование"); return; } WinEnterprise window = new WinEnterprise(); window.Load(item); window.ShowDialog(); btnUpdateE_Click(sender, e); }
public ActionResult AddEnterprise(EnterpriseDto model) { var result = new StandardJsonResult <string>(); result.Try(() => { if (!ModelState.IsValid) { throw new KnownException(ModelState.GetFirstError()); } model.Deleted = false; model.RegistDate = DateTime.Now; model.UpdateTime = DateTime.Now; model.RegistDate = DateTime.Now; string value = _ieIEnterprise.AddEnterprise(model); result.Value = value; }); return(result); }
private void btnDeleteE_Click(object sender, RoutedEventArgs e) { EnterpriseDto item = dgEnterprise.SelectedItem as EnterpriseDto; if (item == null) { MessageBox.Show("Выберите запись для удаления", "Удаление предприятия"); return; } MessageBoxResult result = MessageBox.Show("Удалить " + item.NameEnterprise + "?", "Удаление предприятия", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) { return; } ProcessFactory.GetEnterpriseProcess().Delete(item.IDEnterprise); btnUpdateE_Click(sender, e); }
public bool UpdateEnterprise(EnterpriseDto enterprise) { try { using (var db = new BCEnterpriseContext()) { var temp = db.Enterprises.First(x => x.EnterpriseID.Equals(enterprise.EnterpriseID)); if (null == temp) { throw new KnownException("该对象不存在"); } temp.Name = enterprise.Name; temp.ProfessionID = enterprise.ProfessionID; temp.Province = enterprise.Province; temp.City = enterprise.City; temp.Address = enterprise.Address; temp.Telephone = enterprise.Telephone; temp.Fax = enterprise.Fax; temp.Status = enterprise.Status; temp.UpdateTime = enterprise.UpdateTime; temp.PropertyID = enterprise.PropertyID; if (db.SaveChanges() > 0) { return(true); } else { return(false); } } } catch (Exception e) { throw e; } }
public void Add(EnterpriseDto artist) { _enterpriseDao.Add(DtoConvert.Convert(artist)); }
public string AddEnterprise(EnterpriseDto enterprise) { try { using (var db = new BCEnterpriseContext()) { var idGenerator = ML.BC.Infrastructure.Ioc.GetService <IUniqeIdGenerator>(); var enterpriseId = idGenerator.GeneratorEnterpriseID(enterprise.ProfessionID, enterprise.PropertyID); //为null则行业ID和性质ID长度有误 if (null == enterpriseId) { throw new KnownException("企业ID生成失败"); } else { enterprise.EnterpriseID = enterpriseId; } // 设置注册和更新时间为当前时间 enterprise.RegistDate = DateTime.Now; enterprise.UpdateTime = DateTime.Now; // 判断不允许为空的字段是否为空 if ( string.IsNullOrEmpty(enterprise.EnterpriseID) || string.IsNullOrEmpty(enterprise.Name) || string.IsNullOrEmpty(enterprise.ProfessionID) || string.IsNullOrEmpty(enterprise.PropertyID) || null == enterprise.UpdateTime || null == enterprise.RegistDate) { throw new KnownException("不允许非空字段为空"); } var prof = db.EnterpriseProfessions.FirstOrDefault(x => x.EnterpriseProfessionID.Equals(enterprise.ProfessionID)); if (null == prof) { throw new KnownException("行业ID无效"); } var prop = db.EnterprisePropertys.FirstOrDefault(x => x.EnterprisePropertyID.Equals(enterprise.PropertyID)); if (null == prop) { throw new KnownException("性质ID无效"); } db.Enterprises.Add(enterprise); //添加企业超级管理员 var uid = AddEnterpriseAdmin(db, enterpriseId); //添加企业超级管理员用户角色关系 AddEnterpriseAdaminRole(db, enterpriseId, uid); if (db.SaveChanges() > 0) { return(enterprise.EnterpriseID); } else { return(null); } } } catch (Exception e) { throw 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 static EnterpriseModel ToModel(this EnterpriseDto x) { return(new EnterpriseModel { IsEnabled = true, Id = x.Id, Name = x.Name }); }
public void InsertEnterprise(EnterpriseDto enterprise) { Channel.InsertEnterprise(enterprise); }
private List <EnterpriseDto> GetEnterprisesBase(long?nit, int?idCod, int?idEnterprise) { List <EnterpriseDto> enterprisesDto = new List <EnterpriseDto>(); List <EnterpriseDto> enterprisesDtoAux = new List <EnterpriseDto>(); EnterpriseDto enterpriseDto = new EnterpriseDto(); var codes = nit == null && idCod == null && idEnterprise == null ? _context.Codes : nit != null && idCod == null && idEnterprise == null?_context.Codes.Where(o => o.Owner.Nit.Equals(nit)) : nit == null && idCod == null && idEnterprise != null?_context.Codes.Where(o => o.Owner.Id.Equals(idEnterprise)) : _context.Codes.Where(o => o.Id.Equals(idCod)); //nit == null && idCod == null ? _context.Codes : // nit != null && idCod == null ? _context.Codes.Where(o => o.Owner.Nit.Equals(nit)) : // _context.Codes.Where(o => o.Id.Equals(idCod)); foreach (var item in codes) { enterpriseDto.Id = item.Owner.Id; enterpriseDto.Name = item.Owner.Name; enterpriseDto.Nit = item.Owner.Nit; enterpriseDto.GIn = item.Owner.GIn; enterpriseDto.CodeList = new List <CodeDto>(); if ((nit != null && idCod == null) || idEnterprise != null) { enterpriseDto.CodeList.Add(new CodeDto { Id = item.Id, Name = item.Name, Description = item.Description }); } if (!enterprisesDto.Contains(enterpriseDto)) { enterprisesDto.Add(enterpriseDto); } enterpriseDto = new EnterpriseDto(); } foreach (var ente in enterprisesDto) { if (enterprisesDtoAux.Count > 0 && (nit != null && idCod == null) || idEnterprise != null) { bool aux = enterprisesDtoAux.Select(o => o.Id.Equals(ente.Id)).First(); if (aux) { enterprisesDtoAux.Where(o => o.Id.Equals(ente.Id)).First().CodeList.AddRange(ente.CodeList); } else { enterprisesDtoAux.Add(ente); } } else { enterprisesDtoAux.Add(ente); } } return(enterprisesDtoAux); }