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