private void BindData()
 {
     PM_Promotor m = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
     UC_DetailView1.BindData(m);
     gv_list.ConditionString = " Promotor= " + (int)ViewState["PromotorID"];
     gv_list.BindGrid();
 }
    private void BindGrid()
    {
        int       month        = int.Parse(ddl_Month.SelectedValue);
        int       organizecity = int.Parse(tr_OrganizeCity.SelectValue);
        DataTable dt           = PM_PromotorBLL.GetAnalysisOverview(organizecity, month);

        if (dt.Columns.Count > 0)
        {
            dt.Columns.Remove("Promotor");
            dt.Columns.Remove("ClientID");
            dt.Columns.Remove("BPMID");
            dt.Columns.Remove("BRTID");
            dt.Columns.Remove("取消人");
            dt.Columns.Remove("取消人职务");
            dt.Columns.Remove("取消时间");
        }
        // ViewState["dtSummary"] = dt;
        gv_List.DataSource = dt;
        gv_List.DataBind();
        if (dt.Columns.Count >= 24)
        {
            gv_List.Width = new Unit(dt.Columns.Count * 65);
        }
        else
        {
            gv_List.Width = new Unit(100, UnitType.Percentage);
        }
    }
    private void BindData()
    {
        PM_Promotor m = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;

        UC_DetailView1.BindData(m);
        gv_list.ConditionString = " Promotor= " + (int)ViewState["PromotorID"];
        gv_list.BindGrid();
    }
    public void BindDropDown()
    {
        PM_Promotor p = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;

        ddl_CM.DataTextField  = "FullName";
        ddl_CM.DataValueField = "ID";
        ddl_CM.DataSource     = CM_ClientBLL.GetModelList(" OrganizeCity in (" + p.OrganizeCity + ")" + @" AND ClientType=3 AND ActiveFlag=1 AND ApproveFlag=1 AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',5)='3'");
        ddl_CM.DataBind();
        ddl_CM.Items.Insert(0, new ListItem("请选择", "0"));
    }
    public void BindDropDown()
    {
        PM_Promotor p = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;

        ddl_CM.DataTextField = "FullName";
        ddl_CM.DataValueField = "ID";
        ddl_CM.DataSource = CM_ClientBLL.GetModelList(" OrganizeCity in (" + p.OrganizeCity + ")" + @" AND ClientType=3 AND ActiveFlag=1 AND ApproveFlag=1 AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',5)='3'");
        ddl_CM.DataBind();
        ddl_CM.Items.Insert(0, new ListItem("请选择", "0"));
    }
    protected void bt_TaskDetail_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorID"] == 0)
        {
            MessageBox.Show(this, "对不起,当前还没有审批记录");
            return;
        }

        PM_PromotorBLL _promotor = new PM_PromotorBLL((int)ViewState["PromotorID"]);

        Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + _promotor.Model["TaskID"].ToString());
    }
    private void BindDropdown()
    {
        #region 绑定用户可管辖的片区
        Org_StaffBLL staff = new Org_StaffBLL((int)Session["UserID"]);
        tr_OrganizeCity.DataSource = staff.GetStaffOrganizeCity();

        if ((int)ViewState["PromotorID"] != 0)
        {
            PM_Promotor pm = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
            select_promotor.SelectText = pm.Name;
            select_promotor.SelectValue = pm.ID.ToString();
        }

        if (tr_OrganizeCity.DataSource.Select("ID = 1").Length > 0)
        {
            tr_OrganizeCity.RootValue = "0";
            tr_OrganizeCity.SelectValue = "1";
        }
        else
        {
            tr_OrganizeCity.RootValue = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString();
            tr_OrganizeCity.SelectValue = staff.Model.OrganizeCity.ToString();
        }
        #endregion


        ddl_AccountMonth.DataSource = AC_AccountMonthBLL.GetModelList("");
        ddl_AccountMonth.DataBind();
        ddl_AccountMonth.SelectedValue = (AC_AccountMonthBLL.GetCurrentMonth() - 1).ToString();

        ddl_ApproveFlag.DataSource = DictionaryBLL.GetDicCollections("PUB_ApproveFlag");
        ddl_ApproveFlag.DataBind();
        ddl_ApproveFlag.Items.Insert(0, new ListItem("所有", "0"));

        select_Client.PageUrl = "~/SubModule/CM/PopSearch/Search_SelectClient.aspx?ClientType=2&ExtCondition=\"MCS_SYS.dbo.UF_Spilt(CM_Client.ExtPropertys,~|~,7)=1\"";

        if ((int)ViewState["PromotorID"] != 0)
        {
            PM_Promotor pm = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
            select_promotor.SelectText = pm.Name;
            select_promotor.SelectValue = pm.ID.ToString();
            tr_OrganizeCity.SelectValue = pm.OrganizeCity.ToString();
            BtnDelete.Enabled = false;
            BtnSave.Enabled = false;
            gv_List.Enabled = false;
        }
        if ((int)ViewState["AccountMonth"] != 0)
        {
            ddl_AccountMonth.SelectedValue = ViewState["AccountMonth"].ToString();
            BindGrid();
        }
    }
 protected void Page_LoadComplete(object sender, EventArgs e)
 {
     if ((int)ViewState["PromotorID"] > 0)
     {
         PM_Promotor m = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
         if (m.Dimission == 2)
         {
             TextBox txt_BeginWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_BeginWorkDate");
             txt_BeginWorkDate.Enabled = true;
             //ddl_Classify.Enabled = true;
         }
     }
 }
Ejemplo n.º 9
0
    protected void bt_Export_Click(object sender, EventArgs e)
    {
        string appcode = "";

        if (ddl_State.SelectedValue != "2")
        {
            appcode = ddl_App.SelectedValue;
        }
        int organizecity = int.Parse(tr_OrganizeCity.SelectValue);

        DataTable dt = PM_PromotorBLL.GetApproveList(organizecity, appcode, (int)Session["UserID"]);

        CreateExcel(dt, "Export-" + DateTime.Now.ToString("yyyyMMdd-HHmmss"));
    }
