页面代码:

  1. <form id="form1" enctype="multipart/form-data">
  2. <div style="float:right">
  3. &nbsp;
  4. <button type="button" class="btn btn-primary" onclick="$('#fileUpload').click()" id="reviewFile">浏览</button>
  5. <button class="btn btn-primary" type="button" style="margin-left:5px;height:30px;" id="dataExport">批量导入</button>
  6. <input type="button" class="btn btn-primary" style="margin-left:5px;height:30px;" id="downLoad" value="下载模板">
  7. </div>
  8. <div style="float:right;margin-top:5px">
  9. <input id="fileUpload" name="fileUpload" type="file" style="display:none" />
  10. <input id="fileText" type="text" class="form-control" disabled />
  11. </div>
  12. <script>
  13. $("#fileUpload").change(function () {
  14. $("#fileText").val($(this).val());
  15. })
  16. </script>
  17. </form>

js代码:

  1. //导入excel数据
  2. $("#dataExport").click(function () {
  3. var formData = new FormData($('form')[0]);
  4. $.ajax({
  5. url: '/BaseInfoPage/GetAllDataFromExcel',
  6. type: 'POST',
  7. xhr: function () {
  8. return $.ajaxSettings.xhr();
  9. },
  10. data: formData,
  11. cache: false,
  12. contentType: false,
  13. processData: false,
  14. success: function (data) {
  15. if (data == "导入成功!") {
  16. layer.msg(data, { icon: 1, time: 5000 }, function () {
  17. location.reload(); //刷新父页面 第二个参数设置msg显示的时间长短
  18. });
  19. } else {
  20. layer.msg(data, { icon: 0, time: 5000 }, function () {
  21. return;
  22. });
  23. }
  24.  
  25. },
  26. error: function (e) {
  27. layer.msg(e, { icon: 0, time: 5000 }, function () {
  28. return;
  29. });
  30. }
  31.  
  32. });
  33. })

