RequestHandler.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. using CefSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8. using System.Windows.Forms;
  9. using System.Drawing.Printing;
  10. using FastReport;
  11. using System.Data;
  12. using System.Threading;
  13. using System.Net;
  14. using System.Text;
  15. using System.Web;
  16. using System.Diagnostics;
  17. namespace UAS_Web.tool
  18. {
  19. class RequestHandler : IRequestHandler
  20. {
  21. public event Action<byte[]> NotifyMsg;
  22. //打印图片集合
  23. List<Bitmap> bitmaps = new List<Bitmap>();
  24. Report BarcodeReport = new Report();
  25. //图片打印中间变量
  26. int imagecount = 0;
  27. int index = 0;
  28. string PrinterName = "";
  29. string PrintType = "";
  30. PrinterList print;
  31. string LABELNAME = "";
  32. string labelview = "";
  33. /// <summary>
  34. /// 拦截指定请求
  35. /// </summary>
  36. /// <param name="browserControl"></param>
  37. /// <param name="browser"></param>
  38. /// <param name="frame"></param>
  39. /// <param name="request"></param>
  40. /// <param name="response"></param>
  41. /// <returns></returns>
  42. IResponseFilter IRequestHandler.GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
  43. {
  44. MessageFilter filter;
  45. switch (request.Url.Substring(request.Url.LastIndexOf("/") + 1))
  46. {
  47. case "zplPrinter":
  48. filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
  49. return filter;
  50. case "zplPrint.action":
  51. filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
  52. return filter;
  53. case "getPrintType.action":
  54. filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
  55. return filter;
  56. case "vendorZplPrint.action":
  57. filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
  58. return filter;
  59. default:
  60. break;
  61. }
  62. return null;
  63. }
  64. /// <summary>
  65. /// 完成响应后获取Js返回的数据
  66. /// </summary>
  67. /// <param name="browserControl"></param>
  68. /// <param name="browser"></param>
  69. /// <param name="frame"></param>
  70. /// <param name="request"></param>
  71. /// <param name="response"></param>
  72. /// <param name="status"></param>
  73. /// <param name="receivedContentLength"></param>
  74. void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
  75. {
  76. MessageFilter filter;
  77. string str;
  78. Dictionary<string, object> data;
  79. switch (request.Url.Substring(request.Url.LastIndexOf("/") + 1))
  80. {
  81. case "zplPrinter":
  82. var m = request.Method;
  83. if (request.Method == "POST")
  84. {
  85. using (var postData = request.PostData)
  86. {
  87. if (postData != null)
  88. {
  89. var elements = postData.Elements;
  90. var charSet = request.GetCharSet();
  91. foreach (var element in elements)
  92. {
  93. if (element.Type == PostDataElementType.Bytes)
  94. {
  95. string body = HttpUtility.UrlDecode(element.GetBody(charSet),Encoding.UTF8);
  96. LABELNAME = body.Substring(body.LastIndexOf('=')+1);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. //弹出打印机选择列表
  103. print = new PrinterList(browser) { StartPosition = FormStartPosition.CenterScreen,TopMost=true };
  104. print.Controls["Confirm"].Click += RequestHandler_Click;
  105. print.PrintDoc.PrintPage += PrintPage;
  106. print.ShowDialog();
  107. break;
  108. case "zplPrint.action":
  109. filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
  110. str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
  111. data = ToDictionary(str);
  112. //获取所有的打印格式数据
  113. if (data.ContainsKey("data"))
  114. {
  115. string PrintCode = data["data"].ToString().Replace(" ", "").Replace("\"", "");
  116. List<string> PrintList = new List<string>();
  117. int PrintTime = Regex.Matches(PrintCode, "XA").Count;
  118. for (int i = 0; i < PrintTime; i++)
  119. {
  120. PrintList.Add(PrintCode.Substring(0, PrintCode.IndexOf("XZ") + 2));
  121. PrintCode = PrintCode.Substring(PrintCode.IndexOf("XZ") + 2);
  122. }
  123. for (int i = 0; i < PrintList.Count; i++)
  124. {
  125. PrintHelper.SendStringToPrinter(PrinterName, PrintList[i]);
  126. }
  127. data.Clear();
  128. }
  129. else if (data.ContainsKey("exceptionInfo"))
  130. {
  131. //string PrintCode = data["exceptionInfo"].ToString();
  132. //MessageBox.Show(PrintCode);
  133. }
  134. break;
  135. case "getPrintType.action":
  136. filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
  137. str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
  138. data = ToDictionary(str);
  139. PrintType = data["data"].ToString().Replace("\"", "");
  140. break;
  141. case "vendorZplPrint.action":
  142. try
  143. {
  144. filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
  145. str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
  146. if (str.Contains("不允许打印"))
  147. return;
  148. data = ToDictionary(str);
  149. vendorZplPrint(data);
  150. }
  151. catch (Exception ex)
  152. {
  153. MessageBox.Show(ex.Message + "请重新进行打印");
  154. return;
  155. }
  156. break;
  157. default:
  158. break;
  159. }
  160. }
  161. public void vendorZplPrint(Object data)
  162. {
  163. DataTable dt = new DataTable();
  164. RadioButton PRFR = (RadioButton)print.Controls["PRFR"];
  165. RadioButton PRPIC = (RadioButton)print.Controls["PRPIC"];
  166. string type;
  167. bitmaps.Clear();
  168. List<Dictionary<string, object>> parameter = new List<Dictionary<string, object>>();
  169. List<Dictionary<string, object>> barcode = new List<Dictionary<string, object>>();
  170. try
  171. {
  172. parameter = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["parameter"];
  173. barcode = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["barcode"];
  174. }
  175. catch {
  176. MessageBox.Show("打印数据异常,请联系管理员");
  177. return;
  178. }
  179. try
  180. {
  181. type = ((String)((Dictionary<string, object>)data)["type"]).Replace("\"", "");
  182. }
  183. catch
  184. {
  185. type = "no";
  186. }
  187. try
  188. {
  189. labelview = ((String)((Dictionary<string, object>)data)["label_type"]).Replace("\"", "");
  190. }
  191. catch
  192. {
  193. labelview = "";
  194. }
  195. if (PRFR.Checked)
  196. {
  197. Thread.Sleep(1000);
  198. int i = 0;
  199. while (DownLoadFile.downloading && i < 2)
  200. {
  201. Thread.Sleep(1000);
  202. i++;
  203. }
  204. if (DownLoadFile.downloading)
  205. MessageBox.Show("标签更新有误");
  206. try
  207. {
  208. BarcodeReport.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME + ".frx");
  209. }
  210. catch
  211. {
  212. MessageBox.Show("未找到可使用的标签文件,请重试");
  213. return;
  214. }
  215. }
  216. int la_width = int.Parse(parameter.First()["LA_WIDTH"].ToString());
  217. int la_height = int.Parse(parameter.First()["LA_HEIGHT"].ToString());
  218. foreach (var item in barcode)
  219. {
  220. Bitmap bit = new Bitmap(la_width * 10, la_height * 4);
  221. using (Graphics g = Graphics.FromImage(bit))
  222. {
  223. //g.CompositingQuality = CompositingQuality.HighQuality;
  224. //g.SmoothingMode = SmoothingMode.HighQuality;
  225. //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  226. ////定义一枝画笔
  227. //Pen pen = new Pen(Color.Black);
  228. ////用这个画笔在左上角画一个矩形
  229. //g.DrawRectangle(pen, new Rectangle(10, 10, 50, 20));
  230. foreach (var itemc in item)
  231. {
  232. Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
  233. if (Sidc != null)
  234. {
  235. if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
  236. {
  237. string itemstr = "";
  238. if (itemc.Value != null)
  239. {
  240. itemstr = itemc.Value.ToString();
  241. while (itemstr.StartsWith("\f") || itemstr.StartsWith("\v") || itemstr.StartsWith("\t") || itemstr.StartsWith("\r") || itemstr.StartsWith("\n"))
  242. {
  243. itemstr = itemstr.Remove(0, 2);
  244. }
  245. if (itemstr.StartsWith("\""))
  246. {
  247. itemstr = itemstr.Remove(0, 1);
  248. }
  249. while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
  250. {
  251. itemstr = itemstr.Remove(itemstr.Length - 2);
  252. }
  253. if (itemstr.EndsWith("\""))
  254. {
  255. itemstr = itemstr.Remove(itemstr.Length - 1);
  256. }
  257. if (itemstr.Contains("\\\""))
  258. {
  259. itemstr = itemstr.Replace("\\\"", "\"");
  260. }
  261. }
  262. if (PRFR.Checked)
  263. {
  264. DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
  265. if (!dt.Columns.Contains(itemc.Key))
  266. dt.Columns.Add(DC);
  267. }
  268. if (PRPIC.Checked)
  269. {
  270. PrintHelper.Printstring(itemc.Value != null ? itemstr : " ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()));
  271. }
  272. }
  273. else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
  274. {
  275. if (PRFR.Checked)
  276. {
  277. DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
  278. if (!dt.Columns.Contains(itemc.Key))
  279. dt.Columns.Add(DC);
  280. }
  281. if (PRPIC.Checked)
  282. {
  283. PrintHelper.DrawBarcode(itemc.Value != null ? itemc.Value.ToString().Replace("\"", "") : " ", ref bit, double.Parse(Sidc["LP_LEFTRATE"].ToString()), double.Parse(Sidc["LP_TOPRATE"].ToString()), double.Parse(Sidc["LP_WIDTH"].ToString()), double.Parse(Sidc["LP_HEIGHT"].ToString()) - 2);
  284. PrintHelper.Printstring(itemc.Value != null ? itemc.Value.ToString().Replace("\"", "") : " ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()) + double.Parse(Sidc["LP_HEIGHT"].ToString()) - 2);
  285. }
  286. }
  287. }
  288. }
  289. }
  290. bitmaps.Add(bit);
  291. }
  292. if (PRFR.Checked)
  293. {
  294. foreach (var item in barcode)
  295. {
  296. DataRow dr = dt.NewRow();
  297. //g.CompositingQuality = CompositingQuality.HighQuality;
  298. //g.SmoothingMode = SmoothingMode.HighQuality;
  299. //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  300. ////定义一枝画笔
  301. //Pen pen = new Pen(Color.Black);
  302. ////用这个画笔在左上角画一个矩形
  303. //g.DrawRectangle(pen, new Rectangle(10, 10, 50, 20));
  304. foreach (var itemc in item)
  305. {
  306. Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
  307. if (Sidc != null)
  308. {
  309. if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
  310. {
  311. string itemstr = "";
  312. if (itemc.Value != null)
  313. {
  314. itemstr = itemc.Value.ToString();
  315. while (itemstr.StartsWith("\f") || itemstr.StartsWith("\v") || itemstr.StartsWith("\t") || itemstr.StartsWith("\r") || itemstr.StartsWith("\n"))
  316. {
  317. itemstr = itemstr.Remove(0, 2);
  318. }
  319. if (itemstr.StartsWith("\""))
  320. {
  321. itemstr = itemstr.Remove(0, 1);
  322. }
  323. while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
  324. {
  325. itemstr = itemstr.Remove(itemstr.Length - 2);
  326. }
  327. if (itemstr.EndsWith("\""))
  328. {
  329. itemstr = itemstr.Remove(itemstr.Length - 1);
  330. }
  331. if (itemstr.Contains("\\\""))
  332. {
  333. itemstr = itemstr.Replace("\\\"", "\"");
  334. Console.WriteLine(itemstr);
  335. }
  336. }
  337. dr[itemc.Key] = itemstr;
  338. }
  339. else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
  340. {
  341. dr[itemc.Key] = itemc.Value.ToString().Replace("\"", "");
  342. }
  343. }
  344. }
  345. dt.Rows.Add(dr);
  346. }
  347. }
  348. if (PRPIC.Checked)
  349. {
  350. if (bitmaps.Count > 0)
  351. {
  352. imagecount = bitmaps.Count;
  353. print.PrintDoc.Print();
  354. }
  355. }
  356. if (PRFR.Checked)
  357. {
  358. try
  359. {
  360. if (labelview == "")
  361. {
  362. if (type == "box")
  363. {
  364. BarcodeReport.RegisterData(dt, "VENDORBARCODE_BOX_VIEW");
  365. BarcodeReport.GetDataSource("VENDORBARCODE_BOX_VIEW").Enabled = true;
  366. BarcodeReport.PrintSettings.ShowDialog = false;
  367. BarcodeReport.PrintSettings.Printer = PrinterName;
  368. BarcodeReport.Print();
  369. }
  370. else
  371. {
  372. BarcodeReport.RegisterData(dt, "VENDORBARCODE_VIEW");
  373. BarcodeReport.GetDataSource("VENDORBARCODE_VIEW").Enabled = true;
  374. BarcodeReport.PrintSettings.ShowDialog = false;
  375. BarcodeReport.PrintSettings.Printer = PrinterName;
  376. BarcodeReport.Print();
  377. }
  378. }
  379. else
  380. {
  381. BarcodeReport.RegisterData(dt, labelview);
  382. BarcodeReport.GetDataSource(labelview).Enabled = true;
  383. BarcodeReport.PrintSettings.ShowDialog = false;
  384. BarcodeReport.PrintSettings.Printer = PrinterName;
  385. BarcodeReport.Print();
  386. }
  387. }
  388. catch(Exception ex)
  389. {
  390. MessageBox.Show(ex.Message+"打印出现错误,请检查标签文件选择是否正确");
  391. }
  392. dt.Clear();
  393. }
  394. }
  395. private void PrintPage(object sender, PrintPageEventArgs e)
  396. {
  397. Image i = bitmaps[index];
  398. Graphics g = e.Graphics;
  399. g.DrawImage(i, 4, 10, i.Width, i.Height);
  400. if (index < imagecount - 1)
  401. {
  402. e.HasMorePages = true;
  403. index++;
  404. }
  405. else
  406. {
  407. index = 0;
  408. e.HasMorePages = false;
  409. }
  410. }
  411. private void RequestHandler_Click(object sender, EventArgs e)
  412. {
  413. //设置打印机名称
  414. print.PrintDoc.PrinterSettings.PrinterName = print.Controls["Printer"].Text;
  415. PrinterName = print.Controls["Printer"].Text;
  416. RadioButton PRXA = (RadioButton)print.Controls["PRXA"];
  417. RadioButton PRPIC = (RadioButton)print.Controls["PRPIC"];
  418. //获取矩阵图的分辨率
  419. Graphics gr = print.PrintDoc.PrinterSettings.CreateMeasurementGraphics();
  420. print.browser.FocusedFrame.ExecuteJavaScriptAsync("(function(value,value1){dpi=value,printType=value1})('" + gr.DpiX + "','" + PrintType + "')");
  421. if (PRXA.Checked)
  422. {
  423. print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmZplPrint').click();");
  424. }
  425. else
  426. {
  427. print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmPicturePrint').click();");
  428. }
  429. print.Close();
  430. }
  431. void filter_NotifyData(byte[] data)
  432. {
  433. if (NotifyMsg != null)
  434. {
  435. NotifyMsg(data);
  436. }
  437. }
  438. public bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
  439. {
  440. return false;
  441. }
  442. public bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect)
  443. {
  444. return false;
  445. }
  446. public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
  447. {
  448. return CefReturnValue.Continue;
  449. }
  450. public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback)
  451. {
  452. return false;
  453. }
  454. public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
  455. {
  456. return false;
  457. }
  458. public void OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath)
  459. {
  460. }
  461. public bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url)
  462. {
  463. return false;
  464. }
  465. public bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback)
  466. {
  467. return false;
  468. }
  469. public void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
  470. {
  471. }
  472. public void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser)
  473. {
  474. }
  475. public void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
  476. {
  477. }
  478. public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, ref string newUrl)
  479. {
  480. }
  481. bool IRequestHandler.OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
  482. {
  483. return false;
  484. }
  485. public void GetData()
  486. {
  487. }
  488. public static Dictionary<string, object> ToDictionary(string JsonData)
  489. {
  490. object Data = null;
  491. Dictionary<string, object> Dic = new Dictionary<string, object>();
  492. if (JsonData.StartsWith("["))
  493. {
  494. //如果目标直接就为数组类型,则将会直接输出一个Key为List的List<Dictionary<string, object>>集合
  495. //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["List"];
  496. List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
  497. MatchCollection ListMatch = Regex.Matches(JsonData, @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
  498. foreach (Match ListItem in ListMatch)
  499. {
  500. List.Add(ToDictionary(ListItem.ToString()));//递归调用
  501. }
  502. Data = List;
  503. Dic.Add("List", Data);
  504. }
  505. else
  506. {
  507. MatchCollection Match = Regex.Matches(JsonData, @"""(.+?)"": {0,1}(\[[\s\S]+?\}\s*\]|null|"".+?""(,+?)|"".+?""(\s*?)(\}+?)|-{0,1}\d*)");//使用正则表达式匹配出JSON数据中的键与值
  508. foreach (Match item in Match)
  509. {
  510. try
  511. {
  512. if (item.Groups[2].ToString().StartsWith("["))
  513. {
  514. //如果目标是数组,将会输出一个Key为当前Json的List<Dictionary<string, object>>集合
  515. //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["Json中的Key"];
  516. List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
  517. MatchCollection ListMatch = Regex.Matches(item.Groups[2].ToString(), @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
  518. foreach (Match ListItem in ListMatch)
  519. {
  520. List.Add(ToDictionary(ListItem.ToString()));//递归调用
  521. }
  522. Data = List;
  523. }
  524. else if (item.Groups[2].ToString().ToLower() == "null") Data = null;//如果数据为null(字符串类型),直接转换成null
  525. else if (item.Groups[2].ToString().EndsWith(","))
  526. Data = item.Groups[2].ToString().Remove(item.Groups[2].ToString().Length - 1); //数据为数字、字符串中的一类,则去掉,直接写入
  527. else if (item.Groups[2].ToString().EndsWith("}"))
  528. Data = item.Groups[2].ToString().Remove(item.Groups[2].ToString().Length - 1); //数据为数字、字符串中的一类,则去掉,直接写入
  529. else
  530. Data = item.Groups[2].ToString();
  531. Dic.Add(item.Groups[1].ToString(), Data);
  532. }
  533. catch { }
  534. }
  535. }
  536. return Dic;
  537. }
  538. }
  539. }