Ejemplo n.º 10
0
    private void BindGrid()
    {
        int       organizecity = int.Parse(tr_OrganizeCity.SelectValue);
        DataTable dtlist       = new DataTable();

        if (MCSTabControl1.SelectedTabItem.Value == "2")
        {
            dtlist = PM_PromotorBLL.GetApproveConsult(organizecity, int.Parse(ddl_Level.SelectedValue));
            if (dtlist.Rows.Count > 0)
            {
                DataRow dtrow = dtlist.NewRow();
                dtrow["管理片区"]    = "合计";
                dtrow["导购人数"]    = dtlist.Compute("Sum(导购人数)", "true");
                dtrow["上上月实际销量"] = dtlist.Compute("Sum(上上月实际销量)", "true");
                dtrow["上月实际销量"]  = dtlist.Compute("Sum(上月实际销量)", "true");
                dtrow["预估本月销量"]  = dtlist.Compute("Sum(预估本月销量)", "true");
                dtrow["导购人数"]    = dtlist.Compute("Sum(导购人数)", "true");
                dtrow["陈列费"]     = dtlist.Compute("Sum(陈列费)", "true");
                dtrow["促销员管理费"]  = dtlist.Compute("Sum(促销员管理费)", "true");
                dtrow["底薪"]      = dtlist.Compute("Sum(底薪)", "true");
                //dtrow["社保"] = dtlist.Compute("Sum(社保)", "true");
                dtrow["费率B"] = dtrow["预估本月销量"].ToString() == "0" ? "0" :
                               ((decimal.Parse(dtrow["底薪"].ToString()) + decimal.Parse(dtrow["促销员管理费"].ToString())) / decimal.Parse(dtrow["预估本月销量"].ToString()) * 100).ToString("0.00");
                dtlist.Rows.Add(dtrow);
                gv_Consult.DataSource = dtlist;
                gv_Consult.DataBind();
            }
        }
        else
        {
            string appcode = "";
            if (ddl_State.SelectedValue != "2")
            {
                appcode = ddl_App.SelectedValue;
            }

            DataTable dt = PM_PromotorBLL.GetApproveList(organizecity, appcode, (int)Session["UserID"]);
            gv_List.DataSource = dt;
            gv_List.DataBind();
            gv_List.Width = dt.Columns.Count * 60;

            gv_List.Columns[0].Visible = ddl_State.SelectedValue != "2";


            btn_Approve.Visible   = (gv_List.Rows.Count > 0 && ddl_State.SelectedValue != "2");
            btn_UnApprove.Visible = btn_Approve.Visible;
        }
    }
    public void BindDropDown()
    {
        CM_Client m = new CM_ClientBLL((int)ViewState["ClientID"]).Model;

        ddl_Promotor.DataTextField  = "Name";
        ddl_Promotor.DataValueField = "ID";
        ddl_Promotor.DataSource     = PM_PromotorBLL.GetModelList(" OrganizeCity in (" + m.OrganizeCity + @") AND Dimission=1 AND ApproveFlag=1 AND 
            (MCS_SYS.dbo.UF_Spilt2('MCS_Promotor.dbo.PM_Promotor',ExtPropertys,'Classfiy')='2' OR ID NOT IN (SELECT Promotor FROM MCS_Promotor.dbo.PM_PromotorInRetailer))");
        ddl_Promotor.DataBind();
        ddl_Promotor.Items.Insert(0, new ListItem("请选择", "0"));

        ddl_state.DataSource = DictionaryBLL.GetDicCollections("CM_ContractState");
        ddl_state.DataBind();
        ddl_state.Items.Insert(0, new ListItem("所有", "0"));
        ddl_state.SelectedValue = "3";
    }
Ejemplo n.º 12
0
    protected void select_Client_SelectChange(object sender, MCSControls.MCSWebControls.SelectChangeEventArgs e)
    {
        bt_Generate.Enabled = true;
        int organizecity = 0;
        int client       = 0;
        int month        = 0;

        int.TryParse(tr_OrganizeCity.SelectValue, out organizecity);
        int.TryParse(select_Client.SelectValue, out client);
        int.TryParse(ddl_Month.SelectedValue, out month);
        DataTable promotors = PM_PromotorBLL.GetByDIClient(organizecity, client, month);



        if (promotors.Select("ErrType=2").Count() > 0)
        {
            promotors.DefaultView.RowFilter = "ErrType=2";
            gv_List.DataSource = promotors.DefaultView.ToTable();
            gv_List.DataBind();
            gv_Table.Visible    = true;
            bt_Generate.Enabled = false;
            MessageBox.Show(this, "对不起,有部分导购员的薪酬定义没有正确维护,请正确设定薪酬定义信息后,再生成工资!");
        }



        if (promotors.Select("ErrType=3").Count() > 0)
        {
            promotors.DefaultView.RowFilter = "ErrType=3";
            gv_List.DataSource = promotors.DefaultView.ToTable();
            gv_List.DataBind();
            gv_Table.Visible    = true;
            bt_Generate.Enabled = false;
            MessageBox.Show(this, "对不起,片区内有导购专兼职转换流程未完成,需审批完成后才可生成工资(生成工资前请到奖惩设定与调整项中刷新提成)!");
        }

        if (promotors.Select("ErrType=1").Count() > 0)
        {
            promotors.DefaultView.RowFilter = "ErrType=1";
            gv_List.DataSource = promotors.DefaultView.ToTable();
            gv_List.DataBind();
            gv_Table.Visible = true;
            MessageBox.Show(this, "以下导购员所在门店已生成返利费用或有生效返利协议,不能生成工资,请确认是否排除这些导购?");
        }
    }
    /// <summary>
    /// 审核
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void bt_Approve_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorID"] != 0)
        {
            PM_PromotorBLL _promotor = new PM_PromotorBLL((int)ViewState["PromotorID"]);

            if (PM_PromotorNumberLimitBLL.CheckAllowAdd(_promotor.Model.OrganizeCity, int.Parse(_promotor.Model["Classfiy"])) < 0)
            {
                MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
                return;
            }
            _promotor.Model.ApproveFlag = 1;
            _promotor.Model.UpdateStaff = (int)Session["UserID"];
            _promotor.Update();
            MessageBox.Show(this, "审核成功!");
            BindData();
        }
    }
    protected void bt_Export_Click(object sender, EventArgs e)
    {
        string    filename     = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes("导购投产明细导出_" + DateTime.Now.ToString("yyyyMMddHHmmss")));
        int       month        = int.Parse(ddl_Month.SelectedValue);
        int       organizecity = int.Parse(tr_OrganizeCity.SelectValue);
        DataTable dt           = PM_PromotorBLL.GetAnalysisOverview(organizecity, month);

        if (dt.Rows.Count > 0)
        {
            dt.Columns.Remove("Promotor");
            dt.Columns.Remove("ClientID");
            dt.Columns.Remove("BPMID");
            dt.Columns.Remove("BRTID");
            dt.Columns.Remove("取消人");
            dt.Columns.Remove("取消人职务");
            dt.Columns.Remove("取消时间");
            CreateExcel(dt, filename);
        }
    }
    /// <summary>
    /// 新增返利协议
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void bt_AddContract2_Click(object sender, EventArgs e)
    {
        bool flag = true;//允许生生成陈列协议

        string condition = " Client=" + ViewState["ClientID"].ToString();
        IList <PM_PromotorInRetailer> list = PM_PromotorInRetailerBLL.GetModelList(condition);

        for (int i = 0; i < list.Count; i++)
        {
            PM_PromotorBLL PM_PromotorBLL = new PM_PromotorBLL(list[i].Promotor);
            PM_Promotor    promoter       = PM_PromotorBLL.Model;
            int            endMonth       = AC_AccountMonthBLL.GetMonthByDate(promoter.EndWorkDate);
            int            currentMonth   = AC_AccountMonthBLL.GetCurrentMonth();
            //导购在职或导购离职判断离职日期,即使无销量也需生成基本工资
            if (promoter.Dimission == 1 || promoter.Dimission == 2 && endMonth >= currentMonth)//
            {
                flag = false;
                break;
            }
        }
        if (!flag)
        {
            MessageBox.Show(this, "当前门店存在导购或本月需生成导购工资");
            return;
        }

        bt_OK_Click(null, null);
        CM_ClientBLL _cm = new CM_ClientBLL((int)ViewState["ClientID"]);

        if (_cm.Model["Classification"] == "" || _cm.Model["Classification"] == "0")
        {
            MessageBox.Show(this, "请先选择门店归类再新增返利协议!");
            return;
        }
        //导购店添加返利协议
        if (_cm.Model["RTClassify"] == "3")
        {
            MessageBox.Show(this, _cm.CheckRealClassifyShowMessage(1));
            return;
        }
        Response.Redirect("RetailerContractDetail.aspx?ClientID=" + ViewState["ClientID"].ToString() + "&Classify=2");
    }
    private void BindGrid()
    {
        string promotors = "";
        AC_AccountMonth month = new AC_AccountMonthBLL(int.Parse(ddl_AccountMonth.SelectedValue)).Model;
        int monthdays = month.EndDate.Subtract(month.BeginDate).Days + 1;
        lbl_message.Text = "注意:所选会计月天数为:" + monthdays.ToString() + "天,实际工作天数不能大于会计月天数";
        ViewState["monthdays"] = monthdays;
        string condition = "PM_SalaryDataObject.AccountMonth=" + ddl_AccountMonth.SelectedValue;
        if (tr_OrganizeCity.SelectValue != "1")
        {
            Addr_OrganizeCityBLL orgcity = new Addr_OrganizeCityBLL(int.Parse(tr_OrganizeCity.SelectValue));
            string orgcitys = orgcity.GetAllChildNodeIDs();
            if (orgcitys != "") orgcitys += ",";
            orgcitys += tr_OrganizeCity.SelectValue;
            condition += " AND  MCS_Promotor.dbo.PM_Promotor.OrganizeCity in(" + orgcitys + ") ";
        }
        if (select_promotor.SelectValue != "")
        {
            condition += " AND  MCS_Promotor.dbo.PM_Promotor.ID=" + select_promotor.SelectValue;
        }
        if (ddl_ApproveFlag.SelectedValue != "0")
        {
            condition += " AND  PM_SalaryDataObject.ApproveFlag=" + ddl_ApproveFlag.SelectedValue;
        }
        if (select_Client.SelectValue != "")
        {
            DataTable tb_promotor = PM_PromotorBLL.GetByDIClient(int.Parse(tr_OrganizeCity.SelectValue), int.Parse(select_Client.SelectValue), month.ID);
            foreach (DataRow row in tb_promotor.Rows)
            {
                promotors += row["Promotor"].ToString() + ",";
            }
            if (promotors != "")
                promotors = " AND PM_SalaryDataObject.Promotor IN (" + promotors.Substring(0, promotors.Length - 1) + ")";
            else
                promotors = " AND 1 = 2";

        }
        gv_List.ConditionString = condition + promotors;
        gv_List.BindGrid();
        chkHeader.Checked = false;
    }
    private void BindGrid()
    {
        DataTable dt    = null;
        int       month = int.Parse(ddl_AccountMonth.SelectedValue);

        if (select_Promotor.SelectValue != "")
        {
            string    orgcitys  = "";
            DataTable dtclients = PM_PromotorBLL.GetClientList(int.Parse(select_Promotor.SelectValue));
            foreach (DataRow dr in dtclients.Rows)
            {
                orgcitys += "," + dr["ID"].ToString();
            }
            if (orgcitys != "")
            {
                orgcitys = orgcitys.Substring(1, orgcitys.Length - 1);
            }
            dt = null;// SVM_JXCBLL.GetSummaryJXC(orgcitys, month);
        }
        gv_List.DataSource = dt;
        gv_List.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindDropDown();
            #region 获取页面参数
            if (Request.QueryString["PromotorID"] != null)
            {
                ViewState["PromotorID"] = Int32.Parse(Request.QueryString["PromotorID"]);
                PM_PromotorBLL pro = new PM_PromotorBLL((int)ViewState["PromotorID"]);
                select_Promotor.SelectValue = pro.Model.ID.ToString();
                select_Promotor.SelectText  = pro.Model.Name;
                select_Promotor_SelectChange(null, null);
            }

            if (Request.QueryString["AccountMonth"] != null)
            {
                ddl_AccountMonth.SelectedValue = Request.QueryString["AccountMonth"];
            }
            #endregion

            BindGrid();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindDropDown();
            #region 获取页面参数
            if (Request.QueryString["PromotorID"] != null)
            {
                ViewState["PromotorID"] = Int32.Parse(Request.QueryString["PromotorID"]);
                PM_PromotorBLL pro = new PM_PromotorBLL((int)ViewState["PromotorID"]);
                select_Promotor.SelectValue = pro.Model.ID.ToString();
                select_Promotor.SelectText = pro.Model.Name;
                select_Promotor_SelectChange(null, null);
            }

            if (Request.QueryString["AccountMonth"] != null)
            {
                ddl_AccountMonth.SelectedValue = Request.QueryString["AccountMonth"];
            }
            #endregion

            BindGrid();
        }
    }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorSalaryID"] == 0)
        {
            MessageBox.Show(this, "对不起,请您先保存后在发起申请");
            return;
        }
        PM_PromotorSalaryBLL bll = new PM_PromotorSalaryBLL((int)ViewState["PromotorSalaryID"]);
        PM_Promotor          p   = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;

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

        if (p["Classify"] != "2")  //非流导
        {
            IList <PM_PromotorInRetailer> retailers = PM_PromotorInRetailerBLL.GetModelList(" Promotor=" + ViewState["PromotorID"].ToString());
            //判断导购是否在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;
        PM_PromotorSalary salary = bll.Model;

        if (salary.BasePaySubsidy >= 1)
        {
            bSalaryFlag = true;                                     //有底薪补贴
        }
        if (salary.MinimumWageMode == 2)
        {
            bSalaryFlag = true;                                //特殊保底
        }
        if (salary.InsuranceMode == 1 && salary.InsuranceSubsidy > 100)
        {
            bSalaryFlag = true;                                                                 //社保补贴大于100元的
        }
        #endregion

        NameValueCollection dataobjects = new NameValueCollection();
        dataobjects.Add("ID", p.ID.ToString());
        dataobjects.Add("PromotorSalaryID", ViewState["PromotorSalaryID"].ToString());
        dataobjects.Add("OrganizeCity", p.OrganizeCity.ToString());
        dataobjects.Add("SalaryFlag", bSalaryFlag ? "2" : "1");      //薪酬标志 1:薪酬标准内 2:薪酬标准外
        dataobjects.Add("StaffName", p.Name.ToString());
        dataobjects.Add("IsKAChannel", IsKAChannel ? "1" : "2");     //是否KA卖场的导购

        int TaskID = EWF_TaskBLL.NewTask("Apply_PromotorSalary", (int)Session["UserID"], "调整导购员薪酬福利申请,姓名:" + p.Name,
                                         "~/SubModule/PM/PM_PromotorSalaryDetail.aspx?ID=" + bll.Model.ID.ToString(), dataobjects);
        if (TaskID > 0)
        {
            bll.Model.ApproveTask = TaskID;
            bll.Model.State       = 2;
            bll.Update();
            // new EWF_TaskBLL(TaskID).Start();        //直接启动流程
        }

        Response.Redirect("~/SubModule/EWF/Apply.aspx?TaskID=" + TaskID.ToString());
    }
    private void BindData(PM_PromotorSalary m)
    {
        if (m != null)
        {
            ViewState["PromotorID"]       = m.Promotor;
            ViewState["PromotorSalaryID"] = m.ID;
        }

        #region 获取当前导购标准薪资、保底薪资、导购管理费
        if ((int)ViewState["PromotorID"] > 0)
        {
            decimal basepay = 0, minumumwage = 0, rtmanagecost = 0;
            new PM_PromotorBLL((int)ViewState["PromotorID"]).GetStdPay(out basepay, out minumumwage, out rtmanagecost);
            ViewState["BasePay"]      = basepay;
            ViewState["MinumumWage"]  = minumumwage;
            ViewState["RTManageCost"] = rtmanagecost;
        }
        #endregion
        PM_Promotor p = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
        if (p == null)
        {
            Response.Redirect("PM_PromotorDetail.aspx");
        }
        if (m == null)
        {
            m              = new PM_PromotorSalary();
            m.Promotor     = (int)ViewState["PromotorID"];
            m.State        = 1;
            m.InsertStaff  = (int)Session["UserID"];
            m.RTManageCost = (decimal)ViewState["RTManageCost"];
            if (p["Classfiy"] == "1" || p["Classfiy"] == "2")
            {
                m.SeniorityPayMode = 1;
            }
        }
        if (p["State"] == "2")
        {
            bt_Add.Visible = false;
        }

        UC_DetailView1.BindData(m);
        chk_arrivetarget.Checked = m["ISArriveTarget"] == "1";
        UC_DetailView1.SetControlsEnable(m.State == 1);
        bt_OK.Enabled = m.State == 1;

        if (m.ID != 0)
        {
            bt_Delete.Enabled  = m.State == 1;
            bt_Submit.Enabled  = m.State == 1;
            bt_Approve.Enabled = m.State == 1;
        }
        else
        {
            bt_Submit.Enabled  = false;
            bt_Approve.Enabled = false;
            bt_Delete.Enabled  = false;
        }
        if (m.BasePayMode != 4 && m.BasePayMode != 5)
        {
            setdisabledfloatingcontorl(false);
        }


        //导购为新入职、或离职状态
        if (p.ApproveFlag == 2)
        {
            bt_Submit.Visible = false;
        }
        //if (p.Dimission == 2) bt_Add.Visible = false;

        if (m.RTManageCost > 0 && (decimal)ViewState["RTManageCost"] == m.RTManageCost)
        {
            TextBox tbx = (TextBox)UC_DetailView1.FindControl("PM_PromotorSalary_RTManageCost");
            if (tbx != null)
            {
                tbx.Enabled = false;
            }
        }
        if (m.State < 2)
        {
            #region 兼职导购的限定
            try
            {
                if (ddl_BasePayMode != null)
                {
                    if (p["Classfiy"] != "1" && p["Classfiy"] != "2")   //非专职、非流导,认为是兼职导购
                    {
                        //兼职
                        //ddl_BasePayMode.Items[0].Enabled = false;
                        //ddl_BasePayMode.Items[1].Enabled = false;
                        //ddl_BasePayMode.Items[2].Enabled = false;
                        SetControlsEnable(false);
                        ddl_BasePayMode.SelectedValue = "3";
                        ddl_BasePayMode.Enabled       = false;
                    }
                    else
                    {
                        Addr_OrganizeCityBLL _bll   = new Addr_OrganizeCityBLL(p.OrganizeCity);
                        string[]             city3s = Addr_OrganizeCityParamBLL.GetValueByType(1, 19).Split(new char[] { ',', ',', ';', ';' });
                        int city3ID = TreeTableBLL.GetSuperIDByLevel("MCS_SYS.dbo.Addr_OrganizeCity", p.OrganizeCity, ConfigHelper.GetConfigInt("OrganizePartCity-CityLevel"));

                        if (city3s.Contains(city3ID.ToString()))
                        {
                            ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(非华南)", "4"));
                        }
                        else
                        {
                            decimal AvgSales = 0, BaseFeeRate = 0;
                            int     SalaryDelayDays = ConfigHelper.GetConfigInt("SalaryDelayDays");
                            ddl_SalesType.Enabled = false;
                            new PM_PromotorSalaryBLL().GetFloatingInfo(p.ID, AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-SalaryDelayDays)) - 1, out AvgSales, out BaseFeeRate);

                            if (AvgSales == 0 && BaseFeeRate == 0)//首两月不是固定底薪,不能选择浮动底薪
                            {
                                ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(非华南)", "4"));
                            }
                            else
                            {
                                ViewState["AvgSales"]    = AvgSales;
                                ViewState["BaseFeeRate"] = BaseFeeRate;
                            }

                            ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(华南)", "5"));
                        }
                        ddl_BasePayMode.Items.Remove(new ListItem("兼职底薪", "3"));
                        //50岁只能选择商保(5)或自购(8)
                        DateTime Birthday;
                        if (DateTime.TryParse(p["Birthday"], out Birthday) && Birthday.AddYears(50) < DateTime.Now)
                        {
                            foreach (ListItem item in ddl_InsuranceMode.Items)
                            {
                                if (item.Value != "5" && item.Value != "8" && item.Value != "0")
                                {
                                    item.Enabled = false;
                                }
                            }
                        }
                        //专职或流导
                        //ddl_BasePayMode.Items[3].Enabled = false;
                    }
                }
            }
            catch { }
            #endregion

            ddl_BasePayMode_SelectedIndexChanged(null, null);
            ddl_BasePaySubsidyMode_SelectedIndexChanged(null, null);
            ddl_InsuranceMode_SelectedIndexChanged(null, null);
            ddl_MinimumWageMode_SelectedIndexChanged(null, null);
        }
        BindGrid();
    }
    private void BindData()
    {
        PM_Promotor m = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
        UC_DetailView1.BindData(m);
        gv_list.ConditionString = " Promotor= " + (int)ViewState["PromotorID"];
        gv_list.BindGrid();

        //验证身份证号码
        txt_BankName.Enabled = m["BankType"] == "3";

        if (m.ApproveFlag == 1)
        {
            bt_Approve.Visible = false;
            if (m.Dimission == 1)
            {
                TextBox txt_EndWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_EndWorkDate");
                if (txt_EndWorkDate != null) txt_EndWorkDate.Enabled = false;

                bt_AddApply.Visible = false;
                #region 导购兼职/专职转换
                int classfiy = 0;
                int.TryParse(m["Classfiy"], out classfiy);
                if (classfiy == 0)
                    bt_ChangeClassify.Visible = false;
                else if (classfiy == 1 || classfiy == 2)
                {
                    bt_ChangeClassify.Text = "转为兼职";
                    bt_ChangeClassify.Visible = true;
                }
                else
                {
                    bt_ChangeClassify.Text = "转为专职/流动";
                    bt_ChangeClassify.Visible = true;
                }
                bt_ChangeClassify.OnClientClick = "PopPMClassify_Approve(" + ViewState["PromotorID"].ToString() + ")";
                #endregion
            }
            Header.Attributes["WebPageSubCode"] = "Modify";
            //TextBox txt_BeginWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_BeginWorkDate");

            //临时开放修改功能
            //if (txt_BeginWorkDate != null && m.Dimission==1) txt_BeginWorkDate.Enabled = false;

            //有些离职日期会填写错误,更新为权限修改 12.11.21
            //if (m.Dimission == 2)
            //{
            //    TextBox txt_EndWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_EndWorkDate");
            //    if (txt_EndWorkDate != null) txt_EndWorkDate.Enabled = false;
            //}
            string[] allowdays = Addr_OrganizeCityParamBLL.GetValueByType(1, 9).Replace(" ", "").Split(new char[] { ',', ',', ';', ';' });
            if (allowdays.Contains(DateTime.Now.Day.ToString()))
            {
                bt_ChangeClassify.Enabled = false;
                bt_ChangeClassify.ToolTip = "导购工资生成期间不能互转";
            }

        }

        if (m["State"] == "2")
        {
            //审批中
            bt_AddApply.Visible = false;
            bt_OK.Visible = false;
            bt_TaskDetail.Visible = true;
            bt_ChangeClassify.Enabled = false;
            bt_ChangeClassify.ToolTip = "该导购有未完成的流程,请待流程完成后,再做调整!";
        }
        bt_OK.Text = "保 存";
        bt_OK.ForeColor = System.Drawing.Color.Red;

        if (m["Classfiy"] != "")
        {
            int budget = PM_PromotorNumberLimitBLL.CheckOverBudget(m.OrganizeCity, int.Parse(m["Classfiy"]));
            if (budget == 0)
                lb_OverBudgetInfo.Text = "导购员数量已等于预定的预算人数,请注意!";
            else if (budget < 0)
                lb_OverBudgetInfo.Text = "导购员数量已超过预定的预算人数 " + (0 - budget).ToString() + "人,请注意!";
        }

        if (m["IDCode"].Length == 18 && !Tools.DoVerifyIDCode(m["IDCode"]))
        {
            lb_OverBudgetInfo.Text += "         注意:该导购员身份证号码错误!";
        }

        ddl_Classify_SelectedIndexChanged(null, null);
    }
    private void BindDropdown()
    {
        #region 绑定用户可管辖的片区
        Org_StaffBLL staff = new Org_StaffBLL((int)Session["UserID"]);
        tr_OrganizeCity.DataSource = staff.GetStaffOrganizeCity();

        if ((int)ViewState["PromotorID"] != 0)
        {
            PM_Promotor pm = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
            select_promotor.SelectText = pm.Name;
            select_promotor.SelectValue = pm.ID.ToString();
        }

        if (tr_OrganizeCity.DataSource.Select("ID = 1").Length > 0)
        {
            tr_OrganizeCity.RootValue = "0";
            tr_OrganizeCity.SelectValue = "1";
        }
        else
        {
            tr_OrganizeCity.RootValue = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString();
            tr_OrganizeCity.SelectValue = staff.Model.OrganizeCity.ToString();
        }
        #endregion

        ddl_AccountMonth.DataSource = AC_AccountMonthBLL.GetModelList("");
        ddl_AccountMonth.DataBind();
        ddl_AccountMonth.SelectedValue = (AC_AccountMonthBLL.GetCurrentMonth() - 1).ToString();

        ddl_ApproveFlag.DataSource = DictionaryBLL.GetDicCollections("PUB_ApproveFlag");
        ddl_ApproveFlag.DataBind();
        ddl_ApproveFlag.Items.Insert(0, new ListItem("所有", "0"));

        select_Client.PageUrl = "~/SubModule/CM/PopSearch/Search_SelectClient.aspx?ClientType=2&ExtCondition=\"MCS_SYS.dbo.UF_Spilt(CM_Client.ExtPropertys,~|~,7)=1\"";

        if ((int)ViewState["PromotorID"] != 0)
        {
            PM_Promotor pm = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
            select_promotor.SelectText = pm.Name;
            select_promotor.SelectValue = pm.ID.ToString();
            tr_OrganizeCity.SelectValue = pm.OrganizeCity.ToString();
            BtnDelete.Enabled = false;
            BtnSave.Enabled = false;
            gv_List.Enabled = false;
        }
        if ((int)ViewState["AccountMonth"] != 0)
        {
            ddl_AccountMonth.SelectedValue = ViewState["AccountMonth"].ToString();
            BindGrid();
        }
    }
 protected void Page_LoadComplete(object sender, EventArgs e)
 {
     if ((int)ViewState["PromotorID"] > 0)
     {
         PM_Promotor m = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
         if (m.Dimission == 2)
         {
             TextBox txt_BeginWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_BeginWorkDate");
             txt_BeginWorkDate.Enabled = true;
             //ddl_Classify.Enabled = true;
         }
     }
 }
    protected void bt_TaskDetail_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorID"] == 0)
        {
            MessageBox.Show(this, "对不起,当前还没有审批记录");
            return;
        }

        PM_PromotorBLL _promotor = new PM_PromotorBLL((int)ViewState["PromotorID"]);
        Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + _promotor.Model["TaskID"].ToString());
    }
    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 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);
        }
    }
    private void BindData(int classfiy)
    {
        PM_Promotor p = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;

        #region 获取当前导购标准薪资、保底薪资、导购管理费
        if ((int)ViewState["PromotorID"] > 0)
        {
            decimal basepay = 0, minumumwage = 0, rtmanagecost = 0;
            new PM_PromotorBLL((int)ViewState["PromotorID"]).GetStdPay(out basepay, out minumumwage, out rtmanagecost);
            ViewState["BasePay"]      = basepay;
            ViewState["MinumumWage"]  = minumumwage;
            ViewState["RTManageCost"] = rtmanagecost;
        }
        #endregion

        PM_PromotorSalary m = new PM_PromotorSalary();
        m.Promotor              = (int)ViewState["PromotorID"];
        m.State                 = 1;
        m.InsertStaff           = (int)Session["UserID"];
        m.RTManageCost          = (decimal)ViewState["RTManageCost"];
        ddl_BasePayMode.Enabled = false;
        if (classfiy == 1 || classfiy == 2)
        {
            m.BasePayMode = 3;
        }
        else
        {
            m.SeniorityPayMode            = 1;
            ddl_BankType.Items[3].Enabled = false;

            #region 抓取固定底薪标准
            decimal basepay = (decimal)ViewState["BasePay"];
            m.BasePay = basepay;
            #endregion
            Addr_OrganizeCityBLL _bll = new Addr_OrganizeCityBLL(p.OrganizeCity);
            if (_bll.IsChildOrganizeCity(7))//判断是否为华南区
            {
                ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(非华南)", "4"));
                ddl_BasePayMode.Items.Remove(new ListItem("兼职底薪", "3"));
                ddl_BasePayMode.Enabled = true;
                ddl_SalesType.Enabled   = true;
                txt_BaseFeeRate.Enabled = true;
            }
            else
            {
                m.BasePayMode = 1;
            }
        }
        UC_DetailView1.BindData(m);

        if (m.RTManageCost > 0 && (decimal)ViewState["RTManageCost"] == m.RTManageCost)
        {
            TextBox tbx = (TextBox)UC_DetailView1.FindControl("PM_PromotorSalary_RTManageCost");
            if (tbx != null)
            {
                tbx.Enabled = false;
            }
        }
        if (m.State < 3)
        {
            #region 兼职导购的限定
            try
            {
                if (classfiy != 1 && classfiy != 2)   //非专职、非流导,认为是兼职导购
                {
                    DateTime Birthday;
                    if (DateTime.TryParse(p["Birthday"], out Birthday) && Birthday.AddYears(49) < DateTime.Now)
                    {
                        foreach (ListItem item in ddl_InsuranceMode.Items)
                        {
                            if (item.Value != "5" && item.Value != "8" && item.Value != "0")
                            {
                                item.Enabled = false;
                            }
                        }
                    }
                    SetControlsEnable(true);
                }
                else
                {
                    SetControlsEnable(false);
                }
            }
            catch { }
            #endregion


            ddl_BasePaySubsidyMode_SelectedIndexChanged(null, null);
            ddl_InsuranceMode_SelectedIndexChanged(null, null);
            ddl_MinimumWageMode_SelectedIndexChanged(null, null);
            ddl_BankType_SelectedIndexChanged(null, null);
        }
    }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorSalaryID"] == 0)
        {
            MessageBox.Show(this, "对不起,请您先保存后在发起申请");
            return;
        }
        PM_PromotorSalaryBLL bll = new PM_PromotorSalaryBLL((int)ViewState["PromotorSalaryID"]);
        PM_Promotor p = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;

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

        if (p["Classify"] != "2")       //非流导
        {
            IList<PM_PromotorInRetailer> retailers = PM_PromotorInRetailerBLL.GetModelList(" Promotor=" + ViewState["PromotorID"].ToString());
            //判断导购是否在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;
        PM_PromotorSalary salary = bll.Model;

        if (salary.BasePaySubsidy >= 1) bSalaryFlag = true;         //有底薪补贴
        if (salary.MinimumWageMode == 2) bSalaryFlag = true;   //特殊保底
        if (salary.InsuranceMode == 1 && salary.InsuranceSubsidy > 100) bSalaryFlag = true;     //社保补贴大于100元的
        #endregion

        NameValueCollection dataobjects = new NameValueCollection();
        dataobjects.Add("ID", p.ID.ToString());
        dataobjects.Add("PromotorSalaryID", ViewState["PromotorSalaryID"].ToString());
        dataobjects.Add("OrganizeCity", p.OrganizeCity.ToString());
        dataobjects.Add("SalaryFlag", bSalaryFlag ? "2" : "1");      //薪酬标志 1:薪酬标准内 2:薪酬标准外
        dataobjects.Add("StaffName", p.Name.ToString());
        dataobjects.Add("IsKAChannel", IsKAChannel ? "1" : "2");                 //是否KA卖场的导购

        int TaskID = EWF_TaskBLL.NewTask("Apply_PromotorSalary", (int)Session["UserID"], "调整导购员薪酬福利申请,姓名:" + p.Name,
            "~/SubModule/PM/PM_PromotorSalaryDetail.aspx?ID=" + bll.Model.ID.ToString(), dataobjects);
        if (TaskID > 0)
        {
            bll.Model.ApproveTask = TaskID;
            bll.Model.State = 2;
            bll.Update();
            // new EWF_TaskBLL(TaskID).Start();        //直接启动流程
        }

        Response.Redirect("~/SubModule/EWF/Apply.aspx?TaskID=" + TaskID.ToString());
    }
    /// <summary>
    /// 新增返利协议
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void bt_AddContract2_Click(object sender, EventArgs e)
    {
        bool flag = true;//允许生生成陈列协议

        string condition = " Client=" + ViewState["ClientID"].ToString();
        IList<PM_PromotorInRetailer> list = PM_PromotorInRetailerBLL.GetModelList(condition);
        for (int i = 0; i < list.Count; i++)
        {
            PM_PromotorBLL PM_PromotorBLL = new PM_PromotorBLL(list[i].Promotor);
            PM_Promotor promoter = PM_PromotorBLL.Model;
            int endMonth = AC_AccountMonthBLL.GetMonthByDate(promoter.EndWorkDate);
            int currentMonth = AC_AccountMonthBLL.GetCurrentMonth();
            //导购在职或导购离职判断离职日期,即使无销量也需生成基本工资
            if (promoter.Dimission == 1 || promoter.Dimission == 2 && endMonth >= currentMonth)//
            {
                flag = false;
                break;
            }
        }
        if (!flag)
        {
            MessageBox.Show(this, "当前门店存在导购或本月需生成导购工资");
            return;
        }

        bt_OK_Click(null, null);
        CM_ClientBLL _cm = new CM_ClientBLL((int)ViewState["ClientID"]);
        if (_cm.Model["Classification"] == "" || _cm.Model["Classification"] == "0")
        {
            MessageBox.Show(this, "请先选择门店归类再新增返利协议!");
            return;
        }
        //导购店添加返利协议
        if (_cm.Model["RTClassify"] == "3")
        {
            MessageBox.Show(this, _cm.CheckRealClassifyShowMessage(1));
            return;
        }
        Response.Redirect("RetailerContractDetail.aspx?ClientID=" + ViewState["ClientID"].ToString() + "&Classify=2");
    }
    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, "流程发起成功!");
            }
        }
    }
    private void BindData(int classfiy)
    {
        PM_Promotor p = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
        #region 获取当前导购标准薪资、保底薪资、导购管理费
        if ((int)ViewState["PromotorID"] > 0)
        {
            decimal basepay = 0, minumumwage = 0, rtmanagecost = 0;
            new PM_PromotorBLL((int)ViewState["PromotorID"]).GetStdPay(out basepay, out minumumwage, out rtmanagecost);
            ViewState["BasePay"] = basepay;
            ViewState["MinumumWage"] = minumumwage;
            ViewState["RTManageCost"] = rtmanagecost;
        }
        #endregion

        PM_PromotorSalary m = new PM_PromotorSalary();
        m.Promotor = (int)ViewState["PromotorID"];
        m.State = 1;
        m.InsertStaff = (int)Session["UserID"];
        m.RTManageCost = (decimal)ViewState["RTManageCost"];
        ddl_BasePayMode.Enabled = false;
        if (classfiy == 1 || classfiy == 2)
        {
            m.BasePayMode = 3;
        }
        else
        {

            m.SeniorityPayMode = 1;
            ddl_BankType.Items[3].Enabled = false;

            #region 抓取固定底薪标准
            decimal basepay = (decimal)ViewState["BasePay"];
            m.BasePay = basepay;
            #endregion
            Addr_OrganizeCityBLL _bll = new Addr_OrganizeCityBLL(p.OrganizeCity);
            if (_bll.IsChildOrganizeCity(7))//判断是否为华南区
            {
                ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(非华南)", "4"));
                ddl_BasePayMode.Items.Remove(new ListItem("兼职底薪", "3"));
                ddl_BasePayMode.Enabled = true;
                ddl_SalesType.Enabled = true;
                txt_BaseFeeRate.Enabled = true;

            }
            else
            {
                m.BasePayMode = 1;
            }

        }
        UC_DetailView1.BindData(m);

        if (m.RTManageCost > 0 && (decimal)ViewState["RTManageCost"] == m.RTManageCost)
        {
            TextBox tbx = (TextBox)UC_DetailView1.FindControl("PM_PromotorSalary_RTManageCost");
            if (tbx != null) tbx.Enabled = false;
        }
        if (m.State < 3)
        {
            #region 兼职导购的限定
            try
            {
                if (classfiy != 1 && classfiy != 2)   //非专职、非流导,认为是兼职导购
                {
                    DateTime Birthday;
                    if (DateTime.TryParse(p["Birthday"], out Birthday) && Birthday.AddYears(49) < DateTime.Now)
                    {
                        foreach (ListItem item in ddl_InsuranceMode.Items)
                        {
                            if (item.Value != "5" && item.Value != "8" && item.Value != "0")
                            {
                                item.Enabled = false;
                            }
                        }
                    }
                    SetControlsEnable(true);
                }
                else
                {
                    SetControlsEnable(false);

                }

            }
            catch { }
            #endregion

            ddl_BasePaySubsidyMode_SelectedIndexChanged(null, null);
            ddl_InsuranceMode_SelectedIndexChanged(null, null);
            ddl_MinimumWageMode_SelectedIndexChanged(null, null);
            ddl_BankType_SelectedIndexChanged(null, null);
        }
    }
