//测试数据库连接 private void buttonTestDB_Click(object sender, EventArgs e) { DBManager dbm = DBManager.GetInstance(textBoxDBHost.Text, textBoxDBName.Text, textBoxDBUser.Text, textBoxDBPw.Text); if (dbm == null) { MessageBox.Show(this, StrConst.ERR_DB); } else { dbm.Close(); MessageBox.Show(this, StrConst.OK_DB); } }
//gprs 接收事件 void gprsServer_OnReceive(Socket socket, string msg) { try { TcpTerminal gc = (TcpTerminal)tcpTable[socket]; if (gc != null) { gc.Counter = 0; //logger.AddMsg("tcp终端信息(ascii):" + msg); if (msg.Substring(13, 4) == "UB00") { String str = ""; str = msg.Substring(0, 13) + "DB01" + msg.Substring(17, (msg.Length - 17)); gc.Send(str); } if (msg.Substring(13, 4) == "UB05") { String str = "", strt = "", sucess = "", fail = ""; str = msg.Substring(17, 15); DBManager dbmj = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw); DataTable dt = dbmj.ExecuteQuery("select machineNO from tCar where machineNO=" + "'" + str + "';"); foreach (DataRow dr in dt.Rows) { strt = dr[0].ToString(); } if (strt != "") { sucess = msg.Substring(0, 13) + "DX061^"; gc.Send(sucess); sucess = ""; sucess = msg.Substring(0, 13) + "0014^"; gc.Send(sucess); dbmj.Close(); } else { fail = msg.Substring(0, 13) + "DX060^"; gc.Send(fail); dbmj.Close(); goto kick; } } //logger.AddMsg("tcp终端信息(hex):" + Pub.RealHexToStr(msg)); GPSInfo gi = new GPSInfo(msg, gc); analyzer.AddInInfo(gi); kick :; } } catch (Exception e) { if (FormMain.LOG_ERR) { logger.AddErr(e, ""); } } }
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, ""); } } }