private void InsertOrUpdateDaStock(ContractStockHK uc) { MySqlCommand sqlselectcom = new MySqlCommand(); sqlselectcom.CommandText = SQLText.selectStockSQL; MySqlParameter[] commandParameters = new MySqlParameter[] { new MySqlParameter("@exchange_no", uc.FExchangeNo), new MySqlParameter("@stock_no", uc.FCommodityNo) }; MySqlDataReader reader = MySqlHelper.ExecuteReader(MySqlHelper.ConnectionStringManager, CommandType.Text, sqlselectcom.CommandText, commandParameters); if (reader.Read() == true) { string stock_name = DBValueToStr(reader, "stock_name"); string mortgage_percent = DBValueToStr(reader, "mortgage_percent"); string upper_tick_code = DBValueToStr(reader, "upper_tick_code"); if (stock_name.Equals(uc.FCommodityName) && upper_tick_code.Equals(uc.FUpperTickCode) && CommonFunction.StringToDecimal(mortgage_percent) == CommonFunction.StringToDecimal(uc.FMortgagePercent)) { } else { insertStockSQL(true, uc); } } else { insertStockSQL(false, uc); } reader.Close(); reader.Dispose(); }
private void insertStockSQL(bool isdelete, ContractStockHK uc) { string[] cmdTexts = null; MySqlParameter[][] commandParameters = null; MySqlParameter[] delcommandParameters = new MySqlParameter[] { new MySqlParameter("@exchange_no", uc.FExchangeNo), new MySqlParameter("@stock_no", uc.FCommodityNo) }; Exchange ec = lstExchange.FirstOrDefault(p => p.FExchangeNo == uc.FExchangeNo); if (ec != null) { //将期货的交易所名字换成中文 uc.FExchangeName = ec.FName; } MySqlParameter[] insertcommandParameters = new MySqlParameter[] { new MySqlParameter("@exchange_no", uc.FExchangeNo), new MySqlParameter("@exchange_name", uc.FExchangeName), new MySqlParameter("@stock_no", uc.FCommodityNo), new MySqlParameter("@stock_name", uc.FCommodityName), new MySqlParameter("@stock_type", uc.FCommodityType), new MySqlParameter("@reg_date", DateTime.Now.ToString("yyyyMMdd")), new MySqlParameter("@currency_no", uc.FCurrencyNo), new MySqlParameter("@currency_name", uc.FCurrencyName), new MySqlParameter("@lot_size", uc.FLotSize), new MySqlParameter("@mortgage_percent", uc.FMortgagePercent), new MySqlParameter("@upper_tick_code", uc.FUpperTickCode), new MySqlParameter("@create_by", "batch_id"), new MySqlParameter("@create_date", DateTime.Now), new MySqlParameter("@update_by", "batch_id"), new MySqlParameter("@update_date", DateTime.Now), new MySqlParameter("@commodity_type", "10"), new MySqlParameter("@py_name", GetStringSpell.GetChineseSpell(uc.FCommodityName)) }; if (isdelete) { //需要更新的时候 cmdTexts = new string[] { SQLText.deleteStockSQL, SQLText.insertStockSQL }; commandParameters = new MySqlParameter[][] { delcommandParameters, insertcommandParameters }; } else { cmdTexts = new string[] { // deletefuturesSQL, SQLText.insertStockSQL }; commandParameters = new MySqlParameter[][] { //delcommandParameters, insertcommandParameters }; } bool isInsert = MySqlHelper.ExecuteTransaction(MySqlHelper.ConnectionStringManager, CommandType.Text, cmdTexts, commandParameters); if (!isInsert) { PrintToTxt(uc.FCommodityNo + " 产品更新失败"); marketErrorLoger.log(LogLevel.SYSTEMERROR, uc.FCommodityNo + " 产品更新失败"); } }
/// <summary> /// 执行行情接受线程 /// </summary> public void ExecuteMarketThread() { string value = ""; while (isSave) { try { value = marketBlockingCollection.Take(); NetInfo ni = new NetInfo(); ni.MyReadString(value); if (CommandCode.LOGIN.Equals(ni.code)) { if (string.IsNullOrEmpty(ni.errorCode) || "00000".Equals(ni.errorCode)) { PrintToTxt(user + " 登录成功!"); } else { PrintToTxt(user + " 登录失败!"); } } if (CommandCode.LOGINHK.Equals(ni.code)) { if (string.IsNullOrEmpty(ni.errorCode) || "00000".Equals(ni.errorCode)) { PrintToTxt(user + " 登录成功!"); } else { PrintToTxt(user + " 登录失败!"); } } if (CommandCode.GETTCONTRACT.Equals(ni.code)) { //期货品种 List <UseContract> lstUc = CommonFunction.ObjectListFromString <UseContract>(UseContract.MyPropToString(), ni.infoT); if (lstUc != null && lstUc.Count > 0) { InsertOrUpdateDaFutures(lstUc); int received = CommonFunction.StringToInt(ni.systemCode); if (received != 0) { RequestContract(received); } } else { PrintToTxt("期货产品更新完成 " + ReloadData(ConfigurationManager.AppSettings["futures_reload_url"])); } } if (CommandCode.CURRENCYLIST.Equals(ni.code)) { //期货汇率 List <CurrencyInfo> lstUc = CommonFunction.ObjectListFromString <CurrencyInfo>(CurrencyInfo.MyPropToString(), ni.infoT); foreach (CurrencyInfo ci in lstUc) { UpdateCurrency(ci); } PrintToTxt("汇率更新完成 " + ReloadData(ConfigurationManager.AppSettings["currency_reload_url"])); } if (CommandCode.GetContractStock.Equals(ni.code)) { List <ContractStockHK> lstUc = CommonFunction.ObjectListFromString <ContractStockHK>(ContractStockHK.MyPropToString(), ni.infoT); if (lstUc != null && lstUc.Count > 0) { foreach (ContractStockHK ci in lstUc) { InsertOrUpdateDaStock(ci); } int received = CommonFunction.StringToInt(ni.systemCode); if (received != 0) { RequestContract(received); } } else { PrintToTxt("证券产品更新完成 " + ReloadData(ConfigurationManager.AppSettings["stock_reload_url"])); } } if (CommandCode.GetPlateList.Equals(ni.code) || CommandCode.GetPlateListStockHK.Equals(ni.code)) { List <MyPlateCommodityInfo> list = CommonFunction.ObjectListFromString <MyPlateCommodityInfo>(PlateCommodityInfo.MyPropToString(), ni.infoT); int i = 0; foreach (MyPlateCommodityInfo ci in list) { ci.FSortId = i++.ToString(); } InsertOrUpdatePlateView(list); PrintToTxt("板块更新完成 " + ReloadData(ConfigurationManager.AppSettings["plate_reload_url"])); } } catch (Exception ex) { marketErrorLoger.log(LogLevel.SYSTEMERROR, ex.ToString()); } } }