Exemplo n.º 1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folder = new FolderBrowserDialog();

            if (DialogResult.OK == folder.ShowDialog())
            {
                String    path    = folder.SelectedPath + "\\车辆检测数据" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
                string    columns = "id,carnumber,nozzleno,arrivetime,begintime,leavetime,carlogo,subcarlogo";
                DataTable dt      = queryData(columns, false);
                dt.Columns.Add("carbrand", typeof(string));
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string carlogoKey = dt.Rows[i]["carlogo"].ToString() + "-" + dt.Rows[i]["subcarlogo"].ToString();
                    string carlogo    = "未知";
                    if (Global.carLogoHashtable.Contains(carlogoKey))
                    {
                        carlogo = (string)Global.carLogoHashtable[carlogoKey];
                    }
                    dt.Rows[i]["carbrand"] = carlogo;
                }

                if (SystemUnit.ExportDataToExcel(dt, path))
                {
                    MessageBox.Show("导出数据成功");
                }
                else
                {
                    MessageBox.Show("导出数据失败");
                }
            }

            ;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            MEMORY_INFO MemInfo;

            MemInfo = new MEMORY_INFO();
            SystemUnit.GlobalMemoryStatus(ref MemInfo);
            toolRAM.Text = MemInfo.dwMemoryLoad.ToString() + "%";
        }
        private void ReceiveMasssage(object clientSocket)
        {
            //Socket myClientSocket = (Socket)clientSocket;
            while (isRun)
            {
                try
                {
                    byte[] buff = new byte[1024];

                    int count = cSocket.Receive(buff);
                    if (count > 0)
                    {
                        if (buff[2] == 0x03 && buff[3] == 2)
                        {
                            SystemUnit.PostMessage(SystemUnit.HWND_BROADCAST, (int)Global.WM_CARSNAP, buff[4], buff[5]);
                        }
                        else if (buff[2] == 0x02 && buff[3] == 58 && count >= 62)
                        {
                            struLoginInfo info    = new struLoginInfo();
                            byte[]        reivBuf = new byte[58];
                            Buffer.BlockCopy(buff, 4, reivBuf, 0, 58);
                            info = (struLoginInfo)SystemUnit.BytesToStruts(reivBuf, typeof(struLoginInfo));
                            string ip        = System.Text.Encoding.Default.GetString(info.byIP);
                            int    port      = info.wPort;
                            string loginName = System.Text.Encoding.Default.GetString(info.byLoginName);
                            string password  = System.Text.Encoding.Default.GetString(info.byPassword);
                            byte[] sendbuf   = new byte[9];
                            sendbuf[0] = 0xFF;
                            sendbuf[1] = 0xFF;
                            sendbuf[2] = 0x02;
                            sendbuf[3] = 1;
                            if (ip == Global.clsNvrInfo.ip && port == Global.clsNvrInfo.port &&
                                loginName == Global.clsNvrInfo.loginName && password == Global.clsNvrInfo.password)
                            {
                                sendbuf[4] = 1;//1 成功
                            }
                            else
                            {
                                sendbuf[4] = 0;//0 失败
                            }
                            ushort crc = SystemUnit.getCRC(sendbuf, 0, 5);
                            sendbuf[5] = (byte)(crc / 256);
                            sendbuf[6] = (byte)(crc % 256);
                            sendbuf[7] = 0xEE;
                            sendbuf[8] = 0xEE;
                            Send(sendbuf);
                        }
                    }
                    Thread.Sleep(30);
                }
                catch (System.Exception ex)
                {
                }
            }
        }
Exemplo n.º 4
0
        private void SetNozzleParamToDll()
        {
            int structLenth = Marshal.SizeOf(typeof(struNozzleRecog));

            struNozzleRecog[] nozzleRecog = new struNozzleRecog[Global.nozzleList.Count];
            byte[]            ipp         = new byte[10000];
            int offset = 0;

            for (int i = 0; i < Global.nozzleList.Count; i++)
            {
                nozzleRecog[i].nozzleNo  = Global.nozzleList[i].nozzleNo;
                nozzleRecog[i].areas     = new struArea[8];
                nozzleRecog[i].areaCount = Global.nozzleList[i].linkedMainAreaList.Count;
                for (int j = 0; j < nozzleRecog[i].areaCount; j++)
                {
                    if (Global.areaMap.ContainsKey(Global.nozzleList[i].linkedMainAreaList[j]))
                    {
                        int index = Global.areaMap[Global.nozzleList[i].linkedMainAreaList[j]];
                        nozzleRecog[i].videoChan            = Global.areaList[index].videoChannel;
                        nozzleRecog[i].areas[j].areaNo      = Global.areaList[index].id;
                        nozzleRecog[i].areas[j].left        = (int)(Global.areaList[index].left * Global.nDefaultWidth);
                        nozzleRecog[i].areas[j].right       = (int)(Global.areaList[index].right * Global.nDefaultWidth);
                        nozzleRecog[i].areas[j].top         = (int)(Global.areaList[index].top * Global.nDefaultHeight);
                        nozzleRecog[i].areas[j].bottom      = (int)(Global.areaList[index].bottom * Global.nDefaultHeight);
                        nozzleRecog[i].areas[j].videoLaneNo = Global.areaList[index].videoLaneNo;
                    }
//                     foreach (ClsRecogArea area in Global.areaList)
//                     {
//                         if (Global.nozzleList[i].linkedMainAreaList[j] == area.id)
//                         {
//                             nozzleRecog[i].videoChan = area.videoChannel;
//                             nozzleRecog[i].areas[j].areaNo = area.id;
//                             nozzleRecog[i].areas[j].left = (int)(area.left * Global.nDefaultWidth);
//                             nozzleRecog[i].areas[j].right = (int)(area.right * Global.nDefaultWidth);
//                             nozzleRecog[i].areas[j].top = (int)(area.top * Global.nDefaultHeight);
//                             nozzleRecog[i].areas[j].bottom = (int)(area.bottom * Global.nDefaultHeight);
//                             nozzleRecog[i].areas[j].videoLaneNo = area.videoLaneNo;
//                         }
//                     }
                }

                byte[] bNozzle = SystemUnit.StrutsToBytesArray(nozzleRecog[i]);
                Buffer.BlockCopy(bNozzle, 0, ipp, offset, structLenth);
                offset += structLenth;
            }
            SPlate.SP_InitRunParam_Nozzle(ipp, Global.nozzleList.Count);
            Global.LogServer.Add(new LogInfo("Debug", "Main->InitDev->SetNozzleParamToDll 油枪参数传入动态库完成,油枪数:" + Global.nozzleList.Count.ToString(), (int)EnumLogLevel.DEBUG));
        }
 private void timerServiceStaus_Tick(object sender, EventArgs e)
 {
     this.ShowMemoryInfo();
     this.ShowMatchRatio();
     SystemUnit.PostMessage(SystemUnit.HWND_BROADCAST, (int)WM_HEARTBEAT, 0, 0);
     gcCount++;
     if (gcCount > 60)
     {
         gcCount = 0;
         GC.Collect();
     }
     statusCount++;
     if (statusCount > 3)
     {
         statusCount = 0;
         SendStatusToRemote();
     }
 }
Exemplo n.º 6
0
        private void SetVideoChanParamToDll()
        {
            int structLenth = Marshal.SizeOf(typeof(struVideoChan));

            //IntPtr ip = Marshal.AllocHGlobal(Global.nozzleList.Count* structLenth);
            struVideoChan[] videoChan = new struVideoChan[Global.videoChanList.Count];
            byte[]          ipp       = new byte[10000];
            int             offset    = 0;

            for (int i = 0; i < Global.videoChanList.Count; i++)
            {
                videoChan[i].chanNo    = Global.videoChanList[i].channelNo;
                videoChan[i].areaCount = Global.videoChanList[i].areaNoList.Count;
                videoChan[i].videoType = Global.videoChanList[i].videoType;
                videoChan[i].areas     = new struArea[8];
                for (int j = 0; j < videoChan[i].areaCount; j++)
                {
                    if (Global.areaMap.ContainsKey(Global.videoChanList[i].areaNoList[j]))
                    {
                        int index = Global.areaMap[Global.videoChanList[i].areaNoList[j]];
                        videoChan[i].areas[j].areaNo      = Global.areaList[index].id;
                        videoChan[i].areas[j].left        = (int)(Global.areaList[index].left * Global.nDefaultWidth);
                        videoChan[i].areas[j].right       = (int)(Global.areaList[index].right * Global.nDefaultWidth);
                        videoChan[i].areas[j].top         = (int)(Global.areaList[index].top * Global.nDefaultHeight);
                        videoChan[i].areas[j].bottom      = (int)(Global.areaList[index].bottom * Global.nDefaultHeight);
                        videoChan[i].areas[j].videoChanNo = videoChan[i].chanNo;
                        videoChan[i].areas[j].videoLaneNo = Global.areaList[index].videoLaneNo;
                    }
                }
                byte[] byVideo = SystemUnit.StrutsToBytesArray(videoChan[i]);
                Buffer.BlockCopy(byVideo, 0, ipp, offset, structLenth);
                offset += structLenth;
            }
            SPlate.SP_InitRunParam_Video(ipp, Global.videoChanList.Count);
            Global.LogServer.Add(new LogInfo("Debug", "Main->InitDev->SetVideoParamToDll 视频通道参数传入动态库完成,油枪数:" + Global.videoChanList.Count.ToString(), (int)EnumLogLevel.DEBUG));
        }
        private void ReceiveMasssage(object clientSocket)
        {
            //Socket myClientSocket = (Socket)clientSocket;
            while (isRun)
            {
                try
                {
                    byte[] buff = new byte[10240];

                    int count = cSocket.Receive(buff);
                    if (count > 0)
                    {
                        if (buff[0] == 0x32 && buff[1] == 0x30 && buff[2] == 0x31 && buff[3] == 0x30 && buff[4] == 0x31) //交易数据
                        {
                            int    pidlenth = buff[5];
                            string pid      = Encoding.Default.GetString(buff, 6, pidlenth);
                            string info     = Encoding.UTF8.GetString(buff, 10 + pidlenth, count - pidlenth - 10);
                            Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->ReceiveMasssage 接收交易支付信息:" + pid + "---->" + info, (int)EnumLogLevel.DEBUG));
                            JObject obj = null;
                            try {
                                obj = JObject.Parse(info);
                                string msgid    = obj["msgID"].ToString();
                                byte[] sendbuff = new byte[256];
                                int    offset   = 0;
                                Buffer.BlockCopy(buff, 0, sendbuff, offset, pidlenth + 6);
                                offset          += pidlenth + 6;
                                sendbuff[offset] = (byte)msgid.Length;
                                offset          += 1;
                                byte[] msgbuff = Encoding.Default.GetBytes(msgid);
                                Buffer.BlockCopy(msgbuff, 0, sendbuff, offset, msgbuff.Length);
                                offset          += msgbuff.Length;
                                sendbuff[offset] = 0x31;
                                cSocket.Send(sendbuff, offset + 1, 0);
                                Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->ReceiveMasssage 回复交易支付信息:201019" + pid + msgid.Length.ToString() + msgid + "1", (int)EnumLogLevel.DEBUG));
                            }
                            catch (System.Exception ex) {
                                string msgid    = "9999";
                                byte[] sendbuff = new byte[256];
                                int    offset   = 0;
                                Buffer.BlockCopy(buff, 0, sendbuff, offset, pidlenth + 6);
                                offset          += pidlenth + 6;
                                sendbuff[offset] = (byte)msgid.Length;
                                offset          += 1;
                                byte[] msgbuff = Encoding.Default.GetBytes(msgid);
                                Buffer.BlockCopy(msgbuff, 0, sendbuff, offset, msgbuff.Length);
                                offset          += msgbuff.Length;
                                sendbuff[offset] = 0x32;
                                cSocket.Send(sendbuff, offset + 1, 0);
                                Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->ReceiveMasssage (JSON解析失败)回复交易支付信息:201019" + pid + msgid.Length.ToString() + msgid + "1", (int)EnumLogLevel.DEBUG));

                                continue;
                            }

                            if (pid == "P91_10007")
                            {
                                try
                                {
                                    //Global.LogServer.Add(new LogInfo("tradelog", "step:1", (int)EnumLogLevel.DEBUG));
                                    TradeInfo trade = new TradeInfo();
                                    trade.GasStation_NO = obj["source"].ToString();
                                    trade.REQ_Time      = obj["time"].ToString();
                                    trade.MSG_ID        = obj["msgID"].ToString();
                                    //Global.LogServer.Add(new LogInfo("tradelog", "step:2", (int)EnumLogLevel.DEBUG));
                                    trade.OilGun_NO = obj["data"][0]["1"].ToString();
                                    trade.OIL_TYPE  = obj["data"][0]["2"].ToString();
                                    //Global.LogServer.Add(new LogInfo("tradelog", "step:3", (int)EnumLogLevel.DEBUG));
                                    if (Global.oilInfoHashtable.Contains(trade.OIL_TYPE))
                                    {
                                        OilInfo oil = (OilInfo)Global.oilInfoHashtable[trade.OIL_TYPE];
                                        trade.OilName  = oil.OilName;
                                        trade.OilCode  = oil.OilCode;
                                        trade.OilClass = oil.OilClass;
                                    }
                                    //Global.LogServer.Add(new LogInfo("tradelog", "step:4", (int)EnumLogLevel.DEBUG));
                                    trade.OIL_Q      = double.Parse(obj["data"][0]["3"].ToString());
                                    trade.OIL_AMT    = double.Parse(obj["data"][0]["4"].ToString());
                                    trade.OIL_PRC    = double.Parse(obj["data"][0]["5"].ToString());
                                    trade.START_TIME = obj["data"][0]["6"].ToString();
                                    trade.END_TIME   = obj["data"][0]["7"].ToString();
                                    trade.START_READ = double.Parse(obj["data"][0]["8"].ToString());
                                    trade.END_READ   = double.Parse(obj["data"][0]["9"].ToString());
                                    //Global.LogServer.Add(new LogInfo("tradelog", "step:5", (int)EnumLogLevel.DEBUG));
                                    trade.VehicleNo        = obj["data"][0]["10"].ToString();
                                    trade.VehicleBrandCode = obj["data"][0]["11"].ToString();
                                    trade.SubBrandCode     = obj["data"][0]["12"].ToString();
                                    //Global.LogServer.Add(new LogInfo("tradelog", "step:6", (int)EnumLogLevel.DEBUG));
                                    //if (Global.carBrandHashtable.Contains(trade.VehicleBrandCode+"-"+trade.SubBrandCode))
                                    //                                     {
                                    //                                        CarBrandInfo car = (CarBrandInfo)Global.carLogoHashtable[trade.VehicleBrandCode + "-" + trade.SubBrandCode];
                                    //                                         trade.CarBrand = car.CarBrand;
                                    //                                         trade.SubBrand = car.SubCarBrand;
                                    //                                     }
                                    trade.VehicleModel = obj["data"][0]["13"].ToString();
                                    trade.VehicleColor = obj["data"][0]["14"].ToString();
                                    trade.BodyColor    = obj["data"][0]["15"].ToString();
                                    Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->存储加油交易信息: " + trade.toSaveSqlString(), (int)EnumLogLevel.DEBUG));
                                    int id = Global.mysqlHelper2.ExecuteSqlGetId(trade.toSaveSqlString());

                                    if ((trade.BodyColor == "1" && trade.OilClass == "柴油") ||
                                        (trade.BodyColor == "0" && trade.OilClass == "汽油"))
                                    {
                                        Global.mysqlHelper2.ExecuteSql("update tradelog a ,carbrand b set a.realcarbrand = b.carlogo, a.realsubbrand = b.subcarlogo where a.carbrand = b.carcode and a.subbrand = b.subcarcode and a.id = " + id.ToString());
                                    }
                                    // Global.LogServer.Add(new LogInfo("tradelog", "step:7", (int)EnumLogLevel.DEBUG));

                                    /*
                                     * string sql = "select count(*) from tradelog where startread = " +
                                     * trade.START_READ + " and endread = " + trade.END_READ;
                                     * DataTable dt = Global.mysqlHelper2.GetDataTable(sql);
                                     * if (int.Parse(dt.Rows[0][0].ToString()) == 0)
                                     * {
                                     *  Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->存储加油交易信息: " + trade.toSaveSqlString(), (int)EnumLogLevel.DEBUG));
                                     *  int id = Global.mysqlHelper2.ExecuteSqlGetId(trade.toSaveSqlString());
                                     *  step = "8";
                                     *  if ((trade.BodyColor == "1" && trade.OilClass == "柴油") ||
                                     *      (trade.BodyColor == "0" && trade.OilClass == "汽油"))
                                     *  {
                                     *      Global.mysqlHelper2.ExecuteSql("update tradelog a ,carbrand b set a.realcarbrand = b.carlogo, a.realsubbrand = b.subcarlogo where a.carbrand = b.carcode and a.subbrand = b.subcarcode and a.id = " + id.ToString());
                                     *  }
                                     *  step = "9";
                                     * }
                                     * else
                                     * {
                                     *  Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->存储加油交易信息,该条数据已存在 ", (int)EnumLogLevel.DEBUG));
                                     * }*/
                                }
                                catch (System.Exception ex)
                                {
                                    Global.LogServer.Add(new LogInfo("tradelog", "  SocketTool->ReceiveMasssage :" + ex.ToString(), (int)EnumLogLevel.DEBUG));
                                }
                            }
                            else if (pid == "P91_10003")
                            {
                                foreach (var suborder in obj["data"])
                                {
                                    OrderInfo order = new OrderInfo();
                                    order.GasStation_NO = obj["source"].ToString();
                                    order.REQ_Time      = obj["time"].ToString();
                                    order.MSG_ID        = obj["msgID"].ToString();
                                    order.TRANS_TYPE    = suborder["1"].ToString();
                                    order.TRANS_CODE    = suborder["2"].ToString();
                                    order.BAR_CODE      = suborder["3"].ToString();
                                    order.TRANS_Q       = double.Parse(suborder["4"].ToString());
                                    order.TRANS_PRC     = double.Parse(suborder["6"].ToString());
                                    order.TRANS_AMT     = double.Parse(suborder["5"].ToString());
                                    order.FINISH_TIME   = suborder["7"].ToString();
                                    order.SETTLE_DAY    = suborder["8"].ToString();
                                    order.OilGun_NO     = suborder["9"].ToString();
                                    order.START_READ    = double.Parse(suborder["10"].ToString());
                                    order.END_READ      = double.Parse(suborder["11"].ToString());
                                    order.BILL_NUM      = suborder["12"].ToString();
                                    order.BILL_ITEM_ID  = suborder["13"].ToString();
                                    order.POS_NO        = suborder["14"].ToString();
                                    order.StatusType    = suborder["15"].ToString();
                                    order.Pumpsrv_ref   = suborder["16"].ToString();
                                    Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->存储订单信息: " + order.toSaveSqlString(), (int)EnumLogLevel.DEBUG));

                                    Global.mysqlHelper2.ExecuteSql(order.toSaveSqlString());
                                }
                                foreach (var extra in obj["ext_data"])
                                {
                                    PayInfo pay = new PayInfo();
                                    pay.BILL_NUM     = obj["data"][0]["12"].ToString();
                                    pay.PAY_MODE     = extra["1"].ToString();
                                    pay.PAY_AMT      = double.Parse(extra["2"].ToString());
                                    pay.Discount_AMT = double.Parse(extra["3"].ToString());
                                    pay.PAY_CARD     = extra["4"].ToString();
                                    Global.LogServer.Add(new LogInfo("tradelog", "SocketTool->存储支付信息: " + pay.toSaveSqlString(), (int)EnumLogLevel.DEBUG));
                                    Global.mysqlHelper2.ExecuteSql(pay.toSaveSqlString());
                                }
                            }
                        }
                        else if (Global.ditMode == 1) //DIT动态库模式
                        {
                            if (buff[2] == 0x03 && buff[3] == 2)
                            {
                                SystemUnit.PostMessage(SystemUnit.HWND_BROADCAST, (int)Global.WM_CARSNAP, buff[4], buff[5]);
                            }
                            else if (buff[2] == 0x02 && buff[3] == 58 && count >= 62)
                            {
                                struLoginInfo info    = new struLoginInfo();
                                byte[]        reivBuf = new byte[58];
                                Buffer.BlockCopy(buff, 4, reivBuf, 0, 58);
                                info = (struLoginInfo)SystemUnit.BytesToStruts(reivBuf, typeof(struLoginInfo));
                                string ip        = System.Text.Encoding.Default.GetString(info.byIP);
                                int    port      = info.wPort;
                                string loginName = System.Text.Encoding.Default.GetString(info.byLoginName);
                                string password  = System.Text.Encoding.Default.GetString(info.byPassword);
                                byte[] sendbuf   = new byte[9];
                                sendbuf[0] = 0xFF;
                                sendbuf[1] = 0xFF;
                                sendbuf[2] = 0x02;
                                sendbuf[3] = 1;
                                if (ip == Global.clsNvrInfo.ip && port == Global.clsNvrInfo.port &&
                                    loginName == Global.clsNvrInfo.loginName && password == Global.clsNvrInfo.password)
                                {
                                    sendbuf[4] = 1;//1 成功
                                }
                                else
                                {
                                    sendbuf[4] = 0;//0 失败
                                }
                                ushort crc = SystemUnit.getCRC(sendbuf, 0, 5);
                                sendbuf[5] = (byte)(crc / 256);
                                sendbuf[6] = (byte)(crc % 256);
                                sendbuf[7] = 0xEE;
                                sendbuf[8] = 0xEE;
                                Send(sendbuf);
                            }
                        }
                        else if (Global.ditMode == 2)
                        {
                            string info = Encoding.Default.GetString(buff);
                            Global.LogServer.Add(new LogInfo("Debug", "SocketTool->ReceiveMasssage 接收DIT提挂枪信号:" + info, (int)EnumLogLevel.DEBUG));
                            if (info.IndexOf("PumpFlag") > 0)
                            {
                                PumpInfo pumpInfo = JsonHelper.DeserializeJsonToObject <PumpInfo>(info);
                                Global.currentPump[int.Parse(pumpInfo.PumpID)] = pumpInfo;
                                SystemUnit.PostMessage(SystemUnit.HWND_BROADCAST, (int)Global.WM_CARSNAP, int.Parse(pumpInfo.PumpID), int.Parse(pumpInfo.PumpFlag));
                            }
                        }
                    }
                    Thread.Sleep(30);
                }
                catch (System.Exception ex)
                {
                    // Global.LogServer.Add(new LogInfo("Error", "SocketTool->ReceiveMasssage :" + ex.ToString(), (int)EnumLogLevel.ERROR));
                }
            }
        }