Exemplo n.º 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        this.Validate("AddEdit");
        if (this.IsValid)
        {
            int documentTypeID = Convert.ToInt32(ddlDocumentType.SelectedValue);
            try
            {
                if (documentProvider.CanChangeStatus(txtCustomerCode.Text))
                {
                    switch (RowID)
                    {
                    case 0:
                        documentProvider.Add(
                            Convert.ToInt32(ddlFindBranch.SelectedValue),
                            DateTime.Today,
                            calStartDate.SelectedDate,
                            chkEndDate.Checked ? calEndDate.SelectedDate : (DateTime?)null,
                            txtCustomerCode.Text,
                            documentTypeID,
                            txtNotes.Text);
                        break;

                    default:
                        documentProvider.Update(
                            RowID,
                            DateTime.Today,
                            calStartDate.SelectedDate,
                            chkEndDate.Checked ? calEndDate.SelectedDate : (DateTime?)null,
                            txtCustomerCode.Text,
                            documentTypeID,
                            txtNotes.Text);
                        break;
                    }

                    mvwForm.ActiveViewIndex = 0;
                    gvwMaster.DataBind();
                }
                else
                {
                    WebFormHelper.SetLabelTextWithCssClass(
                        lblStatus,
                        "Cannot change customer status for any unpaid contract",
                        LabelStyleNames.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                WebFormHelper.SetLabelTextWithCssClass(
                    lblStatus,
                    ex.Message,
                    LabelStyleNames.ErrorMessage);
            }
        }
    }