CNAS取数仪器端升级
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.8KB

  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 ReadFileForth:BaseReadFileMode
  11. {
  12. public static DataTable ReadTableStructure()
  13. {
  14. DataTable dt = new DataTable();
  15. dt.Columns.Add("F1");
  16. dt.Columns.Add("F2");
  17. dt.Columns.Add("F3");
  18. dt.Columns.Add("F4");
  19. dt.Columns.Add("F5");
  20. dt.Columns.Add("F6");
  21. dt.Columns.Add("F7");
  22. dt.Columns.Add("F8");
  23. dt.Columns.Add("F9");
  24. dt.Columns.Add("F10");
  25. return dt;
  26. }
  27. internal static DataTable ReadTableData(string strFilePath)
  28. {
  29. DataTable dt = ReadTableStructure();
  30. try
  31. {
  32. List<string> arryList = new List<string>();
  33. if (File.Exists(strFilePath))
  34. {
  35. FileStream fileStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
  36. StreamReader _StreamReaderKey = new StreamReader(fileStream, GetType(strFilePath));
  37. string strLine = "";
  38. while (!string.IsNullOrEmpty((strLine = _StreamReaderKey.ReadLine())))
  39. {
  40. arryList.Add(strLine);
  41. }
  42. fileStream.Close();
  43. }
  44. if (arryList.Count > 0)
  45. {
  46. for (int i = 0; i < arryList.Count; i++)
  47. {
  48. string strData = arryList[i].Trim();
  49. string[] strRowDatas = strData.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
  50. if (strRowDatas.Length == 10)
  51. {
  52. DataRow dr = dt.NewRow();
  53. dr["F1"] = strRowDatas[0].Trim();
  54. dr["F2"] = strRowDatas[1].Trim();
  55. dr["F3"] = strRowDatas[2].Trim();
  56. dr["F4"] = strRowDatas[3].Trim();
  57. dr["F5"] = strRowDatas[4].Trim();
  58. dr["F6"] = strRowDatas[5].Trim();
  59. dr["F7"] = strRowDatas[6].Trim();
  60. dr["F8"] = strRowDatas[7].Trim();
  61. dr["F9"] = strRowDatas[8].Trim();
  62. dr["F10"] = strRowDatas[9].Trim();
  63. dt.Rows.Add(dr);
  64. }
  65. }
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. AppLog.Error(ex.Message);
  71. }
  72. return dt;
  73. }
  74. }
  75. }