public static void GroupIntoPeriods_ForEmptyInput_ReturnsEmptyOuput()
    {
        var expenses = new List <Expense>();
        var periods  = PeriodSplitter.GroupIntoPeriods(expenses, 18);

        Assert.AreEqual(0, periods.Count());
    }
Exemple #2
0
        public TimeLine CreateTimeLine(PeriodSplitter splitter, PeriodNameFormatter PeriodNameFormatter,
                                       BackgroundFormatter backgroundFormatter, string timeLineName, Brush timeLineColor)
        {
            if (splitter.MaxDate != GanttData.MaxDate || splitter.MinDate != GanttData.MinDate)
            {
                throw new ArgumentException("The timeline must have the same max and min -date as the chart");
            }

            var timeLineParts = splitter.Split();

            TimeLine timeline = new TimeLine();

            timeline.Name            = timeLineName;
            timeline.BackgroundColor = timeLineColor;
            foreach (var p in timeLineParts)
            {
                TimeLineItem item = new TimeLineItem()
                {
                    Name = PeriodNameFormatter(p), Start = p.Start, End = p.End.AddSeconds(-1)
                };
                item.BackgroundColor = backgroundFormatter(item);
                timeline.Items.Add(item);
            }

            ganttChartData.TimeLines.Add(timeline);
            return(timeline);
        }
    public static void GroupIntoPeriods_OneExpense_ReturnsInOnePeriod()
    {
        var expenses = new List <Expense>
        {
            new Expense(1, ExpenseType.CellPhoneCall, DateTime.Now)
        };
        var periods = PeriodSplitter.GroupIntoPeriods(expenses, 18);

        Assert.AreEqual(1, periods.Count());
        Assert.AreSame(expenses.First(), periods.First().Expenses.First());
    }
    public static void GroupIntoPeriods_TwoExprensesFromOnePeriod_ReturnsInOnePeriodWith2Expenses()
    {
        var expenses = new List <Expense>
        {
            new Expense(1, ExpenseType.CellPhoneCall, new DateTime(2018, 10, 10)),
            new Expense(1, ExpenseType.CellPhoneCall, new DateTime(2018, 10, 11))
        };
        var periods = PeriodSplitter.GroupIntoPeriods(expenses, 18);

        Assert.AreEqual(1, periods.Count());
        Assert.AreSame(expenses.First(), periods.First().Expenses.First());
    }
    public static void GroupIntoPeriods_TwoExprensesAreFromTwoPeriods_Returns2PeriodsWith1ExpensePerPeriod()
    {
        var expenses = new List <Expense>
        {
            new Expense(1, ExpenseType.CellPhoneCall, DateTime.Now),
            new Expense(1, ExpenseType.CellPhoneCall, DateTime.Now.AddDays(35))
        };
        var periods = PeriodSplitter.GroupIntoPeriods(expenses, 18);

        Assert.AreEqual(2, periods.Count());
        Assert.AreSame(expenses.First(), periods.First().Expenses.First());
        Assert.AreSame(expenses.Last(), periods.Last().Expenses.First());
    }
    public static void GroupIntoPeriods_MultipleExpensesFromTwoPeriods_Returns2PeriodsWithCorrectlyAssignedExpenses()
    {
        var period1expense1 = new Expense(1, ExpenseType.CellPhoneCall, new DateTime(2018, 10, 10));
        var period1expense2 = new Expense(1, ExpenseType.CellPhoneCall, new DateTime(2018, 10, 11));
        var period2expense1 = new Expense(1, ExpenseType.CellPhoneCall, new DateTime(2018, 10, 19));
        var expenses        = new List <Expense>
        {
            period1expense1,
            period1expense2,
            period2expense1,
        };
        var periods = PeriodSplitter.GroupIntoPeriods(expenses, 18);

        Assert.AreEqual(2, periods.Count());
        Assert.AreEqual(2, periods.First().Expenses.Count());
        Assert.AreEqual(1, periods.Last().Expenses.Count());
        Assert.AreSame(period1expense1, periods.First().Expenses.First());
        Assert.AreSame(period1expense2, periods.First().Expenses.Last());
        Assert.AreSame(period2expense1, periods.Last().Expenses.First());
    }
Exemple #7
0
        public TimeLine CreateTimeLine(PeriodSplitter splitter, PeriodNameFormatter PeriodNameFormatter)
        {
            if (splitter.MaxDate != GanttData.MaxDate || splitter.MinDate != GanttData.MinDate)
            {
                throw new ArgumentException("The timeline must have the same max and min -date as the chart");
            }

            var timeLineParts = splitter.Split();

            var timeline = new TimeLine();

            foreach (var p in timeLineParts)
            {
                timeline.Items.Add(new TimeLineItem()
                {
                    Name = PeriodNameFormatter(p), Start = p.Start, End = p.End.AddSeconds(-1)
                });
            }

            ganttChartData.TimeLines.Add(timeline);
            return(timeline);
        }
