private void BindData()
    {
        CM_ClientBLL _ClientBll = new CM_ClientBLL((int)ViewState["ClientID"]);

        if (_ClientBll.Model == null || _ClientBll.Model.ClientType != 3)
        {
            MessageBox.ShowAndRedirect(this, "请先在‘零售商列表’中选择要查看的零售商!", "RetailerList.aspx?URL=" + Request.Url.PathAndQuery);
            return;
        }

        pl_detail.BindData(_ClientBll.Model);

        CM_ClientSupplierInfo clientSupplierInfo = _ClientBll.GetSupplierInfo((int)Session["OwnerClient"]);

        if (clientSupplierInfo != null)
        {
            pl_detail.BindData(clientSupplierInfo);
        }

        #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();
        //    ddl_ChiefLinkMan.Items.Insert(0, new ListItem("请选择", "0"));
        //    ddl_ChiefLinkMan.SelectedValue = m.ChiefLinkMan.ToString();
        //}
        //catch { }

        #endregion

        BindGrid();

        //bt_Map.OnClientClick = "javascript:Pop_MapShow(" + _ClientBll.Model.ID.ToString() + ")";
    }
Exemple #2
0
    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"]);
        }

        #region 获取原供货及厂商管理信息
        CM_ClientSupplierInfo supplierinfo = _bll.GetSupplierInfoByManufacturer((int)Session["Manufacturer"]);
        CM_ClientManufactInfo manufactinfo = _bll.GetManufactInfo((int)Session["Manufacturer"]);

        if (supplierinfo == null)
        {
            supplierinfo          = new CM_ClientSupplierInfo();
            supplierinfo.Supplier = (int)Session["Manufacturer"];
        }

        if (manufactinfo == null)
        {
            manufactinfo = new CM_ClientManufactInfo();
            manufactinfo.Manufacturer = (int)Session["Manufacturer"];
        }
        #endregion

        pl_detail.GetData(_bll.Model);
        pl_detail.GetData(supplierinfo);
        pl_detail.GetData(manufactinfo);

        #region 查重判断
        string chkrpt = "Code='" + manufactinfo.Code + "'";
        if (_bll.Model.ID > 0)
        {
            chkrpt += " AND Client <> " + _bll.Model.ID.ToString();
        }

        IList <CM_ClientManufactInfo> cmlist = CM_ClientManufactInfoBLL.GetModelList(chkrpt);
        if (cmlist.Count > 0)
        {
            MessageBox.Show(this, "客户编码重复,请检查!" + chkrpt.Replace("'", ""));
            return;
        }
        #endregion

        #region 判断必填项
        if (_bll.Model.OfficialCity == 0)
        {
            MessageBox.Show(this, "所属的行政城市必填!");
            return;
        }
        if (manufactinfo.State == 0)
        {
            MessageBox.Show(this, "合作状态必填!");
            return;
        }
        Addr_OrganizeCity orgcity = new Addr_OrganizeCityBLL(manufactinfo.OrganizeCity).Model;
        if (orgcity == null || orgcity.Level < 6)
        {
            MessageBox.Show(this, "销售区域必需选择到营业部级!");
            return;
        }
        #endregion

        #region 判断活跃标志
        if (manufactinfo.State == 1 && manufactinfo.EndDate != new DateTime(1900, 1, 1))
        {
            manufactinfo.EndDate = new DateTime(1900, 1, 1);
        }

        if (manufactinfo.State == 2 && manufactinfo.EndDate == new DateTime(1900, 1, 1))
        {
            manufactinfo.EndDate = DateTime.Now;
        }
        #endregion

        if (ViewState["ClientID"] == null) //新增经销商
        {
            _bll.Model.ClientType  = 2;    //客户类型默认为经销商
            _bll.Model.ApproveFlag = 2;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            _bll.Model.OwnerType   = 2;     //所有权属性默认为厂商级
            _bll.Model.OwnerClient = (int)Session["Manufacturer"];
            ViewState["ClientID"]  = _bll.Add();

            _bll.SetSupplierInfo(supplierinfo);
            _bll.SetManufactInfo(manufactinfo);
            MessageBox.ShowAndRedirect(this, "保存经销商资料成功!", "DistributorDetail.aspx?ClientID=" + ViewState["ClientID"].ToString());
        }
        else//修改时供应商和经销商只能为关联厂商
        {
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
            _bll.SetSupplierInfo(supplierinfo);
            _bll.SetManufactInfo(manufactinfo);

            Response.Redirect("DistributorList.aspx");
        }
    }
