private void BtnSubmit_Click(object sender, EventArgs e) { //Confirm password if (txtConfirm.Text == txtPass.Text) { using (DATABASE_KINGFOODEntities2 context = new DATABASE_KINGFOODEntities2()) { //Check has already this user in account if (context.Personal_Information.Any(o => o.name == txtName.Text)) { MessageBox.Show("Has already this user"); } else { DATABASE_KINGFOODEntities2 db = new DATABASE_KINGFOODEntities2(); // open connection to database Personal_Information kf = new Personal_Information(); // create a new student object kf.name = txtName.Text; kf.password = txtPass.Text; kf.birthday = Convert.ToDateTime(txtBirth.Text); kf.gender = selectedText; //Check user string pass = txtPass.Text; db.Personal_Information.Add(kf); db.SaveChanges(); this.Close(); // MessageBox.Show("Add user successfully!"); } } } else { MessageBox.Show("Wrong Pass"); } }
private void btnDelete_Click(object sender, EventArgs e) { if (lstUsers.SelectedRows.Count == 1) { var row = lstUsers.SelectedRows[0]; var cell = row.Cells["id"]; int id = (int)cell.Value; DATABASE_KINGFOODEntities2 db = new DATABASE_KINGFOODEntities2(); Personal_Information pi = db.Personal_Information.Single(st => st.id == id); db.Personal_Information.Remove(pi); db.SaveChanges(); this.LoadStudent(); } else { MessageBox.Show("You should select a student!"); } }