using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Telerik.WinControls; using RegLibDLL; using SafeMobileLib; using Telerik.WinControls.UI; using MapGoogle; using System.Net.Sockets; using System.Net; using System.Runtime.InteropServices; using System.Threading; using System.Diagnostics; using ReportsLibrary; using NetFwTypeLib; using SharedUI; using System.IO; using Dispatcher.maptab.UIClasses; using System.Globalization; using System.Resources; namespace Safedispatch_4_0 { public partial class Login : Telerik.WinControls.UI.RadForm { private Boolean valid = false; //the object needed to access the database private SMdb_access smdbObj; private string MyConString; private Boolean LoadUser = true; private TcpClient client; //private Int32 registrationPort = 5680; private SDRegistration sdRegistration; private BackgroundWorker bgWorkerRegistration; private WaitingForm wf; public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2; [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); public static CultureInfo culture = CultureInfo.CreateSpecificCulture("en"); private void Login_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); } } public Login() { InitializeComponent(); FireWallException fw = new FireWallException(); string name = System.AppDomain.CurrentDomain.FriendlyName; string path = System.Windows.Forms.Application.ExecutablePath; fw.checkFirewall(name, path); //bool result = fw.AuthorizeProgram(name, path, NET_FW_SCOPE_.NET_FW_SCOPE_ALL, NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY); //if (result) SM.Debug("Firewall exception added for:" + name + " path:" + path); //else SM.Debug("Firewall exception ERROR for:" + name + " path:" + path); // set theme for the Message Box RadMessageBox.SetThemeName("TelerikMetroBlue"); // set theme MainForm2.setThemingColors(MainForm2.radioType); #region THEMING btLogin.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor; btLogin.ButtonElement.ButtonFillElement.NumberOfColors = 1; btnUpdate.ButtonElement.ButtonFillElement.BackColor = Color.White; btnUpdate.ButtonElement.ButtonFillElement.NumberOfColors = 1; btnUpdate.ButtonElement.TextElement.ForeColor = MainForm2.ButtonColor; #endregion // do not allow login button with empty password btLogin.Enabled = false; this.Size = new Size(551, 408); SM debug = new SM(); try { MainForm2.cfg.LoadConfig(); switch (MainForm2.radioType) { case RADIOTYPE.CONECTPLUS: case RADIOTYPE.TETRA: case RADIOTYPE.MOTO: case RADIOTYPE.REPEATER_TRBO: panelControls.Location = new Point(320, 200); panelControls.BackColor = Color.Transparent; cbRemeber.RootElement.ForeColor = Color.Gray; break; case RADIOTYPE.HYT: this.Text = "SafeSyt"; this.BackgroundImage = global::Dispatcher.Properties.Resources.login_hytera_v2; this.Icon = global::Dispatcher.Properties.Resources.HytSmall24; panelControls.BackColor = Color.FromArgb(93,93,93); cbRemeber.RootElement.ForeColor = Color.Gray; panelControls.Location = new Point(287, 164); break; case RADIOTYPE.HARRIS: this.Text = "Vision"; this.BackgroundImage = global::Dispatcher.Properties.Resources.visionLogin; panelControls.BackColor = Color.FromArgb(49, 49, 49); cbRemeber.RootElement.ForeColor = Color.Gray; panelControls.Location = new Point(287, 164); this.Icon = global::Dispatcher.Properties.Resources.HarrisSmall; //ThemeResolutionService.ApplicationThemeName = "Office2010Black"; //this.ThemeName = "Office2010Black"; lbVersion.ForeColor = MainForm2.HarTextColor; break; case RADIOTYPE.ATLAS: this.Text = "Atl25"; this.BackgroundImage = global::Dispatcher.Properties.Resources.login_Atl25; //ATLASCHANGE panelControls.BackColor = Color.Black; panelControls.Location = new Point(287, 164); this.Icon = global::Dispatcher.Properties.Resources.HarrisSmall; lbVersion.ForeColor = MainForm2.HarTextColor; cbRemeber.ButtonElement.TextElement.ForeColor = MainForm2.HarTextColor; break; case RADIOTYPE.SIMOCO: this.Text = "Simoco"; this.BackgroundImage = global::Dispatcher.Properties.Resources.simoco3; //ATLASCHANGE this.Icon = global::Dispatcher.Properties.Resources.simoco_dispatch_24; panelControls.Location = new Point(287, 164); break; case RADIOTYPE.EXCERA: this.Text = "AXYS"; this.BackgroundImage = global::Dispatcher.Properties.Resources.axys ; //ATLASCHANGE this.BackgroundImageLayout = ImageLayout.Stretch; this.Icon = global::Dispatcher.Properties.Resources.AXYS_ICON; panelControls.Location = new Point(147, 164); break; case RADIOTYPE.LINX: case RADIOTYPE.LINXB: this.Text = "LINX"; this.BackgroundImage = global::Dispatcher.Properties.Resources.login_linx; panelControls.Location = new Point(320, 200); panelControls.BackColor = Color.Transparent; cbRemeber.RootElement.ForeColor = Color.Gray; break; } } catch (Exception ex) { SM.Debug("Error on read config file: " + ex.ToString()); } Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; lbVersion.Text = "Version: "+v.ToString(); } #region bg worker registration events void bgWorkerRegistration_DoWork(object sender, DoWorkEventArgs e) { sdRegistration = getRegistration(); MainForm2.cfg.MSG_BUS_IP = sdRegistration.MSG_BUS_IP; // do not use the messagebus port if already specified in the config file if(MainForm2.cfg.MSg_BUS_port == null || MainForm2.cfg.MSg_BUS_port.Length < 2) MainForm2.cfg.MSg_BUS_port = sdRegistration.MSg_BUS_port; MainForm2.cfg.V_MSG_BUS_port = sdRegistration.VoiceMessageBusPort; } void bgWorkerRegistration_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (wf != null) if (wf.IsInitialized) if (wf.IsLoaded) { SM.Debug("Shuting down waiting form"); wf.DialogResult = DialogResult.OK; wf.Close(); } if (appServerMissing) { RadMessageBox.Show("Could not reach Application Server. Please check the connection and try again!!!", "Connection Error", MessageBoxButtons.OK, RadMessageIcon.Error); //System.Environment.Exit(0); System.Windows.Forms.Application.Exit(); return; } ContinueLogin(); } #endregion private String YourIPaddress = "127.0.0.1"; internal static string IPaddress = "127.0.0.1"; private void ContinueLogin() { SM.Debug("Continuing login form after registration info aquired from app server"); if (sdRegistration.ip.Equals("invalid")) { btLogin.Text = "Invalid registration"; btLogin.Enabled = false; switch (MainForm2.radioType) { case RADIOTYPE.CONECTPLUS: case RADIOTYPE.TETRA: case RADIOTYPE.MOTO: case RADIOTYPE.REPEATER_TRBO: Console.WriteLine("map type:" + sdRegistration.map_type); if (sdRegistration.map_type == 9) RadMessageBox.Show("Please register your copy of SafeDispatch using the Administrative Module.\n Your unique ID is:" + MainForm2.uniqueID+" is used by other client", "Info", MessageBoxButtons.OK, RadMessageIcon.Info); else RadMessageBox.Show("Please register your copy of SafeDispatch using the Administrative Module.\n Your IP address is:" + YourIPaddress, "Info", MessageBoxButtons.OK, RadMessageIcon.Info); break; case RADIOTYPE.HYT: RadMessageBox.Show("Please register your copy of SafeSyt using the Administrative Module.\n Your IP address is:" + YourIPaddress, "Info", MessageBoxButtons.OK, RadMessageIcon.Info); break; case RADIOTYPE.HARRIS: ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show("Please register your copy of Vision using the Administrative Module.\n Your IP address is:" + YourIPaddress, "Info", MessageBoxButtons.OK, RadMessageIcon.Info); break; case RADIOTYPE.ATLAS: ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show("Please register your copy of ATL25 using the Administrative Module.\n Your IP address is:" + YourIPaddress, "Info", MessageBoxButtons.OK, RadMessageIcon.Info); break; case RADIOTYPE.SIMOCO: ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show("Please register your copy of Simoco using the Administrative Module.\n Your IP address is:" + YourIPaddress, "Info", MessageBoxButtons.OK, RadMessageIcon.Info); break; case RADIOTYPE.EXCERA: //((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show("Please register your copy of EXCERA using the Administrative Module.\n Your IP address is:" + YourIPaddress, "Info", MessageBoxButtons.OK, RadMessageIcon.Info); break; case RADIOTYPE.LINX: case RADIOTYPE.LINXB: RadMessageBox.Show("Please register your copy of LINXDispatch using the Administrative Module.\n Your IP address is:" + YourIPaddress, "Info", MessageBoxButtons.OK, RadMessageIcon.Info); break; } // System.Environment.Exit(1); System.Windows.Forms.Application.Exit(); } else if (sdRegistration.ip.Equals("valid") && !App.isValidVersion(MainForm2.APP_SERVER_VERSION, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())) { 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) { DisplayModalUpdateDialog(); System.Windows.Forms.Application.Exit(); } else System.Windows.Forms.Application.Exit(); } else { this.Enabled = true; MainForm2.HasVoice = sdRegistration.voice; MainForm2.recordingsDecide = sdRegistration.recordings; MainForm2.ReportDecide = sdRegistration.reports; MainForm2.ZonesDecide = sdRegistration.zones; MainForm2.GPSDecide = sdRegistration.gps; MainForm2.SMSDecide = sdRegistration.sms; MainForm2.TicketingDecide = sdRegistration.ticketing; MainForm2.TelemDecide = sdRegistration.telemetry; MainForm2.cfg.DB_IP = sdRegistration.DatabaseIP; MainForm2.cfg.DB_schema = sdRegistration.Db_schema; MainForm2.cfg.DB_user = sdRegistration.Db_user; MainForm2.cfg.DB_passwd = sdRegistration.Db_password; MainForm2.cfg.DB_port = sdRegistration.Db_port; MyConString = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};Pooling=false;Timeout=60;CommandTimeout=0;", MainForm2.cfg.DB_IP, MainForm2.cfg.DB_port, MainForm2.cfg.DB_user, MainForm2.cfg.DB_passwd, MainForm2.cfg.DB_schema); MainForm2.MapType = MapTYPE.Google; //sdReg.map_type = 3; if (sdRegistration.map_type == 1) { if (MainForm2.googlemaptype.Contains("map")) MainForm2.MapHtmlName = "SfmbMapsMainMap.html"; else if (MainForm2.googlemaptype.Contains("hybrid")) MainForm2.MapHtmlName = "SfmbMapsMain.html"; else if (MainForm2.googlemaptype.Contains("satellite")) MainForm2.MapHtmlName = "SfmbMapsMainSatelitte.html"; /* string sourceDir = System.Windows.Forms.Application.StartupPath + @"\resource\map_google\"; string targetDir = System.Windows.Forms.Application.StartupPath + @"\resource\"; foreach (var file in Directory.GetFiles(sourceDir)) File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true); */ MainForm2.MapType = MapTYPE.Google; } else if (sdRegistration.map_type == 4) MainForm2.MapType = MapTYPE.ArcGis; else if (sdRegistration.map_type == 3) { if (MainForm2.googlemaptype.Contains("map")) MainForm2.MapHtmlName = "SfmbMapsMainMap-osm.html"; else if (MainForm2.googlemaptype.Contains("hybrid")) MainForm2.MapHtmlName = "SfmbMapsMain-osm.html"; else if (MainForm2.googlemaptype.Contains("satellite")) MainForm2.MapHtmlName = "SfmbMapsMainSatelitte-osm.html"; /* string sourceDir = System.Windows.Forms.Application.StartupPath + @"\resource\map_osm\"; string targetDir = System.Windows.Forms.Application.StartupPath + @"\resource\"; foreach (var file in Directory.GetFiles(sourceDir)) File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)), true); */ MainForm2.MapType = MapTYPE.Google; } StaticMembers.MapType = MainForm2.MapType; } try { smdbObj = new SMdb_access(); DBuserManager tmp = new DBuserManager(MainForm2.cfg.DB_IP, MainForm2.cfg.DB_schema, MainForm2.cfg.DB_user, MainForm2.cfg.DB_passwd, MainForm2.cfg.DB_port); MainForm2.UsersList = tmp.getAllDispatcher(); MainForm2.UsersList.Sort(delegate(User p1, User p2) { return p1.UserName.CompareTo(p2.UserName); }); } catch (Exception ex) { MainForm2.UsersList = new List(); SM.Debug("Error on load user from DB" + ex.ToString()); RadMessageBox.Show("Unable to connect to Database!\nThis may be caused by a firewall, please try disabling firewall."); } if (MainForm2.UsersList.Count > 0) { cbUsers.DataSource = MainForm2.UsersList; cbUsers.DisplayMember = "UserName"; cbUsers.SelectedIndex = 0; } else { cbUsers.Text = "No user found"; LoadUser = false; } if (!valid) { MainForm2.KillAPP = true; // MainForm2.RegistrName = "Unregistered"; // MainForm2.ExpireLimit = ""; // lbMapType.Visible = false; // cbMapType.Visible = false; } //cbLang.SelectedIndex = 1; cbLang.SelectedIndex = 0; // restore previous settings from the config file if ((LoadUser) && (MainForm2.cfg.Login != "") && (MainForm2.cfg.Login != " ")) { Int32 cnt = 0; foreach (RadListDataItem obj in cbUsers.Items) { User u = (User)(obj.Value); if (u.UserName.CompareTo(MainForm2.cfg.Login) == 0) { cbUsers.SelectedIndex = cnt; txPass.Text = MainForm2.cfg.Pass; cbRemeber.Checked = true; foreach(RadListDataItem rl in cbLang.Items) { if(rl.Tag.ToString().Equals(u.Language)) { cbLang.SelectedItem = rl; // update the language UI onLanguageChanged(u.Language, u.SipID); culture = CultureInfo.CreateSpecificCulture(u.Language); break; } } break; } cnt++; } } ForceTimer.Enabled = true; ForceTimer.Start(); MainForm2.IsInLogin = false; } private bool appServerMissing = false; #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 DisplayModalUpdateDialog() { App appType = App.DISPATCH_MOTOROLA; switch(MainForm2.radioType) { case RADIOTYPE.MOTO: case RADIOTYPE.TETRA: case RADIOTYPE.REPEATER_TRBO: case RADIOTYPE.CONECTPLUS: appType = App.DISPATCH_MOTOROLA; break; case RADIOTYPE.ATLAS: appType = App.DISPATCH_ATLAS; break; case RADIOTYPE.HYT: appType = App.DISPATCH_HYTERA; break; case RADIOTYPE.HARRIS: appType = App.DISPATCH_HARRIS; break; case RADIOTYPE.SIMOCO: appType = App.DISPATCH_SIMOCO; break; case RADIOTYPE.EXCERA: appType = App.DISPATCH_EXCERA; break; } UpdateForm uf = new UpdateForm(appType, true) { IsDevelop = MainForm2.cfg.isDevelope }; uf.ShowDialog(); } #endregion private SDRegistration getRegistration() { SDRegistration toReturn = new SDRegistration(); try { client = new TcpClient(); IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(MainForm2.cfg.APPLICATION_SERVER_IP), MainForm2.cfg.RegsPort); client.Connect(serverEndPoint); YourIPaddress = (client.Client.LocalEndPoint.ToString().Split(':'))[0]; IPaddress = MainForm2.cfg.LocalIP.Length > 3 ? MainForm2.cfg.LocalIP : YourIPaddress; NetworkStream clientStream = client.GetStream(); System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); byte[] buffer = encoding.GetBytes("100"); clientStream.Write(buffer, 0, buffer.Length); SM.Debug("Sent registration request to server, waiting..."); byte[] message = new byte[256]; clientStream.ReadTimeout = 7000; int result = clientStream.Read(message, 0, message.Length); toReturn = MainForm2.verifyReg(message); if (toReturn.ip.Equals("invalid")) { client.Close(); Thread.Sleep(100); client = new TcpClient(); client.Connect(serverEndPoint); buffer = encoding.GetBytes("1000#" + MainForm2.uniqueID + "#"); NetworkStream clientStream2 = client.GetStream(); clientStream2.Write(buffer, 0, buffer.Length); byte[] message2 = new byte[256]; clientStream2.ReadTimeout = 7000; SM.Debug("Sent registration request to server with unique ID, waiting..."); int result2 = clientStream2.Read(message2, 0, message2.Length); toReturn = MainForm2.verifyReg(message2); } else MainForm2.uniqueID = 0; } catch (Exception ex) { SM.Debug("Dongle registration:" + ex.ToString()); appServerMissing = true; toReturn.ip = "invalid"; } return toReturn; } private void radButton1_Click(object sender, EventArgs e) { if (cbUsers.SelectedItem == null) { if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show(MainForm2.returnLNGString("nouser")); return; } else { Console.WriteLine("Value:" + ((User)((RadListDataItem)cbUsers.SelectedItem).Value).Password.CompareTo(txPass.Text) + " Comp1:" + ((User)((RadListDataItem)cbUsers.SelectedItem).Value).Password + " Comp2:" + txPass.Text); if (((User)((RadListDataItem)cbUsers.SelectedItem).Value).Password.CompareTo(txPass.Text) == 0) { /* MainForm2.MapType = MapTYPE.Google; if (cbMapType.Text.Contains("MapPoint US")) { MainForm2.MapType = MapTYPE.MapPoint; MainForm2.MapsUS = true; } else if (cbMapType.Text.Contains("MapPoint EU")) { MainForm2.MapType = MapTYPE.MapPoint; MainForm2.MapsUS =false; } else if (cbMapType.Text.Contains("MapInfo")) MainForm2.MapType = MapTYPE.MapInfo;*/ //MainForm2.MapType = MapTYPE.MapPoint; //check daca userul este ON sau nu MainForm2.userIDX = ((User)((RadListDataItem)cbUsers.SelectedItem).Value).Id; MainForm2.userLog = ((User)((RadListDataItem)cbUsers.SelectedItem).Value).UserName; MainForm2.userType = ((User)((RadListDataItem)cbUsers.SelectedItem).Value).UType; try { MainForm2.userSipId = MainForm2.radioType == RADIOTYPE.EXCERA ? int.Parse(MainForm2.userLog) : ((User)((RadListDataItem)cbUsers.SelectedItem).Value).SipID; } catch(Exception ex) { Utils.WriteLine(ex.ToString(), ConsoleColor.Red); } if (((User)((RadListDataItem)cbUsers.SelectedItem).Value).UType == USERTYPE.Dispatcher) MainForm2.LimitedUser = false; else MainForm2.LimitedUser = true; MainForm2.Langidx = cbLang.SelectedIndex; if (cbRemeber.Checked) MainForm2.cfg.SavePass(cbUsers.Text, txPass.Text, cbLang.SelectedIndex.ToString()); else MainForm2.cfg.SavePass("", "", "0"); Boolean checkstatus = false; try { checkstatus = smdbObj.CheckUserStatus(MainForm2.userIDX, MyConString); } catch (Exception ex) { SM.Debug("Error check login on DB" + ex.ToString()); } Boolean startmainForm = false; if ((checkstatus)&&(!MainForm2.forceLogin)) { if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; DialogResult dr2 = RadMessageBox.Show(this, "The user " + cbUsers.Text + " is already logged on another computer." + "\r\n" + "Do you want to continue?", "Warning", MessageBoxButtons.YesNo, RadMessageIcon.Exclamation); if (dr2 == DialogResult.Yes) startmainForm = true; } else startmainForm = true; if (startmainForm) { try { User u = ((User)cbUsers.SelectedItem.Value); u.Language = cbLang.SelectedItem.Tag.ToString(); VisualSettings.SetDispatcherLanguage(u.SipID, u.Language); MainForm2.mapLanguage = GetLanguageForMap(cbLang.Text); MainForm2 tmp = new MainForm2(this); tmp.Show(); } catch (Exception ex) { SM.Debug("Exception on start MAINFORM: " + ex.ToString()); if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show("Error starting SafeDispatch. Please check system or contact support.", "Warning", MessageBoxButtons.OK, RadMessageIcon.Exclamation); } } } else { if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show("Please check username and password", "Invalid credentials", MessageBoxButtons.OK, RadMessageIcon.Exclamation); } } } private void CloseButton_Click(object sender, EventArgs e) { Close(); System.Windows.Forms.Application.Exit(); } private void btnUpdate_Click(object sender, EventArgs e) { try { Process proc = new Process(); proc.StartInfo.FileName = "..\\Updater\\Updater.exe"; if (MainForm2.radioType == RADIOTYPE.MOTO) proc.StartInfo.Arguments = "motorola"; else if (MainForm2.radioType == RADIOTYPE.HARRIS) proc.StartInfo.Arguments = "harris"; else if (MainForm2.radioType == RADIOTYPE.HYT) proc.StartInfo.Arguments = "hytera"; else if (MainForm2.radioType == RADIOTYPE.ATLAS) proc.StartInfo.Arguments = "atlas"; else if (MainForm2.radioType == RADIOTYPE.TETRA) proc.StartInfo.Arguments = "tetra"; else if (MainForm2.radioType == RADIOTYPE.CONECTPLUS) proc.StartInfo.Arguments = "conplus"; else if (MainForm2.radioType == RADIOTYPE.REPEATER_TRBO) proc.StartInfo.Arguments = "repeater"; else if (MainForm2.radioType == RADIOTYPE.SIMOCO) proc.StartInfo.Arguments = "simoco"; else if (MainForm2.radioType == RADIOTYPE.EXCERA) proc.StartInfo.Arguments = "excera"; else if (MainForm2.radioType == RADIOTYPE.LINX) proc.StartInfo.Arguments = "linx"; else if (MainForm2.radioType == RADIOTYPE.LINXB) proc.StartInfo.Arguments = "linxb"; proc.Start(); } catch (Exception ex) { SM.Debug("EX:"+ex.ToString()); if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show("Could not find Updater!!!!"); } } private void txPass_KeyPress(object sender, KeyPressEventArgs e) { if ((int)e.KeyChar == 13) btLogin.PerformClick(); } private String NotFindConfig = "Unable to read config file"; private void Login_Shown(object sender, EventArgs e) { try { MainForm2.cfg.LoadConfig(); // i let also the cmd here because here we have MessageShow Error } catch (Exception ex) { SM.Debug("LoadSetup() Exception: " + ex.ToString()); if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor; RadMessageBox.Show(NotFindConfig,"Error", MessageBoxButtons.OK, RadMessageIcon.Error); //Environment.Exit(1); System.Windows.Forms.Application.Exit(); } btLogin.Focus(); bgWorkerRegistration = new BackgroundWorker(); bgWorkerRegistration.DoWork += new DoWorkEventHandler(bgWorkerRegistration_DoWork); bgWorkerRegistration.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorkerRegistration_RunWorkerCompleted); bgWorkerRegistration.RunWorkerAsync(); wf = new WaitingForm("Registering", "Checking your dispatcher registration..."); wf.FormClosing += delegate (object s, FormClosingEventArgs ee) { if(wf.DialogResult == DialogResult.Cancel) System.Windows.Forms.Application.Exit(); }; wf.Show(); } private void ForceTimer_Tick(object sender, EventArgs e) { if (MainForm2.forceLogin) { btLogin.PerformClick(); } ForceTimer.Stop(); ForceTimer.Enabled = false; } private void pbLanguage_Click(object sender, EventArgs e) { cbLang.DropDownListElement.DropDownWidth = 196; cbLang.DropDownListElement.ArrowButton.PerformClick(); } private void cbUsers_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e) { User u = (User)cbUsers.SelectedItem?.Value; if (u != null && u.Language!= null) { onLanguageChanged(u.Language, u.SipID); } } private void cbLang_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e) { User u = (User)cbUsers.SelectedItem?.Value; if (u != null && cbLang.SelectedItem != null) { onLanguageChanged(cbLang.SelectedItem.Tag.ToString(), u.SipID); } } private void onLanguageChanged(string language, Int32 dispatcherSipId) { switch (language) { case "en": pbLanguage.Image = Dispatcher.Properties.Resources.f_en; break; case "zh-CN": pbLanguage.Image = Dispatcher.Properties.Resources.f_cn; break; case "cs": pbLanguage.Image = Dispatcher.Properties.Resources.f_cz; break; case "fr": pbLanguage.Image = Dispatcher.Properties.Resources.f_fr; break; case "de": pbLanguage.Image = Dispatcher.Properties.Resources.f_de; break; case "it": pbLanguage.Image = Dispatcher.Properties.Resources.f_it; break; case "ja": pbLanguage.Image = Dispatcher.Properties.Resources.f_jp; break; case "pl": pbLanguage.Image = Dispatcher.Properties.Resources.f_pl; break; case "pt": pbLanguage.Image = Dispatcher.Properties.Resources.f_pt; break; case "ro": pbLanguage.Image = Dispatcher.Properties.Resources.f_ro; break; case "ru": pbLanguage.Image = Dispatcher.Properties.Resources.f_ru; break; case "sr": pbLanguage.Image = Dispatcher.Properties.Resources.f_rs; break; case "es": pbLanguage.Image = Dispatcher.Properties.Resources.f_es; break; case "sv": pbLanguage.Image = Dispatcher.Properties.Resources.f_se; break; case "tr": pbLanguage.Image = Dispatcher.Properties.Resources.f_tr; break; case "ar": pbLanguage.Image = Dispatcher.Properties.Resources.f_ar; break; } culture = CultureInfo.CreateSpecificCulture(language); UpdateUILanguage(); } /// /// Update the language of the UI elements /// private void UpdateUILanguage() { cbUsers.NullText = returnLNGString("username", culture); txPass.NullText = returnLNGString("password", culture); btLogin.Text = returnLNGString("login", culture).ToUpper(); cbRemeber.Text = returnLNGString("rememberSettings", culture); } public static string returnLNGString(string name, CultureInfo culture) { string returnSTR = ""; ResourceManager RManager = new ResourceManager("Dispatcher.Language.myRes", typeof(MainForm2).Assembly); 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; } /* private void UpdateLanguageImage(string language) { switch (language) { case "English": pbLanguage.Image = Dispatcher.Properties.Resources.f_en; break; case "Chinese": pbLanguage.Image = Dispatcher.Properties.Resources.f_cn; break; case "Czech": pbLanguage.Image = Dispatcher.Properties.Resources.f_cz; break; case "French": pbLanguage.Image = Dispatcher.Properties.Resources.f_fr; break; case "German": pbLanguage.Image = Dispatcher.Properties.Resources.f_de; break; case "Italian": pbLanguage.Image = Dispatcher.Properties.Resources.f_it; break; case "Japanese": pbLanguage.Image = Dispatcher.Properties.Resources.f_jp; break; case "Polish": pbLanguage.Image = Dispatcher.Properties.Resources.f_pl; break; case "Portuguese": pbLanguage.Image = Dispatcher.Properties.Resources.f_pt; break; case "Romanian": pbLanguage.Image = Dispatcher.Properties.Resources.f_ro; break; case "Russian": pbLanguage.Image = Dispatcher.Properties.Resources.f_ru; break; case "Serbian": pbLanguage.Image = Dispatcher.Properties.Resources.f_rs; break; case "Spanish": pbLanguage.Image = Dispatcher.Properties.Resources.f_es; break; case "Swedish": pbLanguage.Image = Dispatcher.Properties.Resources.f_se; break; case "Turkish": pbLanguage.Image = Dispatcher.Properties.Resources.f_tr; break; } } */ private string GetLanguageForMap(string language) { string ret = "en"; switch (language) { case "English": ret = "en"; break; case "Chinese": ret = "zh-CN"; break; case "Czech": ret = "cs"; break; case "French": ret = "fr"; break; case "German": ret = "de"; break; case "Italian": ret = "it"; break; case "Japanese": ret = "ja"; break; case "Polish": ret = "pl"; break; case "Portuguese": ret = "pt"; break; case "Romanian": ret = "ro"; break; case "Russian": ret = "ru"; break; case "Serbian": ret = "sr"; break; case "Spanish": ret = "es"; break; case "Swedish": ret = "sv"; break; case "Turkish": ret = "tr"; break; case "Arabic": ret = "ar"; break; } return ret; } /// /// intercept the changes in password text in order to enable or disable the /// login button /// private void txPass_TextChanged(object sender, EventArgs e) { if (txPass.Text.Length > 0) btLogin.Enabled = true; else btLogin.Enabled = false; } /// /// Change the buttons background color for the animation buttons depending on their enabled/disabled /// state /// private void btLogin_EnabledChanged(object sender, EventArgs e) { if (((RadButton)sender).Enabled) ((RadButton)sender).ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor; else ((RadButton)sender).ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColorDisabled; } private void cbRemeber_KeyPress(object sender, KeyPressEventArgs e) { if ((int)e.KeyChar == 13) btLogin.PerformClick(); } private void Login_Load(object sender, EventArgs e) { } } }