/// <summary> /// 新增门店资料 /// </summary> /// <param name="User">用户</param> /// <param name="TDP"></param> /// <param name="ClientJson">门店资料Json</param> /// <returns>大于0:新增的门店ID -1:Json字符串无法解析 -2:所属经销商无效 -3:新增门店基本资料失败</returns> public static int RetailerAdd(UserInfo User, int TDP, ClientInfo Client, out string ErrorInfo) { ErrorInfo = ""; LogWriter.WriteLog("PBMIFService.RetailerAdd:UserName="******",TDP=" + TDP.ToString() + ",ClientInfo=" + JsonConvert.SerializeObject(Client)); if (User.OwnerType == 3) TDP = User.ClientID; try { ClientInfo c = Client; if (c == null) { ErrorInfo = "Json字符串无法解析"; return -1; } //Json字符串无法解析 CM_Client TDPClient = new CM_ClientBLL(TDP).Model; if (TDPClient == null) { ErrorInfo = "所属经销商无效"; return -2; } //所属经销商无效 #region 判断必填与重复检测 if (c.FullName == "") { ErrorInfo = "门店名称必填"; return -10; } if (c.Mobile == "") { ErrorInfo = "联系电话必填"; return -10; } if (c.Address == "") { ErrorInfo = "门店地址必填"; return -10; } if (c.Mobile.StartsWith("01")) c.Mobile = c.Mobile.Substring(1); if (c.TeleNum.Contains("-")) c.TeleNum = c.TeleNum.Replace("-", ""); if (c.Mobile.Contains("-")) c.Mobile = c.Mobile.Replace("-", ""); //检查门店资料重复 int rptclientid = CM_ClientBLL.CheckRepeat(TDP, 0, c.Mobile, c.TeleNum, c.FullName, c.Address); if (rptclientid > 0) { CM_Client _rptclient = new CM_ClientBLL(rptclientid).Model; ErrorInfo = "门店资料与[" + _rptclient.FullName + "]资料重复,请勿重复新增!"; return -11; } #endregion CM_ClientBLL bll = new CM_ClientBLL(); #region 门店基本资料 bll.Model.Code = c.Code; bll.Model.FullName = c.FullName != "" ? c.FullName : c.ShortName; bll.Model.ShortName = c.ShortName == "" ? c.FullName : c.ShortName; if (c.OfficialCity > 0) bll.Model.OfficialCity = c.OfficialCity; else bll.Model.OfficialCity = TDPClient.OfficialCity; bll.Model.Address = c.Address; bll.Model.DeliveryAddress = c.Address; bll.Model.LinkManName = c.LinkManName; bll.Model.TeleNum = c.TeleNum == "" ? c.Mobile : c.TeleNum; if (c.Mobile.StartsWith("1") && c.Mobile.Length == 11) bll.Model.Mobile = c.Mobile; bll.Model.OpenTime = DateTime.Parse("1900-01-01 08:00"); bll.Model.CloseTime = DateTime.Parse("1900-01-01 20:00"); bll.Model.ClientType = 3; bll.Model.InsertStaff = User.StaffID; bll.Model.OwnerType = 3; bll.Model.OwnerClient = TDPClient.ID; bll.Model.ApproveFlag = 2; //默认为未审核 #endregion int retailerid = bll.Add(); if (retailerid < 0) { ErrorInfo = "新增门店基本资料失败"; return -3; } //新增门店基本资料失败 #region 设置供货商信息 CM_ClientSupplierInfo supplierinfo = new CM_ClientSupplierInfo(); supplierinfo.Code = c.CodeBySupplier; supplierinfo.Client = retailerid; supplierinfo.Supplier = TDP; if (User.OwnerType == 3) { supplierinfo.Salesman = User.StaffID; IList<VST_Route> routes = VST_RouteBLL.GetRouteListByStaff(User.StaffID); if (routes.Count > 0) supplierinfo.VisitRoute = routes[0].ID; } supplierinfo.StandardPrice = c.StandardPrice; supplierinfo.TDPChannel = c.TDPChannel; supplierinfo.TDPSalesArea = c.TDPSalesArea; supplierinfo.VisitSequence = c.VisitSequence; supplierinfo.VisitTemplate = c.VisitTemplate; supplierinfo.InsertStaff = User.StaffID; bll.SetSupplierInfo(supplierinfo); #endregion #region 设置厂商管理信息 CM_ClientManufactInfo manufactinfo = new CM_ClientManufactInfo(); manufactinfo.Client = retailerid; manufactinfo.Code = c.CodeByManufaturer; manufactinfo.Manufacturer = TDPClient.OwnerClient; //门店归属厂商默认为经销商资料的所属厂商 if (User.OwnerType == 2) { manufactinfo.ClientManager = User.StaffID; IList<VST_Route> routes = VST_RouteBLL.GetRouteListByStaff(User.StaffID); if (routes.Count > 0) manufactinfo.VisitRoute = routes[0].ID; } //门店所属区域为经销商对应区域 CM_ClientBLL s = new CM_ClientBLL(TDP); manufactinfo.OrganizeCity = s.GetManufactInfo().OrganizeCity; bll.SetManufactInfo(manufactinfo); #endregion #region 保存 #endregion return retailerid; } catch (System.Exception err) { LogWriter.WriteLog("PBMIFService.RetailerAdd Exception Error!", err); return -100; } }
public string DoImportSupplier(int TemplateID, int Client, ISheet Sheet, out int State) { string ImportInfo = "【供货单位信息】Excel表:"; State = 0; IPT_UploadTemplateBLL _template = new IPT_UploadTemplateBLL(TemplateID); List<string> listSupplier = new List<string>() { "序号", "客户名称", "地址", "联系人", "电话" }; DataTable dt = null; bool flag = VertifySheet(Sheet, listSupplier, out dt, ref ImportInfo); if (!flag) { State = 4; return ImportInfo; } foreach (DataRow dr in dt.Rows)//循环导入数据 { try { string _SupplierName = dr["客户名称"].ToString(); string _SupplierAddress = dr["地址"].ToString(); string _SupplierTeleNum = dr["电话"].ToString(); string _SupplierLinkMan = dr["联系人"].ToString(); if (string.IsNullOrEmpty(_SupplierName)) { ImportInfo += string.Format("序号为{0}的行客户名称均为空,跳过此行信息\r\n", dr["序号"]); continue; } IList<CM_Client> _listClient = CM_ClientBLL.GetModelList(" ClientType=1 AND OwnerType=3 AND OwnerClient=" + _template.Model.ClientID.ToString() + " AND FullName='" + _SupplierName + "'"); if (_listClient != null && _listClient.Count > 0) { ImportInfo += string.Format("序号为{0},名称为{1}的客户已存在,跳过此行信息\r\n", dr["序号"], _SupplierName); continue; } CM_ClientBLL _bllClient = new CM_ClientBLL(); _bllClient.Model.FullName = _SupplierName; _bllClient.Model.ShortName = _SupplierName; _bllClient.Model.Address = _SupplierAddress; _bllClient.Model.TeleNum = _SupplierTeleNum; _bllClient.Model.Remark = "Excel批量导入"; _bllClient.Model.ClientType = 1; _bllClient.Model.OwnerType = 3; _bllClient.Model.OwnerClient = _template.Model.ClientID; _bllClient.Add(); } 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; }
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; }
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; }
public string DoImportSupplier(int TemplateID, int Client, ISheet Sheet, out int State) { string ImportInfo = "【供货单位信息】Excel表:"; State = 0; IPT_UploadTemplateBLL _template = new IPT_UploadTemplateBLL(TemplateID); List <string> listSupplier = new List <string>() { "序号", "客户名称", "地址", "联系人", "电话" }; DataTable dt = null; bool flag = VertifySheet(Sheet, listSupplier, out dt, ref ImportInfo); if (!flag) { State = 4; return(ImportInfo); } foreach (DataRow dr in dt.Rows)//循环导入数据 { try { string _SupplierName = dr["客户名称"].ToString(); string _SupplierAddress = dr["地址"].ToString(); string _SupplierTeleNum = dr["电话"].ToString(); string _SupplierLinkMan = dr["联系人"].ToString(); if (string.IsNullOrEmpty(_SupplierName)) { ImportInfo += string.Format("序号为{0}的行客户名称均为空,跳过此行信息\r\n", dr["序号"]); continue; } IList <CM_Client> _listClient = CM_ClientBLL.GetModelList(" ClientType=1 AND OwnerType=3 AND OwnerClient=" + _template.Model.ClientID.ToString() + " AND FullName='" + _SupplierName + "'"); if (_listClient != null && _listClient.Count > 0) { ImportInfo += string.Format("序号为{0},名称为{1}的客户已存在,跳过此行信息\r\n", dr["序号"], _SupplierName); continue; } CM_ClientBLL _bllClient = new CM_ClientBLL(); _bllClient.Model.FullName = _SupplierName; _bllClient.Model.ShortName = _SupplierName; _bllClient.Model.Address = _SupplierAddress; _bllClient.Model.TeleNum = _SupplierTeleNum; _bllClient.Model.Remark = "Excel批量导入"; _bllClient.Model.ClientType = 1; _bllClient.Model.OwnerType = 3; _bllClient.Model.OwnerClient = _template.Model.ClientID; _bllClient.Add(); } 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); }
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); }