c#后台代码:

  1. public string GetAllDataFromExcel(HttpPostedFileBase fileUpload)
  2. {
  3. if (fileUpload == null)
  4. {
  5. return "文件为空!";
  6. }
  7. try
  8. {
  9. List<LargeTransportLicenseParam> dataList = new List<LargeTransportLicenseParam>();
  10. List<string> rNameLists = new List<string>();
  11. List<string> ltlLists = new List<string>();
  12. List<string> strLId = large_util.QueryLargeIds();//获取所有大件运输许可编号
  13. List<string> strRname = large_util.QueryReName();//获取所有省份
  14. int result = ;
  15. int result2 = ;
  16. string fileExt = Path.GetExtension(fileUpload.FileName).ToLower();
  17. string fileName = fileUpload.FileName;
  18. string filePath = CSysCfg.exFilePath;
  19. if (!Directory.Exists(filePath))
  20. {
  21. Directory.CreateDirectory(filePath);
  22. }
  23. //保存模板到服务器
  24. fileUpload.SaveAs(filePath + "\\" + fileName);
  25. if (fileExt == ".xls" || fileExt == ".xlsx")
  26. {
  27. //1.创建IWorkbook
  28. IWorkbook Workbook;
  29. using (FileStream fileStream = new FileStream(filePath + "\\" + fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  30. {
  31. //XSSFWorkbook 适用XLSX格式,HSSFWorkbook 适用XLS格式
  32. if (fileExt == ".xls")
  33. {
  34. Workbook = new HSSFWorkbook(fileStream);
  35. }
  36. else if (fileExt == ".xlsx")
  37. {
  38. Workbook = new XSSFWorkbook(fileStream);
  39. }
  40. else
  41. {
  42. Workbook = null;
  43. }
  44. }
  45. Dictionary<List<string>, List<string>> dataDic = new Dictionary<List<string>, List<string>>();
  46. //遍历每个Sheet
  47. for (int i = ; i < Workbook.NumberOfSheets; i++)
  48. {
  49. //获取每个Sheet对象
  50. ISheet sheet = Workbook.GetSheetAt(i);
  51.  
  52. //获取每个工作表中的行
  53. //第一,二行是列名舍去,从第三行开始读取 LastRowNum 是当前表的总行数-1(注意)
  54. for (int j = ; j <= sheet.LastRowNum; j++)
  55. {
  56. IRow row = sheet.GetRow(j);
  57.  
  58. #region 数据赋值 判断
  59. if (row != null)
  60. {
  61. LargeTransportLicenseParam param = new LargeTransportLicenseParam();
  62. param.loginId = Cookie.Value.Split(',')[].ToString();
  63. if (strLId.Contains(row.GetCell().ToString()))//判断如果数据库包含此值
  64. {
  65. return "第" + (row.RowNum + ) + "行第" + + "列数据库具有相同的值!";
  66. }
  67. else if (row.GetCell() == null)
  68. {
  69. return "第" + (row.RowNum + ) + "行第" + + "值为空!";
  70. }
  71. else
  72. {
  73. param.ltlId = row.GetCell().ToString();//申请编号 必填
  74.  
  75. }
  76. //车牌号码
  77. if (row.GetCell() == null)
  78. {
  79. return "第" + (row.RowNum + ) + "行第" + + "值为空!";
  80. }
  81. else
  82. {
  83. param.ltlPlateId = row.GetCell().ToString();//车牌号码 必填
  84. }
  85. //开始时间
  86. if (row.GetCell() == null)
  87. {
  88. return "第" + (row.RowNum + ) + "行第" + + "列值为空!";
  89. }
  90. else if (row.GetCell().CellType == CellType.String)
  91. {
  92.  
  93. return "第" + (row.RowNum + ) + "行第" + + "列请输入正确的日期格式!";
  94. }
  95. else
  96. {
  97. param.ltlStarteTime = row.GetCell().DateCellValue.ToString();//当输入文本日期时,通过DateCellValue得到他的日期格式
  98. }
  99. //结束时间
  100. if (row.GetCell() == null)
  101. {
  102. return "第" + (row.RowNum + ) + "行第" + + "值为空!";
  103. }
  104. else if (row.GetCell().CellType == CellType.String)
  105. {
  106.  
  107. return "第" + (row.RowNum + ) + "行第" + + "列请输入正确的日期格式!";
  108. }
  109. else
  110. {
  111. param.ltlEndTime = row.GetCell().DateCellValue.ToString();//结束时间 必填
  112. }
  113.  
  114. //途径省份
  115. if (row.GetCell() == null)
  116. {
  117. return "第" + (row.RowNum + ) + "行第" + + "值为空!";
  118. }
  119. string strs = row.GetCell().ToString();
  120. string[] arr = strs.Split(',');
  121. if (arr[] != null)
  122. {
  123. for (int k = ; k < arr.Length; k++)
  124. {
  125. rNameLists.Add(arr[k]);
  126. ltlLists.Add(row.GetCell().ToString());
  127. }
  128. }
  129.  
  130. param.ltlPassageRoute = row.GetCell() == null ? "" : row.GetCell().ToString();//通行路线
  131. param.ltlRoadTransportNum = row.GetCell() == null ? "" : row.GetCell().ToString();//道路运输证号
  132. param.ltlBrandModel = row.GetCell() == null ? "" : row.GetCell().ToString();//厂牌型号
  133. ICell cell = row.GetCell();//车长(M)
  134. if (cell == null)
  135. {
  136. param.ltlCarLength = ;
  137. }
  138. else if (row.GetCell().CellType == CellType.String)
  139. {
  140. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  141. }
  142. else
  143. {
  144. param.ltlCarLength = Convert.ToInt32(row.GetCell().ToString());//车长(M)
  145. }
  146. ICell cell9 = row.GetCell();//车宽
  147. if (cell9 == null)
  148. {
  149. param.ltlCarWidth = ;
  150. }
  151. else if (row.GetCell().CellType == CellType.String)
  152. {
  153. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  154. }
  155. else
  156. {
  157. param.ltlCarWidth = Convert.ToInt32(row.GetCell().ToString());//车长(M)
  158. }
  159. ICell cell10 = row.GetCell();//车高
  160. if (cell10 == null)
  161. {
  162. param.ltlCarHeight = ;
  163. }
  164. else if (row.GetCell().CellType == CellType.String)
  165. {
  166. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  167. }
  168. else
  169. {
  170. param.ltlCarHeight = Convert.ToInt32(row.GetCell().ToString());
  171. }
  172. ICell cell11 = row.GetCell();//整备质量
  173. if (cell11 == null)
  174. {
  175. param.ltlCurbQuality = ;
  176. }
  177. else if (row.GetCell().CellType == CellType.String)
  178. {
  179. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  180. }
  181. else
  182. {
  183. param.ltlCurbQuality = Convert.ToInt32(row.GetCell().ToString());
  184. }
  185. ICell cell12 = row.GetCell();//荷载质量
  186. if (cell12 == null)
  187. {
  188. param.ltlLoadQuality = ;
  189. }
  190. else if (row.GetCell().CellType == CellType.String)
  191. {
  192. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  193. }
  194. else
  195. {
  196. param.ltlLoadQuality = Convert.ToInt32(row.GetCell().ToString());
  197. }
  198. ICell cell13 = row.GetCell();//牵引质量
  199. if (cell13 == null)
  200. {
  201. param.ltlTractionQuality = ;
  202. }
  203. else if (row.GetCell().CellType == CellType.String)
  204. {
  205. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  206. }
  207. else
  208. {
  209. param.ltlTractionQuality = Convert.ToInt32(row.GetCell().ToString());
  210. }
  211. param.ltlRoadTransportImg = row.GetCell() == null ? "" : row.GetCell().ToString();//道路运输证照片
  212. param.ltlDrivingLicenseImg = row.GetCell() == null ? "" : row.GetCell().ToString();//机动车行驶证照片
  213. ICell cell16 = row.GetCell();//车货总重量(吨)
  214. if (cell16 == null)
  215. {
  216. return "第" + (row.RowNum + ) + "行第" + + "列值为空!";
  217. }
  218. else if (row.GetCell().CellType == CellType.String)
  219. {
  220. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  221. }
  222. else
  223. {
  224. param.ltlTotalWeigth = Convert.ToInt32(row.GetCell().ToString());
  225. }
  226. ICell cell17 = row.GetCell();//轴距
  227. if (cell17 == null)
  228. {
  229. param.ltlWheelbase = ;
  230. }
  231. else if (row.GetCell().CellType == CellType.String)
  232. {
  233. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  234. }
  235. else
  236. {
  237. param.ltlWheelbase = Convert.ToInt32(row.GetCell().ToString());
  238. }
  239. ICell cell18 = row.GetCell();//车货最大长(M)
  240. if (cell16 == null)
  241. {
  242. return "第" + (row.RowNum + ) + "行第" + + "列值为空!";
  243. }
  244. else if (row.GetCell().CellType == CellType.String)
  245. {
  246. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  247. }
  248. else
  249. {
  250. param.ltlMaxLength = Convert.ToInt32(row.GetCell().ToString());
  251. }
  252. ICell cell19 = row.GetCell();//轴载
  253. if (cell19 == null)
  254. {
  255. param.ltlAxleLoad = ;
  256. }
  257. else if (row.GetCell().CellType == CellType.String)
  258. {
  259. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  260. }
  261. else
  262. {
  263. param.ltlAxleLoad = Convert.ToInt32(row.GetCell().ToString());
  264. }
  265. ICell cell20 = row.GetCell();//车货最大宽(M)
  266. if (cell20 == null)
  267. {
  268. return "第" + (row.RowNum + ) + "行第" + + "列值为空!";
  269. }
  270. else if (row.GetCell().CellType == CellType.String)
  271. {
  272. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  273. }
  274. else
  275. {
  276. param.ltlMaxWidth = Convert.ToInt32(row.GetCell().ToString());
  277. }
  278. param.ltlGoodsInfo = row.GetCell() == null ? "" : row.GetCell().ToString();//货物信息
  279. ICell cell22 = row.GetCell();//车货最大高(M)
  280. if (cell22 == null)
  281. {
  282. return "第" + (row.RowNum + ) + "行第" + + "列值为空!";
  283. }
  284. else if (row.GetCell().CellType == CellType.String)
  285. {
  286. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  287. }
  288. else
  289. {
  290. param.ltlMaxHeight = Convert.ToInt32(row.GetCell().ToString());
  291. }
  292. ICell cell23 = row.GetCell();//货物重量(吨)
  293. if (cell23 == null)
  294. {
  295. param.ltlGoodsWeight = ;
  296. }
  297. else if (row.GetCell().CellType == CellType.String)
  298. {
  299. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  300. }
  301. else
  302. {
  303. param.ltlGoodsWeight = Convert.ToInt32(row.GetCell().ToString());
  304. }
  305.  
  306. ICell cell24 = row.GetCell();//货物最大长(M)
  307. if (cell24 == null)
  308. {
  309. param.ltlGoodsMaxLenght = ;
  310. }
  311. else if (row.GetCell().CellType == CellType.String)
  312. {
  313. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  314. }
  315. else
  316. {
  317. param.ltlGoodsMaxLenght = Convert.ToInt32(row.GetCell().ToString());
  318. }
  319. ICell cell25 = row.GetCell();//货物最大宽(M)
  320. if (cell25 == null)
  321. {
  322. param.ltlGoodsMaxWidth = ;
  323. }
  324. else if (row.GetCell().CellType == CellType.String)
  325. {
  326. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  327. }
  328. else
  329. {
  330. param.ltlGoodsMaxWidth = Convert.ToInt32(row.GetCell().ToString());
  331. }
  332. ICell cell26 = row.GetCell();//货物最大高(M)
  333. if (cell26 == null)
  334. {
  335. param.ltlGoodsMaxHeight = ;
  336. }
  337. else if (row.GetCell().CellType == CellType.String)
  338. {
  339. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  340. }
  341. else
  342. {
  343. param.ltlGoodsMaxHeight = Convert.ToInt32(row.GetCell().ToString());
  344. }
  345. ICell cell27 = row.GetCell();//轮胎数
  346. if (cell27 == null)
  347. {
  348. param.ltlTireNumber = ;
  349. }
  350. else if (row.GetCell().CellType == CellType.String)
  351. {
  352. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  353. }
  354. else
  355. {
  356. param.ltlTireNumber = Convert.ToInt32(row.GetCell().ToString());
  357. }
  358. ICell cell28 = row.GetCell();//轴数
  359. if (cell28 == null)
  360. {
  361. param.ltlAxle = ;
  362. }
  363. else if (row.GetCell().CellType == CellType.String)
  364. {
  365. return "第" + (row.RowNum + ) + "行第" + + "列数据类型错误,必须为数值";
  366. }
  367. else
  368. {
  369. param.ltlAxle = Convert.ToInt32(row.GetCell().ToString());
  370. }
  371. param.ltlGoodsImg = row.GetCell() == null ? "" : row.GetCell().ToString();//车货照片
  372. param.ltlBusinessLicenseNum = row.GetCell() == null ? "" : row.GetCell().ToString();//经营许可证编号
  373. param.ltlManagerName = row.GetCell() == null ? "" : row.GetCell().ToString();//经办人姓名
  374. param.ltlManagerIdCard = row.GetCell() == null ? "" : row.GetCell().ToString();//经办人身份证
  375. param.ltlManagerPhone = row.GetCell() == null ? "" : row.GetCell().ToString();//联系电话
  376. param.ltlOpenImg = row.GetCell() == null ? "" : row.GetCell().ToString();//营业执照照片
  377. param.ltlPowerImg = row.GetCell() == null ? "" : row.GetCell().ToString();//授权书照片
  378. param.ltlManagerIdCardImg = row.GetCell() == null ? "" : row.GetCell().ToString();//授权书照片
  379. param.ltlBusinessLicenseImg = row.GetCell() == null ? "" : row.GetCell().ToString();//经营许可证照片
  380.  
  381. dataList.Add(param);
  382. }
  383. else
  384. {
  385. return "暂无数据!";
  386. }
  387. #endregion
  388. }
  389. }
  390. result = large_util.AddLargeInfo2(dataList);
  391. if (result == )
  392. {
  393. if (rNameLists != null && ltlLists != null)
  394. {
  395. result2 = large_util.Add2(ltlLists, rNameLists);
  396. }
  397. else
  398. {
  399. return "暂无数据!";
  400. }
  401. }
  402. return "导入成功!";
  403.  
  404. }
  405. else
  406. {
  407. return "只可以选择Excel文件!";
  408. }
  409. }
  410. catch (Exception ex)
  411. {
  412.  
  413. throw ex;
  414. }
  415.  
  416. }
  1. //批量新增
  2. public int AddLargeInfo2(List<LargeTransportLicenseParam> LargeData)
  3. {
  4. int result = ;
  5. var lgId = "";
  6. try
  7. {
  8. foreach (var item in LargeData)
  9. {
  10. lgId = item.ltlId;
  11. if (item != null)
  12. {
  13. string oldName = System.IO.Path.GetFileName(item.ltlOpenImg);
  14. string expendName = System.IO.Path.GetExtension(oldName);
  15. string filePath = "";
  16. if (oldName != "" || oldName == null)
  17. {
  18. filePath = CSysCfg.lFilePath + "\\" + "ltlOpenImg" + item.ltlId + expendName;
  19. }
  20. string oldName1 = System.IO.Path.GetFileName(item.ltlPowerImg);
  21. string expendName1 = System.IO.Path.GetExtension(oldName1);
  22. string filePath1 = "";
  23. if (oldName1 != "" || oldName1 == null)
  24. {
  25. filePath1 = CSysCfg.lFilePath + "\\" + "ltlPowerImg" + item.ltlId + expendName1;
  26. }
  27. string oldName2 = System.IO.Path.GetFileName(item.ltlManagerIdCardImg);
  28. string expendName2 = System.IO.Path.GetExtension(oldName2);
  29. string filePath2 = "";
  30. if (oldName2 != "" || oldName2 == null)
  31. {
  32. filePath2 = CSysCfg.lFilePath + "\\" + "ltlManagerIdCardImg" + item.ltlId + expendName2;
  33. }
  34. string oldName3 = System.IO.Path.GetFileName(item.ltlBusinessLicenseImg);
  35. string expendName3 = System.IO.Path.GetExtension(oldName3);
  36. string filePath3 = "";
  37. if (oldName3 != "" || oldName3 == null)
  38. {
  39. filePath3 = CSysCfg.lFilePath + "\\" + "ltlBusinessLicenseImg" + item.ltlId + expendName3;
  40. }
  41. string oldName4 = System.IO.Path.GetFileName(item.ltlRoadTransportImg);
  42. string expendName4 = System.IO.Path.GetExtension(oldName4);
  43. string filePath4 = "";
  44. if (oldName4 != "" || oldName4 == null)
  45. {
  46. filePath4 = CSysCfg.lFilePath + "\\" + "ltlRoadTransportImg" + item.ltlId + expendName4;
  47. }
  48. string oldName5 = System.IO.Path.GetFileName(item.ltlDrivingLicenseImg);
  49. string expendName5 = System.IO.Path.GetExtension(oldName5);
  50. string filePath5 = "";
  51. if (oldName5 != "" || oldName5 == null)
  52. {
  53. filePath5 = CSysCfg.lFilePath + "\\" + "ltlDrivingLicenseImg" + item.ltlId + expendName5;
  54. }
  55. string oldName7 = System.IO.Path.GetFileName(item.ltlGoodsImg);
  56. string expendName7 = System.IO.Path.GetExtension(oldName7);
  57. string filePath7 = "";
  58. if (oldName7 != "" || oldName7 == null)
  59. {
  60. filePath7 = CSysCfg.lFilePath + "\\" + "ltlGoodsImg" + item.ltlId + expendName7;
  61. }
  62. LargeTransportLicense large = new LargeTransportLicense
  63. {
  64. ltl_Id = item.ltlId,
  65. ltl_PlateId = item.ltlPlateId,
  66. ltl_StarteTime = DateTime.Parse(item.ltlStarteTime),
  67. ltl_EndTime = DateTime.Parse(item.ltlEndTime),
  68. ltl_PassageRoute = item.ltlPassageRoute,
  69. ltl_BusinessLicenseNum = item.ltlBusinessLicenseNum,
  70. ltl_ManagerName = item.ltlManagerName,
  71. ltl_ManagerIdCard = item.ltlManagerIdCard,
  72. ltl_ManagerPhone = item.ltlManagerPhone,
  73. ltl_OpenImg = filePath,
  74. ltl_PowerImg = filePath1,
  75. ltl_ManagerIdCardImg = filePath2,
  76. ltl_BusinessLicenseImg = filePath3,
  77. ltl_RoadTransportNum = item.ltlRoadTransportNum,
  78. ltl_BrandModel = item.ltlBrandModel,
  79. ltl_CarLength = item.ltlCarLength * ,
  80. ltl_CarWidth = item.ltlCarWidth * ,
  81. ltl_CarHeight = item.ltlCarHeight * ,
  82. ltl_CurbQuality = item.ltlCurbQuality * ,
  83. ltl_LoadQuality = item.ltlLoadQuality * ,
  84. ltl_TractionQuality = item.ltlTractionQuality * ,
  85. ltl_RoadTransportImg = filePath4,
  86. ltl_DrivingLicenseImg = filePath5,
  87. ltl_TotalWeigth = item.ltlTotalWeigth * ,
  88. ltl_Wheelbase = item.ltlWheelbase,
  89. ltl_MaxLength = item.ltlMaxLength * ,
  90. ltl_AxleLoad = item.ltlAxleLoad,
  91. ltl_MaxWidth = item.ltlMaxWidth * ,
  92. ltl_GoodsInfo = item.ltlGoodsInfo,
  93. ltl_MaxHeight = item.ltlMaxHeight * ,
  94. ltl_GoodsWeight = item.ltlGoodsWeight * ,
  95. ltl_GoodsMaxLenght = item.ltlGoodsMaxLenght * ,
  96. ltl_GoodsMaxWidth = item.ltlGoodsMaxWidth * ,
  97. ltl_GoodsMaxHeight = item.ltlGoodsMaxHeight * ,
  98. ltl_TireNumber = item.ltlTireNumber,
  99. ltl_Axle = item.ltlAxle,
  100. ltl_GoodsImg = filePath7
  101. };
  102. using (Entities db = new Entities())
  103. {
  104. db.LargeTransportLicense.Add(large);
  105. db.SaveChanges();
  106. LogUtil.AddLogs("大件运输许可", "添加", "添加大件运输许可:" + item.ltlId);
  107. result = ;
  108. }
  109. }
  110. else
  111. {
  112. result = ;
  113. }
  114. }
  115. }
  116. catch (Exception ex)
  117. {
  118. LogUtil.AddLogs("大件运输许可", "添加", "添加大件运输许可:" + lgId + "失败!");
  119. LogUtil.AddErrorLogs("大件运输许可", "添加", "添加大件运输许可:" + lgId + "异常:" + ex.Message);
  120. throw;
  121. }
  122. return result;
  123. }
  124.  
  125. //批量新增省份
  126. public int Add2(List<string> lId, List<string> rNames)
  127. {
  128. int result = ;
  129. string ltlId = "";//大件运输id
  130. var reIds = "";//行政区划id
  131. try
  132. {
  133. LargeRegionRelation datas = null;
  134. using (Entities db = new Entities())
  135. {
  136. if (lId != null && rNames != null)
  137. {
  138. for (int i = ; i < rNames.Count(); i++)
  139. {
  140. ltlId = lId[i];
  141. string str = rNames[i];
  142. string regStr = "省";
  143. Regex r = new Regex(regStr);
  144. Match m = r.Match(str);//str是否包含省
  145. string str1;
  146. int index = rNames[i].LastIndexOf("省");//获取最后一个字符
  147. if (index >= )//判断省份最后一个字符是否是省
  148. {
  149. if (m.Success)//如是则截取,再进行新增
  150. {
  151. //绿色部分与紫色部分取一种即可。
  152. str = str.Replace(regStr, "");
  153. str1 = str.Substring(, m.Index);
  154. reIds = (from p in db.Region where p.region_Name == str1 select p.region_id).FirstOrDefault();
  155. datas = new LargeRegionRelation
  156. {
  157. lr_ltlId = ltlId,
  158. lr_RegionId = reIds
  159. };
  160. db.LargeRegionRelation.Add(datas);
  161. db.SaveChanges();
  162. result = ;
  163. }
  164. }
  165. else
  166. {
  167. reIds = (from p in db.Region where p.region_Name == rNames[i] select p.region_id).FirstOrDefault();
  168. datas = new LargeRegionRelation
  169. {
  170. lr_ltlId = ltlId,
  171. lr_RegionId = reIds
  172. };
  173. db.LargeRegionRelation.Add(datas);
  174. db.SaveChanges();
  175. result = ;
  176. }
  177. }
  178.  
  179. }
  180. else
  181. {
  182. result = ;
  183. }
  184. }
  185.  
  186. return result;
  187.  
  188. }
  189. catch (Exception)
  190. {
  191. throw;
  192. }
  193. }

ajax模拟表单提交,后台使用npoi实现导入操作 方式二的更多相关文章

  1. ajax模拟表单提交,后台使用npoi实现导入操作 方式一

    页面代码: <form id="form1" enctype="multipart/form-data"> <div style=" ...

  2. 由于想要实现下载的文件可以进行选择,而不是通过<a>标签写死下载文件的参数,所以一直想要使用JFinal结合ajax实现文件下载,但是ajax实现的文件下载并不能触发浏览器的下载文件弹出框,这里通过模拟表单提交实现同样的效果。

    由于想要实现下载的文件可以进行选择,而不是通过<a>标签写死下载文件的参数,所以一直想要使用JFinal结合ajax实现文件下载(这样的话ajax可以传递不同的参数),但是ajax实现的文 ...

  3. 表单提交---前端页面模拟表单提交(form)

    有些时候我们的前端页面总没有<form></form>表单,但是具体的业务时,我们又必须用表单提交才能达到我们想要的结果,LZ最近做了一些关于导出的一些功能,需要调用浏览器默认 ...

  4. ajax form表单提交 input file中的文件

    ajax form表单提交 input file中的文件 现今的主流浏览器由于ajax提交form表单无法把文件类型数据提交到后台,供后台处理,可是开发中由于某些原因又不得不用ajax提交文件, 为了 ...

  5. <记录> axios 模拟表单提交数据

    ajax 可以通过 FormData 对象模拟表单提交数据 第一种方式:自定义FormData信息 //创建formData对象 var formData = new FormData(); //添加 ...

  6. ajax的表单提交,与传送数据

    ajax的表单提交 $.ajax ({ url: "<%=basePath%>resource/addPortDetectOne.action", dataType: ...

  7. 项目总结15:JavaScript模拟表单提交(实现window.location.href-POST提交数据效果)

    JavaScript模拟表单提交(实现window.location.href-POST提交数据效果) 前沿 1-在具体项目开发中,用window.location.href方法下载文件,因windo ...

  8. 利用HttpWebRequest模拟表单提交 JQuery 的一个轻量级 Guid 字符串拓展插件. 轻量级Config文件AppSettings节点编辑帮助类

    利用HttpWebRequest模拟表单提交   1 using System; 2 using System.Collections.Specialized; 3 using System.IO; ...

  9. HTTP通信模拟表单提交数据

    前面记录过一篇关于http通信,发送数据的文章:http://www.cnblogs.com/hyyq/p/7089040.html,今天要记录的是如何通过http模拟表单提交数据. 一.通过GET请 ...

随机推荐

  1. 请解释ASP. NET中的web页面与隐藏类之间的关系

    请解释ASP.NET中的web页面与其隐藏类之间的关系 其实页面与其隐藏类之间就是一个部分类的关系,你在页面上放一个一个的控件就是在这个类中定义一个一个的属性, 因为是同一个类的部分类的关系,所以隐藏 ...

  2. 「树形DP」洛谷P2607 [ZJOI2008]骑士

    P2607 [ZJOI2008]骑士 题面: 题目描述 Z 国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的 ...

  3. 【区间DP】低价回文

    [区间DP]低价回文 标签(空格分隔): 区间DP 回文词 [题目描述] 追踪每头奶牛的去向是一件棘手的任务,为此农夫约翰安装了一套自动系统.他在每头牛身上安装了一个电子身份标签,当奶牛通过扫描器的时 ...

  4. 如何更换Windows中命令提示符(cmd)中的字体

    前言 CMD(命令提示符),全称"Command Prompt":对于这个东西我相信大部分用电脑的人基本都知道,因为常常会用到一些基本的DOS命令进行一些电脑的基本查看处理:但是我 ...

  5. requests库入门笔记1

    1.使用requests库发送请求,fiddler无法抓到包:使用浏览器请求相同的url,可以抓到包 在请求参数中添加 proxies参数,如下: proxies = { 'http': 'http: ...

  6. 开发者必备——API设计问题

    本文主要探讨RPC和RESTFul两种API风格的特点以及在开发中应该如何进行技术选型,同时截取了网上社区,文章一部分关于API设计的想法和观点供读者参考,取舍. 1,背景简述 API学名:应用程序接 ...

  7. Pop!_OS安装与配置(四):GNOME插件篇

    Pop!_OS安装与配置(四):GNOME插件篇 #0x0 效果图 #0x1 自动安装(不保证成功性) #0x2 OpenWeather #0x3 Topicons Plus #0x4 System- ...

  8. Python axis的含义

    axis=0表述列 axis=1表述行 如下面例子: In [52]: arr=np.arange(12).reshape((3,4))In [53]:arrOut[53]:array([[ 0, 1 ...

  9. How to install nginx in Ubuntu

    The steps for installing the nginx on Ubuntu below. 1.install the packages first. apt-get install gc ...

  10. 图文详解在Windows系统中安装JDK

    本文以在Windows10中安装JDK8为例进行安装,其他系统和版本都是大同小异的. 下载 进入Oracle官方网站的下载页面:https://www.oracle.com/technetwork/j ...