示例#1
0
        //Function that add or update device
        private void editDeviceClick(object sender, RoutedEventArgs e)
        {
            fileControl   file       = new fileControl();
            Regex         r          = new Regex("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$");
            appMessageBox appMessage = new appMessageBox();

            nameTextBox.BorderBrush    = new SolidColorBrush(Colors.Transparent);
            addressTextBox.BorderBrush = new SolidColorBrush(Colors.Transparent);

            if (nameTextBox.Text == "")
            {
                nameTextBox.BorderBrush = new SolidColorBrush(Colors.Red);
            }
            else if (!r.IsMatch(addressTextBox.Text))
            {
                addressTextBox.BorderBrush = new SolidColorBrush(Colors.Red);
            }
            else
            {
                if (editDeviceButton.Content.ToString() == "Add")
                {
                    file.addAddress(new Device()
                    {
                        ID = file.getAllAddresses().Count, NAME = nameTextBox.Text, ADDRESS = addressTextBox.Text
                    });
                }
                else
                {
                    Device updateDevice = (Device)main.deviceList.SelectedItem;
                    file.updateAddress(new Device()
                    {
                        ID = updateDevice.ID, NAME = nameTextBox.Text, ADDRESS = addressTextBox.Text
                    });
                }
                this.main.dataRefresh();

                this.Close();
            }
        }
示例#2
0
 //Function that refresh listBox data
 public void dataRefresh()
 {
     this.deviceList.ItemsSource = null;
     this.deviceList.ItemsSource = file.getAllAddresses();
 }