private void buttonSearch_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); int select = 0; if (radioButtonName.Checked) { select = 1; } else if (radioButtonPhone.Checked) { select = 2; } else if (radioButtonAge.Checked) { select = 3; } UsersEditing usersEditing = new UsersEditing(); List <User> foundKey = usersEditing.SearchUser(textBoxContent.Text, select); dataGridView1.ColumnCount = 3; dataGridView1.Columns[0].Name = "Name"; dataGridView1.Columns[1].Name = "Phone"; dataGridView1.Columns[2].Name = "Age"; dataGridView1.Columns[0].HeaderText = "NAME"; dataGridView1.Columns[1].HeaderText = "PHONE"; dataGridView1.Columns[2].HeaderText = "AGE"; foreach (User getUser in foundKey) { string[] data = { getUser.NAME, getUser.PHONE, getUser.AGE.ToString() }; dataGridView1.Rows.Add(data); } }
private void buttonAdd_Click(object sender, EventArgs e) { string getName = textBoxName.Text; string getphone = textBoxPhone.Text; string getage = textBoxAge.Text; try { int intage = int.Parse(getage); UsersEditing usersEditing = new UsersEditing(); bool status = usersEditing.AddUser(getName, getphone, intage); if (status) { MessageBox.Show("Add Complete"); textBoxName.Text = ""; textBoxPhone.Text = ""; textBoxAge.Text = ""; } else { MessageBox.Show("Already Exist"); textBoxPhone.Text = ""; } } catch (Exception ex) { MessageBox.Show("Invaild Age Value"); textBoxAge.Text = ""; } }
private void buttonDelete_Click(object sender, EventArgs e) { string getname = textBoxName.Text; string getphone = textBoxPhone.Text; UsersEditing usersEditing = new UsersEditing(); bool status = usersEditing.DelUser(getname, getphone); if (status) { MessageBox.Show("Delete Complete"); textBoxName.Text = ""; textBoxPhone.Text = ""; } else { MessageBox.Show("Delete Fail"); textBoxName.Text = ""; textBoxPhone.Text = ""; } }