protected void bt_OK_Click(object sender, EventArgs e)
    {
        CM_LinkManBLL _lm = null;
        if (bt_OK.Text == "确 定")
        {
            _lm = new CM_LinkManBLL();
        }
        else
        {
            _lm = new CM_LinkManBLL((int)ViewState["ID"]);
        }

        UC_DetailView1.GetData(_lm.Model);

        if (bt_OK.Text == "确 定")
        {
            ViewState["ID"] = _lm.Add();
            string path = "LinkManDetail.aspx?ID=" + ViewState["ID"].ToString();
            if (Request.QueryString["URL"]!=null) path = Page.ResolveUrl(Request.QueryString["URL"] + "?ClientID=" + Request.QueryString["ClientID"]);
            MessageBox.ShowAndRedirect(this, "保存联系人资料成功!", path);
        }
        else
        {
            _lm.Update();
            MessageBox.ShowAndRedirect(this, "保存联系人资料成功!", "LinkManDetail.aspx?ID=" + ViewState["ID"].ToString());
        }
    }
    protected void bt_AddApply_Click(object sender, EventArgs e)
    {
        bt_OK_Click(null, null);
        if (CM_LinkManBLL.GetModelList("ClientID=" + ViewState["ClientID"].ToString()).Count == 0)
        {
            MessageBox.Show(this, "对不起,请至少提供一名客户联系人!");
            return;
        }
        CM_ClientBLL bll = new CM_ClientBLL((int)ViewState["ClientID"]);

        NameValueCollection dataobjects = new NameValueCollection();

        dataobjects.Add("ID", bll.Model.ID.ToString());
        dataobjects.Add("OrganizeCity", bll.Model.OrganizeCity.ToString());
        dataobjects.Add("ClientName", bll.Model.FullName);
        dataobjects.Add("Channel", bll.Model["RTChannel"]);
        dataobjects.Add("StoreAnalysis", bll.Model["Store_Analysis"]);
        dataobjects.Add("IsACClient", bll.Model["IsACClient"]);

        int TaskID = EWF_TaskBLL.NewTask("Add_Retailer", (int)Session["UserID"], "终端门店名称:" + bll.Model.FullName, "~/SubModule/CM/RT/RetailerDetail.aspx?ClientID=" + ViewState["ClientID"].ToString(), dataobjects);

        if (TaskID > 0)
        {
            bll.Model["TaskID"] = TaskID.ToString();
            bll.Model["State"]  = "2";
            bll.Update();
            //new EWF_TaskBLL(TaskID).Start();        //直接启动流程
        }

        Response.Redirect("~/SubModule/EWF/Apply.aspx?TaskID=" + TaskID.ToString());
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        CM_LinkManBLL _lm = null;

        if (bt_OK.Text == "确 定")
        {
            _lm = new CM_LinkManBLL();
        }
        else
        {
            _lm = new CM_LinkManBLL((int)ViewState["ID"]);
        }

        UC_DetailView1.GetData(_lm.Model);

        if (bt_OK.Text == "确 定")
        {
            ViewState["ID"] = _lm.Add();
            string path = "LinkManDetail.aspx?ID=" + ViewState["ID"].ToString();
            if (Request.QueryString["URL"] != null)
            {
                path = Page.ResolveUrl(Request.QueryString["URL"] + "?ClientID=" + Request.QueryString["ClientID"]);
            }
            MessageBox.ShowAndRedirect(this, "保存联系人资料成功!", path);
        }
        else
        {
            _lm.Update();
            MessageBox.ShowAndRedirect(this, "保存联系人资料成功!", "LinkManDetail.aspx?ID=" + ViewState["ID"].ToString());
        }
    }
    private void BindData()
    {
        CM_LinkMan _lm = new CM_LinkManBLL((int)ViewState["ID"]).Model;

        UC_DetailView1.BindData(_lm);
        bt_OK.Text      = "修 改";
        bt_OK.ForeColor = System.Drawing.Color.Red;
    }
