//When a new entry is selected in the combobox. private void comboBox_ListOfDomains_SelectedIndexChanged(object sender, EventArgs e) { //depending on what is in the combobox, program tells what the UI should be. if (comboBox_ListOfDomains.Text == "(Create a new domain)") { label_EnterAName.Visible = true; textBox_EnterAName.Visible = true; button_RemoveSelectedDomain.Visible = false; button_SaveChangesToDomain.Text = "Save New Domain"; ClearAll(); } else { label_EnterAName.Visible = false; textBox_EnterAName.Visible = false; button_RemoveSelectedDomain.Visible = true; button_SaveChangesToDomain.Text = "Save Changes to Current Domain"; //I did it this way to avoid keeping track of a global indexer variable. Combobox index will always be the same as the generic list's. textBox_EnterAName.Text = ReadConfig.ReadDomainSetting()[comboBox_ListOfDomains.SelectedIndex - 1].UserAssignedName; textBox_Username.Text = ReadConfig.ReadDomainSetting()[comboBox_ListOfDomains.SelectedIndex - 1].Username; textBox_Password.Text = ReadConfig.ReadDomainSetting()[comboBox_ListOfDomains.SelectedIndex - 1].Password; textBox_Domain.Text = ReadConfig.ReadDomainSetting()[comboBox_ListOfDomains.SelectedIndex - 1].Domain; if (ReadConfig.ReadDomainSetting()[comboBox_ListOfDomains.SelectedIndex - 1].Enabled == "1") { checkBox1.Checked = true; } else { checkBox1.Checked = false; } } }
//PROGRAMMER METHODS //------------------------------------------------------------------------------------------------------------------- /// <summary> /// Clears and adds new data into the list of domains combobox. /// </summary> private void ComboBoxRefresh() { comboBox_ListOfDomains.Items.Clear(); //Clear combox completely. comboBox_ListOfDomains.Items.Add("(Create a new domain)"); //Add back the default value at position 0; //Loop through list and at all entries available to the combobox. for (int i = 0; i < ReadConfig.ReadDomainSetting().Count; i++) { comboBox_ListOfDomains.Items.Add(ReadConfig.ReadDomainSetting()[i].UserAssignedName); } }
/// <summary> /// Method for testing whether the IP resolve worked or not. /// </summary> /// <param name="forceRefresh"></param> private void TestIp(bool forceRefresh = false) { ListBoxRefresh(); string ip = Get_Client_IP(); //grabs user's current ip. if ((ip != label_UserIP.Text) || (forceRefresh == true)) //should be good now. If there are issues, it is here! { label_UserIP.Text = ip; //whatever the user's ip is now shows in label. for (int i = 0; i < listBox_ListOfUsersDomains.Items.Count; i++) //Loop though listbox console. { if (ReadConfig.ReadDomainSetting()[i].Enabled == "1") //Only submit domain if it is enabled. { label_UpdateResponse.Text = Update_GoogleDDNS(ReadConfig.ReadDomainSetting()[i].Username, ReadConfig.ReadDomainSetting()[i].Password, ReadConfig.ReadDomainSetting()[i].Domain, ip); //Submit domain info. listBox_ListOfUsersDomains.Items[i] = listBox_ListOfUsersDomains.Items[i].ToString() + " --> Last Check: " + label_UpdateResponse.Text; //Display info for each domain in the listbox console. //backgroundWorker1.ReportProgress(i); } } this.label_UpdateResponse.Text = "All Succeeded."; //default if there are no issues with any domains. STATUS BAR TEXT. label_UpdateResponse.BackColor = System.Drawing.Color.MediumSpringGreen; //default if there are no issues with any domains. STATUS BAR COLOR. this.Icon = Resources.iconGreenNew; //default if there are no issues with any domains. FORM ICON COLOR. mynotifyicon.Icon = Resources.iconGreenNew; //default if there are no issues with any domains. SYSTEM TRAY ICON COLOR. for (int i = 0; i < listBox_ListOfUsersDomains.Items.Count; i++) //Loop through each item in listbox. { if ((listBox_ListOfUsersDomains.Items[i].ToString().Contains("nochg")) || (listBox_ListOfUsersDomains.Items[i].ToString().Contains("good"))) //If the entries ! contain the succeed codes. { //Do nothing for now. } else { label_UpdateResponse.Text = "At least one update failed. Check the console."; //Show that there was an error label_UpdateResponse.BackColor = System.Drawing.Color.Red; mynotifyicon.Icon = Resources.iconRedNew; mynotifyicon.Text = "Update Failed - Flatline DDNS"; this.Icon = Resources.iconRedNew; break; //Exit loop. } } label_LastDNSSync.Text = DateTime.Now.ToString(); //update the last sync time. } label_LastIPCheck.Text = DateTime.Now.ToString(); //update the last ip check time. }
//PROGRAMMER METHODS //------------------------------------------------------------------------------------------------------------------- /// <summary> /// Method for refreshing the listbox of current domains. Does not run a DDNS update. /// </summary> private void ListBoxRefresh() { //Clear out any prior data from the listbox. listBox_ListOfUsersDomains.Items.Clear(); //Loop through all domain settings within the configfile.xml. for (int i = 0; i < ReadConfig.ReadDomainSetting().Count; i++) { //If the setting is enabled, display it as such --- and vice versa. if (ReadConfig.ReadDomainSetting()[i].Enabled == "1") { listBox_ListOfUsersDomains.Items.Add(" (On*) " + ReadConfig.ReadDomainSetting()[i].UserAssignedName); } else { listBox_ListOfUsersDomains.Items.Add(" (Off) " + ReadConfig.ReadDomainSetting()[i].UserAssignedName); } } }