215 lines
8.4 KiB
C#
215 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using SafeMobileLib;
|
|
using System.Collections;
|
|
|
|
namespace AppServerMobile
|
|
{
|
|
class DBhandler
|
|
{
|
|
public DBhandler()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return a list of all dispatchers
|
|
/// </summary>
|
|
/// <returns>ListUser</returns>
|
|
public List<User> 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<User> list = db.getAllDispatcher();
|
|
return list;
|
|
}
|
|
|
|
|
|
public List<AlarmHisItem> 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<AlarmHisItem> 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<Recording> 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<Recording> list = db.GetAllRecordingsForSD(userID,0,0,0);
|
|
List<Recording> 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<Recording> 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<Vehicles> 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<Vehicles> 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<Vehicles> GetVehiclesList(string userID)
|
|
{
|
|
return GetVehiclesList(userID, false);
|
|
}
|
|
|
|
public List<smsmessage> 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<smsmessage> list = db.Get_SMS_for_unit(sc_id, timeGMT);// db.Get_all_SMS_for_unit(sc_id);
|
|
return list;
|
|
}
|
|
|
|
public List<smsmessage> 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<smsmessage> 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<UnitGpsPos> 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<RadioGateway> GetAllRadioGW()
|
|
{
|
|
List<RadioGateway> ret = new List<RadioGateway>();
|
|
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<Gateway> gws = db.getAllGateways();
|
|
foreach (Gateway g in gws)
|
|
{
|
|
List<RadioGateway> rgws = db.gelAllRadioGateways(g.Id);
|
|
ret.AddRange(rgws);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
public List<RadioZones> GetAllRadioZones(int rgw_id)
|
|
{
|
|
List<RadioZones> ret = new List<RadioZones>();
|
|
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<RadioChannels> GetAllRadioChannels(int zone_id)
|
|
{
|
|
List<RadioChannels> ret = new List<RadioChannels>();
|
|
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<UnitGpsPos> 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);
|
|
}
|
|
}
|
|
}
|