//辅助数据库更新线程 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; }
//测试数据库连接 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, ""); } } }
//初始化系统数据 private bool LoadInfoFromDB() { bool ret = false; dbm = DBManager.GetInstance(Config.DbHost, Config.DbName, Config.DbUser, Config.DbPw); if (dbm != null) { try { //regionList.Clear(); teamList.Clear(); userList.Clear(); DataTable dt = null; /*dbm.ExecuteQuery("select_region"); * foreach(DataRow dr in dt.Rows) * { * int id = Int32.Parse(dr[0].ToString()); * String s = dr[1].ToString(); * Region region = new Region(dr[2].ToString()); * region.RegionID = id; * region.RegionName = s; * regionList.Add(region); * }*/ dt = dbm.ExecuteQuery("select_team"); foreach (DataRow dr in dt.Rows) { Team team = new Team(); team.TeamID = Int32.Parse(dr[0].ToString()); team.Password = dr[1].ToString(); team.TeamName = dr[2].ToString(); team.TeamLinkman = dr[3].ToString(); team.TeamTel = dr[4].ToString(); team.TeamAddress = dr[5].ToString(); team.JoinTime = dr[6].ToString(); team.PolicyModCar = Int32.Parse(dr[7].ToString()); team.PolicyOrder = Int32.Parse(dr[8].ToString()); team.PolicyRegion = Int32.Parse(dr[9].ToString()); team.PolicyRegionAlarm = Int32.Parse(dr[10].ToString()); teamList.Add(team); } dt = dbm.ExecuteQuery("select_car"); foreach (DataRow dr in dt.Rows) { Car car = Car.ParseWithPosition(dr); if (car != null) { //if(car.RegionID != 0) //car.Region = GetRegionByID(car.RegionID); car.Team = GetTeamByID(car.TeamID); car.Team.Cars.Add(car); } } dt = dbm.ExecuteQuery("select_user"); foreach (DataRow dr in dt.Rows) { User user = new User(); user.UserID = Int32.Parse(dr[0].ToString()); user.UserName = dr[1].ToString(); user.Password = dr[2].ToString(); user.UserType = Int32.Parse(dr[3].ToString()); user.Tel = dr[4].ToString(); user.Email = dr[5].ToString(); user.JoinTime = dr[6].ToString(); if (user.UserType != User.USER_ADMIN) { user.Teams = new List <Team>(); String ts = dr[7].ToString(); if (ts.Length > 0) { if (ts[0] == Constant.SPLIT_EX_1) { ts = ts.Substring(1); } if (ts[ts.Length - 1] == Constant.SPLIT_EX_1) { ts = ts.Substring(0, ts.Length - 1); } } if (ts != null && ts != "") { user.TeamStr = ts; String[] temp = ts.Split(Constant.SPLIT_EX_1); foreach (String s in temp) { if (s == null || s == "") { continue; } try { Team team = GetTeamByID(Int32.Parse(s)); if (team != null) { user.Teams.Add(team); } } catch { } } } else { user.TeamStr = ""; } user.PolicyModTeam = Int32.Parse(dr[8].ToString()); user.PolicyModCar = Int32.Parse(dr[9].ToString()); user.PolicyOrder = Int32.Parse(dr[10].ToString()); user.PolicyExportCars = Int32.Parse(dr[11].ToString()); user.PolicyDeclare = Int32.Parse(dr[12].ToString()); user.PolicyAlarmList = Int32.Parse(dr[13].ToString()); user.PolicyOverTime = Int32.Parse(dr[14].ToString()); user.PolicyNotify = Int32.Parse(dr[15].ToString()); } else { user.Teams = teamList; } userList.Add(user); } dt = dbm.ExecuteQuery("select_alarm"); foreach (DataRow dr in dt.Rows) { AlarmPosition apos = new AlarmPosition(); apos.Id = Int32.Parse(dr[0].ToString()); apos.CarID = Int32.Parse(dr[1].ToString()); apos.GpsTime = dr[2].ToString(); apos.Pointed = Int32.Parse(dr[3].ToString()); apos.Lo = Double.Parse(dr[4].ToString()); apos.La = Double.Parse(dr[5].ToString()); apos.Speed = Int32.Parse(dr[6].ToString()); apos.Direction = Int32.Parse(dr[7].ToString()); apos.Status = dr[8].ToString(); apos.Alarm = dr[9].ToString(); //GetCarByID(apos.CarID).AlarmPos.Add(apos); 启动弹出对话框 } dt = dbm.ExecuteQuery("select carID from tDeclare where opUser=''"); foreach (DataRow dr in dt.Rows) { try { GetCarByID(Int32.Parse(dr[0].ToString())).DeclareCount++; } catch {} } ret = true; } catch (Exception e) { if (FormMain.LOG_ERR) { logger.AddErr(e, ""); } } } inited = ret; return(ret); }