CNAS取数仪器端升级
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReadFileThird.cs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 ReadFileThird: BaseReadFileMode
  11. {
  12. public static DataTable ReadTableStructure()
  13. {
  14. DataTable dt = new DataTable();
  15. dt.Columns.Add("称号");
  16. dt.Columns.Add("速度");
  17. dt.Columns.Add("毛重");
  18. dt.Columns.Add("皮重");
  19. dt.Columns.Add("载重");
  20. dt.Columns.Add("净重");
  21. dt.Columns.Add("路损");
  22. dt.Columns.Add("盈亏");
  23. dt.Columns.Add("时间");
  24. return dt;
  25. }
  26. internal static DataTable ReadTableData(string strFilePath)
  27. {
  28. DataTable dt = ReadTableStructure();
  29. try
  30. {
  31. List<string> arryList = new List<string>();
  32. if (File.Exists(strFilePath))
  33. {
  34. FileStream fileStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
  35. StreamReader _StreamReaderKey = new StreamReader(fileStream, GetType(strFilePath));
  36. string strLine = "";
  37. while (!string.IsNullOrEmpty((strLine = _StreamReaderKey.ReadLine())))
  38. {
  39. arryList.Add(strLine);
  40. }
  41. fileStream.Close();
  42. }
  43. if (arryList.Count > 0)
  44. {
  45. for (int i = 0; i < arryList.Count; i++)
  46. {
  47. string strData = arryList[i].Trim();
  48. string[] strRowDatas = strData.Split(new string[] { ""},StringSplitOptions.RemoveEmptyEntries);
  49. if (strRowDatas.Length == 14)
  50. {
  51. DataRow dr = dt.NewRow();
  52. dr["入厂批次号"] = arryList[0].Trim();
  53. dr["录入时间"] = arryList[2].Trim();
  54. dr["录入人"] = arryList[4].Trim();
  55. dr["车厢总数"] = arryList[7].Trim();
  56. dr["车厢序号"] = strRowDatas[0];
  57. dr["车厢型号"] = strRowDatas[1];
  58. dr["车厢编码"] = strRowDatas[2];
  59. dr["毛重"] = strRowDatas[3];
  60. dr["皮重"] = strRowDatas[4];
  61. dr["标重"] = strRowDatas[5];
  62. dr["净重"] = strRowDatas[6];
  63. dr["车速"] = strRowDatas[7];
  64. dr["运损"] = strRowDatas[8];
  65. dt.Rows.Add(dr);
  66. }
  67. }
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. AppLog.Error(ex.Message);
  73. }
  74. return dt;
  75. }
  76. }
  77. }