/// <summary> /// 将csv文件导入数据库 /// </summary> /// <param name="code">证券代码</param> /// <param name="name">证券名称</param> /// <param name="csvPath">csv文件路径</param> /// <returns>受影响行数</returns> public int ImportFromCSV(string code, string name, string csvPath) { DataTable dt = TXTUtility.ReadTxtSplitByRegStr(csvPath, 1, @",", null); if (dt == null) { return(0); } else { int insertedLinesCount = 0; foreach (DataRow row in dt.Rows) { StockDayPrice stock1 = new StockDayPrice(); stock1.Code = code; stock1.Name = name; stock1.Date = Convert.ToDateTime(row["Date"]); stock1.Open = Convert.ToDouble(row["Open"]); stock1.High = Convert.ToDouble(row["High"]); stock1.Low = Convert.ToDouble(row["Low"]); stock1.Close = Convert.ToDouble(row["Close"]); stock1.Volume = Convert.ToDouble(row["Volume"]); stock1.AdjClose = Convert.ToDouble(row["Adj Close"]); int j = this.AddNew(stock1); insertedLinesCount += j; } return(insertedLinesCount); } }
/// <summary> /// 将txt文件导入数据库 /// </summary> /// <param name="txtPath">txt文件路径</param> /// <param name="headerLine">列标题所在行号,没有则为0</param> /// <param name="regStr">正则表达式</param> /// <returns>受影响行数</returns> public int ImportFromTxt(string txtPath, int headerLine, string regStr, string[] delStr) { DataTable dt = TXTUtility.ReadTxtSplitByRegStr(txtPath, headerLine, regStr, delStr); if (dt == null) { return(0); } else { int insertedLinesCount = 0; foreach (DataRow row in dt.Rows) { CheckList checkList = new CheckList(); checkList.Date = DateTime.ParseExact((string)row["交割日期"], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); checkList.TradeName = (string)row["业务名称"]; if (string.Equals(checkList.TradeName, "证券买入") || string.Equals(checkList.TradeName, "红股入账") || string.Equals(checkList.TradeName, "新股申购")) { checkList.TradeDirection = 1; } else if (string.Equals(checkList.TradeName, "证券卖出") || string.Equals(checkList.TradeName, "申购还款")) { checkList.TradeDirection = -1; } else { checkList.TradeDirection = 0; } checkList.Code = (string)row["证券代码"]; checkList.Name = (string)row["证券名称"]; checkList.TradePrice = double.Parse((string)row["成交价格"]); checkList.TradeVolume = int.Parse((string)row["成交数量"]); checkList.RemainingVolume = int.Parse((string)row["剩余数量"]); checkList.TradeAmount = double.Parse((string)row["成交金额"]); checkList.SettlementAmount = double.Parse((string)row["清算金额"]); checkList.RemainingAmount = double.Parse((string)row["剩余金额"]); checkList.Commission = double.Parse((string)row["佣金"]); checkList.Tax = double.Parse((string)row["印花税"]); checkList.Fee = double.Parse((string)row["过户费"]); checkList.TradeCode = (string)row["成交编号"]; int j = this.AddNew(checkList); insertedLinesCount += j; } return(insertedLinesCount); } }