/// <summary> /// 添加交易所类型和交易时间 /// </summary> /// <param name="cmBourseType">交易所类型实体</param> /// <param name="cmTradeTimeList">交易时间实体集合</param> /// <returns></returns> public int AddCMBourseTypeAndTradeTime(CM_BourseType cmBourseType, List <CM_TradeTime> cmTradeTimeList) { var cmBourseTypeDal = new CM_BourseTypeDAL(); var cmTradeTimeDal = new CM_TradeTimeDAL(); DbConnection Conn = null; Database db = DatabaseFactory.CreateDatabase(); Conn = db.CreateConnection(); if (Conn.State != ConnectionState.Open) { Conn.Open(); } DbTransaction tran = Conn.BeginTransaction(); //交易所类型ID int BourseTypeID = AppGlobalVariable.INIT_INT; //交易时间ID int TradeTimeID = AppGlobalVariable.INIT_INT; try { if (cmBourseType != null && cmTradeTimeList.Count > 0) { BourseTypeID = cmBourseTypeDal.Add(cmBourseType, tran, db); if (BourseTypeID == AppGlobalVariable.INIT_INT) { tran.Rollback(); } foreach (CM_TradeTime _cmTradeTime in cmTradeTimeList) { _cmTradeTime.BourseTypeID = BourseTypeID; TradeTimeID = cmTradeTimeDal.Add(_cmTradeTime, tran, db); if (TradeTimeID == AppGlobalVariable.INIT_INT) { tran.Rollback(); break; } } } //根据交易所类型ID获取并查找最早的交易开始时间和最晚的交易结束时间 List <CM_TradeTime> cmTTimeList = cmTradeTimeDal.GetListArray(string.Format("BourseTypeID={0}", BourseTypeID), tran, db); if (cmTTimeList.Count > 0) { DateTime _tempStartTime = AppGlobalVariable.INIT_DATETIME; DateTime _tempEndTime = AppGlobalVariable.INIT_DATETIME; bool isStartTime = true; //标志开始值是否改变 bool isEndTime = true; //标志结束值是否改变 for (int i = 0; i < cmTTimeList.Count; i++) { if (isStartTime) { _tempStartTime = (DateTime)cmTTimeList[0].StartTime; } if (isEndTime) { _tempEndTime = (DateTime)cmTTimeList[0].EndTime; } if (_tempStartTime > (DateTime)cmTTimeList[i].StartTime) { _tempStartTime = (DateTime)cmTTimeList[i].StartTime; isStartTime = false; } if (_tempEndTime < (DateTime)cmTTimeList[i].EndTime) { _tempEndTime = (DateTime)cmTTimeList[i].EndTime; isEndTime = false; } } bool result = cmBourseTypeDal.Update(BourseTypeID, _tempStartTime, _tempEndTime, tran, db); if (!result) { tran.Rollback(); } tran.Commit(); } return(BourseTypeID); } catch (Exception ex) { tran.Rollback(); string errCode = "GL-4708"; string errMsg = "添加交易所类型和交易时间失败!"; var exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(AppGlobalVariable.INIT_INT); } finally { if (Conn.State == ConnectionState.Open) { Conn.Close(); } } }
/// <summary> /// 添加交易时间 /// </summary> /// <param name="model">交易所类型_交易时间实体</param> /// <returns></returns> public int AddCMTradeTime(ManagementCenter.Model.CM_TradeTime model) { DbConnection Conn = null; Database db = DatabaseFactory.CreateDatabase(); Conn = db.CreateConnection(); if (Conn.State != ConnectionState.Open) { Conn.Open(); } DbTransaction tran = Conn.BeginTransaction(); try { CM_TradeTimeDAL cM_TradeTimeDAL = new CM_TradeTimeDAL(); CM_BourseTypeDAL cM_BourseTypeDAL = new CM_BourseTypeDAL(); //int tradeTimeID = (int)model.TradeTimeID; int addTTimeResult = AppGlobalVariable.INIT_INT; //交易所类型ID int bourseTypeID = AppGlobalVariable.INIT_INT; bourseTypeID = (int)model.BourseTypeID; addTTimeResult = cM_TradeTimeDAL.Add(model, tran, db); if (addTTimeResult == AppGlobalVariable.INIT_INT) { tran.Rollback(); return(AppGlobalVariable.INIT_INT); } if (bourseTypeID != AppGlobalVariable.INIT_INT) { //根据交易所类型ID获取并查找最早的交易开始时间和最晚的交易结束时间 List <CM_TradeTime> cmTTimeList = cM_TradeTimeDAL.GetListArray(string.Format("BourseTypeID={0}", bourseTypeID), tran, db); if (cmTTimeList.Count > 0) { CM_TradeTime cmTradeTime = CompareTradeTime(cmTTimeList); if (cmTradeTime != null) { bool result = cM_BourseTypeDAL.Update(bourseTypeID, (DateTime)cmTradeTime.StartTime, (DateTime)cmTradeTime.EndTime, tran, db); if (!result) { tran.Rollback(); return(AppGlobalVariable.INIT_INT); } } tran.Commit(); } } return(addTTimeResult); } catch (Exception ex) { tran.Rollback(); string errCode = "GL-4740"; string errMsg = "添加交易时间失败!"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception.InnerException); return(AppGlobalVariable.INIT_INT); } finally { if (Conn.State == ConnectionState.Open) { Conn.Close(); } } }