protected override void OnSaving() { this.DataKey = TheDate.ToString("yyyyMMdd"); this.TheYear = TheDate.Year; this.TheMonth = TheDate.Month; this.TheDay = TheDate.Day; this.WeekDay = TheDate.DayOfWeek; this.Quarter = (季度)((TheDate.Month - 1) / 3); this.WeekOfYear = myCI.Calendar.GetWeekOfYear(TheDate, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday); this.DayOfYear = myCI.Calendar.GetDayOfYear(TheDate); this.SemiYearly = TheMonth > 7 ? 半年.半年 : 半年.半年; var t = this.TheDay; if (t > 30) { t = 30; } this.PeriodOfTenDays = (月旬)((t - 1) / 10); base.OnSaving(); }
public static void BSEParser(string InputPath) { if (File.Exists(InputPath)) { //InputPath = @"D:\Desktop\StockData\BSE-Equity\20170925.csv"; string OutputPath = Path.GetDirectoryName(InputPath) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(InputPath) + "_output.csv"; using (var sr = new StreamReader(InputPath)) { using (var sw = new StreamWriter(OutputFile)) { var reader = new CsvReader((IParser)sr); var writer = new CsvWriter((ISerializer)sw); DateTime TheDate; if (DateTime.TryParseExact(Path.GetFileNameWithoutExtension(InputFile), "yyyyMdd", null, System.Globalization.DateTimeStyles.AssumeLocal, out TheDate)) { reader.Configuration.HeaderValidated = null; reader.Configuration.MissingFieldFound = null; //CSVReader will now read the whole file into an enumerable IEnumerable records = reader.GetRecords <BSEHeaders>().Where(i => i.SC_TYPE == "Q").ToList(); //Write the entire contents of the CSV file into another //writer.WriteRecords(records); //Now we will write the data into the same output file but will do it //Using two methods. The first is writing the entire record. The second //method writes individual fields. Note you must call NextRecord method after //using Writefield to terminate the record. //Note that WriteRecords will write a header record for you automatically. If you //are not using the WriteRecords method and you want to a header, you must call the //Writeheader method like the following: // writer.WriteHeader <BSEHeaders>(); writer.NextRecord(); // //Do not use WriteHeader as WriteRecords will have done that already. string DateString = TheDate.ToString("yyyyMMdd"); foreach (BSEHeaders record in records) { //write record field by field writer.WriteField(record.SC_CODE); writer.WriteField(record.SC_NAME); //writer.WriteField(record.SC_TYPE); record.DATE = DateString; writer.WriteField(record.DATE); writer.WriteField(record.OPEN); writer.WriteField(record.HIGH); writer.WriteField(record.LOW); writer.WriteField(record.CLOSE); writer.WriteField(record.NO_OF_SHRS); //ensure you write end of record when you are using WriteField method writer.NextRecord(); } } } } } }