/// <summary>
        /// 根据交易所ID和撮合日期判断是否在交易撮合日期内
        /// </summary>
        /// <param name="bourseTypeID">交易所ID</param>
        /// <param name="marchDate">撮合日期</param>
        /// <returns></returns>
        public bool IsMarchDate(int bourseTypeID, DateTime marchDate)
        {
            string          key          = bourseTypeID.ToString() + "@" + marchDate.ToString("yyyy-MM-dd");
            CM_NotTradeDate notTradeDate = CommonDataCacheProxy.Instanse.GetCacheNotTradeDateByKey(key);

            if (notTradeDate != null)
            {
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// 指定时间是否在交易日内
        /// </summary>
        /// <param name="bourseTypeID"></param>
        /// <param name="aDate"></param>
        /// <returns></returns>
        public static bool IsTradeDate(int bourseTypeID, DateTime aDate)
        {
            bool result = true;

            try
            {
                #region 从缓存中查询即可,指定时间不在非交易日期中就是交易日了
                // IList<CM_NotTradeDate> notTradeDates = ManagementCenterDataAgent.Instanse.GetComonParaInstanse().GetNotTradeDateByBourseTypeID(bourseTypeID);

                //if (notTradeDates == null || notTradeDates.Count == 0)
                //{
                //    //string errCode = "GT-8033";
                //    //string errMsg = "无法从管理中心获取非交易日列表。";
                //    //throw new VTException(errCode, errMsg);
                //    return result;
                //}

                //var dates = from date in notTradeDates
                //            where date.NotTradeDay.HasValue
                //            select date.NotTradeDay.Value;

                //var ds = from d in dates
                //         where d.Year == aDate.Year && d.Month == aDate.Month && d.Day == aDate.Day
                //         select d;

                //if (ds.Count() > 0)
                //    result = false;

                CM_NotTradeDate cm_noDate = CommonDataCacheProxy.Instanse.GetCacheNotTradeDateByKey(bourseTypeID + "@" + aDate.ToString("yyyy-MM-dd"));
                if (cm_noDate != null)
                {
                    result = false;
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.Message, ex);
            }

            return(result);
        }
        /// <summary>
        /// 添加非交易日
        /// </summary>
        /// <param name="year"></param>
        public static void InitNotTrandingDay(int year)
        {
            try
            {
                CM_BourseTypeDAL     BourseTypeDAL   = new CM_BourseTypeDAL();
                List <CM_BourseType> l               = BourseTypeDAL.GetListArray(string.Empty);
                DateTime             startDate       = DateTime.Parse(string.Format("{0}-01-01", year));
                DateTime             endDate         = DateTime.Parse(string.Format("{0}-12-31", year));
                CM_NotTradeDateDAL   NotTradeDateDAL = new CM_NotTradeDateDAL();
                CM_NotTradeDate      NotTradeDate    = new CM_NotTradeDate();

                foreach (CM_BourseType type in l)
                {
                    for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1))
                    {
                        DayOfWeek t = dt.DayOfWeek;
                        if (t == DayOfWeek.Sunday || t == DayOfWeek.Saturday)
                        {
                            List <ManagementCenter.Model.CM_NotTradeDate> l_NotTradeDate =
                                NotTradeDateDAL.GetListArray(string.Format("NotTradeDay='{0}' AND BourseTypeID={1}", dt, type.BourseTypeID));
                            if (l_NotTradeDate == null || l_NotTradeDate.Count < 1)
                            {
                                NotTradeDate.NotTradeDay  = dt;
                                NotTradeDate.BourseTypeID = type.BourseTypeID;
                                NotTradeDateDAL.Add(NotTradeDate);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errMsg = "初始化非交易日失败!";
                LogHelper.WriteError(errMsg, ex);
            }
        }
 /// <summary>
 /// 确定按钮事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnOK_Click(object sender, EventArgs e)
 {
     //通过判断操作类型来进行操作 1:添加操作 2:修改操作
     if (m_EditType == 1)
     {
         #region 添加操作
         try
         {
             CM_NotTradeDate cM_NotTradeDate = new CM_NotTradeDate();
             int             BourseTypeID;
             DateTime        NotTradeDay;
             if (!string.IsNullOrEmpty(this.cmbBourseTypeID.Text))
             {
                 BourseTypeID = ((UComboItem)this.cmbBourseTypeID.SelectedItem).ValueIndex;
                 cM_NotTradeDate.BourseTypeID = BourseTypeID;
             }
             else
             {
                 //cM_NotTradeDate.BourseTypeID = AppGlobalVariable.INIT_INT;
                 ShowMessageBox.ShowInformation("请选择交易所名称!");
                 return;
             }
             if (!string.IsNullOrEmpty(this.dtNotTradeDay.Text))
             {
                 NotTradeDay = Convert.ToDateTime(this.dtNotTradeDay.Text);
                 cM_NotTradeDate.NotTradeDay = NotTradeDay;
             }
             else
             {
                 // cM_NotTradeDate.NotTradeDay = AppGlobalVariable.INIT_DATETIME;
                 ShowMessageBox.ShowInformation("请选择非交易日!");
                 return;
             }
             ManagementCenter.Model.CM_NotTradeDate NotTradeDate = CommonParameterSetCommon.GetNotTradeDate(BourseTypeID, NotTradeDay);
             if (NotTradeDate == null)
             {
                 int result = CommonParameterSetCommon.AddCMNotTradeDate(cM_NotTradeDate);
                 if (result != AppGlobalVariable.INIT_INT)
                 {
                     ShowMessageBox.ShowInformation("添加成功!");
                     this.ClearAll();
                     this.QueryCMNotTradeDate();
                 }
                 else
                 {
                     ShowMessageBox.ShowInformation("添加失败!");
                 }
             }
             else
             {
                 ShowMessageBox.ShowInformation("该非交易日时间已经存在,请勿添加重复数据!");
             }
         }
         catch (Exception ex)
         {
             string      errCode   = "GL-4421";
             string      errMsg    = " 添加交易所类型_非交易日期失败!";
             VTException exception = new VTException(errCode, errMsg, ex);
             LogHelper.WriteError(exception.ToString(), exception.InnerException);
             return;
         }
         #endregion 添加操作
     }
     else if (m_EditType == 2)
     {
         #region 修改操作
         try
         {
             CM_NotTradeDate cM_NotTradeDate = new CM_NotTradeDate();
             if (m_NotTradeDateID == AppGlobalVariable.INIT_INT)
             {
                 ShowMessageBox.ShowInformation("请选择更新数据!");
                 return;
             }
             cM_NotTradeDate.NotTradeDateID = m_NotTradeDateID;
             //cM_NotTradeDate.BourseTypeID = ((UComboItem)this.cmbBourseTypeID.SelectedItem).ValueIndex;
             //cM_NotTradeDate.NotTradeDay = Convert.ToDateTime(this.dtNotTradeDay.Text);
             int      BourseTypeID;
             DateTime NotTradeDay;
             if (!string.IsNullOrEmpty(this.cmbBourseTypeID.Text))
             {
                 BourseTypeID = ((UComboItem)this.cmbBourseTypeID.SelectedItem).ValueIndex;
                 cM_NotTradeDate.BourseTypeID = BourseTypeID;
             }
             else
             {
                 ShowMessageBox.ShowInformation("请选择交易所名称!");
                 return;
             }
             if (!string.IsNullOrEmpty(this.dtNotTradeDay.Text))
             {
                 NotTradeDay = Convert.ToDateTime(this.dtNotTradeDay.Text);
                 cM_NotTradeDate.NotTradeDay = NotTradeDay;
             }
             else
             {
                 // cM_NotTradeDate.NotTradeDay = AppGlobalVariable.INIT_DATETIME;
                 ShowMessageBox.ShowInformation("请选择非交易日期!");
                 return;
             }
             ManagementCenter.Model.CM_NotTradeDate NotTradeDate = CommonParameterSetCommon.GetNotTradeDate(BourseTypeID, NotTradeDay);
             if (NotTradeDate == null)
             {
                 m_Result = CommonParameterSetCommon.UpdateCMNotTradeDate(cM_NotTradeDate);
                 if (m_Result)
                 {
                     ShowMessageBox.ShowInformation("修改成功!");
                     this.ClearAll();
                     //btnAdd.Enabled = true;
                     //btnModify.Enabled = false;
                     m_NotTradeDateID = AppGlobalVariable.INIT_INT;
                 }
                 else
                 {
                     ShowMessageBox.ShowInformation("修改失败!");
                 }
                 this.QueryCMNotTradeDate();
             }
             else
             {
                 ShowMessageBox.ShowInformation("该非交易日时间已经存在,无法修改成重复数据!");
             }
         }
         catch (Exception ex)
         {
             string      errCode   = "GL-4423";
             string      errMsg    = "修改交易所类型_非交易日期失败!";
             VTException exception = new VTException(errCode, errMsg, ex);
             LogHelper.WriteError(exception.ToString(), exception.InnerException);
             return;
         }
         #endregion 修改操作
     }
 }
        /// <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);
        }