/// <summary> /// 判断交易商品名称是否已经存在 /// </summary> /// <param name="CommodityName">商品名称</param> /// <returns></returns> public bool IsExistCommodityName(string CommodityName) { try { CM_CommodityDAL cMCommodityDAL = new CM_CommodityDAL(); string strWhere = string.Format("CommodityName='{0}'", CommodityName); DataSet _ds = cMCommodityDAL.GetList(strWhere); if (_ds != null) { if (_ds.Tables[0].Rows.Count == 0) { return(true); } return(false); } return(false); } catch (Exception ex) { string errCode = "GL-4308"; string errMsg = "判断交易商品名称是否已经存在失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(false); } }
/// <summary> /// 获取品种类型股指期货的商品代码 /// </summary> /// <returns></returns> public DataSet GetQHSIFCommodityCode() { try { CM_CommodityDAL cMCommodityDAL = new CM_CommodityDAL(); return(cMCommodityDAL.GetQHSIFCommodityCode()); } catch (Exception ex) { string errCode = "GL-4304"; string errMsg = "获取品种类型股指期货的商品代码失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(null); } }
/// <summary> /// 获取所有交易商品 /// </summary> /// <param name="CommodityCode">商品代码</param> /// <param name="CommodityName">商品名称</param> /// <param name="BreedClassID">品种ID</param> /// <param name="pageNo">当前页</param> /// <param name="pageSize">显示记录数</param> /// <param name="rowCount">总行数</param> /// <returns></returns> public DataSet GetAllCMCommodity(string CommodityCode, string CommodityName, int BreedClassID, int pageNo, int pageSize, out int rowCount) { try { CM_CommodityDAL cMCommodityDAL = new CM_CommodityDAL(); return(cMCommodityDAL.GetAllCMCommodity(CommodityCode, CommodityName, BreedClassID, pageNo, pageSize, out rowCount)); } catch (Exception ex) { rowCount = AppGlobalVariable.INIT_INT; string errCode = "GL-4303"; string errMsg = "获取所有交易商品失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(null); } }
/// <summary> /// 添加期货品种时初始化一个周期的和约代码 /// </summary> /// <param name="BreedClassID"></param> public void QHCommdityCodeInit(int BreedClassID) { CommodityCodeUpdate CCP = new CommodityCodeUpdate(); //根据品种ID,找到品种的前缀代码 string QH_PrefixCode = CCP.GetQH_PrefixCodeByID(BreedClassID); //根据品种ID,找到品种的名称 string QH_breedclassName = CCP.GetBreedClassNameByID(BreedClassID); #region 创建代码规则管理器 add by 董鹏 2010-03-10 //根据品种获取交易所 CM_BreedClassBLL bc = new CM_BreedClassBLL(); CM_BourseTypeBLL bt = new CM_BourseTypeBLL(); var bourseType = bt.GetModel(bc.GetModel(BreedClassID).BourseTypeID.Value); //创建代码规则管理 CodeRulesManager codeRule; if (bourseType.CodeRulesType.HasValue) { LogHelper.WriteDebug("===开始自动生成代码,代码规则类型:" + bourseType.CodeRulesType.ToString()); codeRule = new CodeRulesManager((Types.CodeRulesType)bourseType.CodeRulesType.Value); } else { LogHelper.WriteDebug("===开始自动生成代码,没有获取到交易所对应的代码规则,交易所:" + bourseType.BourseTypeName); codeRule = new CodeRulesManager(null); } #endregion CM_CommodityDAL CommodityDAL = new CM_CommodityDAL(); CM_Commodity CM_Commodity = new CM_Commodity(); CM_Commodity.BreedClassID = BreedClassID; CM_Commodity.GoerScale = decimal.MaxValue; CM_Commodity.LabelCommodityCode = null; CM_Commodity.StockPinYin = null; CM_Commodity.MarketDate = DateTime.Now.AddYears(-1); //暂时将日期定为一年前 DateTime.MaxValue; CM_Commodity.turnovervolume = null; CM_Commodity.IsExpired = (int)Types.IsYesOrNo.No; //初始化期货代码时,默认没有过期 CM_Commodity.ISSysDefaultCode = (int)Types.IsYesOrNo.Yes; //新增期货代码时,默认代码没有过期 QH_AgreementDeliveryMonthDAL AgreementDeliveryMonthDAL = new QH_AgreementDeliveryMonthDAL(); List <QH_AgreementDeliveryMonth> L = AgreementDeliveryMonthDAL.GetListArray(string.Format("BreedClassID={0}", BreedClassID)); foreach (QH_AgreementDeliveryMonth AgreementDeliveryMonth in L) { if ((int)AgreementDeliveryMonth.MonthID > System.DateTime.Now.Month && (int)AgreementDeliveryMonth.MonthID <= 12) { //string Code = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + // CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID); //使用代码规则管理器生成代码 string Code = codeRule.GetCode(QH_PrefixCode, DateTime.Now.Year.ToString(), CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID)); CM_Commodity.CommodityCode = Code; CM_Commodity.CommodityName = Code;// QH_breedclassName + Code.Substring(Code.Length - 4); CommodityDAL.Add(CM_Commodity); } if ((int)AgreementDeliveryMonth.MonthID < System.DateTime.Now.Month) { //string Code = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + // CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID); //使用代码规则管理器生成代码 string Code = codeRule.GetCode(QH_PrefixCode, DateTime.Now.AddYears(1).Year.ToString(), CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID)); CM_Commodity.CommodityCode = Code; CM_Commodity.CommodityName = Code;// QH_breedclassName + Code.Substring(Code.Length - 4); CommodityDAL.Add(CM_Commodity); } if ((int)AgreementDeliveryMonth.MonthID == System.DateTime.Now.Month) { int lasttradingday = CCP.GetLastTradingDay(CCP.GetLastTradingDayEntity(BreedClassID), BreedClassID); string Code = string.Empty; if (System.DateTime.Now.Day < lasttradingday) { // Code = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + //CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID); //使用代码规则管理器生成代码 Code = codeRule.GetCode(QH_PrefixCode, DateTime.Now.Year.ToString(), CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID)); } else { // Code = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + //CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID); //使用代码规则管理器生成代码 Code = codeRule.GetCode(QH_PrefixCode, DateTime.Now.AddYears(1).Year.ToString(), CommodityCodeUpdate.GetTwoLenMonth((int)AgreementDeliveryMonth.MonthID)); } CM_Commodity.CommodityCode = Code; CM_Commodity.CommodityName = Code;// QH_breedclassName + Code.Substring(Code.Length - 4); CommodityDAL.Add(CM_Commodity); } if ((int)AgreementDeliveryMonth.MonthID == 13) { SpecialQHCodeInit(BreedClassID, QH_PrefixCode, QH_breedclassName); } } }
private void SpecialQHCodeInit(int BreedClassID, string QH_PrefixCode, string QH_breedclassName) { //1,2,3, 4,5,6, 7,8,9 ,10,11,12 //1,2,3, 6, // 2,3, 6, 9, // 3, 4, 6, 9, // 4,5,6, 9, // 5,6, 9, 12, // 6, 7, 9, 12, // 7,8,9, 12, // 3, 8,9, 12, // 3, 9, 10, 12, // 3, 10,11,12, // 3, 6, 11,12, //1, 3, 6, 12, //1,2,3, 6, CommodityCodeUpdate CCP = new CommodityCodeUpdate(); int lasttradingday = CCP.GetLastTradingDay(CCP.GetLastTradingDayEntity(BreedClassID), BreedClassID); string Code1 = string.Empty; string Code2 = string.Empty; string Code3 = string.Empty; string Code4 = string.Empty; #region switch (System.DateTime.Now.Month) { case 1: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "02"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "03"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "06"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "01"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; } break; case 2: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "03"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "06"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "02"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "04"; } break; case 3: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "04"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "06"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "03"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "05"; } break; case 4: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "05"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "06"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "04"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; } break; case 5: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "06"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "05"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "07"; } break; case 6: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "07"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "06"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "08"; } break; case 7: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "08"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "07"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "03"; } break; case 8: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "03"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "08"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "10"; } break; case 9: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "10"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "03"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "09"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "11"; } break; case 10: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "11"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "03"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "10"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "06"; } break; case 11: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "03"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "06"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "11"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "01"; } break; case 12: Code2 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "01"; Code3 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "03"; Code4 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "06"; if (System.DateTime.Now.Day < lasttradingday) { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now) + "12"; } else { Code1 = QH_PrefixCode + CommodityCodeUpdate.GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "02"; } break; } #endregion CM_CommodityDAL CommodityDAL = new CM_CommodityDAL(); CM_Commodity CM_Commodity = new CM_Commodity(); CM_Commodity.BreedClassID = BreedClassID; CM_Commodity.GoerScale = decimal.MaxValue; CM_Commodity.LabelCommodityCode = null; CM_Commodity.StockPinYin = null; CM_Commodity.MarketDate = DateTime.MaxValue; CM_Commodity.turnovervolume = null; CM_Commodity.IsExpired = (int)Types.IsYesOrNo.No; //初始化期货代码时,默认代码没有过期 CM_Commodity.ISSysDefaultCode = (int)Types.IsYesOrNo.Yes; //初始化期货代码时,默认是系统代码 CM_Commodity.CommodityCode = Code1; CM_Commodity.CommodityName = Code1; // QH_breedclassName + Code1.Substring(Code1.Length - 4); CommodityDAL.Add(CM_Commodity); CM_Commodity.CommodityCode = Code2; CM_Commodity.CommodityName = Code2;// QH_breedclassName + Code2.Substring(Code2.Length - 4); CommodityDAL.Add(CM_Commodity); CM_Commodity.CommodityCode = Code3; CM_Commodity.CommodityName = Code3;// QH_breedclassName + Code3.Substring(Code3.Length - 4); CommodityDAL.Add(CM_Commodity); CM_Commodity.CommodityCode = Code4; CM_Commodity.CommodityName = Code4;// QH_breedclassName + Code4.Substring(Code4.Length - 4); CommodityDAL.Add(CM_Commodity); }
/// <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(); } } }
/// <summary> /// 根据商品代码删除交易商品(相关表的记录同时删除) /// </summary> /// <param name="CommodityCode">商品代码</param> /// <param name="BreedClassID">品种ID</param> /// <returns></returns> public bool DeleteCMCommodity(string CommodityCode, int BreedClassID) { CM_CommodityDAL cMCommodityDAL = new CM_CommodityDAL(); RC_TradeCommodityAssignDAL TradeCommodityAssignDAL = new RC_TradeCommodityAssignDAL(); CM_CommodityFuseDAL cMCommodityFuseDAL = new CM_CommodityFuseDAL(); CM_FuseTimesectionDAL cMFuseTimesectionDAL = new CM_FuseTimesectionDAL(); CM_BreedClassBLL cM_BreedClassBLL = new CM_BreedClassBLL(); DbConnection Conn = null; Database db = DatabaseFactory.CreateDatabase(); Conn = db.CreateConnection(); if (Conn.State != ConnectionState.Open) { Conn.Open(); } DbTransaction Tran = Conn.BeginTransaction(); try { int breedClassTypeID = AppGlobalVariable.INIT_INT;//品种类型ID List <CM_BreedClass> cM_BreedClassList = cM_BreedClassBLL.GetListArray(string.Format("BreedClassID={0}", BreedClassID)); if (cM_BreedClassList.Count > 0) { CM_BreedClass cM_BreedClass = cM_BreedClassList[0]; if (cM_BreedClass != null) { breedClassTypeID = Convert.ToInt32(cM_BreedClass.BreedClassTypeID); } } if (breedClassTypeID == (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.StockIndexFuture) { if (!string.IsNullOrEmpty(CommodityCode)) { if (!cMFuseTimesectionDAL.DeleteByCommodityCode(CommodityCode, Tran, db)) { Tran.Rollback(); return(false); } else { if (!cMCommodityFuseDAL.Delete(CommodityCode, Tran, db)) { Tran.Rollback(); return(false); } } } TradeCommodityAssignDAL.DeleteByCommodityCode(CommodityCode, Tran, db); if (!cMCommodityDAL.Delete(CommodityCode, Tran, db)) { Tran.Rollback(); return(false); } } else { TradeCommodityAssignDAL.DeleteByCommodityCode(CommodityCode, Tran, db); if (!cMCommodityDAL.Delete(CommodityCode, Tran, db)) { Tran.Rollback(); return(false); } } Tran.Commit(); return(true); } catch (Exception ex) { Tran.Rollback(); string errCode = "GL-4301"; string errMsg = "删除交易商品失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(false); } finally { if (Conn.State == ConnectionState.Open) { Conn.Close(); } } }
/// <summary> /// 交易月份类型为本月下月随后的两个季度月份的代码更新 /// </summary> /// <param name="breedclass"></param> private void SpecialQHCodeUpdate(int breedclass) { try { //根据品种ID,找到品种的前缀代码 string QH_PrefixCode = GetQH_PrefixCodeByID(breedclass); //根据品种ID,找到品种的名称 string QH_breedclassName = GetBreedClassNameByID(breedclass); string OldCode = string.Empty; string NewCode = string.Empty; //1,2,3, 4,5,6, 7,8,9 ,10,11,12 //1,2,3, 6, // 2,3, 6, 9, // 3, 4, 6, 9, // 4,5,6, 9, // 5,6, 9, 12, // 6, 7, 9, 12, // 7,8,9, 12, // 3, 8,9, 12, // 3, 9, 10, 12, // 3, 10,11,12, // 3, 6, 11,12, //1, 3, 6, 12, //1,2,3, 6, //add 李健华 2010-01-15 //比如今天之前是,1001,1002,1003,1006,今天之后是1002,1003,1006,1009, //下一个月1002到期后就是,1004,1006,1009,1010 //保证3,6,9,12中有连续2个的季月,以及连续的两个自然月,总共4个合约是不变的。 //============== switch (System.DateTime.Now.Month) { case 1: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "01"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "09"; break; case 2: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "02"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "04"; break; case 3: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "03"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "05"; break; case 4: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "04"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "12"; break; case 5: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "05"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "07"; break; case 6: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "06"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "08"; break; case 7: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "07"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "03"; break; case 8: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "08"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "10"; break; case 9: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "09"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "11"; break; case 10: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "10"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "06"; break; case 11: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "11"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "01"; break; case 12: OldCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now) + "12"; NewCode = QH_PrefixCode + GetTwoLenYear(System.DateTime.Now.AddYears(1)) + "02"; break; } CM_CommodityDAL CommodityDAL = new CM_CommodityDAL(); RC_TradeCommodityAssignDAL TradeCommodityAssignDAL = new RC_TradeCommodityAssignDAL(); CM_Commodity CM_Commodity = CommodityDAL.GetModel(OldCode); if (CM_Commodity == null) { CM_Commodity = new CM_Commodity(); } CM_Commodity.CommodityCode = NewCode; CM_Commodity.MarketDate = DateTime.Parse(System.DateTime.Now.AddDays(1).ToShortDateString()); //若第二天是非交易日则顺延一天 add by 董鹏 2010-03-31 while (!JudgmentIsTrandingDay(CM_Commodity.MarketDate, breedclass)) { CM_Commodity.MarketDate = CM_Commodity.MarketDate.AddDays(1); } CM_Commodity.CommodityName = NewCode; //QH_breedclassName + NewCode.Substring(NewCode.Length - 4); CM_Commodity.BreedClassID = breedclass; CM_Commodity.GoerScale = decimal.MaxValue; CM_Commodity.LabelCommodityCode = null; CM_Commodity.StockPinYin = null; CM_Commodity.turnovervolume = null; CM_Commodity.IsExpired = (int)Types.IsYesOrNo.No; //新增期货代码时,默认代码没有过期 CM_Commodity.ISSysDefaultCode = (int)Types.IsYesOrNo.Yes; //新增期货代码时,默认是系统代码 bool _result = CommodityDAL.Add(CM_Commodity); if (!_result) { LogHelper.WriteDebug("SpecialQHCodeUpdate()方法中的添加代码失败"); return; } //更新代码分配表 TradeCommodityAssignDAL.Update(OldCode, NewCode); // CommodityDAL.Delete(OldCode); //根据2009-7-22需求过期代码添加标识 int isExpired = (int)Types.IsYesOrNo.Yes;//旧代码状态设置为过期 bool _resultUpdate = CommodityDAL.Update(OldCode, isExpired); if (!_resultUpdate) { LogHelper.WriteDebug("SpecialQHCodeUpdate()方法中的更新代码失败"); } //调用把期货新增的代码自动添加到可交易商品_撮合机_分配表中的方法 QHCodeAutoRCTradeCommodityAssign(NewCode, breedclass); } catch (Exception ex) { string errCode = "GL-7003"; string errMsg = "执行更新方法SpecialQHCodeUpdate()失败"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); } }
/// <summary> /// 期货代码更新 /// Update by: 董鹏 /// Update Date: 2010-03-10 /// Desc: 使用代码规则管理器生成代码 /// </summary> /// <param name="breedclass">品种ID</param> /// <param name="LastTradingDayEntity">期货最后交易日实体</param> public void QHCodeUpdata(int breedclass, QH_LastTradingDay LastTradingDayEntity) { try { //根据品种ID,找到品种的代码名称 string QH_Prefixname = GetQH_PrefixCodeByID(breedclass); //根据品种ID,找到品种的名称 string QH_breedclassName = GetBreedClassNameByID(breedclass); //根据品种获取交易所 CM_BreedClassBLL bc = new CM_BreedClassBLL(); CM_BourseTypeBLL bt = new CM_BourseTypeBLL(); var bourseType = bt.GetModel(bc.GetModel(breedclass).BourseTypeID.Value); //创建代码规则管理 CodeRulesManager codeRule; if (bourseType.CodeRulesType.HasValue) { LogHelper.WriteDebug("===开始自动生成代码,代码规则类型:" + bourseType.CodeRulesType.ToString()); codeRule = new CodeRulesManager((Types.CodeRulesType)bourseType.CodeRulesType.Value); } else { LogHelper.WriteDebug("===开始自动生成代码,没有获取到交易所对应的代码规则,交易所:" + bourseType.BourseTypeName); codeRule = new CodeRulesManager(null); } CM_CommodityDAL CommodityDAL = new CM_CommodityDAL(); RC_TradeCommodityAssignDAL TradeCommodityAssignDAL = new RC_TradeCommodityAssignDAL(); string Old_QH_codename; string New_QH_codename; if ((int)LastTradingDayEntity.LastTradingDayTypeID == (int)Types.QHLastTradingDayType.DeliMonthAgoMonthLastTradeDay) { //Old_QH_codename = QH_Prefixname + GetTwoLenYear(DateTime.Now) + // GetTwoLenMonth(DateTime.Now.AddMonths(1)); //New_QH_codename = QH_Prefixname + GetTwoLenYear(DateTime.Now.AddYears(1)) + // GetTwoLenMonth(DateTime.Now.AddMonths(1)); //使用代码规则管理器生成代码 Old_QH_codename = codeRule.GetCode(QH_Prefixname, DateTime.Now.Year.ToString(), DateTime.Now.AddMonths(1).Month.ToString().PadLeft(2, '0')); New_QH_codename = codeRule.GetCode(QH_Prefixname, DateTime.Now.AddYears(1).Year.ToString(), DateTime.Now.AddMonths(1).Month.ToString().PadLeft(2, '0')); } else { //Old_QH_codename = QH_Prefixname + GetTwoLenYear(DateTime.Now) + GetTwoLenMonth(DateTime.Now); //New_QH_codename = QH_Prefixname + GetTwoLenYear(DateTime.Now.AddYears(1)) + // GetTwoLenMonth(DateTime.Now); //使用代码规则管理器生成代码 Old_QH_codename = codeRule.GetCode(QH_Prefixname, DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString().PadLeft(2, '0')); New_QH_codename = codeRule.GetCode(QH_Prefixname, DateTime.Now.AddYears(1).Year.ToString(), DateTime.Now.Month.ToString().PadLeft(2, '0')); } CM_Commodity CM_Commodity = CommodityDAL.GetModel(Old_QH_codename); if (CM_Commodity == null) { CM_Commodity = new CM_Commodity(); } CM_Commodity.CommodityCode = New_QH_codename; CM_Commodity.MarketDate = DateTime.Parse(System.DateTime.Now.AddDays(1).ToShortDateString()); //若第二天是非交易日则顺延一天 add by 董鹏 2010-03-31 while (!JudgmentIsTrandingDay(CM_Commodity.MarketDate, breedclass)) { CM_Commodity.MarketDate = CM_Commodity.MarketDate.AddDays(1); } //根据确认结果 期货名称等于期货代码 CM_Commodity.CommodityName = New_QH_codename;// QH_breedclassName + New_QH_codename.Substring(New_QH_codename.Length - 4); CM_Commodity.BreedClassID = breedclass; CM_Commodity.GoerScale = decimal.MaxValue; CM_Commodity.LabelCommodityCode = null; CM_Commodity.StockPinYin = null; CM_Commodity.turnovervolume = null; CM_Commodity.IsExpired = (int)Types.IsYesOrNo.No; //新增期货代码时,默认代码没有过期 CM_Commodity.ISSysDefaultCode = (int)Types.IsYesOrNo.Yes; //新增期货代码时,默认是系统代码 #region old //bool _result = CommodityDAL.Add(CM_Commodity); //if (!_result) //{ // LogHelper.WriteDebug("添加代码失败"); // return; //} ////更新代码分配表 //TradeCommodityAssignDAL.Update(Old_QH_codename, New_QH_codename); ////CommodityDAL.Delete(Old_QH_codename); ////根据2009-7-22需求过期代码添加标识 //int isExpired = (int)Types.IsYesOrNo.Yes;//旧代码状态设置为过期 //bool _resultUpdate = CommodityDAL.Update(Old_QH_codename, isExpired); //if (!_resultUpdate) //{ // LogHelper.WriteDebug("更新代码失败"); //} ////调用把期货新增的代码自动添加到可交易商品_撮合机_分配表中的方法 //QHCodeAutoRCTradeCommodityAssign(New_QH_codename, breedclass); #endregion //前面的bool值实际上没有用处,改为直接抛出异常,并增加日志记录 update by 董鹏 2010-03-31 LogHelper.WriteDebug("===生成新代码:" + New_QH_codename); //添加新代码 CommodityDAL.Add(CM_Commodity); LogHelper.WriteDebug("===更新代码分配表"); //更新代码分配表 TradeCommodityAssignDAL.Update(Old_QH_codename, New_QH_codename); LogHelper.WriteDebug("===设置代码过期:" + Old_QH_codename); //旧代码状态设置为过期 int isExpired = (int)Types.IsYesOrNo.Yes; CommodityDAL.Update(Old_QH_codename, isExpired); LogHelper.WriteDebug("===将代码添加到撮合机分配表中"); //如果新代码未分配,将代码添加到撮合机分配表中 QHCodeAutoRCTradeCommodityAssign(New_QH_codename, breedclass); LogHelper.WriteDebug("===新代码:" + New_QH_codename + "完成生成并分配到撮合机,旧代码:" + Old_QH_codename + "完成从撮合机分配表中移除并设为过期。"); } catch (Exception ex) { string errCode = "GL-7002"; string errMsg = "执行更新方法QHCodeUpdata()失败"; //VTException exception = new VTException(errCode, errMsg, ex); //LogHelper.WriteError(exception.ToString(), exception.InnerException); LogHelper.WriteError(errCode + ":" + errMsg, ex); } }