/* * /// <summary> * /// 初始化配置信息 * /// </summary> * private static void InitConfig() * { * enterprisecode = ConfigurationManager.AppSettings["EnterpriseCode"]; * enterprisename = ConfigurationManager.AppSettings["EnterpriseName"]; * itemname = ConfigurationManager.AppSettings["ItemName"]; * useramount = Convert.ToInt32(ConfigurationManager.AppSettings["UserAmount"]); * startdate = Convert.ToDateTime(ConfigurationManager.AppSettings["StartDate"]); * expiredate = Convert.ToDateTime(ConfigurationManager.AppSettings["ExpireDate"]); * adminusername = ConfigurationManager.AppSettings["AdminUserName"]; * adminpassword = ConfigurationManager.AppSettings["AdminPassword"]; * * teammodelid = Convert.ToInt32(ConfigurationManager.AppSettings["TeamModelID"]); * teamscalexml = ConfigurationManager.AppSettings["TeamScaleXml"]; * } * * /// <summary> * /// 开始添加测试数据 * /// </summary> * private static void StartProgram() * { * Console.WriteLine("请输入要添加的企业数量:"); * string content = Console.ReadLine(); * int num; * while(!int.TryParse(content, out num)) * { * Console.WriteLine("输入错误请继续:"); * content = Console.ReadLine(); * } * * string code=enterprisecode; * string name=enterprisename; * //InsertData(code, name); * for (int i = 0; i < num; i++) * { * //Console.WriteLine(string .Format("第{0}个企业",i+1)); * code = code.Substring(0, 4) + (Convert.ToInt32(code.Substring(4)) + 1).ToString(); * name = name.Substring(0, 2) + (Convert.ToInt32(name.Substring(2)) + 1).ToString(); * if (!InsertData(code, name)) * { * Console.WriteLine("出错"); * new Log().WriteLog("出错"); * break; * } * } * //然后把最后的企业号修改到配置文件中,为了下次可直接运行。 * Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); * AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings"); * appsection.Settings["EnterpriseCode"].Value = code; * appsection.Settings["EnterpriseName"].Value = name; * config.Save(); * } * * /// <summary> * /// 插入数据 * /// </summary> * /// <returns></returns> * private static bool InsertData(string code,string name) * { * bool flag; * int EnterpriseID = new Program().AddEnterprise(code,name); * if (EnterpriseID <= 0) * { * new Log().WriteLog("添加企业基本信息失败"); * Console.WriteLine("添加企业基本信息失败"); * return false; * } * * flag = new Program().AddUser(EnterpriseID); * if (!flag) * { * new Log().WriteLog("添加用户失败"); * Console.WriteLine("添加用户失败"); * return false; * } * * flag = new Program().AddClientInfo(EnterpriseID, name); * if (!flag) * { * new Log().WriteLog("添加名录失败"); * Console.WriteLine("添加名录失败"); * return false; * } * return true; * } * * /// <summary> * /// 添加企业 * /// </summary> * /// <returns></returns> * private int AddEnterprise(string code,string name) * { * int EnterpriseID = 0; * //---添加企业---- * E_Enterprise EPdata = new E_Enterprise(); * EPdata.EnterpriseCode = code; * EPdata.EnterpriseNames = name; * EPdata.ItemName = itemname; * EPdata.UserAmount = useramount; * EPdata.StartDate = startdate; * EPdata.ExpireDate = expiredate; * EPdata.AdminUserName = adminusername; * EPdata.AdminPassword = MLMGC.COMP.EncryptString.EncryptPassword(adminpassword); * * DateTime now = DateTime.Now; * EnterpriseID = new DataSql().Add(EPdata); * Console.WriteLine("添加企业时间:" + (DateTime.Now - now).TotalMilliseconds.ToString()); * if (EnterpriseID == 0) * { * //new Log().WriteLog("添加企业出错"); * //Console.WriteLine("添加企业出错"); * return 0; * } * * new Log().WriteLog("添加企业成功,企业号:" + EnterpriseID.ToString()); * Console.WriteLine("添加企业成功,企业号:" + EnterpriseID.ToString()); * //------------------- * * //------------设置企业团队模型------------ * E_TeamModel TMdata = new E_TeamModel(); * TMdata.EnterpriseID = EnterpriseID; * TMdata.TeamModelID = teammodelid; * now = DateTime.Now; * int result = new DataSql().SetTeamModel(TMdata); * Console.WriteLine("设置团队模型时间:" + (DateTime.Now - now).TotalMilliseconds.ToString()); * if (result <= 0) * { * //new Log().WriteLog("设置团队模型出错"); * //Console.WriteLine("设置团队模型出错"); * return 0; * } * //new Log().WriteLog("设置团队模型成功"); * //Console.WriteLine("设置团队模型成功"); * //--------------------------------------- * * //----------设置企业团队规模--------- * E_TeamModel data = new E_TeamModel(); * data.EnterpriseID = EnterpriseID; * data.TeamScaleXml = teamscalexml; * data.Child_RoleID = "3,4";//经理roleid 3,组长roleid 4; * data.Child_RoleAmount = "2,4";//经理 2,组长 3; * result = new DataSql().UpdateTeamScale(data); * if (result < 0) * { * //new Log().WriteLog("设置企业团队规模出错"); * //Console.WriteLine("设置企业团队规模出错"); * return 0; * } * //new Log().WriteLog("设置企业团队规模成功"); * //Console.WriteLine("设置企业团队规模成功"); * //---------------------------------- * * //---------修改团队信息(指定上级)---------- * string sql = string.Format("UPDATE dbo.EP_B_Team SET pid= 3 WHERE EnterpriseID={0} AND TeamType=2 AND TeamModelRoleID =9;UPDATE t SET t.pid = 2 FROM (SELECT TOP 2 * FROM dbo.EP_B_Team WHERE EnterpriseID={0} AND TeamType=2 AND TeamModelRoleID =9) t;", EnterpriseID); * //new Log().WriteLog(sql); * //Console.WriteLine(sql); * now = DateTime.Now; * DbHelperSQL.ExecuteSql(sql); * Console.WriteLine("修改团队上级时间:" + (DateTime.Now - now).TotalMilliseconds.ToString()); * //new Log().WriteLog("修改团队信息完成"); * //Console.WriteLine("修改团队信息完成"); * //----------------------------------------- * * //new Log().WriteLog("添加企业完成"); * //Console.WriteLine("添加企业完成"); * return EnterpriseID; * } * * /// <summary> * /// 添加企业用户 * /// </summary> * /// <returns></returns> * private bool AddUser(int EnterpriseID) * { * if (EnterpriseID == 0) * { * new Log().WriteLog("没有企业号"); * Console.WriteLine("没有企业号"); * return false; * } * E_User data = new E_User(); * data.EnterpriseID = EnterpriseID; * data.UserName = "******"; * data.Password = MLMGC.COMP.EncryptString.EncryptPassword("123456"); * data.UserType = (int)UserType.企业用户; * data.TrueName = "总监"; * data.RoleSetting = "7:1"; * if (new DataSql().AddEnterpriseUser(data) < 1) * { * new Log().WriteLog("添加总监失败"); * Console.WriteLine("添加总监失败"); * return false ; * } * //new Log().WriteLog("添加总监成功"); * //Console.WriteLine("添加总监成功"); * * //经理 * for (int i = 0; i < 2; i++) * { * data.UserName = string.Format("jili{0}", i + 1); * data.TrueName = string.Format("经理{0}", i + 1); * data.RoleSetting = string.Format("8:{0}", i + 2); * if (new DataSql().AddEnterpriseUser(data) < 1) * { * new Log().WriteLog(string.Format("添加经理{0}失败",i+1)); * Console.WriteLine(string.Format("添加经理{0}失败", i + 1)); * return false; * } * //new Log().WriteLog(string.Format("添加经理{0}成功", i + 1)); * //Console.WriteLine(string.Format("添加经理{0}成功", i + 1)); * } * * //组长 * * for (int i = 0; i < 4; i++) * { * data.UserName = string.Format("zuzhang{0}", i + 1); * data.TrueName = string.Format("组长{0}", i + 1); * data.RoleSetting = string.Format("9:{0}", i+4); * if (new DataSql().AddEnterpriseUser(data) < 1) * { * new Log().WriteLog(string.Format("添加组长{0}失败", i + 1)); * Console.WriteLine(string.Format("添加组长{0}失败", i + 1)); * return false; * } * //new Log().WriteLog(string.Format("添加组长{0}成功", i + 1)); * //Console.WriteLine(string.Format("添加组长{0}成功", i + 1)); * } * * //业务员 * for (int i = 0; i < 100; i++) * { * data.UserName = string.Format("yewuyuan{0}", i + 1); * data.TrueName = string.Format("业务员{0}", i + 1); * data.RoleSetting = string.Format("10:{0}", i/25 + 4); * DateTime now = DateTime.Now; * if (new DataSql().AddEnterpriseUser(data) < 1) * { * new Log().WriteLog(string.Format("添加业务员{0}失败", i + 1)); * Console.WriteLine(string.Format("添加业务员{0}失败", i + 1)); * return false; * } * double d =(DateTime.Now - now).TotalMilliseconds; * if(d>=250) * Console.WriteLine("添加一个业务员时间:" + d.ToString ()); * //new Log().WriteLog(string.Format("添加业务员{0}成功", i + 1)); * //Console.WriteLine(string.Format("添加业务员{0}成功", i + 1)); * } * //new Log().WriteLog("添加用户完成"); * //Console.WriteLine("添加用户完成"); * return true; * } * * /// <summary> * /// 添加名录 * /// </summary> * /// <returns></returns> * private bool AddClientInfo(int EnterpriseID, string name) * { * if (EnterpriseID == 0) * { * new Log().WriteLog("没有企业号"); * Console.WriteLine("没有企业号"); * return false; * } * bool flag; * //查询所有业务员 * string sql = string.Format("select EPUserTMRID from EP_R_EPUserTMR where EnterpriseID ={0} and TeamModelRoleID =10", EnterpriseID); * DataTable dt = DbHelperSQL.Query(sql).Tables[0]; * if (dt == null) * { * new Log().WriteLog("没有找到业务员"); * Console.WriteLine("没有找到业务员"); * return false; * } * int EPUserTMRID = 0; * * E_ClientInfo data = new E_ClientInfo(); * data.EnterpriseID = EnterpriseID; * foreach (DataRow row in dt.Rows) * { * EPUserTMRID = Convert.ToInt32(row["EPUserTMRID"]); * data.EPUserTMRID = EPUserTMRID; * Console.WriteLine(data.EPUserTMRID); * DateTime now = DateTime.Now; * for (int i = 0; i < 40000; i++) //每个人5条名录 * { * data.ClientName = string.Format("{0}{1}{2}", name, EPUserTMRID, i); * flag = new DataSql().Add(data); * if (!flag) * { * new Log().WriteLog(string.Format("添加{0}的第{1}个名录出错", EPUserTMRID, i)); * Console.WriteLine(string.Format("添加{0}的第{1}个名录出错", EPUserTMRID, i)); * return false; * } * } * Console.WriteLine((DateTime.Now - now).TotalSeconds.ToString()); * } * //Console.WriteLine("添加名录完成"); * //new Log().WriteLog("添加名录完成"); * return true; * } * */ #endregion #region 个人 /// <summary> /// 添加名录 /// </summary> /// <returns></returns> public static bool AddClientInfo(string name, int num) { E_ClientInfo data = new E_ClientInfo(); T_ClientInfo bll = new T_ClientInfo(); data.PersonalID = 9; Console.WriteLine("开始添加:" + DateTime.Now.ToShortTimeString()); new Log().WriteLog("开始添加:" + DateTime.Now.ToShortTimeString()); bool flag = false; for (int i = 1; i <= num; i++) { data.ClientName = string.Format("{0}{1}", name, i); flag = bll.Add(data); if (!flag) { Console.WriteLine("添加出错!"); new Log().WriteLog("添加出错!"); break; } if (i % 1000 == 0) { Console.WriteLine(string.Format("已经添加{0}条,时间:{1}", i, DateTime.Now.ToShortTimeString())); } } Console.WriteLine("添加完成:" + DateTime.Now.ToShortTimeString()); new Log().WriteLog("添加完成:" + DateTime.Now.ToShortTimeString()); return(flag); }
/// <summary> /// 导入名录信息 /// </summary> /// <param name="shtClient"></param> /// <returns></returns> private bool ImportClient(HSSFSheet shtClient) { int count = shtClient.LastRowNum; int succNum = 0, errorNum = 0; HSSFRow row; T_ClientInfo bll = new T_ClientInfo(); E_ClientInfo data; for (int i = 1; i <= count; ++i) { if (ISCheckRowStrNullOrEmpty(i, shtClient)) { continue; } row = shtClient.GetRow(i); data = new E_ClientInfo(); data.PersonalID = _personalid; data.ClientName = GetCellValue(row.GetCell(0)); //名称 data.Address = GetCellValue(row.GetCell(1)); //地址 data.ZipCode = GetCellValue(row.GetCell(2)); //邮编 data.Linkman = GetCellValue(row.GetCell(3)); //联系人 data.Position = GetCellValue(row.GetCell(4)); //职务 data.Tel = GetCellValue(row.GetCell(5)); //电话 data.Mobile = GetCellValue(row.GetCell(6)); //手机 data.Fax = GetCellValue(row.GetCell(7)); //传真 data.Website = GetCellValue(row.GetCell(8)); //网址 data.Email = GetCellValue(row.GetCell(9)); //邮箱 data.QQ = GetCellValue(row.GetCell(10)); //QQ data.MSN = GetCellValue(row.GetCell(11)); //MSN data.SourceName = GetCellValue(row.GetCell(12)); //来源编码 data.TradeName = GetCellValue(row.GetCell(13)); //行业编码 data.AreaName = GetCellValue(row.GetCell(14)); //地区编码 data.Remark = GetCellValue(row.GetCell(15)); //备注 //判断名录名是否存在 bool flag = bll.Exists(new E_ClientInfo() { PersonalID = _personalid, ClientName = data.ClientName, ClientInfoID = 0 }); if (flag) { _result.Add(string.Format("[{0}]已经导入数据库! 位置[{1}]中,第{2}行", data.ClientName, strClientName, i)); ++errorNum; continue; } //名录写入数据库 if (bll.Add(data))//判断名录写入成功与失败 { ++succNum; } else { ++errorNum; } } _result.Add(string.Format("成功导入{0}条,失败{1}条。", succNum, errorNum)); return(errorNum == 0); }
/// <summary> /// 导入名录信息 /// </summary> /// <param name="shtClient"></param> /// <returns></returns> private bool ImportClient(HSSFSheet shtClient) { int count = shtClient.LastRowNum; int succNum = 0, errorNum = 0; HSSFRow row; T_ClientInfo bll = new T_ClientInfo(); E_ClientInfo data; DataTable dt; for (int i = 1; i <= count; ++i) { if (ISCheckRowStrNullOrEmpty(i, shtClient)) { continue; } row = shtClient.GetRow(i); data = new E_ClientInfo(); data.EnterpriseID = _enterpriseid; data.EPUserTMRID = _epusertmrid; data.UserID = _userid; data.ClientName = GetCellValue(row.GetCell(0)); //名称 data.Address = GetCellValue(row.GetCell(1)); //地址 data.ZipCode = GetCellValue(row.GetCell(2)); //邮编 data.Linkman = GetCellValue(row.GetCell(3)); //联系人 data.Position = GetCellValue(row.GetCell(4)); //职务 data.Tel = GetCellValue(row.GetCell(5)); //电话 data.Mobile = GetCellValue(row.GetCell(6)); //手机 data.Fax = GetCellValue(row.GetCell(7)); //传真 data.Website = GetCellValue(row.GetCell(8)); //网址 data.Email = GetCellValue(row.GetCell(9)); //邮箱 data.QQ = GetCellValue(row.GetCell(10)); //QQ data.MSN = GetCellValue(row.GetCell(11)); //MSN data.SourceCode = GetCellValue(row.GetCell(12)); //来源编码 data.TradeCode = GetCellValue(row.GetCell(13)); //行业编码 data.AreaCode = GetCellValue(row.GetCell(14)); //地区编码 data.Remark = GetCellValue(row.GetCell(15)); //备注 //判断名录名是否存在 dt = bll.Exists(new E_ClientInfo() { EnterpriseID = _enterpriseid, ClientName = data.ClientName, ClientInfoID = 0 }); if (dt == null || dt.Rows.Count == 0) { _result.Add("出错了!"); ++errorNum; continue; } if (dt.Rows[0]["Flag"].ToString() != "-1") { _result.Add(string.Format("[{0}]已经导入数据库! 位置[{1}]中,第{2}行", data.ClientName, strClientName, i)); ++errorNum; continue; } //判断手机是否存在 if (!string.IsNullOrEmpty(data.Mobile)) { dt = new T_ClientInfoHelper().ExistsContact(new E_ClientInfoHelper { EnterpriseID = _enterpriseid, ClientInfoID = 0, Type = 1, Value = data.Mobile }); if (dt == null || dt.Rows.Count == 0) { _result.Add("出错了!"); ++errorNum; continue; } if (dt.Rows[0]["Flag"].ToString() != "-1") { _result.Add(string.Format("手机号码[{0}]已经存在于数据库! 位置[{1}]中,第{2}行", data.Mobile, strClientName, i)); ++errorNum; continue; } } //判断电话是否存在 if (!string.IsNullOrEmpty(data.Tel)) { dt = new T_ClientInfoHelper().ExistsContact(new E_ClientInfoHelper { EnterpriseID = _enterpriseid, ClientInfoID = 0, Type = 2, Value = data.Tel }); if (dt == null || dt.Rows.Count == 0) { _result.Add("出错了!"); ++errorNum; continue; } if (dt.Rows[0]["Flag"].ToString() != "-1") { _result.Add(string.Format("电话号码[{0}]已经存在于数据库! 位置[{1}]中,第{2}行", data.Tel, strClientName, i)); ++errorNum; continue; } } //名录写入数据库 if (bll.Add(data))//判断名录写入成功与失败 { ++succNum; } else { ++errorNum; } } _result.Add(string.Format("成功导入{0}条,失败{1}条。", succNum, errorNum)); return(errorNum == 0); }
/// <summary> /// 点击确定按钮处理事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { E_ClientInfo data = new E_ClientInfo(); data.PersonalID = PersonalID; //data.UserID = UserID; //data.EPUserTMRID = EPUserTMRID; data.ClientName = txtName.Text.Trim(); data.Address = txtAddress.Text; data.ZipCode = txtZipCode.Text; data.Position = txtPosition.Text; data.Linkman = txtLinkman.Text; data.Position = txtPosition.Text; data.Tel = txtTel.Text.Trim(); data.Mobile = txtMobile.Text.Trim(); data.Fax = txtFax.Text; data.Email = txtEmail.Text; data.QQ = txtQQ.Text; data.MSN = txtMSN.Text; data.Website = txtWebsite.Text; data.SourceName = trSource.Visible ? ddlSource.SelectedItem.Text.Trim() : string.Empty; data.TradeName = trTrade.Visible ? ddlTrade.SelectedItem.Text.Trim() : string.Empty; data.AreaName = trArea.Visible ? ddlArea.SelectedItem.Text.Trim() : string.Empty; data.Remark = txtRemark.Text; if (string.IsNullOrWhiteSpace(data.ClientName))//判断是否输入名录名称 { Jscript.ShowMsg("请输入名称", this); txtName.Focus(); return; } //添加之前再次确认名录名称、电话、手机是否唯一 bool b = true; //判断名录名是否存在 b = new T_ClientInfo().Exists(new E_ClientInfo() { PersonalID = PersonalID, ClientName = data.ClientName, ClientInfoID = 0 }); if (b) { Jscript.ShowMsg("名录名称已存在!", this); return; } DataTable dt; b = true; //判断手机是否存在 if (!string.IsNullOrEmpty(data.Mobile)) { dt = new T_ClientInfo().ExistsContact(new E_ClientInfo { PersonalID = PersonalID, ClientInfoID = 0, Type = 1, Value = data.Mobile }); if (dt == null && Convert.ToInt32(dt.Rows[0]["Flag"]) > -1) { b = false; } } //判断电话是否存在 if (!string.IsNullOrEmpty(data.Tel)) { dt = new T_ClientInfo().ExistsContact(new E_ClientInfo { PersonalID = PersonalID, ClientInfoID = 0, Type = 2, Value = data.Tel }); if (dt == null && Convert.ToInt32(dt.Rows[0]["Flag"]) > -1) { b = false; } } if (!b) { Jscript.ShowMsg("录入失败", this); return; } T_ClientInfo bll = new T_ClientInfo(); bool flag = bll.Add(data); if (flag) { Jscript.AlertAndRedirect(this, "录入成功", Request.Url.ToString()); } else { Jscript.ShowMsg("录入失败", this); } }
/// <summary> /// 导入数据库 /// </summary> /// <returns></returns> public E_ImportingResult ImportingDB() { E_ImportingResult result = new E_ImportingResult(); XmlDocument xmldoc = new XmlDocument(); //加载文件 try { xmldoc.Load(_filename); } catch { //加载文件失败 result.ErrorNumber = 1; return(result); } //读取配置 E_ImportingClientInfo data = new E_ImportingClientInfo(); data.PersonalID = _personalid; //data.EPUserTMRID = _epuserid; XmlNodeList xnlConfig = xmldoc.SelectNodes("root/CorreField/Field"); for (int i = 0; i < xnlConfig.Count; i++) { XmlElement xe = (XmlElement)xnlConfig[i]; if (string.IsNullOrEmpty(xe.GetAttribute("Source"))) { continue; } switch (xe.GetAttribute("Name").ToLower()) { case "clientname": data.ClientNameFiled = xe.GetAttribute("Source"); break; case "address": data.AddressFiled = xe.GetAttribute("Source"); break; case "zipcode": data.ZipCodeFiled = xe.GetAttribute("Source"); break; case "linkman": data.LinkmanFiled = xe.GetAttribute("Source"); break; case "position": data.PositionFiled = xe.GetAttribute("Source"); break; case "tel": data.TelFiled = xe.GetAttribute("Source"); break; case "mobile": data.MobileFiled = xe.GetAttribute("Source"); break; case "fax": data.FaxFiled = xe.GetAttribute("Source"); break; case "website": data.WebsiteFiled = xe.GetAttribute("Source"); break; case "email": data.EmailFiled = xe.GetAttribute("Source"); break; case "qq": data.QQFiled = xe.GetAttribute("Source"); break; case "msn": data.MSNFiled = xe.GetAttribute("Source"); break; case "remark": data.RemarkFiled = xe.GetAttribute("Source"); break; case "sourcecode": data.SourceCodeFiled = xe.GetAttribute("Source"); break; case "tradecode": data.TradeCodeFiled = xe.GetAttribute("Source"); break; case "areacode": data.AreaCodeFiled = xe.GetAttribute("Source"); break; default: break; } } //读取数据 XmlNodeList xnlList = xmldoc.SelectNodes("root/List/Item"); int len = xnlList.Count; T_ClientInfo bll = new T_ClientInfo(); DataTable dt; for (int i = 0; i < len; i++) { data.ClientName = GetData(xnlList[i], data.ClientNameFiled); data.AddressFiled = GetData(xnlList[i], data.AddressFiled); data.ZipCode = GetData(xnlList[i], data.ZipCodeFiled); data.Linkman = GetData(xnlList[i], data.LinkmanFiled); data.Position = GetData(xnlList[i], data.PositionFiled); data.Tel = GetData(xnlList[i], data.TelFiled); data.Mobile = GetData(xnlList[i], data.MobileFiled); data.Fax = GetData(xnlList[i], data.FaxFiled); data.Website = GetData(xnlList[i], data.WebsiteFiled); data.Email = GetData(xnlList[i], data.EmailFiled); data.QQ = GetData(xnlList[i], data.QQFiled); data.MSN = GetData(xnlList[i], data.MSNFiled); data.Remark = GetData(xnlList[i], data.RemarkFiled); data.SourceName = GetData(xnlList[i], data.SourceCodeFiled); data.TradeName = GetData(xnlList[i], data.TradeCodeFiled); data.AreaName = GetData(xnlList[i], data.AreaCodeFiled); //判断名录名是否存在 bool bb = bll.Exists(new E_ClientInfo() { PersonalID = _personalid, ClientName = data.ClientName, ClientInfoID = 0 }); if (bb) { result.FailList.Add(string.Format("[{0}]已经导入数据库! 第{1}行", data.ClientName, i)); ++result.FailNum; continue; } //判断手机是否存在 if (!string.IsNullOrEmpty(data.Mobile)) { dt = new T_ClientInfo().ExistsContact(new E_ClientInfo { PersonalID = _personalid, ClientInfoID = 0, Type = 1, Value = data.Mobile }); if (dt == null || dt.Rows.Count == 0) { result.FailList.Add("出错了!"); ++result.FailNum; continue; } if (dt.Rows[0]["Flag"].ToString() != "-1") { result.FailList.Add(string.Format("手机号码[{0}]已经存在于数据库! 第{1}行", data.Mobile, i)); ++result.FailNum; continue; } } //判断电话是否存在 if (!string.IsNullOrEmpty(data.Tel)) { dt = new T_ClientInfo().ExistsContact(new E_ClientInfo { PersonalID = _personalid, ClientInfoID = 0, Type = 2, Value = data.Tel }); if (dt == null || dt.Rows.Count == 0) { result.FailList.Add("出错了!"); ++result.FailNum; continue; } if (dt.Rows[0]["Flag"].ToString() != "-1") { result.FailList.Add(string.Format("电话号码[{0}]已经存在于数据库! 第{1}行", data.Tel, i)); ++result.FailNum; continue; } } bool b = bll.Add(data); if (b) { ++result.SuccNum; } else { ++result.FailNum; result.FailList.Add(data.ClientName); } } //删除文件 try { System.IO.File.Delete(_filename); } catch { } return(result); }
protected void btnSubmit_Click(object sender, EventArgs e) { E_ClientInfo data = new E_ClientInfo(); data.EnterpriseID = EnterpriceID; data.UserID = UserID; data.EPUserTMRID = EPUserTMRID; data.ClientName = txtName.Text.Trim(); data.Address = txtAddress.Text.Trim(); data.ZipCode = txtZipCode.Text.Trim(); data.Position = txtPosition.Text.Trim(); data.Linkman = txtLinkman.Text.Trim(); data.Position = txtPosition.Text.Trim(); data.Tel = txtTel.Text.Trim(); data.Mobile = txtMobile.Text.Trim(); data.Fax = txtFax.Text.Trim(); data.Website = txtWebsite.Text.Trim(); data.QQ = txtQQ.Text.Trim(); data.MSN = txtMSN.Text.Trim(); data.Email = txtEmail.Text.Trim(); data.SourceCode = trSource.Visible?txtSourceCode.Text:string.Empty; data.TradeCode = trTrade.Visible ? txtTradeCode.Text : string.Empty; data.AreaCode = trArea.Visible ? txtAreaCode.Text : string.Empty; data.Remark = txtRemark.Text.Trim(); if (string.IsNullOrWhiteSpace(data.ClientName))//判断是否输入名录名称 { Jscript.ShowMsg("请输入名称", this); txtName.Focus(); return; } //添加之前再次确认名录名称、电话、手机是否唯一 bool flag = true; DataTable dt = new T_ClientInfo().Exists(new E_ClientInfo { EnterpriseID = data.EnterpriseID, ClientInfoID = data.ClientInfoID, ClientName = data.ClientName }); if (dt != null && Convert.ToInt32(dt.Rows[0]["Flag"]) > 0) { flag = false; } //如果手机不为空 if (!string.IsNullOrEmpty(data.Mobile.Trim())) { dt = new T_ClientInfoHelper().ExistsContact(new E_ClientInfoHelper { EnterpriseID = data.EnterpriseID, ClientInfoID = data.ClientInfoID, Type = 1, Value = data.Mobile }); if (dt != null && Convert.ToInt32(dt.Rows[0]["Flag"]) > 0) { flag = false; } } //如果电话不为空 if (!string.IsNullOrEmpty(data.Tel.Trim())) { dt = new T_ClientInfoHelper().ExistsContact(new E_ClientInfoHelper { EnterpriseID = data.EnterpriseID, ClientInfoID = data.ClientInfoID, Type = 2, Value = data.Tel }); if (dt != null && Convert.ToInt32(dt.Rows[0]["Flag"]) > 0) { flag = false; } } if (!flag) { Jscript.ShowMsg("录入失败", this); return; } T_ClientInfo bll = new T_ClientInfo(); bool b = bll.Add(data); if (b) { //添加操作日志 new MLMGC.BLL.Enterprise.T_Log().Add(new MLMGC.DataEntity.Enterprise.E_Log() { EnterpriseID = EnterpriceID, UserID = UserID, LogTitle = "添加名录", IP = MLMGC.COMP.Requests.GetRealIP() }); Jscript.AlertAndRedirect(this, "录入成功", Request.Url.ToString()); } else { Jscript.ShowMsg("录入失败", this); } }