Exemple #8
0
        internal static string ClubPeriodOrderCommunicate(string userId, int QID, int OID, string OrderName, string channelAccessToken)
        {
            PeriodOrderTmp periodOrderTmp = new PeriodOrderTmp(userId);

            periodOrderTmp.SelectAllByUserID();
            OrderInfo orderinfo = new OrderInfo(); //準備輸入SQL

            switch (QID)                           //根據QID不同初始化clubOrderAndMyOrder
            {
            case 251:
                periodOrderTmp.ClubIDSelectByUserID();    //撈取ClubID
                orderinfo = new OrderInfo(periodOrderTmp.ClubID, OrderName);
                break;

            default:
                break;
            }

            //切割週期時間
            DateTime      st1      = periodOrderTmp.StartDate.Add(periodOrderTmp.StartTime); //第一次開單時間點
            DateTime      et1      = periodOrderTmp.EndDate.Add(periodOrderTmp.StartTime);   //最後一次開單時間點
            DateTime      st2      = periodOrderTmp.StartDate.Add(periodOrderTmp.EndTime);   //第一次收單時間點
            DateTime      et2      = periodOrderTmp.EndDate.Add(periodOrderTmp.EndTime);     //最後一次收單時間點
            List <string> weekList = new List <string>();

            if (periodOrderTmp.Monday == "Y")
            {
                weekList.Add("Monday");
            }
            if (periodOrderTmp.Tuesday == "Y")
            {
                weekList.Add("Tuesday");
            }
            if (periodOrderTmp.Wednesday == "Y")
            {
                weekList.Add("Wednesday");
            }
            if (periodOrderTmp.Thursday == "Y")
            {
                weekList.Add("Thursday");
            }
            if (periodOrderTmp.Friday == "Y")
            {
                weekList.Add("Friday");
            }
            if (periodOrderTmp.Saturday == "Y")
            {
                weekList.Add("Saturday");
            }
            if (periodOrderTmp.Sunday == "Y")
            {
                weekList.Add("Sunday");
            }
            List <DateTime> dateTimes  = PeriodSplitter.Cut(st1, et1, weekList); //得到每次的開單時間點
            List <DateTime> dateTimes2 = PeriodSplitter.Cut(st2, et2, weekList); //得到每次的收單時間點

            orderinfo.OrderType   = "Period";
            orderinfo.OrderStatus = "wait";


            //開始撈取使用者選擇的複數商店
            ShopListTemp        shopListTemp        = new ShopListTemp(userId);
            List <ShopListTemp> shopListTemps       = shopListTemp.SelectByUserID(); //選取的商店清單
            List <ShopListTemp> randomshopListTemps = new List <ShopListTemp>();     //準備一個要裝進符合選取天數的清單

            //將randomshopListTemps打亂
            while (randomshopListTemps.Count <= dateTimes.Count)
            {
                for (int i = 0; i < shopListTemps.Count; i++)
                {
                    Swap(shopListTemps);
                }
                for (int i = 0; i < shopListTemps.Count; i++)
                {
                    randomshopListTemps.Add(shopListTemps[i]);
                }
            }

            int    result = 0;
            int    count  = 0; //用來檢查迴圈有沒有跑完
            string clubOrderAndMyOrderID;

            switch (QID)
            {
            case 251:
                clubOrderAndMyOrderID = orderinfo.OrderID;
                for (int i = 0; i < dateTimes.Count; i++)
                {
                    orderinfo.StartTime        = dateTimes[i];
                    orderinfo.EndTime          = dateTimes2[i];
                    orderinfo.ShopID           = randomshopListTemps[i].ShopID;
                    orderinfo.OrderPartitionID = "COP" + clubOrderAndMyOrderID + $"-{ dateTimes[i].ToString("yyyyMMdd")}";
                    result = orderinfo.InserClubOrderTableToSQL();
                    if (result <= 0)
                    {
                        break;
                    }
                    count++;
                }

                break;

            default:
                break;
            }
            if (count == dateTimes.Count)
            {
                UserStatus userStatus = new UserStatus(userId);
                userStatus.InitializeUserStatusByUserID();
                periodOrderTmp = new PeriodOrderTmp(userId);
                periodOrderTmp.UpdateInitialPeriodOrderTmp();
                shopListTemp.DeleteByUserID();

                return("訂單建立成功");
            }
            else
            {
                return("訂單建立失敗");
            }
        }
