Esempio n. 1
0
        //定时调用
        private static void Wtimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            string msg = string.Format("调用龙华总务进出门岗系统数据接口:{0}", DateTime.Now);

            LogHelper.DoGetGateRecordLog(msg);

            //调用接口
            try
            {
                LongHua.Service1SoapClient service = new LongHua.Service1SoapClient();
                //不传车牌号  返回的是这段时间范围内所有满足条件的车辆的进出岗的信息
                //传递车牌号  返回的是查询指定车辆的信息
                //开始时间必传
                //不传结束时间   返回的是从开始时间开始到现在的所有满足条件的数据
                //传递结束时间   返回的是从开始时间到结束时间所有满足条件的数据

                //此时的开始时间是上次的结束时间+1毫秒,结束时间是上次的结束时间+任务周期
                string startTime = Convert.ToDateTime(endTime).AddMilliseconds(1).ToString("yyyy-MM-dd HH:mm:ss");
                endTime = Convert.ToDateTime(endTime).AddMilliseconds(timeIntervalFlag).ToString("yyyy-MM-dd HH:mm:ss");
                string rd = service.GetVehicleRecord("", startTime, endTime);

                ResultModel[] rs = JsonConvert.DeserializeObject <ResultModel[]>(rd);
                if (rs.Length > 0)
                {
                    DataTable dt = ConvertToDataTable(rs);

                    List <SqlBulkCopyColumnMapping> mapping = new List <SqlBulkCopyColumnMapping>();
                    #region 数据
                    mapping.Add(new SqlBulkCopyColumnMapping("CarID", "CarID"));
                    mapping.Add(new SqlBulkCopyColumnMapping("CarNumber", "CarNumber"));
                    mapping.Add(new SqlBulkCopyColumnMapping("PassGate", "PassGate"));
                    mapping.Add(new SqlBulkCopyColumnMapping("InOrOut", "InOrOut"));
                    mapping.Add(new SqlBulkCopyColumnMapping("InOrOutTime", "InOrOutTime"));
                    #endregion
                    MSSQLHelper.BulkCopyAsync(dt, "GateSentryRecord", mapping.ToArray());
                }
                else
                {
                    Console.WriteLine("暂无数据");
                    string ms = string.Format("{0}:{1}  无返回数据", startTime, endTime);
                    LogHelper.DoGetGateRecordLog(ms);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogHelper.DoGetGateRecordLog(ex.Message);
            }
        }
Esempio n. 2
0
        //运行程序时候调用
        private static void GetStartData()
        {
            //查询表中有无数据
            string    sql      = string.Format(@"SELECT TOP 1 [InOrOutTime] 
  FROM [dbo].[GateSentryRecord] ORDER BY InOrOutTime DESC ");
            DataTable dtSource = MSSQLHelper.ExecuteDataTable(System.Data.CommandType.Text, sql);

            //如果有异常,则直接返回
            if (dtSource == null)
            {
                return;
            }

            string msg = string.Format("调用龙华总务进出门岗系统数据接口:{0}", DateTime.Now);

            LogHelper.DoGetGateRecordLog(msg);

            //调用接口
            try
            {
                LongHua.Service1SoapClient service = new LongHua.Service1SoapClient();
                string rd, startTime;
                //没有数据时,开始时间为当天00:00:00时间,当前时间为结束时间
                if (dtSource.Rows.Count < 1)
                {
                    startTime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
                    rd        = service.GetVehicleRecord("", startTime, endTime);
                }
                //有数据时,查询出来的时间作为开始时间,当前时间为结束时间
                else
                {
                    startTime = Convert.ToDateTime(dtSource.Rows[0]["InOrOutTime"]).ToString("yyyy-MM-dd HH:mm:ss");
                    rd        = service.GetVehicleRecord("", startTime, endTime);
                }

                ResultModel[] rs = JsonConvert.DeserializeObject <ResultModel[]>(rd);
                if (rs.Length > 0)
                {
                    DataTable dt = ConvertToDataTable(rs);

                    List <SqlBulkCopyColumnMapping> mapping = new List <SqlBulkCopyColumnMapping>();
                    #region 数据
                    mapping.Add(new SqlBulkCopyColumnMapping("CarID", "CarID"));
                    mapping.Add(new SqlBulkCopyColumnMapping("CarNumber", "CarNumber"));
                    mapping.Add(new SqlBulkCopyColumnMapping("PassGate", "PassGate"));
                    mapping.Add(new SqlBulkCopyColumnMapping("InOrOut", "InOrOut"));
                    mapping.Add(new SqlBulkCopyColumnMapping("InOrOutTime", "InOrOutTime"));
                    #endregion
                    MSSQLHelper.BulkCopyAsync(dt, "GateSentryRecord", mapping.ToArray());
                }
                else
                {
                    Console.WriteLine("暂无数据");
                    string ms = string.Format("{0}:{1}  无返回数据", startTime, endTime);
                    LogHelper.DoGetGateRecordLog(ms);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogHelper.DoGetGateRecordLog(ex.Message);
            }
        }