⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressmanager.aspx.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.WebSite.User.Shop
{
    using PowerEasy.Common;
    using PowerEasy.Components;
    using PowerEasy.Controls;
    using PowerEasy.Crm;
    using PowerEasy.Model.Crm;
    using PowerEasy.Web.UI;
    using PowerEasy.WebSite.Controls;
    using PowerEasy.WebSite.Controls.Shop;
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class AddressManager : DynamicPage
    {
        protected AddressPicker AddressPick;
        protected Button BtnCancel;
        protected Button BtnSave;
        protected ExtendedGridView EgvAddress;
        protected HtmlForm form1;
        protected HiddenField HdnAction;
        protected HiddenField HdnAddressID;
        protected HiddenField HdnUserName;
        protected Label LblMsg;
        protected ObjectDataSource OdsAddress;
        protected ScriptManager ScriptManager1;
        protected TextBox TxtConsigneeName;
        protected TextBox TxtMobile;
        protected TextBox TxtPhone;
        protected TextBox TxtZipCode;
        protected System.Web.UI.UpdatePanel UpdatePanel1;
        protected UserNavigation UserCenterNavigation;
        protected PowerEasy.Controls.RequiredFieldValidator ValrContacterName;
        protected PowerEasy.Controls.RequiredFieldValidator ValrZipCode;
        protected CustomValidator ValxPhone;
        protected MobileValidator VmblMobile;
        protected TelephoneValidator VtelPhone;
        protected ZipCodeValidator VzipZipCode;
        protected ExtendedSiteMapPath YourPosition;

        private void AddressPick_AddressChanged(object sender, EventArgs e)
        {
            this.TxtZipCode.Text = this.AddressPick.ZipCode;
        }

        protected void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Reset();
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            if (base.IsValid)
            {
                if (this.HdnAction.Value != "Modify")
                {
                    AddressInfo commonInfo = this.GetCommonInfo();
                    commonInfo.AddressId = Address.GetMaxId() + 1;
                    if (Address.Add(commonInfo))
                    {
                        this.Reset();
                        this.EgvAddress.DataBind();
                    }
                    else
                    {
                        this.LblMsg.Text = "添加收货人地址失败!";
                    }
                }
                else
                {
                    AddressInfo addressInfo = this.GetCommonInfo();
                    addressInfo.AddressId = DataConverter.CLng(this.HdnAddressID.Value);
                    if (Address.Update(addressInfo))
                    {
                        this.Reset();
                        this.EgvAddress.DataBind();
                    }
                    else
                    {
                        this.LblMsg.Text = "更新收货人地址失败!";
                    }
                }
            }
        }

        protected void EgvAddress_RowCommand(object sender, CommandEventArgs e)
        {
            int addressId = DataConverter.CLng(e.CommandArgument);
            string commandName = e.CommandName;
            if (commandName != null)
            {
                if (!(commandName == "Default"))
                {
                    if (!(commandName == "Modify"))
                    {
                        if ((commandName == "Del") && Address.Delete(addressId.ToString(), this.HdnUserName.Value))
                        {
                            if (addressId.ToString() == this.HdnAddressID.Value)
                            {
                                this.Reset();
                            }
                            this.EgvAddress.DataBind();
                        }
                        return;
                    }
                }
                else
                {
                    if (Address.SetDefault(addressId, this.HdnUserName.Value))
                    {
                        this.EgvAddress.DataBind();
                    }
                    return;
                }
                AddressInfo addressById = Address.GetAddressById(addressId, true);
                if (!addressById.IsNull)
                {
                    this.TxtConsigneeName.Text = addressById.ConsigneeName;
                    this.AddressPick.SelectRegion(addressById.Country, addressById.Province, addressById.City, addressById.Area);
                    this.AddressPick.Address = addressById.Address;
                    this.TxtZipCode.Text = addressById.ZipCode;
                    this.TxtPhone.Text = addressById.HomePhone;
                    this.TxtMobile.Text = addressById.Mobile;
                    this.HdnUserName.Value = addressById.UserName;
                    this.HdnAddressID.Value = addressById.AddressId.ToString();
                    this.HdnAction.Value = "Modify";
                    this.BtnSave.Text = "修 改";
                    this.BtnCancel.Visible = true;
                }
            }
        }

        protected void EgvAddress_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                AddressInfo dataItem = e.Row.DataItem as AddressInfo;
                if (!dataItem.IsNull)
                {
                    Label label = e.Row.FindControl("LblArea") as Label;
                    Label label2 = e.Row.FindControl("LblAddress") as Label;
                    if (label != null)
                    {
                        if (dataItem.Country == "中华人民共和国")
                        {
                            label.ToolTip = dataItem.Province + dataItem.City + dataItem.Area;
                        }
                        else
                        {
                            label.ToolTip = dataItem.Country + dataItem.Province + dataItem.City + dataItem.Area;
                        }
                        label.Text = StringHelper.SubString(label.ToolTip, 15, "...");
                    }
                    if (label2 != null)
                    {
                        label2.ToolTip = dataItem.Address;
                        label2.Text = StringHelper.SubString(dataItem.Address, 30, "...");
                    }
                }
            }
        }

        private AddressInfo GetCommonInfo()
        {
            AddressInfo info = new AddressInfo();
            info.UserName = this.HdnUserName.Value;
            info.ConsigneeName = this.TxtConsigneeName.Text.Trim();
            info.Country = this.AddressPick.Country;
            info.Province = this.AddressPick.Province;
            info.City = this.AddressPick.City;
            info.Area = this.AddressPick.Area;
            info.Address = this.AddressPick.Address;
            info.ZipCode = this.TxtZipCode.Text.Trim();
            info.HomePhone = this.TxtPhone.Text.Trim();
            info.Mobile = this.TxtMobile.Text.Trim();
            return info;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.AddressPick.AddressChanged += new EventHandler(this.AddressPick_AddressChanged);
            if (!base.IsPostBack)
            {
                this.HdnUserName.Value = PEContext.Current.User.UserName;
                this.HdnAction.Value = "Add";
                this.HdnAddressID.Value = "0";
            }
            if (string.IsNullOrEmpty(this.HdnUserName.Value))
            {
                this.LblMsg.Text = "请先进行会员登录!";
                this.BtnSave.Enabled = false;
            }
        }

        private void Reset()
        {
            this.HdnAddressID.Value = "0";
            this.HdnAction.Value = "Add";
            this.TxtConsigneeName.Text = "";
            this.TxtMobile.Text = "";
            this.TxtPhone.Text = "";
            this.TxtZipCode.Text = "";
            this.AddressPick.Reset();
            this.BtnSave.Text = "添 加";
            this.LblMsg.Text = "";
            this.BtnCancel.Visible = false;
        }

        protected void ValxPhone_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (string.IsNullOrEmpty(this.TxtPhone.Text) && string.IsNullOrEmpty(this.TxtMobile.Text))
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -