コード例 #1
0
ファイル: DBAssistant.cs プロジェクト: yfyf510/GPS
 //辅助数据库更新线程
 private void UpdateDB()
 {
     while (active)
     {
         try
         {
             //写入操作记录到数据库
             List <String> list = GetPosition();
             list.AddRange(GetOrder());
             list.AddRange(GetOperation());
             //写入记录到数据库
             if (list.Count > 0)
             {
                 DBManager dbm = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw);
                 foreach (String s in list)
                 {
                     dbm.ExecuteUpdate(s);
                 }
                 dbm.Close();
             }
         }
         catch { }
         try
         {
             System.Threading.Thread.Sleep(SLEEP_TIME);
         }
         catch { }
     }
     thread = null;
 }
コード例 #2
0
ファイル: FormMain.Udp.cs プロジェクト: yfyf510/GPS
        void udpConnection_OnReceive(MoonStudio.Udp.UDPConnection uc, string remote, int rPort, string msg)
        {
            try
            {
                //logger.AddMsg("udp终端信息(ascii):" + msg);
                //logger.AddMsg("udp终端信息(hex):" + Pub.RealHexToStr(msg));
                // MessageBox.Show(msg);
                //   MessageBox.Show(msg.Substring(5, 4));

                if (msg.Substring(1, 5) == "SJHXL")
                {
                    String str, str1 = "";
                    str = msg.Substring(6, 8);
                    str = str.Substring(6, 2) + str.Substring(4, 2) + str.Substring(2, 2) + str.Substring(0, 2);
                    DBManager dbms = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw);
                    //  DataTable dt = dbms.ExecuteQuery("select * from Terminal where machineNO="+str+";"); //目前不使用该语句。使用下面的存储过程语句来判断是否存在记录
                    DataTable dt = dbms.ExecuteQuery("select_Terminal " + "'" + str + "'");
                    foreach (DataRow dr in dt.Rows)
                    {
                        str1 = dr[0].ToString();
                    }

                    if (str1 == "")
                    {
                        //  MessageBox.Show("a");
                        dbms.ExecuteUpdate("insert_Terminal " + "'" + str + "'" + "," + "'" + remote + "'" + "," + rPort);
                        string order = Protocol_XunLuoShu.AutoOrder(false, str);
                        udpConnection.Send(remote, rPort, order);
                        dbms.ExecuteUpdate("insert_Terminal " + "'" + str + "'" + "," + "'" + remote + "'" + "," + rPort);
                        order = Protocol_XunLuoShu.AutoOrder(false, str);
                        udpConnection.Send(remote, rPort, order);
                        dbms.ExecuteUpdate("insert_Terminal " + "'" + str + "'" + "," + "'" + remote + "'" + "," + rPort);
                        order = Protocol_XunLuoShu.AutoOrder(false, str);
                        udpConnection.Send(remote, rPort, order);
                    }
                    else
                    {
                        // MessageBox.Show("b");
                        dbms.ExecuteUpdate("update_Terminal " + "'" + str + "'" + "," + rPort + "," + "'" + remote + "'");
                    }


                    dbms.Close();
                }

                if (msg.Substring(5, 4) == "TEST")
                {
                    udpConnection.Send(remote, rPort, msg);
                }

                /* 检测GPRS网络是否发生虚连接 巡逻鼠硬件
                 * E、判断车机与中心的连接情况
                 * 实例:设备定时向中心发送字符“$SJHXTEST,”中心收到后原样字符串“$SJHXTEST,”发送给此IP地址即可,而不用管是哪个设备ID号码发过来的。
                 * //*/
                GPSInfo gi = new GPSInfo(msg, remote, rPort);

                analyzer.AddInInfo(gi);
            }
            catch (Exception e)
            {
                if (FormMain.LOG_ERR)
                {
                    logger.AddErr(e, "");
                }
            }
        }