Beispiel #1
0
        void fucVehicleData(IntPtr pUserData, ref LPRSDK.VehicleData pData)
        {
            for (int count = 0; count < 3; count++)             //三次尝试存储图片,互斥
            {
                if (--pv < 0)
                {
                    pv++;
                    Thread.Sleep(200);
                    if (count == 2)
                    {
                        return;
                    }
                }
                else
                {
                    break;
                }
            }

            if (pData.ucPlate.ToString().Length < 6)         //如果抓拍到摩托车和电瓶车偶尔会返回车牌号为空,这时函数直接返回
            {
                return;
            }
            string sIP = "";
            foreach (DictionaryEntry de in DeviceTable)
            {

                AddDeviceInfo info = (AddDeviceInfo)DeviceTable[de.Key];
                if (info.ptrDeviceHandle == pData.pDeviceHandle)
                {
                    sIP = info.ucDeviceIP;
                    break;
                }
            }
            string fileDirectory = string.Empty;
            fileDirectory = string.Format("{0}\\{1}\\{2}{3}{4}\\", Application.StartupPath, pData.ucDeviceIP, pData.ucTime[0] + 2000,
                pData.ucTime[1], pData.ucTime[2]);
            if (!Directory.Exists(fileDirectory))
            {
                Directory.CreateDirectory(fileDirectory);
            }

            String strSpeFile = "", strPlateFile = "";

            strSpeFile = string.Format("{0}{1}{2}{3}({4})big.jpg", fileDirectory, pData.ucTime[3], pData.ucTime[4], pData.ucTime[5], pData.ucTime[2]);
            strPlateFile = string.Format("{0}{1}{2}{3}({4})plate.jpg", fileDirectory, pData.ucTime[3], pData.ucTime[4], pData.ucTime[5], pData.ucTime[2]);
            picpath = strSpeFile;

            if (pData.uiBigImageLen != 0)
            {
                FileStream fs = new FileStream(strSpeFile, FileMode.Create, FileAccess.Write,FileShare.ReadWrite);
                byte[] bytData = new byte[pData.uiBigImageLen];
                Marshal.Copy(pData.pucBigImage, bytData, 0, (int)pData.uiBigImageLen);

                try
                {
                    fs.Write(bytData, 0, (int)pData.uiBigImageLen);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally {
                    fs.Close();
                    fs.Dispose();                          //确保fs对象被销毁
                }
            }

            if (pData.uiPlateImageLen != 0)
            {
                FileStream fs = new FileStream(strPlateFile, FileMode.Create, FileAccess.Write,FileShare.ReadWrite);
                byte[] bytData = new byte[pData.uiPlateImageLen];
                Marshal.Copy(pData.pucPlateImage, bytData, 0, (int)pData.uiPlateImageLen);
                try
                {
                    fs.Write(bytData, 0, (int)pData.uiPlateImageLen);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    fs.Close();
                    fs.Dispose();                          //确保fs对象被销毁
                }
            }

            //窗口控件绑定变量置空
            this.picBigImage.Image = null;
            this.picPlateImage.Image = null;

            FileInfo fi = new FileInfo(strSpeFile);
            if (fi.Exists)
            {
                this.picBigImage.Load(strSpeFile);
            }

            fi = new FileInfo(strPlateFile);
            if (fi.Exists)
            {
                this.picPlateImage.Load(strPlateFile);
            }

            ShowPlate(pData.ucPlate.ToString(), pData.PlateColor);

            DateTime dt = DateTime.Now;
            paleInfo paleinfoModel = new paleInfo();
            record recordModel = new Ip_Device().getDeviceInfo(pData.ucDeviceIP);  // 获得该设备所在大门号和车道号
            recordModel.Pale = pData.ucPlate.ToString();
            recordModel.T = dt;
            recordModel.Time = dt.ToString();
            string Endirection = recordModel.Direction.Substring(0, 1) == "入" ? "in" : "out";

            recordModel.picPath = DateTime.Today.ToString("yyyy") + DateTime.Today.ToString("MM") + DateTime.Today.ToString("dd") +
                "_" + dt.Hour.ToString().PadLeft(2, '0') + "-" + dt.Minute.ToString().PadLeft(2, '0') + "-" + dt.Second.ToString().PadLeft(2, '0') +
                "_" + recordModel.Gate.Substring(0, 1) + "gate" + "_" + Endirection + recordModel.Direction.Substring(2, 1) + ".jpg";

            string SQL2 = "SELECT * FROM car_pale WHERE pale ='" + recordModel.Pale + "' AND statue='已预约'";
            string SQL3 = "SELECT * FROM car_pale WHERE pale ='" + recordModel.Pale + "' AND statue='已入场'";

            MySqlConnection conn1 = new MySqlConnection(connStr);    //每个进程需实例化一个连接,否则前面进程堵塞时会不能使用该连接
            bool paleflag = false;
            string[] likepale = getpale(recordModel.Pale);
            string DBpale = "";

                for (int i = 0; i < 4; i++)
                {
                    string thisstatue = Endirection == "in" ? "已预约" : "已入场";
                    string LikeSQL = "SELECT * FROM car_pale WHERE pale LIKE'" + likepale[i] + "' AND statue='"+thisstatue+"'";
                    try
                    {
                        conn.Open();
                        MySqlCommand cmd2 = new MySqlCommand(LikeSQL, conn);
                        MySqlDataReader rdr2 = cmd2.ExecuteReader();
                        if (rdr2.HasRows)
                        {
                            paleflag = true;
                            if (rdr2.Read())
                            {
                                DBpale = rdr2[0].ToString();
                                recordModel.regtime = DateTime.Parse(rdr2[1].ToString());
                                paleinfoModel.Name = rdr2[2].ToString();
                                paleinfoModel.Community = rdr2[3].ToString();
                                paleinfoModel.Building = rdr2[4].ToString();
                                paleinfoModel.Unit = rdr2[5].ToString();
                                paleinfoModel.Room = rdr2[6].ToString();
                                rdr2.Close();
                            }
                            break;
                        }
                        conn.Close();
                    }
                    catch (Exception ex)
                    {

                        conn.Close();
                        MessageBox.Show(ex.ToString());
                    }
                    finally { conn.Close(); }
                }

            while (true)
            {
                if (Endirection == "in")
                {

                    try
                    {
                        //conn1.Open();
                        //MySqlCommand cmd2 = new MySqlCommand(SQL2, conn1);
                        //MySqlDataReader rdr2 = cmd2.ExecuteReader();
                        if (paleflag == false)
                        //if (!rdr2.HasRows) {
                        {
                            this.result.ForeColor = Color.Red;
                            this.result.Text = "未预约";
                            this.picBigImage.Load(strSpeFile);
                            this.picPlateImage.Load(strPlateFile);
                            ShowPlate(pData.ucPlate.ToString(), pData.PlateColor);

                            ListViewItem item = new ListViewItem();
                            item.SubItems[0].Text = recordModel.Time;
                            item.SubItems.Add(DBpale);
                            item.SubItems.Add(recordModel.Pale);
                            item.SubItems.Add(recordModel.Gate);
                            item.SubItems.Add(recordModel.Direction);
                            item.SubItems.Add("");
                            item.SubItems.Add("");
                            item.SubItems.Add("未预约");
                            item.SubItems.Add("手动放行");
                            listView2.Items.Insert(0, item);
                            break;
                        }
                        //while(rdr2.Read())
                        //{
                        //    recordModel.regtime = DateTime.Parse(rdr2[1].ToString());
                        //    paleinfoModel.Name = rdr2[2].ToString();
                        //    paleinfoModel.Community = rdr2[3].ToString();
                        //    paleinfoModel.Building = rdr2[4].ToString();
                        //    paleinfoModel.Unit = rdr2[5].ToString();
                        //    paleinfoModel.Room = rdr2[6].ToString();
                        //}
                        //rdr2.Close();
                        //conn1.Close();

                        try
                        {
                            conn1.Open();
                            string SQL1 = "INSERT INTO record (pale,regtime,gate,direction,time,pic) VALUES ('" + DBpale + "','" + recordModel.regtime.ToString() + "','" + recordModel.Gate + "','" + recordModel.Direction + "','" + recordModel.T.ToString() + "','" + recordModel.picPath + "')";
                            MySqlCommand cmd1 = new MySqlCommand(SQL1, conn1);
                            if (cmd1.ExecuteNonQuery() > 0)
                            {
                                conn1.Close();
                                if (recordModel.Direction == "入口1号车道")
                                {
                                    ThreadPAC(0);     //DO 0栏杆打开
                                }
                                else if (recordModel.Direction == "入口2号车道")
                                {
                                    ThreadPAC(1);     //DO 1栏杆打开
                                }
                                else
                                {

                                }
                                this.result.ForeColor = Color.Green;
                                this.result.Text = "放行";
                                carInCount++;
                                ListViewItem item = new ListViewItem();
                                item.SubItems[0].Text = recordModel.Time;
                                item.SubItems.Add(DBpale);
                                item.SubItems.Add(recordModel.Pale);
                                item.SubItems.Add(recordModel.Gate);
                                item.SubItems.Add(recordModel.Direction);
                                item.SubItems.Add(paleinfoModel.Name);
                                item.SubItems.Add(paleinfoModel.Community + paleinfoModel.Building + paleinfoModel.Unit + paleinfoModel.Room + "室");
                                item.SubItems.Add("已入场");
                                item.SubItems.Add("自动放行");
                                listView2.Items.Insert(0, item);

                                try
                                {
                                    conn1.Open();
                                    string SQL4 = "UPDATE car_pale SET statue ='已入场' WHERE pale = '" + DBpale + "' AND regtime='" + recordModel.regtime.ToString() + "'";
                                    MySqlCommand cmd4 = new MySqlCommand(SQL4, conn1);
                                    if (cmd4.ExecuteNonQuery() > 0)
                                    {

                                        conn1.Close();
                                    }
                                }
                                catch { }
                                finally { conn1.Close(); }

                                #region 存储图片
                                if (pData.uiBigImageLen != 0)
                                {
                                    string filepath = System.Environment.CurrentDirectory + "/../../../Resources/palepic/" + recordModel.picPath;
                                    FileStream fs = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                                    byte[] bytData = new byte[pData.uiBigImageLen];
                                    Marshal.Copy(pData.pucBigImage, bytData, 0, (int)pData.uiBigImageLen);

                                    try
                                    {
                                        fs.Write(bytData, 0, (int)pData.uiBigImageLen);
                                        fs.Close();

                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                }
                                # endregion

                                # region 发送图片到服务器
                                try
                                {

                                    StartSend(System.Environment.CurrentDirectory + "/../../../Resources/palepic/" + recordModel.picPath,
                                        new DbHelperMySQL().getPicServerip(), Convert.ToInt32(new DbHelperMySQL().getPicServerPort()));
                                }
                                catch { }   //忽略图片服务器未打开的情况
                                break;

                                #endregion

                            }

                        }
                        catch (Exception e) { MessageBox.Show(e.ToString()); }

                    }
                    catch { }

                }
                else
                {
                    try
                    {
                        //conn1.Open();
                        //MySqlCommand cmd3 = new MySqlCommand(SQL3, conn1);
                        //MySqlDataReader rdr3 = cmd3.ExecuteReader();
                        //if (!rdr3.HasRows)
                        if (paleflag == false)
                        {
                            this.result.ForeColor = Color.Red;
                            this.result.Text = "未预约";
                            this.picBigImage.Load(strSpeFile);
                            this.picPlateImage.Load(strPlateFile);
                            ShowPlate(pData.ucPlate.ToString(), pData.PlateColor);

                            ListViewItem item = new ListViewItem();
                            item.SubItems[0].Text = recordModel.Time;
                            item.SubItems.Add(DBpale);
                            item.SubItems.Add(recordModel.Pale);
                            item.SubItems.Add(recordModel.Gate);
                            item.SubItems.Add(recordModel.Direction);
                            item.SubItems.Add("");
                            item.SubItems.Add("");
                            item.SubItems.Add("未预约");
                            item.SubItems.Add("手动放行");
                            listView2.Items.Insert(0, item);
                            break;
                        }
                        //while (rdr3.Read())
                        //{
                        //    recordModel.regtime = DateTime.Parse(rdr3[1].ToString());
                        //    paleinfoModel.Name = rdr3[2].ToString();
                        //    paleinfoModel.Community = rdr3[3].ToString();
                        //    paleinfoModel.Building = rdr3[4].ToString();
                        //    paleinfoModel.Unit = rdr3[5].ToString();
                        //    paleinfoModel.Room = rdr3[6].ToString();

                        //}
                        //rdr3.Close();
                        //conn1.Close();

                        try
                        {
                            conn1.Open();
                            string SQL1 = "INSERT INTO record (pale,regtime,gate,direction,time,pic) VALUES ('" + DBpale + "','" + recordModel.regtime.ToString() + "','" + recordModel.Gate + "','" + recordModel.Direction + "','" + recordModel.T.ToString() + "','" + recordModel.picPath + "')";
                            MySqlCommand cmd1 = new MySqlCommand(SQL1, conn1);
                            if (cmd1.ExecuteNonQuery() > 0)
                            {
                                conn1.Close();

                                if (recordModel.Direction == "出口1号车道")
                                {
                                    ThreadPAC(2);     //DO 2栏杆打开
                                }
                                else if (recordModel.Direction == "出口2号车道")
                                {
                                    ThreadPAC(3);     //DO 3栏杆打开
                                }
                                else
                                {
                                    MessageBox.Show("你逆行了");
                                    break;
                                }

                                this.result.ForeColor = Color.Green;
                                this.result.Text = "放行";
                                carInCount++;
                                ListViewItem item = new ListViewItem();
                                item.SubItems[0].Text = recordModel.Time;
                                item.SubItems.Add(DBpale);
                                item.SubItems.Add(recordModel.Pale);
                                item.SubItems.Add(recordModel.Gate);
                                item.SubItems.Add(recordModel.Direction);
                                item.SubItems.Add(paleinfoModel.Name);
                                item.SubItems.Add(paleinfoModel.Community + paleinfoModel.Building + paleinfoModel.Unit + paleinfoModel.Room + "室");
                                item.SubItems.Add("已出场");
                                item.SubItems.Add("自动放行");
                                listView2.Items.Insert(0, item);

                                try
                                {
                                    conn1.Open();
                                    string SQL5 = "UPDATE car_pale SET statue ='已出场' WHERE pale = '" + DBpale + "' AND regtime='" + recordModel.regtime.ToString() + "'";
                                    MySqlCommand cmd4 = new MySqlCommand(SQL5, conn1);
                                    if (cmd4.ExecuteNonQuery() > 0)
                                    {
                                        conn1.Close();
                                    }
                                }
                                catch { }

                                #region 存储图片
                                if (pData.uiBigImageLen != 0)
                                {
                                    string filepath = System.Environment.CurrentDirectory + "/../../../Resources/palepic/" + recordModel.picPath;
                                    FileStream fs = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                                    byte[] bytData = new byte[pData.uiBigImageLen];
                                    Marshal.Copy(pData.pucBigImage, bytData, 0, (int)pData.uiBigImageLen);

                                    try
                                    {
                                        fs.Write(bytData, 0, (int)pData.uiBigImageLen);
                                        fs.Close();

                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                }
                                # endregion

                                # region 发送图片到服务器
                                try
                                {
                                StartSend(System.Environment.CurrentDirectory + "/../../../Resources/palepic/" + recordModel.picPath,
                                    new DbHelperMySQL().getPicServerip(), Convert.ToInt32(new DbHelperMySQL().getPicServerPort()));
                                }
                                catch { }  //忽略图片服务器未打开的情况
                                break;

                                #endregion

                            }

                        }
                        catch { }

                    }
                    catch { }
                }
            }

            if (conn.State.ToString() == "Open")
                conn.Close();
            if (conn1.State.ToString() == "Open")
                conn1.Close();

            listview_Color();
            listview_AutoDelet();
            label1.Text = "出入 " + (carInCount + carOutCount).ToString() + " 辆车";
            label2.Text = "入场 " + carInCount.ToString() + " 辆车";
            label3.Text = "出场 " + carOutCount.ToString() + " 辆车";

            pv++;
        }
Beispiel #2
0
 void fucJPGStream(IntPtr pUserData, ref LPRSDK.JPGData pJPGData)
 {
 }
Beispiel #3
0
        //  LPRSDK.LPR_ScanDevice(); 会回调用此方法
        void fucDeviceInfo(IntPtr pUserData, ref LPRSDK.DeviceInfo pDeviceInfo)
        {
            //将扫描的设备添加到列表并自动进行连接
            String sIP = pDeviceInfo.DeviceNetInfo.ucDeviceIP.ToString();
            record recordModel = new Ip_Device().getDeviceInfo(sIP);
            StringBuilder sbIP = new StringBuilder(sIP);
            IntPtr ptrHandle = IntPtr.Zero;
            if ((LPRSDK.FEEKBACK_TYPE)LPRSDK.LPR_ConnectCamera(sbIP, ref ptrHandle) == LPRSDK.FEEKBACK_TYPE.RESULT_OK)
            {
                label4.Hide();
                if (timer1.Enabled == true)
                {
                    timer1.Stop();
                }
                if (timer2.Enabled == true)
                {
                    timer2.Stop();
                }
                lm.WriteLog("IP为" + sIP + "的设备连接成功!");
                if (reconn == true)
                {
                    lm.WriteLog("IP为" + sIP + "的设备重新连接成功!");
                    StartKiller();    //自动关闭提示框
                    MessageBox.Show("网络连接已恢复", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    try {
                          listView1.FindItemWithText(sIP).Remove();                    //将连接失败的item删除
                    }
                    catch { }

                }
                ListViewItem item = this.listView1.Items.Add(recordModel.Gate);
                item.SubItems.Add(recordModel.Direction);
                item.SubItems.Add(sIP);                                                   //将该item重新加入listview1
                item.SubItems.Add("摄像机已连接");
                AddDeviceInfo Info = new AddDeviceInfo();
                Info.ptrDeviceHandle = ptrHandle;
                Info.ucDeviceIP = sIP.ToString();
                DeviceTable.Add(sbIP, Info);
                listview_Resort();
                timer3.Start();
            }
            else if ((LPRSDK.FEEKBACK_TYPE)LPRSDK.LPR_ConnectCamera(sbIP, ref ptrHandle) == LPRSDK.FEEKBACK_TYPE.DEVICE_DISCONNECT)
            {
                ListViewItem item = this.listView1.Items.Add(recordModel.Gate);
                item.SubItems.Add(recordModel.Direction + "口");
                item.SubItems.Add(sIP);
                item.SubItems.Add("摄像机已断开");
                MessageBox.Show("摄像机已断开!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ((LPRSDK.FEEKBACK_TYPE)LPRSDK.LPR_ConnectCamera(sbIP, ref ptrHandle) == LPRSDK.FEEKBACK_TYPE.NO_FIND_DEVICE)
            {
                MessageBox.Show("没有发现设备,请检查摄像机网线是否插好!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ((LPRSDK.FEEKBACK_TYPE)LPRSDK.LPR_ConnectCamera(sbIP, ref ptrHandle) == LPRSDK.FEEKBACK_TYPE.OTHER_ERROR)
            {
                MessageBox.Show("其它错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //MessageBox.Show("未知错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
 void fucDeviceStatus(IntPtr pUserData, ref LPRSDK.DeviceStatus pStatus)
 {
 }
Beispiel #5
0
 public void ShowPlate(String strPlate, LPRSDK.PLATE_COLOR nColor)
 {
     labelPlate.Text = strPlate;
     switch (nColor)
     {
         case LPRSDK.PLATE_COLOR.YELLOW_COLOR:
             labelPlate.BackColor = Color.Yellow;
             labelPlate.ForeColor = Color.Black;
             break;
         case LPRSDK.PLATE_COLOR.BLUE_COLOR:
             labelPlate.BackColor = Color.Blue;
             labelPlate.ForeColor = Color.White;
             break;
         case LPRSDK.PLATE_COLOR.WHITE_COLOR:
             labelPlate.BackColor = Color.White;
             labelPlate.ForeColor = Color.Black;
             break;
         case LPRSDK.PLATE_COLOR.BLACK_COLOR:
             labelPlate.BackColor = Color.Black;
             labelPlate.ForeColor = Color.White;
             break;
         default:
             labelPlate.BackColor = Color.SlateGray;
             labelPlate.ForeColor = Color.Black;
             break;
     }
 }