/// <summary> /// 删除品种时,则根据品种ID,删除所有相关联的表 /// </summary> /// <param name="BreedClassID">品种ID</param> /// <returns></returns> public bool DeleteCMBreedClassALLAbout(int BreedClassID) { XH_SpotTradeRulesBLL xH_SpotTradeRulesBLL = new XH_SpotTradeRulesBLL(); QH_FuturesTradeRulesBLL qH_FuturesTradeRulesBLL = new QH_FuturesTradeRulesBLL(); QH_SIFPositionBLL qH_SIFPositionBLL = new QH_SIFPositionBLL(); CM_CommodityDAL cM_CommodityDAL = new CM_CommodityDAL(); CM_BreedClassDAL cMBreedClassDAL = new CM_BreedClassDAL(); CM_BreedClass cM_BreedClass = new CM_BreedClass(); XH_SpotPositionDAL xH_SpotPositionDAL = new XH_SpotPositionDAL(); UM_DealerTradeBreedClassDAL uM_DealerTradeBreedClassDAL = new UM_DealerTradeBreedClassDAL(); UM_DealerTradeBreedClass uM_DealerTradeBreedClass = new UM_DealerTradeBreedClass(); //QH_SIFPositionDAL qH_SIFPositionDAL=new QH_SIFPositionDAL();//股指期货持仓限制 //QH_SIFPosition qH_SIFPosition=new QH_SIFPosition(); QH_PositionLimitValueDAL qH_PositionLimitValueDAL = new QH_PositionLimitValueDAL(); //期货持仓限制 XH_SpotCostsDAL xH_SpotCostsDAL = new XH_SpotCostsDAL(); //现货交易费用 QH_FutureCostsDAL qH_FutureCostsDAL = new QH_FutureCostsDAL(); //期货交易费用 QH_CFBailScaleValueDAL qH_CFBailScaleValueDAL = new QH_CFBailScaleValueDAL(); //商品期货_保证金比例 HK_SpotTradeRulesBLL hK_SpotTradeRulesBLL = new HK_SpotTradeRulesBLL(); //港股交易规则BLL HK_SpotCostsDAL hK_SpotCostsDAL = new HK_SpotCostsDAL(); //港股交易费用 HK_CommodityDAL hK_CommodityDAL = new HK_CommodityDAL(); //港股交易商品 //期货保证金 add by 董鹏 2010-02-02 QH_SIFBailDAL qh_SIFBailDal = new QH_SIFBailDAL(); RC_TradeCommodityAssignDAL rC_TradeCommodityAssignDAL = new RC_TradeCommodityAssignDAL(); DbConnection Conn = null; Database db = DatabaseFactory.CreateDatabase(); Conn = db.CreateConnection(); if (Conn.State != ConnectionState.Open) { Conn.Open(); } DbTransaction Tran = Conn.BeginTransaction(); try { int NewBreedClassID = AppGlobalVariable.INIT_INT; //未分配品种ID //获取系统默认未分配品种的品种ID List <CM_BreedClass> cMBreedClassList = cMBreedClassDAL.GetListArray(string.Format("DeleteState={0}", (int)Types.IsYesOrNo.Yes)); if (cMBreedClassList.Count == 0) { return(false); } if (cMBreedClassList[0].ISSysDefaultBreed == (int)Types.IsYesOrNo.Yes) { NewBreedClassID = cMBreedClassList[0].BreedClassID; } cM_BreedClass = cMBreedClassDAL.GetModel(BreedClassID); if (cM_BreedClass == null) { return(false); } //删除撮合机里的代码 int ISHKBreedClassType = Convert.ToInt32(cM_BreedClass.ISHKBreedClassType); //是否港股类型 if (ISHKBreedClassType == (int)GTA.VTS.Common.CommonObject.Types.IsYesOrNo.Yes) //当品种类型是港股时 { List <ManagementCenter.Model.HK_Commodity> hkCommodityList = hK_CommodityDAL.GetListArray(string.Format("BreedClassID={0}", BreedClassID)); if (hkCommodityList.Count > 0) { List <ManagementCenter.Model.RC_TradeCommodityAssign> rcTradeCommodityAssignList = rC_TradeCommodityAssignDAL.GetListArray(string.Format("CodeFormSource={0}", (int)Types.IsCodeFormSource.No)); if (rcTradeCommodityAssignList.Count > 0) { for (int i = 0; i < hkCommodityList.Count; i++) { for (int j = i; j < rcTradeCommodityAssignList.Count; j++) { if (hkCommodityList[i].HKCommodityCode == rcTradeCommodityAssignList[j].CommodityCode) { if (!rC_TradeCommodityAssignDAL.DeleteRCByCommodityCode(hkCommodityList[i].HKCommodityCode, Tran, db)) { Tran.Rollback(); return(false); } break; } } } } } } else if (ISHKBreedClassType == (int)GTA.VTS.Common.CommonObject.Types.IsYesOrNo.No)//当其它品种类型是时) { List <ManagementCenter.Model.CM_Commodity> cmCommodityList = cM_CommodityDAL.GetListArray(string.Format("BreedClassID={0}", BreedClassID)); if (cmCommodityList.Count > 0) { List <ManagementCenter.Model.RC_TradeCommodityAssign> rcTradeCommodityAssignList = rC_TradeCommodityAssignDAL.GetListArray(string.Format("CodeFormSource={0}", (int)Types.IsCodeFormSource.Yes)); if (rcTradeCommodityAssignList.Count > 0) { for (int i = 0; i < cmCommodityList.Count; i++) { for (int j = i; j < rcTradeCommodityAssignList.Count; j++) { if (cmCommodityList[i].CommodityCode == rcTradeCommodityAssignList[j].CommodityCode) { if (!rC_TradeCommodityAssignDAL.DeleteRCByCommodityCode(cmCommodityList[i].CommodityCode, Tran, db)) { Tran.Rollback(); return(false); } break; } } } } } } //品种类型ID int breedClassType = Convert.ToInt32(cM_BreedClass.BreedClassTypeID); if (breedClassType == (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.Stock) { if (!xH_SpotTradeRulesBLL.DeleteSpotTradeRulesAboutAll(BreedClassID)) { Tran.Rollback(); return(false); } if (!xH_SpotPositionDAL.Delete(BreedClassID, Tran, db)) //删除持仓 { Tran.Rollback(); return(false); } if (!xH_SpotCostsDAL.Delete(BreedClassID, Tran, db)) //删除现货交易费用 { Tran.Rollback(); return(false); } } else if (breedClassType == (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.StockIndexFuture) { if (!qH_FuturesTradeRulesBLL.DeleteFuturesTradeRulesAboutAll(BreedClassID)) { Tran.Rollback(); return(false); } if (!qH_SIFPositionBLL.DeleteQHSIFPositionAndQHSIFBail(BreedClassID)) { Tran.Rollback(); return(false); } if (!qH_PositionLimitValueDAL.DeletePositionLimitVByBreedClassID(BreedClassID, Tran, db)) { Tran.Rollback(); return(false); } if (!qH_FutureCostsDAL.Delete(BreedClassID, Tran, db)) //删除期货交易费用 { Tran.Rollback(); return(false); } if (!qH_CFBailScaleValueDAL.DeleteCFBailScaleVByBreedClassID(BreedClassID, Tran, db))//删除商品期货_保证金比例 { Tran.Rollback(); return(false); } } else if (breedClassType == (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.HKStock) { if (!hK_SpotTradeRulesBLL.DeleteHKSpotTradeRulesAbout(BreedClassID)) { Tran.Rollback(); return(false); } if (!hK_SpotCostsDAL.Delete(BreedClassID, Tran, db)) //删除港股交易费用 { Tran.Rollback(); return(false); } if (!xH_SpotPositionDAL.Delete(BreedClassID, Tran, db)) //删除持仓 { Tran.Rollback(); return(false); } //根据品种ID,更新港股交易商品表中的品种ID( if (!hK_CommodityDAL.UpdateHKBreedClassID(BreedClassID, NewBreedClassID, Tran, db)) { Tran.Rollback(); return(false); } } if (breedClassType != (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.HKStock) { //根据品种ID,更新交易商品表中的品种ID( if (!cM_CommodityDAL.UpdateBreedClassID(BreedClassID, NewBreedClassID, Tran, db)) { Tran.Rollback(); return(false); } } //删除品种权限表记录 List <Model.UM_DealerTradeBreedClass> uMDealerTradeBreedClass = uM_DealerTradeBreedClassDAL.GetListArray(string.Format("BreedClassID={0}", BreedClassID)); foreach (Model.UM_DealerTradeBreedClass umDTradeBreedClass in uMDealerTradeBreedClass) { if (!uM_DealerTradeBreedClassDAL.DeleteDealerTradeByBreedClassID(Convert.ToInt32(umDTradeBreedClass.BreedClassID), Tran, db)) { Tran.Rollback(); return(false); } } //删除期货保证金记录 add by 董鹏 2010-02-02 if (!qh_SIFBailDal.Delete(BreedClassID, Tran, db)) { Tran.Rollback(); return(false); } if (!cMBreedClassDAL.Delete(BreedClassID, Tran, db)) { Tran.Rollback(); return(false); } Tran.Commit(); return(true); } catch (Exception ex) { Tran.Rollback(); string errCode = "GL-4115"; string errMsg = " 删除品种时,则根据品种ID,删除所有相关联的表失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(false); } finally { if (Conn.State == ConnectionState.Open) { Conn.Close(); } } }