private void btn_addAmpel_Click(object sender, EventArgs e) { if (this.tb_ampelIP.Text != "") { try { IPAddress iPAddress; if (!IPAddress.TryParse(this.tb_ampelIP.Text, out iPAddress)) { IPHostEntry hostEntry = Dns.GetHostEntry(this.tb_ampelIP.Text); int num = 0; while (hostEntry.AddressList[num].ToString().Contains(":")) { num++; } bool flag = IPAddress.TryParse(hostEntry.AddressList[num].ToString(), out iPAddress); } CAmpelButton cAmpelButton = new CAmpelButton(iPAddress); cAmpelButton.Click += new EventHandler(this.ampel_Click); WebRequest webRequest = WebRequest.Create("http://" + iPAddress.ToString() + "/ampel.php"); webRequest.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); string a = streamReader.ReadToEnd(); streamReader.Close(); responseStream.Close(); httpWebResponse.Close(); if (a != "Ampel") { throw new Exception("Keine API gefunden"); } bool flag2 = false; foreach (Control control in this.flp_ampeln.Controls) { CAmpelButton cAmpelButton2 = (CAmpelButton)control; if (cAmpelButton2.Address.ToString().Equals(cAmpelButton.Address.ToString())) { flag2 = true; } } if (flag2) { throw new Exception("Ampel Existiert bereits"); } this.flp_ampeln.Controls.Add(cAmpelButton); MessageBox.Show("Ampel wurde hinzugefügt", "Ampel hinzugefügt", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_ampelIP.Text = ""; } catch (Exception ex) { MessageBox.Show("Es konnte keine Ampel hinzugefügt werden." + Environment.NewLine + "Grund: " + ex.Message, "Keine Ampel", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } }
private void tim_update_Tick(object sender, EventArgs e) { foreach (Control control in this.flp_ampeln.Controls) { CAmpelButton cAmpelButton = (CAmpelButton)control; cAmpelButton.Click -= new EventHandler(this.ampel_Click); cAmpelButton.Click += new EventHandler(this.ampel_Click); cAmpelButton.UpdateAmpel(this.red, this.yellow, this.green, this.horn, this.data, this.timeStr, this.abcd, this.b_time, this.b_abcd, 1); } if (this.red) { this.pb_red.BackColor = Color.Red; } else { this.pb_red.BackColor = Color.Transparent; } if (this.green) { this.pb_green.BackColor = Color.Chartreuse; } else { this.pb_green.BackColor = Color.Transparent; } if (this.yellow) { this.pb_yellow.BackColor = Color.Yellow; } else { this.pb_yellow.BackColor = Color.Transparent; } if (this.cb_string.Checked) { this.lbl_string.Text = this.data; } else { this.lbl_string.Text = this.abcd + " " + this.timeStr; } }