예제 #5
0
 protected void select_RelateClient_SelectChange(object sender, SelectChangeEventArgs e)
 {
     if (!string.IsNullOrEmpty(select_RelateClient.SelectValue))
     {
         try
         {
             ddl_RelateLinkMan.DataSource = CM_LinkManBLL.GetModelList("ClientID=" + select_RelateClient.SelectValue +
                                                                       " AND MCS_SYS.dbo.UF_Spilt2('MCS_CM.dbo.CM_LinkMan',ExtPropertys,'Dimission')!='2'");
             ddl_RelateLinkMan.DataBind();
             ddl_RelateLinkMan.Enabled = true;
             ddl_RelateLinkMan.Items.Insert(0, new ListItem("请选择", "0"));
         }
         catch { }
     }
 }
    private void BindData()
    {
        CSO_OfferBalance_Detail detail = new CSO_OfferBalanceBLL().GetDetailModel((int)ViewState["ID"]);
        if (detail == null)
        {
            MessageBox.ShowAndClose(this, "参数错误!");
            return;
        }

        if (detail.OfferMan > 0)
        {
            CM_LinkMan doctor = new CM_LinkManBLL(detail.OfferMan).Model;
            if (doctor != null) lb_DoctorName.Text = doctor.Name;
        }

        lb_ActualFee.Text = detail.ActualFee.ToString("0.##");
        tbx_AdjustFee.Text = (0 - detail.AwardFee).ToString("0.##");
        tbx_AdjustReason.Text = detail["AdjustReason"];
    }
예제 #7
0
    private void BindData()
    {
        CSO_OfferBalance_Detail detail = new CSO_OfferBalanceBLL().GetDetailModel((int)ViewState["ID"]);

        if (detail == null)
        {
            MessageBox.ShowAndClose(this, "参数错误!");
            return;
        }

        if (detail.OfferMan > 0)
        {
            CM_LinkMan doctor = new CM_LinkManBLL(detail.OfferMan).Model;
            if (doctor != null)
            {
                lb_DoctorName.Text = doctor.Name;
            }
        }

        lb_ActualFee.Text     = detail.ActualFee.ToString("0.##");
        tbx_AdjustFee.Text    = (0 - detail.AwardFee).ToString("0.##");
        tbx_AdjustReason.Text = detail["AdjustReason"];
    }
