/// <summary> /// 得到一个对象实体 /// </summary> public StockCwInfo GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,Code,ReportDate,JBMGSY,MGJZC,MGJYHDCSXJLJE,ZYYWSR,ZYYWLR,YYLR,TZSY,YYEYSZJE,LRZE,JLR,JLROUT,JYHDCSDXJLJE,XJJXJDJWJCJE,ZZC,LDZC,ZFZ,LDFZ,GDQYBHSSGDQY,JZCSYLJQ from StockCwInfo "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; StockCwInfo model = new StockCwInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public void DataAccess() { List <StockInfo> stocklist = _oStockInfo.GetStockCodeList(""); foreach (StockInfo s in stocklist) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem(); item.URL = "http://quotes.money.163.com/service/zycwzb_" + s.stockcode + ".html?type=report"; item.Encoding = Encoding.UTF8; item.Method = "GET"; item.Timeout = 100000; item.ReadWriteTimeout = 30000;//写入Post数据超时时间,可选项默认为30000 HttpResult result = http.GetHtml(item); string Result = result.Html.Replace("\r\n\t", "").Replace(" ", ""); //string[] arrTemp = result.Html.Split('\r\n'); string[] strlist = Result.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (strlist.Length == 1) { continue; } string[] reportDate = strlist[0].Substring(0, strlist[0].Length - 1).Split(','); string[] JBMGSY = strlist[1].Substring(0, strlist[1].Length - 1).Split(','); string[] MGJZC = strlist[2].Substring(0, strlist[2].Length - 1).Split(','); string[] MGJYHDCSXJLJE = strlist[3].Substring(0, strlist[3].Length - 1).Split(','); string[] ZYYWSR = strlist[4].Substring(0, strlist[4].Length - 1).Split(','); string[] ZYYWLR = strlist[5].Substring(0, strlist[5].Length - 1).Split(','); string[] YYLR = strlist[6].Substring(0, strlist[6].Length - 1).Split(','); string[] TZSY = strlist[7].Substring(0, strlist[7].Length - 1).Split(','); string[] YYEYSZJE = strlist[8].Substring(0, strlist[8].Length - 1).Split(','); string[] LRZE = strlist[9].Substring(0, strlist[9].Length - 1).Split(','); string[] JLR = strlist[10].Substring(0, strlist[10].Length - 1).Split(','); string[] JLROUT = strlist[11].Substring(0, strlist[11].Length - 1).Split(','); string[] JYHDCSDXJLJE = strlist[12].Substring(0, strlist[12].Length - 1).Split(','); string[] XJJXJDJWJCJE = strlist[13].Substring(0, strlist[13].Length - 1).Split(','); string[] ZZC = strlist[14].Substring(0, strlist[14].Length - 1).Split(','); string[] LDZC = strlist[15].Substring(0, strlist[15].Length - 1).Split(','); string[] ZFZ = strlist[16].Substring(0, strlist[16].Length - 1).Split(','); string[] LDFZ = strlist[17].Substring(0, strlist[17].Length - 1).Split(','); string[] GDQYBHSSGDQY = strlist[18].Substring(0, strlist[18].Length - 1).Split(','); string strlist19 = strlist[19].Replace("\t", ""); string[] JZCSYLJQ = strlist19.Substring(0, strlist19.Length - 1).Split(','); for (int num = 1; num < reportDate.Length; num++) { int IsHave = _StockCWInfo.GetRecordCount("Symbol='" + s.stockcode + "' AND ReportDate=CONVERT(datetime,'" + reportDate[num].ToString() + "',102)"); if (IsHave != 0) { continue; } StockCwInfo cw = new StockCwInfo(); cw.Code = s.stockcode; cw.ReportDate = Convert.ToDateTime(reportDate[num].ToString()); cw.JBMGSY = decimal.Parse(PublicTool.IsNumElseToZero(JBMGSY[num].ToString())); cw.MGJZC = decimal.Parse(PublicTool.IsNumElseToZero(MGJZC[num].ToString())); cw.MGJYHDCSXJLJE = decimal.Parse(PublicTool.IsNumElseToZero(MGJYHDCSXJLJE[num].ToString())); cw.ZYYWSR = PublicTool.IsNumElseToZero(ZYYWSR[num].ToString()); cw.ZYYWLR = PublicTool.IsNumElseToZero(ZYYWLR[num].ToString()); cw.YYLR = PublicTool.IsNumElseToZero(YYLR[num].ToString()); cw.TZSY = PublicTool.IsNumElseToZero(TZSY[num].ToString()); cw.YYEYSZJE = PublicTool.IsNumElseToZero(YYEYSZJE[num].ToString()); cw.LRZE = PublicTool.IsNumElseToZero(LRZE[num].ToString()); cw.JLR = PublicTool.IsNumElseToZero(JLR[num].ToString()); cw.JLROUT = PublicTool.IsNumElseToZero(JLROUT[num].ToString()); cw.JYHDCSDXJLJE = PublicTool.IsNumElseToZero(JYHDCSDXJLJE[num].ToString()); cw.XJJXJDJWJCJE = PublicTool.IsNumElseToZero(XJJXJDJWJCJE[num].ToString()); cw.ZZC = PublicTool.IsNumElseToZero(ZZC[num].ToString()); cw.LDZC = PublicTool.IsNumElseToZero(LDZC[num].ToString()); cw.ZFZ = PublicTool.IsNumElseToZero(ZFZ[num].ToString()); cw.LDFZ = PublicTool.IsNumElseToZero(LDFZ[num].ToString()); cw.GDQYBHSSGDQY = PublicTool.IsNumElseToZero(GDQYBHSSGDQY[num].ToString()); cw.JZCSYLJQ = decimal.Parse(PublicTool.IsNumElseToZero(JZCSYLJQ[num].ToString())); if (_StockCWInfo.Add(cw) == 0) { continue; } } } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(StockCwInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into StockCwInfo("); strSql.Append("Code,ReportDate,JBMGSY,MGJZC,MGJYHDCSXJLJE,ZYYWSR,ZYYWLR,YYLR,TZSY,YYEYSZJE,LRZE,JLR,JLROUT,JYHDCSDXJLJE,XJJXJDJWJCJE,ZZC,LDZC,ZFZ,LDFZ,GDQYBHSSGDQY,JZCSYLJQ)"); strSql.Append(" values ("); strSql.Append("@Code,@ReportDate,@JBMGSY,@MGJZC,@MGJYHDCSXJLJE,@ZYYWSR,@ZYYWLR,@YYLR,@TZSY,@YYEYSZJE,@LRZE,@JLR,@JLROUT,@JYHDCSDXJLJE,@XJJXJDJWJCJE,@ZZC,@LDZC,@ZFZ,@LDFZ,@GDQYBHSSGDQY,@JZCSYLJQ)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Code", SqlDbType.NVarChar, 10), new SqlParameter("@ReportDate", SqlDbType.DateTime), new SqlParameter("@JBMGSY", SqlDbType.Decimal, 9), new SqlParameter("@MGJZC", SqlDbType.Decimal, 9), new SqlParameter("@MGJYHDCSXJLJE", SqlDbType.Decimal, 9), new SqlParameter("@ZYYWSR", SqlDbType.NVarChar, 50), new SqlParameter("@ZYYWLR", SqlDbType.NVarChar, 50), new SqlParameter("@YYLR", SqlDbType.NVarChar, 50), new SqlParameter("@TZSY", SqlDbType.NVarChar, 50), new SqlParameter("@YYEYSZJE", SqlDbType.NVarChar, 50), new SqlParameter("@LRZE", SqlDbType.NVarChar, 50), new SqlParameter("@JLR", SqlDbType.NVarChar, 50), new SqlParameter("@JLROUT", SqlDbType.NVarChar, 50), new SqlParameter("@JYHDCSDXJLJE", SqlDbType.NVarChar, 50), new SqlParameter("@XJJXJDJWJCJE", SqlDbType.NVarChar, 50), new SqlParameter("@ZZC", SqlDbType.NVarChar, 50), new SqlParameter("@LDZC", SqlDbType.NVarChar, 50), new SqlParameter("@ZFZ", SqlDbType.NVarChar, 50), new SqlParameter("@LDFZ", SqlDbType.NVarChar, 50), new SqlParameter("@GDQYBHSSGDQY", SqlDbType.NVarChar, 50), new SqlParameter("@JZCSYLJQ", SqlDbType.Decimal, 9) }; parameters[0].Value = model.Code; parameters[1].Value = model.ReportDate; parameters[2].Value = model.JBMGSY; parameters[3].Value = model.MGJZC; parameters[4].Value = model.MGJYHDCSXJLJE; parameters[5].Value = model.ZYYWSR; parameters[6].Value = model.ZYYWLR; parameters[7].Value = model.YYLR; parameters[8].Value = model.TZSY; parameters[9].Value = model.YYEYSZJE; parameters[10].Value = model.LRZE; parameters[11].Value = model.JLR; parameters[12].Value = model.JLROUT; parameters[13].Value = model.JYHDCSDXJLJE; parameters[14].Value = model.XJJXJDJWJCJE; parameters[15].Value = model.ZZC; parameters[16].Value = model.LDZC; parameters[17].Value = model.ZFZ; parameters[18].Value = model.LDFZ; parameters[19].Value = model.GDQYBHSSGDQY; parameters[20].Value = model.JZCSYLJQ; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public StockCwInfo DataRowToModel(DataRow row) { StockCwInfo model = new StockCwInfo(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["Code"] != null) { model.Code = row["Code"].ToString(); } if (row["ReportDate"] != null && row["ReportDate"].ToString() != "") { model.ReportDate = DateTime.Parse(row["ReportDate"].ToString()); } if (row["JBMGSY"] != null && row["JBMGSY"].ToString() != "") { model.JBMGSY = decimal.Parse(row["JBMGSY"].ToString()); } if (row["MGJZC"] != null && row["MGJZC"].ToString() != "") { model.MGJZC = decimal.Parse(row["MGJZC"].ToString()); } if (row["MGJYHDCSXJLJE"] != null && row["MGJYHDCSXJLJE"].ToString() != "") { model.MGJYHDCSXJLJE = decimal.Parse(row["MGJYHDCSXJLJE"].ToString()); } if (row["ZYYWSR"] != null) { model.ZYYWSR = row["ZYYWSR"].ToString(); } if (row["ZYYWLR"] != null) { model.ZYYWLR = row["ZYYWLR"].ToString(); } if (row["YYLR"] != null) { model.YYLR = row["YYLR"].ToString(); } if (row["TZSY"] != null) { model.TZSY = row["TZSY"].ToString(); } if (row["YYEYSZJE"] != null) { model.YYEYSZJE = row["YYEYSZJE"].ToString(); } if (row["LRZE"] != null) { model.LRZE = row["LRZE"].ToString(); } if (row["JLR"] != null) { model.JLR = row["JLR"].ToString(); } if (row["JLROUT"] != null) { model.JLROUT = row["JLROUT"].ToString(); } if (row["JYHDCSDXJLJE"] != null) { model.JYHDCSDXJLJE = row["JYHDCSDXJLJE"].ToString(); } if (row["XJJXJDJWJCJE"] != null) { model.XJJXJDJWJCJE = row["XJJXJDJWJCJE"].ToString(); } if (row["ZZC"] != null) { model.ZZC = row["ZZC"].ToString(); } if (row["LDZC"] != null) { model.LDZC = row["LDZC"].ToString(); } if (row["ZFZ"] != null) { model.ZFZ = row["ZFZ"].ToString(); } if (row["LDFZ"] != null) { model.LDFZ = row["LDFZ"].ToString(); } if (row["GDQYBHSSGDQY"] != null) { model.GDQYBHSSGDQY = row["GDQYBHSSGDQY"].ToString(); } if (row["JZCSYLJQ"] != null && row["JZCSYLJQ"].ToString() != "") { model.JZCSYLJQ = decimal.Parse(row["JZCSYLJQ"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(StockCwInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update StockCwInfo set "); strSql.Append("Code=@Code,"); strSql.Append("ReportDate=@ReportDate,"); strSql.Append("JBMGSY=@JBMGSY,"); strSql.Append("MGJZC=@MGJZC,"); strSql.Append("MGJYHDCSXJLJE=@MGJYHDCSXJLJE,"); strSql.Append("ZYYWSR=@ZYYWSR,"); strSql.Append("ZYYWLR=@ZYYWLR,"); strSql.Append("YYLR=@YYLR,"); strSql.Append("TZSY=@TZSY,"); strSql.Append("YYEYSZJE=@YYEYSZJE,"); strSql.Append("LRZE=@LRZE,"); strSql.Append("JLR=@JLR,"); strSql.Append("JLROUT=@JLROUT,"); strSql.Append("JYHDCSDXJLJE=@JYHDCSDXJLJE,"); strSql.Append("XJJXJDJWJCJE=@XJJXJDJWJCJE,"); strSql.Append("ZZC=@ZZC,"); strSql.Append("LDZC=@LDZC,"); strSql.Append("ZFZ=@ZFZ,"); strSql.Append("LDFZ=@LDFZ,"); strSql.Append("GDQYBHSSGDQY=@GDQYBHSSGDQY,"); strSql.Append("JZCSYLJQ=@JZCSYLJQ"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@Code", SqlDbType.NVarChar, 10), new SqlParameter("@ReportDate", SqlDbType.DateTime), new SqlParameter("@JBMGSY", SqlDbType.Decimal, 9), new SqlParameter("@MGJZC", SqlDbType.Decimal, 9), new SqlParameter("@MGJYHDCSXJLJE", SqlDbType.Decimal, 9), new SqlParameter("@ZYYWSR", SqlDbType.NVarChar, 50), new SqlParameter("@ZYYWLR", SqlDbType.NVarChar, 50), new SqlParameter("@YYLR", SqlDbType.NVarChar, 50), new SqlParameter("@TZSY", SqlDbType.NVarChar, 50), new SqlParameter("@YYEYSZJE", SqlDbType.NVarChar, 50), new SqlParameter("@LRZE", SqlDbType.NVarChar, 50), new SqlParameter("@JLR", SqlDbType.NVarChar, 50), new SqlParameter("@JLROUT", SqlDbType.NVarChar, 50), new SqlParameter("@JYHDCSDXJLJE", SqlDbType.NVarChar, 50), new SqlParameter("@XJJXJDJWJCJE", SqlDbType.NVarChar, 50), new SqlParameter("@ZZC", SqlDbType.NVarChar, 50), new SqlParameter("@LDZC", SqlDbType.NVarChar, 50), new SqlParameter("@ZFZ", SqlDbType.NVarChar, 50), new SqlParameter("@LDFZ", SqlDbType.NVarChar, 50), new SqlParameter("@GDQYBHSSGDQY", SqlDbType.NVarChar, 50), new SqlParameter("@JZCSYLJQ", SqlDbType.Decimal, 9), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.Code; parameters[1].Value = model.ReportDate; parameters[2].Value = model.JBMGSY; parameters[3].Value = model.MGJZC; parameters[4].Value = model.MGJYHDCSXJLJE; parameters[5].Value = model.ZYYWSR; parameters[6].Value = model.ZYYWLR; parameters[7].Value = model.YYLR; parameters[8].Value = model.TZSY; parameters[9].Value = model.YYEYSZJE; parameters[10].Value = model.LRZE; parameters[11].Value = model.JLR; parameters[12].Value = model.JLROUT; parameters[13].Value = model.JYHDCSDXJLJE; parameters[14].Value = model.XJJXJDJWJCJE; parameters[15].Value = model.ZZC; parameters[16].Value = model.LDZC; parameters[17].Value = model.ZFZ; parameters[18].Value = model.LDFZ; parameters[19].Value = model.GDQYBHSSGDQY; parameters[20].Value = model.JZCSYLJQ; parameters[21].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }