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, "流程发起成功!");
            }
        }
    }
    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, "流程发起成功!");
            }
        }
    }
    protected void bt_AddApply_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorID"] == 0)
        {
            MessageBox.Show(this, "对不起,请您先保存后在发起申请");
            return;
        }
        bt_OK_Click(null, null);

        PM_PromotorBLL bll = new PM_PromotorBLL((int)ViewState["PromotorID"]);
        DateTime       birthday;

        if (DateTime.TryParse(bll.Model["Birthday"], out birthday))
        {
            if (DateTime.Now < birthday.AddYears(16) || DateTime.Now > birthday.AddYears(50))
            {
                int year = DateTime.Now.Year - birthday.Year;
                if (birthday.AddYears(year) > DateTime.Now)
                {
                    year++;
                }
                MessageBox.Show(this, "对不起,该导购年龄不符合规则(16~49岁),该人员年龄:" + year);
                return;
            }
        }
        if (PM_PromotorNumberLimitBLL.CheckAllowAdd(bll.Model.OrganizeCity, int.Parse(bll.Model["Classfiy"])) < 0)
        {
            MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
            return;
        }
        if (bll.Model.BeginWorkDate.AddDays(40) < DateTime.Now)
        {
            MessageBox.Show(this, "对不起,入职时间必须在发起日期前40天之内!");
            return;
        }
        if (bll.Model["IDCode"] == "")
        {
            MessageBox.Show(this, "请录入身份证号!");
            return;
        }
        if (bll.Model["InfoSource"] == "" || bll.Model["InfoSource"] == "0")
        {
            MessageBox.Show(this, "请正确选择导购来源!");
            return;
        }
        if (bll.Model["OldClassify"] == "" || bll.Model["OldClassify"] == "0")
        {
            MessageBox.Show(this, "请正确选择原属品牌!");
            return;
        }
        if (bll.Model["BankType"] == "" || bll.Model["BankType"] == "0")
        {
            MessageBox.Show(this, "请正确选择银行信息");
            return;
        }
        string[]        allowday  = Addr_OrganizeCityParamBLL.GetValueByType(1, 3).Split(new char[] { ',', ',', ';', ';' });
        AC_AccountMonth lastmonth = GetMaxSalaryDate((int)ViewState["PromotorID"], AC_AccountMonthBLL.GetCurrentMonth() - 1);

        if (lastmonth != null && allowday.Contains(DateTime.Now.Day.ToString()) && bll.Model.BeginWorkDate > lastmonth.EndDate)
        {
            MessageBox.Show(this, "该导购在" + lastmonth.Name + "生成过工资,入职日期不能大于" + lastmonth.EndDate.ToString("yyyy-MM-dd"));
            return;
        }

        #region 判断是否KA店导购
        bool IsKAChannel = false;         //是否KA店导购

        if (bll.Model["Classify"] != "2") //非流导
        {
            IList <PM_PromotorInRetailer> retailers = PM_PromotorInRetailerBLL.GetModelList(" Promotor=" + ViewState["PromotorID"].ToString());
            if (retailers.Count == 0)
            {
                MessageBox.Show(this, "对不起,请关联该导购所在的工作门店!");
                return;
            }

            //判断导购是否在KA店工作
            foreach (PM_PromotorInRetailer item in retailers)
            {
                CM_Client client = new CM_ClientBLL(item.Client).Model;
                if (client["RTChannel"] == "1" || client["RTChannel"] == "2")
                {
                    IsKAChannel = true;
                }
            }
        }
        #endregion

        #region 判断是否超薪酬超准
        bool bSalaryFlag = false;   //false : 薪酬标准内 true:超标准
        IList <PM_PromotorSalary> salarylists = PM_PromotorSalaryBLL.GetModelList("Promotor=" + bll.Model.ID.ToString() + " AND State IN(1,3) Order BY State");

        if (salarylists.Count == 0 || salarylists.Count > 0 && (bll.Model["Classfiy"] == "6" && salarylists[0].BasePayMode != 3 || bll.Model["Classfiy"] != "6" && salarylists[0].BasePayMode == 3))
        {
            MessageBox.Show(this, "对不起,尚未为该导购设定薪酬信息,请设定完薪酬信息后,再提交入职申请!");
            return;
        }
        else
        {
            PM_PromotorSalary salary = salarylists[0];
            if (salary.BasePaySubsidy > 0)
            {
                bSalaryFlag = true;                              //有底薪补贴
            }
            if (salary.MinimumWageMode == 2)
            {
                bSalaryFlag = true;                              //特殊保底
            }
            if (salary.InsuranceMode == 1 && salary.InsuranceSubsidy > 100)
            {
                bSalaryFlag = true;                                                                 //社保补贴大于100元的
            }
        }
        #endregion

        int budget = PM_PromotorNumberLimitBLL.CheckOverBudget(bll.Model.OrganizeCity, int.Parse(bll.Model["Classfiy"]));

        NameValueCollection dataobjects = new NameValueCollection();
        dataobjects.Add("ID", ViewState["PromotorID"].ToString());
        dataobjects.Add("OrganizeCity", bll.Model.OrganizeCity.ToString());
        dataobjects.Add("SalaryFlag", !bSalaryFlag ? "1" : "2");      //薪酬标志 1:薪酬标准内 2:薪酬标准外
        dataobjects.Add("StaffName", bll.Model.Name.ToString());
        dataobjects.Add("IsKAChannel", IsKAChannel ? "1" : "2");      //是否KA卖场的导购
        dataobjects.Add("IsOverBudget", budget < 0 ? "1" : "2");      //是否超人数预算 1:超 2:未超


        int TaskID = EWF_TaskBLL.NewTask("Add_Promotor", (int)Session["UserID"], "新增导购员流程,姓名:" + bll.Model.Name + "【" + ddl_Classify.SelectedItem.Text.ToString() + "】", "~/SubModule/PM/PM_PromotorDetail.aspx?PromotorID=" + ViewState["PromotorID"].ToString(), dataobjects);
        if (TaskID > 0)
        {
            bll.Submit(TaskID, (int)Session["UserID"]);
        }

        Response.Redirect("~/SubModule/EWF/Apply.aspx?TaskID=" + TaskID.ToString());
    }
    protected void bt_AddApply_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorID"] == 0)
        {
            MessageBox.Show(this, "对不起,请您先保存后在发起申请");
            return;
        }
        bt_OK_Click(null, null);

        PM_PromotorBLL bll = new PM_PromotorBLL((int)ViewState["PromotorID"]);
        DateTime birthday;
        if (DateTime.TryParse(bll.Model["Birthday"], out birthday))
        {
            if (DateTime.Now < birthday.AddYears(16) || DateTime.Now > birthday.AddYears(50))
            {
                int year = DateTime.Now.Year - birthday.Year;
                if (birthday.AddYears(year) > DateTime.Now)
                    year++;
                MessageBox.Show(this, "对不起,该导购年龄不符合规则(16~49岁),该人员年龄:" + year);
                return;
            }

        }
        if (PM_PromotorNumberLimitBLL.CheckAllowAdd(bll.Model.OrganizeCity, int.Parse(bll.Model["Classfiy"])) < 0)
        {
            MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
            return;
        }
        if (bll.Model.BeginWorkDate.AddDays(40) < DateTime.Now)
        {
            MessageBox.Show(this, "对不起,入职时间必须在发起日期前40天之内!");
            return;
        }
        if (bll.Model["IDCode"] == "")
        {
            MessageBox.Show(this, "请录入身份证号!");
            return;
        }
        if (bll.Model["InfoSource"] == "" || bll.Model["InfoSource"] == "0")
        {
            MessageBox.Show(this, "请正确选择导购来源!");
            return;
        }
        if (bll.Model["OldClassify"] == "" || bll.Model["OldClassify"] == "0")
        {
            MessageBox.Show(this, "请正确选择原属品牌!");
            return;
        }
        if (bll.Model["BankType"] == "" || bll.Model["BankType"] == "0")
        {
            MessageBox.Show(this, "请正确选择银行信息");
            return;
        }
        string[] allowday = Addr_OrganizeCityParamBLL.GetValueByType(1, 3).Split(new char[] { ',', ',', ';', ';' });
        AC_AccountMonth lastmonth = GetMaxSalaryDate((int)ViewState["PromotorID"], AC_AccountMonthBLL.GetCurrentMonth() - 1);
        if (lastmonth != null && allowday.Contains(DateTime.Now.Day.ToString()) && bll.Model.BeginWorkDate > lastmonth.EndDate)
        {
            MessageBox.Show(this, "该导购在" + lastmonth.Name + "生成过工资,入职日期不能大于" + lastmonth.EndDate.ToString("yyyy-MM-dd"));
            return;
        }

        #region 判断是否KA店导购
        bool IsKAChannel = false;  //是否KA店导购

        if (bll.Model["Classify"] != "2")       //非流导
        {
            IList<PM_PromotorInRetailer> retailers = PM_PromotorInRetailerBLL.GetModelList(" Promotor=" + ViewState["PromotorID"].ToString());
            if (retailers.Count == 0)
            {
                MessageBox.Show(this, "对不起,请关联该导购所在的工作门店!");
                return;
            }

            //判断导购是否在KA店工作
            foreach (PM_PromotorInRetailer item in retailers)
            {
                CM_Client client = new CM_ClientBLL(item.Client).Model;
                if (client["RTChannel"] == "1" || client["RTChannel"] == "2") IsKAChannel = true;
            }
        }
        #endregion

        #region 判断是否超薪酬超准
        bool bSalaryFlag = false;   //false : 薪酬标准内 true:超标准
        IList<PM_PromotorSalary> salarylists = PM_PromotorSalaryBLL.GetModelList("Promotor=" + bll.Model.ID.ToString() + " AND State IN(1,3) Order BY State");

        if (salarylists.Count == 0 || salarylists.Count > 0 && (bll.Model["Classfiy"] == "6" && salarylists[0].BasePayMode != 3 || bll.Model["Classfiy"] != "6" && salarylists[0].BasePayMode == 3))
        {
            MessageBox.Show(this, "对不起,尚未为该导购设定薪酬信息,请设定完薪酬信息后,再提交入职申请!");
            return;
        }
        else
        {
            PM_PromotorSalary salary = salarylists[0];
            if (salary.BasePaySubsidy > 0) bSalaryFlag = true;   //有底薪补贴
            if (salary.MinimumWageMode == 2) bSalaryFlag = true; //特殊保底
            if (salary.InsuranceMode == 1 && salary.InsuranceSubsidy > 100) bSalaryFlag = true;     //社保补贴大于100元的
        }
        #endregion

        int budget = PM_PromotorNumberLimitBLL.CheckOverBudget(bll.Model.OrganizeCity, int.Parse(bll.Model["Classfiy"]));

        NameValueCollection dataobjects = new NameValueCollection();
        dataobjects.Add("ID", ViewState["PromotorID"].ToString());
        dataobjects.Add("OrganizeCity", bll.Model.OrganizeCity.ToString());
        dataobjects.Add("SalaryFlag", !bSalaryFlag ? "1" : "2");      //薪酬标志 1:薪酬标准内 2:薪酬标准外
        dataobjects.Add("StaffName", bll.Model.Name.ToString());
        dataobjects.Add("IsKAChannel", IsKAChannel ? "1" : "2");      //是否KA卖场的导购
        dataobjects.Add("IsOverBudget", budget < 0 ? "1" : "2");      //是否超人数预算 1:超 2:未超

        int TaskID = EWF_TaskBLL.NewTask("Add_Promotor", (int)Session["UserID"], "新增导购员流程,姓名:" + bll.Model.Name+ "【"+ddl_Classify.SelectedItem.Text.ToString()+"】", "~/SubModule/PM/PM_PromotorDetail.aspx?PromotorID=" + ViewState["PromotorID"].ToString() , dataobjects);
        if (TaskID > 0)
        {
            bll.Submit(TaskID, (int)Session["UserID"]);
        }

        Response.Redirect("~/SubModule/EWF/Apply.aspx?TaskID=" + TaskID.ToString());
    }