private void populateServers() { List <List <string> > data = DBM.SQLGetTableData("servers"); foreach (List <string> row in data) { ListBoxItem itm = new ListBoxItem(); itm.Content = row[1]; this.lbStartupServers.Items.Add(itm); } }
private void lbSettingsServers_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem); if (lbi == null) { } else { string serverName = lbi.Content.ToString(); List <List <string> > data = DBM.SQLRaw("SELECT * FROM servers WHERE name = '" + serverName + "'", "servers"); this.tbSettingsName.Text = data[0][1].ToString(); this.tbSettingsIP.Text = data[0][2].ToString(); this.tbSettingsPort.Text = data[0][3].ToString(); } }
private void populateServers() { this.lbSettingsServers.Items.Clear(); List <List <string> > data = DBM.SQLGetTableData("servers"); foreach (List <string> row in data) { //foreach (string item in row) //{ //System.Diagnostics.Debug.WriteLine(item); //} ListBoxItem itm = new ListBoxItem(); itm.Content = row[1]; this.lbSettingsServers.Items.Add(itm); } }
private void bSettingsDelServ_Click(object sender, RoutedEventArgs e) { ListBoxItem lbi = this.lbSettingsServers.SelectedItem as ListBoxItem; if (lbi == null) { } else { string servName = lbi.Content.ToString(); List <List <string> > data = DBM.SQLRaw("DELETE FROM servers WHERE name='" + servName + "'", "servers"); populateServers(); tbSettingsIP.Text = ""; tbSettingsName.Text = ""; tbSettingsPort.Text = ""; } }
private void bSettingsNewServ_Click(object sender, RoutedEventArgs e) { string newName = this.tbSettingsName.Text; string newIP = this.tbSettingsIP.Text; string newPort = this.tbSettingsPort.Text; bool check = true; if (newName == "" || newIP == "" || newPort == "") { MessageBox.Show("Error - Please enter details before creating new server"); } else { List <List <string> > data = DBM.SQLGetTableData("servers"); foreach (List <string> row in data) { if (row[1] == newName) { check = false; } } if (check == true) { try { List <string> newServer = new List <string> { newName, newIP, newPort }; DBM.SQLWriteToTable(newServer, "servers"); populateServers(); } catch { MessageBox.Show("Error - Inputted information was in an invalid format"); } } else { MessageBox.Show("Error - Cannot use duplicate server name"); } } }
private void bSettingsSaveServ_Click(object sender, RoutedEventArgs e) { ListBoxItem lbi = this.lbSettingsServers.SelectedItem as ListBoxItem; if (lbi == null) { MessageBox.Show("Error - Please select a server"); } else { string serverName = lbi.Content.ToString(); string newName = this.tbSettingsName.Text; string newIP = this.tbSettingsIP.Text; string newPort = this.tbSettingsPort.Text; List <List <string> > data = DBM.SQLRaw("UPDATE servers SET name='" + newName + "', ip='" + newIP + "', port=" + newPort + " WHERE name='" + serverName + "'", "servers"); populateServers(); } }
public screenSettings() { InitializeComponent(); pageSettings = this; DBM.SQLInitialise(); populateServers(); List <string> config = CFM.ReadSettings(); cboSettingsClrSch.SelectedValue = config[4]; if (config[4] == "Light Theme") { } else if (config[4] == "Dark Theme") { VM.DarkTheme("screenSettings"); } }
public screenStartup() { InitializeComponent(); pageStartup = this; DBM.SQLInitialise(); populateServers(); MainWindow.main.ResizeMode = ResizeMode.NoResize; config = CFM.ReadSettings(); if (config[4] == "Light Theme") { } else if (config[4] == "Dark Theme") { VM.DarkTheme("screenStartup"); } Panel mainContainer = (Panel)this.Content; /// GetAll UIElement UIElementCollection element = mainContainer.Children; /// casting the UIElementCollection into List List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); /// Geting all Control from list var lstControl = lstElement.OfType <Control>(); foreach (Control control in lstControl) { Debug.WriteLine(control.GetType().ToString()); } if (Convert.ToBoolean(config[0]) == true) { this.cbRememberUser.IsChecked = true; this.tbStartupUsername.Text = config[1]; } }
private void bStartupConn_Click(object sender, RoutedEventArgs e) { if (config[0] == "true") { CFM.UpdateSetting("username", Regex.Replace(tbStartupUsername.Text, @" ", "")); } if (this.lbStartupServers.SelectedItem == null) { MessageBox.Show("Error - Please select a server"); } else if (this.tbStartupUsername.Text == "") { MessageBox.Show("Please enter a username"); } else { ListBoxItem lbi = this.lbStartupServers.SelectedItem as ListBoxItem; string servName = lbi.Content.ToString(); List <List <string> > data = DBM.SQLRaw("SELECT * FROM servers WHERE name='" + servName + "'", "servers"); string servIP = data[0][2]; int servPort = Convert.ToInt16(data[0][3]); bool connected = NM.Connect(servIP, servPort); if (connected == true) { KeyGenerator.SecretKey = KeyGenerator.GetUniqueKey(16); Debug.WriteLine(KeyGenerator.SecretKey); Dictionary <string, object> message = new Dictionary <string, object> { { "username", "" }, { "channel", "" }, { "content", "" }, { "messagetype", "keyRequest" } }; string jsonMessage = JsonConvert.SerializeObject(message); NM.SendMessage(jsonMessage); byte[] bytes = new byte[20480]; int bytesRec = NM.sender.Receive(bytes); // Receieve "publicKey" string jsonData = Encoding.UTF8.GetString(bytes, 0, bytesRec); message = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonData); string publicKey = (string)message["content"]; string ciphertext = EMRSA.Encrypt(KeyGenerator.SecretKey, publicKey); message = new Dictionary <string, object> { { "username", "" }, { "channel", "" }, { "content", ciphertext }, { "messagetype", "secretKey" } }; jsonMessage = JsonConvert.SerializeObject(message); NM.SendMessage(jsonMessage); bytes = new byte[20480]; bytesRec = NM.sender.Receive(bytes); // Recieve "confirmed" jsonData = Encoding.UTF8.GetString(bytes, 0, bytesRec); message = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonData); NM.RecieveMessage(); string username = tbStartupUsername.Text; username = Regex.Replace(username, @" ", ""); List <string> connRequest = new List <string> { username, this.tbStartupPassword.Password }; message = new Dictionary <string, object> { { "username", "" }, { "channel", "" }, { "content", connRequest }, { "messagetype", "connRequest" } }; List <object> encryptedMessage = EMAES.Encrypt(JsonConvert.SerializeObject(message)); jsonMessage = JsonConvert.SerializeObject(encryptedMessage); NM.SendMessage(jsonMessage); } } }