예제 #8
0
    protected void select_Client_SelectChange(object sender, MCSControls.MCSWebControls.SelectChangeEventArgs e)
    {
        ddl_LinkMan.Items.Clear();

        int client = 0;

        if (int.TryParse(select_Client.SelectValue, out client) && client > 0)
        {
            IList <CM_LinkMan> lists = CM_LinkManBLL.GetModelList("ClientID = " + client.ToString());
            foreach (CM_LinkMan item in lists)
            {
                ddl_LinkMan.Items.Add(new ListItem(item.Name, item.ID.ToString()));
            }

            CM_ClientBLL clientbll = new CM_ClientBLL(client);
            decimal      forcast   = clientbll.GetSalesForcast((int)ViewState["AccountMonth"]);
            tbx_SalesForcast.Text     = forcast.ToString("0.##");
            tbx_SalesForcast.ReadOnly = forcast > 0;

            lb_PreSalesVolume.Text = clientbll.GetSalesVolume(AC_AccountMonthBLL.GetCurrentMonth() - 1).ToString("0.##元");
            lb_AvgSalesVolume.Text = clientbll.GetSalesVolumeAvg().ToString("0.##元");
        }
        ddl_LinkMan.Items.Insert(0, new ListItem("请选择", "0"));
    }
    protected void gv_List_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int id = (int)gv_List.DataKeys[e.Row.RowIndex]["ID"];
            if (id > 0)
            {
                Button bt_OpenAdjust = (Button)e.Row.FindControl("bt_OpenAdjust");
                bt_OpenAdjust.OnClientClick = "PopAdjust(" + id.ToString() + ")";
            }

            ListTable<FNA_FeeApplyDetail> _details = ViewState["Details"] as ListTable<FNA_FeeApplyDetail>;
            FNA_FeeApplyDetail item = _details[id.ToString()];

            if (item.Client > 0)
            {
                HyperLink hy_Client = (HyperLink)e.Row.FindControl("hy_Client");
                if (hy_Client != null)
                {
                    CM_Client c = new CM_ClientBLL(item.Client).Model;
                    if (c != null)
                    {
                        hy_Client.Text = c.FullName;
                        hy_Client.NavigateUrl = "../FeeApplyOrWriteoffByClientList.aspx?ClientID=" + item.Client.ToString();

                        int linkman = 0;
                        if (int.TryParse(item["RelateLinkMan"], out linkman) && linkman > 0)
                        {
                            HyperLink hy_RelateLinkMan = (HyperLink)e.Row.FindControl("hy_RelateLinkMan");
                            if (hy_RelateLinkMan != null)
                            {
                                CM_LinkMan m = new CM_LinkManBLL(linkman).Model;
                                if (m != null)
                                {
                                    hy_RelateLinkMan.Text = m.Name;
                                    if (c.ClientType == 5)
                                        hy_RelateLinkMan.NavigateUrl = "~/SubModule/CM/Hospital/DoctorDetail.aspx?ID=" + m.ID.ToString();
                                    else
                                        hy_RelateLinkMan.NavigateUrl = "~/SubModule/CM/LM/LinkManDetail.aspx.aspx?ID=" + m.ID.ToString();
                                }
                            }
                        }
                    }
                }
            }

            Label lb_RelateBrand = (Label)e.Row.FindControl("lb_RelateBrand");
            if (lb_RelateBrand != null)
            {
                foreach (string brand in item.RelateBrands.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    PDT_Brand b = new PDT_BrandBLL(int.Parse(brand)).Model;
                    if (b != null) lb_RelateBrand.Text += b.Name + ",";
                }
            }

        }
    }
