CNAS取数仪器端升级
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 5 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using CnasSynchronousCommon;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. namespace CnasSynchronusDAL
  9. {
  10. public class ReadFileFifth: BaseReadFileMode
  11. {
  12. private static int ColumnCount = 46;
  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 == 46)
  48. {
  49. DataRow dr = dt.NewRow();
  50. dr["Date"] = DateTime.Now.ToString("yyMMdd");
  51. for (int j = 0; j < strRowDatas.Length; j++)
  52. {
  53. dr[$"F{j+1}"]= strRowDatas[j].Trim();
  54. }
  55. dt.Rows.Add(dr);
  56. }
  57. }
  58. }
  59. }
  60. catch (Exception ex)
  61. {
  62. AppLog.Error(ex.Message);
  63. }
  64. return dt;
  65. }
  66. }
  67. }