//拼接股票URL private void stock_appendurl(string stock, ref string stockurl, string url, bool ispicture) { GeneralClass gc = new GeneralClass(); string head = stock.Substring(0, 2); Stock_Index si = new Stock_Index(); if (!gc.stock_checkout(stock, ref si)) { return; } StringBuilder s = new StringBuilder(url); switch (si.market) { case FlagDef.SH: //上海 s.Append("sh"); break; case FlagDef.SZ: //深证 s.Append("sz"); break; default: return; } s.Append(stock); if (ispicture) { s.Append(".gif"); } stockurl = s.ToString(); }
/// <summary> /// 自选股增加功能101 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddStockbt_Click(object sender, EventArgs e) { GeneralClass gc = new GeneralClass(); string stkcode = stockntb.Text; Stock_Index si = new Stock_Index(); //校验是否重复 foreach (string s in CfgStruct.lns) { string _stkcode = s.Split(' ')[0]; if (_stkcode == stkcode) { MessageBox.Show("自选股列表存在该股票,请勿重复添加"); return; } } //校验stkcode if (!gc.stock_checkout(stkcode, ref si)) { MessageBox.Show("e-101001股票代码有误"); //stockntb.Text = ""; return; } if(!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.ADD)) { MessageBox.Show("e-101002向数据库增加个股失败"); return; } RefreshOptionlist(); stockntb.Text = ""; stockntb.Focus(); }
/// <summary> /// DB股票代码校验, 并选出市场代码 /// 合理返回true,不合理返回false /// </summary> public bool stock_checkout(string stock, ref Stock_Index si) { SqlProcess sp = new SqlProcess(); string stockget = null; string dbtable = "stock "; DataTable dt = new DataTable(); //查stock string sql = "select stkcode,market,stkname from" + CfgStruct.dbname + dbtable + "where stkcode =" + "'" + stock + "'"; sp.ExecSingleSQL(CfgStruct.dbconnect_str, sql, dt); //若未查到股票,返回false if (dt.Rows.Count == 0) { return(false); } else { stockget = dt.Rows[0]["stkcode"].ToString().Trim(); //去掉空格 } //比较所选证券代码在DB中是否一致 if (String.Compare(stock, stockget) == 0) //if (String.Compare(stockcode, stockget) == 0) { si.market = Convert.ToInt32(dt.Rows[0]["market"].ToString().Trim()); si.stockname = dt.Rows[0]["stkname"].ToString().Trim(); return(true); } else { return(false); } }
/// <summary> /// 自选股删除功能102 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteStockbt_Click(object sender, EventArgs e) { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; string sdel = "确定要删除" + CfgStruct.stockcur + "吗?"; DialogResult dr = MessageBox.Show(sdel, "删除确定", messButton); if (dr == DialogResult.Cancel) //如果点击“Cancel”按钮 { return; } GeneralClass gc = new GeneralClass(); string stkcode = stockntb.Text; Stock_Index si = new Stock_Index(); //校验stkcode if (!gc.stock_checkout(stkcode, ref si)) { MessageBox.Show("e-102001股票代码有误"); //stockntb.Text = ""; return; } //在数据库中删除 if (!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.REMOVE)) { MessageBox.Show("e-102002向数据库删除个股失败"); return; } RefreshOptionlist(); stockntb.SelectAll(); stockntb.Focus(); }
/// <summary> /// 自选股增加功能101 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddStockbt_Click(object sender, EventArgs e) { GeneralClass gc = new GeneralClass(); string stkcode = stockntb.Text; Stock_Index si = new Stock_Index(); //校验是否重复 foreach (string s in CfgStruct.lns) { string _stkcode = s.Split(' ')[0]; if (_stkcode == stkcode) { MessageBox.Show("自选股列表存在该股票,请勿重复添加"); return; } } //校验stkcode if (!gc.stock_checkout(stkcode, ref si)) { MessageBox.Show("e-101001股票代码有误"); //stockntb.Text = ""; return; } if (!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.ADD)) { MessageBox.Show("e-101002向数据库增加个股失败"); return; } RefreshOptionlist(); stockntb.Text = ""; stockntb.Focus(); }
/// <summary> /// 选中个股功能100 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void optionallist_SelectedIndexChanged(object sender, EventArgs e) { string stockget = optionallist.Text.Split(' ')[0]; Stock_Index si = new Stock_Index(); GeneralClass gc = new GeneralClass(); //检验股票代码是否正确 if (!gc.stock_checkout(stockget, ref si)) { gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stockget, FlagDef.REMOVE); MessageBox.Show("e-100001股票代码不正确,已删除."); return; } stockntb.Text = stockget; CfgStruct.stockcur = stockget; lb_syssem.Items.Clear(); string showstock = "当前选择:" + si.stockname; lb_syssem.Items.Add(showstock); //实时行情获取 Cycle_stockmarket(sender, e); }
/// <summary> /// 下载指定股票的历史数据 /// </summary> /// <param name="stkcode"></param> /// <returns></returns> public void downloadstockdata(ref string msg) { string stkcode = Stkcode; string filepath = CfgStruct.hisdatafilepath; bool IsStockCode = false; StringBuilder sburl = new StringBuilder(CfgStruct.market_daily_his_url); sburl.Append(stkcode); string newfilename = "\\" + stkcode + ".csv"; Stock_Index si = new Stock_Index(); if (!stock_checkout(stkcode, ref si)) { return; } switch (si.market) { case FlagDef.SH: sburl.Append(".ss"); IsStockCode = true; break; case FlagDef.SZ: sburl.Append(".sz"); IsStockCode = true; break; default: MessageBox.Show("Stock code error!"); IsStockCode = false; break; } if (IsStockCode) { string url = sburl.ToString(); if (DownloadFile(url, filepath)) { File.Copy(filepath, Directory.GetCurrentDirectory() + newfilename, true);//每次下载覆盖 msg = stkcode + "下载成功"; } else { msg = stkcode + "下载失败"; } } Thread.Sleep(500); }
/// <summary> /// 获取股票代码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okbutton_Click(object sender, EventArgs e) { GeneralClass gc = new GeneralClass(); string stockget = stockntb.Text; Stock_Index si = new Stock_Index(); if (gc.stock_checkout(stockget, ref si)) { AdvStock.mystock = stockget; statusl.Text = AdvStock.mystock + " Get"; currentstockl.Text = si.stockname; } else { MessageBox.Show("Error: " + stockget + " is not a stock code."); } }
//拼接股票URL private void stock_appendurl(string stock, ref string stockurl, string url, bool ispicture) { GeneralClass gc = new GeneralClass(); string head = stock.Substring(0, 2); Stock_Index si = new Stock_Index(); if (!gc.stock_checkout(stock, ref si)) return; StringBuilder s = new StringBuilder(url); switch (si.market) { case FlagDef.SH: //上海 s.Append("sh"); break; case FlagDef.SZ: //深证 s.Append("sz"); break; default: return; } s.Append(stock); if(ispicture) s.Append(".gif"); stockurl = s.ToString(); }
/// <summary> /// 自选股删除功能102 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteStockbt_Click(object sender, EventArgs e) { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; string sdel = "确定要删除" + CfgStruct.stockcur + "吗?"; DialogResult dr = MessageBox.Show(sdel, "删除确定", messButton); if (dr == DialogResult.Cancel) //如果点击“Cancel”按钮 return; GeneralClass gc = new GeneralClass(); string stkcode = stockntb.Text; Stock_Index si = new Stock_Index(); //校验stkcode if (!gc.stock_checkout(stkcode, ref si)) { MessageBox.Show("e-102001股票代码有误"); //stockntb.Text = ""; return; } //在数据库中删除 if (!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.REMOVE)) { MessageBox.Show("e-102002向数据库删除个股失败"); return; } RefreshOptionlist(); stockntb.SelectAll(); stockntb.Focus(); }
/// <summary> /// DB股票代码校验, 并选出市场代码 /// 合理返回true,不合理返回false /// </summary> public bool stock_checkout(string stock, ref Stock_Index si) { SqlProcess sp = new SqlProcess(); string stockget = null; string dbtable = "stock "; DataTable dt = new DataTable(); //查stock string sql = "select stkcode,market,stkname from" + CfgStruct.dbname + dbtable + "where stkcode =" + "'" + stock + "'"; sp.ExecSingleSQL(CfgStruct.dbconnect_str, sql, dt); //若未查到股票,返回false if (dt.Rows.Count == 0) return false; else stockget = dt.Rows[0]["stkcode"].ToString().Trim(); //去掉空格 //比较所选证券代码在DB中是否一致 if (String.Compare(stock, stockget) == 0) //if (String.Compare(stockcode, stockget) == 0) { si.market = Convert.ToInt32(dt.Rows[0]["market"].ToString().Trim()); si.stockname = dt.Rows[0]["stkname"].ToString().Trim(); return true; } else return false; }
public bool downloadstockdata(string stkcode) { string filepath = CfgStruct.hisdatafilepath; bool IsStockCode = false; StringBuilder sburl = new StringBuilder(CfgStruct.market_daily_his_url); sburl.Append(stkcode); string newfilename = "\\" + stkcode + ".csv"; Stock_Index si = new Stock_Index(); if (!stock_checkout(stkcode, ref si)) return false; switch (si.market) { case FlagDef.SH: sburl.Append(".ss"); IsStockCode = true; break; case FlagDef.SZ: sburl.Append(".sz"); IsStockCode = true; break; default: MessageBox.Show("Stock code error!"); IsStockCode = false; break; } if (IsStockCode) { string url = sburl.ToString(); if (!DownloadFile(url, filepath)) return false; else File.Copy(filepath, Directory.GetCurrentDirectory() + newfilename, true);//每次下载覆盖 } return true; }
/// <summary> /// 获取股票代码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okbutton_Click(object sender, EventArgs e) { GeneralClass gc = new GeneralClass(); string stockget = stockntb.Text; Stock_Index si = new Stock_Index(); if (gc.stock_checkout(stockget, ref si)) { AdvStock.mystock = stockget; statusl.Text = AdvStock.mystock + " Get"; currentstockl.Text = si.stockname; } else MessageBox.Show("Error: " + stockget + " is not a stock code."); }