Ejemplo n.º 33
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime minday, maxday=DateTime.Now;
            HSSFWorkbook hssfworkbook;
            FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
            hssfworkbook = new HSSFWorkbook(file);
            ISheet sheet = hssfworkbook.GetSheetAt(0);
            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            int i = 0, count = getRowsCount()-1;
            bool flag = true;
            try
            {
                IRow headerRow = sheet.GetRow(0);
                if (headerRow.GetCell(0).ToString() != "零售商ID" ||
                    headerRow.GetCell(1).ToString() != "零售商编号" ||
                    headerRow.GetCell(2).ToString() != "零售商名称" ||
                    headerRow.GetCell(3).ToString() != "零售商分类" ||
                    headerRow.GetCell(4).ToString() != "归属月份" ||
                    headerRow.GetCell(5).ToString() != "导购ID" ||
                    headerRow.GetCell(6).ToString() != "导购姓名")
                {

                    flag = false;
                }
                if (!flag)
                {
                    MessageBox.Show(this, "表头(1~7列)错误!");
                    return;
                }
                int column = getColumnCount(headerRow) + 1;
                int month = 0;
                rows.MoveNext();

                while (rows.MoveNext())
                {
                    int datacolumn = 7;

                    i++;
                    HSSFRow row = (HSSFRow)rows.Current;
                    if (row.GetCell(0).ToString() == "")
                    {
                        break;
                    }

                    int clientid = 0; int promotorid = 0;
                    if (!int.TryParse(row.GetCell(0).ToString(), out clientid))
                    {
                        errormessage += "零售商:" + row.GetCell(2).ToString() + "的ID错误;\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    CM_Client client = new CM_ClientBLL(clientid).Model;

                    if (client == null)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "零售商在系统中不存在!\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    if (int.TryParse(row.GetCell(5).ToString(), out promotorid))
                    {
                        PM_Promotor pm = new PM_PromotorBLL(promotorid).Model;
                        if (pm == null)
                        {
                            errormessage += "导购ID号:" + promotorid.ToString() + "导购在系统中不存在!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }

                    }

                    if (month == 0 && headerRow.GetCell(4).ToString() == "归属月份")
                    {
                        IList<AC_AccountMonth> _monthlist = AC_AccountMonthBLL.GetModelList("Name='" + row.GetCell(4).ToString() + "'");
                        if (_monthlist.Count > 0)
                        {
                            month = _monthlist[0].ID;
                            minday = _monthlist[0].BeginDate;
                            maxday = DateTime.Today < _monthlist[0].EndDate ? DateTime.Today : _monthlist[0].EndDate;
                        }
                        else
                        {
                            errormessage += "会计月错误;\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                    }
                    #region 组织销量头
                    SVM_SalesVolumeBLL bll = null;
                    string conditon = "";

                    conditon = "Supplier=" + clientid.ToString()
                  + "AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',4)='7' AND Type=3 AND AccountMonth=" + month.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                  + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString();

                    IList<SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon);
                    if (svmlists.Count > 0)
                    {
                        if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
                        {
                            errormessage += "ID号:" + row.GetCell(0).ToString() + "," + client.FullName
                                           + ",导购:" + row.GetCell(6).ToString() + "  当月的销量单" + "已审核,不可再次导入!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                        if (svmlists.Count == 1)
                        {
                            bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                            bll.Items.Clear();
                        }
                    }
                    if (bll == null)
                    {
                        bll = new SVM_SalesVolumeBLL();

                        bll.Model.Client = 0;
                        bll.Model.Supplier = client.ID;
                        bll.Model.Promotor = promotorid;
                        bll.Model.Type = 3;

                        bll.Model.OrganizeCity = client.OrganizeCity;
                        bll.Model.AccountMonth = month;
                        bll.Model.SalesDate = maxday;
                        bll.Model.ApproveFlag = 2;
                        bll.Model.Flag = 1;             //成品销售
                        bll.Model["IsCXP"] = "N";
                        bll.Model.InsertStaff = 1;
                        bll.Model.Remark = "线下补录导入";

                    }
                    #endregion
                    bll.Model["SubmitFlag"] = "1";
                    bll.Model["DataSource"] = "7";
                    IList<SVM_SalesVolume_Detail> details = new List<SVM_SalesVolume_Detail>();
                    bool wrongflag = false;//判断导入数量是否正常(除空导致的异常)
                    int quantity = 0;
                    bool isnumber = false;
                    while (true)
                    {

                        PDT_Product product = null;
                        quantity = 0;

                        if (headerRow.GetCell(datacolumn) == null||headerRow.GetCell(datacolumn).CellType == CellType.BLANK || headerRow.GetCell(datacolumn).ToString() == string.Empty)
                        {
                            break;
                        }

                        IList<PDT_Product> products = PDT_ProductBLL.GetModelList("ShortName='" + headerRow.GetCell(datacolumn).ToString() + "' AND State=1");
                        if (products.Count > 0)
                        {
                            product = products[0];
                        }
                        else
                        {
                            errormessage += "产品名称:" + headerRow.GetCell(datacolumn).ToString() + "在产品列表中不存在!\r\n";
                            datacolumn++;
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }

                        if ((product != null) && row.GetCell(datacolumn).CellType != CellType.BLANK)
                        {
                            int.TryParse(row.GetCell(datacolumn).ToString(), out quantity);
                            if (int.TryParse(row.GetCell(datacolumn).ToString(), out quantity) && !isnumber)
                            {
                                isnumber = true;
                            }
                            if (quantity != 0 && quantity <= 5000 && quantity >= 0)
                            {

                                decimal factoryprice = 0, salesprice = 0;
                                PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice);

                                if (factoryprice == 0) factoryprice = product.FactoryPrice;
                                if (salesprice == 0) salesprice = product.NetPrice;

                                SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                                detail.Product = product.ID;
                                detail.FactoryPrice = factoryprice;
                                detail.SalesPrice = salesprice;
                                detail.Quantity = quantity;
                                details.Add(detail);
                            }
                            else if (row.GetCell(datacolumn).CellType != CellType.BLANK && (row.GetCell(datacolumn).ToString() != "0"))
                            {
                                wrongflag = true;
                                break;
                            }
                            else if (quantity < 0)
                            {
                                wrongflag = true;
                                break;
                            }
                        }
                        datacolumn++;

                    }
                    if (wrongflag)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "," + client.FullName
                                     + ",导购:" + row.GetCell(6).ToString() + "  当月的线下补录销量单"
                                          + "未能导入!产品名称:" + headerRow.GetCell(datacolumn).ToString() + "数量填写错误。\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }

                    #region 更新销量至数据库
                    if (bll.Model.ID > 0)
                    {
                        if (details.Count > 0)
                        {
                            bll.DeleteDetail();     //先清除原先导入的数据
                            bll.Items = details;
                            bll.Model.UpdateStaff = 1;
                            bll.AddDetail();
                            bll.Update();

                            string message = " ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                                + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + "的销量单" + "被成功更新!产品SKU数:"
                          + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                        if (details.Count == 0 && isnumber)
                        {
                            bll.DeleteDetail();
                        }

                    }
                    else
                    {
                        if (details.Count > 0 || svmlists.Count == 0)    //没有产品也新增一条空销量头
                        {
                            bll.Items = details;
                            if (bll.Add() > 0)
                            {
                                foreach (SVM_SalesVolume m in svmlists)
                                {
                                    bll = new SVM_SalesVolumeBLL(m.ID);
                                    bll.DeleteDetail();
                                    bll.Delete();
                                }
                            }
                            string message = "ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                          + "的销量单" + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                         + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                    }
                    #endregion
                    ((BackgroundWorker)sender).ReportProgress(i * 100 / count, i);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
            finally
            {
                FileStream writefile = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
                hssfworkbook.Write(writefile);
                writefile.Close();

                sheet = null;
            }
        }
Ejemplo n.º 34
0
        private void threadStartImport(BackgroundWorker worker, DoWorkEventArgs e)
        {
            DataTable dt_OfficialCity = Addr_OfficialCityBLL.GetAllOfficialCity();
            DataTable dt_OrganizeCity = Addr_OrganizeCityBLL.GetAllOrganizeCity();
            DataTable dt_Position = Org_PositionBLL.GetAllPostion();
            bool bFind = false;

            StringBuilder _xhs_success = new StringBuilder("");//成功导入的记录序号(用于定期批量更新导入标志)
            string XH = "";

            #region 导入销售人员资料
            try
            {
                if (cbx_Promotor.Checked)
                {
                    lb_Count.Text = dt_SalesStaff.Rows.Count.ToString();
                    tabControl1.SelectedIndex = 0;
                    XH = "";
                    for (int i = 0; i < dt_SalesStaff.Rows.Count; i++)
                    {
                        worker.ReportProgress((i + 1) * 100 / this.dt_SalesStaff.Rows.Count, i);
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }
                        XH = dt_SalesStaff.Rows[i]["序号"].ToString();
                        Org_StaffBLL staff = new Org_StaffBLL();

                        //序号
                        if (dt_SalesStaff.Rows[i]["员工工号"].ToString() != "")
                            staff.Model["StaffCode"] = dt_SalesStaff.Rows[i]["员工工号"].ToString();
                        else
                            staff.Model["StaffCode"] = FormatClientCode('S', dt_SalesStaff.Rows[i]["序号"].ToString().Trim(), dt_SalesStaff.Rows[i]["管理片区代码"].ToString().Trim());

                        #region 判断数据是否重复
                        if (Org_StaffBLL.GetStaffList("StaffCode = '" + staff.Model["StaffCode"] + "'").Count > 0)
                        {
                            UpdateImportFlag(1, i, "导入失败,数据重复!");
                            continue;
                        }
                        #endregion

                        //姓名
                        staff.Model["RealName"] = dt_SalesStaff.Rows[i]["姓名"].ToString().Trim();

                        //职务
                        DataRow[] rows_Position = dt_Position.Select("Name = '" + dt_SalesStaff.Rows[i]["职务"].ToString().Trim() + "'");
                        if (rows_Position.Length == 0)
                        {
                            UpdateImportFlag(1, i, "导入失败,职务在系统字典中不存在!");
                            continue;
                        }
                        else
                            staff.Model["Position"] = rows_Position[0]["ID"].ToString().Trim();

                        //管理片区代码
                        DataRow[] rows_OrganizeCity = dt_OrganizeCity.Select("Code='" + dt_SalesStaff.Rows[i]["管理片区代码"].ToString().Trim() + "'");
                        if (rows_OrganizeCity.Length == 0)
                        {
                            UpdateImportFlag(1, i, "导入失败,管理片区代码在系统字典中不存在!");
                            continue;
                        }
                        else
                            staff.Model["OrganizeCity"] = rows_OrganizeCity[0]["ID"].ToString().Trim();

                        //性别
                        staff.Model["Sex"] = dt_SalesStaff.Rows[i]["性别"].ToString();
                        //bFind = false;
                        //foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("Pub_Sex").Values)
                        //{
                        //    if (item.Name == dt_SalesStaff.Rows[i]["性别"].ToString().Trim())
                        //    {
                        //        staff.Model["Sex"] = item.Code;
                        //        bFind = true;
                        //        break;
                        //    }
                        //}
                        //if (!bFind)
                        //{
                        //    UpdateImportFlag(1, i, "导入失败,性别在系统字典中不存在!");
                        //    continue;
                        //}

                        //联系电话
                        staff.Model["TeleNum"] = dt_SalesStaff.Rows[i]["联系电话"].ToString().Trim();

                        //手机
                        staff.Model["Mobile"] = dt_SalesStaff.Rows[i]["手机"].ToString().Trim();

                        //城市
                        string cityname = dt_SalesStaff.Rows[i]["城市"].ToString().Trim();
                        if (cityname.Length > 3) cityname = cityname.Substring(0, 3);
                        DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + cityname + "%'");
                        if (rows_OfficialCity.Length == 0)
                        {
                            UpdateImportFlag(1, i, "导入失败,城市在系统字典中不存在!");
                            continue;
                        }
                        else
                            staff.Model["OfficialCity"] = rows_OfficialCity[0]["ID"].ToString().Trim();

                        //家庭地址
                        staff.Model["Address"] = dt_SalesStaff.Rows[i]["家庭地址"].ToString().Trim();

                        //身份证号
                        staff.Model["IDCode"] = dt_SalesStaff.Rows[i]["身份证号"].ToString().Trim();

                        //上岗时间
                        if (dt_SalesStaff.Rows[i]["上岗时间"].ToString().Trim() != "")
                            staff.Model["BeginWorkTime"] = dt_SalesStaff.Rows[i]["上岗时间"].ToString().Trim();

                        //离岗时间
                        if (dt_SalesStaff.Rows[i]["离岗时间"].ToString().Trim() != "")
                            staff.Model["EndWorkTime"] = dt_SalesStaff.Rows[i]["离岗时间"].ToString().Trim();

                        //银行类别
                        staff.Model["BankName"] = dt_SalesStaff.Rows[i]["银行类别"].ToString().Trim();

                        //工资卡号
                        staff.Model["BankAccount"] = dt_SalesStaff.Rows[i]["工资卡号"].ToString().Trim();

                        //在职标志
                        staff.Model["Dimission"] = "1";

                        int iret = staff.Add();
                        if (iret > 0)
                        {
                            _xhs_success.Append(XH + ",");
                            //UpdateImportFlag(1, i, "导入成功,ID=" + iret.ToString());

                            #region 创建用户登录帐户
                            string username = staff.Model.RealName;
                            string pwd = "000000";
                            MembershipUserCollection haveusers = Membership.FindUsersByName(username);
                            if (haveusers.Count > 0)
                            {
                                username += "_" + haveusers.Count.ToString();
                            }
                            if (staff.Model["IDCode"].Length >= 6)
                                pwd = staff.Model["IDCode"].Substring(staff.Model["IDCode"].Length - 6);

                            MembershipUser user = Membership.CreateUser(username, pwd, "*****@*****.**");

                            if (user != null)
                            {
                                UserBLL.Membership_SetStaffID(user.UserName, iret);

                                Roles.AddUserToRole(user.UserName, " 全体员工");
                            }
                            #endregion
                        }
                        else
                            UpdateImportFlag(1, i, "导入失败,写入数据库失败!");
                    }
                    UpdateSuccess(_xhs_success.ToString(), 1);
                }
            }
            catch (System.Exception err)
            {
                UpdateSuccess(_xhs_success.ToString(), 1);
                MessageBox.Show(err.Source + "~r~n" + err.StackTrace, err.Message);
            }
            #endregion

            Thread.Sleep(1000);

            #region 导入经销商
            try
            {
                if (checkBox2.Checked)
                {
                    lb_Count.Text = dt_Distributor.Rows.Count.ToString();
                    tabControl1.SelectedIndex = 1;
                    XH = "";
                    for (int i = 0; i < dt_Distributor.Rows.Count; i++)
                    {
                        worker.ReportProgress((i + 1) * 100 / this.dt_Distributor.Rows.Count, i);

                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }
                        XH = dt_Distributor.Rows[i]["序号"].ToString();
                        CM_ClientBLL client = new CM_ClientBLL();

                        client.Model.ClientType = 2;    //经销商

                        #region 编号
                        if (dt_Distributor.Rows[i]["经销商编号"].ToString().Trim() != "")
                            client.Model["Code"] = dt_Distributor.Rows[i]["经销商编号"].ToString().Trim();
                        else
                            client.Model["Code"] = FormatClientCode('D', dt_Distributor.Rows[i]["序号"].ToString().Trim(), dt_Distributor.Rows[i]["管理片区代码"].ToString().Trim());

                        #region 判断数据是否重复
                        if (CM_ClientBLL.GetModelList("Code = '" + client.Model["Code"] + "'").Count > 0)
                        {
                            UpdateImportFlag(2, i, "导入失败,数据重复!");
                            continue;
                        }
                        #endregion
                        #endregion

                        //全称
                        client.Model["FullName"] = dt_Distributor.Rows[i]["全称"].ToString().Trim();
                        client.Model["ShortName"] = dt_Distributor.Rows[i]["简称"].ToString().Trim();

                        #region 管理片区代码
                        DataRow[] rows_OrganizeCity = dt_OrganizeCity.Select("Code='" + dt_Distributor.Rows[i]["管理片区代码"].ToString().Trim() + "'");
                        if (rows_OrganizeCity.Length == 0)
                        {
                            UpdateImportFlag(2, i, "导入失败,管理片区代码在系统字典中不存在!");
                            continue;
                        }
                        else
                            client.Model["OrganizeCity"] = rows_OrganizeCity[0]["ID"].ToString().Trim();
                        #endregion

                        #region 联系方式
                        client.Model["TeleNum"] = dt_Distributor.Rows[i]["固定电话"].ToString().Trim();
                        client.Model["Fax"] = dt_Distributor.Rows[i]["传真"].ToString().Trim();
                        client.Model["PostCode"] = dt_Distributor.Rows[i]["邮编"].ToString().Trim();
                        client.Model["Email"] = dt_Distributor.Rows[i]["Email"].ToString().Trim();
                        client.Model["Address"] = dt_Distributor.Rows[i]["地址"].ToString().Trim();
                        #endregion

                        #region 所在城市
                        string cityname = dt_Distributor.Rows[i]["城市"].ToString().Trim();
                        string areaname = dt_Distributor.Rows[i]["县城"].ToString().Trim();
                        if (areaname != "")
                        {
                            DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + areaname + "%'");
                            if (rows_OfficialCity.Length == 1)
                                client.Model.OfficalCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                        }
                        if (cityname != "" && client.Model.OfficalCity == 0)
                        {
                            DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + cityname + "%'");
                            if (rows_OfficialCity.Length == 1)
                                client.Model.OfficalCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                        }

                        if (client.Model["TeleNum"] != "" && client.Model.OfficalCity == 0)
                        {
                            Addr_OfficialCity city = null;
                            city = Addr_OfficialCityBLL.GetCityByTeleNumOrPostCode(client.Model["TeleNum"]);
                            if (city != null) client.Model.OfficalCity = city.ID;
                        }

                        if (client.Model["PostCode"] != "" && client.Model.OfficalCity == 0)
                        {
                            Addr_OfficialCity city = null;
                            city = Addr_OfficialCityBLL.GetCityByTeleNumOrPostCode(client.Model["PostCode"]);
                            if (city != null) client.Model.OfficalCity = city.ID;
                        }

                        if (dt_Distributor.Rows[i]["手机"].ToString().Trim() != "" && client.Model.OfficalCity == 0)
                        {
                            Addr_OfficialCity city = null;
                            city = Addr_OfficialCityBLL.GetCityByTeleNumOrPostCode(dt_Distributor.Rows[i]["手机"].ToString().Trim());
                            if (city != null) client.Model.OfficalCity = city.ID;
                        }

                        if (client.Model.OfficalCity == 0)
                        {
                            UpdateImportFlag(2, i, "导入失败,城市在系统字典中不存在!");
                            continue;
                        }
                        #endregion

                        #region 经销商类别
                        bFind = false;
                        foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_DI_Classify").Values)
                        {
                            if (item.Name == dt_Distributor.Rows[i]["类别"].ToString().Trim())
                            {
                                client.Model["DIClassify"] = item.Code;
                                bFind = true;
                                break;
                            }
                        }
                        if (!bFind)
                        {
                            UpdateImportFlag(2, i, "导入失败,类别在系统字典中不存在!");
                            continue;
                        }

                        #endregion

                        #region 活跃状态
                        bFind = false;
                        foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_ActiveFlag").Values)
                        {
                            if (item.Name == dt_Distributor.Rows[i]["活跃状态"].ToString().Trim())
                            {
                                client.Model["ActiveFlag"] = item.Code;
                                bFind = true;
                                break;
                            }
                        }
                        if (!bFind)
                        {
                            UpdateImportFlag(2, i, "导入失败,活跃状态在系统字典中不存在!");
                            continue;
                        }
                        #endregion

                        #region 纳税类型
                        if (dt_Distributor.Rows[i]["纳税类型"].ToString().Trim() != "")
                        {
                            bFind = false;
                            foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_TaxesClassify").Values)
                            {
                                if (item.Name == dt_Distributor.Rows[i]["纳税类型"].ToString().Trim())
                                {
                                    client.Model["TaxesClassify"] = item.Code;
                                    bFind = true;
                                    break;
                                }
                            }
                            if (!bFind)
                            {
                                UpdateImportFlag(2, i, "导入失败,纳税类型在系统字典中不存在!");
                                continue;
                            }
                        }
                        #endregion

                        #region 市场类型
                        if (dt_Distributor.Rows[i]["市场类型"].ToString().Trim() != "")
                        {
                            bFind = false;
                            foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_MarketType").Values)
                            {
                                if (item.Name == dt_Distributor.Rows[i]["市场类型"].ToString().Trim())
                                {
                                    client.Model["MarketType"] = item.Code;
                                    bFind = true;
                                    break;
                                }
                            }
                            if (!bFind)
                            {
                                UpdateImportFlag(2, i, "导入失败,市场类型在系统字典中不存在!");
                                continue;
                            }
                        }
                        #endregion

                        #region 主营渠道
                        if (dt_Distributor.Rows[i]["主营渠道"].ToString().Trim() != "")
                        {
                            bFind = false;
                            foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_RT_Channel").Values)
                            {
                                if (item.Name == dt_Distributor.Rows[i]["主营渠道"].ToString().Trim())
                                {
                                    client.Model["RTChannel"] = item.Code;
                                    bFind = true;
                                    break;
                                }
                            }
                            if (!bFind)
                            {
                                UpdateImportFlag(2, i, "导入失败,主营渠道在系统字典中不存在!");
                                continue;
                            }
                        }
                        #endregion

                        //开始合作时间
                        if (dt_Distributor.Rows[i]["开始合作时间"].ToString().Trim() != "")
                            client.Model["OpenTime"] = dt_Distributor.Rows[i]["开始合作时间"].ToString().Trim();

                        //覆盖区域
                        client.Model["CoverageArea"] = dt_Distributor.Rows[i]["覆盖区域"].ToString().Trim();

                        //主要销售奶粉品牌
                        client.Model["MostlyBrand"] = dt_Distributor.Rows[i]["主要销售奶粉品牌"].ToString().Trim();

                        //开户行类别
                        client.Model["BankName"] = dt_Distributor.Rows[i]["开户行类别"].ToString().Trim();
                        //开户行账号
                        client.Model["BankAccountNo"] = dt_Distributor.Rows[i]["开户行账号"].ToString().Trim();

                        #region 隶属一级商编号
                        if (client.Model["DIClassify"] != "1" && dt_Distributor.Rows[i]["隶属一级商编号"].ToString().Trim() != "")
                        {
                            IList<CM_Client> lists = CM_ClientBLL.GetModelList("Code='" + dt_Distributor.Rows[i]["隶属一级商编号"].ToString().Trim() + "'");
                            if (lists.Count > 0)
                            {
                                client.Model["Supplier"] = lists[0]["ID"];
                            }
                            else
                            {
                                //UpdateImportFlag(2, i, "导入失败,隶属一级商编号在客户中不存在!");
                                //continue;
                            }
                        }
                        else if (client.Model["DIClassify"] == "1")
                        {
                            client.Model.Supplier = 1223; //总部仓库
                        }
                        #endregion

                        #region 责任业代
                        bool fail1 = false;
                        if (dt_Distributor.Rows[i]["责任业代"].ToString().Trim() != "")
                        {
                            string cityids = new Addr_OrganizeCityBLL(client.Model.OrganizeCity).GetAllChildNodeIDs();
                            if (cityids != "") cityids += ",";
                            cityids += client.Model.OrganizeCity.ToString();

                            IList<Org_Staff> staffs = Org_StaffBLL.GetStaffList("OrganizeCity IN(" + cityids + ") AND RealName='" + dt_Distributor.Rows[i]["责任业代"].ToString().Trim() + "' AND Dimission=1");
                            if (staffs.Count == 1)
                                client.Model.ClientManager = staffs[0].ID;
                            else
                            {
                                fail1 = true;
                                //UpdateImportFlag(2, i, "导入失败,责任业代在员工表中不存在!" + staffs.Count.ToString());
                                //continue;
                            }
                        }
                        #endregion

                        client.Model.ApproveFlag = 1;
                        int iret = client.Add();
                        if (iret > 0)
                        {
                            //_xhs_success.Append(XH + ",");
                            if (!fail1)
                                UpdateImportFlag(2, i, "导入成功,ID=" + iret.ToString());
                            else
                                UpdateImportFlag(2, i, "部分导入成功,责任业代在员工表中不存在!");
                        }
                        else
                        {
                            UpdateImportFlag(2, i, "导入失败,写入数据库失败!");
                            continue;
                        }

                        #region 加入联系人
                        CM_LinkManBLL linkman = new CM_LinkManBLL();
                        linkman.Model.ClientID = iret;

                        #region 负责人
                        if (dt_Distributor.Rows[i]["负责人"].ToString().Trim() != "")
                        {
                            linkman.Model["Name"] = dt_Distributor.Rows[i]["负责人"].ToString().Trim();

                            #region 负责人职务
                            if (dt_Distributor.Rows[i]["负责人职务"].ToString().Trim() != "")
                            {
                                bFind = false;
                                foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_LinkManJob").Values)
                                {
                                    if (item.Name == dt_Distributor.Rows[i]["负责人职务"].ToString().Trim())
                                    {
                                        linkman.Model["Job"] = item.Code;
                                        bFind = true;
                                        break;
                                    }
                                }
                            }
                            #endregion

                            //固定电话
                            linkman.Model["OfficeTeleNum"] = dt_Distributor.Rows[i]["固定电话"].ToString().Trim();

                            //手机
                            linkman.Model["Mobile"] = dt_Distributor.Rows[i]["手机"].ToString().Trim();
                            iret = linkman.Add();

                            if (iret > 0)
                            {
                                client.Model["ChiefLinkMan"] = iret.ToString();
                                client.Update();
                            }
                        }
                        #endregion

                        #region 法人
                        if (dt_Distributor.Rows[i]["负责人"].ToString().Trim() != "")
                        {
                            linkman.Model["Name"] = dt_Distributor.Rows[i]["法人代表"].ToString().Trim();
                            linkman.Model["Job"] = "2";       //法人代表
                            linkman.Model["OfficeTeleNum"] = dt_Distributor.Rows[i]["法人联系电话"].ToString().Trim();

                            if (linkman.Model["OfficeTeleNum"].StartsWith("1"))
                                linkman.Model["Mobile"] = linkman.Model["OfficeTeleNum"];

                            linkman.Add();
                        }
                        #endregion

                        #endregion
                    }
                    //UpdateSuccess(_xhs_success.ToString(), 2);
                }
            }
            catch (System.Exception err)
            {
                UpdateSuccess(_xhs_success.ToString(), 1);
                MessageBox.Show(err.Source + "~r~n" + err.StackTrace, err.Message);
            }
            #endregion

            Thread.Sleep(1000);

            #region 导入终端门店资料表
            StringBuilder _xhs_rt_fail1 = new StringBuilder("");
            StringBuilder _xhs_rt_fail2 = new StringBuilder("");
            try
            {
                if (checkBox3.Checked)
                {
                    lb_Count.Text = dt_Retailer.Rows.Count.ToString();
                    tabControl1.SelectedIndex = 2;
                    XH = "";
                    for (int i = 0; i < dt_Retailer.Rows.Count; i++)
                    {
                        worker.ReportProgress((i + 1) * 100 / this.dt_Retailer.Rows.Count, i);
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }

                        bool bsuccess = true;
                        XH = dt_Retailer.Rows[i]["序号"].ToString();
                        CM_ClientBLL client = new CM_ClientBLL();

                        client.Model.ClientType = 3;    //终端门店

                        #region 序号
                        client.Model["Code"] = dt_Retailer.Rows[i]["门店编码"].ToString().Trim();

                        #region 判断数据是否重复
                        if (CM_ClientBLL.GetModelList("Code = '" + client.Model["Code"] + "'").Count > 0)
                        {
                            UpdateImportFlag(3, i, "导入失败,数据重复!");
                            continue;
                        }
                        #endregion
                        #endregion

                        //连锁店名称
                        client.Model["ChainStoreName"] = dt_Retailer.Rows[i]["连锁店名称"].ToString().Trim();

                        //门店全称
                        client.Model["FullName"] = dt_Retailer.Rows[i]["门店全称"].ToString().Trim();

                        //门店简称
                        client.Model["ShortName"] = dt_Retailer.Rows[i]["门店简称"].ToString().Trim();
                        if (client.Model.ShortName == "") client.Model.ShortName = client.Model.FullName;

                        #region 管理片区代码
                        DataRow[] rows_OrganizeCity = dt_OrganizeCity.Select("Code='" + dt_Retailer.Rows[i]["管理片区代码"].ToString().Trim() + "'");
                        if (rows_OrganizeCity.Length == 0)
                        {
                            UpdateImportFlag(3, i, "导入失败,管理片区代码在系统字典中不存在!");
                            continue;
                        }
                        else
                            client.Model["OrganizeCity"] = rows_OrganizeCity[0]["ID"].ToString().Trim();
                        #endregion

                        //固定电话
                        client.Model["TeleNum"] = dt_Retailer.Rows[i]["固定电话"].ToString().Trim();
                        if (client.Model["TeleNum"] == "") client.Model["TeleNum"] = dt_Retailer.Rows[i]["联系人手机"].ToString().Trim();

                        //门店地址
                        client.Model["Address"] = dt_Retailer.Rows[i]["门店地址"].ToString().Trim();

                        #region 所在城市
                        string cityname = dt_Retailer.Rows[i]["城市"].ToString().Trim();
                        string areaname = dt_Retailer.Rows[i]["县城"].ToString().Trim();
                        string townname = dt_Retailer.Rows[i]["乡镇"].ToString().Trim();
                        if (townname != "")
                        {
                            DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + townname + "%'");
                            if (rows_OfficialCity.Length == 1)
                                client.Model.OfficalCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                        }
                        if (areaname != "" && client.Model.OfficalCity == 0)
                        {
                            DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + areaname + "%'");
                            if (rows_OfficialCity.Length == 1)
                                client.Model.OfficalCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                        }
                        if (cityname != "" && client.Model.OfficalCity == 0)
                        {
                            DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + cityname + "%'");
                            if (rows_OfficialCity.Length > 0)
                                client.Model.OfficalCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                        }

                        if (client.Model["TeleNum"] != "" && client.Model.OfficalCity == 0)
                        {
                            Addr_OfficialCity city = null;
                            city = Addr_OfficialCityBLL.GetCityByTeleNumOrPostCode(client.Model["TeleNum"]);
                            if (city != null) client.Model.OfficalCity = city.ID;
                        }

                        if (client.Model.OfficalCity == 0)
                        {
                            UpdateImportFlag(3, i, "导入失败,城市在系统字典中不存在!");
                            continue;
                        }
                        #endregion

                        #region 门店渠道
                        if (dt_Retailer.Rows[i]["门店渠道"].ToString().Trim() != "")
                        {
                            bFind = false;
                            foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_RT_Channel").Values)
                            {
                                if (item.Name == dt_Retailer.Rows[i]["门店渠道"].ToString().Trim().ToUpper())
                                {
                                    client.Model["RTChannel"] = item.Code;
                                    bFind = true;
                                    break;
                                }
                            }
                            if (!bFind)
                            {
                                UpdateImportFlag(3, i, "导入失败,门店渠道在系统字典中不存在!");
                                continue;
                            }
                        }
                        #endregion

                        #region 门店类型
                        if (dt_Retailer.Rows[i]["门店类型"].ToString().Trim() != "")
                        {
                            bFind = false;
                            foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_RT_Classify").Values)
                            {
                                if (item.Name == dt_Retailer.Rows[i]["门店类型"].ToString().Trim())
                                {
                                    client.Model["RTClassify"] = item.Code;
                                    bFind = true;
                                    break;
                                }
                            }
                            if (!bFind)
                            {
                                UpdateImportFlag(3, i, "导入失败,门店类型在系统字典中不存在!");
                                continue;
                            }
                        }
                        #endregion

                        #region 销售代表
                        if (dt_Retailer.Rows[i]["销售代表工号"].ToString().Trim() != "")
                        {
                            IList<Org_Staff> staffs = Org_StaffBLL.GetStaffList("StaffCode='" + dt_Retailer.Rows[i]["销售代表工号"].ToString().Trim() + "' AND Dimission=1");
                            if (staffs.Count > 1) staffs = Org_StaffBLL.GetStaffList("StaffCode='" + dt_Retailer.Rows[i]["销售代表工号"].ToString().Trim() + "' AND Dimission=1 AND RealName='" + dt_Retailer.Rows[i]["销售代表"].ToString().Trim() + "'");

                            if (staffs.Count == 0)
                            {
                                _xhs_rt_fail2.Append(XH + ",");
                                bsuccess = false;
                                //UpdateImportFlag(3, i, "导入失败,销售代表在员工中不存在!");
                                //continue;
                            }
                            else if (staffs.Count > 1)
                            {
                                _xhs_rt_fail2.Append(XH + ",");
                                bsuccess = false;
                                //UpdateImportFlag(3, i, "导入失败,销售代表在员工中有多个相同姓名的员工!");
                                //continue;
                            }
                            else
                            {
                                client.Model["ClientManager"] = staffs[0]["ID"];
                            }
                        }
                        #endregion

                        #region 送货经销商编号
                        IList<CM_Client> clients = CM_ClientBLL.GetModelList("Code='" + dt_Retailer.Rows[i]["送货经销商编号"].ToString().Trim() + "'");
                        if (clients.Count == 0)
                        {
                            _xhs_rt_fail1.Append(XH + ",");
                            bsuccess = false;
                            //UpdateImportFlag(3, i, "导入失败,送货经销商编号在客户中不存在!");
                            //continue;
                        }
                        else if (clients.Count > 1)
                        {
                            _xhs_rt_fail1.Append(XH + ",");
                            bsuccess = false;
                            //UpdateImportFlag(3, i, "导入失败,送货经销商编号在客户中有多个相同编号的客户!");
                            //continue;
                        }
                        else
                        {
                            client.Model["Supplier"] = clients[0]["ID"];
                        }
                        #endregion

                        client.Model["Salesroom"] = dt_Retailer.Rows[i]["奶粉月容量"].ToString().Trim();
                        client.Model["BusinessArea"] = dt_Retailer.Rows[i]["卖场面积"].ToString().Trim();

                        client.Model["BankName"] = dt_Retailer.Rows[i]["开户行全称"].ToString().Trim();
                        client.Model["AccountName"] = dt_Retailer.Rows[i]["开户名"].ToString().Trim();
                        client.Model["BankAccountNo"] = dt_Retailer.Rows[i]["卡账号"].ToString().Trim();

                        //活跃状态
                        client.Model["ActiveFlag"] = "1";
                        client.Model.ApproveFlag = 1;

                        int iret = client.Add();
                        if (iret > 0)
                        {
                            if (bsuccess) _xhs_success.Append(XH + ",");
                            if (_xhs_success.Length >= 10000)
                            {
                                UpdateSuccess(_xhs_success.ToString(), 3);
                                UpdateFail1(_xhs_rt_fail1.ToString());
                                UpdateFail2(_xhs_rt_fail2.ToString());

                                _xhs_success = new StringBuilder("");
                                _xhs_rt_fail1 = new StringBuilder("");
                                _xhs_rt_fail2 = new StringBuilder("");
                            }
                            //UpdateImportFlag(3, i, "导入成功,ID=" + iret.ToString());
                        }
                        else
                        {
                            UpdateImportFlag(3, i, "导入失败,写入数据库失败!");
                            continue;
                        }

                        #region 加入联系人
                        CM_LinkManBLL linkman = new CM_LinkManBLL();
                        linkman.Model.ClientID = iret;

                        //门店联系人
                        linkman.Model["Name"] = dt_Retailer.Rows[i]["门店联系人"].ToString().Trim();
                        if (linkman.Model["Name"] == "") linkman.Model.Name = "无";

                        //联系人职务
                        #region 联系人职务
                        if (dt_Retailer.Rows[i]["联系人职务"].ToString().Trim() != "")
                        {
                            bFind = false;
                            foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("CM_LinkManJob").Values)
                            {
                                if (item.Name == dt_Retailer.Rows[i]["联系人职务"].ToString().Trim())
                                {
                                    linkman.Model["Job"] = item.Code;
                                    bFind = true;
                                    break;
                                }
                            }
                        }
                        #endregion

                        //联系人固定电话
                        linkman.Model["OfficeTeleNum"] = dt_Retailer.Rows[i]["联系人固定电话"].ToString().Trim();

                        //联系人手机
                        linkman.Model["Mobile"] = dt_Retailer.Rows[i]["联系人手机"].ToString().Trim();

                        if (linkman.Model.Name == "无" && linkman.Model["OfficeTeleNum"] == "" && linkman.Model["Mobile"] == "")
                        {
                        }
                        else
                        {
                            iret = linkman.Add();

                            if (iret > 0)
                            {
                                client.Model["ChiefLinkMan"] = iret.ToString();
                                client.Update();
                            }
                        }
                        #endregion
                    }
                    UpdateSuccess(_xhs_success.ToString(), 3);
                    UpdateFail1(_xhs_rt_fail1.ToString());
                    UpdateFail2(_xhs_rt_fail2.ToString());
                }
            }
            catch (System.Exception err)
            {
                UpdateSuccess(_xhs_success.ToString(), 3);
                UpdateFail1(_xhs_rt_fail1.ToString());
                UpdateFail2(_xhs_rt_fail2.ToString());

                MessageBox.Show(err.Source + "~r~n" + err.StackTrace, err.Message);
            }
            #endregion

            Thread.Sleep(1000);

            #region 导入促销员
            try
            {
                if (checkBox4.Checked)
                {
                    lb_Count.Text = dt_Promotor.Rows.Count.ToString();
                    tabControl1.SelectedIndex = 3;
                    XH = "";

                    for (int i = 0; i < dt_Promotor.Rows.Count; i++)
                    {
                        worker.ReportProgress((i + 1) * 100 / this.dt_Promotor.Rows.Count, i);
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }
                        XH = dt_Promotor.Rows[i]["序号"].ToString();

                        PM_PromotorBLL promotor = new PM_PromotorBLL();

                        //序号
                        promotor.Model["Code"] = dt_Promotor.Rows[i]["导购编号"].ToString().Trim();

                        //判断数据是否重复
                        int promotorid = 0;
                        if (PM_PromotorBLL.GetModelList("Code = '" + promotor.Model["Code"] + "'").Count == 0)
                        {
                            #region 导入促销员资料
                            //姓名
                            promotor.Model["Name"] = dt_Promotor.Rows[i]["姓名"].ToString().Trim();

                            //管理片区代码
                            DataRow[] rows_OrganizeCity = dt_OrganizeCity.Select("Code='" + dt_Promotor.Rows[i]["管理片区代码"].ToString().Trim() + "'");
                            if (rows_OrganizeCity.Length == 0)
                            {
                                UpdateImportFlag(4, i, "导入失败,管理片区代码在系统字典中不存在!");
                                continue;
                            }
                            else
                                promotor.Model["OrganizeCity"] = rows_OrganizeCity[0]["ID"].ToString().Trim();

                            //联系电话
                            promotor.Model["TeleNum"] = dt_Promotor.Rows[i]["联系电话"].ToString().Trim();
                            if (promotor.Model["TeleNum"] == "")
                            {
                                promotor.Model["TeleNum"] = dt_Promotor.Rows[i]["手机"].ToString().Trim();
                            }

                            //手机
                            promotor.Model["Mobile"] = dt_Promotor.Rows[i]["手机"].ToString().Trim();
                            if (promotor.Model["Mobile"] == "" && promotor.Model["TeleNum"].StartsWith("1")) promotor.Model["Mobile"] = promotor.Model["TeleNum"];

                            #region 所在城市
                            string cityname = dt_Promotor.Rows[i]["城市"].ToString().Trim();
                            string areaname = dt_Promotor.Rows[i]["县城"].ToString().Trim();
                            string townname = dt_Promotor.Rows[i]["乡镇"].ToString().Trim();
                            if (townname != "")
                            {
                                DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + townname + "%'");
                                if (rows_OfficialCity.Length == 1)
                                    promotor.Model.OfficialCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                            }
                            if (areaname != "" && promotor.Model.OfficialCity == 0)
                            {
                                DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + areaname + "%'");
                                if (rows_OfficialCity.Length == 1)
                                    promotor.Model.OfficialCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                            }
                            if (cityname != "" && promotor.Model.OfficialCity == 0)
                            {
                                DataRow[] rows_OfficialCity = dt_OfficialCity.Select("Name like '" + cityname + "%'");
                                if (rows_OfficialCity.Length > 0)
                                    promotor.Model.OfficialCity = int.Parse(rows_OfficialCity[0]["ID"].ToString().Trim());
                            }

                            if (promotor.Model["TeleNum"] != "" && promotor.Model.OfficialCity == 0)
                            {
                                Addr_OfficialCity city = null;
                                city = Addr_OfficialCityBLL.GetCityByTeleNumOrPostCode(promotor.Model["TeleNum"]);
                                if (city != null) promotor.Model.OfficialCity = city.ID;
                            }

                            if (promotor.Model.OfficialCity == 0)
                            {
                                UpdateImportFlag(4, i, "导入失败,城市在系统字典中不存在!");
                                continue;
                            }
                            #endregion

                            //性别
                            if (dt_Promotor.Rows[i]["性别"].ToString().Trim() != "")
                            {
                                bFind = false;
                                foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("PUB_Sex").Values)
                                {
                                    if (item.Name == dt_Promotor.Rows[i]["性别"].ToString().Trim())
                                    {
                                        promotor.Model["Sex"] = item.Code;
                                        bFind = true;
                                        break;
                                    }
                                }
                                if (!bFind)
                                {
                                    UpdateImportFlag(4, i, "导入失败,性别在系统字典中不存在!");
                                    continue;
                                }
                            }

                            //分类
                            if (dt_Promotor.Rows[i]["分类"].ToString().Trim() != "")
                            {
                                bFind = false;
                                foreach (Dictionary_Data item in DictionaryBLL.GetDicCollections("PM_PromotorClassify").Values)
                                {
                                    if (item.Name == dt_Promotor.Rows[i]["分类"].ToString().Trim())
                                    {
                                        promotor.Model["Classfiy"] = item.Code;
                                        bFind = true;
                                        break;
                                    }
                                }
                                if (!bFind)
                                {
                                    UpdateImportFlag(4, i, "导入失败,分类在系统字典中不存在!");
                                    continue;
                                }
                            }

                            //家庭地址
                            promotor.Model["Address"] = dt_Promotor.Rows[i]["家庭地址"].ToString().Trim();

                            //身份证号
                            promotor.Model["IDCode"] = dt_Promotor.Rows[i]["身份证号"].ToString().Trim();

                            //上岗时间
                            if (dt_Promotor.Rows[i]["上岗时间"].ToString().Trim() != "")
                                promotor.Model["BeginWorkDate"] = dt_Promotor.Rows[i]["上岗时间"].ToString().Trim();

                            //离岗时间
                            if (dt_Promotor.Rows[i]["离岗时间"].ToString().Trim() != "")
                                promotor.Model["EndWorkDate"] = dt_Promotor.Rows[i]["离岗时间"].ToString().Trim();

                            //银行类别
                            promotor.Model["BankName"] = dt_Promotor.Rows[i]["银行类别"].ToString().Trim();

                            //工资卡号
                            promotor.Model["BankAccount"] = dt_Promotor.Rows[i]["工资卡号"].ToString().Trim();

                            //在职标志
                            promotor.Model["Dimission"] = "1";
                            promotor.Model.ApproveFlag = 1;
                            promotorid = promotor.Add();
                            if (promotorid > 0)
                            {
                                _xhs_success.Append(XH + ",");
                                //UpdateImportFlag(4, i, "导入成功,ID=" + iret.ToString());
                            }
                            else
                            {
                                UpdateImportFlag(4, i, "导入失败,写入数据库失败!");
                                continue;
                            }
                            #endregion
                        }
                        else
                        {
                            promotorid = PM_PromotorBLL.GetModelList("Code = '" + promotor.Model["Code"] + "'")[0].ID;
                        }

                        #region 促销员所在门店
                        //门店编号
                        string rtcodes = dt_Promotor.Rows[i]["门店编号"].ToString().Trim();
                        if (rtcodes != "")
                        {
                            char[] sep = { ',' };
                            string[] codes = rtcodes.Split(sep);
                            foreach (string c in codes)
                            {
                                if (string.IsNullOrEmpty(c)) continue;
                                //if (c.IndexOf('-') > 0)
                                //{
                                //    char[] sep2 = { '-' };
                                //    string[] codes2 = c.Split(sep2);

                                //    if (codes2.Length == 2)
                                //    {
                                //        int begincode, endcode;
                                //        if (int.TryParse(codes2[0], out begincode) && int.TryParse(codes2[1], out endcode))
                                //        {
                                //            for (int codexh = begincode; codexh <= endcode; codexh++)
                                //            {
                                //                string code = FormatClientCode('R', codexh.ToString(), dt_Promotor.Rows[i]["管理片区代码"].ToString().Trim());

                                //                IList<CM_Client> clients = CM_ClientBLL.GetModelList("Code='" + code + "' AND ClientType = 3");
                                //                if (clients.Count == 1)
                                //                {
                                //                    PM_PromotorInRetailerBLL pinr = new PM_PromotorInRetailerBLL();
                                //                    pinr.Model.Promotor = promotorid;
                                //                    pinr.Model.Client = clients[0].ID;
                                //                    pinr.Add();
                                //                }
                                //                else
                                //                    break;
                                //            }
                                //        }

                                //    }
                                //    else
                                //    {
                                //        string xhs = _xhs_success.ToString();
                                //        if (xhs.EndsWith(","))
                                //        {
                                //            xhs = xhs.Substring(0, xhs.Length - 1);
                                //            xhs = xhs.Substring(0, xhs.LastIndexOf(',') + 1);
                                //            _xhs_success.Remove(0, _xhs_success.Length);
                                //            _xhs_success.Append(xhs);
                                //        }
                                //        UpdateImportFlag(4, i, "导入成功,ID=" + promotorid.ToString() + ",关联所在门店失败!");
                                //        break;
                                //    }
                                //}
                                //else
                                {
                                    string code = c;

                                    IList<CM_Client> clients = CM_ClientBLL.GetModelList("Code='" + code + "' AND ClientType = 3");
                                    if (clients.Count == 1)
                                    {
                                        PM_PromotorInRetailerBLL pinr = new PM_PromotorInRetailerBLL();
                                        pinr.Model.Promotor = promotorid;
                                        pinr.Model.Client = clients[0].ID;
                                        pinr.Add();
                                    }
                                    else
                                    {
                                        string xhs = _xhs_success.ToString();
                                        if (xhs.EndsWith(","))
                                        {
                                            xhs = xhs.Substring(0, xhs.Length - 1);
                                            xhs = xhs.Substring(0, xhs.LastIndexOf(',') + 1);
                                            _xhs_success.Remove(0, _xhs_success.Length);
                                            _xhs_success.Append(xhs);
                                        }
                                        UpdateImportFlag(4, i, "导入成功,ID=" + promotorid.ToString() + ",关联所在门店失败!");
                                        break;
                                    }
                                }
                            }
                        }

                        #endregion
                    }

                    UpdateSuccess(_xhs_success.ToString(), 4);

                }
            }
            catch (System.Exception err)
            {
                UpdateSuccess(_xhs_success.ToString(), 1);
                MessageBox.Show(err.Source + "~r~n" + err.StackTrace, err.Message);
            }
            #endregion

            return;
        }
    private void BindData(PM_PromotorSalary m)
    {
        if (m != null)
        {
            ViewState["PromotorID"] = m.Promotor;
            ViewState["PromotorSalaryID"] = m.ID;
        }

        #region 获取当前导购标准薪资、保底薪资、导购管理费
        if ((int)ViewState["PromotorID"] > 0)
        {
            decimal basepay = 0, minumumwage = 0, rtmanagecost = 0;
            new PM_PromotorBLL((int)ViewState["PromotorID"]).GetStdPay(out basepay, out minumumwage, out rtmanagecost);
            ViewState["BasePay"] = basepay;
            ViewState["MinumumWage"] = minumumwage;
            ViewState["RTManageCost"] = rtmanagecost;
        }
        #endregion
        PM_Promotor p = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;
        if (p == null) Response.Redirect("PM_PromotorDetail.aspx");
        if (m == null)
        {
            m = new PM_PromotorSalary();
            m.Promotor = (int)ViewState["PromotorID"];
            m.State = 1;
            m.InsertStaff = (int)Session["UserID"];
            m.RTManageCost = (decimal)ViewState["RTManageCost"];
            if (p["Classfiy"] == "1" || p["Classfiy"] == "2")
            {
                m.SeniorityPayMode = 1;
            }
        }
        if (p["State"] == "2") bt_Add.Visible = false;

        UC_DetailView1.BindData(m);
        chk_arrivetarget.Checked = m["ISArriveTarget"] == "1";
        UC_DetailView1.SetControlsEnable(m.State == 1);
        bt_OK.Enabled = m.State == 1;

        if (m.ID != 0)
        {
            bt_Delete.Enabled = m.State == 1;
            bt_Submit.Enabled = m.State == 1;
            bt_Approve.Enabled = m.State == 1;
        }
        else
        {
            bt_Submit.Enabled = false;
            bt_Approve.Enabled = false;
            bt_Delete.Enabled = false;
        }
        if (m.BasePayMode != 4 && m.BasePayMode != 5)
        {
            setdisabledfloatingcontorl(false);
        }

        //导购为新入职、或离职状态
        if (p.ApproveFlag == 2) bt_Submit.Visible = false;
        //if (p.Dimission == 2) bt_Add.Visible = false;

        if (m.RTManageCost > 0 && (decimal)ViewState["RTManageCost"] == m.RTManageCost)
        {
            TextBox tbx = (TextBox)UC_DetailView1.FindControl("PM_PromotorSalary_RTManageCost");
            if (tbx != null) tbx.Enabled = false;
        }
        if (m.State < 2)
        {
            #region 兼职导购的限定
            try
            {
                if (ddl_BasePayMode != null)
                {
                    if (p["Classfiy"] != "1" && p["Classfiy"] != "2")   //非专职、非流导,认为是兼职导购
                    {
                        //兼职
                        //ddl_BasePayMode.Items[0].Enabled = false;
                        //ddl_BasePayMode.Items[1].Enabled = false;
                        //ddl_BasePayMode.Items[2].Enabled = false;
                        SetControlsEnable(false);
                        ddl_BasePayMode.SelectedValue = "3";
                        ddl_BasePayMode.Enabled = false;
                    }
                    else
                    {
                        Addr_OrganizeCityBLL _bll = new Addr_OrganizeCityBLL(p.OrganizeCity);
                        string[] city3s = Addr_OrganizeCityParamBLL.GetValueByType(1, 19).Split(new char[] { ',', ',', ';', ';' });
                        int city3ID = TreeTableBLL.GetSuperIDByLevel("MCS_SYS.dbo.Addr_OrganizeCity", p.OrganizeCity, ConfigHelper.GetConfigInt("OrganizePartCity-CityLevel"));

                        if (city3s.Contains(city3ID.ToString()))
                        {
                            ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(非华南)", "4"));
                        }
                        else
                        {
                            decimal AvgSales = 0, BaseFeeRate = 0;
                            int SalaryDelayDays = ConfigHelper.GetConfigInt("SalaryDelayDays");
                            ddl_SalesType.Enabled = false;
                            new PM_PromotorSalaryBLL().GetFloatingInfo(p.ID, AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-SalaryDelayDays)) - 1, out AvgSales, out BaseFeeRate);

                            if (AvgSales == 0 && BaseFeeRate == 0)//首两月不是固定底薪,不能选择浮动底薪
                            {
                                ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(非华南)", "4"));
                            }
                            else
                            {
                                ViewState["AvgSales"] = AvgSales;
                                ViewState["BaseFeeRate"] = BaseFeeRate;
                            }

                            ddl_BasePayMode.Items.Remove(new ListItem("浮动底薪(华南)", "5"));
                        }
                        ddl_BasePayMode.Items.Remove(new ListItem("兼职底薪", "3"));
                        //50岁只能选择商保(5)或自购(8)
                        DateTime Birthday;
                        if (DateTime.TryParse(p["Birthday"], out Birthday) && Birthday.AddYears(50) < DateTime.Now)
                        {
                            foreach (ListItem item in ddl_InsuranceMode.Items)
                            {
                                if (item.Value != "5" && item.Value != "8" && item.Value != "0")
                                {
                                    item.Enabled = false;
                                }
                            }
                        }
                        //专职或流导
                        //ddl_BasePayMode.Items[3].Enabled = false;
                    }

                }
            }
            catch { }
            #endregion

            ddl_BasePayMode_SelectedIndexChanged(null, null);
            ddl_BasePaySubsidyMode_SelectedIndexChanged(null, null);
            ddl_InsuranceMode_SelectedIndexChanged(null, null);
            ddl_MinimumWageMode_SelectedIndexChanged(null, null);
        }
        BindGrid();
    }
