Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(tbxPersonalLedgerName.Text))
                {
                    errorProviderPerLedger.SetError(tbxPersonalLedgerName, Constants.Messages.RequiredField);
                    tbxPersonalLedgerName.SelectAll();
                    tbxPersonalLedgerName.Focus();
                    return;
                }

                if (String.IsNullOrWhiteSpace(tbxEmailAddress.Text) || !ExtensionMethods.IsValidEmail(tbxEmailAddress.Text))
                {
                    errorProviderPerLedger.SetError(tbxEmailAddress, Constants.Messages.InValidEmail);
                    tbxPersonalLedgerName.SelectAll();
                    tbxPersonalLedgerName.Focus();
                    return;
                }

                Status status;
                Enum.TryParse <Status>(cbxStatus.SelectedValue.ToString(), out status);

                PersonalLedgerMaster personalLedgerMaster = new PersonalLedgerMaster()
                {
                    PersonalLedgerName      = tbxPersonalLedgerName.Text,
                    PersonalLedgerShortName = tbxPersonalLedgerShortName.Text,
                    Address       = tbxAddress.Text,
                    ContactPerson = tbxContactPerson.Text,
                    Mobile        = tbxMobile.Text,
                    Pager         = tbxPager.Text,
                    Fax           = tbxFax.Text,
                    OfficePhone   = tbxOfficePhone.Text,
                    ResidentPhone = tbxResidentPhone.Text,
                    EmailAddress  = tbxEmailAddress.Text,
                    Status        = status == Status.Active
                };

                int actionResult = 0;
                // if form is in Edit mode then udate item , else add item
                if (_personLedgerid == 0)
                {
                    actionResult = applicationFacade.AddPersonalLedger(personalLedgerMaster);
                }
                else
                {
                    personalLedgerMaster.PersonalLedgerId = _personLedgerid;
                    actionResult = applicationFacade.UpdatePersonalLedger(personalLedgerMaster);
                }

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