/// <summary> /// 类型为第几日(自然日),求最后交易日,如果当天为非交易日,往后顺延 /// </summary> /// <param name="LastTradingDay"></param> /// <param name="code"></param> /// <returns></returns> private static int DeliMonthOfDay(QH_LastTradingDay LastTradingDay, string code) { int day = (int)LastTradingDay.WhatDay; DateTime now = DateTime.Now; int CurrentYear = now.Year; int CurrentMonth = now.Month; DateTime dt = DateTime.Parse(string.Format("{0}-{1}-{2}", CurrentYear, CurrentMonth, day)); while (!JudgmentIsTrandingDay(dt, code)) { dt = dt.AddDays(1); if (dt.Month != CurrentMonth) { break; } } if (dt.Month == CurrentMonth) { return(dt.Day); } return(int.MaxValue); }
/// <summary> /// 获取当前月份最后交易日 /// </summary> /// <param name="code"></param> /// <returns></returns> public static int GetLastTradingDay(string code) { //CM_Commodity commodity = CommonDataCacheProxy.Instanse.GetCacheCommodityByCode(code); //if (commodity == null || commodity.BreedClassID.HasValue == false) //{ // throw new VTException("IsExpireLastedTradeDate", "无法获取期货合约代码对应的商品"); //} //CM_BreedClass cmBreedClass = CommonDataCacheProxy.Instanse.GetCacheCM_BreedClassByKey((int)commodity.BreedClassID); //if (cmBreedClass == null) //{ // throw new VTException("IsExpireLastedTradeDate", "无法获取期货合约代码对应的商品类型"); //} QH_FuturesTradeRules qhFuturesTradeRules = GetQH_FuturesTradeRulesByCommodityCode(code);// FuturesTradeRules.GetFuturesTradeRulesByBreedClassID(cmBreedClass.BreedClassID); if (qhFuturesTradeRules == null) { throw new VTException("IsExpireLastedTradeDate", "无法获取期货商品类型对应的交易规则"); } // QH_LastTradingDay qhLastTradingDay = ManagementCenterDataAgent.Instanse.GetFutureTradeRulesInstanse().GetLastTradingDayByLastTradingDayID((int)qhFuturesTradeRules.LastTradingDayID); QH_LastTradingDay qhLastTradingDay = CommonDataCacheProxy.Instanse.GetCacheQH_LastTradingDayByID((int)qhFuturesTradeRules.LastTradingDayID); if (qhLastTradingDay == null) { throw new VTException("IsExpireLastedTradeDate", "无法获取期货商品类型对应的最后交易日"); } return(GetLastTradingDay(qhLastTradingDay, code)); }
/// <summary> /// 获取当前月份最后交易日 /// </summary> /// <param name="LastTradingDayEntity"></param> /// <param name="code"></param> /// <returns></returns> private static int GetLastTradingDay(QH_LastTradingDay LastTradingDayEntity, string code) { //交易所代码 CM_BourseType _CMBourseType = GetCM_BourseTypeByCommodityCode(code); int bourseTypeID = _CMBourseType.BourseTypeID; switch ((int)LastTradingDayEntity.LastTradingDayTypeID) { //第几天 case (int)Types.QHLastTradingDayType.DeliMonthAndDay: return(DeliMonthOfDay(LastTradingDayEntity, code)); // return int.MaxValue; //倒数或者顺数第几个交易日 case (int)Types.QHLastTradingDayType.DeliMonthAndDownOrShunAndWeek: return(DeliMonthOfTurnOrBackTrandingDay(LastTradingDayEntity, bourseTypeID)); // return int.MaxValue; //交割月份的前一个月份的倒数或者顺数第几个交易日 case (int)Types.QHLastTradingDayType.DeliMonthAgoMonthLastTradeDay: return(DeliMonthOfAgoMonthTradeDay(LastTradingDayEntity, bourseTypeID)); // return int.MaxValue; //第几周的星期几 case (int)Types.QHLastTradingDayType.DeliMonthAndWeek: return(DeliMonthOfWeekDay(LastTradingDayEntity, bourseTypeID)); // return int.MaxValue; } return(0); }
/// <summary> /// 根据品种获取最后交易日实体 /// </summary> /// <param name="breedclass"></param> /// <returns></returns> public QH_LastTradingDay GetLastTradingDayEntity(int breedclass) { QH_FuturesTradeRulesDAL FuturesTradeRulesDAL = new QH_FuturesTradeRulesDAL(); QH_LastTradingDayDAL LastTradingDayDAL = new QH_LastTradingDayDAL(); QH_FuturesTradeRules FuturesTradeRules = FuturesTradeRulesDAL.GetModel(breedclass); QH_LastTradingDay LastTradingDay = LastTradingDayDAL.GetModel((int)FuturesTradeRules.LastTradingDayID); return(LastTradingDay); }
/// <summary> /// 当天为最后交易日,更新和约代码 /// </summary> /// <param name="breedclass">品种ID</param> public void Production(int breedclass) { QH_LastTradingDay LastTradingDayEntity = GetLastTradingDayEntity(breedclass); int LastTradingDay = GetLastTradingDay(LastTradingDayEntity, breedclass); if (System.DateTime.Now.Day == LastTradingDay) { QHCodeUpdata(breedclass, LastTradingDayEntity); } }
/// <summary> /// 类型为第几周的星期几,求最后交易日 /// </summary> /// <param name="LastTradingDay"></param> /// <param name="bourseTypeID"></param> /// <returns></returns> private static int DeliMonthOfWeekDay(QH_LastTradingDay LastTradingDay, int bourseTypeID) { if (LastTradingDay == null) { return(int.MaxValue); } DateTime now = DateTime.Now; int CurrentYear = now.Year; int CurrentMonth = now.Month; return(getDay(CurrentYear, CurrentMonth, (int)LastTradingDay.WhatWeek, (int)LastTradingDay.Week)); }
/// <summary> /// 根据交易日实体和品种得到最后交易日,当前月份为交割月份 /// </summary> /// <param name="LastTradingDayEntity">交易日实体</param> /// <param name="breedclass">品种ID</param> /// <returns></returns> public int GetLastTradingDay(QH_LastTradingDay LastTradingDayEntity, int breedclass) { try { switch ((int)LastTradingDayEntity.LastTradingDayTypeID) { //第几天 case (int)Types.QHLastTradingDayType.DeliMonthAndDay: if (IsTradingMonth(System.DateTime.Now.Month, breedclass)) { return(DeliMonthOfDay(LastTradingDayEntity, breedclass)); } return(int.MaxValue); //倒数或者顺数第几个交易日 case (int)Types.QHLastTradingDayType.DeliMonthAndDownOrShunAndWeek: if (IsTradingMonth(System.DateTime.Now.Month, breedclass)) { return(DeliMonthOfTurnOrBackTrandingDay(LastTradingDayEntity, breedclass)); } return(int.MaxValue); //交割月份的前一个月份的倒数或者顺数第几个交易日 case (int)Types.QHLastTradingDayType.DeliMonthAgoMonthLastTradeDay: if (IsTradingMonth(System.DateTime.Now.AddMonths(1).Month, breedclass)) { return(DeliMonthOfAgoMonthTradeDay(LastTradingDayEntity, breedclass)); } return(int.MaxValue); //第几周的星期几 case (int)Types.QHLastTradingDayType.DeliMonthAndWeek: if (IsTradingMonth(System.DateTime.Now.Month, breedclass)) { return(DeliMonthOfWeekDay(LastTradingDayEntity, breedclass)); } return(int.MaxValue); } } catch (Exception ex) { string errCode = "GL-7001"; string errMsg = "根据类型求和约的最后交易日失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); } return(int.MaxValue); }
/// <summary> /// 类型为交割月份的前一个月份的倒数或者顺数第几个交易日,求最后交易日 /// </summary> /// <param name="LastTradingDay"></param> /// <param name="bourseTypeID"></param> /// <returns></returns> private static int DeliMonthOfAgoMonthTradeDay(QH_LastTradingDay LastTradingDay, int bourseTypeID) { return(DeliMonthOfTurnOrBackTrandingDay(LastTradingDay, bourseTypeID)); }
/// <summary> /// 类型为倒数或者顺数第几个交易日,求最后交易日 /// </summary> /// <param name="LastTradingDay"></param> /// <param name="bourseTypeID"></param> /// <returns></returns> private static int DeliMonthOfTurnOrBackTrandingDay(QH_LastTradingDay LastTradingDay, int bourseTypeID) { int day = (int)LastTradingDay.WhatDay; DateTime now = DateTime.Now; int CurrentYear = now.Year; int CurrentMonth = now.Month; // CM_NotTradeDateDAL NotTradeDateDAL = new CM_NotTradeDateDAL(); int temp = 0; #region 已经有缓存了 ////根据品种获取当前月份里面的非交易日列表 //CM_BreedClass breedClassEntry = CommonDataCacheProxy.Instanse.GetCacheCM_BreedClassByKey(bourseTypeID); //IList<CM_NotTradeDate> List_CM_NotTradeDate = ManagementCenterDataAgent.Instanse.GetComonParaInstanse().GetNotTradeDateByBourseTypeID(breedClassEntry.BourseTypeID.Value); #endregion #region 根据类型求出最后交易日 if (LastTradingDay.Sequence == (int)Types.QHLastTradingDayIsSequence.Order) { for (int i = 1; i <= DateTime.DaysInMonth(CurrentYear, CurrentMonth); i++) { DateTime dt = DateTime.Parse(string.Format("{0}-{1}-{2}", CurrentYear, CurrentMonth, i)); bool falg = false; #region 从缓存中查询 //foreach (CM_NotTradeDate date in List_CM_NotTradeDate) //{ // if (((DateTime)date.NotTradeDay).ToShortDateString() == dt.ToShortDateString()) // { // falg = true; // break; // } //} CM_NotTradeDate cm_noDate = CommonDataCacheProxy.Instanse.GetCacheNotTradeDateByKey(bourseTypeID + "@" + dt.ToString("yyyy-MM-dd")); if (cm_noDate != null) { falg = true; } #endregion if (!falg) { temp = temp + 1; if (temp == day) { return(i); } } } } else { for (int i = DateTime.DaysInMonth(CurrentYear, CurrentMonth); i >= 1; i--) { DateTime dt = DateTime.Parse(string.Format("{0}-{1}-{2}", CurrentYear, CurrentMonth, i)); bool falg = false; #region 从缓存中查询 //foreach (CM_NotTradeDate date in List_CM_NotTradeDate) //{ // if (((DateTime)date.NotTradeDay).ToShortDateString() == dt.ToShortDateString()) // { // falg = true; // break; // } //} CM_NotTradeDate cm_noDate = CommonDataCacheProxy.Instanse.GetCacheNotTradeDateByKey(bourseTypeID + "@" + dt.ToString("yyyy-MM-dd")); if (cm_noDate != null) { falg = true; } #endregion if (!falg) { temp = temp + 1; if (temp == day) { return(i); } } } } #endregion return(int.MaxValue); }
/// <summary> /// 添加或修改最后交易日 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { try { QH_LastTradingDay qHLastTradingDay = new QH_LastTradingDay(); if (!string.IsNullOrEmpty(this.cmbLastTradingDayType.Text)) { qHLastTradingDay.LastTradingDayTypeID = ((UComboItem)this.cmbLastTradingDayType.SelectedItem).ValueIndex; } else { // qHLastTradingDay.LastTradingDayTypeID = AppGlobalVariable.INIT_INT; ShowMessageBox.ShowInformation("最后交易日类型不能为空!"); return; } if (!string.IsNullOrEmpty(this.cmbSequence.Text)) { qHLastTradingDay.Sequence = ((UComboItem)this.cmbSequence.SelectedItem).ValueIndex; } else { qHLastTradingDay.Sequence = AppGlobalVariable.INIT_INT; } if (!string.IsNullOrEmpty(this.cmbWeek.Text)) { qHLastTradingDay.Week = ((UComboItem)this.cmbWeek.SelectedItem).ValueIndex; } else { qHLastTradingDay.Week = AppGlobalVariable.INIT_INT; } if (!string.IsNullOrEmpty(this.speWhatDay.Text)) { qHLastTradingDay.WhatDay = Convert.ToInt32(this.speWhatDay.EditValue); ; } else { qHLastTradingDay.WhatDay = AppGlobalVariable.INIT_INT; } if (!string.IsNullOrEmpty(this.speWhatWeek.Text)) { qHLastTradingDay.WhatWeek = Convert.ToInt32(this.speWhatWeek.EditValue); } else { qHLastTradingDay.WhatWeek = AppGlobalVariable.INIT_INT; } if (LastTradingDayUIEditType == (int)UITypes.EditTypeEnum.AddUI) { int lastTradingDayID = FuturesManageCommon.AddQHLastTradingDay(qHLastTradingDay); if (lastTradingDayID != AppGlobalVariable.INIT_INT) { LastTradingDayID = lastTradingDayID; ShowMessageBox.ShowInformation("添加成功!"); this.ClearAll(); this.DialogResult = DialogResult.OK; this.Close(); } else { ShowMessageBox.ShowInformation("添加失败!"); } } else if (LastTradingDayUIEditType == (int)UITypes.EditTypeEnum.UpdateUI) { switch (this.cmbLastTradingDayType.SelectedIndex) { case (int)GTA.VTS.Common.CommonObject.Types.QHLastTradingDayType.DeliMonthAndDay - 1: qHLastTradingDay.WhatWeek = 0; qHLastTradingDay.Week = 0; qHLastTradingDay.Sequence = 1; //默认顺数 break; case (int)GTA.VTS.Common.CommonObject.Types.QHLastTradingDayType.DeliMonthAndDownOrShunAndWeek - 1: //qHLastTradingDay.WhatDay = 0; qHLastTradingDay.Week = 0; qHLastTradingDay.WhatWeek = 0; break; case (int)GTA.VTS.Common.CommonObject.Types.QHLastTradingDayType.DeliMonthAndWeek - 1: qHLastTradingDay.WhatDay = 0; qHLastTradingDay.Sequence = 1; //默认顺数 break; case (int)GTA.VTS.Common.CommonObject.Types.QHLastTradingDayType.DeliMonthAgoMonthLastTradeDay - 1: qHLastTradingDay.WhatWeek = 0; qHLastTradingDay.Week = 0; //qHLastTradingDay.Sequence = 1;//默认顺数 break; } if (m_UpdateLastTradingDayID != AppGlobalVariable.INIT_INT) { qHLastTradingDay.LastTradingDayID = m_LastTradingDayID; } bool _UpResult = FuturesManageCommon.UpdateQHLastTradingDay(qHLastTradingDay); if (_UpResult) { ShowMessageBox.ShowInformation("修改成功!"); this.DialogResult = DialogResult.OK; this.Close(); } else { ShowMessageBox.ShowInformation("修改失败!"); } } } catch (Exception ex) { string errCode = "GL-5841"; string errMsg = "添加或修改最后交易日失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return;; } }
/// <summary> /// 当前UI是修改最后交易日UI时,初始化控件的值 UpdateInitData /// </summary> private void UpdateInitData() { try { if (UpdateLastTradingDayID != AppGlobalVariable.INIT_INT) { QH_LastTradingDay qH_LastTradingDay = FuturesManageCommon.GetQHLastTradingDayModel(UpdateLastTradingDayID); if (qH_LastTradingDay != null) { if (qH_LastTradingDay.LastTradingDayTypeID != 0) { foreach (object item in this.cmbLastTradingDayType.Properties.Items) { if (((UComboItem)item).ValueIndex == qH_LastTradingDay.LastTradingDayTypeID) { this.cmbLastTradingDayType.SelectedItem = item; break; } } } else { this.cmbLastTradingDayType.SelectedIndex = 0; } if (qH_LastTradingDay.Week != 0) { foreach (object item in this.cmbWeek.Properties.Items) { if (((UComboItem)item).ValueIndex == qH_LastTradingDay.Week) { this.cmbWeek.SelectedItem = item; break; } } } else { this.cmbWeek.SelectedIndex = 0; } if (qH_LastTradingDay.Sequence != 0) { foreach (object item in this.cmbSequence.Properties.Items) { if (((UComboItem)item).ValueIndex == qH_LastTradingDay.Sequence) { this.cmbSequence.SelectedItem = item; break; } } } else { this.cmbSequence.SelectedIndex = 0; } this.speWhatDay.Text = qH_LastTradingDay.WhatDay.ToString(); this.speWhatWeek.Text = qH_LastTradingDay.WhatWeek.ToString(); m_LastTradingDayID = qH_LastTradingDay.LastTradingDayID; } } } catch (Exception ex) { string errCode = "GL-5842"; string errMsg = "当前UI是修改最后交易日UI时,初始化控件的值失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return; } }
/// <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); } }
/// <summary> /// 类型为交割月份的前一个月份的倒数或者顺数第几个交易日,求最后交易日 /// </summary> /// <param name="LastTradingDay"></param> /// <param name="breedclass"></param> /// <returns></returns> private int DeliMonthOfAgoMonthTradeDay(QH_LastTradingDay LastTradingDay, int breedclass) { return(DeliMonthOfTurnOrBackTrandingDay(LastTradingDay, breedclass)); }
/// <summary> /// 类型为倒数或者顺数第几个交易日,求最后交易日 /// </summary> /// <param name="LastTradingDay"></param> /// <param name="breedclass"></param> /// <returns></returns> private int DeliMonthOfTurnOrBackTrandingDay(QH_LastTradingDay LastTradingDay, int breedclass) { int day = (int)LastTradingDay.WhatDay; DateTime now = DateTime.Now; int CurrentYear = now.Year; int CurrentMonth = now.Month; CM_NotTradeDateDAL NotTradeDateDAL = new CM_NotTradeDateDAL(); int temp = 0; //根据品种获取当前月份里面的非交易日列表 List <CM_NotTradeDate> List_CM_NotTradeDate = NotTradeDateDAL.GetListArrayByBreedClassID(breedclass); #region 根据类型求出最后交易日 if ((int)LastTradingDay.Sequence == (int)Types.QHLastTradingDayIsSequence.Order) { for (int i = 1; i <= System.DateTime.DaysInMonth(CurrentYear, CurrentMonth); i++) { DateTime dt = DateTime.Parse(string.Format("{0}-{1}-{2}", CurrentYear, CurrentMonth, i)); bool falg = false; foreach (CM_NotTradeDate date in List_CM_NotTradeDate) { if (((DateTime)date.NotTradeDay).ToShortDateString() == dt.ToShortDateString()) { falg = true; break; } } if (!falg) { temp = temp + 1; if (temp == day) { return(i); } } } } else { for (int i = System.DateTime.DaysInMonth(CurrentYear, CurrentMonth); i >= 1; i--) { DateTime dt = DateTime.Parse(string.Format("{0}-{1}-{2}", CurrentYear, CurrentMonth, i)); bool falg = false; foreach (CM_NotTradeDate date in List_CM_NotTradeDate) { if (((DateTime)date.NotTradeDay).ToShortDateString() == dt.ToShortDateString()) { falg = true; break; } } if (!falg) { temp = temp + 1; if (temp == day) { return(i); } } } } #endregion return(int.MaxValue); }
/// <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); } }