Пример #1
0
        private void btnAddComputer_Click(object sender, RoutedEventArgs e)
        {
            var clientListString = "";

            clientListString += Convert.ToInt32(txRoomNr.Text) + " " + Convert.ToInt32(txtbNr.Text) + " " + txbName.Text +
                                " " +
                                "" + " " + txbMacAddress.Text + Environment.NewLine;
            var fileClients = new StreamWriter("clients.txt", true);

            fileClients.Write(clientListString);
            fileClients.Close();
            var lc = new LabClient(Convert.ToInt32(txRoomNr.Text), txbName.Text, Convert.ToInt32(txtbNr.Text),
                                   txbMacAddress.Text);

            Service.GetInstance().clientlist.Add(lc);

            MessageBox.Show(
                "The LabClient has been added, if its turn on it should appear on the list with a white background");
            Close();
        }
Пример #2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            LabClient lc = (LabClient)listBox.SelectedItem;

            if (lc != null)
            {
                string line;
                string text = File.ReadAllText("clients.txt");
                using (var file = File.Open("clients.txt", FileMode.Open, FileAccess.ReadWrite))
                {
                    var reader = new StreamReader(file);
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Contains(lc.ComputerName))
                        {
                            if (Regex.IsMatch(macAdresstxb.Text, "^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}|(?:[0-9a-fA-F]{2}-){5}[0-9a-fA-F]{2}|(?:[0-9a-fA-F]{2}){5}[0-9a-fA-F]{2}$"))
                            {
                                lc.ComputerName = computerNametxb.Text;
                                lc.Mac          = macAdresstxb.Text;
                                StringBuilder newFile = new StringBuilder();

                                string newline = lc.BoothName + " " + lc.BoothNo + " " + lc.ComputerName + " " + lc.Mac;
                                text = text.Replace(line, newline);

                                MessageBox.Show("The computer was replaced");
                            }
                            else
                            {
                                MessageBox.Show("Mac address is in a wrong format");
                            }
                        }
                    }
                }
                File.WriteAllText("clients.txt", text);
                listBox.ItemsSource = null;
                listBox.ItemsSource = service.GetLabComputersFromStorage();
            }
        }