/// <summary> /// 插入银行美容活动场次配置 /// </summary> /// <param name="roundConfig"></param> /// <returns></returns> public static bool InsertBankMRActivityRoundConfig(SqlConnection conn, BankMRActivityRoundConfig roundConfig) { var sql = @"INSERT INTO Tuhu_groupon..BankMRActivityRoundConfig ( ActivityId , LimitCount , StartTime , EndTime , IsActive ) VALUES ( @ActivityId , @LimitCount , @StartTime , @EndTime , @IsActive )"; var sqlParameters = new SqlParameter[] { new SqlParameter("@ActivityId", roundConfig.ActivityId), new SqlParameter("@LimitCount", roundConfig.LimitCount), new SqlParameter("@StartTime", roundConfig.StartTime), new SqlParameter("@EndTime", roundConfig.EndTime), new SqlParameter("@IsActive", roundConfig.IsActive) }; return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, sqlParameters) > 0); }
/// <summary> /// 根据活动场次ID查询活动场次 /// </summary> /// <param name="pkid"></param> /// <returns></returns> public static BankMRActivityRoundConfig GetBankMRActivityRoundConfigByPKID(int pkid) { BankMRActivityRoundConfig result = null; try { result = TuhuGrouponDbScopeManagerReadOnly.Execute(conn => BankMRActivityDal.SelectBankMRActivityRoundConfigByPKID(conn, pkid)); } catch (Exception ex) { Logger.Error(ex.Message, ex); }; return(result); }
/// <summary> /// 更新银行美容活动场次配置 /// </summary> /// <param name="roundConfig">活动场次配置</param> /// <returns></returns> public bool UpdateBankMRActivityRoundConfig(BankMRActivityRoundConfig roundConfig) { var result = false; try { TuhuGrouponDbScopeManager.Execute(conn => result = BankMRActivityDal.UpdateBankMRActivityRoundConfig(conn, roundConfig)); } catch (Exception ex) { Logger.Error(ex.Message, ex); }; return(result); }
/// <summary> /// 更新银行美容活动场次配置 /// </summary> /// <param name="roundConfig"></param> /// <returns></returns> public static bool UpdateBankMRActivityRoundConfig(SqlConnection conn, BankMRActivityRoundConfig roundConfig) { var sql = @"UPDATE Tuhu_groupon..BankMRActivityRoundConfig SET ActivityId = @ActivityId , LimitCount = @LimitCount , StartTime = @StartTime , EndTime = @EndTime , IsActive = @IsActive WHERE PKID = @PKID"; var sqlParameters = new SqlParameter[] { new SqlParameter("@ActivityId", roundConfig.ActivityId), new SqlParameter("@LimitCount", roundConfig.LimitCount), new SqlParameter("@StartTime", roundConfig.StartTime), new SqlParameter("@EndTime", roundConfig.EndTime), new SqlParameter("@IsActive", roundConfig.IsActive), new SqlParameter("@PKID", roundConfig.PKID) }; return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, sqlParameters) > 0); }
/// <summary> /// 生成银行美容活动场次 /// </summary> /// <returns></returns> public bool GenerateBankMRActivityRound(SqlConnection conn, BankMRActivityConfig config) { var result = false; var startTime = config.StartTime; var endTime = config.StartTime; switch (config.RoundCycleType) { case "year": while (endTime <= config.EndTime) { endTime = endTime.AddYears(1); if (endTime > config.EndTime) { endTime = config.EndTime; } var roundConfig = new BankMRActivityRoundConfig() { ActivityId = config.ActivityId, StartTime = startTime, EndTime = endTime, IsActive = true }; result = BankMRActivityDal.InsertBankMRActivityRoundConfig(conn, roundConfig); if (!result) { return(result); } startTime = endTime = endTime.AddDays(1); } break; case "quarter": while (endTime <= config.EndTime) { switch (startTime.Month) { case 1: case 2: case 3: endTime = new DateTime(startTime.Year, 3, 31); if (endTime > config.EndTime) { endTime = config.EndTime; } result = BankMRActivityDal.InsertBankMRActivityRoundConfig(conn, new BankMRActivityRoundConfig() { ActivityId = config.ActivityId, StartTime = startTime, EndTime = endTime, IsActive = true }); if (!result) { return(result); } startTime = endTime = endTime.AddDays(1); break; case 4: case 5: case 6: endTime = new DateTime(startTime.Year, 7, 1); endTime = endTime.AddDays(-1); if (endTime > config.EndTime) { endTime = config.EndTime; } result = BankMRActivityDal.InsertBankMRActivityRoundConfig(conn, new BankMRActivityRoundConfig() { ActivityId = config.ActivityId, StartTime = startTime, EndTime = endTime, IsActive = true }); if (!result) { return(result); } startTime = endTime = endTime.AddDays(1); break; case 7: case 8: case 9: endTime = new DateTime(startTime.Year, 10, 1); endTime = endTime.AddDays(-1); if (endTime > config.EndTime) { endTime = config.EndTime; } result = BankMRActivityDal.InsertBankMRActivityRoundConfig(conn, new BankMRActivityRoundConfig() { ActivityId = config.ActivityId, StartTime = startTime, EndTime = endTime, IsActive = true }); if (!result) { return(result); } startTime = endTime = endTime.AddDays(1); break; case 10: case 11: case 12: endTime = new DateTime(startTime.Year, 12, 31); if (endTime > config.EndTime) { endTime = config.EndTime; } result = BankMRActivityDal.InsertBankMRActivityRoundConfig(conn, new BankMRActivityRoundConfig() { ActivityId = config.ActivityId, StartTime = startTime, EndTime = endTime, IsActive = true }); if (!result) { return(result); } startTime = endTime = endTime.AddDays(1); break; } } break; case "month": while (endTime <= config.EndTime) { var monthIndex = endTime.Month; while (monthIndex == endTime.Month) { endTime = endTime.AddDays(1); if (endTime > config.EndTime) { break; } } ; var roundConfig = new BankMRActivityRoundConfig() { ActivityId = config.ActivityId, StartTime = startTime, EndTime = endTime.AddDays(-1), IsActive = true }; result = BankMRActivityDal.InsertBankMRActivityRoundConfig(conn, roundConfig); if (!result) { return(result); } startTime = endTime; } break; case "week": while (endTime <= config.EndTime) { while (((int)endTime.DayOfWeek) > 0) { endTime = endTime.AddDays(1); } ; if (endTime > config.EndTime) { endTime = config.EndTime; } var roundConfig = new BankMRActivityRoundConfig() { ActivityId = config.ActivityId, StartTime = startTime, EndTime = endTime, IsActive = true }; result = BankMRActivityDal.InsertBankMRActivityRoundConfig(conn, roundConfig); if (!result) { return(result); } startTime = endTime = endTime.AddDays(1); } break; } return(result); }