Нет описания

CustomerNewController.cs 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using CallCenterApi.Interface.Models.Input;
  5. using CallCenterApi.Model;
  6. using Newtonsoft.Json;
  7. using NPOI.HSSF.UserModel;
  8. using NPOI.SS.UserModel;
  9. using NPOI.XSSF.UserModel;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text.RegularExpressions;
  16. using System.Web;
  17. using System.Web.Mvc;
  18. namespace CallCenterApi.Interface.Controllers.customer
  19. {
  20. public class CustomerNewController : BaseController
  21. {
  22. BLL.T_Cus_CustomerBaseNew cusbll = new BLL.T_Cus_CustomerBaseNew();
  23. BLL.T_Cus_ContactPersonNew conbll = new BLL.T_Cus_ContactPersonNew();
  24. BLL.T_Sys_Department deptbll = new BLL.T_Sys_Department();
  25. BLL.T_Sys_RoleInfo rolebll = new BLL.T_Sys_RoleInfo();
  26. BLL.T_Cus_CustomerFinance finbll = new BLL.T_Cus_CustomerFinance();
  27. BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  28. #region 客户管理
  29. /// <summary>
  30. /// 获取客户列表
  31. /// </summary>
  32. /// <param name="code">客户编号</param>
  33. /// <param name="cmpname">公司名称</param>
  34. /// <param name="cmpaddress">公司地址</param>
  35. /// <param name="legname">法人姓名</param>
  36. /// <param name="legtel">法人电话</param>
  37. /// <param name="subtrade">所属行业</param>
  38. /// <param name="layer">客户信誉等级</param>
  39. /// <param name="bedept">客户归属部门</param>
  40. /// <param name="bereladd">客户归属涉税会计</param>
  41. /// <param name="beaudacc">客户归属审核会计</param>
  42. /// <param name="bemakeacc">客户归属做账会计</param>
  43. /// <param name="conname">联系人姓名</param>
  44. /// <param name="contel">联系人电话</param>
  45. /// <returns></returns>
  46. public ActionResult GetList(string code, string cmpname, string legname, string legtel,string province, string city,
  47. string country, string township, int areaid = 0, int branchid = 0,int pageindex = 1, int pagesize = 10)
  48. {
  49. string sql = $" and F_IsDelete=0";
  50. DataTable dt = new DataTable();
  51. #region 筛选条件
  52. if (areaid > 0)//大区
  53. sql += $" and F_AreaID=" + areaid;
  54. if (branchid > 0)//分公司
  55. sql += $" and F_BranchID=" + branchid;
  56. if (!string.IsNullOrWhiteSpace(code))//客户编号
  57. {
  58. if (valcode(code))
  59. sql += $" and F_CustomerCode like '%" + code.Trim() + "%'";
  60. }
  61. if (!string.IsNullOrWhiteSpace(cmpname))//公司名称
  62. sql += $" and F_CompanyName like '%" + cmpname.Trim() + "%'";
  63. if (!string.IsNullOrWhiteSpace(legname))//法人姓名
  64. sql += $" and F_Legal like '%" + legname.Trim() + "%'";
  65. if (!string.IsNullOrWhiteSpace(legtel))//法人电话
  66. sql += $" and F_LegalPhone like '%" + legtel.Trim() + "%'";
  67. if (!string.IsNullOrWhiteSpace(province))//省
  68. sql += $" and F_AddressProvince like '%" + province.Trim() + "%'";
  69. if (!string.IsNullOrWhiteSpace(province))//市
  70. sql += $" and F_AddressCity like '%" + city.Trim() + "%'";
  71. if (!string.IsNullOrWhiteSpace(province))//县
  72. sql += $" and F_AddressCountry like '%" + country.Trim() + "%'";
  73. if (!string.IsNullOrWhiteSpace(province))//乡
  74. sql += $" and F_AddressTownship like '%" + township.Trim() + "%'";
  75. #endregion
  76. int recordCount = 0;
  77. if (!string.IsNullOrWhiteSpace(sql))
  78. {
  79. dt = BLL.PagerBLL.GetListPager(
  80. "T_Cus_CustomerBaseNew",
  81. "F_CustomerId",
  82. "*,dbo.GetUserName(F_CreateBy) as F_CreateByName",
  83. sql,
  84. "ORDER BY F_CustomerId desc",
  85. pagesize,
  86. pageindex,
  87. true,
  88. out recordCount);
  89. }
  90. List<Model.T_Cus_CustomerBaseNew> modlelist = new BLL.T_Cus_CustomerBaseNew().DataTableToList(dt);
  91. List<CustomerBaseNewInput> Input = modeltooip(modlelist);
  92. var obj = new
  93. {
  94. state = "success",
  95. message = "成功",
  96. rows = Input,
  97. total = recordCount
  98. };
  99. return Content(obj.ToJson());
  100. }
  101. /// <summary>
  102. /// 根据关键字搜索公司
  103. /// </summary>
  104. public ActionResult GetListByKey(string keywords)
  105. {
  106. string sql = "";
  107. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  108. sql += $" ( F_CompanyName like '%" + keywords.Trim() + "%' or F_CustomerCode like '%" + keywords.Trim() + "%' ) ";
  109. var list = new List<Model.T_Cus_CustomerBaseNew>();
  110. if (!string.IsNullOrWhiteSpace(sql))
  111. {
  112. sql += " and F_IsDelete=0";
  113. list = cusbll.GetModelList(sql);
  114. }
  115. List<CustomerBaseNewInput> Input = modeltooip(list);
  116. if (Input.Count > 0)
  117. return Success("根据关键字获取公司信息", Input.FirstOrDefault());
  118. else
  119. return Error("没有获取到相关公司,请重新搜索");
  120. }
  121. /// <summary>
  122. /// 获取客户信息
  123. /// </summary>
  124. /// <returns></returns>
  125. public ActionResult GetCustomer(int cusid)
  126. {
  127. if (cusid != 0)
  128. {
  129. Model.T_Cus_CustomerBaseNew userModel = cusbll.GetModel(cusid);
  130. List<Model.T_Cus_CustomerBaseNew> model = new List<T_Cus_CustomerBaseNew>();
  131. if (userModel != null)
  132. {
  133. model.Add(userModel);
  134. List<CustomerBaseNewInput> Input = modeltooip(model);
  135. return Success("获取成功", Input.FirstOrDefault());
  136. }
  137. else
  138. {
  139. return Error("获取失败");
  140. }
  141. }
  142. else
  143. {
  144. return Error("参数传输失败");
  145. }
  146. }
  147. /// <summary>
  148. /// 通过来电号码获取来电弹屏左侧客户信息
  149. /// </summary>
  150. /// <returns></returns>
  151. public ActionResult GetCustomerByTel(string tel)
  152. {
  153. if (!string.IsNullOrWhiteSpace(tel))
  154. {
  155. var sql = $" and (F_SalesPhone like '%" + tel.Trim() + "%' or F_LegalPhone like '%" + tel.Trim() + "%')";
  156. var userModel = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_IsDelete = 0 " + sql);
  157. if (userModel.Count() > 0)
  158. {
  159. List<CustomerBaseNewInput> Input = modeltooip(userModel);
  160. var model = Input.Last();
  161. return Success("获取成功", model);
  162. }
  163. else
  164. {
  165. return Success("获取成功");
  166. }
  167. }
  168. else
  169. {
  170. return Error("参数传输失败");
  171. }
  172. }
  173. /// <summary>
  174. /// 添加客户信息
  175. /// </summary>
  176. /// <returns></returns>
  177. public ActionResult Add(CustomerBaseNewInput input)
  178. {
  179. string usercode = CurrentUser.UserData.F_UserCode;
  180. #region 添加验证判断
  181. if (string.IsNullOrEmpty(input.F_CustomerCode))
  182. return Error("编号不能为空!");
  183. if (!valcode(input.F_CustomerCode))
  184. return Error("编号必须是10位数字");
  185. if (getunique(0, input.F_CustomerCode))
  186. return Error("编号已被占用,请重新输入!");
  187. #endregion
  188. var model = new Model.T_Cus_CustomerBaseNew();
  189. #region 保存客户基本信息
  190. model = inputtoobj(model, input);
  191. model.F_CreateBy = usercode;
  192. model.F_CreateOn = DateTime.Now;
  193. model.F_IsDelete = 0;
  194. #endregion
  195. int n = cusbll.Add(model);
  196. if (n > 0)
  197. {
  198. return Success("新增成功!");
  199. }
  200. else
  201. return Error("新增失败!");
  202. }
  203. /// <summary>
  204. /// 修改客户信息
  205. /// </summary>
  206. /// <returns></returns>
  207. public ActionResult Update(CustomerBaseNewInput input)
  208. {
  209. string usercode = CurrentUser.UserData.F_UserCode;
  210. #region 添加验证判断
  211. if (input.F_CustomerId <= 0)
  212. return Error("参数错误!");
  213. if (getunique(input.F_CustomerId, input.F_CustomerCode))
  214. return Error("编号已被占用,请重新输入!");
  215. #endregion
  216. var model = cusbll.GetModel(input.F_CustomerId);
  217. #region 保存客户基本信息
  218. model = inputtoobj(model, input);
  219. #endregion
  220. bool n = cusbll.Update(model);
  221. if (n)
  222. {
  223. return Success("保存成功!");
  224. }
  225. else
  226. return Error("保存失败!");
  227. }
  228. /// <summary>
  229. /// 根据model返回CustomerBaseNewInput对象
  230. /// </summary>
  231. private List<CustomerBaseNewInput> modeltooip(List <Model.T_Cus_CustomerBaseNew> model)
  232. {
  233. if (model!=null &&model .Count >0)
  234. {
  235. List<CustomerBaseNewInput> Input = new List<CustomerBaseNewInput>(model.Count);
  236. for (int i=0;i<model .Count;i++)
  237. {
  238. CustomerBaseNewInput Input1 = new CustomerBaseNewInput();
  239. #region 基本字段
  240. if (!string.IsNullOrWhiteSpace(model[i].F_CustomerCode))
  241. Input1.F_CustomerCode = model[i].F_CustomerCode;
  242. if (!string.IsNullOrWhiteSpace(model[i].F_CompanyName))
  243. Input1.F_CompanyName = model[i].F_CompanyName;
  244. Input1.F_AreaID = model[i].F_AreaID;//大区ID
  245. Input1.F_BranchID = model[i].F_BranchID;//分公司ID
  246. Model.T_Sys_Department pdModel = departmentBLL.GetModel(model[i].F_AreaID);
  247. if (pdModel != null)
  248. {
  249. Input1.F_AreaName = pdModel.F_DeptName.ToString();
  250. }
  251. Model.T_Sys_Department pdModel1 = departmentBLL.GetModel(model[i].F_BranchID);
  252. if (pdModel1 != null)
  253. {
  254. Input1.F_BranchName = pdModel1.F_DeptName.ToString();
  255. }
  256. Input1.F_Salesman = model[i].F_Salesman;//业务员
  257. Input1.F_SalesPhone = model[i].F_SalesPhone;//业务员电话
  258. Input1.F_CustomerNature = model[i].F_CustomerNature;//客户性质
  259. Input1.F_Channel = model[i].F_Channel;// 渠道类型:总经销、二级商、种田大户、农户、化工客户、公司员工
  260. Input1.F_Credit = model[i].F_Credit;//信用等级:一星、二星、三星、四星、五星、空
  261. Input1.F_Legal = model[i].F_Legal;//法人
  262. Input1.F_LegalPhone = model[i].F_LegalPhone;//法人电话
  263. Input1.F_AddressProvince = model[i].F_AddressProvince;//省
  264. Input1.F_AddressCity = model[i].F_AddressCity;//市
  265. Input1.F_AddressCountry = model[i].F_AddressCountry;//县
  266. Input1.F_AddressTownship = model[i].F_AddressTownship;//乡
  267. Input1.F_AddressFull = model[i].F_AddressFull;//详细地址
  268. Input1.F_Brands = model[i].F_Brands;// 经营品牌:心连心、手拉手、沃利沃、双心、空
  269. Input1.F_Product = model[i].F_Product;//产品:复合肥心连心、复合肥手拉手、复合肥沃利沃、复合肥双心、尿素心连心、尿素手拉手、尿素沃利沃、尿素双心
  270. Input1.F_FrozenFlag = model[i].F_FrozenFlag;//冻结标志
  271. Input1.F_IsOpenAccount = model[i].F_IsOpenAccount;//是否开户:已开户、未开户
  272. Input1.F_LevelCode = model[i].F_LevelCode;//上级客户编码
  273. Input1.F_LevelName = model[i].F_LevelName;//上级客户名称
  274. Input1.F_MnemonicCode = model[i].F_MnemonicCode;//助记码
  275. Input1.F_InvoiceBank = model[i].F_InvoiceBank;//开票银行名称
  276. Input1.F_InvoiceBankAccount = model[i].F_InvoiceBankAccount;//开票银行账号
  277. Input1.F_TaxRegCode = model[i].F_TaxRegCode;//纳税人登记号
  278. Input1.F_IsRunXLX = model[i].F_IsRunXLX;// 是否经营心连心:是、否
  279. Input1.F_AnnualSales = model[i].F_AnnualSales;//年销量
  280. Input1.F_Formula = model[i].F_Formula;//配方
  281. Input1.F_RaiseCrops = model[i].F_RaiseCrops;//种植作物
  282. Input1.F_PlantingArea = model[i].F_PlantingArea;//种植面积
  283. Input1.F_FertilizerBrand = model[i].F_FertilizerBrand;//用肥品牌
  284. Input1.F_Remark = model[i].F_Remark;//备注
  285. Input1.F_FileId = 0;
  286. Input.Add(Input1);
  287. #endregion
  288. }
  289. return Input;
  290. }
  291. else
  292. {
  293. return null;
  294. }
  295. }
  296. /// <summary>
  297. /// 根据传入的对象和input的内容返回对象
  298. /// </summary>
  299. private Model.T_Cus_CustomerBaseNew inputtoobj(Model.T_Cus_CustomerBaseNew model,CustomerBaseNewInput input)
  300. {
  301. var newmodel = model;
  302. if (!string.IsNullOrWhiteSpace(input.F_CustomerCode))
  303. model.F_CustomerCode = input.F_CustomerCode;
  304. else
  305. model.F_CustomerCode = model.F_CustomerCode;
  306. if (!string.IsNullOrWhiteSpace(input.F_CompanyName))
  307. model.F_CompanyName = input.F_CompanyName;
  308. #region 基本字段
  309. model.F_AreaID = input.F_AreaID;//大区ID
  310. model.F_BranchID = input.F_BranchID;//分公司ID
  311. model.F_Salesman = input.F_Salesman;//业务员
  312. model.F_SalesPhone = input.F_SalesPhone;//业务员电话
  313. model.F_CustomerNature = input.F_CustomerNature;//客户性质
  314. model.F_Channel = input.F_Channel;// 渠道类型:总经销、二级商、种田大户、农户、化工客户、公司员工
  315. model.F_Credit = input.F_Credit;//信用等级:一星、二星、三星、四星、五星、空
  316. model.F_Legal = input.F_Legal;//法人
  317. model.F_LegalPhone = input.F_LegalPhone;//法人电话
  318. model.F_AddressProvince = input.F_AddressProvince;//省
  319. model.F_AddressCity = input.F_AddressCity;//市
  320. model.F_AddressCountry = input.F_AddressCountry;//县
  321. model.F_AddressTownship = input.F_AddressTownship;//乡
  322. model.F_AddressFull = input.F_AddressFull;//详细地址
  323. model.F_Brands = input.F_Brands;// 经营品牌:心连心、手拉手、沃利沃、双心、空
  324. model.F_Product = input.F_Product;//产品:复合肥心连心、复合肥手拉手、复合肥沃利沃、复合肥双心、尿素心连心、尿素手拉手、尿素沃利沃、尿素双心
  325. model.F_FrozenFlag = input.F_FrozenFlag;//冻结标志
  326. model.F_IsOpenAccount = input.F_IsOpenAccount;//是否开户:已开户、未开户
  327. model.F_LevelCode = input.F_LevelCode;//上级客户编码
  328. model.F_LevelName = input.F_LevelName;//上级客户名称
  329. model.F_MnemonicCode = input.F_MnemonicCode;//助记码
  330. model.F_InvoiceBank = input.F_InvoiceBank;//开票银行名称
  331. model.F_InvoiceBankAccount = input.F_InvoiceBankAccount;//开票银行账号
  332. model.F_TaxRegCode = input.F_TaxRegCode;//纳税人登记号
  333. model.F_IsRunXLX = input.F_IsRunXLX;// 是否经营心连心:是、否
  334. model.F_AnnualSales = input.F_AnnualSales;//年销量
  335. model.F_Formula = input.F_Formula;//配方
  336. model.F_RaiseCrops = input.F_RaiseCrops;//种植作物
  337. model.F_PlantingArea = input.F_PlantingArea;//种植面积
  338. model.F_FertilizerBrand = input.F_FertilizerBrand;//用肥品牌
  339. model.F_Remark = input.F_Remark;//备注
  340. model.F_FileId = 0;
  341. #endregion
  342. return model;
  343. }
  344. /// <summary>
  345. /// 验证客户编号是否唯一
  346. /// </summary>
  347. private bool getunique(int id, string code)
  348. {
  349. var sql = " F_IsDelete=0 ";
  350. sql += "and (F_CustomerCode='" + code + "')";
  351. if (id > 0)
  352. sql += " and F_CustomerId<>"+id;
  353. var count=cusbll.GetModelList(sql).Count();
  354. return count > 0;
  355. }
  356. /// <summary>
  357. /// 删除客户
  358. /// </summary>
  359. /// <param name="ids"></param>
  360. /// <returns></returns>
  361. public ActionResult DelCustomer(string[] ids)
  362. {
  363. if (ids != null && ids.Length > 0)
  364. {
  365. string idd = " ";
  366. foreach (string str in ids)
  367. {
  368. idd += str + ",";
  369. }
  370. if (!string.IsNullOrEmpty(idd.Trim()))
  371. {
  372. if (cusbll.DeleteList(idd.TrimEnd(',')))
  373. {
  374. conbll.DeleteListByCusid(idd.TrimEnd(','));
  375. return Success("设置成功");
  376. }
  377. else
  378. {
  379. return Error("设置失败");
  380. }
  381. }
  382. else
  383. {
  384. return Error("请选择用户");
  385. }
  386. }
  387. else
  388. {
  389. return Error("获取参数失败");
  390. }
  391. }
  392. #region 客户使用微信端才会使用
  393. ///// <summary>
  394. ///// 重置密码
  395. ///// </summary>
  396. ///// <param name="ids"></param>
  397. ///// <returns></returns>
  398. //public ActionResult UpdatePWD(string[] ids)
  399. //{
  400. // if (ids != null && ids.Length > 0)
  401. // {
  402. // string idd = " ";
  403. // foreach (string str in ids)
  404. // {
  405. // idd += str + ",";
  406. // }
  407. // if (!string.IsNullOrEmpty(idd.Trim()))
  408. // {
  409. // if (cusbll.UpdatePWD(idd.TrimEnd(','),"123456"))
  410. // {
  411. // return Success("设置成功");
  412. // }
  413. // else
  414. // {
  415. // return Error("设置失败");
  416. // }
  417. // }
  418. // else
  419. // {
  420. // return Error("请选择用户");
  421. // }
  422. // }
  423. // else
  424. // {
  425. // return Error("获取参数失败");
  426. // }
  427. //}
  428. #endregion
  429. #endregion
  430. #region 导入客户资料
  431. /// <summary>
  432. /// 导入excel
  433. /// </summary>
  434. public ActionResult ImportExcel()
  435. {
  436. string usercode = CurrentUser.UserData.F_UserCode;
  437. string ip = DTRequest.GetIP();
  438. if (!string.IsNullOrWhiteSpace(usercode))
  439. {
  440. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  441. if (_upFile != null)
  442. {
  443. int headrow = 0;
  444. #region 上传文件
  445. string filepath = "";
  446. string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  447. string aLastName = Path.GetExtension(_upFile.FileName);
  448. string oriname = Path.GetFileNameWithoutExtension(_upFile.FileName);
  449. if (aLastName != "xls" && aLastName != "xlsx")
  450. {
  451. return Error("文件类型错误,请选择Excel文件");
  452. }
  453. string newpath = datepath + "_" + _upFile.FileName;
  454. if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  455. {
  456. Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  457. }
  458. filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  459. string PhysicalPath = Server.MapPath(filepath);
  460. _upFile.SaveAs(PhysicalPath);
  461. #endregion
  462. #region 添加附件日志
  463. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  464. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  465. model_T_Sys_Accessories.F_FileName = newpath;//附件名称
  466. model_T_Sys_Accessories.F_FileType = aLastName;//附件类型
  467. model_T_Sys_Accessories.F_FileUrl = filepath;//附件地址
  468. model_T_Sys_Accessories.F_UserCode = usercode;//上传人
  469. model_T_Sys_Accessories.F_OriName = oriname;
  470. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  471. #endregion
  472. NPOIHelper np = new NPOIHelper();
  473. DataTable dt = np.ExcelToTable(_upFile, headrow);
  474. string msg = string.Empty;
  475. if (dt == null || dt.Rows.Count == 0)
  476. return Error("文件没有数据");
  477. else
  478. {
  479. Model.T_Cus_CustomerBaseNew dModel = new Model.T_Cus_CustomerBaseNew();
  480. dModel.F_CreateBy = usercode;
  481. dModel.F_IsDelete = 0;
  482. dModel.F_FileId = fid;
  483. foreach (DataRow dr in dt.Rows)
  484. {
  485. #region 数据入库
  486. headrow = headrow + 1;
  487. if (dr["客户编号"].ToString() != "" && valcode(dr["客户编号"].ToString()))
  488. {
  489. dModel.F_CustomerCode = dr["客户编号"].ToString();
  490. dModel.F_CompanyName = dr["公司名称"].ToString();
  491. #region
  492. Model.T_Sys_Department pdModel = departmentBLL.GetModel(dr["大区名称"].ToString());
  493. if (pdModel!=null )
  494. {
  495. dModel.F_AreaID = pdModel.F_DeptId.ToString();
  496. }
  497. Model.T_Sys_Department pdModel1 = departmentBLL.GetModel(dr["分公司名称"].ToString());
  498. if (pdModel1!=null )
  499. {
  500. dModel.F_BranchID = pdModel1.F_DeptId.ToString();
  501. }
  502. dModel.F_Salesman = dr["业务员"].ToString();
  503. dModel.F_SalesPhone = dr["业务员电话"].ToString();
  504. dModel.F_CustomerNature = dr["客户性质"].ToString();
  505. dModel.F_Channel = dr["渠道类型"].ToString();
  506. dModel.F_Credit = dr["信用等级"].ToString();
  507. dModel.F_Legal = dr["法人"].ToString();
  508. dModel.F_LegalPhone = dr["法人电话"].ToString();
  509. dModel.F_AddressProvince = dr["省"].ToString();
  510. dModel.F_AddressCity = dr["市"].ToString();
  511. dModel.F_AddressCountry = dr["县"].ToString();
  512. dModel.F_AddressTownship = dr["乡"].ToString();
  513. dModel.F_AddressFull = dr["详细地址"].ToString();
  514. dModel.F_Brands = dr["经营品牌"].ToString();
  515. dModel.F_Product = dr["产品"].ToString();
  516. dModel.F_FrozenFlag = dr["冻结标志"].ToString();
  517. dModel.F_IsOpenAccount = dr["是否开户"].ToString();
  518. dModel.F_LevelCode = dr["上级客户编码"].ToString();
  519. dModel.F_LevelName = dr["上级客户名称"].ToString();
  520. dModel.F_MnemonicCode = dr["助记码"].ToString();
  521. dModel.F_InvoiceBank = dr["开票银行名称"].ToString();
  522. dModel.F_InvoiceBankAccount = dr["开票银行账号"].ToString();
  523. dModel.F_TaxRegCode = dr["纳税人登记号"].ToString();
  524. dModel.F_IsRunXLX = dr["是否经营心连心"].ToString();
  525. dModel.F_AnnualSales = dr["年销量"].ToString();
  526. dModel.F_Formula = dr["配方"].ToString();
  527. dModel.F_RaiseCrops = dr["种植作物"].ToString();
  528. dModel.F_PlantingArea = dr["种植面积"].ToString();
  529. dModel.F_FertilizerBrand = dr["用肥品牌"].ToString();
  530. dModel.F_Remark = dr["备注"].ToString();
  531. #endregion
  532. dModel.F_CreateOn = DateTime.Now;
  533. var res = cusbll.Add(dModel);
  534. if (res > 0)
  535. {
  536. addoptlog(usercode, ip, EnumOpt.import.ToString(), res.ToString(), "导入成功,导入的文件为:" + newpath + ",当前为第" + headrow + "行");
  537. }
  538. else
  539. {
  540. msg = msg + "第" + headrow + "行,导入失败<br>";
  541. }
  542. }
  543. else
  544. msg = msg + "第" + headrow + "行,物料编号为空或格式不正确,未导入<br>";
  545. #endregion
  546. }
  547. if (string.IsNullOrEmpty(msg))
  548. return Success("导入成功 " );
  549. else
  550. return Error(msg);
  551. }
  552. }
  553. return Error("数据源上传失败");
  554. }
  555. return Error("用户登录失败,请重新登录");
  556. }
  557. #endregion
  558. #region 私有方法
  559. /// <summary>
  560. /// 验证物料编码为10位纯数字
  561. /// </summary>
  562. private bool valcode(string code)
  563. {
  564. var res = false;
  565. //11位数字
  566. if (code.Length == 10 && Regex.IsMatch(code, @"^\d{10}$"))
  567. res = true;
  568. return res;
  569. }
  570. /// <summary>
  571. /// 操作日志
  572. /// </summary>
  573. /// <param name="usercode">操作人工号</param>
  574. /// <param name="ip">操作人IP</param>
  575. /// <param name="optcode">操作编号</param>
  576. /// <param name="optid">操作id</param>
  577. /// <param name="des">操作描述</param>
  578. private void addoptlog(string usercode, string ip, string optcode, string optid, string des)
  579. {
  580. new BLL.T_Sys_OperateLogs().AddOptLog("客户管理", usercode, ip, des, optcode, "T_Cus_CustomerBaseNew", optid);
  581. }
  582. #endregion
  583. }
  584. }