/// <summary> /// Handles the Load event of the geraeteSuchen control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param> public void SearchForDevices_Load(object sender, RoutedEventArgs e) { DataGridDevices.ItemsSource = Config.GetInstance().Devices.DefaultView; if (DataGridDevices.Columns.Count >= 7) { DataGridDevices.Columns[6].Visibility = Visibility.Hidden; DataGridDevices.Columns[0].IsReadOnly = true; DataGridDevices.Columns[1].IsReadOnly = true; DataGridDevices.Columns[2].IsReadOnly = true; DataGridDevices.Columns[3].IsReadOnly = true; DataGridDevices.Columns[4].IsReadOnly = true; DataGridDevices.Columns[5].IsReadOnly = true; } var ip = ScanIp.GetIpMask(); var ipaddr = ScanIp.FindIpRange(ScanIp.GetIpMask()); var start = ipaddr[0].GetAddressBytes(); var stop = ipaddr[1].GetAddressBytes(); TextBoxIpFirstSegmentOne.Text = Convert.ToString(start[0]); TextBoxIpFirstSegmentTwo.Text = Convert.ToString(start[1]); TextBoxIpFirstSegmentThree.Text = Convert.ToString(start[2]); TextBoxIpFirstSegmentFour.Text = Convert.ToString(start[3]); TextBoxIpSecondSegmentOne.Text = Convert.ToString(stop[0]); TextBoxIpSecondSegmentTwo.Text = Convert.ToString(stop[1]); TextBoxIpSecondSegmentThree.Text = Convert.ToString(stop[2]); TextBoxIpSecondSegmentFour.Text = Convert.ToString(stop[3]); }
/// <summary> /// Handles the Click event of the ButtonSaveEntry control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param> private void ButtonSaveEntry_Click(object sender, RoutedEventArgs e) { FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "EditDevices", "Button Save clicked"); var ipAddress = TextBoxIpSegmentOne.Text + "." + TextBoxIpSegmentTwo.Text + "." + TextBoxIpSegmentThree.Text + "." + TextBoxIpSegmentFour.Text; var active = "1"; try { if (ipAddress.Length == 3 && !selected) { var ipFromHostName = ScanIp.ResolveHostName(TextBoxHostName.Text); ipAddress = ipFromHostName.ToString(); } else { IPAddress.Parse(ipAddress); } if (CheckBoxActive.IsChecked != null && !(bool)CheckBoxActive.IsChecked) { active = "0"; } if (selected) { if (drv["IP"].ToString().CompareTo(ipAddress) == 0) { Config.GetInstance().NonQuery("update Devices set Active='" + active + "' where IP='" + ipAddress + "';"); LoadGridData(); lockElements(); } else { var thread = new Thread(UpdateDevicesViaThread); thread.Start(new object[] { ipAddress, active, drv["IP"].ToString() }); lockElements(); } } else { if (Config.GetInstance().Query( "Select * from Devices where ip='" + ipAddress + "'").Rows.Count > 0) { MessageBox.Show( "Diese IP wird derzeit schon verwendet\nZum Ändern wählen sie das gerät in der tabelle\nund tragen den neuen Wert ein"); } else { lockElements(); var thread = new Thread(InsertInDevicesViaThread); thread.Start(new object[] { ipAddress, active }); } } } catch (Exception ex) { FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "EditDevices", "Button Save Error: " + ex.Message); MessageBox.Show("Fehlerhafte Eingabe der IP", "IPEingabeError", MessageBoxButton.OK, MessageBoxImage.Error); } }