Ejemplo n.º 36
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            DateTime     minday, maxday = DateTime.Now;
            HSSFWorkbook hssfworkbook;
            FileStream   file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);

            hssfworkbook = new HSSFWorkbook(file);
            ISheet sheet = hssfworkbook.GetSheetAt(0);

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            int  i = 0, count = getRowsCount() - 1;
            bool flag = true;

            try
            {
                IRow headerRow = sheet.GetRow(0);
                if (headerRow.GetCell(0).ToString() != "零售商ID" ||
                    headerRow.GetCell(1).ToString() != "零售商编号" ||
                    headerRow.GetCell(2).ToString() != "零售商名称" ||
                    headerRow.GetCell(3).ToString() != "零售商分类" ||
                    headerRow.GetCell(4).ToString() != "归属月份" ||
                    headerRow.GetCell(5).ToString() != "导购ID" ||
                    headerRow.GetCell(6).ToString() != "导购姓名")
                {
                    flag = false;
                }
                if (!flag)
                {
                    MessageBox.Show(this, "表头(1~7列)错误!");
                    return;
                }
                int column = getColumnCount(headerRow) + 1;
                int month  = 0;
                rows.MoveNext();

                while (rows.MoveNext())
                {
                    int datacolumn = 7;

                    i++;
                    HSSFRow row = (HSSFRow)rows.Current;
                    if (row.GetCell(0).ToString() == "")
                    {
                        break;
                    }


                    int clientid = 0; int promotorid = 0;
                    if (!int.TryParse(row.GetCell(0).ToString(), out clientid))
                    {
                        errormessage += "零售商:" + row.GetCell(2).ToString() + "的ID错误;\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    CM_Client client = new CM_ClientBLL(clientid).Model;

                    if (client == null)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "零售商在系统中不存在!\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }
                    if (int.TryParse(row.GetCell(5).ToString(), out promotorid))
                    {
                        PM_Promotor pm = new PM_PromotorBLL(promotorid).Model;
                        if (pm == null)
                        {
                            errormessage += "导购ID号:" + promotorid.ToString() + "导购在系统中不存在!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                    }

                    if (month == 0 && headerRow.GetCell(4).ToString() == "归属月份")
                    {
                        IList <AC_AccountMonth> _monthlist = AC_AccountMonthBLL.GetModelList("Name='" + row.GetCell(4).ToString() + "'");
                        if (_monthlist.Count > 0)
                        {
                            month  = _monthlist[0].ID;
                            minday = _monthlist[0].BeginDate;
                            maxday = DateTime.Today < _monthlist[0].EndDate ? DateTime.Today : _monthlist[0].EndDate;
                        }
                        else
                        {
                            errormessage += "会计月错误;\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                    }
                    #region 组织销量头
                    SVM_SalesVolumeBLL bll      = null;
                    string             conditon = "";

                    conditon = "Supplier=" + clientid.ToString()
                               + "AND MCS_SYS.dbo.UF_Spilt(ExtPropertys,'|',4)='7' AND Type=3 AND AccountMonth=" + month.ToString() //+ " AND SalesDate='" + salesdate.ToString("yyyy-MM-dd")
                               + " AND Flag=1 AND ISNULL(Promotor,0)=" + promotorid.ToString();

                    IList <SVM_SalesVolume> svmlists = SVM_SalesVolumeBLL.GetModelList(conditon);
                    if (svmlists.Count > 0)
                    {
                        if (svmlists.FirstOrDefault(p => p.ApproveFlag == 1) != null)
                        {
                            errormessage += "ID号:" + row.GetCell(0).ToString() + "," + client.FullName
                                            + ",导购:" + row.GetCell(6).ToString() + "  当月的销量单" + "已审核,不可再次导入!\r\n";
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }
                        if (svmlists.Count == 1)
                        {
                            bll = new SVM_SalesVolumeBLL(svmlists[0].ID);
                            bll.Items.Clear();
                        }
                    }
                    if (bll == null)
                    {
                        bll = new SVM_SalesVolumeBLL();

                        bll.Model.Client   = 0;
                        bll.Model.Supplier = client.ID;
                        bll.Model.Promotor = promotorid;
                        bll.Model.Type     = 3;


                        bll.Model.OrganizeCity = client.OrganizeCity;
                        bll.Model.AccountMonth = month;
                        bll.Model.SalesDate    = maxday;
                        bll.Model.ApproveFlag  = 2;
                        bll.Model.Flag         = 1;     //成品销售
                        bll.Model["IsCXP"]     = "N";
                        bll.Model.InsertStaff  = 1;
                        bll.Model.Remark       = "线下补录导入";
                    }
                    #endregion
                    bll.Model["SubmitFlag"] = "1";
                    bll.Model["DataSource"] = "7";
                    IList <SVM_SalesVolume_Detail> details = new List <SVM_SalesVolume_Detail>();
                    bool wrongflag = false;//判断导入数量是否正常(除空导致的异常)
                    int  quantity  = 0;
                    bool isnumber  = false;
                    while (true)
                    {
                        PDT_Product product = null;
                        quantity = 0;

                        if (headerRow.GetCell(datacolumn) == null || headerRow.GetCell(datacolumn).CellType == CellType.BLANK || headerRow.GetCell(datacolumn).ToString() == string.Empty)
                        {
                            break;
                        }

                        IList <PDT_Product> products = PDT_ProductBLL.GetModelList("ShortName='" + headerRow.GetCell(datacolumn).ToString() + "' AND State=1");
                        if (products.Count > 0)
                        {
                            product = products[0];
                        }
                        else
                        {
                            errormessage += "产品名称:" + headerRow.GetCell(datacolumn).ToString() + "在产品列表中不存在!\r\n";
                            datacolumn++;
                            row.GetCell(column).SetCellValue(errormessage);
                            continue;
                        }

                        if ((product != null) && row.GetCell(datacolumn).CellType != CellType.BLANK)
                        {
                            int.TryParse(row.GetCell(datacolumn).ToString(), out quantity);
                            if (int.TryParse(row.GetCell(datacolumn).ToString(), out quantity) && !isnumber)
                            {
                                isnumber = true;
                            }
                            if (quantity != 0 && quantity <= 5000 && quantity >= 0)
                            {
                                decimal factoryprice = 0, salesprice = 0;
                                PDT_ProductPriceBLL.GetPriceByClientAndType(client.ID, product.ID, 3, out factoryprice, out salesprice);

                                if (factoryprice == 0)
                                {
                                    factoryprice = product.FactoryPrice;
                                }
                                if (salesprice == 0)
                                {
                                    salesprice = product.NetPrice;
                                }

                                SVM_SalesVolume_Detail detail = new SVM_SalesVolume_Detail();
                                detail.Product      = product.ID;
                                detail.FactoryPrice = factoryprice;
                                detail.SalesPrice   = salesprice;
                                detail.Quantity     = quantity;
                                details.Add(detail);
                            }
                            else if (row.GetCell(datacolumn).CellType != CellType.BLANK && (row.GetCell(datacolumn).ToString() != "0"))
                            {
                                wrongflag = true;
                                break;
                            }
                            else if (quantity < 0)
                            {
                                wrongflag = true;
                                break;
                            }
                        }
                        datacolumn++;
                    }
                    if (wrongflag)
                    {
                        errormessage += "ID号:" + clientid.ToString() + "," + client.FullName
                                        + ",导购:" + row.GetCell(6).ToString() + "  当月的线下补录销量单"
                                        + "未能导入!产品名称:" + headerRow.GetCell(datacolumn).ToString() + "数量填写错误。\r\n";
                        row.GetCell(column).SetCellValue(errormessage);
                        continue;
                    }

                    #region 更新销量至数据库
                    if (bll.Model.ID > 0)
                    {
                        if (details.Count > 0)
                        {
                            bll.DeleteDetail();     //先清除原先导入的数据
                            bll.Items             = details;
                            bll.Model.UpdateStaff = 1;
                            bll.AddDetail();
                            bll.Update();

                            string message = " ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                                             + " 的原有日期为:" + bll.Model.SalesDate.ToString("yyyy-MM-dd") + "的销量单" + "被成功更新!产品SKU数:"
                                             + bll.Items.Count.ToString() + ",产品总数量:" + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                        if (details.Count == 0 && isnumber)
                        {
                            bll.DeleteDetail();
                        }
                    }
                    else
                    {
                        if (details.Count > 0 || svmlists.Count == 0)    //没有产品也新增一条空销量头
                        {
                            bll.Items = details;
                            if (bll.Add() > 0)
                            {
                                foreach (SVM_SalesVolume m in svmlists)
                                {
                                    bll = new SVM_SalesVolumeBLL(m.ID);
                                    bll.DeleteDetail();
                                    bll.Delete();
                                }
                            }
                            string message = "ID号:" + clientid.ToString() + ",该零售商:" + client.FullName
                                             + "的销量单" + "已成功导入!产品SKU数:" + bll.Items.Count.ToString() + ",产品总数量:"
                                             + bll.Items.Sum(p => p.Quantity).ToString() + "\r\n";
                            improtmessage += message;
                            row.CreateCell(column).SetCellValue(message);
                        }
                    }
                    #endregion
                    ((BackgroundWorker)sender).ReportProgress(i * 100 / count, i);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                FileStream writefile = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
                hssfworkbook.Write(writefile);
                writefile.Close();

                sheet = null;
            }
        }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        PM_PromotorBLL _promotor = null;

        if ((int)ViewState["PromotorID"] == 0)
        {
            _promotor = new PM_PromotorBLL();
        }
        else
        {
            _promotor = new PM_PromotorBLL((int)ViewState["PromotorID"]);
        }

        int classify = 0, oldClassify = 0;

        int.TryParse(_promotor.Model["Classfiy"], out oldClassify);
        int oldOrganizeCity = _promotor.Model.OrganizeCity;

        UC_DetailView1.GetData(_promotor.Model);

        #region 判断数据有效性
        if (!(_promotor.Model.OrganizeCity > 1))
        {
            MessageBox.Show(this, "请选择导购员所在的管理片区!");
            return;
        }
        int.TryParse(_promotor.Model["Classfiy"], out classify);
        if (classify == 0)
        {
            MessageBox.Show(this, "请正确选择导购员类别!");
            return;
        }
        if (_promotor.Model["InfoSource"] == "" || _promotor.Model["InfoSource"] == "0")
        {
            MessageBox.Show(this, "请正确选择导购来源!");
            return;
        }
        if (_promotor.Model["OldClassify"] == "" || _promotor.Model["OldClassify"] == "0")
        {
            MessageBox.Show(this, "请正确选择原属品牌!");
            return;
        }
        if (_promotor.Model["BankType"] == "" || _promotor.Model["BankType"] == "0")
        {
            MessageBox.Show(this, "请正确选择银行信息");
            return;
        }
        int bankid = int.Parse(ddl_BankType.SelectedValue);
        if (_promotor.Model["BankName"] == "" || bankid <= 2 && _promotor.Model["BankName"] != ddl_BankType.SelectedItem.Text)
        {
            MessageBox.Show(this, "银行备注信息不正确");
            return;
        }
        //Org_Staff _staffM = new Org_StaffBLL((int)Session["UserID"]).Model;
        //if (_staffM.OrganizeCity == _promotor.Model.OrganizeCity)
        //{
        //    MessageBox.Show(this, "对不起,你不能把导购员放在与你同级的管理片区");
        //    return;
        //}

        #endregion


        #region 判断在职及离职状态
        if (_promotor.Model.Dimission == 1)
        {
            _promotor.Model.EndWorkDate = new DateTime(1900, 1, 1);
        }
        else if (_promotor.Model.EndWorkDate == new DateTime(1900, 1, 1))
        {
            _promotor.Model.EndWorkDate = DateTime.Today;
        }
        #endregion
        #region 如果有工资生成判断离职时间
        if ((int)ViewState["PromotorID"] > 0)
        {
            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()) && _promotor.Model.BeginWorkDate > lastmonth.EndDate)
            {
                MessageBox.Show(this, "该导购在" + lastmonth.Name + "生成过工资,入职日期不能大于" + lastmonth.EndDate.ToString("yyyy-MM-dd"));
                return;
            }
            if (_promotor.Model.Dimission == 2 && _promotor.Model.EndWorkDate < _promotor.Model.BeginWorkDate && _promotor.Model.EndWorkDate.AddDays(40) > DateTime.Now)
            {
                MessageBox.Show(this, "导购离职日期不能小于入职日期!");
                return;
            }
            AC_AccountMonth month = GetMaxSalaryDate((int)ViewState["PromotorID"], 0);
            if (month != null && _promotor.Model.Dimission == 2 && _promotor.Model.EndWorkDate < month.BeginDate)
            {
                MessageBox.Show(this, "该导购在" + month.Name + "生成过工资,离职日期不能小于" + month.BeginDate.ToString("yyyy-MM-dd"));
                return;
            }
        }
        #endregion
        if (_promotor.Model["IDCode"] != string.Empty && _promotor._GetModelList("ID!=" + ViewState["PromotorID"].ToString() + " AND MCS_SYS.dbo.UF_Spilt(PM_Promotor.ExtPropertys,'|',1)='" + _promotor.Model["IDCode"] + "'").Count > 0)
        {
            MessageBox.Show(this, "对不起,该身份证号的导购员已在系统中,请核实后再新增!");
            return;
        }

        if ((int)ViewState["PromotorID"] == 0)
        {
            DateTime birthday;
            if (DateTime.TryParse(_promotor.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(_promotor.Model.OrganizeCity, classify) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
                return;
            }

            _promotor.Model.InputStaff  = (int)Session["UserID"];
            _promotor.Model.ApproveFlag = 2;
            _promotor.Model.Dimission   = 1;
            _promotor.Model.EndWorkDate = new DateTime(1900, 1, 1);
            ViewState["PromotorID"]     = _promotor.Add();
        }
        else
        {
            if (!PM_PromotorNumberLimitBLL.IsSameLimit(oldOrganizeCity, _promotor.Model.OrganizeCity, oldClassify, classify) &&
                PM_PromotorNumberLimitBLL.CheckAllowAdd(_promotor.Model.OrganizeCity, classify) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
                return;
            }

            _promotor.Model.UpdateStaff = (int)Session["UserID"];
            _promotor.Update();
        }
        if (sender != null)
        {
            Response.Redirect("PM_PromotorDetail.aspx?PromotorID=" + ViewState["PromotorID"].ToString());
        }
    }
    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_OK_Click(object sender, EventArgs e)
    {
        PM_PromotorBLL _promotor = null;
        if ((int)ViewState["PromotorID"] == 0)
        {
            _promotor = new PM_PromotorBLL();
        }
        else
        {
            _promotor = new PM_PromotorBLL((int)ViewState["PromotorID"]);
        }

        int classify = 0, oldClassify = 0;
        int.TryParse(_promotor.Model["Classfiy"], out oldClassify);
        int oldOrganizeCity = _promotor.Model.OrganizeCity;

        UC_DetailView1.GetData(_promotor.Model);

        #region 判断数据有效性
        if (!(_promotor.Model.OrganizeCity > 1))
        {
            MessageBox.Show(this, "请选择导购员所在的管理片区!");
            return;
        }
        int.TryParse(_promotor.Model["Classfiy"], out classify);
        if (classify == 0)
        {
            MessageBox.Show(this, "请正确选择导购员类别!");
            return;
        }
        if (_promotor.Model["InfoSource"] == "" || _promotor.Model["InfoSource"] == "0")
        {
            MessageBox.Show(this, "请正确选择导购来源!");
            return;
        }
        if (_promotor.Model["OldClassify"] == "" || _promotor.Model["OldClassify"] == "0")
        {
            MessageBox.Show(this, "请正确选择原属品牌!");
            return;
        }
        if (_promotor.Model["BankType"] == "" || _promotor.Model["BankType"] == "0")
        {
            MessageBox.Show(this, "请正确选择银行信息");
            return;
        }
        int bankid = int.Parse(ddl_BankType.SelectedValue);
        if (_promotor.Model["BankName"] == "" || bankid <= 2 && _promotor.Model["BankName"] != ddl_BankType.SelectedItem.Text)
        {
            MessageBox.Show(this, "银行备注信息不正确");
            return;
        }
        //Org_Staff _staffM = new Org_StaffBLL((int)Session["UserID"]).Model;
        //if (_staffM.OrganizeCity == _promotor.Model.OrganizeCity)
        //{
        //    MessageBox.Show(this, "对不起,你不能把导购员放在与你同级的管理片区");
        //    return;
        //}

        #endregion

        #region 判断在职及离职状态
        if (_promotor.Model.Dimission == 1)
            _promotor.Model.EndWorkDate = new DateTime(1900, 1, 1);
        else if (_promotor.Model.EndWorkDate == new DateTime(1900, 1, 1))
        {
            _promotor.Model.EndWorkDate = DateTime.Today;
        }
        #endregion
        #region 如果有工资生成判断离职时间
        if ((int)ViewState["PromotorID"] > 0)
        {
            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()) && _promotor.Model.BeginWorkDate > lastmonth.EndDate)
            {
                MessageBox.Show(this, "该导购在" + lastmonth.Name + "生成过工资,入职日期不能大于" + lastmonth.EndDate.ToString("yyyy-MM-dd"));
                return;
            }
            if (_promotor.Model.Dimission == 2 && _promotor.Model.EndWorkDate < _promotor.Model.BeginWorkDate && _promotor.Model.EndWorkDate.AddDays(40) > DateTime.Now)
            {
                MessageBox.Show(this, "导购离职日期不能小于入职日期!");
                return;
            }
            AC_AccountMonth month = GetMaxSalaryDate((int)ViewState["PromotorID"], 0);
            if (month != null && _promotor.Model.Dimission == 2 && _promotor.Model.EndWorkDate < month.BeginDate)
            {
                MessageBox.Show(this, "该导购在" + month.Name + "生成过工资,离职日期不能小于" + month.BeginDate.ToString("yyyy-MM-dd"));
                return;
            }
        }
        #endregion
        if (_promotor.Model["IDCode"] != string.Empty && _promotor._GetModelList("ID!=" + ViewState["PromotorID"].ToString() + " AND MCS_SYS.dbo.UF_Spilt(PM_Promotor.ExtPropertys,'|',1)='" + _promotor.Model["IDCode"] + "'").Count > 0)
        {
            MessageBox.Show(this, "对不起,该身份证号的导购员已在系统中,请核实后再新增!");
            return;
        }

        if ((int)ViewState["PromotorID"] == 0)
        {

            DateTime birthday;
            if (DateTime.TryParse(_promotor.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(_promotor.Model.OrganizeCity, classify) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
                return;
            }

            _promotor.Model.InputStaff = (int)Session["UserID"];
            _promotor.Model.ApproveFlag = 2;
            _promotor.Model.Dimission = 1;
            _promotor.Model.EndWorkDate = new DateTime(1900, 1, 1);
            ViewState["PromotorID"] = _promotor.Add();
        }
        else
        {
            if (!PM_PromotorNumberLimitBLL.IsSameLimit(oldOrganizeCity, _promotor.Model.OrganizeCity, oldClassify, classify) &&
                PM_PromotorNumberLimitBLL.CheckAllowAdd(_promotor.Model.OrganizeCity, classify) <= 0)
            {
                MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
                return;
            }

            _promotor.Model.UpdateStaff = (int)Session["UserID"];
            _promotor.Update();
        }
        if (sender != null)
            Response.Redirect("PM_PromotorDetail.aspx?PromotorID=" + ViewState["PromotorID"].ToString());
    }
Ejemplo n.º 40
0
    private void BindData()
    {
        SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;

        ViewState["Type"] = sv.Type;

        ViewState["ClientID"]          = sv.Type == 3 ? sv.Supplier : sv.Client;
        tbx_VolumeDate.Text            = sv.SalesDate.ToString("yyyy-MM-dd");
        ddl_AccountMonth.SelectedValue = sv.AccountMonth.ToString();
        ddl_Flag.SelectedValue         = sv.Flag.ToString();
        ddl_Flag.Enabled   = false;
        tbx_sheetCode.Text = sv.SheetCode;
        tbx_Remark.Text    = sv.Remark;
        ViewState["IsCXP"] = (sv.Flag > 10);
        if (!(bool)ViewState["IsCXP"])
        {
            tb_AddProduct.Visible = false;
        }
        DataTable dt = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], (int)ViewState["ClientID"],
                                                          (int)ViewState["Type"], sv.AccountMonth, (bool)ViewState["IsCXP"]); //初始化产品列表

        DataColumn[] keys = { dt.Columns["Product"] };
        dt.PrimaryKey         = keys;
        ViewState["DTDetail"] = dt;
        BindClientInfo(sv.Client, sv.Supplier);

        if (sv.Promotor != 0)
        {
            if (ddl_Promotor.Items.FindByValue(sv.Promotor.ToString()) == null)
            {
                PM_Promotor pm = new PM_PromotorBLL(sv.Promotor).Model;
                if (pm != null)
                {
                    ddl_Promotor.Items.Add(new ListItem(pm.Name + "【已离开该门店】", sv.Promotor.ToString()));
                }
            }
            ddl_Promotor.SelectedValue = sv.Promotor.ToString();
        }
        if (sv["DataSource"] == "2")
        {
            gv_List.Columns[7].Visible = true;

            gv_List.Columns[8].HeaderText = "数量确认";
        }
        else if (sv["DataSource"] == "1")
        {
            gv_List.SetControlsEnable(false);
        }
        BindGrid();
        if (sv.InsertStaff != (int)Session["UserID"])
        {
            bt_Delete.Visible = false;
            bt_Save.Visible   = false;
            bt_Submit.Visible = false;
        }
        if (sv.ApproveFlag == 1)
        {
            #region 已审核,不可再修改
            tbx_VolumeDate.Enabled   = false;
            ddl_AccountMonth.Enabled = false;
            ddl_Flag.Enabled         = false;
            ddl_Promotor.Enabled     = false;
            tbx_Remark.Enabled       = false;
            tbx_sheetCode.Enabled    = false;
            gv_List.SetControlsEnable(false);

            bt_Save.Visible      = false;
            bt_Submit.Visible    = false;
            bt_Delete.Visible    = false;
            bt_Approve.Visible   = false;
            bt_ToForcast.Visible = false;

            tb_AddProduct.Visible  = false;
            bt_AddProduct.Visible  = false;
            select_Product.Visible = false;
            #endregion
        }
        else
        {
            bt_Delete.Visible = (int)Session["UserID"] == sv.InsertStaff;
            if (sv["SubmitFlag"] == "1")
            {
                bt_Submit.Visible = false;       //已提交
            }
            else
            {
                bt_Approve.Visible = false;     //未提交
            }
            //门店销售单,不允许即时提交及审核
            if ((int)ViewState["Type"] == 3)
            {
                bt_Submit.Visible  = false;
                bt_Approve.Visible = false;
            }

            if ((int)ViewState["Type"] != 3 || (bool)ViewState["IsCXP"])
            {
                bt_ToForcast.Visible = false;
            }
        }
        if (sv["DataSource"] == "1")
        {
            gv_List.SetControlsEnable(false);
        }
        if (sv["DataSource"] == "2")
        {
            cb_OnlyDisplayUnZero.Enabled = false;
        }
    }
    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());
    }
