using System; using System.Collections.Generic; using System.Linq; using System.Text; using SafeMobileLib; using System.Collections; namespace AppServerMobile { class DBhandler { public DBhandler() { } /// /// Return a list of all dispatchers /// /// ListUser public List GetUserList() { DBuserManager db = new DBuserManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); List list = db.getAllDispatcher(); return list; } public List GetAlarmList(Int32 userID) { DBalarmManager db = new DBalarmManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); List list = db.Get_nonACK_alarms_user_id(userID); ArrayList tmpX = new ArrayList(); foreach (AlarmHisItem obj in list) tmpX.Add(obj); tmpX.Sort(new AlarmHisItemComparer()); list.Clear(); foreach (AlarmHisItem obj in tmpX) list.Add(obj); return list; } public List GetRecordingList(int userID,int Gw_ID,int Radio_gw_id) { DBrecordingsManager db = new DBrecordingsManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); List list = db.GetAllRecordingsForSD(userID,0,0,0); List list2 = db.GetAllRecordingsForGW(Gw_ID, Radio_gw_id,0,0,0,10); foreach (Recording obj in list2) list.Add(obj); ArrayList tmpX = new ArrayList(); foreach (Recording obj in list) tmpX.Add(obj); tmpX.Sort(new RecordingComparer()); list.Clear(); foreach (Recording obj in tmpX) list.Add(obj); return list; } public List GetAllRecordingsForDispatcherAndAssignGateway(ArrayList parameters, Int64 start_time, Int64 stop_time, Int32 useridx) { DBrecordingsManager db = new DBrecordingsManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); return db.GetAllRecordingsForDispatcherAndAssignGateway(parameters, start_time, stop_time, useridx); } public Int32 SendAckAlarm(int ID,Int32 type, string id) { int userId; bool isParsable = Int32.TryParse(id, out userId); if (!isParsable) return 0; DBalarmManager db = new DBalarmManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); AlarmTypes tmpType = AlarmTypes.emergency; switch (type) { case 0: tmpType = AlarmTypes.emergency; break; case 1:tmpType = AlarmTypes.landmark; break; case 2: tmpType = AlarmTypes.zone; break; case 3: tmpType = AlarmTypes.speed; break; case 4: tmpType = AlarmTypes.telemetry; break; } sqlResponse Response = db.ACKalarms(ID, tmpType, userId, DateTime.Now.ToUniversalTime().DateTo70Format()); if (Response == sqlResponse.done) return 1; else return 0; } public List GetVehiclesList(string userID, bool onlyActive) { DBsubsOperationManager dbsub = new DBsubsOperationManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); DBvehiclesManager db = new DBvehiclesManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); List list = db.getAllVehiclesForCurrentUser(userID, onlyActive); foreach (Vehicles veh in list) { int status = 1; try { status = dbsub.getSUenableDisableStatus(veh.Imei); } catch (Exception ex) { SM.Debug(ex.ToString()); } veh.EnableStatus = status; } ArrayList tmpX = new ArrayList(); foreach (Vehicles obj in list) tmpX.Add(obj); tmpX.Sort(new VehicleNameComparer()); list.Clear(); foreach (Vehicles obj in tmpX) list.Add(obj); return list; } public List GetVehiclesList(string userID) { return GetVehiclesList(userID, false); } public List GetSMSforUnit(int sc_id, int timeGMT=0) { DBsmsManager db = new DBsmsManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); List list = db.Get_SMS_for_unit(sc_id, timeGMT);// db.Get_all_SMS_for_unit(sc_id); return list; } public List GetLastSMS(Int32 user_ID) { DBsmsManager db = new DBsmsManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); List list = db.Get_last_SMS_user(user_ID); return list; } public UnitSysPosition GetUnitSysPosition(int sc_id) { DBvehiclesManager db = new DBvehiclesManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); return db.getSystemPosition(sc_id); } public String GetImei(int sc_id) { DBvehiclesManager db = new DBvehiclesManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); return db.getIMEI(sc_id); } public List GetLastPos(int user_id) { DBvehiclesManager db = new DBvehiclesManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); return db.GetLastPosUserID(user_id); } public List GetAllRadioGW() { List ret = new List(); DBgatewaysManager db = new DBgatewaysManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); List gws = db.getAllGateways(); foreach (Gateway g in gws) { List rgws = db.gelAllRadioGateways(g.Id); ret.AddRange(rgws); } return ret; } public List GetAllRadioZones(int rgw_id) { List ret = new List(); DBgatewaysManager db = new DBgatewaysManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); ret = db.gelAllradioZones(rgw_id); return ret; } public List GetAllRadioChannels(int zone_id) { List ret = new List(); DBgatewaysManager db = new DBgatewaysManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); ret = db.gelAllradioChannels(zone_id); return ret; } public List GetGPSHistory(int sc_id, int startGMT, int stopGMT) { DBvehiclesManager db = new DBvehiclesManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); return db.GET_HistoryPositions(sc_id, startGMT, stopGMT); } public string getTalkGroupNameFromCpsId(int group_cpsId) { DBgroupsManager db = new DBgroupsManager(Program.CFG.DB_IP, Program.CFG.DB_schema, Program.CFG.DB_user, Program.CFG.DB_passwd, Program.CFG.DB_port); return db.getTalkGroupNameFromCpsId(group_cpsId); } } }