Exemple #3
0
    private void BindData()
    {
        int clientID = 0;

        if (ViewState["ClientID"] == null || !int.TryParse(ViewState["ClientID"].ToString(), out clientID))
        {
            return;
        }

        CM_ClientBLL clientbll = new CM_ClientBLL(clientID);
        CM_Client    m         = clientbll.Model;

        if (m == null)
        {
            Response.Redirect("DistributorList.aspx");
        }

        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);

        tr_OfficialCity_Selected(null, null);
        tr_OrganizeCity_Selected(null, null);

        CM_ClientSupplierInfo supplierinfo = clientbll.GetSupplierInfoByManufacturer((int)Session["Manufacturer"]);
        CM_ClientManufactInfo manufactinfo = clientbll.GetManufactInfo((int)Session["Manufacturer"]);

        if (supplierinfo != null)
        {
            pl_detail.BindData(supplierinfo);
        }
        if (manufactinfo != null)
        {
            pl_detail.BindData(manufactinfo);
        }

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

        if (select_ClientManager != null && manufactinfo != null)
        {
            select_ClientManager.PageUrl = "~/SubModule/StaffManage/Pop_Search_Staff.aspx?OrganizeCity=" + manufactinfo.OrganizeCity.ToString() + "&IncludeSuperManager=Y";
        }
        if (manufactinfo != null && manufactinfo.ApproveFlag == 1)
        {
            //已审核
            TextBox tbx_BeginDate = (TextBox)pl_detail.FindControl("CM_ClientManufactInfo_BeginDate");
            if (tbx_BeginDate != null && tbx_BeginDate.Text != "")
            {
                tbx_BeginDate.Enabled = false;
            }
            TextBox tbx_Code = (TextBox)pl_detail.FindControl("CM_ClientManufactInfo_Code");
            if (tbx_Code != null)
            {
                tbx_Code.Enabled = false;
            }

            bt_Approve.Visible = false;
            Header.Attributes["WebPageSubCode"] = "Modify";
        }
    }
Exemple #4
0
    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"]);
        }

        #region 获取原供货及厂商管理信息
        CM_ClientSupplierInfo supplierinfo = _bll.GetSupplierInfoByManufacturer((int)Session["Manufacturer"]);
        CM_ClientManufactInfo manufactinfo = _bll.GetManufactInfo((int)Session["Manufacturer"]);

        if (supplierinfo == null)
        {
            supplierinfo = new CM_ClientSupplierInfo();
        }
        if (manufactinfo == null)
        {
            manufactinfo = new CM_ClientManufactInfo();
            manufactinfo.Manufacturer = (int)Session["Manufacturer"];
        }
        #endregion

        pl_detail.GetData(_bll.Model);
        pl_detail.GetData(supplierinfo);
        pl_detail.GetData(manufactinfo);

        #region 判断必填项
        if (_bll.Model.OfficialCity == 0)
        {
            MessageBox.Show(this, "所属的行政城市必填!");
            return;
        }
        #endregion

        #region 判断活跃标志
        if (manufactinfo.State == 1 && manufactinfo.EndDate != new DateTime(1900, 1, 1))
        {
            manufactinfo.EndDate = new DateTime(1900, 1, 1);
        }

        if (manufactinfo.State == 2 && manufactinfo.EndDate == new DateTime(1900, 1, 1))
        {
            manufactinfo.EndDate = DateTime.Now;
        }
        #endregion

        if (ViewState["ClientID"] == null)
        {
            _bll.Model.ClientType  = 3;
            _bll.Model.ApproveFlag = 1;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            _bll.Model.OwnerType   = 2;
            _bll.Model.OwnerClient = (int)Session["Manufacturer"];
            ViewState["ClientID"]  = _bll.Add();

            _bll.SetSupplierInfo(supplierinfo);
            _bll.SetManufactInfo(manufactinfo);
        }
        else
        {
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
            _bll.SetSupplierInfo(supplierinfo);
            _bll.SetManufactInfo(manufactinfo);
        }

        if (sender != null)
        {
            Response.Redirect("RetailerList.aspx");
        }
    }
