コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var validationResult = ValidateForm();

            if (!String.IsNullOrEmpty(validationResult))
            {
                Controller.HandleError(validationResult, "Validation Error");
                return;
            }
            else
            {
                if (_InsuranceBrokerId > 0)
                {
                    var InsuranceBroker = _DataContext.InsuranceBrokerSet.Single(a => a.id == _InsuranceBrokerId);
                    InsuranceBroker.CompanyName         = txtCompanyName.Text.Trim();
                    InsuranceBroker.CompanyRegistration = txtCompanyReg.Text.Trim();
                    InsuranceBroker.VATNumber           = txtVatNumber.Text.Trim();
                    InsuranceBroker.ContactPerson       = txtContactPerson.Text.Trim();
                    InsuranceBroker.EmailAddress        = txtEmailAddress.Text.Trim();
                    InsuranceBroker.ContactNumber       = txtContactNumber.Text.Trim();
                    _DataContext.SaveChanges();
                }
                else
                {
                    var InsuranceBroker = _DataContext.InsuranceBrokerSet.FirstOrDefault(a => a.CompanyName == txtCompanyName.Text.Trim());

                    if (InsuranceBroker != null)
                    {
                        Controller.HandleError("InsuranceBroker with the same name already exists.", "Save Error");
                        return;
                    }
                    else
                    {
                        var InsuranceBrokerItem = new Data.InsuranceData.InsuranceBroker()
                        {
                            CompanyName         = txtCompanyName.Text.Trim(),
                            CompanyRegistration = txtCompanyReg.Text.Trim(),
                            VATNumber           = txtVatNumber.Text.Trim(),
                            ContactPerson       = txtContactPerson.Text.Trim(),
                            EmailAddress        = txtEmailAddress.Text.Trim(),
                            ContactNumber       = txtContactNumber.Text.Trim(),
                        };

                        _DataContext.InsuranceBrokerSet.Add(InsuranceBrokerItem);
                        _DataContext.SaveChanges();
                        _InsuranceBrokerId = InsuranceBrokerItem.id;
                    }
                }
                if (_closeOnSave)
                {
                    RaiseSaveSuccess();
                }
                else
                {
                    PopulateForm();
                }
            }
        }
コード例 #2
0
 private void LookupControl_InsuranceBrokerSelectedEvent(object sender, InsuranceBrokerSelectEventArgs e)
 {
     SelectedInsuranceBroker = e.SelectedItem;
     if (e.InsuranceBrokerSelected)
     {
         DialogResult = DialogResult.OK;
     }
     else
     {
         DialogResult = DialogResult.Cancel;
     }
     Close();
 }