Exemple #9
0
        internal static string MyPeriodOrderCommunicate(string userId, int QID, int OID, string OrderName, string channelAccessToken)
        {
            PeriodOrderTmp periodOrderTmp = new PeriodOrderTmp(userId);

            periodOrderTmp.SelectAllByUserID();
            OrderInfo orderinfo = new OrderInfo(); //準備輸入SQL

            switch (QID)                           //根據QID不同初始化clubOrderAndMyOrder
            {
            case 211:
                orderinfo = new OrderInfo(userId, OrderName);
                break;

            default:
                break;
            }


            //切割週期時間
            DateTime st1 = periodOrderTmp.StartDate.Add(periodOrderTmp.StartTime); //第一次開單時間點
            DateTime et1 = periodOrderTmp.EndDate.Add(periodOrderTmp.StartTime);   //最後一次開單時間點
            DateTime st2 = periodOrderTmp.StartDate.Add(periodOrderTmp.EndTime);   //第一次收單時間點
            DateTime et2 = periodOrderTmp.EndDate.Add(periodOrderTmp.EndTime);     //最後一次收單時間點

            if (DateTimeChecker.DateTimeCheckIsEarlierThanNow(st1))                //週期單開始時間點若是比現在時間點早則往後一天
            {
                st1 = st1.AddDays(1);
                st2 = st2.AddDays(1);
            }


            List <string> weekList = new List <string>();

            if (periodOrderTmp.Monday == "Y")
            {
                weekList.Add("Monday");
            }
            if (periodOrderTmp.Tuesday == "Y")
            {
                weekList.Add("Tuesday");
            }
            if (periodOrderTmp.Wednesday == "Y")
            {
                weekList.Add("Wednesday");
            }
            if (periodOrderTmp.Thursday == "Y")
            {
                weekList.Add("Thursday");
            }
            if (periodOrderTmp.Friday == "Y")
            {
                weekList.Add("Friday");
            }
            if (periodOrderTmp.Saturday == "Y")
            {
                weekList.Add("Saturday");
            }
            if (periodOrderTmp.Sunday == "Y")
            {
                weekList.Add("Sunday");
            }
            List <DateTime> dateTimes  = PeriodSplitter.Cut(st1, et1, weekList); //得到每次的開單時間點
            List <DateTime> dateTimes2 = PeriodSplitter.Cut(st2, et2, weekList); //得到每次的收單時間點

            //
            orderinfo.OrderType   = "Period";
            orderinfo.OrderStatus = "wait";

            //開始撈取使用者選擇的複數商店
            ShopListTemp        shopListTemp        = new ShopListTemp(userId);
            List <ShopListTemp> shopListTemps       = shopListTemp.SelectByUserID(); //選取的商店清單
            List <ShopListTemp> randomshopListTemps = new List <ShopListTemp>();     //準備一個要裝進符合選取天數的清單

            //將randomshopListTemps打亂
            while (randomshopListTemps.Count <= dateTimes.Count)
            {
                for (int i = 0; i < shopListTemps.Count; i++)
                {
                    Swap(shopListTemps);
                }
                for (int i = 0; i < shopListTemps.Count; i++)
                {
                    randomshopListTemps.Add(shopListTemps[i]);
                }
            }
            //

            int    result = 0;
            int    count  = 0; //用來檢查迴圈有沒有跑完
            string OrderID;

            switch (QID)
            {
            case 211:
                OrderID = orderinfo.OrderID;
                for (int i = 0; i < dateTimes.Count; i++)
                {
                    orderinfo.StartTime        = dateTimes[i];
                    orderinfo.EndTime          = dateTimes2[i];
                    orderinfo.ShopID           = randomshopListTemps[i].ShopID;
                    orderinfo.OrderPartitionID = "MOP" + OrderID + $"-{ dateTimes[i].ToString("yyyyMMdd")}";
                    result = orderinfo.InserMyOrderTableToSQL();
                    if (result <= 0)
                    {
                        break;
                    }
                    count++;
                }

                break;

            default:
                break;
            }
            if (count == dateTimes.Count)
            {
                UserStatus userStatus = new UserStatus(userId);
                userStatus.InitializeUserStatusByUserID();
                periodOrderTmp = new PeriodOrderTmp(userId);
                periodOrderTmp.UpdateInitialPeriodOrderTmp();
                orderinfo.InsertOrdeUserTable();
                shopListTemp.DeleteByUserID();

                isRock.LineBot.Utility.PushMessage(userId, orderinfo.OrderID, channelAccessToken);
                // string orderCreateMessage = "上面是你的訂單參加碼,可以將此參加碼分享給其他人,讓其他人加入你的訂單喔~";
                // isRock.LineBot.Utility.PushMessage(userId, orderCreateMessage, channelAccessToken);

                return("訂單建立成功喔~~\n上面是你的訂單參加碼,可以將此參加碼分享給其他人,讓其他人加入你的訂單喔~");
            }
            else
            {
                return("訂單建立失敗");
            }
        }