Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtCompanyName.Text))
                {
                    throw new Exception("Company Name can not be blank");
                }
                Status status;
                Choice choice;
                DI     di;

                CompanyMaster company = new CompanyMaster();
                company.CompanyCode             = txtCompanyCode.Text;
                company.CompanyId               = this.CompanyId;
                company.CompanyName             = txtCompanyName.Text;
                company.OrderPreferenceRating   = string.IsNullOrEmpty(txtOrderPrefRating.Text) ? 0 : Convert.ToInt32(txtOrderPrefRating.Text);
                company.BillingPreferenceRating = string.IsNullOrEmpty(txtBillingPrefRating.Text) ? 0 : Convert.ToInt32(txtBillingPrefRating.Text);
                Enum.TryParse <Status>(cbxStatus.SelectedValue.ToString(), out status);
                company.Status = status == Status.Active;
                Enum.TryParse <Choice>(cbxSSRequired.SelectedValue.ToString(), out choice);
                company.StockSummaryRequired = choice == Choice.Yes;

                Enum.TryParse <DI>(cbxDI.SelectedValue.ToString(), out di);
                company.IsDirect = di == DI.Direct;

                int result = CompanyId > 0 ? applicationFacade.UpdateCompany(company) : applicationFacade.AddCompany(company);

                //Close this form if operation is successful
                if (result > 0)
                {
                    this.CompanyId = result;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }