Нет описания

CustomerNewController.cs 28KB

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