using System; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Nini.Config; using SafeMobileLib; using Telerik.WinControls; using RegLibDLL; using System.Net.Sockets; using System.Net; using System.Resources; using System.Globalization; using Telerik.WinControls.UI; using SafeMobileLib.DBmanagers; using System.Diagnostics; using System.IO; using System.Linq; using SharedUI; using System.Threading.Tasks; namespace SubscriberAndUserManager { public partial class MainForm : Telerik.WinControls.UI.RadRibbonForm { // save the version of the application server in order to use it for the updater public static String APP_SERVER_VERSION = ""; public static SafeMobileLib.IconTheme iconThemeType = SafeMobileLib.IconTheme.PIN; private Login lgForm; public static bool HasEmailSettings; #region THEMING public static Color LabelColor = Color.FromArgb(255, 64, 0); public static Color LabelColorTicketSubject = Color.FromArgb(72, 191, 255); public static Color ButtonColor = Color.FromArgb(211, 111, 15); public static Color ButtonColorDisabled = Color.FromArgb(113, 113, 113); public static Color GroupHeaderColor = Color.FromArgb(255, 64, 0); public static Color TabSelectedColor = Color.FromArgb(15, 158, 190); public static Color TabOverColor = Color.FromArgb(255, 64, 0); public static Color TabNormalColor = Color.FromArgb(15, 115, 211); public static Color GridSelectedRow = Color.FromArgb(146, 217, 255); public static Color GridAlternateRow = Color.FromArgb(193, 235, 255); public static Dictionary imagesDictionary = new Dictionary(); private static RibbonTab currentTab; public static void setThemingColors(RADIOTYPE themeType) { switch (themeType) { case RADIOTYPE.MOTO: case RADIOTYPE.CONECTPLUS: case RADIOTYPE.REPEATER_TRBO: case RADIOTYPE.TETRA: { LabelColor = Color.FromArgb(27, 161, 226); LabelColorTicketSubject = Color.FromArgb(72, 191, 255); ButtonColor = Color.FromArgb(27, 161, 226); ButtonColorDisabled = Color.FromArgb(113, 113, 113); GroupHeaderColor = Color.FromArgb(27, 161, 226); TabSelectedColor = Color.FromArgb(15, 158, 190); TabOverColor = Color.FromArgb(23, 131, 238); TabNormalColor = Color.FromArgb(15, 115, 211); GridSelectedRow = Color.FromArgb(146, 217, 255); GridAlternateRow = Color.FromArgb(239, 250, 255); break; } case RADIOTYPE.HYT: { LabelColor = Color.FromArgb(244, 177, 131); LabelColorTicketSubject = Color.FromArgb(0, 99, 147); ButtonColor = Color.FromArgb(244, 177, 131); ButtonColorDisabled = Color.FromArgb(113, 113, 113); GroupHeaderColor = Color.FromArgb(244, 177, 131); TabSelectedColor = Color.FromArgb(255, 181, 61); TabOverColor = Color.FromArgb(200, 122, 49); TabNormalColor = Color.FromArgb(255, 164, 101); GridSelectedRow = Color.FromArgb(255, 184, 146); GridAlternateRow = Color.FromArgb(255, 244, 239); break; } case RADIOTYPE.SIMOCO: { LabelColor = Color.FromArgb(71, 101, 154); LabelColorTicketSubject = Color.FromArgb(0, 99, 147); ButtonColor = Color.FromArgb(71, 101, 154); ButtonColorDisabled = Color.FromArgb(113, 113, 113); GroupHeaderColor = Color.FromArgb(71, 101, 154); TabSelectedColor = Color.FromArgb(117, 139, 217); TabOverColor = Color.FromArgb(70, 102, 213); TabNormalColor = Color.FromArgb(71, 101, 154); GridSelectedRow = Color.FromArgb(177, 200, 223); GridAlternateRow = Color.FromArgb(239, 248, 255); break; } case RADIOTYPE.EXCERA: { LabelColor = Color.FromArgb(139, 146, 158); LabelColorTicketSubject = Color.FromArgb(158, 167, 171); ButtonColor = Color.FromArgb(56, 60, 63); ButtonColorDisabled = Color.FromArgb(113, 113, 113); GroupHeaderColor = Color.FromArgb(139, 146, 158); TabSelectedColor = Color.FromArgb(139, 146, 158); TabOverColor = Color.FromArgb(151, 153, 161); TabNormalColor = Color.FromArgb(56, 60, 63); GridSelectedRow = Color.FromArgb(222, 224, 226); GridAlternateRow = Color.FromArgb(231, 235, 239); break; } case RADIOTYPE.HARRIS: { LabelColor = Color.FromArgb(184, 54, 41); LabelColorTicketSubject = Color.FromArgb(0, 99, 147); ButtonColor = Color.FromArgb(184, 54, 41); ButtonColorDisabled = Color.FromArgb(113, 113, 113); GroupHeaderColor = Color.FromArgb(184, 54, 41); TabSelectedColor = Color.FromArgb(215, 125, 100); TabOverColor = Color.FromArgb(208, 82, 47); TabNormalColor = Color.FromArgb(184, 54, 41); GridSelectedRow = Color.FromArgb(240, 160, 164); GridAlternateRow = Color.FromArgb(255, 244, 245); break; } case RADIOTYPE.ATLAS: { LabelColor = Color.FromArgb(0, 0, 0); LabelColorTicketSubject = Color.FromArgb(0, 99, 147); ButtonColor = Color.FromArgb(0, 0, 0); ButtonColorDisabled = Color.FromArgb(113, 113, 113); GroupHeaderColor = Color.FromArgb(0, 0, 0); TabSelectedColor = Color.FromArgb(200, 200, 200); TabOverColor = Color.FromArgb(155, 155, 155); TabNormalColor = Color.FromArgb(0, 0, 0); GridSelectedRow = Color.FromArgb(200, 200, 200); GridAlternateRow = Color.FromArgb(244, 244, 244); break; } case RADIOTYPE.LINX: case RADIOTYPE.LINXB: { LabelColor = Color.FromArgb(0, 0, 0); LabelColorTicketSubject = Color.FromArgb(0, 99, 147); ButtonColor = Color.FromArgb(0, 0, 0); ButtonColorDisabled = Color.FromArgb(113, 113, 113); GroupHeaderColor = Color.FromArgb(0, 0, 0); TabSelectedColor = Color.FromArgb(200, 200, 200); TabOverColor = Color.FromArgb(155, 155, 155); TabNormalColor = Color.FromArgb(0, 0, 0); GridSelectedRow = Color.FromArgb(200, 200, 200); GridAlternateRow = Color.FromArgb(244, 244, 244); break; } default: { break; } } } #endregion //private IConfigSource source = null; public static string CFG_FILE = "SubsConfig.ini"; //public static Boolean Hytera =false; public static RADIOTYPE radioType = RADIOTYPE.HARRIS; public static Color HyteraColor = Color.Moccasin; public static Color HarrisColor = System.Drawing.SystemColors.ControlDark; public static Color HarTextColor = Color.White; public static bool IS_SIERRA_WIRELESS = false; public static string DBServer, DBSchema, DBUser, DBPass, DBPort; public static string dbIpforSip; private bool DBcleanUp = false; public DBuserManager db4users; private DBvehiclesManager db4vehs; private DBsettingsManager db4settings; private DBalarmManager db4alarmTypes; private DBtelemetryManager db4telemetry; private DBalarmManager db4Alarm; private DBgatewaysManager db4gateway; private DBgroupsManager db4groups; private DBcontactsManager db4contacts; private DBregistrationManager db4Registration; private DBdailyreportManager db4Reports; private DBemailServiceManager db4emailService; private static DBiconsManager dbicons; private DBTicketingManager db4Ticketing; private DBsubsOperationManager dbsub; private DBcallPatchManager dbpatch; private controlUser usrControl; private controlUnit unitControl; private controlSettings setControl; private controlSystem systemControl; private controlGateways gatewayControl; private controlRegistration registrationControl; private controlReports reportControl; private controlTicketing ticketingControl; private TcpClient client; private Int32 registrationPort = 5680; static String serverIP = ""; Int32 totalGateways = 0; Int32 totalGPS = 0; Int32 totalSMS = 0; Int32 totalTicketing = 0; Int32 totalReports = 0; Int32 totalVoice = 0; Int32 totalRecordings = 0; Int32 totalZones = 0; Int32 totalTelemetry = 0; Int32 totalGoogle = 0; Int32 totalUS = 0; Int32 totalOpenStreetMap = 0; Int32 totalArcgis = 0; internal static Int32 totalUnits = 0; internal static Int32 numberOfActiveUnits = 0; int totaldbunits = 0; public static ResourceManager RManager = new ResourceManager("SubscriberAndUserManager.Language.Language", typeof(MainForm).Assembly); public static CultureInfo culture = CultureInfo.CreateSpecificCulture(""); public static Int32 Langidx=0; public static ArrayList VehNameList = new ArrayList(); public static ArrayList ImeiList = new ArrayList(); public static ArrayList imgList = new ArrayList(); public static Dictionary carImages = new Dictionary(); internal static string SipServer, WebServer, RestartSipLink, reloadDataLink; internal static bool hideLinxFeatures = true; internal static string selectedItemDDSierra = ""; private string messageBusIP; private int messageBusPort; private bool autoupdate = true; private bool isDevelop = false; internal static Vehicles selectedVeh; public volatile static UdpMulticast udp; private string localIP = ""; public static string returnLNGString(string name) { string returnSTR = ""; string temp = RManager.GetString(name, culture); returnSTR = temp; if (temp != null) if (temp.Contains("\\r\\n")) { returnSTR = temp.Replace("\\r\\n", "\r\n"); } return returnSTR; } public static Boolean TestIP(string IP) { String[] tmp = IP.Split('.'); if (tmp.Length != 4) return false; Int32 number; bool result; for(Int32 i=0;i<=3;i++) { result = Int32.TryParse(tmp[i], out number); if (result) { if ((number < 0) || (number > 255)) return false; } else return false; } return true; } private void setLanguage() { this.Text = returnLNGString("adminModule"); tabUnits.Text = returnLNGString("units"); tabUser.Text = returnLNGString("users"); tabTicketing.Text = returnLNGString("ts"); tabSettings.Text = returnLNGString("sett"); tabSystem.Text = returnLNGString("alarms"); tabRegistration.Text = returnLNGString("regs"); tabGateways.Text = returnLNGString("gate"); tabReports.Text = returnLNGString("Dailyreports"); btnAddUnit.Text = returnLNGString("add"); btnUserAdd.Text = returnLNGString("add"); btnUnitDelete.Text = returnLNGString("del"); btnUserDelete.Text = returnLNGString("del"); btnUnitEdit.Text = returnLNGString("edit"); btnGroupEdit.Text = returnLNGString("lbGrp"); btnUserEdit.Text = returnLNGString("edit"); btnSaveSettings4User.Text = rbtSaveUnits.Text = rbtSaveGateways.Text = rbtSaveRegistration.Text = rbtSaveReports.Text = rbtSaveSettings.Text = returnLNGString("saveset"); btnTelemetrySave.Text = returnLNGString("save"); radRibbonBarGroup1.Text = returnLNGString("sett"); radRibbonBarGroup2.Text = returnLNGString("units"); radRibbonBarGroup6.Text = returnLNGString("group"); radRibbonBarGroup4.Text = returnLNGString("sett"); radRibbonBarGroup5.Text = returnLNGString("sett"); radRibbonBarGroup10.Text = returnLNGString("sett"); radRibbonBarGroup11.Text = returnLNGString("sett"); radRibbonBarGroup12.Text = returnLNGString("sett"); radRibbonBarGroup15.Text = returnLNGString("refreshGrid"); radRibbonBarGroup13.Text = returnLNGString("sett"); radRibbonBarGroup14.Text = returnLNGString("sett"); rbtSaveGateways.Text = returnLNGString("save"); rbtSaveRegistration.Text = returnLNGString("save"); rbtSaveReports.Text = returnLNGString("save"); rbtSaveSettings.Text = returnLNGString("save"); rbtSaveUnits.Text = returnLNGString("save"); btnTelemetrySave.Text = returnLNGString("save"); //radRibbonBarGroup5.Text = returnLNGString("sdset"); lbsaveNotificationSip.Text = returnLNGString("saveNotificationSip"); } #region Constructor private DialogResult loginDialogResult = DialogResult.Cancel; public MainForm() { // initialize the InitializeComponent(); SM debug = new SM(); setThemingColors(radioType); LoadConfig(); if (serverIP.Equals("localhost")) { serverIP = "127.0.0.1"; } dbIpforSip = MainForm.serverIP == "127.0.0.1" ? UdpMulticast.getPreferedIPAdress().ToString() : serverIP; RadMessageBox.SetThemeName("TelerikMetroBlue"); if (radioType==RADIOTYPE.HYT) { //this.AllowAero = false; this.Icon = global::SubscriberAndUserManager.Properties.Resources.SYTADMIN24x; } else if (radioType == RADIOTYPE.HARRIS) { //this.AllowAero = false; this.Icon = global::SubscriberAndUserManager.Properties.Resources.visionSmall; } else if (radioType == RADIOTYPE.ATLAS) { //ThemeResolutionService.ApplicationThemeName = "Office2010Black"; //ATLASCHANGE //this.AllowAero = false; this.Icon = global::SubscriberAndUserManager.Properties.Resources.ATLASadmin32; } else if (radioType == RADIOTYPE.SIMOCO) { //this.AllowAero = false; this.Icon = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_241; } else if (radioType == RADIOTYPE.EXCERA) { //this.AllowAero = false; this.Icon = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_241; } // ThemeResolutionService.ApplicationThemeName = "Breeze"; //show login form lgForm = new Login(Login.RegistrationStatus.NOT_REGISTERED); lgForm.FormClosing += delegate (object sender, FormClosingEventArgs e) { registrationBackgroundWorker.CancelAsync(); if(lgForm.DialogResult != DialogResult.OK) Application.Exit(); }; /* if (totalGateways > 0) { lgForm = new Login(db4users, true); } else { lgForm = new Login(db4users, false); }*/ // This event will be raised on the worker thread when the worker starts registrationBackgroundWorker.DoWork += new DoWorkEventHandler(registrationBackgroundWorker_DoWork); // Start the registration background worker registrationBackgroundWorker.RunWorkerAsync(); loginDialogResult = lgForm.ShowDialog(); //Console.WriteLine("login dialog result =" + loginDialogResult); //if login form was closed without entering a correct password exit if (loginDialogResult != DialogResult.OK) //System.Environment.Exit(0); { // I should not do anything, the login form will close the application Application.Exit(); } else { db4vehs = new DBvehiclesManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4settings = new DBsettingsManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4telemetry = new DBtelemetryManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4Alarm = new DBalarmManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4gateway = new DBgatewaysManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4groups = new DBgroupsManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4contacts = new DBcontactsManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4emailService = new DBemailServiceManager(DBServer, DBSchema, DBUser, DBPass, DBPort); dbicons = new DBiconsManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4Reports = new DBdailyreportManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4Ticketing = new DBTicketingManager(DBServer, DBSchema, DBUser, DBPass, DBPort); dbsub = new DBsubsOperationManager(DBServer, DBSchema, DBUser, DBPass, DBPort); dbpatch = new DBcallPatchManager(DBServer, DBSchema, DBUser, DBPass, DBPort); HasEmailSettings = db4emailService.GetEmailServiceSettings().Enable; // detect if Sierra Wireless IS_SIERRA_WIRELESS = dbsub.IsSierraWireless(); LoadUnitIcons(); this.AllowAero = false; //cleanup DB from old IMEIS if (DBcleanUp) DB_Cleanup(); switch (MainForm.Langidx) { case 0: culture = CultureInfo.CreateSpecificCulture("en"); break; case 1: culture = CultureInfo.CreateSpecificCulture("zh-CN"); break; case 2: culture = CultureInfo.CreateSpecificCulture("cs"); break; case 3: culture = CultureInfo.CreateSpecificCulture("fr"); break; case 4: culture = CultureInfo.CreateSpecificCulture("de"); break; case 5: culture = CultureInfo.CreateSpecificCulture("it"); break; case 6: culture = CultureInfo.CreateSpecificCulture("ja"); break; case 7: culture = CultureInfo.CreateSpecificCulture("pl"); break; case 8: culture = CultureInfo.CreateSpecificCulture("pt"); break; case 9: culture = CultureInfo.CreateSpecificCulture("ro"); break; case 10: culture = CultureInfo.CreateSpecificCulture("ru"); break; case 11: culture = CultureInfo.CreateSpecificCulture("sr"); break; case 12: culture = CultureInfo.CreateSpecificCulture("es"); break; case 13: culture = CultureInfo.CreateSpecificCulture("sv"); break; case 14: culture = CultureInfo.CreateSpecificCulture("tr"); break; case 15: culture = CultureInfo.CreateSpecificCulture("ar"); break; } setLanguage(); tabUnits.IsSelected = true; radRibbonBar1.RibbonBarElement.QuickAccessToolBar.Visibility = Telerik.WinControls.ElementVisibility.Hidden; radRibbonBar1.CollapseRibbonOnTabDoubleClick = false; if ((totalGateways == 0) || (totalGPS == 0 && totalSMS == 0 && totalTicketing == 0 && totalReports == 0 && totalTelemetry == 0 && totalVoice == 0 && totalRecordings == 0 && totalZones == 0 && totalGoogle == 0 && totalArcgis == 0)) { radRibbonBar1.Enabled = false; MainPanel.Enabled = false; RadMessageBox.Show(MainForm.returnLNGString("dongleError") + "\n" + MainForm.returnLNGString("pleaseInsertValidDongle"), MainForm.returnLNGString("err"), MessageBoxButtons.OK, RadMessageIcon.Error); //System.Environment.Exit(0); System.Windows.Forms.Application.Exit(); } if ((radioType == RADIOTYPE.HARRIS) || (radioType == RADIOTYPE.ATLAS)) { this.btnAddUnit.ForeColor = MainForm.HarTextColor; //this.btnGroupAdd.ForeColor = MainForm.HarTextColor; //this.btnGroupDelete.ForeColor = MainForm.HarTextColor; this.btnGroupEdit.ForeColor = MainForm.HarTextColor; this.btnSaveSettings4User.ForeColor = MainForm.HarTextColor; this.btnTelemetrySave.ForeColor = MainForm.HarTextColor; this.btnUnitDelete.ForeColor = MainForm.HarTextColor; this.btnUnitEdit.ForeColor = MainForm.HarTextColor; this.btnUserAdd.ForeColor = MainForm.HarTextColor; this.btnUserEdit.ForeColor = MainForm.HarTextColor; this.btnUserDelete.ForeColor = MainForm.HarTextColor; this.radRibbonBarGroup1.ForeColor = MainForm.HarTextColor; this.radRibbonBarGroup2.ForeColor = MainForm.HarTextColor; this.radRibbonBarGroup4.ForeColor = MainForm.HarTextColor; this.radRibbonBarGroup5.ForeColor = MainForm.HarTextColor; this.radRibbonBarGroup6.ForeColor = MainForm.HarTextColor; btnAddUnit.MouseEnter += new EventHandler(btnAddUnit_MouseEnter); btnAddUnit.MouseLeave += new EventHandler(btnAddUnit_MouseLeave); //btnGroupAdd.MouseEnter += new EventHandler(btnGroupAdd_MouseEnter); //btnGroupAdd.MouseLeave += new EventHandler(btnGroupAdd_MouseLeave); //btnGroupDelete.MouseEnter += new EventHandler(btnGroupDelete_MouseEnter); //btnGroupDelete.MouseLeave += new EventHandler(btnGroupDelete_MouseLeave); btnGroupEdit.MouseEnter += new EventHandler(btnGroupEdit_MouseEnter); btnGroupEdit.MouseLeave += new EventHandler(btnGroupEdit_MouseLeave); btnSaveSettings4User.MouseEnter += new EventHandler(btnSaveSettings4User_MouseEnter); btnSaveSettings4User.MouseLeave += new EventHandler(btnSaveSettings4User_MouseLeave); btnTelemetrySave.MouseEnter += new EventHandler(btnTelemetrySave_MouseEnter); btnTelemetrySave.MouseLeave += new EventHandler(btnTelemetrySave_MouseLeave); btnUnitDelete.MouseEnter += new EventHandler(btnUnitDelete_MouseEnter); btnUnitDelete.MouseLeave += new EventHandler(btnUnitDelete_MouseLeave); btnUnitEdit.MouseEnter += new EventHandler(btnUnitEdit_MouseEnter); btnUnitEdit.MouseLeave += new EventHandler(btnUnitEdit_MouseLeave); btnUserAdd.MouseEnter += new EventHandler(btnUserAdd_MouseEnter); btnUserAdd.MouseLeave += new EventHandler(btnUserAdd_MouseLeave); btnUserEdit.MouseEnter += new EventHandler(btnUserEdit_MouseEnter); btnUserEdit.MouseLeave += new EventHandler(btnUserEdit_MouseLeave); btnUserDelete.MouseEnter += new EventHandler(btnUserDelete_MouseEnter); btnUserDelete.MouseLeave += new EventHandler(btnUserDelete_MouseLeave); } if ((radioType == RADIOTYPE.ATLAS) || (radioType == RADIOTYPE.CONECTPLUS)) { //RADIOTYPE.ATLAS radRibbonBar1.CommandTabs.Remove(tabGateways); } if ((radioType != RADIOTYPE.MOTO) && (radioType != RADIOTYPE.REPEATER_TRBO)) { //RADIOTYPE.ATLAS radRibbonBar1.CommandTabs.Remove(tabTicketing); totalTicketing = 0; } //int UDP multicast udp = new UdpMulticast(messageBusIP, messageBusPort); udp.OnNewDataRecv += new UdpMulticast.newData4Send(udp_OnNewDataRecv); udp.StartListen(localIP); string lanLinxServer = db4settings.getSettingValue(0, "lanLinxServer"); string lanSipServerPort = db4settings.getSettingValue(0, "lanSipPort"); string lanSigServerPort = db4settings.getSettingValue(0, "lanSigPort"); SipServer = $"{lanLinxServer}:{lanSipServerPort}"; WebServer = $"{lanLinxServer}:{lanSigServerPort}"; RestartSipLink = $"http://{WebServer}/restart-sip"; reloadDataLink = $"http://{WebServer}/reload-data"; ddSierraWireless.SelectedIndex = 0; } } // On worker thread so do our thing! private void registrationBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { System.Threading.Thread.Sleep(200); // exit application if APP Server could not be reached if (getRegistration() == false) { /* if (!this.IsHandleCreated) { this.CreateHandle(); }*/ lgForm.Invoke((MethodInvoker)delegate () { lgForm.OnRegistrationStatusChanged(Login.RegistrationStatus.UNAUTHORIZED); RadMessageBox.Instance.TopMost = true; RadMessageBox.Instance.TopLevel = true; if ((radioType == RADIOTYPE.HARRIS) || (radioType == RADIOTYPE.ATLAS)) ((RadLabel) RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm.HarTextColor; RadMessageBox.SetThemeName("TelerikMetroBlue"); RadMessageBox.Show(MainForm.returnLNGString("cantapp"), MainForm.returnLNGString("err"), MessageBoxButtons.OK, RadMessageIcon.Error); }); //System.Environment.Exit(0); System.Threading.Thread.Sleep(500); Application.Exit(); } else registrationBackgroundWorker.ReportProgress(100); } private void registrationBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { // registration process had finished if (e.ProgressPercentage == 100) { db4Registration = new DBregistrationManager(DBServer, DBSchema, DBUser, DBPass, DBPort); db4users = new DBuserManager(DBServer, DBSchema, DBUser, DBPass, DBPort); lgForm.dbUserManager = db4users; lgForm.OnRegistrationStatusChanged(Login.RegistrationStatus.REGISTERED); } } private void LoadUnitIcons() { // create icons MainForm.imgList = db4vehs.get_all_car_picture(); string fileName = ""; string filePath = ""; foreach (Car c in MainForm.imgList) { fileName = c.fileName; filePath = System.Windows.Forms.Application.StartupPath + @"\resource\cars\" + (SubscriberAndUserManager.MainForm.iconThemeType == SafeMobileLib.IconTheme.CLASSIC ? "" : "list_") + SubscriberAndUserManager.MainForm.iconThemeType + "_" + c.iconPattern + ".png"; if (filePath.Length == 0) { GetCustomIcon(c.idx); } try { Bitmap bmp = new Bitmap(filePath); { Image tmp2 = bmp; try { // add the car to the dictionary if not exists if (!MainForm.carImages.ContainsKey(c.idx)) MainForm.carImages.Add(c.idx, Utils.ScaleImage(tmp2, 32, 32)); } catch (Exception ex) { Utils.WriteLine("Exception on populating icons: " + ex.ToString()); } } } catch (Exception ex) { Utils.WriteLine("\nBmp " + filePath + " exception " + ex.ToString(), ConsoleColor.Red); } } } public static void GetCustomIcon(int idx) { Utils.WriteLine("Got custom icon with id " + idx); Byte[] newCarBytes = dbicons.Get_Unit_Image(idx); try { using (var m = new MemoryStream(newCarBytes)) { // save the image received from the database to a png file Bitmap bmp = new Bitmap(m); { // add the car to the dictionary if not exists if (!MainForm.carImages.ContainsKey(idx)) MainForm.carImages.Add(idx, Utils.ScaleImage(bmp, 32, 32)); } } } catch (Exception ex) { Utils.WriteLine("Exception on populating icons: " + ex.ToString()); } } void udp_OnNewDataRecv(byte[] data, int dataLen) { string str = System.Text.Encoding.ASCII.GetString(data, 0, dataLen); SM.Debug("RX: " + str.Trim()); try { BussMessageParser(data, dataLen); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } //BussMessageParser2(data,dataLen); } private bool BussMessageParser(byte[] rawData, int actualLen) { string data = System.Text.Encoding.ASCII.GetString(rawData, 0, actualLen); //SM.Debug("RX: " + data.Trim()); string[] tempArr = data.Split('#'); if (tempArr.Length == 0) { SM.Debug("incorect message=" + data); return false; } int messLen = Convert.ToInt32(tempArr[1]); if (actualLen != messLen) { Console.WriteLine("message length({0}) != actual length({1})", messLen, actualLen); return false; } int opCode = Convert.ToInt32(tempArr[3]); switch (opCode) { case (byte)61: SM.Debug("controSettings-> got DB backup reply"); string status = (tempArr[4] == "1") ? MainForm.returnLNGString("backup") + MainForm.returnLNGString("done") : MainForm.returnLNGString("backup") + MainForm.returnLNGString("failed"); setControl.parseMultiCastData((Int32)opCode, status); break; case (byte)71: SM.Debug("controSettings-> got DB backup request ACK"); setControl.parseMultiCastData((Int32)opCode, MainForm.returnLNGString("backupProgress")); break; case (byte)62: SM.Debug("controSettings-> got DB restore reply"); status = (tempArr[4] == "1") ? MainForm.returnLNGString("restore") + MainForm.returnLNGString("done") : MainForm.returnLNGString("restore") + MainForm.returnLNGString("failed"); setControl.parseMultiCastData((Int32)opCode, status); break; case (byte)72: SM.Debug("controSettings-> got DB restore request ACK"); setControl.parseMultiCastData((Int32)opCode, MainForm.returnLNGString("restoreProgress")); break; case (byte)63: SM.Debug("controSettings-> got DB backup list"); string fileNames = tempArr[4]; if(setControl != null) setControl.parseMultiCastData((Int32)opCode, fileNames); break; default: break; } return true; } public void SendRestart() { udp.Send(Utils.Convert_text_For_multicast("#0.0#209#"), Utils.Convert_text_For_multicast("#0.0#209#").Length); } public static void BroadcastRegistrationSD(string msg) { Encoding enc = System.Text.Encoding.ASCII; byte[] buf = enc.GetBytes(msg); udp.Send(buf, buf.Length); } #region Change Label Color for Harris private void btnAddUnit_MouseLeave(object sender, EventArgs e) { btnAddUnit.ForeColor = MainForm.HarTextColor; } private void btnAddUnit_MouseEnter(object sender, EventArgs e) { btnAddUnit.ForeColor = Color.Black; } private void btnGroupEdit_MouseLeave(object sender, EventArgs e) { btnGroupEdit.ForeColor = MainForm.HarTextColor; } private void btnGroupEdit_MouseEnter(object sender, EventArgs e) { btnGroupEdit.ForeColor = Color.Black; } private void btnSaveSettings4User_MouseLeave(object sender, EventArgs e) { btnSaveSettings4User.ForeColor = MainForm.HarTextColor; } private void btnSaveSettings4User_MouseEnter(object sender, EventArgs e) { btnSaveSettings4User.ForeColor = Color.Black; } private void btnTelemetrySave_MouseLeave(object sender, EventArgs e) { btnTelemetrySave.ForeColor = MainForm.HarTextColor; } private void btnTelemetrySave_MouseEnter(object sender, EventArgs e) { btnTelemetrySave.ForeColor = Color.Black; } private void btnUnitDelete_MouseLeave(object sender, EventArgs e) { btnUnitDelete.ForeColor = MainForm.HarTextColor; } private void btnUnitDelete_MouseEnter(object sender, EventArgs e) { btnUnitDelete.ForeColor = Color.Black; } private void btnUnitEdit_MouseLeave(object sender, EventArgs e) { btnUnitEdit.ForeColor = MainForm.HarTextColor; } private void btnUnitEdit_MouseEnter(object sender, EventArgs e) { btnUnitEdit.ForeColor = Color.Black; } private void btnUserAdd_MouseLeave(object sender, EventArgs e) { btnUserAdd.ForeColor = MainForm.HarTextColor; } private void btnUserAdd_MouseEnter(object sender, EventArgs e) { btnUserAdd.ForeColor = Color.Black; } private void btnUserEdit_MouseLeave(object sender, EventArgs e) { btnUserEdit.ForeColor = MainForm.HarTextColor; } private void btnUserEdit_MouseEnter(object sender, EventArgs e) { btnUserEdit.ForeColor = Color.Black; } private void btnUserDelete_MouseLeave(object sender, EventArgs e) { btnUserDelete.ForeColor = MainForm.HarTextColor; } private void btnUserDelete_MouseEnter(object sender, EventArgs e) { btnUserDelete.ForeColor = Color.Black; } #endregion private Boolean getRegistration() { Boolean toReturn = false; try { client = new TcpClient(); IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), registrationPort); client.Connect(serverEndPoint); NetworkStream clientStream = client.GetStream(); System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); byte[] buffer = encoding.GetBytes("300"); clientStream.Write(buffer, 0, buffer.Length); Console.WriteLine("Sent registration request to server, waiting..."); byte[] message = new byte[256]; clientStream.WriteTimeout = 3000; clientStream.ReadTimeout = 3000; int result = clientStream.Read(message, 0, message.Length); Console.WriteLine("Received registration from server"); String decodedString = encoding.GetString(message).Trim('\0'); String[] options = decodedString.Split(';'); Console.WriteLine("Option" + decodedString); APP_SERVER_VERSION = options[options.Length - 1].Replace("valid-", ""); if (!App.isValidVersion(APP_SERVER_VERSION, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())) { lgForm.Invoke((MethodInvoker)delegate () { RadMessageBox.Instance.TopMost = true; RadMessageBox.Instance.TopLevel = true; if ((radioType == RADIOTYPE.HARRIS) || (radioType == RADIOTYPE.ATLAS)) ((RadLabel) RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm.HarTextColor; RadMessageBox.SetThemeName("TelerikMetroBlue"); DialogResult dr = RadMessageBox.Show("Please update your version of software to the latest one required by Application Server. Do you wish to update now?", "Update required...", MessageBoxButtons.YesNo, RadMessageIcon.Exclamation); if (dr == DialogResult.Yes) { UpdateForm uf = new UpdateForm(App.ADMIN_MODULE, true) { IsDevelop = isDevelop }; uf.ShowDialog(); Application.Exit(); } else Application.Exit(); }); } if (options[0].Equals("301")) { totalGateways = Int32.Parse(options[1]); totalGPS = Int32.Parse(options[2]); totalSMS = Int32.Parse(options[3]); totalTicketing = Int32.Parse(options[4]); totalReports = Int32.Parse(options[5]); totalVoice = Int32.Parse(options[6]); totalRecordings = Int32.Parse(options[7]); totalZones = Int32.Parse(options[8]); totalTelemetry = Int32.Parse(options[9]); totalGoogle = Int32.Parse(options[10]); totalUS = Int32.Parse(options[11]); totalOpenStreetMap = Int32.Parse(options[12]); totalArcgis = Int32.Parse(options[13]); totalUnits = Int32.Parse(options[14]); messageBusIP = options[15]; messageBusPort = Int32.Parse(options[16]); DBServer = options[17]; DBSchema = options[18]; DBUser = options[19]; DBPass = options[20]; DBPort = options[21]; Console.WriteLine("Totals: GW:" + totalGateways + " GPS:" + totalGPS + " SMS:" + totalSMS + " Job Ticketing:" + totalTicketing + " Reports:" + totalReports + " Voice:" + totalVoice + " Recordings:" + totalRecordings + " Zones:" + totalZones + " Telemetry:" + totalTelemetry + " Google:" + totalGoogle + /*" US:" + totalUS +*/ " OpenStreetMap:" + totalOpenStreetMap + " Arcgis:" + totalArcgis + " Units: " + totalUnits + " Messagebus IP: " + messageBusIP + " Messagebus port: " + messageBusPort + " Database IP: " + DBServer + $" Database schema: {DBSchema} Database user: {DBUser} Database port: {DBPort}"); } toReturn = true; } catch (Exception ex) { Console.WriteLine("Exception in gateway:getRegistration():" + ex.ToString()); toReturn = false; } return toReturn; } private void LoadConfig() { try { Program.source = new IniConfigSource(CFG_FILE); if (Program.source.Configs["Registration"] == null) Program.source.Configs.Add("Registration"); registrationPort = GetInt32Value("Registration", "port", 5680); // Convert.ToInt32(Program.source.Configs["Registration"].Get("port")); if (Program.source.Configs["Database"] == null) Program.source.Configs.Add("Database"); serverIP = GetStringValue("Server", "IP", "127.0.0.1"); DBcleanUp = GetBooleanValue("Database", "deleteOrphanIMEI", true); // Convert.ToBoolean(source.Configs["Database"].Get("deleteOrphanIMEI")); localIP = GetStringValue("Database", "localIP", ""); if (Program.source.Configs["Language"] == null) Program.source.Configs.Add("Language"); Langidx = GetInt32Value("Language", "Language", 0); // Convert.ToInt32(source.Configs["Language"].Get("Language")); if (Program.source.Configs["MessageBus"] == null) Program.source.Configs.Add("MessageBus"); if (Program.source.Configs["Update"] == null) Program.source.Configs.Add("Update"); autoupdate = GetBooleanValue("Update", "autoupdate", true); if (Program.source.Configs["Update"].Contains("develop")) isDevelop = Program.source.Configs["Update"].GetBoolean("develop"); GetStringValue("Update", "Version", "1.0.0.2"); GetBooleanValue("Update", "Enable", true); if (Program.source.Configs["Registration"].Contains("Linx")) hideLinxFeatures = !Program.source.Configs["Registration"].GetBoolean("Linx"); if (MainForm.radioType == RADIOTYPE.LINX || MainForm.radioType == RADIOTYPE.LINXB) hideLinxFeatures = false; // save config file Program.source.Save(); } catch (Exception e) { Console.WriteLine(e.Message + " " + e.StackTrace + " " + e.Source); } } #endregion #region tabs load functions private void radRibbonBar1_CommandTabSelected(object sender, Telerik.WinControls.UI.CommandTabEventArgs args) { lbUnitsRegistation.Visible = args.CommandTab == tabUnits; lbsaveNotificationSip.Visible = args.CommandTab == tabUnits && needRestart; ddSierraWireless.Visible = ddSierraWireless.Visible = IS_SIERRA_WIRELESS && args.CommandTab == tabUnits; currentTab = args.CommandTab; if (args.CommandTab == tabUser) LoadUserTab(); if (args.CommandTab == tabUnits) LoadUnitsTab(); if (args.CommandTab == tabSystem) LoadSystemTab(); if (args.CommandTab == tabSettings) LoadSettingsTab(); if (args.CommandTab == tabGateways) LoadGatewayTab(); if (args.CommandTab == tabRegistration) LoadRegistrationTab(); if (args.CommandTab == tabReports) LoadDailyReportTab(); if (args.CommandTab == tabTicketing) LoadTicketingTab(); } private void LoadRegistrationTab() { if (registrationControl == null) registrationControl = new controlRegistration(db4Registration, totalGateways, totalGPS, totalSMS, totalTicketing, totalReports, totalVoice, totalRecordings, totalZones, totalTelemetry,totalGoogle,totalUS,totalOpenStreetMap,totalArcgis); registrationControl.Dock = System.Windows.Forms.DockStyle.Fill; registrationControl.OnAppServerRefreshRequest += delegate() { SendRestart(); }; MainPanel.Controls.Clear(); MainPanel.Controls.Add(registrationControl); } private void LoadDailyReportTab() { if (db4Reports != null) { reportControl = new controlReports(db4Reports, db4users); reportControl.Dock = System.Windows.Forms.DockStyle.Fill; } MainPanel.Controls.Clear(); MainPanel.Controls.Add(reportControl); } private void LoadUserTab() { if (db4users != null) { usrControl = new controlUser(db4users, db4vehs, dbicons, db4settings, db4gateway, db4groups); usrControl.Dock = System.Windows.Forms.DockStyle.Fill; } lbsaveNotificationSip.Visible = needRestart; MainPanel.Controls.Clear(); MainPanel.Controls.Add(usrControl); } private void LoadUnitsTab() { numberOfActiveUnits = db4vehs.getActiveVehiclesCount(totalUnits, MainForm.IS_SIERRA_WIRELESS, out totaldbunits); lbUnitsRegistation.Text = string.Format(returnLNGString("activeTotalUnits"), numberOfActiveUnits, totaldbunits, totalUnits); lbsaveNotificationSip.Visible = needRestart; MainPanel.Controls.Clear(); if (db4vehs != null) { unitControl = new controlUnit(db4users, db4vehs, db4groups, dbicons, db4contacts); //unitControl.Parent = this; unitControl.Dock = System.Windows.Forms.DockStyle.Fill; if (selectedVeh != null) unitControl.RefreshGrid(selectedVeh); } MainPanel.Controls.Add(unitControl); } private void LoadSystemTab() { MainPanel.Controls.Clear(); if (db4vehs != null) { systemControl = new controlSystem(db4vehs, db4telemetry, db4Alarm, this); systemControl.Dock = System.Windows.Forms.DockStyle.Fill; } MainPanel.Controls.Add(systemControl); } private void LoadSettingsTab() { MainPanel.Controls.Clear(); if (db4emailService != null) { setControl = new controlSettings(DBUser, DBSchema, DBServer, db4emailService, db4Alarm, dbicons, db4settings); setControl.Dock = System.Windows.Forms.DockStyle.Fill; } MainPanel.Controls.Add(setControl); } private void LoadGatewayTab() { MainPanel.Controls.Clear(); if (db4gateway != null) { gatewayControl = new controlGateways(db4gateway, totalGateways, db4Registration); gatewayControl.Dock = System.Windows.Forms.DockStyle.Fill; } lbsaveNotificationSip.Visible = needRestart; MainPanel.Controls.Add(gatewayControl); } private void LoadTicketingTab() { MainPanel.Controls.Clear(); if (db4Ticketing != null) { ticketingControl = new controlTicketing(db4Ticketing); ticketingControl.Dock = System.Windows.Forms.DockStyle.Fill; } MainPanel.Controls.Add(ticketingControl); } #endregion #region users private void btnUserAdd_Click(object sender, EventArgs e) { Console.WriteLine("User form ; mode = ADD"); UsersForm uf = new UsersForm(db4users, db4settings,db4gateway); uf.FormClosed += new FormClosedEventHandler(uf_FormClosed); uf.Show(); } void uf_FormClosed(object sender, FormClosedEventArgs e) { if (usrControl.selectedUser != null) { if (UsersForm.UsersCollection.ContainsKey(usrControl.selectedUser.Id)) UsersForm.UsersCollection.Remove(usrControl.selectedUser.Id); } if (currentTab == tabUser) LoadUserTab(); } private void btnUserEdit_Click(object sender, EventArgs e) { Console.WriteLine("User form ; mode = EDIT"); if (usrControl != null && usrControl.selectedUser != null) { UsersForm uf = UsersForm.GetSingleton(db4users, usrControl.selectedUser); uf.FormClosed += new FormClosedEventHandler(uf_FormClosed); uf.Show(); uf.BringToFront(); if (uf.WindowState == FormWindowState.Minimized) uf.WindowState = FormWindowState.Normal; } else { //RadMessageBox.Show("Select an user first","error!", MessageBoxButtons.OK, RadMessageIcon.Error); CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("selfirst"), MainForm.returnLNGString("err")); } } private void btnUserDelete_Click(object sender, EventArgs e) { if (usrControl != null && usrControl.selectedUser != null) { if (usrControl.selectedUser.UType == USERTYPE.Admin) { CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("adminUSR"), MainForm.returnLNGString("err")); return; } Int32 countGeo = db4users.countGeofencesForUser(usrControl.selectedUser.Id); Int32 countLand = db4users.countLandmarksForUser(usrControl.selectedUser.Id); DialogResult dr = CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("deluser"), MainForm.returnLNGString("areyou"), true); if (dr == DialogResult.Yes && countLand == 0 && countGeo == 0) { db4users.deleteUser(usrControl.selectedUser.UserName); db4settings.deleteSettingForUser(usrControl.selectedUser.Id); db4gateway.deleteGatewayforUser(usrControl.selectedUser.Id); dbpatch.deletePatchFromAdmin(0, usrControl.selectedUser.Id.ToString()); LoadUserTab(); } else if(dr == DialogResult.Yes) { PopupForm tmp = new PopupForm(usrControl.selectedUser.UserName ,countGeo, countLand); tmp.ShowDialog(); string user; user = tmp.Name; if (!String.IsNullOrEmpty(user)) { int idForUSer = db4users.getUserId(user); db4users.resetallGeoFenceAndLandmarks(usrControl.selectedUser.Id, idForUSer); db4users.deleteUser(usrControl.selectedUser.UserName); db4settings.deleteSettingForUser(usrControl.selectedUser.Id); db4gateway.deleteGatewayforUser(usrControl.selectedUser.Id); dbpatch.deletePatchFromAdmin(0, usrControl.selectedUser.Id.ToString()); } LoadUserTab(); } } else { CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("selfirst"), MainForm.returnLNGString("err")); } } #endregion #region vehicles private void btnAddUnit_Click(object sender, EventArgs e) { if (numberOfActiveUnits >= totalUnits) { CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("maxUnitsReached"), MainForm.returnLNGString("err")); return; } selectedVeh = unitControl.selectedVeh; List usrList = db4users.getAllUsers(); VehiclesForm vf = new VehiclesForm(db4vehs,db4groups,db4gateway, db4Alarm, db4telemetry, usrList,this); vf.FormClosed += new FormClosedEventHandler(vf_FormClosed); vf.Show(); } void vf_FormClosed(object sender, FormClosedEventArgs e) { if (currentTab == tabUnits) LoadUnitsTab(); } private void btnUnitEdit_Click(object sender, EventArgs e) { if (unitControl != null && unitControl.selectedVeh != null) { List usrList = db4users.getAllUsers(); VehiclesForm vf; selectedVeh = unitControl.selectedVeh; if (unitControl.GridViewUnitsList.SelectedRows.Count > 1) { //VehiclesForm vf = new VehiclesForm(db4vehs, db4groups, db4gateway, usrList, unitControl.parms, this); vf = VehiclesForm.GetSingleton(db4vehs, db4groups, db4gateway, usrList, unitControl.parms, this); } else { //vf = new VehiclesForm(db4vehs, db4groups,db4gateway, usrList, unitControl.selectedVeh, this); vf = VehiclesForm.GetSingleton(db4vehs, db4groups, db4gateway, usrList, unitControl.selectedVeh, this); } vf.FormClosed += new FormClosedEventHandler(vf_FormClosed); vf.Show(); vf.BringToFront(); if (vf.WindowState == FormWindowState.Minimized) vf.WindowState = FormWindowState.Normal; } } private void btnUnitDelete_Click(object sender, EventArgs e) { if (unitControl != null) { selectedVeh = null; if (unitControl.GridViewUnitsList.SelectedRows.Count > 1) { DialogResult dr = RadMessageBox.Show(MainForm.returnLNGString("aredelList"), MainForm.returnLNGString("areyou"), MessageBoxButtons.YesNo, RadMessageIcon.Exclamation); if (dr == DialogResult.Yes) { db4vehs.deleteVehicleList(unitControl.parms.imeiList, unitControl.parms.IdList); //MainForm.CallWebServer(MainForm.RestartSipLink); MainForm.needRestart = true; } } else { DialogResult dr = RadMessageBox.Show(MainForm.returnLNGString("aredel"), MainForm.returnLNGString("areyou"), MessageBoxButtons.YesNo, RadMessageIcon.Exclamation); //CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("aredel"), MainForm.returnLNGString("areyou"), true); if (dr == DialogResult.Yes) { db4vehs.deleteVehicle(unitControl.selectedVeh.Imei); //MainForm.CallWebServer(MainForm.RestartSipLink); MainForm.needRestart = true; } } LoadUnitsTab(); } } #endregion private void btnTelemetrySave_Click(object sender, EventArgs e) { systemControl.Save(); DisplayToast(MainForm.returnLNGString("settingSvdSucces"), MainForm.returnLNGString("HTMLsettingSvdSucces")); } private void btnSaveSettings4User_Click(object sender, EventArgs e) { usrControl.SaveSettings(); DisplayToast(MainForm.returnLNGString("settingSvdSucces"), MainForm.returnLNGString("HTMLsettingSvdSucces")); //SendRestart(); restartSipProcedure(); } #region groups private void btnGroupAdd_Click(object sender, EventArgs e) { //unitControl.AddNewGroup(); GroupsForm gf = new GroupsForm(unitControl,db4groups, db4gateway, "add"); gf.Show(); } private void btnGroupEdit_Click(object sender, EventArgs e) { //GroupsForm gf = new GroupsForm(unitControl, db4groups, db4gateway, "edit"); GroupsForm gf = GroupsForm.GetSingleton(unitControl, db4groups, db4gateway, "edit"); gf.Show(); gf.BringToFront(); if (gf.WindowState == FormWindowState.Minimized) gf.WindowState = FormWindowState.Normal; } private void btnGroupDelete_Click(object sender, EventArgs e) { GroupsForm gf = new GroupsForm(unitControl, db4groups, db4gateway, "delete"); gf.Show(); } #endregion private void btnAddNewGateway_Click(object sender, EventArgs e) { //todo: add new gateway in the database } private void btnAddNewSafeDispatch_Click(object sender, EventArgs e) { //todo: add new SafeDispatch in the database } private void btnSaveSettings_Click(object sender, EventArgs e) { } #region Job Tickets private void btnTicketAdd_Click(object sender, EventArgs e) { Console.WriteLine("Job Ticketing form ; mode = ADD"); TicketingForm tf = new TicketingForm(db4Ticketing, db4settings, db4gateway); tf.FormClosed += new FormClosedEventHandler(tf_FormClosed); tf.Show(); } void tf_FormClosed(object sender, FormClosedEventArgs e) { LoadTicketingTab(); } private void btnTicketEdit_Click(object sender, EventArgs e) { Console.WriteLine("Job Ticketing form ; mode = EDIT"); if (ticketingControl != null && ticketingControl.selectedTicketStatus != null) { TicketingForm tf = new TicketingForm(db4Ticketing, ticketingControl.selectedTicketStatus); tf.FormClosed += new FormClosedEventHandler(tf_FormClosed); tf.Show(); } else { //RadMessageBox.Show("Select an user first","error!", MessageBoxButtons.OK, RadMessageIcon.Error); CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("tsselfirst"), MainForm.returnLNGString("err")); } } private void btnTicketDelete_Click(object sender, EventArgs e) { if (ticketingControl != null && ticketingControl.selectedTicketStatus != null) { DialogResult dr = CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("delts"), MainForm.returnLNGString("areyou"), true); if (dr == DialogResult.Yes) { TicketResponse resp = db4Ticketing.deleteTicketingStatus(ticketingControl.selectedTicketStatus.Status); TicketingForm tf = new TicketingForm(db4Ticketing, ticketingControl.selectedTicketStatus); if (resp == TicketResponse.alreadyInTransactions) CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("tsallintrans"), MainForm.returnLNGString("err")); LoadTicketingTab(); } } else { //RadMessageBox.Show("Select an user first", "error!", MessageBoxButtons.OK, RadMessageIcon.Error); CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("selfirst"), MainForm.returnLNGString("err")); } } private void ddSierraWireless_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e) { if (!IS_SIERRA_WIRELESS) return; selectedItemDDSierra = ddSierraWireless.SelectedItem.Text; unitControl?.ShowVehs(controlUnit.isCheckboxChecked); } #endregion //DB cleanup private void DB_Cleanup() { SM.Debug("DB cleanup function!!!!!!!"); List list = new List(); list = db4vehs.getOrphanImeis(); foreach (SUID_AND_IMEI obj in list) { SM.Debug("Imei:" + obj.Imei +" found in DB without a vehicle attached!!!",false); vehResponse resp = db4vehs.CleanupSC_ID(obj.Sc_id); if (resp == vehResponse.done) { SM.Debug("Imei:" + obj.Imei + " removed from DB"); } else { SM.Debug("Imei:" + obj.Imei + " failed to cleanup from DB"); } } } private void Main_Shown(object sender, EventArgs e) { if (radioType==RADIOTYPE.HYT) { /*Theme currentTheme = Telerik.WinControls.ThemeResolutionService.GetTheme("Desert"); currentTheme.AddColorBlend("BaseColor", HslColor.FromColor(Color.FromArgb(153, 204, 255))); Color c1 = Color.Orange; Color c2 = Color.FromArgb(c1.A, (int)(c1.R * 0.9), (int)(c1.G * 0.9), (int)(c1.B * 0.9)); currentTheme.ThemeProperties["BaseColor"] = HslColor.FromColor(c2);*/ this.Icon = global::SubscriberAndUserManager.Properties.Resources.SYTADMIN64x; radRibbonBar1.StartButtonImage = global::SubscriberAndUserManager.Properties.Resources.SYT_admin_mod_2_small; //this.BackColor = HyteraColor; //MainPanel.BackColor = HyteraColor; btnUserAdd.Image = global::SubscriberAndUserManager.Properties.Resources.addNewOR; btnAddUnit.Image = global::SubscriberAndUserManager.Properties.Resources.addNewOR; //btnGroupAdd.Image = global::SubscriberAndUserManager.Properties.Resources.addNewOR; btnUserEdit.Image = global::SubscriberAndUserManager.Properties.Resources.editNewOR; btnUnitEdit.Image = global::SubscriberAndUserManager.Properties.Resources.editNewOR; btnGroupEdit.Image = global::SubscriberAndUserManager.Properties.Resources.i_groupsOR; btnUserDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewOR; btnUnitDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewOR; //btnGroupDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewOR; btnSaveSettings4User.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewOR; btnTelemetrySave.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewOR; rbtSaveGateways.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewOR; rbtSaveRegistration.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewOR; rbtSaveReports.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewOR; rbtSaveSettings.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewOR; rbtSaveUnits.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewOR; } else if (radioType == RADIOTYPE.HARRIS) { this.Icon = global::SubscriberAndUserManager.Properties.Resources.visionSmall; radRibbonBar1.StartButtonImage = global::SubscriberAndUserManager.Properties.Resources.VISIONadminsmall; //this.BackColor = HarrisColor; //MainPanel.BackColor = HarrisColor; btnUserAdd.Image = global::SubscriberAndUserManager.Properties.Resources.addNewGR; btnAddUnit.Image = global::SubscriberAndUserManager.Properties.Resources.addNewGR; //btnGroupAdd.Image = global::SubscriberAndUserManager.Properties.Resources.addNewGR; btnUserEdit.Image = global::SubscriberAndUserManager.Properties.Resources.editNewGR; btnUnitEdit.Image = global::SubscriberAndUserManager.Properties.Resources.editNewGR; btnGroupEdit.Image = global::SubscriberAndUserManager.Properties.Resources.i_groupsGR; btnUserDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewGR; btnUnitDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewGR; //btnGroupDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewGR; btnSaveSettings4User.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGR; btnTelemetrySave.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGR; rbtSaveGateways.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGR; rbtSaveRegistration.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGR; rbtSaveReports.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGR; rbtSaveSettings.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGR; rbtSaveUnits.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGR; } else if (radioType == RADIOTYPE.ATLAS) //ATLASCHANGE { //Theme currentTheme = Telerik.WinControls.ThemeResolutionService.GetTheme("Office2010Black"); // Theme currentTheme = Telerik.WinControls.ThemeResolutionService.GetTheme("Office2010Black"); this.Icon = global::SubscriberAndUserManager.Properties.Resources.ATLASadmin32; radRibbonBar1.StartButtonImage = global::SubscriberAndUserManager.Properties.Resources.Atlas_img_32; //this.BackColor = HarrisColor; //MainPanel.BackColor = HarrisColor; btnUserAdd.Image = global::SubscriberAndUserManager.Properties.Resources.addNewGE; btnAddUnit.Image = global::SubscriberAndUserManager.Properties.Resources.addNewGE; //btnGroupAdd.Image = global::SubscriberAndUserManager.Properties.Resources.addNewGE; btnUserEdit.Image = global::SubscriberAndUserManager.Properties.Resources.editNewGE; btnUnitEdit.Image = global::SubscriberAndUserManager.Properties.Resources.editNewGE; btnGroupEdit.Image = global::SubscriberAndUserManager.Properties.Resources.i_groupsGE; btnUserDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewGE; btnUnitDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewGE; //btnGroupDelete.Image = global::SubscriberAndUserManager.Properties.Resources.deleteNewGE; btnSaveSettings4User.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGE; btnTelemetrySave.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGE; rbtSaveGateways.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGE; rbtSaveRegistration.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGE; rbtSaveReports.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGE; rbtSaveSettings.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGE; rbtSaveUnits.Image = global::SubscriberAndUserManager.Properties.Resources.write1NewGE; } else if (radioType == RADIOTYPE.SIMOCO) { //Theme currentTheme = Telerik.WinControls.ThemeResolutionService.GetTheme("Office2010Black"); this.Icon = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_64; radRibbonBar1.StartButtonImage = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_24; } else if (radioType == RADIOTYPE.EXCERA) { //Theme currentTheme = Telerik.WinControls.ThemeResolutionService.GetTheme("Office2010Black"); this.Icon = global::SubscriberAndUserManager.Properties.Resources.AXYS_ICON; radRibbonBar1.StartButtonImage = global::SubscriberAndUserManager.Properties.Resources.axys_tools_24; } } private void MainForm_Load(object sender, EventArgs e) { //if registration is unsuccessfull db4vehs will be null if (db4vehs == null) return; radRibbonBar1.CollapseRibbonOnTabDoubleClick = false; lbUnitsRegistation.Text = string.Format(returnLNGString("activeTotalUnits"), numberOfActiveUnits, totaldbunits, totalUnits); LoadUnitsTab(); ContextMenu contextMenu = new ContextMenu(); contextMenu.MenuItems.Add("Check for updates...", (s, e2) => { UpdateForm uf = new UpdateForm(App.ADMIN_MODULE, true) { IsDevelop = isDevelop }; uf.Show(); }); contextMenu.MenuItems.Add("Exit", (s, e2) => CloseApp()); notifyIcon1.ContextMenu = contextMenu; notifyIcon1.ShowBalloonTip(500); // check for a new version if available if (autoupdate) CheckForUpdate(); } #region UPDATE /// /// Check for new version release on SafeMobile Portal /// The check is done by comparing Current Assembly Version with the one /// written in a xml file on the portal. /// private void CheckForUpdate() { App appType = App.ADMIN_MODULE; AutoUpdate au = new AutoUpdate(appType) { IsDevelop = isDevelop }; au.OnNewVersionAvailable += delegate (string version) { notifyIcon1.Text = "New version available"; notifyIcon1.ShowBalloonTip(2500, $"{App.GetAppName(appType)} version {version} available", $"Press to download and install the latest version of {App.GetAppName(appType)}.", ToolTipIcon.Info); notifyIcon1.BalloonTipClicked += delegate (object sender, EventArgs e) { if (notifyIcon1.Text.Equals("New version available")) { UpdateForm uf = new UpdateForm(appType, true) { IsDevelop = isDevelop }; uf.Show(); } }; }; // call method to check for new updated au.CheckUpdate(); } #endregion private void CloseApp() { Process oldProcess = Process.GetCurrentProcess(); oldProcess.Kill(); Application.Exit(); } public void DisplayToast(String captionText, String contentText) { // hide alert if already opened if (desktopAlertFeedback.IsDisposed || desktopAlertFeedback.IsDisposing) desktopAlertFeedback.Hide(); desktopAlertFeedback.CaptionText = captionText; desktopAlertFeedback.ContentText = contentText; desktopAlertFeedback.Show(); } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { db4users?.CloseConnection(); registrationBackgroundWorker?.CancelAsync(); CallWebServer(RestartSipLink); CallWebServer(reloadDataLink); } internal static bool needRestart = false; internal static bool needReload = false; private void btSaveSettings_FakeClick(object sender, EventArgs e) { DisplayToast(MainForm.returnLNGString("settingSvdSucces"), MainForm.returnLNGString("HTMLsettingSvdSucces")); restartSipProcedure(); } private void rtbRefreshGrid_Click(object sender, EventArgs e) { reportControl?.populateList(); } internal void restartSipProcedure() { if (needRestart) CallWebServer(RestartSipLink); if (needReload) CallWebServer(reloadDataLink); needRestart = false; needReload = true; lbsaveNotificationSip.Visible = false; } internal void setVisibleSipRestartNotification() { needRestart = true; needReload = true; lbsaveNotificationSip.Visible = true; } internal void setVisibleReloadNotification() { needReload = true; lbsaveNotificationSip.Visible = true; } public static async void CallWebServer(string address) { udp.Send(Utils.Convert_text_For_multicast("#0.0#209#1"), Utils.Convert_text_For_multicast("#0.0#209#1").Length); //if (MainForm.radioType != RADIOTYPE.SIMOCO) await Utils.CallWebServerAsync(address); } /// /// Get an int value from the configuration file. The desired value is identifiec by /// the key and the header under which is placed is pointed by the header. Also a default /// value can be set in case the value doesn't exist and needs to be created before /// beeing returned /// /// Header unde which the desired config parameter is placed /// The Key that designates the desired config parameter /// A default value that will be used and returned in case the /// config file doesn't have a value for the parameter /// Parameter value from the config file, or the default value in case it doesn't /// exist private Int32 GetInt32Value(String header, String key, Int32 defaultValue) { if (!Program.source.Configs[header].Contains(key)) Program.source.Configs[header].Set(key, defaultValue); return Program.source.Configs[header].GetInt(key); } /// /// Get a string value from the configuration file. The desired value is identifiec by /// the key and the header under which is placed is pointed by the header. Also a default /// value can be set in case the value doesn't exist and needs to be created before /// beeing returned /// /// Header unde which the desired config parameter is placed /// The Key that designates the desired config parameter /// A default value that will be used and returned in case the /// config file doesn't have a value for the parameter /// Parameter value from the config file, or the default value in case it doesn't /// exist private String GetStringValue(String header, String key, String defaultValue) { if (!Program.source.Configs[header].Contains(key)) Program.source.Configs[header].Set(key, defaultValue); return Program.source.Configs[header].GetString(key); } /// /// Get a boolean value from the configuration file. The desired value is identifiec by /// the key and the header under which is placed is pointed by the header. Also a default /// value can be set in case the value doesn't exist and needs to be created before /// beeing returned /// /// Header unde which the desired config parameter is placed /// The Key that designates the desired config parameter /// A default value that will be used and returned in case the /// config file doesn't have a value for the parameter /// Parameter value from the config file, or the default value in case it doesn't /// exist private Boolean GetBooleanValue(String header, String key, Boolean defaultValue) { if (!Program.source.Configs[header].Contains(key)) Program.source.Configs[header].Set(key, defaultValue); return Program.source.Configs[header].GetBoolean(key); } } //public enum RADIOTYPE //{ // MOTO = 0, // HYT = 1, // HARRIS = 2, // ATLAS = 3, // TETRA =4, // UNKNOWN = 5, // CONECTPLUS =6, // REPEATER_TRBO = 7, // SIMOCO = 8, // LINX = 9, // LINXB = 10, // EXCERA = 11, //} }