Exemple #5
0
    private void BindData()
    {
        CM_ClientBLL clientbll = new CM_ClientBLL((int)ViewState["ClientID"]);
        CM_Client    m         = clientbll.Model;

        if (m == null)
        {
            Response.Redirect("RetailerList.aspx");
        }

        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;
        }

        CM_ClientSupplierInfo supplierinfo = clientbll.GetSupplierInfoByManufacturer((int)Session["Manufacturer"]);
        CM_ClientManufactInfo manufactinfo = clientbll.GetManufactInfo((int)Session["Manufacturer"]);

        pl_detail.BindData(m);

        if (supplierinfo != null)
        {
            pl_detail.BindData(supplierinfo);
        }
        if (manufactinfo != null)
        {
            BindGeoCode(m.OfficialCity);
            BindVisitRoute(manufactinfo.OrganizeCity);
            pl_detail.BindData(manufactinfo);
        }



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

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

        if (manufactinfo != null)
        {
            if (manufactinfo.SyncState != 0 && manufactinfo.SyncState != 1 && manufactinfo.SyncState != 8)
            {
                bt_Submit.Visible = false;
            }
            if (manufactinfo.SyncState != 2)
            {
                bt_Approve.Visible = false; bt_UnApprove.Visible = false;
            }

            //有公司客户编号后,页面为编辑权限模式
            if (!string.IsNullOrEmpty(manufactinfo.Code))
            {
                Header.Attributes["WebPageSubCode"] = "Modify";
            }
        }

        bt_Map.OnClientClick = "javascript:Pop_MapShow(" + m.ID.ToString() + ")";
    }
        private void FillClientInfo(CM_Client m, int TDP)
        {
            if (m == null)
            {
                return;
            }

            CM_ClientBLL ClientBLL = new CM_ClientBLL(m.ID);

            if (ClientBLL.Model == null)
            {
                return;
            }

            #region 绑定基本资料
            ID           = m.ID;
            Code         = m.Code;
            FullName     = m.FullName == "" ? m.ShortName : m.FullName;
            ShortName    = m.ShortName;
            OfficialCity = m.OfficialCity;
            Address      = m.Address;
            ClientType   = m.ClientType;
            LinkManName  = m.LinkManName;
            TeleNum      = m.TeleNum;
            Mobile       = m.Mobile == "" ? m.TeleNum : m.Mobile;

            OfficialCityName = TreeTableBLL.GetFullPathName("MCS_SYS.dbo.Addr_OfficialCity", m.OfficialCity).Replace("->", " ");
            #endregion

            #region 绑定供货信息
            CM_ClientSupplierInfo SupplierInfo = ClientBLL.GetSupplierInfo(TDP);
            if (SupplierInfo != null)
            {
                CodeBySupplier = SupplierInfo.Code;
                Supplier       = SupplierInfo.Supplier;
                StandardPrice  = SupplierInfo.StandardPrice;
                TDPChannel     = SupplierInfo.TDPChannel;
                TDPSalesArea   = SupplierInfo.TDPSalesArea;
                VisitRoute     = SupplierInfo.VisitRoute;
                VisitSequence  = SupplierInfo.VisitSequence;
                VisitTemplate  = SupplierInfo.VisitTemplate;

                #region 获取供货商名称
                CM_Client s = new CM_ClientBLL(Supplier).Model;
                if (s != null)
                {
                    SupplierName = s.ShortName == "" ? s.ShortName : s.FullName;
                }
                #endregion

                #region 获取价表名称
                if (StandardPrice != 0)
                {
                    PDT_StandardPrice price = new PDT_StandardPriceBLL(StandardPrice).Model;
                    if (price != null)
                    {
                        StandardPriceName = price.Name;
                    }
                }
                #endregion

                #region 获取渠道名称
                if (TDPChannel > 0)
                {
                    CM_RTChannel_TDP channel = new CM_RTChannel_TDPBLL(TDPChannel).Model;
                    if (channel != null)
                    {
                        TDPChannelName = channel.Name;
                    }
                }
                #endregion

                #region 获取区域名称
                if (TDPSalesArea > 0)
                {
                    CM_RTSalesArea_TDP area = new CM_RTSalesArea_TDPBLL(TDPSalesArea).Model;
                    if (area != null)
                    {
                        TDPSalesAreaName = area.Name;
                    }
                }
                #endregion

                #region 获取路线及拜访模板名称
                if (VisitRoute != 0)
                {
                    VST_Route r = new VST_RouteBLL(VisitRoute).Model;
                    if (r != null)
                    {
                        VisitRouteName = r.Name;
                    }
                }

                if (VisitTemplate != 0)
                {
                    VST_VisitTemplate t = new VST_VisitTemplateBLL(VisitTemplate).Model;
                    if (t != null)
                    {
                        VisitTemplateName = t.Name;
                    }
                }
                #endregion

                #region 获取销售员名称
                if (Salesman != 0)
                {
                    Org_Staff staff = new Org_StaffBLL(Salesman).Model;
                    if (staff != null)
                    {
                        SalesmanName = staff.RealName;
                    }
                }
                #endregion
            }
            #endregion

            #region 绑定厂商管理信息
            int manufacturer = 0;           //归属厂商
            if (m.ClientType == 3)
            {
                //门店的归属厂商为当前TDP所归属的厂商
                CM_Client supplier = new CM_ClientBLL(TDP).Model;
                if (supplier != null)
                {
                    manufacturer = supplier.OwnerClient;
                }
            }
            else if (m.ClientType == 2)
            {
                //TDP经销商的归属厂商
                manufacturer = m.OwnerClient;
            }

            CM_ClientManufactInfo ManufactInfo = ClientBLL.GetManufactInfo(manufacturer);
            if (ManufactInfo != null)
            {
                CodeByManufaturer = ManufactInfo.Code;
            }
            #endregion

            #region 绑定客户定位信息
            CM_ClientGeoInfo geo = CM_ClientGeoInfoBLL.GetGeoInfoByClient(m.ID);
            if (geo != null)
            {
                Latitude  = (float)geo.Latitude;
                Longitude = (float)geo.Longitude;
            }
            #endregion

            #region 绑定客户供货产品目录
            ClientProductLists = new List <ProductList>();
            foreach (CM_ClientProductList item in CM_ClientProductListBLL.GetModelList
                         ("Client=" + m.ID.ToString() + (TDP == 0 ? "" : " AND Supplier=" + TDP.ToString())))
            {
                ClientProductLists.Add(new ProductList(item));
            }
            #endregion

            #region 查询预收款余额
            AC_CurrentAccount ac = AC_CurrentAccountBLL.GetByTradeClient(TDP, m.ID);
            if (ac != null)
            {
                ARBalance = ac.PreReceivedAmount - ac.AR;
            }
            #endregion

            #region 获取附件明细
            IList <ATMT_Attachment> atts = ATMT_AttachmentBLL.GetAttachmentList(30, m.ID, DateTime.Today.AddMonths(-3), new DateTime(2100, 1, 1));
            Atts = new List <Attachment>(atts.Count);
            foreach (ATMT_Attachment item in atts.OrderByDescending(p => p.UploadTime))
            {
                Atts.Add(new Attachment(item));
            }
            #endregion
        }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        CM_ClientBLL _bll = null;

        if (ViewState["ClientID"] == null || (int)ViewState["ClientID"] == 0)
        {
            _bll = new CM_ClientBLL();
        }
        else
        {
            _bll = new CM_ClientBLL((int)ViewState["ClientID"]);
        }

        CM_ClientSupplierInfo supplierinfo = _bll.GetSupplierInfo((int)Session["OwnerClient"]);
        CM_ClientManufactInfo manufactinfo = _bll.GetManufactInfo((int)Session["Manufacturer"]);

        if (supplierinfo == null)
        {
            supplierinfo          = new CM_ClientSupplierInfo();
            supplierinfo.Supplier = (int)Session["OwnerClient"];
        }
        if (manufactinfo == null)
        {
            manufactinfo = new CM_ClientManufactInfo();
            manufactinfo.Manufacturer = (int)Session["Manufacturer"];

            //门店所属区域为经销商对应区域
            CM_ClientBLL s = new CM_ClientBLL((int)Session["OwnerClient"]);
            manufactinfo.OrganizeCity = s.GetManufactInfo().OrganizeCity;
        }

        pl_detail.GetData(_bll.Model);
        pl_detail.GetData(supplierinfo);

        #region 判断必填项
        #endregion

        #region 判断活跃标志
        if (supplierinfo.State == 1 && supplierinfo.EndDate != new DateTime(1900, 1, 1))
        {
            supplierinfo.EndDate = new DateTime(1900, 1, 1);
        }

        if (supplierinfo.State == 2 && supplierinfo.EndDate == new DateTime(1900, 1, 1))
        {
            supplierinfo.EndDate = DateTime.Now;
        }
        #endregion

        if (ViewState["ClientID"] == null || (int)ViewState["ClientID"] == 0)
        {
            _bll.Model.ClientType  = 3;
            _bll.Model.ApproveFlag = 1;
            _bll.Model.InsertStaff = (int)Session["UserID"];
            _bll.Model.OwnerType   = 3;         //所属经销商
            _bll.Model.OwnerClient = (int)Session["OwnerClient"];
            ViewState["ClientID"]  = _bll.Add();

            _bll.SetSupplierInfo(supplierinfo);
            _bll.SetManufactInfo(manufactinfo);
        }
        else
        {
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            _bll.Update();
            _bll.SetSupplierInfo(supplierinfo);
            _bll.SetManufactInfo(manufactinfo);
        }

        Response.Redirect("RetailerDetail.aspx?ClientID=" + ViewState["ClientID"].ToString());
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // 在此处放置用户代码以初始化页面
        if (!Page.IsPostBack)
        {
            int ClientID = Request.QueryString["ClientID"] != null && int.TryParse(Request.QueryString["ClientID"].ToString(), out ClientID) ? ClientID : 0;
            ViewState["ClientID"] = ClientID;

            BindDropDown();

            if ((int)ViewState["ClientID"] > 0)
            {
                BindData();
            }
            else
            {
                #region 新增门店时的初始值
                CM_Client tdp = new CM_ClientBLL((int)Session["OwnerClient"]).Model;
                if (tdp == null)
                {
                    Response.Redirect("RetailerList.aspx");
                    return;
                }

                CM_Client m = new CM_Client();
                m.OfficialCity = tdp.OfficialCity;
                m.PostCode     = tdp.PostCode;

                CM_ClientSupplierInfo supplierinfo = new CM_ClientSupplierInfo();
                supplierinfo.State         = 1;
                supplierinfo.BeginDate     = DateTime.Today;
                supplierinfo.StandardPrice = PDT_StandardPriceBLL.GetDefaultPrice(tdp.ID);

                pl_detail.BindData(m);
                pl_detail.BindData(supplierinfo);

                bt_Map.Visible        = false;
                bt_AddLinkMan.Visible = false;
                tr_LinkMan.Visible    = false;

                #region 新增客户时,首要联系人字段不可编辑
                DropDownList ddl_ChiefLinkMan = (DropDownList)pl_detail.FindControl("CM_Client_ChiefLinkMan");
                try
                {
                    if (ddl_ChiefLinkMan != null)
                    {
                        ddl_ChiefLinkMan.Items.Clear();
                        ddl_ChiefLinkMan.Enabled = false;
                    }
                }
                catch { }
                #endregion

                #endregion
            }
        }

        #region 给活跃标志加事件
        //DropDownList ddl_ActiveFlag_1 = (DropDownList)pl_detail.FindControl("CM_Client_ActiveFlag");
        //ddl_ActiveFlag_1.AutoPostBack = true;
        //ddl_ActiveFlag_1.SelectedIndexChanged += new EventHandler(ddl_ActiveFlag_SelectedIndexChanged);
        #endregion


        #region 注册弹出窗口脚本
        string script = "function Pop_MapShow(id){\r\n";
        script += "var tempid = Math.random() * 10000; \r\n window.showModalDialog('" + Page.ResolveClientUrl("~/SubModule/CM/Map/ClientInMap.aspx") +
                  "?ClientID=' + id + '&tempid='+tempid, window, 'dialogWidth:800px;DialogHeight=550px;status:yes;resizable=yes');}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopShow", script, true);
        #endregion
    }
