protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            #region 获取页面参数
            ViewState["TradeClient"] = Request.QueryString["TradeClient"] != null ? int.Parse(Request.QueryString["TradeClient"]) : 0;
            #endregion

            BindDropDown();

            if ((int)ViewState["TradeClient"] != 0)
            {
                CM_Client c = new CM_ClientBLL((int)ViewState["TradeClient"]).Model;
                if (c != null && ddl_Supplier.Items.FindByValue(c.ToString()) != null)
                {
                    ddl_Supplier.SelectedValue = c.ID.ToString();
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            #region 获取页面参数
            ViewState["TradeClient"] = Request.QueryString["TradeClient"] != null?int.Parse(Request.QueryString["TradeClient"]) : 0;

            #endregion

            BindDropDown();

            if ((int)ViewState["TradeClient"] != 0)
            {
                CM_Client c = new CM_ClientBLL((int)ViewState["TradeClient"]).Model;
                if (c != null && ddl_Supplier.Items.FindByValue(c.ToString()) != null)
                {
                    ddl_Supplier.SelectedValue = c.ID.ToString();
                }
            }
        }
    }
    private void BindContractClassify(int classify)
    {
        switch (classify)
        {
            case 1:     //陈列合同
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_03", false);
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_04", false);
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_05", false);
                bt_FeeApply.Visible = false;
                break;
            case 2:     //返利合同
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_02", false);
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_04", false);
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_05", false);
                bt_FeeApply.Visible = false;
                tr_AddDetail.Visible = false;
                tr_ContractDetail.Visible = false;

                #region 获取适用的返利标准
                if (ddl_RebateLevel != null && (int)ViewState["ClientID"] > 0)
                {
                    ddl_RebateLevel.Items.Clear();
                    int city = new CM_ClientBLL((int)ViewState["ClientID"]).Model.OrganizeCity;

                    IList<CM_RebateRule> rules = CM_RebateRuleBLL.GetModelList
                        ("ApproveFlag = 1 AND ID IN (SELECT RebateRule FROM CM_RebateRule_ApplyCity WHERE OrganizeCity IN ("
                        + new Addr_OrganizeCityBLL(city).GetAllSuperNodeIDs() + "," + city.ToString() + "))");
                    foreach (CM_RebateRule item in rules)
                    {
                        ddl_RebateLevel.Items.Add(new ListItem(item.Name, item.ID.ToString()));
                    }
                    ddl_RebateLevel.Items.Insert(0, new ListItem("请选择...", "0"));
                }
                #endregion

                #region 设置默认值
                if ((int)ViewState["ContractID"] == 0 && (int)ViewState["ClientID"] > 0)
                {
                    CM_Client client = new CM_ClientBLL((int)ViewState["ClientID"]).Model;
                    if (client != null)
                    {
                        TextBox tbx_BankName = (TextBox)pl_detail.FindControl("CM_Contract_BankName");
                        if (tbx_BankName != null) tbx_BankName.Text = client["BankName"];

                        TextBox tbx_BankAccountNo = (TextBox)pl_detail.FindControl("CM_Contract_BankAccountNo");
                        if (tbx_BankAccountNo != null) tbx_BankAccountNo.Text = client["BankAccountNo"];

                        TextBox tbx_AccountName = (TextBox)pl_detail.FindControl("CM_Contract_AccountName");
                        if (tbx_AccountName != null) tbx_AccountName.Text = client["AccountName"];
                    }
                }
                #endregion

                break;
            case 3:     //导购费用协议
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_02", false);
                pl_detail.SetPanelVisible("Panel_RT_RetailDetail_Contract_03", false);
                bt_FeeApply.Visible = false;
                #region 设置默认值
                if ((int)ViewState["ContractID"] == 0)
                {
                    TextBox tbx_PromotorCostRate = (TextBox)pl_detail.FindControl("CM_Contract_PromotorCostRate");
                    if (tbx_PromotorCostRate != null) tbx_PromotorCostRate.Text = "0";

                    TextBox tbx_PromotorAwardRate = (TextBox)pl_detail.FindControl("CM_Contract_PromotorAwardRate");
                    if (tbx_PromotorAwardRate != null) tbx_PromotorAwardRate.Text = "100";

                    //TextBox tbx_PromotorCount =pl_detail.FindControl("CM_Contract_PromotorCount")==null?null:(TextBox)pl_detail.FindControl("CM_Contract_PromotorCount");
                    //IList<PM_PromotorInRetailer> pms = PM_PromotorInRetailerBLL.GetModelList("Client=" + ViewState["ClientID"] + "AND EXISTS (SELECT 1 FROM MCS_Promotor.dbo.PM_Promotor " +
                    //                                                           " WHERE Dimission=1 AND ApproveFlag=1 AND PM_Promotor.ID=PM_PromotorInRetailer.Promotor)");
                    //if (tbx_PromotorCount != null && pms.Count > 0)
                    //{
                    //    tbx_PromotorCount.Text = pms.Count.ToString();
                    //}

                    DropDownList ddl_PromotorCostPayMode = (DropDownList)pl_detail.FindControl("CM_Contract_PromotorCostPayMode");
                    if (ddl_PromotorCostPayMode != null)
                    {
                        //月付的管理费,不需上协议
                        if (ddl_PromotorCostPayMode.Items.FindByValue("1") != null)
                            ddl_PromotorCostPayMode.Items.FindByValue("1").Enabled = false;

                        if (ddl_PromotorCostPayMode.Items.FindByValue("20") != null)
                            ddl_PromotorCostPayMode.Items.FindByValue("20").Enabled = false;
                    }

                }
                #endregion
                lt_RebateRemark.Text = "<div style=\"color:red;margin-left:5px;\"><b>导购协议填报说明:</b><br/>方式一:门店仅需做预付管理费申请,请填写模块一,需填写导购员数量,管理费(每人每月每店)及预付款方式,模块二内容无需填写。<br/>方式二:门店仅需申请特殊提成分摊比例,请填写模块二,需填写经销商承担比例(%)。(注:模块一中的管理费(每人每月每店)填写数字0,预付款方式可按备选内容进行选填)<br/>方式三:门店既需预付管理费,又需要申请特殊特提成分摊比例,请分别填写模块一、二,所有必填字段均需按实际填写。</div><br>";
                tr_AddDetail.Visible = false;
                tr_ContractDetail.Visible = false;
                break;
            default:
                break;
        }
    }