private void btnSaveCompany_Click(object sender, EventArgs e) { if (ValidationUtility.FieldNotAllowNull(txtsupplierCode) == false) { lblNotify1.SetText(UI.hasnoinfomation, LabelNotify.EnumStatus.Failed); return; } if (m_Suplier == null) { return; } CoverObjectUtility.GetAutoBindingData(this, m_Suplier); if (m_Subsupplier.SupplierId <= 0) { lblNotify1.SetText(UI.failed, ToolBoxCS.LabelNotify.EnumStatus.Failed); return; } m_Subsupplier.SetModify(); try { SaveSupplier(m_Suplier); lblNotify1.SetText(UI.success, ToolBoxCS.LabelNotify.EnumStatus.Success); UpdateNode(m_Suplier); FormatTreeView(m_Suplier); InitializeForm(m_Suplier); } catch (Exception ex) { lblNotify1.SetText(UI.failed, ToolBoxCS.LabelNotify.EnumStatus.Failed); } }
private SubSupplier SaveAccount(Users user) { int supplierId = string.IsNullOrWhiteSpace(txtsupplierId.Text) == false?Convert.ToInt32(txtsupplierId.Text) : 0; if (supplierId <= 0) { lblNotify1.SetText(UI.deputyhasnocompany, LabelNotify.EnumStatus.Failed); return(null); } if (ValidationUtility.IsTextAllowed(user.UserName) == false) { lblNotify1.SetText(UI.usernotallowspace, LabelNotify.EnumStatus.Failed); return(null); } user.Sex = rdNam.Checked == true ? true : false; user.SetCreate(); user.UserGroupId = (int)UserTypeFlag.Customer; m_Subsupplier = new SubSupplier(); CoverObjectUtility.GetAutoBindingData(groupSubsupplier, m_Subsupplier); if (user.UserId <= 0) { m_Subsupplier.SubSupplierId = 0; } m_Subsupplier.SubSupplierName = user.FullName; m_Subsupplier.IsActive = cbActive.Checked; m_Subsupplier.Email = user.Email; m_Subsupplier.Phone = user.Phone; m_Subsupplier.Address = user.Address; m_Subsupplier.Sex = user.Sex; m_Subsupplier.UserId = user.UserId; m_Subsupplier.SupplierId = supplierId; IList <SubSupplier> lstExistsDeputy = gridControl1.DataSource as IList <SubSupplier>; SubSupplier main = lstExistsDeputy != null?lstExistsDeputy.Where(p => p.IsMain == true && p.SubSupplierId != m_Subsupplier.SubSupplierId).FirstOrDefault() : null; if (main == null) { m_Subsupplier.IsMain = true; } else { m_Subsupplier.IsMain = false; } using (IUnitOfWork uow = new UnitOfWork()) { if (user.UserId <= 0) { uow.UsersRepository.Add(user); m_Subsupplier.SetCreate(); m_Subsupplier.UserId = user.UserId; m_Subsupplier.SubSupplierId = 0; uow.SubSupplierRepository.Add(m_Subsupplier); } else { uow.UsersRepository.Update(user); m_Subsupplier.SetModify(); uow.SubSupplierRepository.Update(m_Subsupplier); } uow.Commit(); } return(m_Subsupplier); }