Example #1
0
        private void SetTXTSubsidiaryGroupCode(Data.CompanyDetail companyDetail)
        {
            try
            {
                var subsidiaryGroups = Business.GetCompanyDetailBusiness().GetByCodeTitleId(Common.Constants.CodeTitle.CompanyMainGroup).
                                       Where(r => r.CDIDIn.StartsWith(companyDetail.CDIDIn)).ToList();

                subsidiaryGroups.Select(r => r.CDName).Distinct().ToList().ForEach(r => txtSubsidiaryGroup.AddItem(new WPFAutoCompleteTextbox.AutoCompleteEntry(r, r)));
                subsidiaryGroups.Select(r => r.CDIDIn).Distinct().ToList().ForEach(r => txtSubsidiaryGroupCode.AddItem(new WPFAutoCompleteTextbox.AutoCompleteEntry(r, r)));
            }
            catch
            {
                throw;
            }
        }
Example #2
0
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var companyBusiness       = Business.GetCompanyBusiness();
                var companyDetailBusiness = Business.GetCompanyDetailBusiness();

                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted,
                    Timeout = new TimeSpan(2, 0, 0)
                }))
                {
                    var company = new Data.Company();

                    if (this.CompanyId.HasValue)
                    {
                        company = companyBusiness.GetById(this.CompanyId.Value);
                    }


                    var comapnyMainGroupName       = string.Empty;
                    var companySubsidiaryGroupName = string.Empty;

                    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;
                    comapnyMainGroupName       = txtMainGroup.Text;
                    companySubsidiaryGroupName = txtSubsidiaryGroup.Text;

                    company.CRegisterNo = txtLegalCRegistrationNo.Text.ToNullableInt();

                    companyBusiness.Save(company);
                    this.CompanyId = company.Id;

                    var companyMainGroup = companyDetailBusiness.GetByCompanyId(CompanyId, Constants.CodeTitle.CompanyMainGroup).FirstOrDefault();

                    if (companyMainGroup == null)
                    {
                        companyMainGroup = new Data.CompanyDetail()
                        {
                            CDName      = comapnyMainGroupName,
                            CDIDIn      = txtMainGroupCode.Text,
                            IDCodeTitle = Common.Constants.CodeTitle.CompanyMainGroup,
                            IDCompany   = CompanyId
                        };

                        Business.GetCompanyDetailBusiness().Save(companyMainGroup);
                    }

                    var companySubsidiaryGroup = companyDetailBusiness.GetByCompanyId(CompanyId, Constants.CodeTitle.CompanySubsidiaryGroup).FirstOrDefault();

                    if (companySubsidiaryGroup == null)
                    {
                        companySubsidiaryGroup = new Data.CompanyDetail()
                        {
                            CDName      = companySubsidiaryGroupName,
                            CDIDIn      = txtMainGroupCode.Text + txtSubsidiaryGroupCode.Text,
                            IDCodeTitle = Common.Constants.CodeTitle.CompanySubsidiaryGroup,
                            IDCompany   = this.CompanyId,
                        };
                        Business.GetCompanyDetailBusiness().Save(companySubsidiaryGroup);
                    }

                    var companyType = companyDetailBusiness.GetByCompanyId(companySubsidiaryGroup.Id, Constants.CodeTitle.CompanyType).FirstOrDefault();

                    if (companyType == null)
                    {
                        companyType = new Data.CompanyDetail()
                        {
                            CDName      = txtLastName.Text,
                            CDIDIn      = txtMainGroupCode.Text + txtSubsidiaryGroupCode.Text + txtCDIDIn.Text,
                            IDCodeTitle = Common.Constants.CodeTitle.CompanyType,
                            IDCompany   = this.CompanyId,
                        };
                        Business.GetCompanyDetailBusiness().Save(companyType);
                    }

                    scope.Complete();
                }

                this.Close();
            }
            catch (Exception ex)
            {
                AccountingKernel.Forms.Base.BaseWindow.ShowError(ex);
            }
        }