private void ClearTextBoxes() { Array.ForEach(Controls.OfType <TextBox>().ToArray(), box => box.Clear()); }
private async void button1_Click(object sender, EventArgs e) { var checkedButton = Controls.OfType <RadioButton>() .FirstOrDefault(r => r.Checked); string command = checkedButton.Text; if (command.Equals("Add")) { SendMessageFromSocket("SAVE"); Computer computer = new Computer(); computer.Id = textBox3.Text; computer.Price = textBox1.Text; computer.Brand = textBox2.Text; var serializedComp = computer.SerializeToString(); SendAndGetMessageFromSocket(serializedComp); } if (command.Equals("Edit")) { SendMessageFromSocket("EDIT"); Computer computer = new Computer(); computer.Id = textBox3.Text; computer.Price = textBox1.Text; computer.Brand = textBox2.Text; var serializedComp = computer.SerializeToString(); SendAndGetMessageFromSocket(serializedComp); } if (command.Equals("Delete")) { SendMessageFromSocket("DELETE"); Computer computer = new Computer(); computer.Id = textBox3.Text; computer.Price = textBox1.Text; computer.Brand = textBox2.Text; var serializedComp = computer.SerializeToString(); SendAndGetMessageFromSocket(serializedComp); } if (command.Equals("Find by brand")) { if (textBox2.Text.Equals("")) { SendAndGetMessageFromSocket("GET_ALL"); } else { SendMessageFromSocket("FIND"); Computer computer = new Computer(); computer.Id = ""; computer.Price = ""; computer.Brand = textBox2.Text; var serializedComp = computer.SerializeToString(); SendAndGetMessageFromSocket(serializedComp); } } textBox.Text += "\r\ndata has sent to the server"; }