/// <summary> /// 根据配置文件中IP和端口获取撮合中心主键ID,如果从管理中心获取数据有异常或者返回的为null时 /// 这里返回的ID为0 /// </summary> /// <returns></returns> protected int GetMatchCenterIDByAddress() { int id = 0; RC_MatchCenter model = GetMatchCenterByAddress(AppConfig.GetConfigMatchCenterIP(), AppConfig.GetConfigMatchCenterPort()); if (model != null) { id = model.MatchCenterID; } return(id); }
/// <summary> /// 向内部缓存数据添加数据初始化 /// 程序启动时对些方法调用一次 /// </summary> public void Initialize() { try { ShowMessage.Instanse.ShowFormTitleMessage("正在获取管理中心数据初始化内部参数"); commotity.Fill(key => key.CommodityCode, GetAllCommodity()); bourseTypes.Fill(key => key.BourseTypeID, GetAllBourseType()); breedClasss.Fill(key => key.BreedClassID, GetAllBreedClass()); breedClassTypes.Fill(key => key.BreedClassTypeID, GetAllBreedClassType()); //缓存根据期货品种类型缓存相关代码 privateInitCommotityByBreedClassID(); //=========== commodityFuses.Fill(key => key.CommodityCode, GetAllCommodityFuse()); //fieldRanages.Fill(key => key.FieldRangeID, GetAllFieldRange()); fuseTimeSections.Fill(key => key.TimesectionID, GetAllFuseTimesection()); //minChangePriceValues.Fill(key => key.BreedClassID.ToString() + "@" + key.FieldRangeID.ToString(), GetAllMinChangePriceValue()); qh_HighLowStopScopeType.Fill(key => key.HighLowStopScopeID, GetAllQH_HighLowStopScopeType()); qh_FuturesTradeRules.Fill(key => key.BreedClassID, GetAllQH_FutureTradeRules()); RC_MatchCenter model = GetMatchCenterByAddress(); int matchCenterID = model.MatchCenterID; matchCenter.Add(matchCenterID, model); matchMachine.Fill(key => key.MatchMachineID, GetAllMatchMachineByMatchCenterID(matchCenterID)); tradeCommodityAssign.Fill(key => key.CommodityCode, GetAllTradeCommodityAssign()); spotTradeRules.Fill(key => key.BreedClassID, GetAllSpotTradeRules()); //tradeTimes.Fill(key => key.TradeTimeID, GetAllTradeTime()); //改由以下以交易所ID为主键 privateInitTradeTime(); validDeclareTypes.Fill(key => key.BreedClassValidID, GetAllValidDeclareType()); validDeclareValues.Fill(key => key.ValidDeclareValueID, GetAllValidDeclareValue()); xh_SpotHighLowControlType.Fill(key => key.BreedClassHighLowID, GetAllSpotHighLowControlType()); xh_SpotHighLowValues.Fill(key => key.HightLowValueID, GetAllSpotHighLowValue()); zFCommodity.Fill(key => key.stkcd.ToString() + "@" + key.paydt.ToString(), GetAllZFCommodity()); //获取所有非交易日的日期 cm_notTradeDate.Fill(key => key.BourseTypeID.Value + "@" + key.NotTradeDay.Value.ToString("yyyy-MM-dd"), GetAllCMNotTradeDate()); qh_LastTradingDay.Fill(key => key.LastTradingDayID, GetAllLastTradingDay()); #region 港股部分 hk_MinPriceFiled.Fill(key => key.FieldRangeID, GetHKMinChangePriceFieldRange()); hk_spotTradeRules.Fill(key => key.BreedClassID, GetHKSpotTradeRules()); hk_commodity.Fill(key => key.HKCommodityCode, GetAllHKCommodity()); //hkSpotCosts.Fill(key => key.BreedClassID, get()); #endregion ShowMessage.Instanse.ShowFormTitleMessage("获取管理中心数据初始化内部参数(完)"); } catch (Exception ex) { LogHelper.WriteError("CH-0002:初始化缓存数据异常0001", ex); ShowMessage.Instanse.ShowFormTitleMessage("获取管理中心数据初始化内部参数异常"); throw ex; } }
/// <summary> /// 设置控件的值 /// </summary> /// <param name="matchcenter"></param> private void SetTextValue(RC_MatchCenter matchcenter) { if (matchcenter == null) { m_cutRow = this.ViewCenter.FocusedRowHandle; DataRow dw = ViewCenter.GetDataRow(m_cutRow); if (dw == null) { return; } int MatchCenterID = int.Parse(dw["MatchCenterID"].ToString()); matchcenter = MatchCenterBLL.GetModel(MatchCenterID); if (matchcenter == null) { return; } } this.txt_CenterIP.Text = matchcenter.IP; this.txt_CenterName.Text = matchcenter.MatchCenterName; this.txt_cuoheService.Text = matchcenter.CuoHeService; this.txt_Port.Text = matchcenter.Port.ToString(); this.txt_xiadanService.Text = matchcenter.XiaDanService; this.txt_CenterID.Text = matchcenter.MatchCenterID.ToString(); }
/// <summary> /// 初始化撮合机 /// </summary> private void InitDevice() { string showmsg = "正在初始化行撮合机"; LogHelper.WriteDebug(showmsg + DateTime.Now); ShowMessage.Instanse.ShowFormTitleMessage(showmsg); RC_MatchCenter center = CommonDataCacheProxy.Instanse.GetCacheMatchCenterByConfig(); if (center != null) { AppConfig.MatchCenterName = "【" + center.MatchCenterName + "】"; } List <RC_MatchMachine> matchMachines = CommonDataCacheProxy.Instanse.GetCacheRC_MatchMachine(); string matchTypeID = AppConfig.GetConfigMatchBreedClassType(); //撮合中心撮合机不能为空 if (Utils.IsNullOrEmpty(matchMachines)) { LogHelper.WriteInfo("撮合中心初始化撮合机分配代码时没有找到撮合机--撮合中心初始化不成功!" + DateTime.Now); return; } int k = 0; showmsg += "[" + matchMachines.Count + "]=="; #region 先清空所有撮合管理器中内容 //先清空所有撮合管理器中内容 //MatchCenterManager.Instance.matchDevices.Clear(); foreach (var item in MatchCenterManager.Instance.matchDevices) { MatchDevice dev = item.Value; if (dev != null) { dev.ClearAllTimerEvent(); } } MatchCenterManager.Instance.matchDevices.Clear(); #endregion #region 清除所有下单过滤行情数据列表 MatchCodeDictionary.hk_ActivityOrderDic.Clear(); MatchCodeDictionary.xh_ActivityOrderDic.Clear(); MatchCodeDictionary.qh_ActivityOrderDic.Clear(); //add by 董鹏 2010-01-25 MatchCodeDictionary.spqh_ActivityOrderDic.Clear(); #endregion foreach (RC_MatchMachine machine in matchMachines) { #region 初始货所有撮合机器 k += 1; ShowMessage.Instanse.ShowFormTitleMessage(showmsg + k + "号撮合机"); CM_BourseType bourseType = CommonDataCacheProxy.Instanse.GetCacheCM_BourseTypeByKey((int)machine.BourseTypeID); MatchDevice device = new MatchDevice(); //TradeTimeManager.Instanse.AcceptStartTime = (DateTime)bourseType.ReceivingConsignStartTime; //TradeTimeManager.Instanse.AcceptEndTime = (DateTime)bourseType.ReceivingConsignEndTime; //List<CM_TradeTime> tradeTimes = CommonDataCacheProxy.Instanse.GetCacheCM_TradeTimeByBourseID(bourseType.BourseTypeID); List <RC_TradeCommodityAssign> assigns = CommonDataManagerOperate.GetTradeCommodityAssignByMatchineID(machine.MatchMachineID); if (Utils.IsNullOrEmpty(assigns)) { continue; } //撮合中心遍历撮合单元 foreach (RC_TradeCommodityAssign assign in assigns) { string iniCode = assign.CommodityCode; #region 根据配置初始化要撮合的商品代码 CM_BreedClass breedClass = CommonDataManagerOperate.GetBreedClassByCommodityCode(iniCode, assign.CodeFormSource); if (breedClass != null && breedClass.BreedClassTypeID.HasValue) { //根据配置初始化要撮合的商品代码 switch ((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID) { case Types.BreedClassTypeEnum.Stock: //根据配置是否初始化本商品撮合代码 if (matchTypeID.Substring(3, 1) == "0") { continue; } #region 初始化现货撮合机 //ShowMessage.Instanse.ShowFormTitleMessage(showmsg + "正在初始现货代码[" + assign.CommodityCode + "]撮合机"); //if ((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID == Types.BreedClassTypeEnum.Stock) //{ var stockMatcher = new StockMatcher(iniCode); stockMatcher.bourseTypeID = bourseType.BourseTypeID; device.bourseTypeID = bourseType.BourseTypeID; device.IniMatchDevice((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID.Value); //====获取相关代码中数据库的所有已下的委托 并添加到委托队列中 List <StockDataOrderEntity> xhEntity = StockDataOrderDataAccess.GetStockEntityList(iniCode); if (!Utils.IsNullOrEmpty(xhEntity)) { foreach (var entity in xhEntity) { //市场存量故障恢复 if (entity.MarketVolumeNo == entity.OrderNo && entity.MarkLeft > 0 && entity.MatchState != Types.MatchCenterState.First && entity.IsMarketPrice == (int)Types.MarketPriceType.otherPrice) { string stockKey = entity.SholderCode + "@" + entity.OrderPrice + "@" + entity.MarketVolumeNo; if ((Types.TransactionDirection)entity.TransactionDirection == Types.TransactionDirection.Buying) { stockMatcher.buyMarketVolume.AddMarketVolume(stockKey, entity.MarkLeft); } else if ((Types.TransactionDirection)entity.TransactionDirection == Types.TransactionDirection.Selling) { stockMatcher.sellMarketVolume.AddMarketVolume(stockKey, entity.MarkLeft); } } //添加过滤行情列表数据 MatchCodeDictionary.AddXH_ActivityOrderDic(entity.StockCode); stockMatcher.EntityBuffer.InsertQueueItem(entity); } } //============================== if (device.StockMarkers.ContainsKey(iniCode)) { device.StockMarkers.Remove(iniCode); } device.StockMarkers.Add(iniCode, stockMatcher); //} #endregion break; case Types.BreedClassTypeEnum.CommodityFuture: #region 初始化商品期货撮合机 add by 董鹏 2010-01-22 //根据配置是否初始化本商品撮合代码 if (matchTypeID.Substring(0, 1) == "0") { continue; } var cfMatcher = new SPQHMatcher(iniCode); cfMatcher.bourseTypeID = bourseType.BourseTypeID; device.bourseTypeID = bourseType.BourseTypeID; device.IniMatchDevice((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID.Value); //====获取相关代码中数据库的所有已下的委托 并添加到委托队列中 List <CommoditiesDataOrderEntity> cfModel = CommoditiesDataOrderAccess.GetFutureEntityList(iniCode); if (!Utils.IsNullOrEmpty(cfModel)) { foreach (var entity in cfModel) { //市场存量故障恢复 if (entity.MarketVolumeNo == entity.OrderNo && entity.MarkLeft > 0 && entity.MatchState != Types.MatchCenterState.First && entity.IsMarketPrice == (int)Types.MarketPriceType.otherPrice) { string futKey = entity.SholderCode + "@" + entity.OrderPrice + "@" + entity.MarketVolumeNo; if ((Types.TransactionDirection)entity.TransactionDirection == Types.TransactionDirection.Buying) { cfMatcher.buyMarketVolume.AddMarketVolume(futKey, entity.MarkLeft); } else if ((Types.TransactionDirection)entity.TransactionDirection == Types.TransactionDirection.Selling) { cfMatcher.sellMarketVolume.AddMarketVolume(futKey, entity.MarkLeft); } } //添加过滤行情列表数据 MatchCodeDictionary.AddSPQH_ActivityOrderDic(entity.StockCode); cfMatcher.EntityBuffer.InsertQueueItem(entity); } } //========================================// if (device.CommoditiesMarkers.ContainsKey(iniCode)) { device.CommoditiesMarkers.Remove(iniCode); } device.CommoditiesMarkers.Add(iniCode, cfMatcher); #endregion break; case Types.BreedClassTypeEnum.StockIndexFuture: #region 初始化股指期货撮合机 //ShowMessage.Instanse.ShowFormTitleMessage(showmsg + "正在初始期货代码[" + assign.CommodityCode + "]撮合机"); //根据配置是否初始化本商品撮合代码 if (matchTypeID.Substring(2, 1) == "0") { continue; } //if ((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID == Types.BreedClassTypeEnum.StockIndexFuture) //{ var futureMatcher = new FutureMatcher(iniCode); futureMatcher.bourseTypeID = bourseType.BourseTypeID; device.bourseTypeID = bourseType.BourseTypeID; device.IniMatchDevice((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID.Value); //====获取相关代码中数据库的所有已下的委托 并添加到委托队列中 List <FutureDataOrderEntity> qhModel = FutureDataOrderDataAccess.GetFutureEntityList(iniCode); if (!Utils.IsNullOrEmpty(qhModel)) { foreach (var entity in qhModel) { //市场存量故障恢复 if (entity.MarketVolumeNo == entity.OrderNo && entity.MarkLeft > 0 && entity.MatchState != Types.MatchCenterState.First && entity.IsMarketPrice == (int)Types.MarketPriceType.otherPrice) { string futKey = entity.SholderCode + "@" + entity.OrderPrice + "@" + entity.MarketVolumeNo; if ((Types.TransactionDirection)entity.TransactionDirection == Types.TransactionDirection.Buying) { futureMatcher.buyMarketVolume.AddMarketVolume(futKey, entity.MarkLeft); } else if ((Types.TransactionDirection)entity.TransactionDirection == Types.TransactionDirection.Selling) { futureMatcher.sellMarketVolume.AddMarketVolume(futKey, entity.MarkLeft); } } //添加过滤行情列表数据 MatchCodeDictionary.AddQH_ActivityOrderDic(entity.StockCode); futureMatcher.EntityBuffer.InsertQueueItem(entity); } } //========================================// if (device.FutureMarkers.ContainsKey(iniCode)) { device.FutureMarkers.Remove(iniCode); } device.FutureMarkers.Add(iniCode, futureMatcher); //} #endregion break; case Types.BreedClassTypeEnum.HKStock: #region 初始化港股撮合机 //根据配置是否初始化本商品撮合代码 if (matchTypeID.Substring(1, 1) == "0") { continue; } //ShowMessage.Instanse.ShowFormTitleMessage(showmsg + "正在初始港股代码[" + iniCode + "]撮合机"); //if ((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID == Types.BreedClassTypeEnum.HKStock) //{ // LogHelper.WriteInfo("正在初始化港股撮合机" + DateTime.Now); var hkMatcher = new HKStockMatcher(iniCode); hkMatcher.bourseTypeID = bourseType.BourseTypeID; device.bourseTypeID = bourseType.BourseTypeID; device.IniMatchDevice((Types.BreedClassTypeEnum)breedClass.BreedClassTypeID.Value); //====获取相关代码中数据库的所有已下的委托 并添加到委托队列中 List <HKEntrustOrderInfo> hkOrders = HKEntrustOrderDal.GetHKEntrustOrderList(iniCode); if (!Utils.IsNullOrEmpty(hkOrders)) { foreach (var entity in hkOrders) { LogHelper.WriteDebug("程序启动==【港股】初始化重新添加委托到队列中" + entity.OrderNo + "当前委托量" + entity.OrderVolume + "原委托量:" + entity.OldVolume + "代码:" + entity.HKSecuritiesCode); //市场存量故障恢复 if (entity.MarketVolumeNo == entity.OrderNo && entity.MarkLeft > 0 && entity.MatchState != Types.MatchCenterState.First && entity.OrderType != (int)Types.HKPriceType.SLO) { string hkKey = entity.SholderCode + "@" + entity.OrderPrice + "@" + entity.MarketVolumeNo; if ((Types.TransactionDirection)entity.TradeType == Types.TransactionDirection.Buying) { hkMatcher.buyMarketVolume.AddMarketVolume(hkKey, entity.MarkLeft); } else if ((Types.TransactionDirection)entity.TradeType == Types.TransactionDirection.Selling) { hkMatcher.sellMarketVolume.AddMarketVolume(hkKey, entity.MarkLeft); } } //添加过滤行情列表数据 MatchCodeDictionary.AddHK_ActivityOrderDic(entity.HKSecuritiesCode); hkMatcher.orderCache.InsertQueueItem(entity); } } //=============================// if (device.HKStockMarkers.ContainsKey(iniCode)) { device.HKStockMarkers.Remove(iniCode); } device.HKStockMarkers.Add(iniCode, hkMatcher); //} #endregion break; default: break; } //以上加载并验证通过后再删除和加入 if (MatchCenterManager.Instance.matchDevices.ContainsKey(iniCode)) { MatchCenterManager.Instance.matchDevices[iniCode] = null; MatchCenterManager.Instance.matchDevices.Remove(iniCode); } MatchCenterManager.Instance.matchDevices.Add(iniCode, device); // ShowMessage.Instanse.ShowFormTitleMessage(showmsg + "初始化代码[" + iniCode + "]撮合机(完)"); } #endregion } #endregion } //删除完所有撤单数据,因为已经把数据都放入列表,已经不删除当再重启时又会重写一次到数据库 //这样就会重复 CancelOrderRecoveryDal.DeleteAll(); //清除初始化管理中心的数据中没有再使用到的数据 CommonDataCacheProxy.Instanse.ClearOther(); LogHelper.WriteInfo("撮合中心初始化成功!" + DateTime.Now); }
/// <summary> /// 把新增的现货代码(StockInfo表和HKStockInfo表中)新增的代码自动添加到交易商品_撮合机_分配表中 /// </summary> public void XHCodeAutoRCTradeCommodityAssign() { try { //交易所类型ID int bourseTypeID = 0; StockInfoBLL stockInfoBLL = new StockInfoBLL(); HKStockInfoBLL hKStockInfoBLL = new HKStockInfoBLL(); CM_BreedClassBLL cM_BreedClassBLL = new CM_BreedClassBLL(); RC_MatchCenterBLL rcMatchCenterBll = new RC_MatchCenterBLL(); RC_MatchMachineBLL rcMatchMachineBll = new RC_MatchMachineBLL(); RC_TradeCommodityAssignBLL rcTradeCommodityAssignBll = new RC_TradeCommodityAssignBLL(); RC_MatchMachine rcMatchMachine = new RC_MatchMachine(); RC_MatchCenter rcMatchCenterModel = new RC_MatchCenter(); RC_TradeCommodityAssign rcTradeCommodityAssignModel = new RC_TradeCommodityAssign(); //获取撮合中心记录 List <ManagementCenter.Model.RC_MatchCenter> rcMatchCenters = rcMatchCenterBll.GetListArray(string.Empty); if (rcMatchCenters.Count == 0) { string errCode = "GL-7005"; string errMsg = "撮合中心记录不存在!"; LogHelper.WriteDebug(errCode + errMsg); VTException exception = new VTException(errCode, errMsg); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } //获取所有新添加的普通代码 string strWhereStock = " StockCode not in (select CommodityCode from CM_Commodity) "; List <StockInfo> stockInfoList = stockInfoBLL.GetStockInfoList(strWhereStock); //获取所有新添加的港股代码 string strWhereHKStock = " StockCode not in (select HKCommodityCode from HK_Commodity) "; List <HKStockInfo> hKStockInfoList = hKStockInfoBLL.GetHKStockInfoList(strWhereHKStock); if (stockInfoList.Count > 0) { int breedClassID = 0;//品种标识 foreach (StockInfo info in stockInfoList) { if (breedClassID != info.BreedClassID) { breedClassID = info.BreedClassID; //获取相同品种ID的所有代码 string strWhereStock1 = " StockCode not in (select CommodityCode from CM_Commodity) and BreedClassID={0} "; List <StockInfo> _stockInfoList = stockInfoBLL.GetStockInfoList(string.Format(strWhereStock1, breedClassID));//(string.Format(" and BreedClassID={0}", breedClassID)); if (_stockInfoList == null || _stockInfoList.Count == 0) { string errCode = "GL-7006"; string errMsg = "相同品种ID的所有普通代码为空!"; LogHelper.WriteDebug(errCode + errMsg); VTException exception = new VTException(errCode, errMsg); LogHelper.WriteError(exception.ToString(), exception.InnerException); continue; } //根据品种ID获取交易所ID CM_BreedClass cmBreedClass = cM_BreedClassBLL.GetModel(breedClassID); if (cmBreedClass != null) { bourseTypeID = (int)cmBreedClass.BourseTypeID; //根据交易所类型ID,获取撮合机记录 List <ManagementCenter.Model.RC_MatchMachine> rcMatchMachines = rcMatchMachineBll.GetListArray(string.Format("BourseTypeID={0}", bourseTypeID)); if (rcMatchMachines.Count == 0) { string errCode = "GL-7007"; string errMsg = "获取撮合机记录不存在!"; LogHelper.WriteDebug(errCode + errMsg); VTException exception = new VTException(errCode, errMsg); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } //把同一品种ID的所有代码添加到交易商品_撮合机_分配表中 foreach (StockInfo _stockInfo in _stockInfoList) { rcTradeCommodityAssignModel.CommodityCode = _stockInfo.StockCode; rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID; rcTradeCommodityAssignModel.CodeFormSource = (int)GTA.VTS.Common.CommonObject.Types.IsCodeFormSource.Yes; //_stockInfo.CodeFromSource; rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel); } } } continue; } } if (hKStockInfoList.Count > 0) { int breedClassID = 0;//品种标识 foreach (HKStockInfo hKInfo in hKStockInfoList) { if (breedClassID != hKInfo.BreedClassID) { breedClassID = hKInfo.BreedClassID; //获取相同品种ID的所有港股代码 string strWhereHKStock1 = " StockCode not in (select HKCommodityCode from HK_Commodity) and BreedClassID={0} "; List <HKStockInfo> _hKStockInfoList = hKStockInfoBLL.GetHKStockInfoList(string.Format(strWhereHKStock1, breedClassID));//(string.Format(" and BreedClassID={0}", breedClassID)); if (_hKStockInfoList == null || _hKStockInfoList.Count == 0) { string errCode = "GL-7008"; string errMsg = "相同品种ID的所有港股代码为空!"; LogHelper.WriteDebug(errCode + errMsg); VTException exception = new VTException(errCode, errMsg); LogHelper.WriteError(exception.ToString(), exception.InnerException); continue; } //根据品种ID获取交易所ID CM_BreedClass cmBreedClass = cM_BreedClassBLL.GetModel(breedClassID); if (cmBreedClass != null) { bourseTypeID = (int)cmBreedClass.BourseTypeID; //根据交易所类型ID,获取撮合机记录 List <ManagementCenter.Model.RC_MatchMachine> rcMatchMachines = rcMatchMachineBll.GetListArray(string.Format("BourseTypeID={0}", bourseTypeID)); if (rcMatchMachines.Count == 0) { string errCode = "GL-7009"; string errMsg = "获取撮合机记录不存在!"; LogHelper.WriteDebug(errCode + errMsg); VTException exception = new VTException(errCode, errMsg); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } //把同一品种ID的所有港股代码添加到交易商品_撮合机_分配表中 foreach (HKStockInfo _hKStockInfo in _hKStockInfoList) { rcTradeCommodityAssignModel.CommodityCode = _hKStockInfo.StockCode; rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID; rcTradeCommodityAssignModel.CodeFormSource = (int)GTA.VTS.Common.CommonObject.Types.IsCodeFormSource.No; //_hKStockInfo.CodeFromSource; rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel); } } } continue; } } } catch (Exception ex) { string errCode = "GL-7010"; string errMsg = "把新增的现货代码(StockInfo表和HKStockInfo表中)新增的代码添加到交易商品_撮合机_分配表中失败!"; LogHelper.WriteDebug(errCode + errMsg); VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); } }
/// <summary> /// 把期货新增的代码自动添加到可交易商品_撮合机_分配表中 /// </summary> /// <param name="CommodityName">商品代码</param> /// <param name="BreedClassID">品种ID</param> public void QHCodeAutoRCTradeCommodityAssign(string CommodityName, int BreedClassID) { try { //交易所类型ID int bourseTypeID = 0; CM_BreedClassBLL cM_BreedClassBLL = new CM_BreedClassBLL(); RC_MatchCenterBLL rcMatchCenterBll = new RC_MatchCenterBLL(); RC_MatchMachineBLL rcMatchMachineBll = new RC_MatchMachineBLL(); RC_TradeCommodityAssignBLL rcTradeCommodityAssignBll = new RC_TradeCommodityAssignBLL(); RC_MatchMachine rcMatchMachine = new RC_MatchMachine(); RC_MatchCenter rcMatchCenterModel = new RC_MatchCenter(); RC_TradeCommodityAssign rcTradeCommodityAssignModel = new RC_TradeCommodityAssign(); //根据品种ID获取交易所ID CM_BreedClass cmBreedClass = cM_BreedClassBLL.GetModel(BreedClassID); if (cmBreedClass != null) { bourseTypeID = (int)cmBreedClass.BourseTypeID; } //获取撮合中心记录 List <ManagementCenter.Model.RC_MatchCenter> rcMatchCenters = rcMatchCenterBll.GetListArray(string.Empty); //撮合中心记录存在 if (rcMatchCenters.Count > 0) { //根据交易所类型ID,获取撮合机记录 List <ManagementCenter.Model.RC_MatchMachine> rcMatchMachines = rcMatchMachineBll.GetListArray(string.Format("BourseTypeID={0}", bourseTypeID)); //有撮合机存在,则向可交易商品_撮合机_分配表中添加新代码 if (rcMatchMachines.Count > 0) { //判断代码分配记录已存在则退出 add by 董鹏 2010-03-31 if (rcTradeCommodityAssignBll.Exists(CommodityName, rcMatchMachines[0].MatchMachineID)) { return; } rcTradeCommodityAssignModel.CommodityCode = CommodityName; rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID; rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel); } else { //撮合机不存在,则添加撮合机 rcMatchMachine.MatchCenterID = rcMatchCenters[0].MatchCenterID; rcMatchMachine.MatchMachineName = "自动添加的撮合机名称";//保证不重复 rcMatchMachine.BourseTypeID = bourseTypeID; int result = rcMatchMachineBll.Add(rcMatchMachine); if (result > 0) { rcTradeCommodityAssignModel.CommodityCode = CommodityName; rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID; rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel); } else { //写错误日志 LogHelper.WriteDebug("添加撮合机失败"); } } } else { //添加撮合中心记录 rcMatchCenterModel.MatchCenterName = "自动添加的撮合中心名称"; rcMatchCenterModel.IP = "127.0.0.1"; rcMatchCenterModel.Port = 9281; rcMatchCenterModel.CuoHeService = "OrderDealRpt"; rcMatchCenterModel.XiaDanService = "DoOrderService"; int addrcMatchCResultID = rcMatchCenterBll.Add(rcMatchCenterModel); if (addrcMatchCResultID > 0) { //撮合中心添加成功,则添加撮合机 rcMatchMachine.MatchCenterID = addrcMatchCResultID; // rcMatchCenterslist[0].MatchCenterID; rcMatchMachine.MatchMachineName = "自动添加的撮合机名称"; //保证不重复 rcMatchMachine.BourseTypeID = bourseTypeID; int resultMatchMachineID = rcMatchMachineBll.Add(rcMatchMachine); //撮合机添加成功,则向可交易商品_撮合机_分配表中添加新代码 if (resultMatchMachineID > 0) { rcTradeCommodityAssignModel.CommodityCode = CommodityName; rcTradeCommodityAssignModel.MatchMachineID = resultMatchMachineID;// rcMatchMachineslist[0].MatchMachineID; rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel); } else { //写错误日志 LogHelper.WriteDebug("向可交易商品_撮合机_分配表中添加新代码失败"); } } else { //写错误日志 LogHelper.WriteDebug("添加撮合中心失败"); } } } catch (Exception ex) { string errCode = "GL-7004"; string errMsg = "执行期货新增代码自动添加到可交易商品撮合机分配表中失败"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } }
/// <summary> /// 向导数据保存 /// </summary> /// <param name="MatchCenter">撮合中心实体</param> /// <param name="dt">交易所撮合机个数分配表</param> /// <returns></returns> public bool GuideSave(RC_MatchCenter MatchCenter, DataTable dt) { try { RC_MatchCenterDAL MatchCenterDAL = new RC_MatchCenterDAL(); RC_MatchMachineDAL MatchMachineDAL = new RC_MatchMachineDAL(); RC_TradeCommodityAssignDAL TradeCommodityAssignDAL = new RC_TradeCommodityAssignDAL(); Database db = DatabaseFactory.CreateDatabase(); DbConnection Conn = db.CreateConnection(); if (Conn.State != ConnectionState.Open) { Conn.Open(); } DbTransaction Tran = Conn.BeginTransaction(); try { TradeCommodityAssignDAL.DeleteAll(Tran, db); MatchMachineDAL.DeleteAll(Tran, db); MatchCenterDAL.DeleteAll(Tran, db); int MatchCenterID = MatchCenterDAL.Add(MatchCenter, Tran, db); for (int i = 0; i < dt.Rows.Count; i++) { int BourseTypeID = int.Parse(dt.Rows[i]["BourseTypeID"].ToString()); int MachineNO = int.Parse(dt.Rows[i]["MachineNo"].ToString()); if (!AssignCode(MachineNO, BourseTypeID, MatchCenterID, Tran, db)) { return(false); } } Tran.Commit(); return(true); } catch (Exception ex) { Tran.Rollback(); string errCode = "GL-2200"; string errMsg = "向导数据保存失败"; VTException vte = new VTException(errCode, errMsg, ex); LogHelper.WriteError(vte.ToString(), vte.InnerException); return(false); } finally { if (Conn.State == ConnectionState.Open) { Conn.Close(); } } } catch (Exception ex) { string errCode = "GL-2201"; string errMsg = "数据库连接失败"; VTException vte = new VTException(errCode, errMsg, ex); LogHelper.WriteError(vte.ToString(), vte.InnerException); return(false); } }