|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using CnasSynchronousCommon;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
-
- namespace CnasSynchronusDAL
- {
- public class ReadFileForth:BaseReadFileMode
- {
- public static DataTable ReadTableStructure()
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("F1");
- dt.Columns.Add("F2");
- dt.Columns.Add("F3");
- dt.Columns.Add("F4");
- dt.Columns.Add("F5");
- dt.Columns.Add("F6");
- dt.Columns.Add("F7");
- dt.Columns.Add("F8");
- dt.Columns.Add("F9");
- dt.Columns.Add("F10");
- 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++)
- {
- string strData = arryList[i].Trim();
- string[] strRowDatas = strData.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
- if (strRowDatas.Length == 10)
- {
- DataRow dr = dt.NewRow();
- dr["F1"] = strRowDatas[0].Trim();
- dr["F2"] = strRowDatas[1].Trim();
- dr["F3"] = strRowDatas[2].Trim();
- dr["F4"] = strRowDatas[3].Trim();
- dr["F5"] = strRowDatas[4].Trim();
- dr["F6"] = strRowDatas[5].Trim();
- dr["F7"] = strRowDatas[6].Trim();
- dr["F8"] = strRowDatas[7].Trim();
- dr["F9"] = strRowDatas[8].Trim();
- dr["F10"] = strRowDatas[9].Trim();
- dt.Rows.Add(dr);
- }
- }
- }
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message);
- }
- return dt;
- }
- }
- }
|