示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            saveButton.Click   += new EventHandler(saveButton_Click);
            cancelButton.Click += new EventHandler(cancelButton_Click);
            deleteButton.Click += new EventHandler(deleteButton_Click);
            deleteButton.Attributes["onclick"] = "javascript: return confirm('Are you sure want to delete this item?');";

            int salesPersonId = GetIdFromQueryString();

            if (!Page.IsPostBack)
            {
                if (salesPersonId > 0)
                {
                    createEditLabel.Text = "Edit";

                    SalesPersonTableAdapter salesPersonAdapter = new SalesPersonTableAdapter();

                    DollarSaverDB.SalesPersonDataTable salesPeople = salesPersonAdapter.GetSalesPerson(salesPersonId);

                    if (salesPeople.Count != 1)
                    {
                        Response.Redirect("~/admin/SalesPersonList.aspx");
                    }

                    DollarSaverDB.SalesPersonRow salesPerson = salesPeople[0];

                    if (salesPerson.StationId != StationId)
                    {
                        Response.Redirect("~/admin/SalesPersonList.aspx");
                    }


                    idHidden.Value      = salesPersonId.ToString();
                    firstNameBox.Text   = salesPerson.FirstName;
                    lastNameBox.Text    = salesPerson.LastName;
                    isActiveBox.Checked = salesPerson.IsActive;

                    if (!salesPerson.IsEmailAddressNull())
                    {
                        emailBox.Text = salesPerson.EmailAddress;
                    }

                    if (!salesPerson.IsMobilePhoneNull())
                    {
                        mobilePhoneBox.Text = salesPerson.MobilePhone;
                    }

                    if (!salesPerson.IsWorkPhoneNull())
                    {
                        workPhoneBox.Text = salesPerson.WorkPhone;
                    }
                }
                else
                {
                    deleteButton.Visible = false;
                    saveButton.Text      = "Create";
                    createEditLabel.Text = "Create";
                }
            }
        }
        void salesPeopleGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DollarSaverDB.SalesPersonRow salesPerson = (DollarSaverDB.SalesPersonRow)e.Row.DataItem;
                Label emailLabel = (Label)e.Row.FindControl("emailLabel");

                if (!salesPerson.IsEmailAddressNull())
                {
                    emailLabel.Text = salesPerson.EmailAddress;
                }
            }
        }