private void commitchange(Data.Com company) { company.CPriceType = cmbCPriceType.SelectedValue.ToGUID(); company.CPersonType = cmbCPersonType.SelectedValue.ToGUID(); company.CType = cmbCType.SelectedValue.ToGUID(); company.CName = txtLastName.Text; company.CNameEn = txtCNameEn.Text; company.CNationalCode = txtNationalCode.Text; company.CPostalCode = txtZipCode.Text.ToString(); company.CAddress = txtAddress.Text; company.CTell = txtPhone.Text; company.CMobile = txtCellPhone.Text; company.CRegisterNo = txtLegalCRegistrationNo.Text.ToNullableInt(); Data.CompanyStructureDefine _companyDefine = Business.GetCompanyStructureDefineBusiness().GetStructure(Constants.CodeTitle.CompanyType, txtLastName.Text, CompanyParentID, CompanyCode); string s = Business.GetCompanyStructureDefineBusiness().GetMaxCode(CompanyCode).Select(r => r.Code).FirstOrDefault(); _companyDefine.Type = Constants.CodeTitle.CompanyType; using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted, Timeout = new TimeSpan(2, 0, 0) })) { Business.GetCompanyStructureDefineBusiness().SaveByID(_companyDefine); company.CompanyStructureDefineId = _companyDefine.ID; Business.GetComBusiness().Save(company); scope.Complete(); } this.Close(); }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { if (FormIsValid()) { if (txtPrimeryGroupCode.IsEnabled) { //ParentID = Business.GetCompanyStructureDefineBusiness().GetRecord(txtPrimeryGroupCode.Text, Constants.CodeTitle.CompanyMainGroup).ID; var s = Business.GetCompanyStructureDefineBusiness().GetRecord(txtPrimeryGroupCode.Text, Constants.CodeTitle.CompanyMainGroup); if (s == null) { string Name = txtPrimeryGroupName.Text; Data.CompanyStructureDefine _entityPrimery = Business.GetCompanyStructureDefineBusiness().GetStructure(Constants.CodeTitle.CompanyMainGroup, Name, null, txtPrimeryGroupCode.Text); Business.GetCompanyStructureDefineBusiness().SaveByID(_entityPrimery); ParentID = _entity.ID; } else { ParentID = s.ID; } } if (txtSecenderyGroupCode.Text.IsNullOrEmpty() == false) { if (_entity.ID == Guid.Empty) { string Name = string.Format("{0} {1}", txtPrimeryGroupName.Text, txtSecenderyGroupName.Text); string Code = string.Format("{0}{1}", txtPrimeryGroupCode.Text, txtSecenderyGroupCode.Text); _entity = Business.GetCompanyStructureDefineBusiness(). GetStructure(Constants.CodeTitle.CompanySubsidiaryGroup, Name, ParentID, Code); } else { _EditedItem.Code = txtSecenderyGroupCode.Text; if (txtSecenderyGroupName.Text.IsNullOrEmpty() == false) { _EditedItem.Name = txtSecenderyGroupName.Text; } _entity = _EditedItem; } Business.GetCompanyStructureDefineBusiness().SaveByID(_entity); } this.Close(); } }
public void Insert(Data.CompanyStructureDefine _companyStructureDefine) { try { if (_companyStructureDefine.ID == Guid.Empty) { _companyStructureDefine.ID = Guid.NewGuid(); } this.Table.Add(_companyStructureDefine); this.SubmitChanges(); } catch { throw; } }
public Data.CompanyStructureDefine GetStructure(Guid Type, string Name, Guid?ParentID, string Code) { Data.CompanyStructureDefine _entity = new Data.CompanyStructureDefine(); _entity.ID = Guid.NewGuid(); _entity.Type = Type; _entity.Name = Name; _entity.Parent_ID = ParentID; _entity.Code = GetCode(_entity.Parent_ID, _entity.Type, Code); _entity.LastEdit = DateTime.Now; _entity.Uniq_Path = GetUniqPath(_entity); return(_entity); }
public void SaveByID(Data.CompanyStructureDefine _companyStructureDefine) { try { Guid i = Business.GetCompanyStructureDefineBusiness().GetAll().Where(r => r.ID == _companyStructureDefine.ID).Select(r => r.ID).FirstOrDefault(); if (i == Guid.Empty) { this.Insert(_companyStructureDefine); } else { this.SubmitChanges(); } } catch { throw; } }
private string GetUniqPath(Data.CompanyStructureDefine entity) { if (entity.Type == Constants.CodeTitle.CompanyMainGroup) { return(string.Format("#{0}", entity.ID)); } else if (entity.Type == Constants.CodeTitle.CompanySubsidiaryGroup) { return(string.Format("#{0}#{1}", GetParentID(entity).ID, entity.ID)); } else if (entity.Type == Constants.CodeTitle.CompanyType) { return(string.Format("#{0}#{1}#{2}", GetParentID(GetParentID(entity)).ID, GetParentID(entity).ID, entity.ID)); } else { return("error"); } }
private Data.CompanyStructureDefine GetParentID(Data.CompanyStructureDefine entity) { Data.CompanyStructureDefine result = null; try { if (entity.Type == Constants.CodeTitle.CompanySubsidiaryGroup) { result = this.GetAll().Where(r => r.Code.StartsWith(entity.Code.Substring(0, MainLen)) && r.Type == Constants.CodeTitle.CompanyMainGroup).FirstOrDefault(); } if (entity.Type == Constants.CodeTitle.CompanyType) { result = this.GetAll().Where(r => r.Code.StartsWith(entity.Code.Substring(0, SubsidiaryLen)) && r.Type == Constants.CodeTitle.CompanySubsidiaryGroup).FirstOrDefault(); } return(result); } catch { throw; } }
public frmCoRegister(Data.CompanyStructureDefine EditedItem) { InitializeComponent(); Auto(); if (EditedItem != null) { this._EditedItem = EditedItem; txtPrimeryGroupCode.IsEnabled = false; txtPrimeryGroupName.IsEnabled = false; if (Business.GetCompanyStructureDefineBusiness().HaveChildren(EditedItem.ID) == false) { txtSecenderyGroupCode.Text = _EditedItem.Code; } else { txtSecenderyGroupCode.IsEnabled = false; } txtSecenderyGroupName.Text = _EditedItem.Name; _entity = _EditedItem; } }