Ejemplo n.º 42
0
    /// <summary>
    /// 绑定客户信息
    /// </summary>
    /// <param name="type">销量类型 1:经销商进货 3:经销商出货(即门店进货) 3:门店出货</param>
    /// <param name="sellinclient">进货客户</param>
    /// <param name="supplier">出货客户</param>
    private void BindClientInfo(int sellinclient, int supplier)
    {
        if (sellinclient > 0)
        {
            CM_Client _r = new CM_ClientBLL(sellinclient).Model;
            switch (_r.ClientType)
            {
            case 1:     //公司仓库
                hy_SellInClient.NavigateUrl = "~/SubModule/CM/Store/StoreDetail.aspx?ClientID=" + sellinclient.ToString();
                break;

            case 2:     //经销商
                hy_SellInClient.NavigateUrl = "~/SubModule/CM/DI/DistributorDetail.aspx?ClientID=" + sellinclient.ToString();
                break;

            case 3:     //终端门店
                hy_SellInClient.NavigateUrl = "~/SubModule/CM/RT/RetailerDetail.aspx?ClientID=" + sellinclient.ToString();
                break;
            }
            hy_SellInClient.Text = "(" + _r.Code + ")" + _r.FullName;

            if (supplier == 0)
            {
                supplier = _r.Supplier;

                #region 根据门店或分销商取供货商
                //成品,只取第一供货商
                //赠品,先取第二供货商,如果取不到,则取第一供货商
                if ((bool)ViewState["IsCXP"])
                {
                    int supplier2 = 0;
                    int.TryParse(_r["Supplier2"], out supplier2);
                    if (supplier2 != 0)
                    {
                        supplier = supplier2;
                    }
                }
                CM_Client _s = new CM_ClientBLL(supplier).Model;
                ddl_SellOutClient.Items.Add(new ListItem("(" + _s.Code + ")" + _s.FullName, _s.ID.ToString()));
                #endregion

                hy_SellOutClient.Visible = false;

                //经销商登录时,供货商直接选择该经销商
                Org_StaffBLL staff = new Org_StaffBLL((int)Session["UserID"]);
                if (!string.IsNullOrEmpty(staff.Model["RelateClient"]))
                {
                    if (ddl_SellOutClient.Items.FindByValue(staff.Model["RelateClient"]) == null)
                    {
                        MessageBox.ShowAndRedirect(this, "对不起,您无法向该客户配送" + ((bool)ViewState["IsCXP"] ? "赠品" : "成品") + "!",
                                                   "SalesVolumeList.aspx?Type=" + ViewState["Type"].ToString() + "&SellInClientID=" + _r.ID.ToString());
                    }

                    ddl_SellOutClient.SelectedValue = staff.Model["RelateClient"];
                    ddl_SellOutClient.Enabled       = false;
                }
            }

            if ((int)ViewState["VolumeID"] == 0 && new CM_ClientBLL(int.Parse(ddl_SellOutClient.SelectedValue)).Model.ClientType == 2 && SVM_InventoryBLL.GetModelList("Client=" + ddl_SellOutClient.SelectedValue + " AND AccountMonth=" + ddl_AccountMonth.SelectedValue + " AND ApproveFlag=2").Count > 0)
            {
                MessageBox.ShowAndRedirect(this, "该经销商本月还有未审核库存,请先审核库存再作此操作。", "InventoryList.aspx?ClientID=" + ddl_SellOutClient.SelectedValue);
                return;
            }
        }
        else
        {
            hy_SellInClient.Visible = false;
            lb_SellInTitle.Visible  = false;
        }

        if (hy_SellOutClient.Visible)
        {
            if (supplier > 0)
            {
                CM_Client _s = new CM_ClientBLL(supplier).Model;
                switch (_s.ClientType)
                {
                case 1:     //公司仓库
                    hy_SellOutClient.NavigateUrl = "~/SubModule/CM/Store/StoreDetail.aspx?ClientID=" + supplier.ToString();
                    break;

                case 2:     //经销商
                    hy_SellOutClient.NavigateUrl = "~/SubModule/CM/DI/DistributorDetail.aspx?ClientID=" + supplier.ToString();
                    break;

                case 3:     //终端门店
                    hy_SellOutClient.NavigateUrl = "~/SubModule/CM/RT/RetailerDetail.aspx?ClientID=" + supplier.ToString();

                    #region 绑定门店导购员
                    try
                    {
                        lbl_Promotor.Visible = true;
                        ddl_Promotor.Visible = true;

                        AC_AccountMonth month     = new AC_AccountMonthBLL(int.Parse(ddl_AccountMonth.SelectedValue)).Model;
                        StringBuilder   condition = new StringBuilder(" PM_Promotor.BeginWorkDate<='" + month.EndDate.AddDays(1).ToString("yyyy-MM-dd") + "' AND ISNULL(PM_Promotor.EndWorkDate,GETDATE())>='" + month.BeginDate.ToString("yyyy-MM-dd") + "' AND PM_Promotor.ApproveFlag=1 ");
                        condition.Append("AND ID in (SELECT Promotor FROM PM_PromotorInRetailer WHERE Client = " + supplier.ToString() + ")");
                        //if ((int)ViewState["VolumeID"] == 0)
                        //{
                        //    condition.Append(" AND ID NOT IN (SELECT Promotor  FROM [MCS_SVM].[dbo].[SVM_SalesVolume] WHERE Type=3 AND Supplier= " + supplier.ToString() + "  AND AccountMonth=" + ddl_AccountMonth.SelectedValue + " AND Promotor IS NOT NULL)");
                        //}
                        ddl_Promotor.DataSource = PM_PromotorBLL.GetModelList(condition.ToString());
                        ddl_Promotor.DataBind();
                        ddl_Promotor.Items.Insert(0, new ListItem("请选择..", "0"));
                    }
                    catch { }
                    #endregion

                    break;
                }
                hy_SellOutClient.Text     = "(" + _s.Code + ")" + _s.FullName;
                ddl_SellOutClient.Visible = false;
            }
            else
            {
                hy_SellOutClient.Visible  = false;
                ddl_SellOutClient.Visible = false;
                lb_SellOutTitle.Visible   = false;
            }
        }
    }
    /// <summary>
    /// 审核
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void bt_Approve_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["PromotorID"] != 0)
        {
            PM_PromotorBLL _promotor = new PM_PromotorBLL((int)ViewState["PromotorID"]);

            if (PM_PromotorNumberLimitBLL.CheckAllowAdd(_promotor.Model.OrganizeCity, int.Parse(_promotor.Model["Classfiy"])) < 0)
            {
                MessageBox.Show(this, "对不起当前城市导购员人数满额,要想继续新增请与人事经理联系");
                return;
            }
            _promotor.Model.ApproveFlag = 1;
            _promotor.Model.UpdateStaff = (int)Session["UserID"];
            _promotor.Update();
            MessageBox.Show(this, "审核成功!");
            BindData();
        }
    }
    private void BindData()
    {
        SVM_SalesVolume sv = new SVM_SalesVolumeBLL((int)ViewState["VolumeID"]).Model;
        ViewState["Type"] = sv.Type;

        ViewState["ClientID"] = sv.Type == 3 ? sv.Supplier : sv.Client;
        tbx_VolumeDate.Text = sv.SalesDate.ToString("yyyy-MM-dd");
        ddl_AccountMonth.SelectedValue = sv.AccountMonth.ToString();
        ddl_Flag.SelectedValue = sv.Flag.ToString();
        ddl_Flag.Enabled = false;
        tbx_sheetCode.Text = sv.SheetCode;
        tbx_Remark.Text = sv.Remark;
        ViewState["IsCXP"] = (sv.Flag > 10);
        if (!(bool)ViewState["IsCXP"]) tb_AddProduct.Visible = false;
        DataTable dt = SVM_SalesVolumeBLL.InitProductList((int)ViewState["VolumeID"], (int)ViewState["ClientID"],
            (int)ViewState["Type"], sv.AccountMonth, (bool)ViewState["IsCXP"]); //初始化产品列表
        DataColumn[] keys = { dt.Columns["Product"] };
        dt.PrimaryKey = keys;
        ViewState["DTDetail"] = dt;
        BindClientInfo(sv.Client, sv.Supplier);

        if (sv.Promotor != 0)
        {
            if (ddl_Promotor.Items.FindByValue(sv.Promotor.ToString()) == null)
            {
                PM_Promotor pm = new PM_PromotorBLL(sv.Promotor).Model;
                if (pm != null)
                    ddl_Promotor.Items.Add(new ListItem(pm.Name + "【已离开该门店】", sv.Promotor.ToString()));
            }
            ddl_Promotor.SelectedValue = sv.Promotor.ToString();
        }
        if (sv["DataSource"] == "2")
        {
            gv_List.Columns[7].Visible = true;

            gv_List.Columns[8].HeaderText = "数量确认";
        }
        else if (sv["DataSource"] == "1")
            gv_List.SetControlsEnable(false);
        BindGrid();
        if (sv.InsertStaff != (int)Session["UserID"])
        {
            bt_Delete.Visible = false;
            bt_Save.Visible = false;
            bt_Submit.Visible = false;
        }
        if (sv.ApproveFlag == 1)
        {
            #region 已审核,不可再修改
            tbx_VolumeDate.Enabled = false;
            ddl_AccountMonth.Enabled = false;
            ddl_Flag.Enabled = false;
            ddl_Promotor.Enabled = false;
            tbx_Remark.Enabled = false;
            tbx_sheetCode.Enabled = false;
            gv_List.SetControlsEnable(false);

            bt_Save.Visible = false;
            bt_Submit.Visible = false;
            bt_Delete.Visible = false;
            bt_Approve.Visible = false;
            bt_ToForcast.Visible = false;

            tb_AddProduct.Visible = false;
            bt_AddProduct.Visible = false;
            select_Product.Visible = false;
            #endregion
        }
        else
        {
            bt_Delete.Visible = (int)Session["UserID"] == sv.InsertStaff;
            if (sv["SubmitFlag"] == "1")
                bt_Submit.Visible = false;       //已提交
            else
            {
                bt_Approve.Visible = false;     //未提交
            }
            //门店销售单,不允许即时提交及审核
            if ((int)ViewState["Type"] == 3)
            {
                bt_Submit.Visible = false;
                bt_Approve.Visible = false;
            }

            if ((int)ViewState["Type"] != 3 || (bool)ViewState["IsCXP"])
            {
                bt_ToForcast.Visible = false;
            }
        }
        if (sv["DataSource"] == "1")
            gv_List.SetControlsEnable(false);
        if (sv["DataSource"] == "2")
        {
            cb_OnlyDisplayUnZero.Enabled = false;
        }
    }
    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());
    }