Exemple #9
0
        public string DoImportClient(int TemplateID, int Client, ISheet Sheet, out int State)
        {
            string ImportInfo = "【客户资料】Excel表:";

            State = 0;
            IPT_UploadTemplateBLL _template = new IPT_UploadTemplateBLL(TemplateID);

            List <string> listClient = new List <string>()
            {
                "序号", "区域", "渠道", "客户编号", "客户名称", "联系人", "地址", "电话", "手机", "销售线路", "备注"
            };

            DataTable dt   = null;
            bool      flag = VertifySheet(Sheet, listClient, out dt, ref ImportInfo);

            if (!flag)
            {
                State = 4; return(ImportInfo);
            }

            foreach (DataRow dr in dt.Rows)//循环导入数据
            {
                try
                {
                    string _ClientCode = dr["客户编号"].ToString();//客户自编码
                    string _ClientName = dr["客户名称"].ToString();

                    if (string.IsNullOrEmpty(_ClientCode))                                        // && string.IsNullOrEmpty(_ClientName)
                    {
                        ImportInfo += "导入序列号为" + dr["序号"].ToString() + "的数据行时找不到门店编码,跳过此行记录\r\n"; //门店名称和
                        continue;
                    }
                    IList <CM_Client> _listClient = CM_ClientBLL.GetModelList(" ApproveFlag=1 AND ClientType=3 AND OwnerType=3 AND OwnerClient=" + _template.Model.ClientID + "AND EXISTS(SELECT 1 FROM MCS_CM.dbo.CM_ClientSupplierInfo WHERE Supplier=" + _template.Model.ClientID + " AND Client= CM_Client.id  AND Code=" + _ClientCode + " ) ");
                    if (_listClient != null && _listClient.Count > 0)
                    {
                        ImportInfo += "导入序列号为" + dr["序号"].ToString() + "的数据行时找到相同编码的门店,跳过此行记录\r\n";
                        continue;
                    }

                    string _ClientLinkMan = dr["联系人"].ToString();
                    string _ClientAddress = dr["地址"].ToString();
                    string _ClientTel     = dr["电话"].ToString();
                    string _ClientMobile  = dr["手机"].ToString();
                    #region 获取线路
                    string    _strClientVisitRoute = dr["销售线路"].ToString();                                                                //业务拜访模板Code
                    VST_Route _route = null;
                    if (!string.IsNullOrEmpty(_strClientVisitRoute))                                                                       //优先匹配厂商级的拜访记录
                    {
                        _route = VST_RouteBLL.GetModelList(" OwnerType IN(1,2) AND Code='" + _strClientVisitRoute + "'").FirstOrDefault(); //IList<VST_Route>_listRoute
                        if (_route == null)                                                                                                //找不到厂商级的线路找经销商级别的
                        {
                            _route = VST_RouteBLL.GetModelList(" OwnerType=3 AND OwnerClient=" + _template.Model.ClientID + " AND Code='" + _strClientVisitRoute + "'").FirstOrDefault();
                        }
                    }

                    /*模板中存在负责业务时获取门店业代和拜访记录代码
                     * int _ClientSalesMan = 0;//负责业务
                     * int _ClientVisitRoute = 0;//业务拜访模板ID
                     * string _strClientSalesMan = dr["负责业务"].ToString();
                     * if (!string.IsNullOrEmpty(_strClientSalesMan))
                     * {
                     *  IList<Org_Staff> _listStaff = Org_StaffBLL.GetStaffList(" OwnerClient=" + _template.Model.ClientID + " AND OwnerType=3 AND RealName='" + _strClientSalesMan + "'");
                     *  if (_listStaff != null && _listStaff.Count > 0)
                     *  {
                     *      _ClientSalesMan = _listStaff[0].ID;
                     *      IList<VST_Route> _listRoute = VST_RouteBLL.GetModelList(" OwnerClient=" + _template.Model.ClientID + " AND RelateStaff=" + _ClientSalesMan);
                     *      if (_listRoute != null && _listRoute.Count > 0) _ClientVisitRoute = _listRoute[0].ID;
                     *  }
                     *  else
                     *  {
                     *      Org_StaffBLL _bllStaff = new Org_StaffBLL();
                     *      CM_ClientBLL c = new CM_ClientBLL(_template.Model.ClientID);
                     *      CM_ClientManufactInfo manufactinfo = c.GetManufactInfo();
                     *      if (c != null && manufactinfo != null)
                     *      {
                     *          _bllStaff.Model.OrganizeCity = manufactinfo.OrganizeCity;
                     *          _bllStaff.Model.OfficialCity = c.Model.OfficialCity;
                     *      }
                     *      _bllStaff.Model.RealName = _strClientSalesMan;
                     *      _bllStaff.Model.Position = 1030;//默认为业务员
                     *      _bllStaff.Model.InsertStaff = _template.Model.InsertStaff;
                     *      _bllStaff.Model.OwnerClient = _template.Model.ClientID;
                     *      _bllStaff.Model.OwnerType = 3;
                     *      _bllStaff.Model.Dimission = 1;
                     *      _bllStaff.Model.ApproveFlag = 1;
                     *      _ClientSalesMan = _bllStaff.Add();
                     *      //创建默认员工线路
                     *      if (_ClientSalesMan > 0)
                     *      {
                     *          if (_bllStaff.Model.Position == 1030)
                     *          {
                     *              VST_RouteBLL routebll = new VST_RouteBLL();
                     *              routebll.Model.Code = "R" + _ClientSalesMan.ToString();
                     *              routebll.Model.Name = "线路-" + _bllStaff.Model.RealName;
                     *              routebll.Model.RelateStaff = _ClientSalesMan;
                     *              routebll.Model.OrganizeCity = _bllStaff.Model.OrganizeCity;
                     *              routebll.Model.OwnerClient = _template.Model.ClientID;
                     *              routebll.Model.OwnerType = 3;
                     *              routebll.Model.ApproveFlag = 1;
                     *              routebll.Model.EnableFlag = "Y";
                     *              routebll.Model.InsertStaff = _template.Model.InsertStaff;
                     *              _ClientVisitRoute = routebll.Add();
                     *          }
                     *      }
                     *  }
                     * }*/
                    #endregion
                    string _ClientRemark = dr["备注"].ToString();

                    int _OwnerClient = _template.Model.ClientID;

                    #region 获取所在区域
                    int    _SalesArea    = 0;//区域
                    string _strSalesArea = dr["区域"].ToString();
                    if (!string.IsNullOrEmpty(_strSalesArea))
                    {
                        IList <CM_RTSalesArea_TDP> _listSalesArea = CM_RTSalesArea_TDPBLL.GetModelList(" OwnerClient= " + _OwnerClient.ToString() + " AND Name='" + _strSalesArea + "' ");
                        if (_listSalesArea != null && _listSalesArea.Count > 0)
                        {
                            _SalesArea = _listSalesArea[0].ID;
                        }
                        else
                        {
                            CM_RTSalesArea_TDPBLL _bllRTSalesArea_TDPBLL = new CM_RTSalesArea_TDPBLL();
                            _bllRTSalesArea_TDPBLL.Model.Name        = _strSalesArea;
                            _bllRTSalesArea_TDPBLL.Model.OwnerClient = _OwnerClient;
                            _bllRTSalesArea_TDPBLL.Model.Remark      = "Excel批量导入";
                            _bllRTSalesArea_TDPBLL.Model.InsertStaff = _template.Model.InsertStaff;
                            _bllRTSalesArea_TDPBLL.Model.InsertTime  = DateTime.Now;
                            _SalesArea = _bllRTSalesArea_TDPBLL.Add();
                        }
                    }
                    #endregion
                    #region 获取所在渠道
                    int    _RTChannel    = 0;//渠道
                    string _strRTChannel = dr["渠道"].ToString();
                    if (!string.IsNullOrEmpty(_strRTChannel))
                    {
                        IList <CM_RTChannel_TDP> _listRTChannel = CM_RTChannel_TDPBLL.GetModelList(" OwnerClient= " + _OwnerClient.ToString() + " AND Name='" + _strRTChannel + "' ");
                        if (_listRTChannel != null && _listRTChannel.Count > 0)
                        {
                            _RTChannel = _listRTChannel[0].ID;
                        }
                        else
                        {
                            CM_RTChannel_TDPBLL _bllRTSalesArea_TDPBLL = new CM_RTChannel_TDPBLL();
                            _bllRTSalesArea_TDPBLL.Model.Name        = _strRTChannel;
                            _bllRTSalesArea_TDPBLL.Model.OwnerClient = _OwnerClient;
                            _bllRTSalesArea_TDPBLL.Model.Remark      = "Excel批量导入";
                            _bllRTSalesArea_TDPBLL.Model.InsertStaff = _template.Model.InsertStaff;
                            _bllRTSalesArea_TDPBLL.Model.InsertTime  = DateTime.Now;
                            _RTChannel = _bllRTSalesArea_TDPBLL.Add();
                        }
                    }
                    #endregion

                    CM_ClientBLL _bll = new CM_ClientBLL();//Client表Code字段暂不启用,以FactoryCode作为厂商编码。经销商对门店的编码存于CM_ClientSupplierInfo表的Code字段
                    _bll.Model.FullName    = _ClientName;
                    _bll.Model.ShortName   = _ClientName;
                    _bll.Model.LinkManName = _ClientLinkMan;
                    _bll.Model.Address     = _ClientAddress;
                    _bll.Model.TeleNum     = _ClientTel;
                    _bll.Model.Mobile      = _ClientMobile;
                    _bll.Model.Remark      = string.IsNullOrEmpty(_ClientRemark) ? "Excel批量导入" : _ClientRemark;
                    _bll.Model.ClientType  = 3;
                    _bll.Model.ApproveFlag = 1;
                    _bll.Model.InsertStaff = _template.Model.InsertStaff;
                    _bll.Model.OwnerType   = 3;         //所属经销商
                    _bll.Model.OwnerClient = _OwnerClient;
                    int _ClientID = _bll.Add();
                    if (_ClientID > 0)
                    {
                        CM_ClientSupplierInfo _Supplierinfo = _bll.GetSupplierInfo(_OwnerClient);
                        if (_Supplierinfo == null)
                        {
                            _Supplierinfo          = new CM_ClientSupplierInfo();
                            _Supplierinfo.Supplier = _OwnerClient;
                        }
                        _Supplierinfo.TDPChannel   = _RTChannel;
                        _Supplierinfo.TDPSalesArea = _SalesArea;
                        _Supplierinfo.Code         = _ClientCode;
                        _Supplierinfo.Remark       = _ClientRemark;

                        CM_ClientBLL          s             = new CM_ClientBLL(_OwnerClient);
                        CM_ClientManufactInfo _manufactinfo = _bll.GetManufactInfo(s.Model.OwnerClient);
                        if (_manufactinfo == null)
                        {
                            _manufactinfo = new CM_ClientManufactInfo();
                            //门店所属区域为经销商对应区域
                            _manufactinfo.Manufacturer = s.Model.OwnerClient;
                            _manufactinfo.OrganizeCity = s.GetManufactInfo().OrganizeCity;
                        }

                        if (_route != null && _route.OwnerType == 3)//线路为经销商级别的存放在经销商表中
                        {
                            _Supplierinfo.VisitRoute = _route.ID;
                        }
                        else if (_route != null && (_route.OwnerType == 1 || _route.OwnerType == 2))//线路为厂商级别的存放在经销商表中
                        {
                            _manufactinfo.VisitRoute = _route.ID;
                        }

                        _bll.SetSupplierInfo(_Supplierinfo);
                        _bll.SetManufactInfo(_manufactinfo);
                    }
                }
                catch (Exception ex)
                {
                    ImportInfo += "导入序列号为" + dr["序号"].ToString() + "的数据行时出现错误,错误说明:" + ex.Message + "\r\n";
                    State       = 5;
                    continue;
                }
            }
            if (State == 0)
            {
                State = 3;
            }
            ImportInfo += (State == 3 ? "导入完成!\r\n" : "");
            IPT_UploadTemplateMessageBLL _bllUploadTemplateMessage = new IPT_UploadTemplateMessageBLL();
            _bllUploadTemplateMessage.Model.TemplateID  = TemplateID;
            _bllUploadTemplateMessage.Model.MessageType = State;
            _bllUploadTemplateMessage.Model.Content     = ImportInfo;
            _bllUploadTemplateMessage.Add();
            return(ImportInfo);
        }