//读取GameEvent表; void readGameEvent() { // Read sample data from CSV file using (ReadWriteCsv.CsvFileReader reader = new ReadWriteCsv.CsvFileReader("D://GameEvent.CSV")) { ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow(); int i = 1; while (reader.ReadRow(row)) { Model.GameEvent temp = new Model.GameEvent(); if (i > 4) { temp.id = row[0]; temp.eventSign = row[1]; int.TryParse(row[2], out temp.eventType); temp.eventName = row[3]; temp.eventTalk = row[4]; temp.eventRoles = row[5]; gEvent.Add(temp); } i++; } } }
void readGameTalk() { using (ReadWriteCsv.CsvFileReader reader = new ReadWriteCsv.CsvFileReader("D://GameTalk.CSV")) { ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow(); int i = 1; while (reader.ReadRow(row)) { Model.GameTalk temp = new Model.GameTalk(); if (i > 4) { temp.id = row[0]; //int.TryParse(row[1], out temp.ResultType); temp.TalkGroup = row[1]; temp.TalkRole = row[2]; int.TryParse(row[3], out temp.RoleHead); temp.EventName = row[4]; temp.TalkSelect = row[5]; gTalk.Add(temp); } i++; } } }
//static void Main(string[] args) //{ // CsvRow row = new CsvRow(); // CsvFileReader reader = new CsvFileReader("C:\\temp\\XICData.csv"); // while (reader.ReadRow(row)) // { // Console.Out.WriteLine(row[0] + " -> " + row[1]); // } // Console.Read(); //} static void Main(string[] args) { List<XICDataPoint> xicData = new List<XICDataPoint>(); CsvRow row = new CsvRow(); CsvFileReader reader = new CsvFileReader("C:\\temp\\XICData.csv"); while (reader.ReadRow(row)) { Console.Out.WriteLine(row[0] + " -> " + row[1]); int scanNumber; double intensity; if (int.TryParse(row[0], out scanNumber) && double.TryParse(row[1], out intensity)) xicData.Add(new XICDataPoint { scanNumber = scanNumber, intensity = intensity }); } PeakFinder finder = new PeakFinder(); foreach (var peakData in finder.GetPeaks(xicData)) { Console.Out.WriteLine(peakData.startScan + " -> " , peakData.endScan); foreach (var intensity in peakData.intensityValues) { Console.Out.WriteLine("Intensity = " + intensity); } } Console.Read(); }
void readGameMonster() { using (ReadWriteCsv.CsvFileReader reader = new ReadWriteCsv.CsvFileReader("D://GameMonster.CSV")) { ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow(); int i = 1; while (reader.ReadRow(row)) { Model.GameMonster temp = new Model.GameMonster(); if (i > 4) { temp.id = row[0]; temp.MonsterName = row[1]; int.TryParse(row[2], out temp.TypeID); temp.TeamHeadIcon = row[3]; int.TryParse(row[4], out temp.BaseLife); int.TryParse(row[5], out temp.BaseDef); int.TryParse(row[6], out temp.BaseAct); float.TryParse(row[7], out temp.AttrProp); mEvent.Add(temp); } i++; } } }
void readGamePartner() { using (ReadWriteCsv.CsvFileReader reader = new ReadWriteCsv.CsvFileReader("D://GamePartner.CSV")) { ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow(); int i = 1; while (reader.ReadRow(row)) { Model.GamePartner temp = new Model.GamePartner(); if (i > 4) { temp.id = row[0]; //int.TryParse(row[1], out temp.ResultType); temp.PartnerName = row[1]; int.TryParse(row[2], out temp.TypeId); int.TryParse(row[3], out temp.BaseLife); int.TryParse(row[4], out temp.BaseDef); int.TryParse(row[5], out temp.BaseAct); float.TryParse(row[6], out temp.TalentProp); gPartner.Add(temp); } i++; } } }
public static string kToSqlCreateTable(string tblFileName, string csvFilePath) { string cmdText = string.Empty; using (CsvFileReader reader = new CsvFileReader(csvFilePath)) { CsvRow row = new CsvRow(); bool isHeader = true; string tTblFile = tblFileName.Substring(0, tblFileName.IndexOf("_")); Console.WriteLine("c o d i n g . . . t r a n s c o d i n g . . . t r a n s . . . . . "); cmdText += string.Format("DROP TABLE IF EXISTS `{0}`;", tTblFile) + Environment.NewLine; cmdText += string.Format("CREATE TABLE IF NOT EXISTS `{0}` (", tTblFile) + Environment.NewLine; while (reader.ReadRow(row)) { if (isHeader) { isHeader = false; continue; } string tRowType = kToMySQLTypeStatement(row); cmdText += "\t" + (tRowType.Equals(",") ? "" : tRowType) + Environment.NewLine; } cmdText = cmdText.Remove(cmdText.LastIndexOf(","), 1); cmdText += ") ENGINE=InnoDB DEFAULT CHARSET=utf8;" + Environment.NewLine; Console.WriteLine(cmdText); Console.WriteLine("DONE !!!"); reader.Close(); } return cmdText; }
public void import(string fileName, int headerRow) { List<string> columns = new List<string>(); List<Dictionary<string, string>> rows = new List<Dictionary<string,string>>(); // Read sample data from CSV file using (CsvFileReader reader = new CsvFileReader(fileName)) { int lineNumber = 0; CsvRow row = new CsvRow(); while (reader.ReadRow(row)) { if (lineNumber == headerRow) { // Read Header Values foreach (string s in row) { columns.Add(s.Replace(" ", "")); } } else if (lineNumber > headerRow) { int columnIndex = 0; Dictionary<string, string> dataRow = new Dictionary<string,string>(); foreach (string s in row) { dataRow.Add(columns[columnIndex], s); ++columnIndex; } rows.Add(dataRow); } ++lineNumber; } } // Output using code generator // IList<BusinessRule> rules = new List<BusinessRule>(); // rules.Add(new BusinessRule // { // ErrorCode = "AIRBR1001", // RuleNumber = "1095C-006", // Description = "Form 1095C 'TINRequestTypeCd' in 'EmployeeInfoGrp' must have a value equal to 'INDIVIDUAL_TIN'.", // ErrorCategory = "Incorrect Data", // Severity = "Report Error", // Status = "Active" // }); CodeCompileUnit code = new CodeCompileUnit(); CodeNamespace namespaces = new CodeNamespace(); namespaces.Imports.Add(new CodeNamespaceImport("System")); }
public static void kToSqlCreateTable(string tblsFile, string sqlFile = cSqlCreateTblScriptFile) { string tSqlFile = string.Format("{0}k{1}.{2}", cScriptHomePath, sqlFile, cSqlFileExt); SqlScriptLogger scriptLogger = new SqlScriptLogger(tSqlFile); scriptLogger.kWriteLine("USE akm_m6dtx;" + Environment.NewLine); Console.WriteLine(string.Format("Creating {0} . . .", tSqlFile)); string tCsvFile = string.Format("{0}{1}_{2}.{3}", cDataHomePath, tblsFile, cDataPostfix, cCsvFileExt); CsvFileReader reader = new CsvFileReader(tCsvFile); Console.WriteLine(string.Format("Opening {0} . . .", tCsvFile)); Console.WriteLine("[Press the ENTER key to begin . . .]"); Console.ReadKey(); CsvRow row = new CsvRow(); bool isHeader = true; while (reader.ReadRow(row)) { if (isHeader) { isHeader = false; continue; } foreach (string tblSchema in row) { string script = string.Empty; try { string tTblSchemaFile = string.Format("{0}_{1}", tblSchema, cSchemaPostfix); scriptLogger.kWriteLineHeader(tblSchema); scriptLogger.kWriteLine(2); scriptLogger.kWriteLine(SqlScriptTrans.kToSqlCreateTable(tTblSchemaFile, string.Format("{0}{1}.{2}", cDataHomePath, tTblSchemaFile, cCsvFileExt))); scriptLogger.kWriteLine(2); scriptLogger.kWriteLineFooter(); } catch (FileNotFoundException) { scriptLogger.kWriteLine("## [ERROR::" + tblSchema + "] The table does not exists in the database."); continue; } scriptLogger.kWriteLine(4); } } reader.Close(); scriptLogger.kClose(); }
public void Test() { using (CsvFileReader reader = new CsvFileReader(HttpContext.Current.Server.MapPath("~/SyncFiles/clb_20140825_1134.CSV"))) { CsvRow row = new CsvRow(); while (reader.ReadRow(row)) { foreach (string s in row) { Console.Write(s); Console.Write(" "); } Console.WriteLine(); } } }
public static void kToSqlInsert(string tblsFile, string sqlFile = cSqlInsertScriptFile) { string tSqlFile = string.Format("{0}{1}.{2}", cScriptHomePath, sqlFile, cSqlFileExt); // Console.WriteLine(string.Format("Creating {0} . . .", tSqlFile)); string tCsvFile = string.Format("{0}{1}_{2}.{3}", cDataHomePath, tblsFile, cDataPostfix, cCsvFileExt); CsvFileReader reader = new CsvFileReader(tCsvFile); Console.WriteLine(string.Format("Opening {0} . . .", tCsvFile)); Console.WriteLine("[Press the ENTER key to begin . . .]"); Console.ReadKey(); CsvRow row = new CsvRow(); bool isHeader = true; while (reader.ReadRow(row)) { if (isHeader) { isHeader = false; continue; } foreach (string tblName in row) { string tTblDataFile = string.Format("{0}_{1}.{2}", tblName, cDataPostfix, cCsvFileExt); try { SqlScriptTrans.kToSqlInsertTable(tTblDataFile, string.Format("{0}{1}", cDataHomePath, tTblDataFile)); } catch (FileNotFoundException) { Console.WriteLine("[ERROR::" + tblName + "]Reading a non-existent physical database table."); continue; } } } reader.Close(); }
void readGameBattle() { using (ReadWriteCsv.CsvFileReader reader = new ReadWriteCsv.CsvFileReader("D://GameBattle.CSV")) { ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow(); int i = 1; while (reader.ReadRow(row)) { Model.GameBattle temp = new Model.GameBattle(); if (i > 4) { temp.id = row[0]; //int.TryParse(row[1], out temp.ResultType); temp.BattleObject = row[1]; temp.BattleWise = row[2]; gBattle.Add(temp); } i++; } } }
void readTalkResult() { using (ReadWriteCsv.CsvFileReader reader = new ReadWriteCsv.CsvFileReader("D://TalkResult.CSV")) { ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow(); int i = 1; while (reader.ReadRow(row)) { Model.TalkResult temp = new Model.TalkResult(); if (i > 4) { temp.id = row[0]; int.TryParse(row[1], out temp.ResultType); temp.ResultName = row[2]; temp.EventTalk = row[3]; temp.EventGroup = row[4]; talkR.Add(temp); } i++; } } }
//static void Main(string[] args) //{ // var client = new JsonServiceClient("http://sactmoapp5.azurewebsites.net/api"); // TestData data = new TestData{ paramName ="param1", paramValue = 10}; // TestResponse res = client.Post(data); // Console.Out.WriteLine(res.valueName + " : " + res.value); // Console.Read(); //} static void Main(string[] args) { //var client = new JsonServiceClient("http://sactmoapp5.azurewebsites.net/api"); var client = new JsonServiceClient("http://localhost:58518//api"); //TestData data = new TestData { paramName = "param1", paramValue = 10 }; //TestResponse res = client.Post(data); List<XICDataPoint> xicData = new List<XICDataPoint>(); CsvRow row = new CsvRow(); CsvFileReader reader = new CsvFileReader("C:\\temp\\XICData.csv"); while (reader.ReadRow(row)) { Console.Out.WriteLine(row[0] + " -> " + row[1]); int scanNumber; double intensity; if (int.TryParse(row[0], out scanNumber) && double.TryParse(row[1], out intensity)) xicData.Add(new XICDataPoint { scanNumber = scanNumber, intensity = intensity }); } PeakFinderInput input = new PeakFinderInput { xicData = xicData }; PeakFinderOutput res = client.Post(input); foreach (var peakData in res.peaklist) { Console.Out.WriteLine(peakData.startScan + " -> ", peakData.endScan); foreach (var intensity in peakData.intensityValues) { Console.Out.WriteLine("Intensity = " + intensity); } } Console.Read(); }
private void ReadTotalLoadsRload() { // Read sample data from CSV file using(CsvFileReader reader = new CsvFileReader(_fileTotalLoadsRload)) { Application.DoEvents(); CsvRow row = new CsvRow(); if(reader.ReadRow(row)) { //foreach (String s in row) //{ // dgvDados.Columns.Add(s, s); //} } while(reader.ReadRow(row) /*&& i < limitValues*/) { _SourceTotalLoadsRload.Add(new Source.citTotalLoadsRload(row)); } var query = _SourceTotalLoadsRload.GroupBy(x => x.KycrspFundno, (k, g) => g.Aggregate((a, x) => (x.RearLoad > a.RearLoad) ? x : a)); _SourceTotalLoadsRload = query.ToList(); dgvTotalLoadsRload.DataSource = _SourceTotalLoadsRload; } }
void ReadTestFDO() { //dgvDados.Columns.Clear(); // Read sample data from CSV file using (CsvFileReader reader = new CsvFileReader(_file)) { Application.DoEvents(); CsvRow row = new CsvRow(); if (reader.ReadRow(row)) { } int i = 0; while (reader.ReadRow(row) /*&& i < limitValues*/) { DadosAddLineFOD(row); // adiciona uma linha à grelha i++; } } }
public static void kToSqlInsertTable(string tblFileName, string csvFilePath) { string cmdText = string.Empty; using (CsvFileReader reader = new CsvFileReader(csvFilePath)) { CsvRow row = new CsvRow(); bool isHeader = true; string tTblName = tblFileName.Substring(0, tblFileName.LastIndexOf("_data")); string tblFilePath = string.Format("{0}k{1}.{2}", SqlScriptGen.cScriptHomePath, tTblName, SqlScriptGen.cSqlFileExt); SqlScriptLogger scriptLogger = new SqlScriptLogger(tblFilePath); scriptLogger.kWriteLine("USE akm_m6dtx;" + Environment.NewLine); scriptLogger.kWriteLineHeader(tblFileName); scriptLogger.kWriteLine(2); cmdText = string.Format("INSERT INTO {0} (", tTblName) + Environment.NewLine; while (reader.ReadRow(row)) { string insertCmd = string.Empty; /** * Filter the columns of the table and translate to its template header script. */ if (isHeader) { isHeader = false; row.ForEach(col => { cmdText += string.Format("`{0}`,", col); }); cmdText = cmdText.Remove(cmdText.LastIndexOf(","), 1); cmdText += ") VALUES (" + Environment.NewLine; } else { insertCmd = cmdText; foreach (string col in row) { // TODO: Improve filtering by using Regex if ((col.IndexOf("AM") > 0 || col.IndexOf("PM") > 0) && col.IndexOf(@"/") > 0 && col.IndexOf(@":") > 0) { insertCmd += string.Format(@"STR_TO_DATE('{0}', '%m/%d/%Y %l:%i:%s %p'),", col); } else insertCmd += string.Format("\t'{0}',", col.Replace('\'', '^')) + Environment.NewLine; } insertCmd = insertCmd.Remove(insertCmd.LastIndexOf(","), 1); insertCmd += Environment.NewLine + ");"; Console.Write("c o d i n g . . . t r a n s c o d i n g . . . t r a n s . . . . . "); scriptLogger.kWriteLine(insertCmd); Console.WriteLine("DONE !!!"); } } scriptLogger.kWriteLine(2); scriptLogger.kWriteLineFooter(); scriptLogger.kClose(); reader.Close(); } }
private void ReadExpensiveTurnoverFee() { // Read sample data from CSV file using(CsvFileReader reader = new CsvFileReader(_fileExpenseTurnoverFee)) { Application.DoEvents(); CsvRow row = new CsvRow(); if(reader.ReadRow(row)) { //foreach (String s in row) //{ // dgvDados.Columns.Add(s, s); //} } while(reader.ReadRow(row) /*&& i < limitValues*/) { _SourceExpensiveTurnoverFee.Add(new Source.citExpenseTurnoverFee(row)); Console.WriteLine(row[0]); } dgvExpenseTurnoverFee.DataSource = _SourceExpensiveTurnoverFee; } }
private void ReadModeloC() { // Read sample data from CSV file using (CsvFileReader reader = new CsvFileReader(_fileModeloC)) { Application.DoEvents(); CsvRow row = new CsvRow(); if (reader.ReadRow(row)) { //foreach (String s in row) //{ // dgvDados.Columns.Add(s, s); //} } while (reader.ReadRow(row) /*&& i < limitValues*/) { _SourceModeloC.Add(new Source.citModeloC(row)); } dgvModeloC.DataSource = _SourceModeloC; } }