private void btnDelete_Click(object sender, EventArgs e) { SqlConnection conn; conn = DB.getinstance(); conn.Open(); ClsDonor D = new ClsDonor(); D.Delete = Convert.ToInt32(txtDelete.Text); try { D.delete(); MessageBox.Show("Donor deleted succesffully."); dataGridView1.DataSource = null; dataGridView2.DataSource = new ClsDonor.DonorDAL().GetAllDonor(); dataGridView2.Enabled = true; } catch (Exception) { MessageBox.Show("Donor Can't be deleted."); } txtDelete.Text = ""; }
private void btnInsert_Click(object sender, EventArgs e) { SqlConnection conn; conn = DB.getinstance(); conn.Open(); ClsDonor D = new ClsDonor(); D.Donor_Name = txtDonorName.Text; D.Donor_Age = Convert.ToInt32(txtDonorAge.Text); D.Donor_BloodGroup = txtBloodGroup.Text; if (rdbMale.Checked == true) { D.Donor_Gender = rdbMale.Text; } else if (rdbFemale.Checked == true) { D.Donor_Gender = rdbFemale.Text; } D.Donor_Phone = Convert.ToInt32(txtDonorContact.Text); D.Donor_Address = txtAddress.Text; D.Donor_Id = Convert.ToInt32(txtDonorId.Text); D.Branch_Id = Convert.ToInt32(txtBranch.Text); try { D.insert(); MessageBox.Show("Info inserted"); txtDonorId.Text = new ClsDonor.DonorDAL().GetDonorId(); txtDonorName.Text = ""; txtDonorAge.Text = ""; txtBloodGroup.Text = ""; txtBloodGroup.Text = ""; rdbMale.Checked = false; rdbFemale.Checked = false; txtDonorContact.Text = ""; txtAddress.Text = ""; txtBranch.Text = ""; dataGridView2.DataSource = new ClsDonor.DonorDAL().GetAllDonor(); dataGridView2.Enabled = true; } catch (Exception) { MessageBox.Show("Kindly check your data.."); } }
private void btnUpdate_Click(object sender, EventArgs e) { SqlConnection conn; conn = DB.getinstance(); conn.Open(); ClsDonor Donor = new ClsDonor(); Donor.Id = Convert.ToInt32(txtId.Text); Donor.Name = txtName.Text; Donor.Age = Convert.ToInt32(txtAge.Text); Donor.BloodGroup = bg.Text; if (btnMale.Checked == true) { Donor.Gender = btnMale.Text; } else if (btnFemale.Checked == true) { Donor.Gender = btnFemale.Text; } Donor.Phone = Convert.ToInt32(txtContact.Text); Donor.Address = txtDAddress.Text; try { Donor.update(); MessageBox.Show("Donor Updated."); dataGridView2.DataSource = new ClsDonor.DonorDAL().GetAllDonor(); dataGridView2.Enabled = true; } catch (Exception) { MessageBox.Show("Error"); } txtId.Text = ""; txtName.Text = ""; txtAge.Text = ""; bg.Text = ""; btnMale.Checked = false; btnFemale.Checked = false; txtContact.Text = ""; txtDAddress.Text = ""; }