Beispiel #1
0
        private static void Timer_Tick(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            dtczEntities1       de    = new dtczEntities1();
            List <station_site> datas = de.station_site.Where(p => p.Del_State == 1 && p.Station_Port.Equals(port)).AsQueryable().ToList();

            if (receivedCount > 0)
            {
                datas[0].received_state = 1;
                receivedCount           = 0;
            }
            else
            {
                datas[0].received_state = 0;
            }
            //de.station_site.Add(datas[0]);
            try
            {
                SysLog.WriteLog("[定时任务]定时判断接收状态");
                Console.WriteLine("[定时任务]定时判断接收状态");
                de.SaveChanges();
            }
            catch (Exception eirl)
            {
                SysLog.WriteError("[定时任务]定时判断接收状态保存出错" + eirl.Message);
                Console.WriteLine("[定时任务]定时判断接收状态保存出错" + eirl.Message);
            }
        }
Beispiel #2
0
        private static void saveintoDatabase(object oht)
        {
            try
            {
                Hashtable  ht   = (Hashtable)oht;
                VehicleMsg vMsg = (VehicleMsg)ht["vMsg"];
                string     IP   = (string)ht["IP"];
                string     port = (string)ht["port"];
                //tv是全部车辆数据
                t_vehicle_msg tv = new t_vehicle_msg();
                //tvt是当日车辆数据,数据库每天零点会清空
                t_vehicle_msg_today tvt = null;
                //tvot是超重超载车辆数据,当车重符合条件并超过规定数额时,增加一条
                t_vehicle_overweight_temp tvot = null;

                t_vehicle_overweight tvo = null;

                t_vehicle_msg_abnormal tva = null;

                //tv.id_local = System.Guid.NewGuid().ToString("N");//用UUID作为当前一条数据的ID。
                tv.id_local          = vMsg.Id;
                tv.Id                = vMsg.Id;
                tv.Station_Id        = vMsg.StationId;
                tv.Evt_Time          = vMsg.EvtTime;
                tv.Msg_Time          = vMsg.MsgTime;
                tv.Lane_No           = (sbyte)vMsg.LaneNo;
                tv.Plate             = vMsg.Plate;
                tv.Plate_Color       = (sbyte)vMsg.PlateColor;
                tv.Class_Index       = (sbyte)vMsg.ClassIndex;
                tv.Length            = (short)vMsg.Length;
                tv.Speed             = vMsg.Speed;
                tv.Direction         = (sbyte)vMsg.Direction;
                tv.Axles_Count       = (sbyte)vMsg.AxlesCount;
                tv.Total_Weight      = (int)vMsg.TotalWeight;
                tv.Is_Straddle       = (sbyte)vMsg.IsStraddle;
                tv.Temperature       = (sbyte)vMsg.Temperature;
                tv.Over_Weight       = (int)vMsg.OverWeight;
                tv.Over_Weight_Ratio = vMsg.OverWeightRatio;

                tv.Axle1  = vMsg.AxleWeights[0];
                tv.Axle2  = vMsg.AxleWeights[1];
                tv.Axle3  = vMsg.AxleWeights[2];
                tv.Axle4  = vMsg.AxleWeights[3];
                tv.Axle5  = vMsg.AxleWeights[4];
                tv.Axle6  = vMsg.AxleWeights[5];
                tv.Axle7  = vMsg.AxleWeights[6];
                tv.Axle8  = vMsg.AxleWeights[7];
                tv.Axle9  = vMsg.AxleWeights[8];
                tv.Axle10 = vMsg.AxleWeights[9];

                tv.Axle_space1  = vMsg.axleSpaces[0];
                tv.Axle_space2  = vMsg.axleSpaces[1];
                tv.Axle_space3  = vMsg.axleSpaces[2];
                tv.Axle_space4  = vMsg.axleSpaces[3];
                tv.Axle_space5  = vMsg.axleSpaces[4];
                tv.Axle_space6  = vMsg.axleSpaces[5];
                tv.Axle_space7  = vMsg.axleSpaces[6];
                tv.Axle_space8  = vMsg.axleSpaces[7];
                tv.Axle_space9  = vMsg.axleSpaces[8];
                tv.Gap          = vMsg.Gap;
                tv.TimeGap      = vMsg.TimeGap;
                tv.Headway      = vMsg.Headway;
                tv.ValidityCode = vMsg.ValidityCode;
                tv.Wheelbase    = vMsg.Wheelbase;

                tv.Station_IP = port;
                tv.WIM_Id     = "";
                tv.LPR_id     = "";

                if (vMsg.OverWeightDataState == -1)
                {
                    tva                   = new t_vehicle_msg_abnormal();
                    tva.id_local          = tv.id_local;//用UUID作为当前一条数据的ID。
                    tva.Id                = tv.Id;
                    tva.Station_Id        = tv.Station_Id;
                    tva.Evt_Time          = tv.Evt_Time;
                    tva.Msg_Time          = tv.Msg_Time;
                    tva.Lane_No           = tv.Lane_No;
                    tva.Plate             = tv.Plate;
                    tva.Plate_Color       = tv.Plate_Color;
                    tva.Class_Index       = tv.Class_Index;
                    tva.Length            = tv.Length;
                    tva.Speed             = tv.Speed;
                    tva.Direction         = tv.Direction;
                    tva.Axles_Count       = tv.Axles_Count;
                    tva.Total_Weight      = tv.Total_Weight;
                    tva.Is_Straddle       = tv.Is_Straddle;
                    tva.Temperature       = tv.Temperature;
                    tva.Over_Weight       = tv.Over_Weight;
                    tva.Over_Weight_Ratio = tv.Over_Weight_Ratio;

                    tva.Axle1  = tv.Axle1;
                    tva.Axle2  = tv.Axle2;
                    tva.Axle3  = tv.Axle3;
                    tva.Axle4  = tv.Axle4;
                    tva.Axle5  = tv.Axle5;
                    tva.Axle6  = tv.Axle6;
                    tva.Axle7  = tv.Axle7;
                    tva.Axle8  = tv.Axle8;
                    tva.Axle9  = tv.Axle9;
                    tva.Axle10 = tv.Axle10;

                    tva.Axle_space1  = tv.Axle_space1;
                    tva.Axle_space2  = tv.Axle_space2;
                    tva.Axle_space3  = tv.Axle_space3;
                    tva.Axle_space4  = tv.Axle_space4;
                    tva.Axle_space5  = tv.Axle_space5;
                    tva.Axle_space6  = tv.Axle_space6;
                    tva.Axle_space7  = tv.Axle_space7;
                    tva.Axle_space8  = tv.Axle_space8;
                    tva.Axle_space9  = tv.Axle_space9;
                    tva.Gap          = tv.Gap;
                    tva.TimeGap      = tv.TimeGap;
                    tva.Headway      = tv.Headway;
                    tva.ValidityCode = tv.ValidityCode;
                    tva.Wheelbase    = tv.Wheelbase;

                    tva.Station_IP = tv.Station_IP;
                    tva.WIM_Id     = tv.WIM_Id;
                    tva.LPR_id     = tv.LPR_id;
                }

                if ((DateTime.Compare(DateTime.Now.Date, tv.Evt_Time.Date) == 0))
                {
                    tvt                   = new t_vehicle_msg_today();
                    tvt.id_local          = tv.id_local;//用UUID作为当前一条数据的ID。
                    tvt.Id                = tv.Id;
                    tvt.Station_Id        = tv.Station_Id;
                    tvt.Evt_Time          = tv.Evt_Time;
                    tvt.Msg_Time          = tv.Msg_Time;
                    tvt.Lane_No           = tv.Lane_No;
                    tvt.Plate             = tv.Plate;
                    tvt.Plate_Color       = tv.Plate_Color;
                    tvt.Class_Index       = tv.Class_Index;
                    tvt.Length            = tv.Length;
                    tvt.Speed             = tv.Speed;
                    tvt.Direction         = tv.Direction;
                    tvt.Axles_Count       = tv.Axles_Count;
                    tvt.Total_Weight      = tv.Total_Weight;
                    tvt.Is_Straddle       = tv.Is_Straddle;
                    tvt.Temperature       = tv.Temperature;
                    tvt.Over_Weight       = tv.Over_Weight;
                    tvt.Over_Weight_Ratio = tv.Over_Weight_Ratio;

                    tvt.Axle1  = tv.Axle1;
                    tvt.Axle2  = tv.Axle2;
                    tvt.Axle3  = tv.Axle3;
                    tvt.Axle4  = tv.Axle4;
                    tvt.Axle5  = tv.Axle5;
                    tvt.Axle6  = tv.Axle6;
                    tvt.Axle7  = tv.Axle7;
                    tvt.Axle8  = tv.Axle8;
                    tvt.Axle9  = tv.Axle9;
                    tvt.Axle10 = tv.Axle10;

                    tvt.Axle_space1  = tv.Axle_space1;
                    tvt.Axle_space2  = tv.Axle_space2;
                    tvt.Axle_space3  = tv.Axle_space3;
                    tvt.Axle_space4  = tv.Axle_space4;
                    tvt.Axle_space5  = tv.Axle_space5;
                    tvt.Axle_space6  = tv.Axle_space6;
                    tvt.Axle_space7  = tv.Axle_space7;
                    tvt.Axle_space8  = tv.Axle_space8;
                    tvt.Axle_space9  = tv.Axle_space9;
                    tvt.Gap          = tv.Gap;
                    tvt.TimeGap      = tv.TimeGap;
                    tvt.Headway      = tv.Headway;
                    tvt.ValidityCode = tv.ValidityCode;
                    tvt.Wheelbase    = tv.Wheelbase;

                    tvt.Station_IP = tv.Station_IP;
                    tvt.WIM_Id     = tv.WIM_Id;
                    tvt.LPR_id     = tv.LPR_id;
                }

                /*      if (tv.Total_Weight >= 80000)
                 *    {
                 *        tvot = new t_vehicle_overweight_temp();
                 *        tvot.id_local = tv.id_local;
                 *        tvot.Id = tv.Id;
                 *        tvot.Station_Id = tv.Station_Id;
                 *        tvot.Evt_Time = tv.Evt_Time;
                 *        tvot.Msg_Time = tv.Msg_Time;
                 *        tvot.Lane_No = tv.Lane_No;
                 *        tvot.Plate = tv.Plate;
                 *        tvot.Plate_Color = tv.Plate_Color;
                 *        tvot.Class_Index = tv.Class_Index;
                 *        tvot.Length = tv.Length;
                 *        tvot.Speed = tv.Speed;
                 *        tvot.Direction = tv.Direction;
                 *        tvot.Axles_Count = tv.Axles_Count;
                 *        tvot.Total_Weight = tv.Total_Weight;
                 *        tvot.Is_Straddle = tv.Is_Straddle;
                 *        tvot.Temperature = tv.Temperature;
                 *        tvot.Over_Weight = tv.Over_Weight;
                 *        tvot.Over_Weight_Ratio = tv.Over_Weight_Ratio;
                 *
                 *        tvot.Axle1 = tv.Axle1;
                 *        tvot.Axle2 = tv.Axle2;
                 *        tvot.Axle3 = tv.Axle3;
                 *        tvot.Axle4 = tv.Axle4;
                 *        tvot.Axle5 = tv.Axle5;
                 *        tvot.Axle6 = tv.Axle6;
                 *        tvot.Axle7 = tv.Axle7;
                 *        tvot.Axle8 = tv.Axle8;
                 *        tvot.Axle9 = tv.Axle9;
                 *        tvot.Axle10 = tv.Axle10;
                 *
                 *        tvot.Axle_space1 = tv.Axle_space1;
                 *        tvot.Axle_space2 = tv.Axle_space2;
                 *        tvot.Axle_space3 = tv.Axle_space3;
                 *        tvot.Axle_space4 = tv.Axle_space4;
                 *        tvot.Axle_space5 = tv.Axle_space5;
                 *        tvot.Axle_space6 = tv.Axle_space6;
                 *        tvot.Axle_space7 = tv.Axle_space7;
                 *        tvot.Axle_space8 = tv.Axle_space8;
                 *        tvot.Axle_space9 = tv.Axle_space9;
                 *        tvot.Station_IP = tv.Station_IP;
                 *        tvot.WIM_Id = tv.WIM_Id;
                 *        tvot.LPR_id = tv.LPR_id;
                 *    }
                 */
                if (tv.Over_Weight != 0 && vMsg.OverWeightDataState != -1)
                {
                    tvo                   = new t_vehicle_overweight();
                    tvo.id_local          = tv.id_local;
                    tvo.Id                = tv.Id;
                    tvo.Station_Id        = tv.Station_Id;
                    tvo.Evt_Time          = tv.Evt_Time;
                    tvo.Msg_Time          = tv.Msg_Time;
                    tvo.Lane_No           = tv.Lane_No;
                    tvo.Plate             = tv.Plate;
                    tvo.Plate_Color       = tv.Plate_Color;
                    tvo.Class_Index       = tv.Class_Index;
                    tvo.Length            = tv.Length;
                    tvo.Speed             = tv.Speed;
                    tvo.Direction         = tv.Direction;
                    tvo.Axles_Count       = tv.Axles_Count;
                    tvo.Total_Weight      = tv.Total_Weight;
                    tvo.Is_Straddle       = tv.Is_Straddle;
                    tvo.Temperature       = tv.Temperature;
                    tvo.Over_Weight       = tv.Over_Weight;
                    tvo.Over_Weight_Ratio = tv.Over_Weight_Ratio;

                    tvo.Axle1  = tv.Axle1;
                    tvo.Axle2  = tv.Axle2;
                    tvo.Axle3  = tv.Axle3;
                    tvo.Axle4  = tv.Axle4;
                    tvo.Axle5  = tv.Axle5;
                    tvo.Axle6  = tv.Axle6;
                    tvo.Axle7  = tv.Axle7;
                    tvo.Axle8  = tv.Axle8;
                    tvo.Axle9  = tv.Axle9;
                    tvo.Axle10 = tv.Axle10;

                    tvo.Axle_space1  = tv.Axle_space1;
                    tvo.Axle_space2  = tv.Axle_space2;
                    tvo.Axle_space3  = tv.Axle_space3;
                    tvo.Axle_space4  = tv.Axle_space4;
                    tvo.Axle_space5  = tv.Axle_space5;
                    tvo.Axle_space6  = tv.Axle_space6;
                    tvo.Axle_space7  = tv.Axle_space7;
                    tvo.Axle_space8  = tv.Axle_space8;
                    tvo.Axle_space9  = tv.Axle_space9;
                    tvo.Gap          = tv.Gap;
                    tvo.TimeGap      = tv.TimeGap;
                    tvo.Headway      = tv.Headway;
                    tvo.ValidityCode = tv.ValidityCode;
                    tvo.Wheelbase    = tv.Wheelbase;

                    tvo.Station_IP = tv.Station_IP;
                    tvo.WIM_Id     = tv.WIM_Id;
                    tvo.LPR_id     = tv.LPR_id;
                }
                dtczEntities1 de = null;
                try
                {
                    de = new dtczEntities1();
                    //先判断是否为异常数据,不是异常数据正常插入,判断是否超重。异常数据直接插入异常表
                    if (vMsg.OverWeightDataState == 1)
                    {
                        de.t_vehicle_msg.Add(tv);
                        if (tvt != null)
                        {
                            de.t_vehicle_msg_today.Add(tvt);
                        }
                        if (tvot != null)
                        {
                            if (vMsg.ImgData.Length > 0)
                            {
                                SysLog.WriteLog($"图片id名称:{tv.id_local}--Image,图片大小:{vMsg.ImgData.Length}");
                                Console.WriteLine($"图片id名称:{tv.id_local},图片大小:{vMsg.ImgData.Length}");
                                SaveImage2(vMsg.ImgData, port, tv.id_local, "Image", tv);
                            }
                            SysLog.WriteLog($"车辆超重超载将计入数据库");
                            Console.WriteLine($"车辆超重超载将计入数据库");
                            de.t_vehicle_overweight_temp.Add(tvot);
                        }
                        if (tvo != null)
                        {
                            if (vMsg.ImgData.Length > 0)
                            {
                                SysLog.WriteLog($"图片id名称:{tv.id_local}--Image,图片大小:{vMsg.ImgData.Length}");
                                Console.WriteLine($"图片id名称:{tv.id_local},图片大小:{vMsg.ImgData.Length}");
                                SaveImage2(vMsg.ImgData, port, tv.id_local, "Image", tv);
                            }
                            SysLog.WriteLog($"车辆超重超载将计入数据库");
                            Console.WriteLine($"车辆超重超载将计入数据库");
                            de.t_vehicle_overweight.Add(tvo);


                            //以下是不发送条件
                            if (vMsg == null || vMsg.PlateImgData == null || vMsg.ImgData == null || tvo.Station_IP == null || port == null || tvo == null || tvo.Plate.Equals("无车牌") || tvo.Station_IP.Equals("10015") || tvo.Station_IP.Equals("10016") || Convert.ToInt32(port) > 10014 || vMsg.ImgData.Length == 0 || vMsg.PlateImgData.Length == 0)
                            {
                            }
                            //满足条件后发给json,最后到执法局
                            else if (tvo.Over_Weight_Ratio >= 0.05 && tvo.Axles_Count < 8 && tvo.Length < 2200 && tvo.Axle1 < 9000 && tvo.Speed <= 100)
                            {
                                string imgBase64       = Convert.ToBase64String(vMsg.ImgData);
                                string plate_imgBase64 = Convert.ToBase64String(vMsg.PlateImgData);
                                SysLog.WriteLog($"发送出json数据");
                                Console.WriteLine($"发送出json数据");
                                sendTvoJson(tvo, plate_imgBase64, imgBase64);
                            }
                        }
                    }
                    else
                    {
                        if (vMsg.ImgData.Length > 0)
                        {
                            SysLog.WriteLog($"图片id名称:{tv.id_local}--Image,图片大小:{vMsg.ImgData.Length}");
                            Console.WriteLine($"图片id名称:{tv.id_local},图片大小:{vMsg.ImgData.Length}");
                            SaveImage2(vMsg.ImgData, port, tv.id_local, "Image", tv);
                        }
                        SysLog.WriteLog($"车辆超重超载数据异常,将计入异常数据库");
                        Console.WriteLine($"车辆超重超载数据异常,将计入异常数据库");
                        de.t_vehicle_msg_abnormal.Add(tva);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("错误处507行" + e.Message);
                    SysLog.WriteError("错误处507行" + e.Message);
                }
                try
                {
                    int c = de.SaveChanges();
                    SysLog.WriteLog($"车辆信息写入成功,1条记录");
                    Console.WriteLine($"车辆信息写入成功,1条记录");
                }
                catch (DbUpdateException due)
                {
                    SysLog.WriteError($"车辆信息存入数据库出错,数据重复:{due.InnerException.InnerException.Message}");
                    Console.WriteLine($"车辆信息存入数据库出错,数据重复:{due.InnerException.InnerException.Message}");
                    Console.WriteLine("--------------------------------------------------------------------------------");
                    return;
                }
                catch (Exception err)
                {
                    SysLog.WriteError($"车辆信息存入数据库出错,将写入本地:{err.Message}");
                    Console.WriteLine($"车辆信息存入数据库出错,将写入本地:{err.Message}");
                    //Console.WriteLine($"车辆信息存入数据库出错,将写入本地:{err.InnerException.InnerException.Message}");
                    saveInFile2(tv.Station_IP, tv, vMsg.ImgData, vMsg.PlateImgData, vMsg.OverWeightDataState);
                }

                if (vMsg.PlateImgData.Length > 0)
                {
                    SysLog.WriteLog($"图片id名称:{tv.id_local}--PlateImg,图片大小:{vMsg.PlateImgData.Length}");
                    Console.WriteLine($"图片id名称:{tv.id_local},图片大小:{vMsg.PlateImgData.Length}");
                    SaveImage2(vMsg.PlateImgData, port, tv.id_local, "PlateImg", tv);
                }
                if (vMsg.LaserImgData.Length > 0)
                {
                    SysLog.WriteLog($"图片id名称:{tv.id_local}--LaserImg,图片大小:{vMsg.LaserImgData.Length}");
                    Console.WriteLine($"图片id名称:{tv.id_local},图片大小:{vMsg.LaserImgData.Length}");
                    SaveImage2(vMsg.LaserImgData, port, tv.id_local, "LaserImg", tv);
                }
                Console.WriteLine("--------------------------------------------------------------------------------");
                vMsg = null;
                de   = null;
                tv   = null;
                tvt  = null;
                tvot = null;
                tvo  = null;
            }
            catch (Exception e)
            {
                Console.WriteLine("saveintoDatabase里的错误" + e.Message);
                SysLog.WriteError("saveintoDatabase里的错误" + e.Message);
            }
        }