Form4.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using NPOI.HSSF.UserModel;
  2. using NPOI.SS.UserModel;
  3. using NPOI.XSSF.UserModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. using UMESDLLService;
  17. namespace FileWatcher
  18. {
  19. public partial class Form4 : Form
  20. {
  21. public Form4()
  22. {
  23. InitializeComponent();
  24. }
  25. private void label12_Click(object sender, EventArgs e)
  26. {
  27. }
  28. private void textBox7_TextChanged(object sender, EventArgs e)
  29. {
  30. }
  31. private void textBox3_TextChanged(object sender, EventArgs e)
  32. {
  33. }
  34. //DataHelper dh = new DataHelper();
  35. private void Form4_Load(object sender, EventArgs e)
  36. {
  37. //Regex re = new Regex("\\d+.\\d+");
  38. //Console.WriteLine(re.Match(". 67.9\u001bENTER").Value);
  39. ////Regex re = new Regex("\\d+.\\w+");
  40. //Console.WriteLine(re.Match("2540.0").Value); ;
  41. ////WebClient wc = new WebClient();
  42. string json = "";
  43. string json1 = "";
  44. MESHelper mes = new MESHelper();
  45. mes.GetMEIOrNetCodeRange(null, "354904108016523", "", out json1, out json);
  46. //mes.GetMobileAllInfo("F45112235030001", out json1, out json);
  47. //Console.WriteLine(mes.CheckRoutePassed("S558B231013033559", "IMEI-01", out json));
  48. //Console.WriteLine(mes.GetMEIOrNetCodeRange(null, "352977841215497", null, out json1, out json));
  49. Console.WriteLine(json);
  50. //mes.CheckRoutePassed( "204295638R002314", "ZZ_01_ATI", out json);
  51. //Console.WriteLine(mes.SetMobileData("F5KKX2335053623", "F5KKX2335053623", "IMEI-01","IMEI-01","OK","","", out json));
  52. //Console.WriteLine(json);
  53. //string[] sss = new string[] { "F5KKX2335069950", "F5KKX2335069028", "F5KKX2335021555", "F5KKX2335111850", "F5KKX2335019799", "F5KKX2335111166", "F5KKX2335110438", "F5KKX2335045369" };
  54. //for (int i = 0; i < sss.Length; i++)
  55. //{
  56. // string rr = "";
  57. // string sn = sss[i];
  58. // mes.GetMEIOrNetCodeRange(sn, "", "", out rr, out json);
  59. // string[] str = rr.Split('^');
  60. // string IMEI1 = str[0].Replace("IMEI1:", "");
  61. // string IMEI2 = str[1].Replace("IMEI2:", "");
  62. // string PSN = str[4].Replace("PSN:", "");
  63. // mes.SetIMEIInfo(sn, IMEI1, IMEI2, "", "", "", "", "", "", out json);
  64. // mes.GetAddressRangeByMO(sn, out rr, out json);
  65. // string[] str1 = rr.Split('^');
  66. // string MAC = str1[1].Replace("BT:", "");
  67. // mes.SetAddressInfo(sn, "", MAC, "", "", "", out json);
  68. // mes.SetMobileData(sn, sn, "IMEI-01", "zhangz", "OK", "", "", out json);
  69. // Console.WriteLine(json);
  70. //}
  71. }
  72. public static string ToUrlEncode(string strCode)
  73. {
  74. StringBuilder sb = new StringBuilder();
  75. byte[] byStr = System.Text.Encoding.UTF8.GetBytes(strCode); //默认是System.Text.Encoding.Default.GetBytes(str)
  76. System.Text.RegularExpressions.Regex regKey = new System.Text.RegularExpressions.Regex("^[A-Za-z0-9]+$");
  77. for (int i = 0; i < byStr.Length; i++)
  78. {
  79. string strBy = Convert.ToChar(byStr[i]).ToString();
  80. if (regKey.IsMatch(strBy))
  81. {
  82. //是字母或者数字则不进行转换
  83. sb.Append(strBy);
  84. }
  85. else
  86. {
  87. sb.Append(@"%" + Convert.ToString(byStr[i], 16));
  88. }
  89. }
  90. return (sb.ToString());
  91. }
  92. private void textBox4_TextChanged(object sender, EventArgs e)
  93. {
  94. }
  95. private void SaveFileToJPG(string filename)
  96. {
  97. DataHelper dh = new DataHelper();
  98. DataTable dt = ExcelToDataTable(filename, true);
  99. for (int i = 0; i < dt.Rows.Count; i++)
  100. {
  101. string sql = "insert into deviceproduct(dp_id,dp_prodcode,dp_decode)values(deviceproduct_seq.nextval,'" + dt.Rows[i]["dp_prodcode"].ToString() + "','" + dt.Rows[i]["de_code"].ToString() + "')";
  102. dh.ExecuteSql(sql, "insert");
  103. }
  104. }
  105. public static DataTable ExcelToDataTable(string filePath, bool isColumnName)
  106. {
  107. DataTable dataTable = null;
  108. FileStream fs = null;
  109. DataColumn column = null;
  110. DataRow dataRow = null;
  111. IWorkbook workbook = null;
  112. ISheet sheet = null;
  113. IRow row = null;
  114. ICell cell = null;
  115. int startRow = 0;
  116. try
  117. {
  118. using (fs = File.OpenRead(filePath))
  119. {
  120. // 2007版本
  121. if (filePath.IndexOf(".xlsx") > 0)
  122. {
  123. workbook = new XSSFWorkbook(fs);
  124. }
  125. // 2003版本
  126. else if (filePath.IndexOf(".xls") > 0)
  127. {
  128. workbook = new HSSFWorkbook(fs);
  129. }
  130. if (workbook != null)
  131. {
  132. sheet = workbook.GetSheetAt(0);//读取第一个sheet,当然也可以循环读取每个sheet
  133. dataTable = new DataTable();
  134. if (sheet != null)
  135. {
  136. int rowCount = sheet.LastRowNum;//总行数
  137. if (rowCount > 0)
  138. {
  139. IRow firstRow = sheet.GetRow(0);//第一行
  140. int cellCount = firstRow.LastCellNum;//列数
  141. //构建datatable的列
  142. if (isColumnName)
  143. {
  144. startRow = 1;//如果第一行是列名,则从第二行开始读取
  145. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  146. {
  147. cell = firstRow.GetCell(i);
  148. if (cell != null)
  149. {
  150. if (cell.StringCellValue != null)
  151. {
  152. column = new DataColumn(cell.StringCellValue);
  153. dataTable.Columns.Add(column);
  154. }
  155. }
  156. }
  157. }
  158. else
  159. {
  160. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  161. {
  162. column = new DataColumn("column" + (i + 1));
  163. dataTable.Columns.Add(column);
  164. }
  165. }
  166. //填充行
  167. for (int i = startRow; i <= rowCount; ++i)
  168. {
  169. row = sheet.GetRow(i);
  170. if (row == null) continue;
  171. dataRow = dataTable.NewRow();
  172. for (int j = row.FirstCellNum; j < cellCount; ++j)
  173. {
  174. cell = row.GetCell(j);
  175. if (cell == null)
  176. {
  177. dataRow[j] = "";
  178. }
  179. else
  180. {
  181. //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
  182. switch (cell.CellType)
  183. {
  184. case CellType.Blank:
  185. dataRow[j] = "";
  186. break;
  187. case CellType.Numeric:
  188. short format = cell.CellStyle.DataFormat;
  189. //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
  190. if (format == 14 || format == 31 || format == 57 || format == 58)
  191. dataRow[j] = cell.DateCellValue;
  192. else
  193. dataRow[j] = cell.NumericCellValue;
  194. break;
  195. case CellType.String:
  196. dataRow[j] = cell.StringCellValue;
  197. break;
  198. case CellType.Formula:
  199. dataRow[j] = cell.StringCellValue;
  200. break;
  201. }
  202. }
  203. }
  204. dataTable.Rows.Add(dataRow);
  205. }
  206. }
  207. }
  208. }
  209. }
  210. return dataTable;
  211. }
  212. catch (Exception)
  213. {
  214. if (fs != null)
  215. {
  216. fs.Close();
  217. }
  218. return null;
  219. }
  220. }
  221. }
  222. }