Esempio n. 1
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);
        }