No Description

CustomerController.cs 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using CallCenterApi.Interface.Controllers.Base;
  8. using System.Data;
  9. using CallCenter.Utility;
  10. using CallCenterApi.Common;
  11. using CallCenterApi.DB;
  12. using System.IO;
  13. using NPOI.XSSF.UserModel;
  14. using NPOI.HSSF.UserModel;
  15. using NPOI.SS.UserModel;
  16. using Newtonsoft.Json;
  17. namespace CallCenterApi.Interface.Controllers.customer
  18. {
  19. //[Authority]
  20. public class CustomerController : BaseController
  21. {
  22. /// <summary>
  23. /// 获取客户列表
  24. /// </summary>
  25. /// <returns></returns>
  26. public ActionResult GetList()
  27. {
  28. ActionResult res = NoToken("未知错误,请重新登录");
  29. if (Request.IsAuthenticated)
  30. {
  31. string sql = " and F_DeleteFlag=0";
  32. DataTable dt = new DataTable();
  33. //联系人
  34. string strname = RequestString.GetQueryString("name");
  35. //电话
  36. string strtel = RequestString.GetQueryString("tel");
  37. //客户名称
  38. string strCus = RequestString.GetQueryString("Cusname");
  39. //省份
  40. string strprov = RequestString.GetQueryString("province");
  41. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  42. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  43. string strpageindex = RequestString.GetQueryString("page");
  44. int pageindex = 1;
  45. string strpagesize = RequestString.GetQueryString("pagesize");
  46. int pagesize = 10;
  47. if (strname.Trim() != "" && strname != "undefined")
  48. {
  49. sql += " and F_CustomerName like '%" + strname.Trim() + "%' ";
  50. }
  51. if (strtel.Trim() != "" && strtel != "undefined")
  52. {
  53. sql += " and F_Telephone like '%" + strtel + "%' ";
  54. }
  55. if (strCus.Trim() != "" && strCus != "undefined")
  56. {
  57. sql += " and F_CustomerIndustry like '%" + strCus.Trim() + "%' ";
  58. }
  59. if (strprov.Trim() != "" && strprov.Trim() != "undefined")
  60. {
  61. sql += " and F_Province like '%" + strprov.Trim() + "%' ";
  62. }
  63. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  64. {
  65. sql += " and datediff(day,F_CreatedOn,'" + strstarttime + "')<=0 ";
  66. }
  67. if (strendtime.Trim() != "" && strendtime != "undefined")
  68. {
  69. sql += " and datediff(day,F_CreatedOn,'" + strendtime + "')>=0 ";
  70. }
  71. if (strpageindex.Trim() != "")
  72. {
  73. pageindex = Convert.ToInt32(strpageindex);
  74. }
  75. if (strpagesize.Trim() != "")
  76. {
  77. pagesize = Convert.ToInt32(strpagesize);
  78. }
  79. int recordCount = 0;
  80. dt = BLL.PagerBLL.GetListPager(
  81. "T_Cus_CustomerBase",
  82. "F_CustomerId",
  83. "*",
  84. sql,
  85. "ORDER BY F_CustomerId desc",
  86. pagesize,
  87. pageindex,
  88. true,
  89. out recordCount);
  90. var obj = new
  91. {
  92. state = "success",
  93. message = "成功",
  94. rows = dt,
  95. total = recordCount
  96. };
  97. res = Content(obj.ToJson());
  98. }
  99. return res;
  100. }
  101. /// <summary>
  102. /// 获取客户信息
  103. /// </summary>
  104. /// <returns></returns>
  105. public ActionResult GetCustomer()
  106. {
  107. ActionResult res = NoToken("未知错误,请重新登录");
  108. if (Request.IsAuthenticated)
  109. {
  110. int cid = Utils.StrToInt(RequestString.GetQueryString("cid"), 0);
  111. if (cid != 0)
  112. {
  113. Model.T_Cus_CustomerBase userModel = new BLL.T_Cus_CustomerBase().GetModel(cid);
  114. if (userModel != null)
  115. {
  116. res = Success("获取成功", userModel);
  117. }
  118. else
  119. {
  120. res = Error("获取失败");
  121. }
  122. }
  123. else
  124. {
  125. res = Error("参数传输失败");
  126. }
  127. }
  128. return res;
  129. }
  130. /// <summary>
  131. /// 通过来电号码获取来电弹屏左侧客户信息
  132. /// </summary>
  133. /// <returns></returns>
  134. public ActionResult GetCustomerByTel()
  135. {
  136. ActionResult res = NoToken("未知错误,请重新登录");
  137. if (Request.IsAuthenticated)
  138. {
  139. string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  140. if (!string.IsNullOrEmpty(tel))
  141. {
  142. //var userModel = new BLL.T_Cus_CustomerBase().GetModelList(" F_Telephone like '%" + tel + "%' or F_Mobile like '%" + tel + "%' ");
  143. //2018-04-25 lihai 问题是客户资料删除来电弹屏还有信息,添加F_DeleteFlag = 0条件
  144. var userModel = new BLL.T_Cus_CustomerBase().GetModelList(" (F_Telephone = '" + tel + "' or F_Mobile = '" + tel + "') AND F_DeleteFlag = 0 ");
  145. if (userModel.Count() > 0)
  146. {
  147. res = Success("获取成功", userModel.Last());
  148. }
  149. else
  150. {
  151. res = Success("获取成功");
  152. }
  153. }
  154. else
  155. {
  156. res = Error("参数传输失败");
  157. }
  158. }
  159. return res;
  160. }
  161. /// <summary>
  162. /// 添加/修改客户信息
  163. /// </summary>
  164. /// <returns></returns>
  165. public ActionResult AddCustomer()
  166. {
  167. ActionResult res = NoToken("未知错误,请重新登录");
  168. if (Request.IsAuthenticated)
  169. {
  170. int userId = CurrentUser.UserData.F_UserId;
  171. if (userId != 0)
  172. {
  173. //联系人
  174. string name = RequestString.GetFormString("name");
  175. //省份
  176. string province = RequestString.GetFormString("province");
  177. //来电单位
  178. string customerindustry = RequestString.GetFormString("customerindustry");
  179. //电话
  180. string mobile = RequestString.GetFormString("mobile");
  181. //获取当前表格选择的客户
  182. int cid = Utils.StrToInt(RequestString.GetFormString("cid"), 0);
  183. #region 2018-05-03 lihai 添加验证判断
  184. if (string.IsNullOrEmpty(name))
  185. return Error("姓名不能为空!");
  186. if (string.IsNullOrEmpty(province))
  187. return Error("省份不能为空!");
  188. if (!Validate.IsHasCHZN(province))
  189. return Error("请输入有效的省份!");
  190. if (Validate.GetStringLength(province) <= 2)
  191. return Error("省份名称不能少于2个字!");
  192. if (string.IsNullOrEmpty(mobile))
  193. return Error("联系电话不能为空!");
  194. if (string.IsNullOrEmpty(customerindustry))
  195. return Error("来电单位不能为空!");
  196. #endregion
  197. Model.T_Cus_CustomerBase model = new Model.T_Cus_CustomerBase();
  198. BLL.T_Cus_CustomerBase bll = new BLL.T_Cus_CustomerBase();
  199. //添加或修改时要根据电话判断是否已有记录
  200. if (cid == 0)
  201. {
  202. var cusmodel = bll.GetModelList("F_Telephone='" + mobile + "' AND F_DeleteFlag = 0");
  203. if (cusmodel.Count() > 0)
  204. return Error("已存在该号码的用户,请直接编辑!");
  205. else
  206. {
  207. model.F_CustomerName = name;
  208. model.F_Province = province;
  209. model.F_CustomerIndustry = customerindustry;
  210. //统一为F_Telephone
  211. model.F_Telephone = mobile;
  212. model.F_CreateBy = userId;
  213. model.F_CreatedOn = DateTime.Now;
  214. model.F_DeleteFlag = 0;
  215. int n = bll.Add(model);
  216. if (n > 0)
  217. {
  218. return Success("新增成功!", n);
  219. }
  220. else
  221. {
  222. return Error("新增失败!");
  223. }
  224. }
  225. }
  226. else
  227. {
  228. model = bll.GetModel(cid);
  229. if (model != null)
  230. {
  231. if (!string.IsNullOrEmpty(name))
  232. model.F_CustomerName = name;
  233. if (!string.IsNullOrEmpty(province))
  234. model.F_Province = province;
  235. if (!string.IsNullOrEmpty(customerindustry))
  236. model.F_CustomerIndustry = customerindustry;
  237. if (!string.IsNullOrEmpty(mobile))
  238. model.F_Telephone = mobile;
  239. if (bll.Update(model))
  240. {
  241. return Success("修改成功!", model.F_CustomerId);
  242. }
  243. else
  244. {
  245. return Error("修改失败!");
  246. }
  247. }
  248. }
  249. List<string> lddep = new BLL.T_Cus_CustomerBase().GetLDdep();
  250. var gdlddep = new BLL.T_Wo_WorkOrder().GetModelList("1=1").Select(p => p.Address).Distinct().ToList();//从工单来电单位中加载
  251. var gdfkdep = new BLL.T_Wo_WorkOrder().GetModelList("1=1").Select(p => p.Source).Distinct().ToList();//从工单反馈单位中加载
  252. foreach (var item in gdlddep)
  253. {
  254. if (!lddep.Contains(item))
  255. lddep.Add(item);
  256. }
  257. foreach (var item in gdfkdep)
  258. {
  259. if (!lddep.Contains(item))
  260. lddep.Add(item);
  261. }
  262. CacheHelper.Insert("LDDep", lddep);
  263. }
  264. return Error("参数错误");
  265. }
  266. return Error("未知错误,请重新登录");
  267. }
  268. /// <summary>
  269. /// 删除客户
  270. /// </summary>
  271. /// <param name="ids"></param>
  272. /// <returns></returns>
  273. public ActionResult DelCustomer(string[] ids)
  274. {
  275. ActionResult res = NoToken("未知错误,请重新登录");
  276. if (Request.IsAuthenticated)
  277. {
  278. if (ids != null && ids.Length > 0)
  279. {
  280. string idd = " ";
  281. foreach (string str in ids)
  282. {
  283. idd += str + ",";
  284. }
  285. //string state = RequestString.GetQueryString("state");
  286. string sql = "update T_Cus_CustomerBase set F_DeleteFlag=1 where F_CustomerId in (" + idd.TrimEnd(',') + ")";
  287. if (!string.IsNullOrEmpty(idd.Trim()))
  288. {
  289. if (DbHelperSQL.ExecuteSql(sql) > 0)
  290. {
  291. res = Success("设置成功");
  292. List<string> lddep = new BLL.T_Cus_CustomerBase().GetLDdep();
  293. var gdlddep = new BLL.T_Wo_WorkOrder().GetModelList("1=1").Select(p => p.Address).Distinct().ToList();//从工单来电单位中加载
  294. var gdfkdep = new BLL.T_Wo_WorkOrder().GetModelList("1=1").Select(p => p.Source).Distinct().ToList();//从工单反馈单位中加载
  295. foreach (var item in gdlddep)
  296. {
  297. if (!lddep.Contains(item))
  298. lddep.Add(item);
  299. }
  300. foreach (var item in gdfkdep)
  301. {
  302. if (!lddep.Contains(item))
  303. lddep.Add(item);
  304. }
  305. CacheHelper.Insert("LDDep", lddep);
  306. }
  307. else
  308. {
  309. res = Error("设置失败");
  310. }
  311. }
  312. else
  313. {
  314. res = Error("请选择用户");
  315. }
  316. }
  317. else
  318. {
  319. res = Error("获取参数失败");
  320. }
  321. }
  322. return res;
  323. }
  324. /// <summary>
  325. /// 绑定来电单位
  326. /// </summary>
  327. /// <returns></returns>
  328. public ActionResult BindLDdep()
  329. {
  330. ActionResult res = NoToken("未知错误,请重新登录");
  331. //string keypara = RequestString.GetQueryString("keypara");
  332. if (Request.IsAuthenticated)
  333. {
  334. //List<string> lddep = new BLL.T_Cus_CustomerBase().GetLDdep();
  335. List<string> lddep = null;
  336. lddep = CacheHelper.Get("LDDep") as List<string>;
  337. List<string> resdep = new List<string>();
  338. if (lddep != null && lddep.Count > 0)
  339. {
  340. foreach (string dep in lddep)
  341. {
  342. if (!Utils.IsNumeric(dep))
  343. {
  344. resdep.Add(dep);
  345. }
  346. //if (dep.Contains(keypara))
  347. //{
  348. // resdep.Add(dep);
  349. //}
  350. }
  351. var obj = new
  352. {
  353. dep = resdep
  354. };
  355. res = Success("获取成功", obj);
  356. }
  357. else
  358. {
  359. lddep = new BLL.T_Cus_CustomerBase().GetLDdep();//从客户信息查找
  360. var gdlddep = new BLL.T_Wo_WorkOrder().GetModelList("1=1").Select(p => p.Address).Distinct().ToList();//从工单来电单位中加载
  361. var gdfkdep = new BLL.T_Wo_WorkOrder().GetModelList("1=1").Select(p => p.Source).Distinct().ToList();//从工单反馈单位中加载
  362. foreach (var item in gdlddep)
  363. {
  364. if (!lddep.Contains(item))
  365. lddep.Add(item);
  366. }
  367. foreach (var item in gdfkdep)
  368. {
  369. if (!lddep.Contains(item))
  370. lddep.Add(item);
  371. }
  372. if (lddep != null && lddep.Count > 0)
  373. {
  374. foreach (string dep in lddep)
  375. {
  376. if (!Utils.IsNumeric(dep)) {
  377. resdep.Add(dep);
  378. }
  379. //if (!string.IsNullOrEmpty(keypara) || !Utils.IsNumeric(dep))
  380. //{
  381. // if (dep.Contains(keypara))
  382. // {
  383. // resdep.Add(dep);
  384. // }
  385. //}
  386. }
  387. var obj = new
  388. {
  389. dep = resdep
  390. };
  391. res = Success("获取成功", obj);
  392. }
  393. else
  394. res = Error("获取失败,没有对应数据");
  395. }
  396. }
  397. return res;
  398. }
  399. /// <summary>
  400. /// 判断来电单位是否存在。不存在才可以
  401. /// </summary>
  402. /// <returns></returns>
  403. public ActionResult LDdepExist()
  404. {
  405. ActionResult res = NoToken("未知错误,请重新登录");
  406. if (Request.IsAuthenticated)
  407. {
  408. string lddep = RequestString.GetQueryString("lddep");
  409. if (!string.IsNullOrEmpty(lddep))
  410. {
  411. bool lddepexists = new BLL.T_Cus_CustomerBase().LDdepExist(lddep);
  412. if (lddepexists)
  413. {
  414. res = Success("获取成功");
  415. }
  416. else
  417. {
  418. res = Error("获取失败");
  419. }
  420. }
  421. else
  422. {
  423. res = Error("参数传输失败");
  424. }
  425. }
  426. return res;
  427. }
  428. /// <summary>
  429. /// 导入excel
  430. /// </summary>
  431. /// <returns></returns>
  432. public ActionResult ExportExcel()
  433. {
  434. ActionResult res = NoToken("未知错误,请重新登录");
  435. if (Request.IsAuthenticated)
  436. {
  437. //string filestr = RequestString.GetFormString("file");
  438. //string filestr = RequestString.GetQueryString("file");
  439. int userId = CurrentUser.UserData.F_UserId;
  440. if (userId != 0)
  441. {
  442. ////需要先将文件保存到服务器项目下,再读取
  443. ////传入的应该是整个文件,file和上传按钮
  444. //string file = Request.Files[0].FileName;
  445. //string fileextension = Request.Files[0].ContentType;
  446. //if (!string.IsNullOrEmpty(file) && file != "undefined")
  447. //{
  448. // //string extensionstr = Path.GetExtension(filestr);
  449. // //if (extensionstr == ".xls" || extensionstr == ".xlsx")
  450. // if (fileextension == "application/vnd.ms-excel" || fileextension == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  451. // {
  452. // //将上传的文件保存在服务器下
  453. // Request.SaveAs(Server.MapPath("~/App_Data/" + file), false);
  454. // if (System.IO.File.Exists(Server.MapPath("~/App_Data/" + file)))
  455. // {
  456. // HSSFWorkbook hssfworkbook;
  457. // XSSFWorkbook xssfworkbook;
  458. // ISheet sheet;
  459. // DataTable dt = new DataTable();
  460. // using (FileStream filestream = new FileStream(Path.GetFullPath(file), FileMode.Open, FileAccess.Read))
  461. // {
  462. // if (fileextension == "application/vnd.ms-excel")
  463. // {
  464. // hssfworkbook = new HSSFWorkbook(filestream);
  465. // sheet = hssfworkbook.GetSheetAt(0);
  466. // }
  467. // else
  468. // {
  469. // xssfworkbook = new XSSFWorkbook(filestream);
  470. // sheet = xssfworkbook.GetSheetAt(0);
  471. // }
  472. // }
  473. // System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  474. // IRow headerRow = sheet.GetRow(0);
  475. // int cellCount = headerRow.LastCellNum;
  476. // for (int j = 0; j < cellCount; j++)
  477. // {
  478. // ICell cell = headerRow.GetCell(j);
  479. // dt.Columns.Add(cell.ToString());
  480. // }
  481. // Model.T_Cus_CustomerBase model = new Model.T_Cus_CustomerBase();
  482. // BLL.T_Cus_CustomerBase bll = new BLL.T_Cus_CustomerBase();
  483. // int count = 0;
  484. // for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
  485. // {
  486. // IRow row = sheet.GetRow(i);
  487. // DataRow dataRow = dt.NewRow();
  488. // for (int j = row.FirstCellNum; j < cellCount; j++)
  489. // {
  490. // if (row.GetCell(j) != null)
  491. // dataRow[j] = row.GetCell(j).ToString();
  492. // }
  493. // dt.Rows.Add(dataRow);
  494. // //导入后要插入数据库
  495. // model.F_CustomerName = dataRow[2].ToString();
  496. // model.F_Province = dataRow[0].ToString();
  497. // model.F_CustomerIndustry = dataRow[1].ToString();
  498. // model.F_Mobile = dataRow[3].ToString();
  499. // model.F_CreateBy = userId;
  500. // model.F_CreatedOn = DateTime.Now;
  501. // model.F_DeleteFlag = 0;
  502. // int n = bll.Add(model);
  503. // if (n > 0)
  504. // { count++; }
  505. // }
  506. // res = Success("共导入" + dt.Rows.Count + "条,成功" + count + "条", dt);
  507. // }
  508. // else
  509. // {
  510. // res = Error("文件未上传成功");
  511. // }
  512. // }
  513. // else
  514. // {
  515. // res = Error("文件类型错误");
  516. // }
  517. //}
  518. //else
  519. //{
  520. // res = Error("参数传输失败");
  521. //}
  522. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  523. if (_upFile != null)
  524. {
  525. string filepath = "";
  526. string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  527. string aLastName = _upFile.FileName.Substring(_upFile.FileName.LastIndexOf(".") + 1, (_upFile.FileName.Length - _upFile.FileName.LastIndexOf(".") - 1)); //扩展名
  528. if (aLastName != "xls" && aLastName != "xlsx")
  529. {
  530. res = Error("文件类型错误,请选择Excel文件");
  531. }
  532. string newpath = datepath + "_" + _upFile.FileName;
  533. if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  534. {
  535. Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  536. }
  537. filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  538. string PhysicalPath = Server.MapPath(filepath);
  539. _upFile.SaveAs(PhysicalPath);
  540. DataTable dt = new DataTable();
  541. IWorkbook workbook = null;
  542. using (FileStream file = new FileStream(PhysicalPath, FileMode.Open, FileAccess.Read))
  543. {
  544. if (aLastName == "xlsx") // 2007版本
  545. {
  546. workbook = new XSSFWorkbook(file);
  547. }
  548. else if (aLastName == "xls") // 2003版本
  549. {
  550. workbook = new HSSFWorkbook(file);
  551. }
  552. //hssfworkbook = new HSSFWorkbook(file);
  553. }
  554. ISheet sheet = workbook.GetSheetAt(0);
  555. System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  556. IRow headerRow = sheet.GetRow(0);
  557. int cellCount = headerRow.LastCellNum;
  558. if (cellCount < 1)
  559. res = Error("文件标题没有数据");
  560. for (int j = 0; j < cellCount; j++)
  561. {
  562. ICell cell = headerRow.GetCell(j);
  563. dt.Columns.Add(cell.ToString());
  564. }
  565. Model.T_Cus_CustomerBase model = new Model.T_Cus_CustomerBase();
  566. BLL.T_Cus_CustomerBase bll = new BLL.T_Cus_CustomerBase();
  567. int count = 0;
  568. //客户名称加入来电单位
  569. List<string> lddep = null;
  570. lddep = CacheHelper.Get("LDDep") as List<string>;
  571. for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
  572. {
  573. IRow row = sheet.GetRow(i);
  574. DataRow dataRow = dt.NewRow();
  575. for (int j = row.FirstCellNum; j < cellCount; j++)
  576. {
  577. if (row.GetCell(j) != null)
  578. dataRow[j] = row.GetCell(j).ToString();
  579. }
  580. //dt.Rows.Add(dataRow);
  581. dt.Rows.Add(dataRow);
  582. if (dt.Rows.Count < 1)
  583. res = Error("文件内容没有数据");
  584. //导入后要插入数据库
  585. model.F_CustomerName = dataRow[2].ToString();
  586. model.F_Province = dataRow[0].ToString();
  587. model.F_CustomerIndustry = dataRow[1].ToString();
  588. //model.F_Mobile = dataRow[3].ToString();
  589. model.F_Telephone = dataRow[3].ToString();
  590. model.F_CreateBy = userId;
  591. model.F_CreatedOn = DateTime.Now;
  592. model.F_DeleteFlag = 0;
  593. int n = bll.Add(model);
  594. if (n > 0)
  595. {
  596. count++;
  597. var cusindustry = dataRow[1].ToString();
  598. if (!lddep.Contains(cusindustry))
  599. {
  600. lddep.Add(cusindustry);
  601. CacheHelper.Insert("LDDep", lddep);
  602. }
  603. }
  604. }
  605. //if (dt == null || dt.Rows.Count == 0)
  606. if (dt == null || dt.Rows.Count == 0)
  607. res = Error("文件没有数据");
  608. //var jstr = DataTableToJson(dt);
  609. else
  610. {
  611. var jstr = DataTableToJson(dt);
  612. res = Success("导入成功", jstr);
  613. }
  614. }
  615. }
  616. }
  617. return res;
  618. }
  619. public string DataTableToJson(DataTable dt)
  620. {
  621. string JsonString = string.Empty;
  622. JsonString = JsonConvert.SerializeObject(dt);
  623. return JsonString;
  624. }
  625. }
  626. }