|
- using CnasSynchronousCommon;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
-
- namespace CnasSynchronusDAL
- {
- public class ReadFileFifth: BaseReadFileMode
- {
- private static int ColumnCount = 46;
- public static DataTable ReadTableStructure()
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("Date");
- for (int i = 0; i < ColumnCount; i++)
- {
- dt.Columns.Add($"F{i+1}");
- }
- return dt;
- }
-
- internal static DataTable ReadTableData(string strFilePath)
- {
- DataTable dt = ReadTableStructure();
- try
- {
- List<string> arryList = new List<string>();
- if (File.Exists(strFilePath))
- {
- FileStream fileStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
- StreamReader _StreamReaderKey = new StreamReader(fileStream, GetType(strFilePath));
- string strLine = "";
- while (!string.IsNullOrEmpty((strLine = _StreamReaderKey.ReadLine())))
- {
- arryList.Add(strLine);
- }
-
- fileStream.Close();
- }
-
- if (arryList.Count > 0)
- {
- for (int i = 0; i < arryList.Count; i++)
- {
- if (i == 0) continue; //第一行不是数据行
-
- string strData = arryList[i].Trim();
- string[] strRowDatas = strData.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- if (strRowDatas.Length == 46)
- {
- DataRow dr = dt.NewRow();
- dr["Date"] = DateTime.Now.ToString("yyMMdd");
- for (int j = 0; j < strRowDatas.Length; j++)
- {
- dr[$"F{j+1}"]= strRowDatas[j].Trim();
- }
- dt.Rows.Add(dr);
- }
- }
- }
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message);
- }
- return dt;
- }
- }
- }
|