CNAS取数仪器端升级
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

4 miesięcy temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using System.IO;
  7. using CnasSynchronousCommon;
  8. namespace CnasSynchronusDAL
  9. {
  10. public class ReadFileThirdth : BaseReadFileMode
  11. {
  12. private static int ColumnCount = 10;
  13. public static DataTable ReadTableStructure()
  14. {
  15. DataTable dt = new DataTable();
  16. dt.Columns.Add("Date");
  17. for (int i = 0; i < ColumnCount; i++)
  18. {
  19. dt.Columns.Add($"F{i + 1}");
  20. }
  21. return dt;
  22. }
  23. internal static DataTable ReadTableData(string strFilePath)
  24. {
  25. DataTable dt = ReadTableStructure();
  26. try
  27. {
  28. List<string> arryList = new List<string>();
  29. if (File.Exists(strFilePath))
  30. {
  31. FileStream fileStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
  32. StreamReader _StreamReaderKey = new StreamReader(fileStream, GetType(strFilePath));
  33. string strLine = "";
  34. while (!string.IsNullOrEmpty((strLine = _StreamReaderKey.ReadLine())))
  35. {
  36. arryList.Add(strLine);
  37. }
  38. fileStream.Close();
  39. }
  40. if (arryList.Count > 0)
  41. {
  42. for (int i = 0; i < arryList.Count; i++)
  43. {
  44. if (i == 0) continue; //第一行不是数据行
  45. string strData = arryList[i].Trim();
  46. string[] strRowDatas = strData.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  47. if (strRowDatas.Length == 10)
  48. {
  49. DataRow dr = dt.NewRow();
  50. DateTime dtTime = DateTime.ParseExact(string.Concat(strFilePath.Substring(strFilePath.Length - 21, 21).Take(14)), "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true));
  51. dr["Date"] = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
  52. for (int j = 0; j < strRowDatas.Length; j++)
  53. {
  54. dr[$"F{j + 1}"] = strRowDatas[j].Trim();
  55. }
  56. dt.Rows.Add(dr);
  57. }
  58. if (strRowDatas.Length == 9) //内容中可能存在数据连接在一起的情况
  59. {
  60. DataRow dr = dt.NewRow();
  61. DateTime dtTime = DateTime.ParseExact(string.Concat(strFilePath.Substring(strFilePath.Length - 21, 21).Take(14)), "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true));
  62. dr["Date"] = dtTime.ToString("yyyy-MM-dd HH:mm:ss");
  63. int index = 0;
  64. for (int j = 0; j < strRowDatas.Length; j++)
  65. {
  66. string strCurrentString = strRowDatas[j].Trim();
  67. if (System.Text.RegularExpressions.Regex.IsMatch(strCurrentString, @"[\u4e00-\u9fa5]"))
  68. {
  69. var strArray = strCurrentString.ToCharArray();
  70. string strString = "";
  71. for (int indexs = 0; indexs < strArray.Length; indexs++)
  72. {
  73. if (strArray[indexs] >= 0x4e00 && strArray[indexs] <= 0x9fa5)
  74. break;
  75. strString += strArray[indexs];
  76. }
  77. dr[$"F{index + 1}"] = strString;
  78. index++;
  79. dr[$"F{index + 1}"]=strCurrentString.Replace(strString,"").Trim();
  80. index++;
  81. }
  82. else
  83. {
  84. dr[$"F{index + 1}"] = strRowDatas[j].Trim();
  85. index++;
  86. }
  87. }
  88. dt.Rows.Add(dr);
  89. }
  90. }
  91. }
  92. }
  93. catch (Exception ex)
  94. {
  95. AppLog.Error(ex.Message);
  96. }
  97. return dt;
  98. }
  99. }
  100. }