/// <summary> /// 根据品种标识返回合约交割月份 /// </summary> /// <param name="breedClassID">品种标识</param> /// <returns></returns> public List <ManagementCenter.Model.QH_AgreementDeliveryMonth> GetQHAgreementDeliveryMonth(int breedClassID) { try { QH_AgreementDeliveryMonthDAL qHAgreementDeliveryMonthDAL = new QH_AgreementDeliveryMonthDAL(); return(qHAgreementDeliveryMonthDAL.GetListArray(string.Format("BreedClassID={0}", breedClassID))); } catch (Exception ex) { string errCode = "GL-6062"; string errMsg = "根据品种标识返回合约交割月份失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(null); } }
/// <summary> /// 判断月份是否为交割月 /// </summary> /// <param name="month"></param> /// <param name="breedclass"></param> /// <returns></returns> public bool IsTradingMonth(int month, int breedclass) { QH_AgreementDeliveryMonthDAL AgreementDeliveryMonthDAL = new QH_AgreementDeliveryMonthDAL(); List <QH_AgreementDeliveryMonth> L = AgreementDeliveryMonthDAL.GetListArray(string.Format("BreedClassID={0}", breedclass)); bool falg = false; foreach (QH_AgreementDeliveryMonth AgreementDeliveryMonth in L) { if ((int)AgreementDeliveryMonth.MonthID == month || (int)AgreementDeliveryMonth.MonthID == 13) { falg = true; break; } } return(falg); }
/// <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); } } }
/// <summary> ///根据品种标识,删除期货品种交易规则(规则相关表全部删除) /// </summary> /// <param name="BreedClassID">品种标识</param> /// <returns></returns> public bool DeleteFuturesTradeRulesAboutAll(int BreedClassID) { QH_FuturesTradeRulesDAL qHFuturesTradeRulesDAL = new QH_FuturesTradeRulesDAL(); QH_AgreementDeliveryMonthDAL qH_AgreementDeliveryMonthDAL = new QH_AgreementDeliveryMonthDAL(); QH_ConsignQuantumDAL qH_ConsignQuantumDAL = new QH_ConsignQuantumDAL(); QH_SingleRequestQuantityDAL qH_SingleRequestQuantityDAL = new QH_SingleRequestQuantityDAL(); QH_LastTradingDayDAL qH_LastTradingDayDAL = new QH_LastTradingDayDAL(); DbConnection Conn = null; Database db = DatabaseFactory.CreateDatabase(); Conn = db.CreateConnection(); if (Conn.State != ConnectionState.Open) { Conn.Open(); } DbTransaction Tran = Conn.BeginTransaction(); try { int ConsignQuantumID = AppGlobalVariable.INIT_INT; int LastTradingDayID = AppGlobalVariable.INIT_INT; QH_FuturesTradeRules qHFuturesTradeRules = new QH_FuturesTradeRules(); qHFuturesTradeRules = qHFuturesTradeRulesDAL.GetModel(BreedClassID); if (qHFuturesTradeRules != null) { if (!string.IsNullOrEmpty(qHFuturesTradeRules.ConsignQuantumID.ToString())) { ConsignQuantumID = Convert.ToInt32(qHFuturesTradeRules.ConsignQuantumID); } if (!string.IsNullOrEmpty(qHFuturesTradeRules.LastTradingDayID.ToString())) { LastTradingDayID = Convert.ToInt32(qHFuturesTradeRules.LastTradingDayID); } if (ConsignQuantumID != AppGlobalVariable.INIT_INT) { if (!qH_SingleRequestQuantityDAL.DeleteSingleRQByConsignQuantumID(ConsignQuantumID, Tran, db)) { Tran.Rollback(); return(false); } } List <Model.QH_AgreementDeliveryMonth> qHAgreementDeliveryM = qH_AgreementDeliveryMonthDAL.GetListArray(string.Format("BreedClassID={0}", BreedClassID), Tran, db); foreach (Model.QH_AgreementDeliveryMonth MonthID in qHAgreementDeliveryM) { if (!qH_AgreementDeliveryMonthDAL.Delete((Int32)MonthID.MonthID, BreedClassID)) //?处理 { Tran.Rollback(); return(false); } } if (!qHFuturesTradeRulesDAL.Delete(BreedClassID, Tran, db)) { Tran.Rollback(); return(false); } if (ConsignQuantumID != AppGlobalVariable.INIT_INT) { if (!qH_ConsignQuantumDAL.Delete(ConsignQuantumID, Tran, db)) { Tran.Rollback(); return(false); } } if (LastTradingDayID != AppGlobalVariable.INIT_INT) { if (!qH_LastTradingDayDAL.Delete(LastTradingDayID, Tran, db)) { Tran.Rollback(); return(false); } } } Tran.Commit(); return(true); } catch (Exception ex) { Tran.Rollback(); string errCode = "GL-6004"; 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> public void CheckCodeIsExpired() { try { QH_AgreementDeliveryMonthDAL AgreementDeliveryMonthDAL = new QH_AgreementDeliveryMonthDAL(); //一般品种,交割月为1~12月份 QH_FuturesTradeRulesDAL FuturesTradeRulesDAL = new QH_FuturesTradeRulesDAL(); //获取交易规则 List <QH_FuturesTradeRules> L = FuturesTradeRulesDAL.GetListArray(string.Empty); if (L != null) { foreach (QH_FuturesTradeRules FuturesTradeRules in L) { #region old //List<QH_AgreementDeliveryMonth> listQHAgreDeMonth = AgreementDeliveryMonthDAL.GetListArray(string.Format("BreedClassID={0}", FuturesTradeRules.BreedClassID)); //foreach (QH_AgreementDeliveryMonth AgreementDeliveryMonth in listQHAgreDeMonth) //{ // if ((int)AgreementDeliveryMonth.MonthID != 13) // { // Production(FuturesTradeRules.BreedClassID); // } //} #endregion //交割月份要么等于13,要么不等于,因此不需循环,造成重复执行多遍 //update by 董鹏 2010-03-31 //获取交易规则中的交割月份 List <QH_AgreementDeliveryMonth> listQHAgreDeMonth = AgreementDeliveryMonthDAL.GetListArray(string.Format("BreedClassID={0} and MonthID!={1}", FuturesTradeRules.BreedClassID, 13)); if (listQHAgreDeMonth.Count != 0) { Production(FuturesTradeRules.BreedClassID); } } } else { LogHelper.WriteDebug("期货交易规则数据为空"); } #region old ////特殊处理,本月下月随后的两个季度月份 ////QH_AgreementDeliveryMonthDAL AgreementDeliveryMonthDAL = new QH_AgreementDeliveryMonthDAL(); //List<QH_AgreementDeliveryMonth> L_m = AgreementDeliveryMonthDAL.GetListArray(string.Empty); //if (L_m != null) //{ // foreach (QH_AgreementDeliveryMonth AgreementDeliveryMonth in L_m) // { // if ((int)AgreementDeliveryMonth.MonthID == 13) // { // QH_LastTradingDay LastTradingDayEntity = // GetLastTradingDayEntity((int)AgreementDeliveryMonth.BreedClassID); // if (System.DateTime.Now.Day == // GetLastTradingDay(LastTradingDayEntity, (int)AgreementDeliveryMonth.BreedClassID)) // { // SpecialQHCodeUpdate((int)AgreementDeliveryMonth.BreedClassID); // } // } // } //} //else //{ // LogHelper.WriteDebug("期货合约交割月份数据为空"); //} #endregion //update by 董鹏 2010-03-31 //特殊处理,本月下月随后的两个季度月份 //QH_AgreementDeliveryMonthDAL AgreementDeliveryMonthDAL = new QH_AgreementDeliveryMonthDAL(); List <QH_AgreementDeliveryMonth> L_m = AgreementDeliveryMonthDAL.GetListArray(string.Format("MonthID={0}", 13)); if (L_m != null) { foreach (QH_AgreementDeliveryMonth AgreementDeliveryMonth in L_m) { QH_LastTradingDay LastTradingDayEntity = GetLastTradingDayEntity((int)AgreementDeliveryMonth.BreedClassID); if (System.DateTime.Now.Day == GetLastTradingDay(LastTradingDayEntity, (int)AgreementDeliveryMonth.BreedClassID)) { SpecialQHCodeUpdate((int)AgreementDeliveryMonth.BreedClassID); } } } else { LogHelper.WriteDebug("期货合约交割月份数据为空"); } } catch (Exception ex) { string errCode = "GL-7000"; string errMsg = "更新期货和约代码失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); } }