using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.Data.SqlClient; using System.IO; using JTB.LOK.Batch.BLL.Common; namespace ConsoleApplication1 { class CsvRead { //private static readonly string B2B_SALES_RESULT_FACT_PATH = Constant.B2B_SALES_RESULT_FACT_PATH; //private static readonly string B2B_SYSTEM_SALES_RESULT_FILE_PATH = Constant.B2B_SYSTEM_SALES_RESULT_FILE_PATH; //private static readonly string B2B_SALES_RESULT_ERROR_FILE_PATH = Constant.B2B_SALES_RESULT_ERROR_FILE_PATH; public CsvRead() { //Hashtable hash = new Hashtable(); //GetData(hash, B2B_SALES_RESULT_FACT_PATH + @"/2.csv"); } //販売実績データ読み込み処理 private int GetData(Hashtable hash, string filepath) { //string filepath = (string)hash["filepath"]; File.OpenRead(filepath); if (File.Exists(filepath)) { List<List<SqlParameter>> dataList = new List<List<SqlParameter>>(); // Open the stream and read it back. using (FileStream fs = File.OpenRead(filepath)) { StreamReader sReader = new StreamReader(filepath); string temp; //byte[] b = new byte[1024]; //UTF8Encoding temp = new UTF8Encoding(true); string[] strTitle = null; int row = 0; List<SqlParameter> dtlist = new List<SqlParameter>(); do { temp = sReader.ReadLine(); if (temp != null) { List<SqlParameter> list = new List<SqlParameter>(); if (row == 0) { strTitle = temp.Split(','); } else { string[] str = temp.Split(','); for (int i = 0; i < str.Length; i++) { SqlParameter sp = new SqlParameter(strTitle[i], str[i]); list.Add(sp); dataList.Add(dtlist); } } row++; } } while (temp != null); } hash["dataList"] = dataList; } return 0; } 未取込ファイル名取得処理 //private int GetFileName(Hashtable hash) //{ // string filepath = ""; // int n = 0; // try // { // DirectoryInfo dir = new DirectoryInfo(@"d:/"); // //最も日付の古いファイル名の判断 // foreach (FileInfo f in dir.GetFiles("drsum_*.csv")) // { // string temp = (f.Name).Substring(6, 8); // if (n == 0) // n = int.Parse(temp); // if (n > int.Parse(temp)) // n = int.Parse(temp); // } // //未取込ファイルのパス取得 // filepath = @"d:/" + "drsum_" + n.ToString() + ".csv"; // } // catch (Exception e) // { // return 1; // } // //ファイルのきほんぞくせい取得 // FileInfo fileinfo = new FileInfo(filepath); // if (!fileinfo.Exists) // { // hash["messageId"] = Constant.EXIST_FOLDER_ERR_MESSAGE_NO; // hash["messageDetail"] = filepath; // return 1; // } // hash["filepath"] = filepath; // //未取込ファイル名取得 // hash["filename"] = "drsum_" + n.ToString() + ".csv"; // return 0; //} } }