Ejemplo n.º 46
0
    protected void bt_DownloadTemplate_Click(object sender, EventArgs e)
    {
        #region 获取最迟的销量日期
        int             JXCDelayDays = ConfigHelper.GetConfigInt("JXCDelayDays");
        AC_AccountMonth month        = new AC_AccountMonthBLL(AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-JXCDelayDays))).Model;
        DateTime        day          = DateTime.Today < month.EndDate ? DateTime.Today : month.EndDate;
        #endregion

        #region 判断有无选择业代
        if (string.IsNullOrEmpty(select_Staff.SelectValue) || select_Staff.SelectValue == "0")
        {
            MessageBox.Show(this, "对不起,请选择责任业代!");
            return;
        }
        #endregion

        #region 获取业代负责的零售商及所有产品数据
        int staff = int.Parse(select_Staff.SelectValue);
        IList <CM_Client> clientlists = CM_ClientBLL.GetModelList("ClientType=3 AND ClientManager=" + staff.ToString() +
                                                                  " AND ActiveFlag=1 AND ApproveFlag=1 AND OpenTime<'" + day.ToString("yyyy-MM-dd") + " 23:59:59' ORDER BY Code");
        if (clientlists.Count == 0)
        {
            MessageBox.Show(this, "对不起,没有当前人直接负责的终端店!");
            return;
        }

        IList <PDT_Product> productlists = PDT_ProductBLL.GetModelList("Brand IN (SELECT ID FROM dbo.PDT_Brand WHERE IsOpponent='1') AND State=1 AND ApproveFlag=1 ORDER BY ISNULL(SubUnit,999999),Code");
        #endregion

        #region 组织文件路径及文件名
        string path = ConfigHelper.GetConfigString("AttachmentPath");
        if (path.StartsWith("~"))
        {
            path = Server.MapPath(path);
        }
        if (!path.EndsWith("\\"))
        {
            path = path + "\\";
        }
        path += "ImportExcelSVM\\Download\\";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        string filename = "销量导入模板-" + select_Staff.SelectText + "-" + DateTime.Today.ToString("yyyyMMdd") + ".xls";
        path += filename;
        #endregion

        #region 生成Excel文件
        object           missing  = System.Reflection.Missing.Value;
        ApplicationClass ExcelApp = null;

        try
        {
            ExcelApp               = new ApplicationClass();
            ExcelApp.Visible       = false;
            ExcelApp.DisplayAlerts = false;

            Workbook  workbook1 = null;
            Worksheet worksheet1 = null, worksheet2 = null;
            try
            {
                workbook1  = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                worksheet1 = (Worksheet)workbook1.Worksheets["sheet1"];
                worksheet2 = (Worksheet)workbook1.Worksheets.Add(missing, worksheet1, 1, missing);

                worksheet1.Name = "零售商进货";
                worksheet2.Name = "零售商销货";

                #region 创建表头
                worksheet1.Cells[1, 1] = "零售商ID";
                worksheet1.Cells[1, 2] = "零售商编号";
                worksheet1.Cells[1, 3] = "零售商名称";
                worksheet1.Cells[1, 4] = "零售商分类";
                worksheet1.Cells[1, 5] = "归属月份";

                worksheet1.get_Range("B2", "B2").ColumnWidth             = 15;
                worksheet1.get_Range("C2", "C2").ColumnWidth             = 20;
                worksheet1.get_Range("D2", "E2").ColumnWidth             = 10;
                worksheet1.get_Range("A1", "A1").RowHeight               = 50;
                worksheet1.get_Range("A1", "CC1").WrapText               = true;
                worksheet1.get_Range("A1", "CC1").Font.Bold              = true;
                worksheet1.get_Range("A1", "CC1000").Font.Size           = 9;
                worksheet1.get_Range("A1", "CC1000").HorizontalAlignment = XlHAlign.xlHAlignCenter;

                worksheet2.Cells[1, 1] = "零售商ID";
                worksheet2.Cells[1, 2] = "零售商编号";
                worksheet2.Cells[1, 3] = "零售商名称";
                worksheet2.Cells[1, 4] = "零售商分类";
                worksheet2.Cells[1, 5] = "归属月份";
                worksheet2.Cells[1, 6] = "导购ID";
                worksheet2.Cells[1, 7] = "导购姓名";

                worksheet2.get_Range("B2", "B2").ColumnWidth             = 15;
                worksheet2.get_Range("C2", "C2").ColumnWidth             = 20;
                worksheet2.get_Range("D2", "G2").ColumnWidth             = 10;
                worksheet2.get_Range("A1", "A1").RowHeight               = 50;
                worksheet2.get_Range("A1", "CC1").WrapText               = true;
                worksheet2.get_Range("A1", "CC1").Font.Bold              = true;
                worksheet2.get_Range("A1", "CC1000").Font.Size           = 9;
                worksheet2.get_Range("A1", "CC1000").HorizontalAlignment = XlHAlign.xlHAlignCenter;

                int bgcolor1 = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightYellow);
                int bgcolor2 = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen);

                //将产品写入表头
                for (int i = 0; i < productlists.Count; i++)
                {
                    worksheet1.Cells[1, 6 + i] = productlists[i].ShortName;
                    worksheet2.Cells[1, 8 + i] = productlists[i].ShortName;

                    #region  品牌设置产品列颜色
                    if (i > 0)
                    {
                        if (productlists[i].Brand == productlists[i - 1].Brand)
                        {
                            worksheet1.get_Range(worksheet1.Cells[1, 6 + i], worksheet1.Cells[1000, 6 + i]).Interior.Color =
                                worksheet1.get_Range(worksheet1.Cells[1, 6 + i - 1], worksheet1.Cells[1000, 6 + i - 1]).Interior.Color;

                            worksheet2.get_Range(worksheet2.Cells[1, 8 + i], worksheet2.Cells[1000, 8 + i]).Interior.Color =
                                worksheet2.get_Range(worksheet2.Cells[1, 8 + i - 1], worksheet2.Cells[1000, 8 + i - 1]).Interior.Color;
                        }
                        else
                        {
                            if (int.Parse(worksheet1.get_Range(worksheet1.Cells[1, 6 + i - 1], worksheet1.Cells[1000, 6 + i - 1]).Interior.Color.ToString()) == bgcolor1)
                            {
                                worksheet1.get_Range(worksheet1.Cells[1, 6 + i], worksheet1.Cells[1000, 6 + i]).Interior.Color = bgcolor2;
                            }
                            else
                            {
                                worksheet1.get_Range(worksheet1.Cells[1, 6 + i], worksheet1.Cells[1000, 6 + i]).Interior.Color = bgcolor1;
                            }

                            if (int.Parse(worksheet2.get_Range(worksheet2.Cells[1, 8 + i - 1], worksheet2.Cells[1000, 8 + i - 1]).Interior.Color.ToString()) == bgcolor1)
                            {
                                worksheet2.get_Range(worksheet2.Cells[1, 8 + i], worksheet2.Cells[1000, 8 + i]).Interior.Color = bgcolor2;
                            }
                            else
                            {
                                worksheet2.get_Range(worksheet2.Cells[1, 8 + i], worksheet2.Cells[1000, 8 + i]).Interior.Color = bgcolor1;
                            }
                        }
                    }
                    else
                    {
                        worksheet1.get_Range(worksheet1.Cells[1, 6 + i], worksheet1.Cells[1000, 6 + i]).Interior.Color = bgcolor1;
                        worksheet2.get_Range(worksheet2.Cells[1, 8 + i], worksheet2.Cells[1000, 8 + i]).Interior.Color = bgcolor1;
                    }
                    #endregion
                }
                #endregion

                #region 将零售商信息写入表格内
                int sellinrow = 2, selloutrow = 2;
                foreach (CM_Client client in clientlists)
                {
                    worksheet1.Cells[sellinrow, 1] = client.ID;
                    worksheet1.Cells[sellinrow, 2] = client.Code;
                    worksheet1.Cells[sellinrow, 3] = client.FullName;
                    worksheet1.Cells[sellinrow, 4] = DictionaryBLL.GetDicCollections("CM_RT_Classify")[client["RTClassify"]].Name;
                    worksheet1.Cells[sellinrow, 5] = "'" + month.Name;
                    //worksheet1.Cells[sellinrow, 5] = day.ToString("yyyy-MM-dd");
                    sellinrow++;

                    worksheet2.Cells[selloutrow, 1] = client.ID;
                    worksheet2.Cells[selloutrow, 2] = client.Code;
                    worksheet2.Cells[selloutrow, 3] = client.FullName;
                    worksheet2.Cells[selloutrow, 4] = DictionaryBLL.GetDicCollections("CM_RT_Classify")[client["RTClassify"]].Name;
                    worksheet2.Cells[selloutrow, 5] = "'" + month.Name;
                    //worksheet2.Cells[selloutrow, 5] = day.ToString("yyyy-MM-dd");

                    IList <PM_Promotor> promotorlists = PM_PromotorBLL.GetModelList("ID IN (SELECT Promotor FROM dbo.PM_PromotorInRetailer WHERE Client = " + client.ID.ToString() + ") AND Dimission=1 AND ApproveFlag=1");
                    for (int j = 0; j < promotorlists.Count; j++)
                    {
                        if (j > 0)
                        {
                            worksheet2.Cells[selloutrow, 1] = client.ID;
                            worksheet2.Cells[selloutrow, 2] = client.Code;
                            worksheet2.Cells[selloutrow, 3] = client.FullName;
                            worksheet2.Cells[selloutrow, 4] = DictionaryBLL.GetDicCollections("CM_RT_Classify")[client["RTClassify"]].Name;
                            worksheet2.Cells[selloutrow, 5] = "'" + month.Name;
                            //worksheet2.Cells[selloutrow, 5] = day.ToString("yyyy-MM-dd");
                        }
                        worksheet2.Cells[selloutrow, 6] = promotorlists[j].ID;
                        worksheet2.Cells[selloutrow, 7] = promotorlists[j].Name;

                        if (j != promotorlists.Count - 1)
                        {
                            selloutrow++;
                        }
                    }
                    selloutrow++;
                }
                #endregion

                #region 设置表格格式
                //设置行高
                worksheet1.get_Range(worksheet1.Cells[2, 1], worksheet1.Cells[sellinrow - 1, 1]).RowHeight  = 16;
                worksheet2.get_Range(worksheet2.Cells[2, 1], worksheet2.Cells[selloutrow - 1, 1]).RowHeight = 16;

                //设置表格单元格格线
                worksheet1.get_Range(worksheet1.Cells[1, 1], worksheet1.Cells[sellinrow - 1, 6 + productlists.Count - 1]).Borders.Color  = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
                worksheet2.get_Range(worksheet2.Cells[1, 1], worksheet2.Cells[selloutrow - 1, 8 + productlists.Count - 1]).Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);

                #endregion

                worksheet1.Activate();
                ExcelApp.AlertBeforeOverwriting = false;
                workbook1.SaveAs(path, XlFileFormat.xlExcel8, "", "", false, false, XlSaveAsAccessMode.xlNoChange, 1, false, missing, missing, missing);
            }
            catch (System.Exception err)
            {
                string error = "Message:" + err.Message + "<br/>" + "Source:" + err.Source + "<br/>" +
                               "StackTrace:" + err.StackTrace + "<br/>";
                lb_ErrorInfo.Text = error;

                MessageBox.Show(this, "系统错误-1!" + err.Message);
            }
            finally
            {
                if (workbook1 != null)
                {
                    workbook1.Close(false, missing, missing);
                }

                if (worksheet1 != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet1);
                }
                if (worksheet2 != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet2);
                }
                if (workbook1 != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook1);
                }

                worksheet1 = null;
                worksheet2 = null;
                workbook1  = null;

                if (File.Exists(path))
                {
                    Downloadfile(path, filename);
                }
            }
        }
        catch (System.Exception err)
        {
            string error = "Message:" + err.Message + "<br/>" + "Source:" + err.Source + "<br/>" +
                           "StackTrace:" + err.StackTrace + "<br/>";
            lb_ErrorInfo.Text = error;

            MessageBox.Show(this, "系统错误-2!" + err.Message);
        }
        finally
        {
            if (ExcelApp != null)
            {
                ExcelApp.Workbooks.Close();
                ExcelApp.Quit();

                System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelApp);
                ExcelApp = null;
            }
            GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
        #endregion
    }
    private void BindData()
    {
        PM_Promotor m = new PM_PromotorBLL((int)ViewState["PromotorID"]).Model;

        UC_DetailView1.BindData(m);
        gv_list.ConditionString = " Promotor= " + (int)ViewState["PromotorID"];
        gv_list.BindGrid();

        //验证身份证号码
        txt_BankName.Enabled = m["BankType"] == "3";

        if (m.ApproveFlag == 1)
        {
            bt_Approve.Visible = false;
            if (m.Dimission == 1)
            {
                TextBox txt_EndWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_EndWorkDate");
                if (txt_EndWorkDate != null)
                {
                    txt_EndWorkDate.Enabled = false;
                }

                bt_AddApply.Visible = false;
                #region 导购兼职/专职转换
                int classfiy = 0;
                int.TryParse(m["Classfiy"], out classfiy);
                if (classfiy == 0)
                {
                    bt_ChangeClassify.Visible = false;
                }
                else if (classfiy == 1 || classfiy == 2)
                {
                    bt_ChangeClassify.Text    = "转为兼职";
                    bt_ChangeClassify.Visible = true;
                }
                else
                {
                    bt_ChangeClassify.Text    = "转为专职/流动";
                    bt_ChangeClassify.Visible = true;
                }
                bt_ChangeClassify.OnClientClick = "PopPMClassify_Approve(" + ViewState["PromotorID"].ToString() + ")";
                #endregion
            }
            Header.Attributes["WebPageSubCode"] = "Modify";
            //TextBox txt_BeginWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_BeginWorkDate");

            //临时开放修改功能
            //if (txt_BeginWorkDate != null && m.Dimission==1) txt_BeginWorkDate.Enabled = false;

            //有些离职日期会填写错误,更新为权限修改 12.11.21
            //if (m.Dimission == 2)
            //{
            //    TextBox txt_EndWorkDate = (TextBox)UC_DetailView1.FindControl("PM_Promotor_EndWorkDate");
            //    if (txt_EndWorkDate != null) txt_EndWorkDate.Enabled = false;
            //}
            string[] allowdays = Addr_OrganizeCityParamBLL.GetValueByType(1, 9).Replace(" ", "").Split(new char[] { ',', ',', ';', ';' });
            if (allowdays.Contains(DateTime.Now.Day.ToString()))
            {
                bt_ChangeClassify.Enabled = false;
                bt_ChangeClassify.ToolTip = "导购工资生成期间不能互转";
            }
        }

        if (m["State"] == "2")
        {
            //审批中
            bt_AddApply.Visible       = false;
            bt_OK.Visible             = false;
            bt_TaskDetail.Visible     = true;
            bt_ChangeClassify.Enabled = false;
            bt_ChangeClassify.ToolTip = "该导购有未完成的流程,请待流程完成后,再做调整!";
        }
        bt_OK.Text      = "保 存";
        bt_OK.ForeColor = System.Drawing.Color.Red;


        if (m["Classfiy"] != "")
        {
            int budget = PM_PromotorNumberLimitBLL.CheckOverBudget(m.OrganizeCity, int.Parse(m["Classfiy"]));
            if (budget == 0)
            {
                lb_OverBudgetInfo.Text = "导购员数量已等于预定的预算人数,请注意!";
            }
            else if (budget < 0)
            {
                lb_OverBudgetInfo.Text = "导购员数量已超过预定的预算人数 " + (0 - budget).ToString() + "人,请注意!";
            }
        }


        if (m["IDCode"].Length == 18 && !Tools.DoVerifyIDCode(m["IDCode"]))
        {
            lb_OverBudgetInfo.Text += "         注意:该导购员身份证号码错误!";
        }

        ddl_Classify_SelectedIndexChanged(null, null);
    }