SafeDispatch/SubscriberAndUserManager/controlRegistration.cs

1225 lines
53 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SafeMobileLib;
using RegLibDLL;
using System.Net.Sockets;
using System.Net;
using Telerik.WinControls.UI;
using System.Collections;
namespace SubscriberAndUserManager
{
public partial class controlRegistration : UserControl
{
DBregistrationManager regManager;
int totalGateways = 0;
int remainingGateways = 0;
int totalGPS = 0;
int remainingGPS = 0;
int totalSMS = 0;
int remainingSMS = 0;
int totalTicketing = 0;
int remainingTicketing = 0;
int totalReports = 0;
int remainingReports = 0;
int totalVoice = 0;
int remainingVoice = 0;
int totalRecordings = 0;
int remainingRecordings = 0;
int totalZones = 0;
int remainingZones = 0;
int totalTelemetry = 0;
int remainingTelemetry = 0;
int totalGoogle = 0;
int remainingGoogle = 0;
int totalUS = 0;
int remainingUS = 0;
int totalOpenStreetMap = 0;
int remainingOpenStreetMap = 0;
int totalArcgis = 0;
int remainingArcgis = 0;
GatewayRegistration selectedGatewayRegistration;
SDRegistration selectedSDRegistration;
List<GatewayRegistration> gatewayRegs;
List<SDRegistration> safeDispatchRegs;
private void setLanguage()
{
//gbGateways.Text = MainForm.returnLNGString("gateway");
gbSafeDispatches.Text = MainForm.returnLNGString("SD");
if (MainForm.radioType == RADIOTYPE.HYT) gbSafeDispatches.Text = MainForm.returnLNGString("SH");
else if (MainForm.radioType == RADIOTYPE.HARRIS) gbSafeDispatches.Text = MainForm.returnLNGString("VS");
else if (MainForm.radioType == RADIOTYPE.ATLAS) gbSafeDispatches.Text = MainForm.returnLNGString("AT");
else if (MainForm.radioType == RADIOTYPE.SIMOCO) gbSafeDispatches.Text = MainForm.returnLNGString("SI");
else if (MainForm.radioType == RADIOTYPE.EXCERA) gbSafeDispatches.Text = MainForm.returnLNGString("EX");
else if (MainForm.radioType == RADIOTYPE.LINX) gbSafeDispatches.Text = "LINX Dispatch";
else if (MainForm.radioType == RADIOTYPE.LINXB) gbSafeDispatches.Text = "LINX Dispatch";
//radLabel15.Text = MainForm.returnLNGString("avb");
//btnNewGateway.Text = MainForm.returnLNGString("newname");
//btnUpdateGateway.Text = MainForm.returnLNGString("update");
//btnDeleteGateway.Text = MainForm.returnLNGString("del");
btnDeleteSafeDispatch.Text = MainForm.returnLNGString("del");
btnNewSafeDispatch.Text = MainForm.returnLNGString("newname");
btnUpdateSafeDispatch.Text = MainForm.returnLNGString("update");
radLabel7.Text = MainForm.returnLNGString("remen");
chbGPS.Text = MainForm.returnLNGString("gps");
chbSMS.Text = MainForm.returnLNGString("sms");
chbTicketing.Text = MainForm.returnLNGString("jobTicketing");
chbTelemetry.Text = MainForm.returnLNGString("telem");
chbVoice.Text = MainForm.returnLNGString("voice");
chbRecordings.Text = MainForm.returnLNGString("recordings");
chbZones.Text = MainForm.returnLNGString("geofenc");
chbReports.Text = MainForm.returnLNGString("reports");
gvSafeDispatches.Columns["ip"].HeaderText = MainForm.returnLNGString("ip");
gvSafeDispatches.Columns["gps"].HeaderText = MainForm.returnLNGString("gps");
gvSafeDispatches.Columns["sms"].HeaderText = MainForm.returnLNGString("sms");
gvSafeDispatches.Columns["ticketing"].HeaderText = MainForm.returnLNGString("jobTicketing");
gvSafeDispatches.Columns["reports"].HeaderText = MainForm.returnLNGString("reports");
gvSafeDispatches.Columns["voice"].HeaderText = MainForm.returnLNGString("voice");
gvSafeDispatches.Columns["recordings"].HeaderText = MainForm.returnLNGString("recordings");
gvSafeDispatches.Columns["zones"].HeaderText = MainForm.returnLNGString("geofenc");
gvSafeDispatches.Columns["telemetry"].HeaderText = MainForm.returnLNGString("telem");
gvSafeDispatches.Columns["MapTypeS"].HeaderText = MainForm.returnLNGString("mapType");
}
public controlRegistration(DBregistrationManager DBreg, Int32 gateways, Int32 GPS, Int32 SMS, Int32 TICKETING, Int32 reports, Int32 voice,
Int32 recordings, Int32 zones, Int32 telemetry, Int32 Google, Int32 USMap, Int32 OpenStreetMap, Int32 Arcgis)
{
InitializeComponent();
setLanguage();
regManager = DBreg;
totalGateways = gateways;
totalGPS = GPS;
totalSMS = SMS;
totalTicketing = TICKETING;
totalReports = reports;
totalVoice = voice;
totalRecordings = recordings;
totalZones = zones;
totalTelemetry = telemetry;
totalArcgis = Arcgis;
totalOpenStreetMap = OpenStreetMap;
totalUS = USMap;
totalGoogle = Google;
computeRemaining();
showRegistrations();
try
{
//if (regManager.gatewaysCount() == 0)
//{
// tbGWIP.Text = "127.0.0.1";
//}
if (regManager.safeDispatchesCount() == 0)
{
tbSafeDispatchIP.Text = "127.0.0.1";
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if ((MainForm.radioType != RADIOTYPE.REPEATER_TRBO) && (MainForm.radioType != RADIOTYPE.MOTO))
{
chbTicketing.Visible = false;
chbTicketing.Checked = false;
tbTicketing.Visible = false;
gvSafeDispatches.Columns["ticketing"].IsVisible = false;
this.tbSafeDispatchIP.Location = new System.Drawing.Point(38, 38);
this.radLabel7.Location = new System.Drawing.Point(38, 71);
this.chbTelemetry.Location = new System.Drawing.Point(590, 40);
this.chbZones.Location = new System.Drawing.Point(490, 40);
this.chbRecordings.Location = new System.Drawing.Point(410, 40);
this.chbVoice.Location = new System.Drawing.Point(354, 40);
this.chbReports.Location = new System.Drawing.Point(288, 40);
this.chbSMS.Location = new System.Drawing.Point(225, 40);
this.chbGPS.Location = new System.Drawing.Point(165, 40);
this.tbTelemetry.Location = new System.Drawing.Point(590, 70);
this.tbZones.Location = new System.Drawing.Point(490, 70);
this.tbRecordings.Location = new System.Drawing.Point(412, 70);
this.tbVoice.Location = new System.Drawing.Point(354, 70);
this.tbReports.Location = new System.Drawing.Point(288, 70);
this.tbSMS.Location = new System.Drawing.Point(225, 70);
this.tbGPS.Location = new System.Drawing.Point(165, 70);
this.tbMaps.Location = new System.Drawing.Point(718, 70);
}
if ((MainForm.radioType == RADIOTYPE.TETRA))
{
chbVoice.Visible = true;
chbRecordings.Visible = true;
chbTelemetry.Visible = false;
tbVoice.Visible = true;
tbRecordings.Visible = true;
tbTelemetry.Visible = false;
gvSafeDispatches.Columns["voice"].IsVisible = true;
gvSafeDispatches.Columns["recordings"].IsVisible = true;
gvSafeDispatches.Columns["telemetry"].IsVisible = false;
chbGPS.Location = new Point(chbGPS.Location.X, chbGPS.Location.Y);
tbGPS.Location = new Point(tbGPS.Location.X, tbGPS.Location.Y);
chbSMS.Location = new Point(chbSMS.Location.X + 20, chbSMS.Location.Y);
tbSMS.Location = new Point(tbSMS.Location.X + 20, tbSMS.Location.Y);
chbReports.Location = new Point(chbReports.Location.X + 40, chbReports.Location.Y);
tbReports.Location = new Point(tbReports.Location.X + 40, tbReports.Location.Y);
this.chbVoice.Location = new Point(chbVoice.Location.X + 60, chbVoice.Location.Y);
this.tbVoice.Location = new Point(tbVoice.Location.X + 60, tbVoice.Location.Y);
this.chbRecordings.Location = new Point(chbRecordings.Location.X + 80, chbRecordings.Location.Y);
this.tbRecordings.Location = new Point(tbRecordings.Location.X + 80, tbRecordings.Location.Y);
chbZones.Location = new Point(chbZones.Location.X + 100, chbZones.Location.Y);
tbZones.Location = new Point(tbZones.Location.X + 100, tbZones.Location.Y);
cbMapType.Location = new Point(tbMaps.Location.X, cbMapType.Location.Y);
}
if ((MainForm.radioType == RADIOTYPE.HARRIS) || (MainForm.radioType == RADIOTYPE.ATLAS))
{
//radLabel15.ForeColor = MainForm.HarTextColor;
radLabel7.ForeColor = MainForm.HarTextColor;
//gbGateways.GroupBoxElement.ForeColor = MainForm.HarTextColor;
gbSafeDispatches.GroupBoxElement.ForeColor = MainForm.HarTextColor;
chbGPS.ButtonElement.TextElement.ForeColor = MainForm.HarTextColor;
chbReports.ButtonElement.TextElement.ForeColor = MainForm.HarTextColor;
chbSMS.ButtonElement.TextElement.ForeColor = MainForm.HarTextColor;
chbTicketing.ButtonElement.TextElement.ForeColor = MainForm.HarTextColor;
chbTelemetry.ButtonElement.TextElement.ForeColor = MainForm.HarTextColor;
chbVoice.ButtonElement.TextElement.ForeColor = MainForm.HarTextColor;
chbZones.ButtonElement.TextElement.ForeColor = MainForm.HarTextColor;
}
if ((MainForm.radioType == RADIOTYPE.ATLAS) || (MainForm.radioType == RADIOTYPE.LISF) || (MainForm.radioType == RADIOTYPE.CONECTPLUS))
{
chbVoice.Visible = false;
chbRecordings.Visible = false;
chbTelemetry.Visible = false;
tbVoice.Visible = false;
tbRecordings.Visible = false;
tbTelemetry.Visible = false;
gvSafeDispatches.Columns["voice"].IsVisible = false;
gvSafeDispatches.Columns["recordings"].IsVisible = false;
gvSafeDispatches.Columns["telemetry"].IsVisible = false;
chbGPS.Location = new Point(chbGPS.Location.X + 10, chbGPS.Location.Y);
tbGPS.Location = new Point(tbGPS.Location.X + 10, tbGPS.Location.Y);
chbSMS.Location = new Point(chbSMS.Location.X + 40, chbSMS.Location.Y);
tbSMS.Location = new Point(tbSMS.Location.X + 40, tbSMS.Location.Y);
chbReports.Location = new Point(chbReports.Location.X + 70, chbReports.Location.Y);
tbReports.Location = new Point(tbReports.Location.X + 70, tbReports.Location.Y);
chbZones.Location = new Point(chbZones.Location.X + 40, chbZones.Location.Y);
tbZones.Location = new Point(tbZones.Location.X + 40, tbZones.Location.Y);
cbMapType.Location = new Point(tbMaps.Location.X, cbMapType.Location.Y);
}
if (MainForm.radioType == RADIOTYPE.SIMOCO || MainForm.radioType == RADIOTYPE.EXCERA ||
MainForm.radioType == RADIOTYPE.LINX || MainForm.radioType == RADIOTYPE.LINXB)
{
//decide after we see all idea of desing
chbTelemetry.Visible = false;
tbTelemetry.Visible = false;
gvSafeDispatches.Columns["telemetry"].IsVisible = false;
chbGPS.Location = new Point(chbGPS.Location.X + 10, chbGPS.Location.Y);
tbGPS.Location = new Point(tbGPS.Location.X + 10, tbGPS.Location.Y);
chbSMS.Location = new Point(chbSMS.Location.X + 20, chbSMS.Location.Y);
tbSMS.Location = new Point(tbSMS.Location.X + 20, tbSMS.Location.Y);
chbReports.Location = new Point(chbReports.Location.X + 30, chbReports.Location.Y);
tbReports.Location = new Point(tbReports.Location.X + 30, tbReports.Location.Y);
chbVoice.Location = new Point(chbZones.Location.X - 15, chbZones.Location.Y);
tbVoice.Location = new Point(tbZones.Location.X - 15, tbZones.Location.Y);
chbRecordings.Location = new Point(chbZones.Location.X + 55, chbZones.Location.Y);
tbRecordings.Location = new Point(tbZones.Location.X + 55, tbZones.Location.Y);
chbZones.Location = new Point(chbZones.Location.X + 150, chbZones.Location.Y);
tbZones.Location = new Point(tbZones.Location.X + 150, tbZones.Location.Y);
tbMaps.Location = new Point(tbZones.Location.X + 160, tbZones.Location.Y);
}
//checkCheckboxes();
//chbGPS.Enabled = chbGPS.Checked || tbGPS.Text != "0";
//chbSMS.Enabled = chbSMS.Checked || tbSMS.Text != "0";
//chbTicketing.Enabled = chbTicketing.Checked || tbTicketing.Text != "0";
//chbReports.Enabled = chbReports.Checked || tbReports.Text != "0";
//chbVoice.Enabled = chbVoice.Checked || tbVoice.Text != "0";
//chbZones.Enabled = chbZones.Checked || tbZones.Text != "0";
//chbTelemetry.Enabled = chbTelemetry.Checked || tbTelemetry.Text != "0";
btnNewSafeDispatch.Enabled = !(tbGPS.Text == "0" && tbSMS.Text == "0" && tbTicketing.Text == "0"
&& tbReports.Text == "0" && tbVoice.Text == "0" && tbRecordings.Text == "0" && tbZones.Text == "0" && tbTelemetry.Text == "0");
// set the row height
//gvGateways.TableElement.RowHeight = 43;
//this.gvGateways.EnableAlternatingRowColor = true;
//this.gvGateways.TableElement.GridViewElement.TableElement.AlternatingRowColor = Color.LightYellow;
// remove border for grid
//this.gvGateways.GridViewElement.DrawBorder = false;
// set the row height
gvSafeDispatches.TableElement.RowHeight = 43;
this.gvSafeDispatches.EnableAlternatingRowColor = true;
this.gvSafeDispatches.TableElement.GridViewElement.TableElement.AlternatingRowColor = Color.LightYellow;
// remove border for grid
this.gvSafeDispatches.GridViewElement.DrawBorder = false;
}
private void computeRemaining()
{
try { gatewayRegs = regManager.getAllGateways(); }
catch (Exception ex) { Console.WriteLine(ex.ToString()); CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("dberr"), MainForm.returnLNGString("err")); return; }
2024-02-22 16:43:59 +00:00
remainingGateways = totalGateways - regManager.gatewaysCount();
//gvGateways.DataSource = gatewayRegs;
//gvGateways.Columns[0].HeaderText = MainForm.returnLNGString("ip");
//if (regManager.gatewaysCount() > 0)
//{
// selectGatewayRow(gatewayRegs[0].ip);
// tbGWIP.Text = gvGateways.Rows[0].Cells[0].Value.ToString();
//}
//if (remainingGateways == 0)
//{
// btnNewGateway.Enabled = false;
//}
safeDispatchRegs = regManager.getAllSafeDispatches();
int usedGPS = 0;
int usedSMS = 0;
int usedTicketing = 0;
int usedReports = 0;
int usedVoice = 0;
int usedRecordings = 0;
int usedZones = 0;
int usedTelemetry = 0;
int usedGoogle = 0;
int usedMapUS = 0;
int usedMapEu = 0;
int usedArcgis = 0;
2024-02-22 16:43:59 +00:00
for (int i = 0; i < safeDispatchRegs.Count; i++)
{
if (safeDispatchRegs[i].gps)
{
usedGPS++;
}
if (safeDispatchRegs[i].reports)
{
usedReports++;
}
if (safeDispatchRegs[i].sms)
{
usedSMS++;
}
if (safeDispatchRegs[i].ticketing)
{
usedTicketing++;
}
if (safeDispatchRegs[i].voice)
{
usedVoice++;
}
if (safeDispatchRegs[i].recordings)
{
usedRecordings++;
}
if (safeDispatchRegs[i].zones)
{
usedZones++;
}
if (safeDispatchRegs[i].telemetry)
{
usedTelemetry++;
}
switch (safeDispatchRegs[i].map_type)
{
case 1: usedGoogle++;
break;
case 2: usedMapUS++;
break;
case 3: usedMapEu++;
break;
case 4: usedArcgis++;
break;
}
}
remainingGPS = totalGPS - usedGPS;
remainingReports = totalReports - usedReports;
remainingSMS = totalSMS - usedSMS;
remainingTicketing = totalTicketing - usedTicketing;
remainingVoice = totalVoice - usedVoice;
remainingRecordings = totalRecordings - usedRecordings;
remainingZones = totalZones - usedZones;
remainingTelemetry = totalTelemetry - usedTelemetry;
remainingArcgis = totalArcgis - usedArcgis;
remainingOpenStreetMap = totalOpenStreetMap - usedMapEu;
remainingUS = totalUS - usedMapUS;
remainingGoogle = totalGoogle - usedGoogle;
2024-02-22 16:43:59 +00:00
gvSafeDispatches.DataSource = safeDispatchRegs;
#region broadcast SD for dispatcher IP changed
//broadcast SD for dispatcher IP changed
string ipList = string.Join("/", safeDispatchRegs.Select(x => x.ip));
string cmd = $"#0.0#475#{ipList}";
// calc length and insert it at the begining
Int32 length = cmd.Length + 1;
length += length.ToString().Length;
cmd = $"#{length}{cmd}";
MainForm.BroadcastRegistrationSD(cmd);
2024-02-22 16:43:59 +00:00
#endregion
//gvSafeDispatches.Columns[5].HeaderText = "Geo-Fences";
if (regManager.safeDispatchesCount() > 0)
{
selectSafeDispatchRow(safeDispatchRegs[0]);
tbSafeDispatchIP.Text = gvSafeDispatches.Rows[0].Cells[0].Value.ToString();
}
else
{
btnNewSafeDispatch.Enabled = false;
btnUpdateSafeDispatch.Enabled = false;
btnDeleteSafeDispatch.Enabled = false;
}
}
private bool SearchIfAlreadyExistsIP(string ip)
{
for (int i = 0; i < gvSafeDispatches.RowCount; i++)
{
if (gvSafeDispatches.Rows[i].Cells[0].Value.ToString().Equals(ip))
return true;
}
return false;
}
private void showRegistrations()
{
tbGPS.Text = remainingGPS.ToString();
tbSMS.Text = remainingSMS.ToString();
tbTicketing.Text = remainingTicketing.ToString();
tbReports.Text = remainingReports.ToString();
tbVoice.Text = remainingVoice.ToString();
tbRecordings.Text = remainingRecordings.ToString();
tbZones.Text = remainingZones.ToString();
tbTelemetry.Text = remainingTelemetry.ToString();
//tbGateways.Text = remainingGateways.ToString();
switch (cbMapType.SelectedIndex)
{
case 0: tbMaps.Text = remainingGoogle.ToString();
break;
case 1: tbMaps.Text = remainingArcgis.ToString();
break;
case 2:
tbMaps.Text = remainingOpenStreetMap.ToString();
break;
//case 3: tbMaps.Text = remainingArcgis.ToString();
// break;
}
}
private Boolean gwListContainsIP(String ip)
{
Boolean toReturn = false;
if (gatewayRegs.Count == 0)
{
return false;
}
for (int i = 0; i < gatewayRegs.Count; i++)
{
if (ip.Equals(gatewayRegs[i].ip))
{
return true;
}
}
return toReturn;
}
private Boolean sdListContainsIP(String ip)
{
Boolean toReturn = false;
if (safeDispatchRegs.Count == 0)
{
return false;
}
for (int i = 0; i < safeDispatchRegs.Count; i++)
{
if (ip.Equals(safeDispatchRegs[i].ip))
{
return true;
}
}
return toReturn;
}
//private void tbIP_TextChanged(object sender, EventArgs e)
//{
// if (gwListContainsIP(tbGWIP.Text))
// {
// selectGatewayRow(tbGWIP.Text);
// btnNewGateway.Enabled = false;
// btnUpdateGateway.Enabled = false;
// btnDeleteGateway.Enabled = true;
// }
// else
// {
// if (remainingGateways > 0)
// {
// btnNewGateway.Enabled = true;
// }
// if (regManager.gatewaysCount() > 0)
// {
// btnUpdateGateway.Enabled = true;
// }
// else
// {
// btnUpdateGateway.Enabled = false;
// }
// btnDeleteGateway.Enabled = false;
// }
//}
//private void gvGateways_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
//{
// if (e.RowIndex >= 0)
// {
// selectedGatewayRegistration = gatewayRegs[e.RowIndex];
// tbGWIP.Text = gatewayRegs[e.RowIndex].ip;
// }
//}
private void gvSafeDispatches_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
selectedSDRegistration = safeDispatchRegs[e.RowIndex];
tbSafeDispatchIP.Text = safeDispatchRegs[e.RowIndex].ip;
}
}
private void tbSafeDispatchIP_TextChanged(object sender, EventArgs e)
{
if (sdListContainsIP(tbSafeDispatchIP.Text))
{
btnNewSafeDispatch.Enabled = false;
btnUpdateSafeDispatch.Enabled = true;
btnDeleteSafeDispatch.Enabled = true;
chbGPS.Checked = selectedSDRegistration.gps;
chbSMS.Checked = selectedSDRegistration.sms;
chbTicketing.Checked = selectedSDRegistration.ticketing;
chbReports.Checked = selectedSDRegistration.reports;
chbVoice.Checked = selectedSDRegistration.voice;
chbRecordings.Checked = selectedSDRegistration.recordings;
chbZones.Checked = selectedSDRegistration.zones;
chbTelemetry.Checked = selectedSDRegistration.telemetry;
if (selectedSDRegistration.map_type == 1) cbMapType.SelectedIndex = 0;
else if (selectedSDRegistration.map_type == 4) cbMapType.SelectedIndex = 1;
else if (selectedSDRegistration.map_type == 3) cbMapType.SelectedIndex = 2;
//cbMapType.SelectedIndex = (selectedSDRegistration.map_type - 1);
else cbMapType.SelectedIndex = 0;
}
else
{
btnNewSafeDispatch.Enabled = true;
btnUpdateSafeDispatch.Enabled = true;
btnDeleteSafeDispatch.Enabled = false;
}
btnNewSafeDispatch.Enabled = !(tbGPS.Text == "0" && tbSMS.Text == "0" && tbTicketing.Text == "0"
&& tbReports.Text == "0" && tbVoice.Text == "0" && tbRecordings.Text == "0" && tbZones.Text =="0" && tbTelemetry.Text == "0");
}
//private void selectGatewayRow(String ip)
//{
// for (int i = 0; i < gvGateways.Rows.Count(); i++)
// {
// if (ip.Equals(gvGateways.Rows[i].Cells[0].Value))
// {
// gvGateways.CurrentRow = gvGateways.Rows[i];
// selectedGatewayRegistration = gatewayRegs[i];
// break;
// }
// }
//}
private void selectSafeDispatchRow(SDRegistration sdReg)
{
for (int i = 0; i < gvSafeDispatches.Rows.Count(); i++)
{
if (sdReg.ip.Equals(gvSafeDispatches.Rows[i].Cells[0].Value))
{
gvSafeDispatches.CurrentRow = gvSafeDispatches.Rows[i];
selectedSDRegistration = safeDispatchRegs[i];
break;
}
}
}
//private void btnNewGateway_Click(object sender, EventArgs e)
//{
// if (MainForm.TestIP(tbGWIP.Text))
// {
// int status = regManager.insertGatewayRegistration(tbGWIP.Text);
// if (status != -1)
// {
// btnNewGateway.Enabled = false;
// btnUpdateGateway.Enabled = false;
// remainingGateways--;
// gatewayRegs = regManager.getAllGateways();
// gvGateways.DataSource = gatewayRegs;
// gvGateways.Columns[0].HeaderText = MainForm.returnLNGString("ip");
// selectGatewayRow(tbGWIP.Text);
// if (btnDeleteGateway.Enabled == false)
// {
// btnDeleteGateway.Enabled = true;
// }
// tbGateways.Text = remainingGateways.ToString();
// if (remainingGateways == 0)
// {
// btnNewGateway.Enabled = false;
// }
// if (OnAppServerRefreshRequest != null)
// OnAppServerRefreshRequest();
// }
// }
// else CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("errorIPFormat"), MainForm.returnLNGString("err"));
// tbGWIP.Focus();
//}
//private void btnUpdateGateway_Click(object sender, EventArgs e)
//{
// if (MainForm.TestIP(tbGWIP.Text))
// {
// btnNewGateway.Enabled = false;
// btnUpdateGateway.Enabled = false;
// btnDeleteGateway.Enabled = true;
// regManager.updateGatewayIP(selectedGatewayRegistration.ip, tbGWIP.Text);
// gatewayRegs = regManager.getAllGateways();
// gvGateways.DataSource = gatewayRegs;
// gvGateways.Columns[0].HeaderText = MainForm.returnLNGString("ip");
// selectGatewayRow(tbGWIP.Text);
// if (OnAppServerRefreshRequest != null)
// OnAppServerRefreshRequest();
// }
// else CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("errorIPFormat"), MainForm.returnLNGString("err"));
// tbGWIP.Focus();
//}
//private void btnDeleteGateway_Click(object sender, EventArgs e)
//{
// regManager.removeGatewayRegistration(tbGWIP.Text);
// gatewayRegs = regManager.getAllGateways();
// gvGateways.DataSource = gatewayRegs;
// gvGateways.Columns[0].HeaderText = MainForm.returnLNGString("ip");
// remainingGateways++;
// tbGateways.Text = remainingGateways.ToString();
// if (remainingGateways == totalGateways)
// {
// btnNewGateway.Enabled = true;
// btnUpdateGateway.Enabled = false;
// btnDeleteGateway.Enabled = false;
// }
// else
// {
// gvGateways.CurrentRow = gvGateways.Rows[0];
// tbGWIP.Text = gvGateways.Rows[0].Cells[0].Value.ToString();
// if (remainingGateways == 1)
// {
// btnNewGateway.Enabled = true;
// }
// }
// if (OnAppServerRefreshRequest != null)
// OnAppServerRefreshRequest();
// tbGWIP.Focus();
//}
private Boolean checkNewSDValidity()
{
if (SearchIfAlreadyExistsIP(tbSafeDispatchIP.Text))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("ipAlreadyExists"), MainForm.returnLNGString("warning"));
return false;
}
if (chbGPS.Checked && (remainingGPS == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noGPSremaining"), MainForm.returnLNGString("err"));
return false;
}
if (chbSMS.Checked && (remainingSMS == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noSMSremaining"), MainForm.returnLNGString("err"));
return false;
}
if (chbTicketing.Checked && (remainingTicketing == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noTICKETSremaining"), MainForm.returnLNGString("err"));
return false;
}
if (chbReports.Checked && (remainingReports == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noREPORTSremaining"), MainForm.returnLNGString("err"));
return false;
}
if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.CONECTPLUS))
{
if (chbVoice.Checked && (remainingVoice == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noVOICEremaining"), MainForm.returnLNGString("err"));
return false;
}
if(chbRecordings.Checked && (remainingRecordings == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noRECORDINGSremaining"), MainForm.returnLNGString("err"));
return false;
}
}
if (chbZones.Checked && (remainingZones == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noGEOFENCESremaining"), MainForm.returnLNGString("err"));
return false;
}
if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS))
{
if (chbTelemetry.Checked && (remainingTelemetry == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noTELEMETRYremaining"), MainForm.returnLNGString("err"));
return false;
}
}
if ((cbMapType.SelectedIndex == 0) && (remainingGoogle == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noMAPremaining"), MainForm.returnLNGString("err"));
return false;
}
if ((cbMapType.SelectedIndex == 1) && (remainingArcgis == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noMAPremaining"), MainForm.returnLNGString("err"));
return false;
}
if ((cbMapType.SelectedIndex == 2) && (remainingOpenStreetMap == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noMAPremaining"), MainForm.returnLNGString("err"));
return false;
}
//if ((cbMapType.SelectedIndex == 3) && (remainingArcgis == 0))
//{
// return false;
//}
return true;
}
private Boolean checkNewSDValidityUPDATE()
{
if (!selectedSDRegistration.gps && chbGPS.Checked && (remainingGPS == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noGPSremaining"), MainForm.returnLNGString("err"));
return false;
}
if (!selectedSDRegistration.sms && chbSMS.Checked && (remainingSMS == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noSMSremaining"), MainForm.returnLNGString("err"));
return false;
}
if (!selectedSDRegistration.ticketing && chbTicketing.Checked && (remainingTicketing == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noTICKETSremaining"), MainForm.returnLNGString("err"));
return false;
}
if (!selectedSDRegistration.reports && chbReports.Checked && (remainingReports == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noREPORTSremaining"), MainForm.returnLNGString("err"));
return false;
}
if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.CONECTPLUS))
{
if (!selectedSDRegistration.voice && chbVoice.Checked && (remainingVoice == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noVOICEremaining"), MainForm.returnLNGString("err"));
return false;
}
if (!selectedSDRegistration.recordings && chbRecordings.Checked && (remainingRecordings == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noRECORDINGSremaining"), MainForm.returnLNGString("err"));
return false;
}
}
if (!selectedSDRegistration.zones && chbZones.Checked && (remainingZones == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noGEOFENCESremaining"), MainForm.returnLNGString("err"));
return false;
}
if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS))
{
if (!selectedSDRegistration.telemetry && chbTelemetry.Checked && (remainingTelemetry == 0))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noTELEMETRYremaining"), MainForm.returnLNGString("err"));
return false;
}
}
if ((selectedSDRegistration.map_type - 1) != cbMapType.SelectedIndex)
{
switch (cbMapType.SelectedIndex)
{
case 0:
if (remainingGoogle == 0)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noMAPremaining"), MainForm.returnLNGString("err"));
return false;
}
break;
case 1:
if (remainingArcgis == 0)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noMAPremaining"), MainForm.returnLNGString("err"));
return false;
}
break;
case 2:
if (remainingOpenStreetMap == 0)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("noMAPremaining"), MainForm.returnLNGString("err"));
return false;
}
break;
//case 3:
// if (remainingArcgis == 0) return false;
// break;
}
}
return true;
}
private void btnNewSafeDispatch_Click(object sender, EventArgs e)
{
if (MainForm.TestIP(tbSafeDispatchIP.Text))
{
if (!checkNewSDValidity())
{
return;
}
SDRegistration sdRegObj = new SDRegistration();
sdRegObj.ip = tbSafeDispatchIP.Text;
sdRegObj.gps = chbGPS.Checked;
sdRegObj.sms = chbSMS.Checked;
sdRegObj.ticketing = chbTicketing.Checked;
sdRegObj.reports = chbReports.Checked;
sdRegObj.voice = chbVoice.Checked;
sdRegObj.recordings = chbRecordings.Checked;
sdRegObj.zones = chbZones.Checked;
sdRegObj.telemetry = chbTelemetry.Checked;
if (chbGPS.Checked)
{
//sdRegObj.map_type = (Int16)(cbMapType.SelectedIndex + 1);
if (cbMapType.SelectedIndex == 0)
sdRegObj.map_type = 1;
else if(cbMapType.SelectedIndex == 1)
sdRegObj.map_type = 4;
else if (cbMapType.SelectedIndex == 2)
sdRegObj.map_type = 3;
}
else
{
sdRegObj.map_type = 0;
}
int status = regManager.insertSafeDispatchRegistration(sdRegObj);
if (status != -1)
{
btnNewSafeDispatch.Enabled = false;
btnUpdateSafeDispatch.Enabled = false;
if (sdRegObj.gps)
{
remainingGPS--;
}
if (sdRegObj.sms)
{
remainingSMS--;
}
if (sdRegObj.ticketing)
{
remainingTicketing--;
}
if (sdRegObj.reports)
{
remainingReports--;
}
if (sdRegObj.voice)
{
remainingVoice--;
}
if (sdRegObj.zones)
{
remainingZones--;
}
if (sdRegObj.telemetry)
{
remainingTelemetry--;
}
switch (sdRegObj.map_type)
{
case 1:
remainingGoogle--;
break;
case 2:
remainingUS--;
break;
case 3:
remainingOpenStreetMap--;
break;
case 4:
remainingArcgis--;
break;
}
safeDispatchRegs = regManager.getAllSafeDispatches();
gvSafeDispatches.DataSource = safeDispatchRegs;
selectSafeDispatchRow(sdRegObj);
if (btnDeleteSafeDispatch.Enabled == false)
{
btnDeleteSafeDispatch.Enabled = true;
}
updateRemainingFeaturesTextBoxes();
if (OnAppServerRefreshRequest != null)
OnAppServerRefreshRequest();
}
}
else CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("errorIPFormat"), MainForm.returnLNGString("err"));
tbSafeDispatchIP.Focus();
}
private void updateRemainingFeaturesTextBoxes()
{
tbGPS.Text = remainingGPS.ToString();
tbSMS.Text = remainingSMS.ToString();
tbTicketing.Text = remainingTicketing.ToString();
tbReports.Text = remainingReports.ToString();
tbVoice.Text = remainingVoice.ToString();
tbRecordings.Text = remainingRecordings.ToString();
tbZones.Text = remainingZones.ToString();
tbTelemetry.Text = remainingTelemetry.ToString();
switch (cbMapType.SelectedIndex)
{
case 0:
tbMaps.Text = remainingGoogle.ToString();
break;
case 1:
tbMaps.Text = remainingArcgis.ToString();
break;
case 2:
tbMaps.Text = remainingOpenStreetMap.ToString();
break;
//case 3:
// tbMaps.Text = remainingArcgis.ToString();
// break;
}
}
private void btnDeleteSafeDispatch_Click(object sender, EventArgs e)
{
regManager.removeSafeDispatchRegistration(tbSafeDispatchIP.Text);
safeDispatchRegs = regManager.getAllSafeDispatches();
gvSafeDispatches.DataSource = safeDispatchRegs;
computeRemaining();
//if (remainingGateways == totalGateways)
//{
// btnNewGateway.Enabled = true;
// btnUpdateGateway.Enabled = false;
// btnDeleteGateway.Enabled = false;
//}
//else
//{
// gvGateways.CurrentRow = gvGateways.Rows[0];
// tbGWIP.Text = gvGateways.Rows[0].Cells[0].Value.ToString();
// if (remainingGateways == 1)
// {
// btnNewGateway.Enabled = true;
// }
//}
updateRemainingFeaturesTextBoxes();
tbSafeDispatchIP.Focus();
if (OnAppServerRefreshRequest != null)
OnAppServerRefreshRequest();
}
private void btnUpdateSafeDispatch_Click(object sender, EventArgs e)
{
if (MainForm.TestIP(tbSafeDispatchIP.Text))
{
if (!checkNewSDValidityUPDATE())
{
return;
}
btnNewSafeDispatch.Enabled = false;
btnUpdateSafeDispatch.Enabled = false;
btnDeleteSafeDispatch.Enabled = true;
SDRegistration newSDRegistration = new SDRegistration();
newSDRegistration.ip = tbSafeDispatchIP.Text;
newSDRegistration.gps = chbGPS.Checked;
newSDRegistration.sms = chbSMS.Checked;
newSDRegistration.ticketing = chbTicketing.Checked;
newSDRegistration.reports = chbReports.Checked;
newSDRegistration.voice = chbVoice.Checked;
newSDRegistration.recordings = chbRecordings.Checked;
newSDRegistration.zones = chbZones.Checked;
newSDRegistration.telemetry = chbTelemetry.Checked;
//newSDRegistration.map_type = (Int16)(cbMapType.SelectedIndex + 1);
if (cbMapType.SelectedIndex == 0)
newSDRegistration.map_type = 1;
else if(cbMapType.SelectedIndex == 1)
newSDRegistration.map_type = 4;
else if (cbMapType.SelectedIndex == 2)
newSDRegistration.map_type = 3;
regManager.updateSafeDispatchRegistration(selectedSDRegistration, newSDRegistration);
safeDispatchRegs = regManager.getAllSafeDispatches();
gvSafeDispatches.DataSource = safeDispatchRegs;
selectSafeDispatchRow(newSDRegistration);
computeRemaining();
updateRemainingFeaturesTextBoxes();
if (OnAppServerRefreshRequest != null)
OnAppServerRefreshRequest();
}
else CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("errorIPFormat"), MainForm.returnLNGString("err"));
tbSafeDispatchIP.Focus();
}
private void checkExistingSafeDispatch()
{
SDRegistration tempSDRegistration = new SDRegistration();
tempSDRegistration.ip = tbSafeDispatchIP.Text;
tempSDRegistration.gps = chbGPS.Checked;
tempSDRegistration.sms = chbSMS.Checked;
tempSDRegistration.ticketing = chbTicketing.Checked;
tempSDRegistration.reports = chbReports.Checked;
tempSDRegistration.voice = chbVoice.Checked;
tempSDRegistration.recordings = chbRecordings.Checked;
tempSDRegistration.zones = chbZones.Checked;
tempSDRegistration.telemetry = chbTelemetry.Checked;
if (cbMapType.SelectedIndex == 0)
tempSDRegistration.map_type = 1;
else if (cbMapType.SelectedIndex == 1)
tempSDRegistration.map_type = 4;
else if (cbMapType.SelectedIndex == 2)
tempSDRegistration.map_type = 3;
//tempSDRegistration.map_type = (Int16)(cbMapType.SelectedIndex + 1);
if (tempSDRegistration.Equals(selectedSDRegistration))
{
btnNewSafeDispatch.Enabled = false;
btnUpdateSafeDispatch.Enabled = false;
btnDeleteSafeDispatch.Enabled = true;
}
else
{
if (selectedSDRegistration != null)
if (tempSDRegistration.ip.Equals(selectedSDRegistration.ip))
{
btnNewSafeDispatch.Enabled = false;
}
else
{
btnNewSafeDispatch.Enabled = true;
}
else
btnNewSafeDispatch.Enabled = true;
btnUpdateSafeDispatch.Enabled = true;
btnDeleteSafeDispatch.Enabled = true;
}
//checkCheckboxes();
}
private void chbGPS_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
checkExistingSafeDispatch();
if (chbGPS.Checked)
{
chbZones.Enabled = true;
chbZones.Checked = true;
}
else
{
chbZones.Enabled = false;
chbZones.Checked = false;
}
}
private void chbSMS_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
checkExistingSafeDispatch();
}
private void chbTicketing_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
checkExistingSafeDispatch();
}
private void chbReports_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
checkExistingSafeDispatch();
}
private void chbVoice_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
checkExistingSafeDispatch();
}
private void chbRecordings_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
checkExistingSafeDispatch();
}
private void chbZones_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
checkExistingSafeDispatch();
}
private void chbTelemetry_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
checkExistingSafeDispatch();
}
private void gvGateways_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
GridCellElement cellElement = e.CellElement;
GridViewDataColumn columnInfo = e.CellElement.ColumnInfo as GridViewDataColumn;
if (cellElement == null || columnInfo == null)
return;
// do not draw border
cellElement.DrawBorder = false;
// do not highlight the cell on which was clicked
if (e.CellElement.IsCurrent)
{
e.CellElement.IsCurrent = false;
}
}
private void gvSafeDispatches_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
GridCellElement cellElement = e.CellElement;
GridViewDataColumn columnInfo = e.CellElement.ColumnInfo as GridViewDataColumn;
if (cellElement == null || columnInfo == null)
return;
// do not draw border
cellElement.DrawBorder = false;
// do not highlight the cell on which was clicked
if (e.CellElement.IsCurrent)
{
e.CellElement.IsCurrent = false;
}
}
private void cbMapType_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
switch (cbMapType.SelectedIndex)
{
case 0: tbMaps.Text = remainingGoogle.ToString();
break;
case 1: tbMaps.Text = remainingArcgis.ToString();
break;
case 2:
tbMaps.Text = remainingOpenStreetMap.ToString();
break;
//case 3: tbMaps.Text = remainingArcgis.ToString();
// break;
}
checkExistingSafeDispatch();
}
private void checkCheckboxes()
{
chbGPS.Enabled = chbGPS.Checked || tbGPS.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
chbSMS.Enabled = chbSMS.Checked || tbSMS.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
chbTicketing.Enabled = chbTicketing.Checked || tbTicketing.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
chbReports.Enabled = chbReports.Checked || tbReports.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
chbVoice.Enabled = chbVoice.Checked || tbVoice.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
chbRecordings.Enabled = chbRecordings.Checked || tbRecordings.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
chbZones.Enabled = chbZones.Checked || tbZones.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
chbTelemetry.Enabled = chbTelemetry.Checked || tbTelemetry.Text != "0" /*|| btnUpdateSafeDispatch.Enabled*/;
}
public delegate void AppServerRefreshRequest();
public event AppServerRefreshRequest OnAppServerRefreshRequest;
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void gvSafeDispatches_RowFormatting(object sender, RowFormattingEventArgs e)
{
e.RowElement.DrawFill = true;
e.RowElement.NumberOfColors = 1;
if (e.RowElement.IsSelected)
e.RowElement.BackColor = MainForm.GridSelectedRow;
else
e.RowElement.BackColor = (e.RowElement.RowInfo.Index % 2 == 0 ? Color.White : MainForm.GridAlternateRow);
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void gvGateways_RowFormatting(object sender, RowFormattingEventArgs e)
{
e.RowElement.DrawFill = true;
e.RowElement.NumberOfColors = 1;
if (e.RowElement.IsSelected)
e.RowElement.BackColor = MainForm.GridSelectedRow;
else
e.RowElement.BackColor = (e.RowElement.RowInfo.Index % 2 == 0 ? Color.White : MainForm.GridAlternateRow);
}
private void gvSafeDispatches_SelectionChanged(object sender, EventArgs e)
{
int index = (((RadGridView)sender).SelectedRows[0]).Index;
if (index >= 0)
{
selectedSDRegistration = safeDispatchRegs[index];
tbSafeDispatchIP.Text = safeDispatchRegs[index].ip;
}
}
}
}