using cuidian.Sql; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WangToTempDb; namespace TaskSchedule { public class Realize { //public static bool ______flag=true; /// /// 按天遍历 /// /// public static void GetDaysAndExecute(Dictionary dic, IUpLoad iup, string entity) { //保存最末时间 string endTimeStr = dic["end_time"]; //两个时间间隔 double end = Convert.ToDateTime(dic["end_time"]).Subtract(Convert.ToDateTime(dic["start_time"])).TotalDays; //判断间隔是否大于30天,是则一天一天遍历 if (end > 30) { for (int i = 0; i <= end; i++) { if (i == (int)end) { dic["end_time"] = endTimeStr; iup.UpLoad(dic); if (entity == "其他入库") { IUpLoad iupThree = new StockinUpLoad(); dic.Add("status", "60"); dic.Add("order_type", "2"); iupThree.UpLoad(dic); dic.Remove("status"); dic.Remove("order_type"); } } else { dic["start_time"] = (Convert.ToDateTime(dic["start_time"])).ToString(); //给endTime//天数加1 dic["end_time"] = (Convert.ToDateTime(dic["start_time"]).AddDays(1)).ToString(); //旺店通到中间 iup.UpLoad(dic); if (entity == "其他入库") { IUpLoad iupThree = new StockinUpLoad(); dic.Add("status", "60"); dic.Add("order_type", "2"); iupThree.UpLoad(dic); dic.Remove("status"); dic.Remove("order_type"); } } Console.WriteLine("---------------"); Console.WriteLine(dic["start_time"]); Console.WriteLine(dic["end_time"]); //并更新表时间,旺店通时间跨度为闭区间,所以把秒数+1以便明天10点再次取值 DbUtils.ExecuteNonQuery(string.Format("update transtime set lasttime=DATEADD(SECOND,+1,'{0}') where entitytype='{1}'", dic["end_time"], entity), ConnectionUtils.Instance.GetConnection("TempDB")); //实现后更新遍历时间 dic["start_time"] = (Convert.ToDateTime(dic["end_time"]).AddSeconds(1)).ToString(); } } else { iup.UpLoad(dic); if (entity == "其他入库") { IUpLoad iupThree = new StockinUpLoad(); dic.Add("status", "60"); dic.Add("order_type", "2"); iupThree.UpLoad(dic); dic.Remove("status"); dic.Remove("order_type"); } Console.WriteLine("------------------"); Console.WriteLine(dic["start_time"]); Console.WriteLine(dic["end_time"]); //并更新表时间,旺店通时间跨度为闭区间,所以把秒数+1以便明天10点再次取值 DbUtils.ExecuteNonQuery(string.Format("update transtime set lasttime=DATEADD(SECOND,+1,'{0}') where entitytype='{1}'", dic["end_time"], entity), ConnectionUtils.Instance.GetConnection("TempDB")); } } /// /// 按小时遍历 /// /// public static void GetHoursAndExecute(Dictionary dic, IUpLoad iup, string entity) { //保存最末时间 string endTimeStr = dic["end_time"]; //两个时间间隔 double end = Convert.ToDateTime(dic["end_time"]).Subtract(Convert.ToDateTime(dic["start_time"])).TotalHours; //判断间隔是否大于1个小时,是则按小时遍历 if (end > 1) { for (int i = 0; i <= end; i++) { if (i == (int)end) { dic["end_time"] = endTimeStr; iup.UpLoad(dic); if (entity == "销售出库") { IUpLoad iupTwo = new DispatchListSendUpLoad(); iupTwo.UpLoad(dic); } else if (entity == "其他入库") { IUpLoad iupThree = new StockinUpLoad(); dic.Add("status", "60"); dic.Add("order_type", "2"); iupThree.UpLoad(dic); dic.Remove("status"); dic.Remove("order_type"); } } else { dic["start_time"] = (Convert.ToDateTime(dic["start_time"])).ToString(); //给endTime//天数加1 dic["end_time"] = (Convert.ToDateTime(dic["start_time"]).AddHours(1)).ToString(); //旺店通到中间 iup.UpLoad(dic); if (entity == "销售出库") { IUpLoad iupTwo = new DispatchListSendUpLoad(); iupTwo.UpLoad(dic); } else if (entity == "其他入库") { IUpLoad iupThree = new StockinUpLoad(); dic.Add("status", "60"); dic.Add("order_type", "2"); iupThree.UpLoad(dic); dic.Remove("status"); dic.Remove("order_type"); } } Console.WriteLine("---------------"); Console.WriteLine(dic["start_time"]); Console.WriteLine(dic["end_time"]); //并更新表时间,旺店通时间跨度为闭区间,所以把秒数+1以便明天10点再次取值 DbUtils.ExecuteNonQuery(string.Format("update transtime set lasttime=DATEADD(SECOND,+1,'{0}') where entitytype='{1}'", dic["end_time"], entity), ConnectionUtils.Instance.GetConnection("TempDB")); //实现后更新遍历时间 dic["start_time"] = (Convert.ToDateTime(dic["end_time"]).AddSeconds(1)).ToString(); } } else { iup.UpLoad(dic); if (entity == "销售出库") { IUpLoad iupTwo = new DispatchListSendUpLoad(); iupTwo.UpLoad(dic); } else if (entity == "其他入库") { IUpLoad iupThree = new StockinUpLoad(); dic.Add("status", "60"); dic.Add("order_type", "2"); iupThree.UpLoad(dic); dic.Remove("status"); dic.Remove("order_type"); } Console.WriteLine("------------------"); Console.WriteLine(dic["start_time"]); Console.WriteLine(dic["end_time"]); //并更新表时间,旺店通时间跨度为闭区间,所以把秒数+1以便明天10点再次取值 DbUtils.ExecuteNonQuery(string.Format("update transtime set lasttime=DATEADD(SECOND,+1,'{0}') where entitytype='{1}'", dic["end_time"], entity), ConnectionUtils.Instance.GetConnection("TempDB")); } } } }