コード例 #1
0
    protected void gvwMaster_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "EditRow")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                RowID = id;
                mvwForm.SetActiveView(viwAddEdit);
                chkGenerateNewBarcodeCustomer.Visible = false;
                Contract contract = contractProvider.Get(id);
                chkGenerateNewBarcodeCustomer.Checked = false;
                lblBranch.Text              = contract.Branch.Name;
                lblContractNo.Text          = contract.ContractNo;
                calDate.SelectedDate        = contract.Date;
                calDateOfBirth.SelectedDate = contract.Customer.DateOfBirth.HasValue ? contract.Customer.DateOfBirth.Value : DateTime.Today;
                txtCustomerBarcode.Text     = contract.Customer.Barcode;
                txtCustomerBarcode.ReadOnly = true;
                lblCustomerName.Text        = String.Format("{0} {1}", contract.Customer.FirstName.Trim(), contract.Customer.LastName.Trim());
                ddlPackage.SelectedValue    = contract.PackageID.ToString();
                ddlPackage_SelectedIndexChanged(sender, null);
                txtHomePhone.Text             = contract.Customer.HomePhone;
                txtCellPhone.Text             = contract.Customer.CellPhone1;
                calEffectiveDate.SelectedDate = contract.EffectiveDate;

                ddlBillingType.SelectedValue = contract.BillingTypeID.ToString();

                ddlBillingCardType.SelectedValue = contract.Customer.CreditCardTypeID.ToString();
                ddlBillingBank.SelectedValue     = contract.Customer.BankID.ToString();
                txtBillingCardNo.Text            = contract.Customer.CardNo;
                txtBillingCardHolderName.Text    = contract.Customer.CardHolderName;
                txtBillingCardHolderID.Text      = contract.Customer.CardHolderID;

                if (contract.Customer.ExpiredDate.HasValue)
                {
                    ddlCardExpiredMonth.SelectedValue = contract.Customer.ExpiredDate.Value.Month.ToString();
                    ddlCardExpiredYear.SelectedValue  = contract.Customer.ExpiredDate.Value.Year.ToString();
                }

                txtMailingAddress.Text = contract.Customer.MailingAddress;
                txtMailingZipCode.Text = contract.Customer.MailingZipCode;
                txtAddress.Text        = contract.Customer.Address;
                txtZipCode.Text        = contract.Customer.ZipCode;

                if (ddlArea.Items.FindByValue(contract.Customer.AreaID.ToString()) != null)
                {
                    ddlArea.SelectedValue = contract.Customer.AreaID.ToString();
                }
                else
                {
                    ddlArea.SelectedIndex = 0;
                }


                if (contract.Customer.SchoolID.HasValue)
                {
                    txtSchoolID.Text   = contract.Customer.SchoolID.Value.ToString();
                    txtSchoolName.Text = contract.Customer.School.Name;
                }
                else
                {
                    txtSchoolID.Text   = String.Empty;
                    txtSchoolName.Text = String.Empty;
                }

                lblStatus.Text = contractProvider.DecodeStatus(Convert.ToChar(contract.Status));
                txtNotes.Text  = contract.Notes;

                lblActiveDate.Text = contract.ActiveDate.HasValue ? contract.ActiveDate.Value.ToString("dddd, dd MMMM yyyy") : "Not Active";

                btnVoid.Enabled = contract.Status == "A";

                if (employeeProvider.Get(User.Identity.Name).CanEditActiveContract)
                {
                    btnSave.Enabled = true;
                }
                else
                {
                    btnSave.Enabled = contract.Status == "P";
                }

                lblClosedDate.Text          = contract.ClosedDate.HasValue ? contract.ClosedDate.Value.ToString("dddd, dd MMMM yyyy") : "This contract has not been closed";
                lblVoidDate.Text            = contract.VoidDate.HasValue ? contract.VoidDate.Value.ToString("dddd, dd MMMM yyyy") : "This contract has not been void";
                calExpiredDate.Enabled      = true;
                calExpiredDate.SelectedDate = contract.ExpiredDate;

                ddlMonthlyDuesItem.SelectedValue = Convert.ToString(contract.BillingItemID);
                calNextDuesDate.SelectedDate     = contract.NextDuesDate.Value;
                txtDuesAmount.Text = contract.DuesAmount.ToString("###,##0.00");

                Person father = contract.Customer.Persons.SingleOrDefault(p => p.Connection == "F");
                chkFather.Checked = father != null;
                if (father != null)
                {
                    txtFatherName.Text                = father.Name;
                    txtFatherPhone.Text               = father.Phone1;
                    txtIDCardNoFather.Text            = father.IDCardNo;
                    txtFatherEmail.Text               = father.Email;
                    chkFatherBirthDateUnknown.Checked = !father.BirthDate.HasValue;
                    if (father.BirthDate.HasValue)
                    {
                        calBirthDateFather.SelectedValue = father.BirthDate.Value;
                    }
                }

                Person mother = contract.Customer.Persons.SingleOrDefault(p => p.Connection == "M");
                chkMother.Checked = mother != null;
                if (mother != null)
                {
                    txtMotherName.Text                = mother.Name;
                    txtMotherPhone.Text               = mother.Phone1;
                    txtIDCardNoMother.Text            = mother.IDCardNo;
                    txtMotherEmail.Text               = mother.Email;
                    chkMotherBirthDateUnknown.Checked = !mother.BirthDate.HasValue;
                    if (mother.BirthDate.HasValue)
                    {
                        calBirthDateMother.SelectedValue = mother.BirthDate.Value;
                    }
                }

                btnVoid.Enabled          = !contract.VoidDate.HasValue;
                btnCloseContract.Enabled = !contract.VoidDate.HasValue;

                btnVoid.Enabled          = !contract.ClosedDate.HasValue;
                btnCloseContract.Enabled = !contract.ClosedDate.HasValue;

                if (!String.IsNullOrEmpty(contract.ContractType))
                {
                    chkIsTransfer.Checked = contract.ContractType == "T";

                    if (contract.ContractType != "T")
                    {
                        ddlRenewalOrUpgrade.SelectedValue = contract.ContractType;
                    }
                }
                ddlRenewalOrUpgrade.Enabled = false;
                chkIsTransfer.Enabled       = false;

                ClientScript.RegisterStartupScript(this.GetType(), "_cust", "$(document).ready(function() { $('#customer').show(); });", true);
                hypLookUpCustomer.Visible = false;
            }
        }
        catch (Exception ex)
        {
            mvwForm.SetActiveView(viwRead);
            WebFormHelper.SetLabelTextWithCssClass(lblMessage, ex.Message, LabelStyleNames.ErrorMessage);
        }
    }