예제 #10
0
    protected void gv_List_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int id = (int)gv_List.DataKeys[e.Row.RowIndex]["ID"];
            if (id > 0)
            {
                Button bt_OpenAdjust = (Button)e.Row.FindControl("bt_OpenAdjust");
                bt_OpenAdjust.OnClientClick = "PopAdjust(" + id.ToString() + ")";
            }

            ListTable <FNA_FeeApplyDetail> _details = ViewState["Details"] as ListTable <FNA_FeeApplyDetail>;
            FNA_FeeApplyDetail             item     = _details[id.ToString()];

            if (item.Client > 0)
            {
                HyperLink hy_Client = (HyperLink)e.Row.FindControl("hy_Client");
                if (hy_Client != null)
                {
                    CM_Client c = new CM_ClientBLL(item.Client).Model;
                    if (c != null)
                    {
                        hy_Client.Text        = c.FullName;
                        hy_Client.NavigateUrl = "../FeeApplyOrWriteoffByClientList.aspx?ClientID=" + item.Client.ToString();

                        int linkman = 0;
                        if (int.TryParse(item["RelateLinkMan"], out linkman) && linkman > 0)
                        {
                            HyperLink hy_RelateLinkMan = (HyperLink)e.Row.FindControl("hy_RelateLinkMan");
                            if (hy_RelateLinkMan != null)
                            {
                                CM_LinkMan m = new CM_LinkManBLL(linkman).Model;
                                if (m != null)
                                {
                                    hy_RelateLinkMan.Text = m.Name;
                                    if (c.ClientType == 5)
                                    {
                                        hy_RelateLinkMan.NavigateUrl = "~/SubModule/CM/Hospital/DoctorDetail.aspx?ID=" + m.ID.ToString();
                                    }
                                    else
                                    {
                                        hy_RelateLinkMan.NavigateUrl = "~/SubModule/CM/LM/LinkManDetail.aspx.aspx?ID=" + m.ID.ToString();
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Label lb_RelateBrand = (Label)e.Row.FindControl("lb_RelateBrand");
            if (lb_RelateBrand != null)
            {
                foreach (string brand in item.RelateBrands.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    PDT_Brand b = new PDT_BrandBLL(int.Parse(brand)).Model;
                    if (b != null)
                    {
                        lb_RelateBrand.Text += b.Name + ",";
                    }
                }
            }
        }
    }
    private void BindData()
    {
        CM_Client m = new CM_ClientBLL((int)ViewState["ClientID"]).Model;

        switch (m.ClientType)
        {
        case 1:
            Response.Redirect("../Store/StoreDetail.aspx?ClientID=" + m.ID.ToString());
            break;

        case 2:
            break;

        case 3:
            Response.Redirect("../RT/RetailerDetail.aspx?ClientID=" + m.ID.ToString());
            break;

        default:
            MessageBox.ShowAndRedirect(this, "请先在‘经销商列表’中选择要查看的经销商!", "DistributorList.aspx?URL=" + Request.Url.PathAndQuery);
            break;
        }
        pl_detail.BindData(m);



        MCSSelectControl select_ClientManager = (MCSSelectControl)pl_detail.FindControl("CM_Client_ClientManager");

        select_ClientManager.PageUrl = "~/SubModule/StaffManage/Pop_Search_Staff.aspx?OrganizeCity=" + m.OrganizeCity;

        if (m.ApproveFlag == 1)
        {
            //已审核
            TextBox tbx_OpenTime = (TextBox)pl_detail.FindControl("CM_Client_OpenTime");
            if (tbx_OpenTime != null && tbx_OpenTime.Text != "")
            {
                tbx_OpenTime.Enabled = false;
            }

            if (m.ActiveFlag == 1)
            {
                bt_AddApply.Visible = false;
                bt_DIUP.Visible     = false;
            }
            else
            {
                TextBox tbx_CloseTime = (TextBox)pl_detail.FindControl("CM_Client_CloseTime");
                if (tbx_CloseTime != null && tbx_CloseTime.Text != "")
                {
                    tbx_CloseTime.Enabled = false;
                }
                bt_RevocationApply.Visible = false;
            }
            bt_Approve.Visible = false;
        }

        if (m.ActiveFlag == 1)
        {
            Header.Attributes["WebPageSubCode"] = "Modify";
            bt_AddApply.Visible = false;
            bt_Approve.Visible  = false;
        }
        else
        {
            bt_RevocationApply.Visible = false;
        }

        if (string.IsNullOrEmpty(m["TaskID"]))
        {
            bt_Record.Visible = false;
        }
        else
        {
            if (m["State"] == "2")
            {
                //审批中,不可修改数据
                bt_AddApply.Visible        = false;
                bt_RevocationApply.Visible = false;
                bt_OK.Visible = false;
                bt_RevocationApply.Visible = false;
                bt_DIACUpgrade.Visible     = false;
                bt_DIUP.Visible            = false;
            }
        }

        #region 绑定该客户的首要联系人
        DropDownList ddl_ChiefLinkMan = (DropDownList)pl_detail.FindControl("CM_Client_ChiefLinkMan");
        try
        {
            ddl_ChiefLinkMan.DataTextField  = "Name";
            ddl_ChiefLinkMan.DataValueField = "ID";
            ddl_ChiefLinkMan.DataSource     = CM_LinkManBLL.GetModelList("ClientID=" + ViewState["ClientID"].ToString());
            ddl_ChiefLinkMan.DataBind();
        }
        catch { }

        ddl_ChiefLinkMan.Items.Insert(0, new ListItem("请选择", "0"));
        ddl_ChiefLinkMan.SelectedValue = m.ChiefLinkMan.ToString();

        #endregion

        BindGrid();
        bt_Add.Enabled = true;

        if (m.ClientType != 2 || m["DIClassify"] != "3")
        {
            bt_DIACUpgrade.Visible = false;
        }
        if (m.ClientType != 2 || m["DIClassify"] == "2")
        {
            bt_DIUP.Visible = false;
        }

        bt_ReplaceSupplier.OnClientClick      = "javascript:PopReplaceSupplier(" + m.ID.ToString() + ")";
        bt_ReplaceSupplier2.OnClientClick     = "javascript:PopReplaceSupplier2(" + m.ID.ToString() + ")";
        bt_ReplaceClientManager.OnClientClick = "javascript:PopReplaceClientManager(" + m.ClientManager.ToString() + "," + m.ClientType.ToString() + ")";
    }
 private void BindData()
 {
     CM_LinkMan _lm = new CM_LinkManBLL((int)ViewState["ID"]).Model;
     UC_DetailView1.BindData(_lm);
     bt_OK.Text = "修 改";
     bt_OK.ForeColor = System.Drawing.Color.Red;
 }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        CM_ClientBLL _bll = null;

        if (ViewState["ClientID"] == null)
        {
            _bll = new CM_ClientBLL();
        }
        else
        {
            _bll = new CM_ClientBLL((int)ViewState["ClientID"]);
            if (CM_LinkManBLL.GetModelList("ClientID=" + ViewState["ClientID"].ToString()).Count == 0)
            {
                MessageBox.Show(this, "对不起,请至少提供一名客户联系人!");
                return;
            }
        }

        string IsRMSClient = _bll.Model["IsRMSClient"];

        pl_detail.GetData(_bll.Model);


        #region 判断必填项
        if (_bll.Model.OrganizeCity == 0)
        {
            MessageBox.Show(this, "所属的管理片区必填!");
            return;
        }
        if (_bll.Model.OfficalCity == 0)
        {
            MessageBox.Show(this, "所属的行政城市必填!");
            return;
        }
        if (_bll.Model.Supplier == 0)
        {
            MessageBox.Show(this, "供货商信息必填!");
            return;
        }
        if (_bll.Model["Supplier2"] == "")
        {
            MessageBox.Show(this, "赠品供货商信息必填!");
            return;
        }
        if (_bll.Model["OperateProperty"] == "0")
        {
            MessageBox.Show(this, "归属办事处类型必填!");
            return;
        }
        if (new Addr_OfficialCityBLL(_bll.Model.OfficalCity).Model.Level < 3)
        {
            MessageBox.Show(this, "门店所在行政城市必须到区或县城!");
            return;
        }
        if (_bll.Model["RTChannel"] == "0")
        {
            MessageBox.Show(this, "门店渠道必填!");
            return;
        }
        if ((_bll.Model["RTChannel"] == "1" || _bll.Model["RTChannel"] == "2") && _bll.Model["VestKA"] == "0")
        {
            MessageBox.Show(this, "当门店渠道为LKA,或NKA时,KA系统必填!");
            return;
        }
        if (_bll.Model["Classification"] == "" || _bll.Model["Classification"] == "0")
        {
            MessageBox.Show(this, "“门店归类”必填!");
            return;
        }
        if ((_bll.Model["MarketType"] == "" || _bll.Model["MarketType"] == "0"))
        {
            MessageBox.Show(this, "“市场类型”必填!");
            return;
        }
        #endregion

        if (_bll.Model["IsRMSClient"] == "2" && IsRMSClient != "2")
        {
            _bll.Model["RMSCloseDate"] = DateTime.Now.ToString("yyyy-MM-dd");
        }

        string[] RTChannelLimit1    = ConfigHelper.GetConfigString("RTChannelLimit1").Split(',');
        string[] RTChannelLimit2    = ConfigHelper.GetConfigString("RTChannelLimit2").Split(',');
        string[] RT_Classification1 = ConfigHelper.GetConfigString("Classification1").Split(',');
        string[] RT_Classification2 = ConfigHelper.GetConfigString("Classification2").Split(',');
        if (RTChannelLimit1.Contains(_bll.Model["RTChannel"]) && !RT_Classification1.Contains(_bll.Model["Classification"]) ||
            RTChannelLimit2.Contains(_bll.Model["RTChannel"]) && !RT_Classification2.Contains(_bll.Model["Classification"]))
        {
            MessageBox.Show(this, "“门店渠道”与“门店归类”匹配不规范,请重新选填!");
            return;
        }


        #region 判断活跃标志
        if (_bll.Model.ActiveFlag == 1 && _bll.Model.CloseTime != new DateTime(1900, 1, 1))
        {
            _bll.Model.CloseTime = new DateTime(1900, 1, 1);
        }

        if (_bll.Model.ActiveFlag == 2 && _bll.Model.CloseTime == new DateTime(1900, 1, 1))
        {
            _bll.Model.CloseTime = DateTime.Now;
        }
        #endregion

        #region 自动设定“是否促销店”字段
        switch (_bll.Model["RTClassify"])
        {
        case "2":          //返利店
            _bll.Model["IsPromote"] = "2";
            _bll.Model["IsRebate"]  = "1";
            break;

        case "3":          //导购店
            _bll.Model["IsPromote"] = "1";
            _bll.Model["IsRebate"]  = "2";
            break;

        case "4":          //导购返利店
            _bll.Model["IsPromote"] = "1";
            _bll.Model["IsRebate"]  = "1";
            break;

        case "1":          //流通店
        default:
            _bll.Model["IsPromote"] = "2";
            _bll.Model["IsRebate"]  = "2";
            break;
        }
        #endregion

        Addr_OfficialCity city = new Addr_OfficialCityBLL(_bll.Model.OfficalCity).Model;
        if (city != null)
        {
            if (_bll.Model.PostCode == "")
            {
                _bll.Model.PostCode = city.PostCode;
            }
            if (_bll.Model["Township"] == "" && city.Level == 4)
            {
                _bll.Model["Township"] = city.Name;
            }
        }

        if (ViewState["ClientID"] == null)
        {
            _bll.Model.ClientType  = 3;
            _bll.Model.ApproveFlag = 2;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            ViewState["ClientID"]  = _bll.Add();
        }
        else
        {
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
        }
        if (sender != null)
        {
            MessageBox.ShowAndRedirect(this, "保存终端门店资料成功!", "RetailerDetail.aspx?ClientID=" + ViewState["ClientID"].ToString());
        }
    }
    private void BindData()
    {
        CM_ClientBLL _bll = new CM_ClientBLL((int)ViewState["ClientID"]);
        CM_Client    m    = _bll.Model;

        switch (m.ClientType)
        {
        case 1:
            Response.Redirect("../Store/StoreDetail.aspx?ClientID=" + m.ID.ToString());
            break;

        case 2:
            Response.Redirect("../DI/DistributorDetail.aspx?ClientID=" + m.ID.ToString());
            break;

        case 3:
            break;

        default:
            MessageBox.ShowAndRedirect(this, "请先在‘零售商列表’中选择要查看的零售商!", "RetailerList.aspx?URL=" + Request.Url.PathAndQuery);
            break;
        }

        pl_detail.BindData(m);


        //lbl_preSales.Text = _bll.GetSalesVolume(AC_AccountMonthBLL.GetCurrentMonth() - 1).ToString();
        //lbl_AvageSales.Text = _bll.GetSalesVolumeAvg().ToString();

        MCSSelectControl select_ClientManager = (MCSSelectControl)pl_detail.FindControl("CM_Client_ClientManager");

        if (select_ClientManager != null)
        {
            select_ClientManager.PageUrl = "~/SubModule/StaffManage/Pop_Search_Staff.aspx?OrganizeCity=" + m.OrganizeCity + "&IncludeSuperManager=Y";
        }

        MCSSelectControl select_Supplier = (MCSSelectControl)pl_detail.FindControl("CM_Client_Supplier");

        if (select_Supplier != null)
        {
            select_Supplier.PageUrl = "~/SubModule/CM/PopSearch/Search_SelectClient.aspx?ClientType=2&OrganizeCityEnabled=Y&OrganizeCity=" + m.OrganizeCity + "&ExtCondition=\"MCS_SYS.dbo.UF_Spilt(CM_Client.ExtPropertys,~|~,7) IN (1,2)\"";
        }

        MCSSelectControl select_Supplier2 = (MCSSelectControl)pl_detail.FindControl("CM_Client_Supplier2");

        if (select_Supplier2 != null)
        {
            select_Supplier2.PageUrl = "~/SubModule/CM/PopSearch/Search_SelectClient.aspx?ClientType=2&OrganizeCityEnabled=Y&OrganizeCity=" + m.OrganizeCity + "&ExtCondition=\"MCS_SYS.dbo.UF_Spilt(CM_Client.ExtPropertys,~|~,7) IN (1,2)\"";
        }

        if (m.ApproveFlag == 1)
        {
            //已审核
            TextBox tbx_OpenTime = (TextBox)pl_detail.FindControl("CM_Client_OpenTime");

            if (m.ActiveFlag == 1)
            {
                if (tbx_OpenTime != null && tbx_OpenTime.Text != "")
                {
                    tbx_OpenTime.Enabled = false;
                }
                bt_AddApply.Visible = false;
            }
            else
            {
                TextBox tbx_CloseTime = (TextBox)pl_detail.FindControl("CM_Client_CloseTime");
                if (tbx_CloseTime != null && tbx_CloseTime.Text != "")
                {
                    tbx_CloseTime.Enabled = false;
                }
                bt_RevocationApply.Visible = false;
            }

            Header.Attributes["WebPageSubCode"] = "Modify";
            bt_Approve.Visible = false;
        }
        else
        {
            bt_RevocationApply.Visible = false;
        }

        if (string.IsNullOrEmpty(m["TaskID"]))
        {
            bt_Record.Visible = false;
        }
        else
        {
            if (m["State"] == "2")
            {
                //审批中,不可修改数据
                bt_AddApply.Visible        = false;
                bt_RevocationApply.Visible = false;
                bt_OK.Visible = false;
                bt_RevocationApply.Visible = false;
            }
        }


        #region 绑定该客户的首要联系人
        DropDownList ddl_ChiefLinkMan = pl_detail.FindControl("CM_Client_ChiefLinkMan") != null ? (DropDownList)pl_detail.FindControl("CM_Client_ChiefLinkMan") : null;
        try
        {
            ddl_ChiefLinkMan.DataTextField  = "Name";
            ddl_ChiefLinkMan.DataValueField = "ID";
            ddl_ChiefLinkMan.DataSource     = CM_LinkManBLL.GetModelList("ClientID=" + ViewState["ClientID"].ToString());
            ddl_ChiefLinkMan.DataBind();

            ddl_ChiefLinkMan.Items.Insert(0, new ListItem("请选择", "0"));
            ddl_ChiefLinkMan.SelectedValue = m.ChiefLinkMan.ToString();
        }
        catch { }

        #endregion

        BindGrid();
        //MessageBox.Show(this, Session["UserID"].ToString());
        bt_ReplaceClientManager.OnClientClick = "javascript:PopReplaceClientManager(" + m.ClientManager.ToString() + "," + m.ClientType.ToString() + ")";

        //管理员登录状况下  雅慧电商的流通店  数据有误发出警报
        if (Session["UserID"].ToString() == "1" && m["RTChannel"] != "20" && m["RTClassify"] == "1" &&
            (m["IsRMSClient"] != "2" || m["RMSAccountEnabled"] != "2"))
        {
            MessageBox.Show(this, "非雅慧电商的流通店积分店状态(" + m["IsRMSClient"] + ")或积分账户启用否(" + m["RMSAccountEnabled"] + ")数据有误");
        }
    }
예제 #15
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;
        }