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("訂單建立失敗"); } }
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("訂單建立失敗"); } }