private void Form1_Load(object sender, EventArgs e) { E = new ControlAddEx(AddR); R = new ControlAddR(AddR); Thread thread1 = new Thread(() => { while (true) { ProcessData(); Thread.Sleep(50000); } }); thread1.Start(); //_dateTime = DateTime.Now; //Thread thread2 = new Thread(() => //{ // while (true) // { // if (DateTime.Now.Hour == 20) // { // try // { // string sql = "select 内部编号 " + // " from tblRouteBusStatus" + // " where convert(varchar(10), UpdateTime, 120) < '" + DateTime.Now.ToString("yyyy-MM-dd") + "'" + // " and convert(varchar(10),时刻,120) < '" + DateTime.Now.ToString("yyyy-MM-dd") + "'"; // var routeData1 = SqlHelper.ExecuteDataTable(sql); // foreach (DataRow row in routeData1.Rows) // { // sql = "insert into tblRouteRFormD_bak2019 " + // " select * from tblRouteRFormD " + // " where 内部编号='" + Convert.ToString(row["内部编号"]) + "' " + // " and 日期='" + DateTime.Now.ToString("yyyy-MM-dd") + "'"; // SqlHelper.ExuteNonQuery(sql); // sql = " delete from tblRouteRFormD " + // " where 内部编号='" + Convert.ToString(row["内部编号"]) + "' " + // " and 日期='" + DateTime.Now.ToString("yyyy-MM-dd") + "' "; // SqlHelper.ExuteNonQuery(sql); // } // } // catch (Exception ex) // { // LogHelper.WriteLog(ex.Message); // } // } // if (_dateTime.Date < DateTime.Now.Date) // DelFormD(); // Thread.Sleep(100000); // } //}); //thread2.Start(); }
private void Form1_Load(object sender, EventArgs e) { E = new ControlAddEx(AddR); R = new ControlAddR(AddR); _routeS = (from p in SqlHelper.ExecuteDataTable(@"select 线路ID,'上行' as 方向,ISNULL(CAST(上行长度 as varchar),'0') as 长度 from tblRoute union all select 线路ID,'下行' as 方向,ISNULL(CAST(下行长度 as varchar),'0') as 长度 from tblRoute ").AsEnumerable() select new Route { 线路 = p.Field <string>("线路ID"), 方向 = p.Field <string>("方向"), 长度 = p.Field <string>("长度") }).ToList(); var data = SqlHelper.ExecuteDataTable(@"select 线路id,线路内序号,'上行始发' as 类型,站名 from tblrouted where 上行始发=1 union all select 线路id, 线路内序号,'上行终点' as 类型,站名 from tblrouted where 上行终点 = 1 union all select 线路id, 线路内序号,'下行始发' as 类型,站名 from tblrouted where 下行始发 = 1 union all select 线路id, 线路内序号,'下行终点' as 类型,站名 from tblrouted where 下行终点 = 1"); foreach (DataRow row in data.Rows) { _routeSRangeS.Add(new RouteSRange { 线路 = Convert.ToString(row["线路id"]), 线路内序号 = Convert.ToInt32(row["线路内序号"]), 类型 = Convert.ToString(row["类型"]), 站名 = Convert.ToString(row["站名"]), }); } ///处理非营运路单 Thread threadNonFormD = new Thread(() => { while (true) { ProcessNonFormD(); Thread.Sleep(10000); } }); threadNonFormD.IsBackground = true; threadNonFormD.Start(); ///更新 实际发,实际到,单边里程 Thread Formd = new Thread(() => { while (true) { ProcessData(); Thread.Sleep(50000); } }); Formd.IsBackground = true; Formd.Start(); DateTime excuteTime = DateTime.Now.AddDays(-1).Date; ///处理 ,最后路单的实际到 Thread threadLastForm = new Thread(() => { while (true) { if (!excuteTime.Equals(DateTime.Now.Date)) { if (DateTime.Now.Hour > 4) { isexcute = true; } } if (isexcute) { string sql = "select 替换车号,ActualRoute,convert(varchar,max(isnull(调整时刻,计划发车时间)),108) 发车时间 from tbldailyplan1_bak where 日期=convert(varchar(10),dateadd(day,-1,getdate()),121) group by 替换车号,ActualRoute"; DataTable data1 = SqlHelper.ExecuteDataTable(sql); if (data1.Rows.Count > 0) { foreach (DataRow row in data1.Rows) { try { string rformdsql = "select 流水号,状态 from tblRouteRFormD where 线路id='" + Convert.ToString(row["ActualRoute"]) + "' and 内部编号='" + Convert.ToString(row["替换车号"]) + "' and convert(varchar, 计划发车时刻,108)='" + Convert.ToString(row["发车时间"]) + "' and 日期=convert(varchar(10),dateadd(day,-1,getdate()),121)"; DataTable formD = SqlHelper.ExecuteDataTable(rformdsql); if (formD.Rows.Count > 0) { if (!formD.Rows[0]["状态"].ToString().Equals("2")) { string formSql = "select top 1 CONVERT(varchar(19), 到达时刻,121) 到达时刻 from tblRouteRFormX" + DateTime.Now.ToString("yyyyMMdd") + " where 内部编号='" + Convert.ToString(row["替换车号"]) + "' and 线路id='" + Convert.ToString(row["ActualRoute"]) + "' order by 流水号 desc"; DataTable rFormXData = SqlHelper.ExecuteDataTable(formSql); if (rFormXData.Rows.Count > 0) { string updateSql = "update tblRouteRFormD set 实际到达时刻='" + Convert.ToString(rFormXData.Rows[0]["到达时刻"]) + "' where 流水号=" + Convert.ToString(formD.Rows[0]["流水号"]); SqlHelper.ExuteNonQuery(updateSql); } } } } catch (Exception ex) { } } } isexcute = false; excuteTime = DateTime.Now.Date; } Thread.Sleep(100000); } }); threadLastForm.IsBackground = true; threadLastForm.Start(); _dateTime = DateTime.Now; ///更新 ,第一班路单驾驶员信息 Thread FormDUpdateJsy = new Thread(() => { while (true) { RunJsy(); Thread.Sleep(100000); } }); FormDUpdateJsy.IsBackground = true; FormDUpdateJsy.Start(); string maxsql = "select convert(varchar(10), dateadd( DAY,1,max(日期)),21) 日期 from tblDailyReport"; _cTime = Convert.ToDateTime(SqlHelper.ExecuteDataTable(maxsql).Rows[0]["日期"].ToString()); ///备份大日报 Thread DailyReportBak = new Thread(() => { while (true) { if (_cTime.Date < DateTime.Now.Date) { BuildDailyReport(); } Thread.Sleep(10000); } }); DailyReportBak.IsBackground = true; DailyReportBak.Start(); }
private void Form1_Load(object sender, EventArgs e) { E = new ControlAddEx(AddR); R = new ControlAddR(AddR); _routeS = (from p in SqlHelper.ExecuteDataTable(@"select 线路ID,'上行' as 方向,ISNULL(CAST(上行长度 as varchar),'0') as 长度 from tblRoute union all select 线路ID,'下行' as 方向,ISNULL(CAST(下行长度 as varchar),'0') as 长度 from tblRoute ").AsEnumerable() select new Route { 线路 = p.Field <string>("线路ID"), 方向 = p.Field <string>("方向"), 长度 = p.Field <string>("长度") }).ToList(); var data = SqlHelper.ExecuteDataTable(@"select 线路id,线路内序号,'上行始发' as 类型,站名 from tblrouted where 上行始发=1 union all select 线路id, 线路内序号,'上行终点' as 类型,站名 from tblrouted where 上行终点 = 1 union all select 线路id, 线路内序号,'下行始发' as 类型,站名 from tblrouted where 下行始发 = 1 union all select 线路id, 线路内序号,'下行终点' as 类型,站名 from tblrouted where 下行终点 = 1"); foreach (DataRow row in data.Rows) { _routeSRangeS.Add(new RouteSRange { 线路 = Convert.ToString(row["线路id"]), 线路内序号 = Convert.ToInt32(row["线路内序号"]), 类型 = Convert.ToString(row["类型"]), 站名 = Convert.ToString(row["站名"]), }); } ///更新 实际发,实际到,单边里程 Thread Formd = new Thread(() => { while (true) { ProcessData(); Thread.Sleep(50000); } }); Formd.IsBackground = true; Formd.Start(); Thread FormdXXX = new Thread(() => { while (true) { ProcessXXX(); Thread.Sleep(5000); } }); FormdXXX.IsBackground = true; FormdXXX.Start(); Doss(); Dow(); }
private void Form1_Load(object sender, EventArgs e) { E = new ControlAddEx(AddR); R = new ControlAddR(AddR); _routeS = (from p in SqlHelper.ExecuteDataTable(@"select 线路ID,'上行' as 方向,ISNULL(CAST(上行长度 as varchar),'0') as 长度 from tblRoute union all select 线路ID,'下行' as 方向,ISNULL(CAST(下行长度 as varchar),'0') as 长度 from tblRoute ").AsEnumerable() select new Route { 线路 = p.Field <string>("线路ID"), 方向 = p.Field <string>("方向"), 长度 = p.Field <string>("长度") }).ToList(); var data = SqlHelper.ExecuteDataTable(@"select 线路id,线路内序号,'上行始发' as 类型,站名 from tblrouted where 上行始发=1 union all select 线路id, 线路内序号,'上行终点' as 类型,站名 from tblrouted where 上行终点 = 1 union all select 线路id, 线路内序号,'下行始发' as 类型,站名 from tblrouted where 下行始发 = 1 union all select 线路id, 线路内序号,'下行终点' as 类型,站名 from tblrouted where 下行终点 = 1"); foreach (DataRow row in data.Rows) { _routeSRangeS.Add(new RouteSRange { 线路 = Convert.ToString(row["线路id"]), 线路内序号 = Convert.ToInt32(row["线路内序号"]), 类型 = Convert.ToString(row["类型"]), 站名 = Convert.ToString(row["站名"]), }); } Thread thread1SS = new Thread(() => { while (true) { ProcessNonFormD(); Thread.Sleep(10000); } }); thread1SS.Start(); ///更新实际发实际到单边里程 Thread Formd = new Thread(() => { while (true) { ProcessData(); Thread.Sleep(50000); } }); Formd.Start(); _dateTime = DateTime.Now; ///去掉没有到离站的车辆路单 Thread FormDDelMore = new Thread(() => { while (true) { RunJsy(); Thread.Sleep(100000); } }); FormDDelMore.Start(); string maxsql = "select convert(varchar(10), dateadd( DAY,1,max(日期)),21) 日期 from tblDailyReport"; _cTime = Convert.ToDateTime(SqlHelper.ExecuteDataTable(maxsql).Rows[0]["日期"].ToString()); ///备份大日报 Thread DailyReportBak = new Thread(() => { while (true) { if (_cTime.Date < DateTime.Now.Date) { BuildDailyReport(); } Thread.Sleep(10000); } }); DailyReportBak.Start(); }