protected void Page_Load(object sender, EventArgs e)
    {
        ddl_BasePayMode        = (DropDownList)UC_DetailView1.FindControl("PM_PromotorSalary_BasePayMode");
        ddl_BasePaySubsidyMode = (DropDownList)UC_DetailView1.FindControl("PM_PromotorSalary_BasePaySubsidyMode");
        ddl_MinimumWageMode    = (DropDownList)UC_DetailView1.FindControl("PM_PromotorSalary_MinimumWageMode");
        ddl_InsuranceMode      = (DropDownList)UC_DetailView1.FindControl("PM_PromotorSalary_InsuranceMode");
        ddl_SeniorityPayMode   = (DropDownList)UC_DetailView1.FindControl("PM_PromotorSalary_SeniorityPayMode");
        ddl_SalesType          = (DropDownList)UC_DetailView1.FindControl("PM_PromotorSalary_SalesType");

        ddl_BankType = DV_pm.FindControl("PM_Promotor_BankType") == null ? null : (DropDownList)UC_DetailView1.FindControl("PM_Promotor_BankType");
        txt_BankName = DV_pm.FindControl("PM_Promotor_BankName") == null ? null : (TextBox)UC_DetailView1.FindControl("PM_Promotor_BankName");


        if (ddl_BankType != null)
        {
            ddl_BankType.AutoPostBack          = true;
            ddl_BankType.SelectedIndexChanged += new EventHandler(ddl_BankType_SelectedIndexChanged);
        }

        ddl_BasePaySubsidyMode.AutoPostBack          = true;
        ddl_BasePaySubsidyMode.SelectedIndexChanged += new EventHandler(ddl_BasePaySubsidyMode_SelectedIndexChanged);

        ddl_MinimumWageMode.AutoPostBack          = true;
        ddl_MinimumWageMode.SelectedIndexChanged += new EventHandler(ddl_MinimumWageMode_SelectedIndexChanged);

        ddl_InsuranceMode.AutoPostBack          = true;
        ddl_InsuranceMode.SelectedIndexChanged += new EventHandler(ddl_InsuranceMode_SelectedIndexChanged);


        txt_AvgSales       = (TextBox)UC_DetailView1.FindControl("PM_PromotorSalary_AvgSales");
        txt_BaseFeeRate    = (TextBox)UC_DetailView1.FindControl("PM_PromotorSalary_BaseFeeRate");
        txt_FloatingTarget = (TextBox)UC_DetailView1.FindControl("PM_PromotorSalary_FloatingTarget");



        Page.ClientScript.RegisterClientScriptInclude("meizzDate", Page.ResolveClientUrl("~/App_Themes/basic/meizzDate.js"));
        if (!IsPostBack)
        {
            txt_AvgSales.Enabled           = false;
            txt_BaseFeeRate.Enabled        = false;
            txt_FloatingTarget.Enabled     = false;
            ddl_SalesType.Enabled          = false;
            ddl_BasePaySubsidyMode.Enabled = false;
            ddl_MinimumWageMode.Enabled    = false;

            txt_FloatingTarget.Text = "0";
            txt_AvgSales.Text       = "0";
            txt_BaseFeeRate.Text    = "0";

            ViewState["PromotorID"] = Request.QueryString["PromotorID"] == null ? 0 : int.Parse(Request.QueryString["PromotorID"]);

            //新增薪资标准
            #region 判断当前导购是否有所在工作的门店
            if (PM_PromotorInRetailerBLL.GetModelList("Promotor=" + ViewState["PromotorID"].ToString()).Count == 0)
            {
                MessageBox.ShowAndRedirect(this, "请设置该导购员所在的门店!", "PM_PromotorDetail.aspx?PromotorID=" + ViewState["PromotorID"].ToString());
                return;
            }
            #endregion

            PM_Promotor m = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
            if (m != null)
            {
                DV_pm.BindData(m);
            }
            else
            {
                MessageBox.ShowAndClose(this, "导购员信息读取失败!");
                return;
            }



            DropDownList ddl_Classfiy      = DV_pm.FindControl("PM_Promotor_Classfiy") as DropDownList;
            TextBox      tbx_BeginWorkDate = DV_pm.FindControl("PM_Promotor_BeginWorkDate") as TextBox;
            int          classfiy          = 0;
            int.TryParse(m["Classfiy"], out classfiy);
            if (classfiy == 0)
            {
                MessageBox.ShowAndClose(this, "导购员类别读取失败!");
                return;
            }
            if (m["State"] == "2")
            {
                MessageBox.ShowAndClose(this, "导购有流程正在审批,无法再发起流程!");
                return;
            }
            else if (classfiy == 1 || classfiy == 2)
            {
                ddl_Classfiy.Items.FindByValue("1").Enabled = false;
                ddl_Classfiy.Items.FindByValue("2").Enabled = false;
            }
            else
            {
                ddl_Classfiy.Items.FindByValue("6").Enabled = false;
            }
            tbx_BeginWorkDate.Text = "";
            BindData(classfiy);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        PM_PromotorBLL _promotor = new PM_PromotorBLL((int)ViewState["PromotorID"]);

        if (_promotor.Model["State"] == "2")
        {
            MessageBox.Show(this, "该导购有未完成的流程,请待流程完成后,再做调整!");
            return;
        }
        DropDownList ddl_Classfiy      = DV_pm.FindControl("PM_Promotor_Classfiy") as DropDownList;
        TextBox      tbx_BeginWorkDate = DV_pm.FindControl("PM_Promotor_BeginWorkDate") as TextBox;
        TextBox      tbx_Remark        = DV_pm.FindControl("PM_Promotor_Education") as TextBox;
        TextBox      tbx_AccountNO     = (TextBox)DV_pm.FindControl("PM_Promotor_AccountCode");

        if (ddl_BankType.SelectedValue == "0" || txt_BankName.Text.Trim() == "")
        {
            MessageBox.Show(this, "请选择开户行!");
            return;
        }

        if (ddl_Classfiy.SelectedValue != "0" && tbx_BeginWorkDate.Text.Trim() != "")
        {
            int budget = PM_PromotorNumberLimitBLL.CheckOverBudget(_promotor.Model.OrganizeCity, int.Parse(_promotor.Model["Classfiy"]));
            NameValueCollection dataobjects = new NameValueCollection();
            dataobjects.Add("ID", ViewState["PromotorID"].ToString());
            dataobjects.Add("OrganizeCity", _promotor.Model.OrganizeCity.ToString());
            dataobjects.Add("BeginWorkDate", tbx_BeginWorkDate.Text.ToString());
            dataobjects.Add("Classify", ddl_Classfiy.SelectedValue);
            dataobjects.Add("Remark", tbx_Remark.Text);
            dataobjects.Add("PM_Name", _promotor.Model.Name.ToString());
            dataobjects.Add("BankType", ddl_BankType.SelectedValue);
            dataobjects.Add("BankName", txt_BankName.Text.Trim());
            dataobjects.Add("AccountNO", tbx_AccountNO.Text.Trim());
            PM_PromotorSalaryBLL bll = new PM_PromotorSalaryBLL();
            UC_DetailView1.GetData(bll.Model);
            #region 数据录入判断
            if (bll.Model.BasePayMode == 0)
            {
                MessageBox.Show(this, "请选择正确的底薪模式!");
                return;
            }
            if (bll.Model.BasePayMode == 1)
            {
                if (bll.Model.SeniorityPayMode == 0)
                {
                    MessageBox.Show(this, "当底薪模式为固定底薪时,必须选择工龄工资模式!");
                    return;
                }
                if (bll.Model.InsuranceMode == 0)
                {
                    MessageBox.Show(this, "当底薪模式为固定底薪时,必须选择社保!");
                    return;
                }
            }
            if (bll.Model.BasePaySubsidyMode != 0 && bll.Model.BasePaySubsidy == 0)
            {
                MessageBox.Show(this, "当选择了底薪补贴类型时,请设定补贴金额!");
                return;
            }

            if (bll.Model.BasePaySubsidyMode != 0 && bll.Model.BasePaySubsidyBeginDate.Year == 1900)
            {
                MessageBox.Show(this, "当选择了底薪补贴类型时,请设定底薪补贴起始日期!");
                return;
            }
            if (bll.Model.BasePaySubsidyMode == 1 && bll.Model.BasePaySubsidyEndDate.Year == 1900)
            {
                MessageBox.Show(this, "当选择了底薪补贴类型为临时补贴时,请设定底薪补贴截止日期!");
                return;
            }

            if (bll.Model.MinimumWageMode == 2 && bll.Model.MinimumWage == 0)
            {
                MessageBox.Show(this, "当选择了特殊保底时,请设定保底金额!");
                return;
            }

            if (bll.Model.MinimumWageMode != 0 && bll.Model.MinimumWageBeginDate.Year == 1900)
            {
                MessageBox.Show(this, "当选择了薪资保底时,请设定保底的起始日期!");
                return;
            }
            if (bll.Model.MinimumWageMode != 0 && bll.Model.MinimumWageEndDate.Year == 1900)
            {
                MessageBox.Show(this, "当选择了薪资保底时,请设定保底的截止日期!");
                return;
            }
            if (bll.Model.InsuranceMode == 0 && bll.Model.BasePayMode != 3)
            {
                MessageBox.Show(this, "非兼职,请选择正确的社保模式!");
                return;
            }
            if (bll.Model.InsuranceMode == 1 && bll.Model.InsuranceSubsidy <= 0)
            {
                MessageBox.Show(this, "请正确输入保险补贴金额!");
                return;
            }
            if (bll.Model.BasePayMode == 4 && bll.Model["FloatingTarget"] == "0")
            {
                MessageBox.Show(this, "当底薪模式为浮动底薪(非华南)时,请设定浮动底薪上限任务量!");
                return;
            }
            if (bll.Model.BasePayMode == 4 && bll.Model["AvgSales"] == "0")
            {
                MessageBox.Show(this, "当底薪模式为浮动底薪(非华南)时,请设定前两月平均销量!");
                return;
            }
            if (bll.Model.BasePayMode == 5 && bll.Model["SalesType"] == "0")
            {
                MessageBox.Show(this, "当底薪模式为浮动底薪(华南)时,请设定实销类别!");
                return;
            }
            if (bll.Model.BasePayMode == 5 && bll.Model["BaseFeeRate"] == "0")
            {
                MessageBox.Show(this, "当底薪模式为浮动底薪(华南)时,请设定底薪费率!");
                return;
            }
            #endregion
            int TaskID = EWF_TaskBLL.NewTask("PMClassify_Change", (int)Session["UserID"], "导购员类型变更流程,姓名:" + _promotor.Model.Name, "~/SubModule/PM/PM_PromotorDetail.aspx?PromotorID=" + ViewState["PromotorID"].ToString(), dataobjects);
            if (TaskID > 0)
            {
                bll.Model.Promotor    = (int)ViewState["PromotorID"];
                bll.Model.State       = 2;
                bll.Model.ApproveTask = TaskID;
                bll.Model.ApproveFlag = 2;
                bll.Model.InsertStaff = (int)Session["UserID"];
                bll.Add();
                _promotor.Submit(TaskID, (int)Session["UserID"]);
                new EWF_TaskBLL(TaskID).Start();
                MessageBox.ShowAndClose(this, "流程发起成功!");
            }
        }
    }