private bool Save()
    {
        PDT_StandardPriceBLL _bll;

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll = new PDT_StandardPriceBLL((int)ViewState["ID"]);
        }
        else
        {
            //新增
            _bll = new PDT_StandardPriceBLL();
        }

        pl_detail.GetData(_bll.Model);

        #region 判断必填项

        #endregion

        #region 判断是否与默认价表重复
        if (_bll.Model.IsDefault.ToUpper() == "Y")
        {
            int _priceid = PDT_StandardPriceBLL.GetDefaultPrice((int)Session["OwnerClient"]);
            if (_priceid != _bll.Model.ID)
            {
                MessageBox.Show(this, "对不起,不能重复新增默认价表,新增的价表必须限制区域或渠道!");
                return(false);
            }
        }

        #endregion

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
        }
        else
        {
            //新增
            _bll.Model.Supplier    = (int)Session["OwnerClient"];
            _bll.Model.ApproveFlag = 2;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            ViewState["ID"]        = _bll.Add();
        }

        #region 保存修改明细
        foreach (GridViewRow row in gv_List.Rows)
        {
            PDT_StandardPrice_Detail item = new PDT_StandardPrice_Detail();
            item.PriceID = _bll.Model.ID;
            item.ID      = int.Parse(gv_List.DataKeys[row.RowIndex]["ID"].ToString());
            item.Product = int.Parse(gv_List.DataKeys[row.RowIndex]["Product"].ToString());

            PDT_Product p = new PDT_ProductBLL(item.Product).Model;

            if (row.FindControl("tbx_Price") != null)
            {
                decimal d = 0;
                if (decimal.TryParse(((TextBox)row.FindControl("tbx_Price")).Text, out d))
                {
                    item.Price = d;
                }

                PDT_ProductBLL productbll = new PDT_ProductBLL(item.Product);
                item.Price = item.Price / productbll.Model.ConvertFactor;

                PDT_ProductExtInfo extinfo = productbll.GetProductExtInfo((int)Session["OwnerClient"]);
                if (extinfo != null)
                {
                    if (extinfo.MinSalesPrice > 0 && item.Price < extinfo.MinSalesPrice)
                    {
                        MessageBox.Show(this, "对不起,您发布的价格不能小于建议零售价!");
                        return(false);
                    }
                    else if (extinfo.MaxSalesPrice > 0 && item.Price > extinfo.MaxSalesPrice)
                    {
                        MessageBox.Show(this, "对不起,您发布的价格不能过高于建议零售价!");
                        return(false);
                    }
                }
            }


            if (row.FindControl("tbx_Remark") != null)
            {
                item.Remark = ((TextBox)row.FindControl("tbx_Remark")).Text;
            }

            _bll.UpdateDetail(item);
        }

        #endregion

        return(true);
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // 在此处放置用户代码以初始化页面
        if (!Page.IsPostBack)
        {
            int ClientID = Request.QueryString["ClientID"] != null && int.TryParse(Request.QueryString["ClientID"].ToString(), out ClientID) ? ClientID : 0;
            ViewState["ClientID"] = ClientID;

            BindDropDown();

            if ((int)ViewState["ClientID"] > 0)
            {
                BindData();
            }
            else
            {
                #region 新增门店时的初始值
                CM_Client tdp = new CM_ClientBLL((int)Session["OwnerClient"]).Model;
                if (tdp == null)
                {
                    Response.Redirect("RetailerList.aspx");
                    return;
                }

                CM_Client m = new CM_Client();
                m.OfficialCity = tdp.OfficialCity;
                m.PostCode     = tdp.PostCode;

                CM_ClientSupplierInfo supplierinfo = new CM_ClientSupplierInfo();
                supplierinfo.State         = 1;
                supplierinfo.BeginDate     = DateTime.Today;
                supplierinfo.StandardPrice = PDT_StandardPriceBLL.GetDefaultPrice(tdp.ID);

                pl_detail.BindData(m);
                pl_detail.BindData(supplierinfo);

                bt_Map.Visible        = false;
                bt_AddLinkMan.Visible = false;
                tr_LinkMan.Visible    = false;

                #region 新增客户时,首要联系人字段不可编辑
                DropDownList ddl_ChiefLinkMan = (DropDownList)pl_detail.FindControl("CM_Client_ChiefLinkMan");
                try
                {
                    if (ddl_ChiefLinkMan != null)
                    {
                        ddl_ChiefLinkMan.Items.Clear();
                        ddl_ChiefLinkMan.Enabled = false;
                    }
                }
                catch { }
                #endregion

                #endregion
            }
        }

        #region 给活跃标志加事件
        //DropDownList ddl_ActiveFlag_1 = (DropDownList)pl_detail.FindControl("CM_Client_ActiveFlag");
        //ddl_ActiveFlag_1.AutoPostBack = true;
        //ddl_ActiveFlag_1.SelectedIndexChanged += new EventHandler(ddl_ActiveFlag_SelectedIndexChanged);
        #endregion


        #region 注册弹出窗口脚本
        string script = "function Pop_MapShow(id){\r\n";
        script += "var tempid = Math.random() * 10000; \r\n window.showModalDialog('" + Page.ResolveClientUrl("~/SubModule/CM/Map/ClientInMap.aspx") +
                  "?ClientID=' + id + '&tempid='+tempid, window, 'dialogWidth:800px;DialogHeight=550px;status:yes;resizable=yes');}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopShow", script, true);
        #endregion
    }