//delete admin public void DeleteAdmin(AdminDB objt) { DBConnection mycon = new DBConnection(); String SQL = "delete from Administrator where AdminID='" + objt.NICNumber + "'"; mycon.addvalues(SQL); }
//update Admin details public void enterupdaeAdmin(AdminDB obj) { String SQL = "update Administrator set FristName='" + obj.FristName + "',LastName='" + obj.LastName + "',Email='" + obj.Email + "',UserPassword='******',gender='" + obj.Gender + "',Adress ='" + obj.Address + "',Phone_Number='" + obj.Phonenumber + "'where AdminID='" + obj.NICNumber + "'"; DBConnection mycon = new DBConnection(); mycon.addvalues(SQL); }
private void buttonDelete_Click(object sender, EventArgs e) {// delete button try { AdminDB objt = new AdminDB(); String NicNumber; NicNumber = dataGridViewUpdateAdmin.SelectedCells[0].Value.ToString(); objt.NICNumber1 = NicNumber; objt.DeleteAdmin(objt); } catch (Exception ex) { MessageBox.Show(ex.Message); } // refersh table try { AdminDB obcj = new AdminDB(); SqlDataReader DR = obcj.getAdminInfo(); DataTable dt = new DataTable(); dt.Columns.Add("AdminID"); dt.Columns.Add("FristName"); dt.Columns.Add("LastName"); dt.Columns.Add("Email"); dt.Columns.Add("UserPassword"); dt.Columns.Add("gender"); dt.Columns.Add("Adress"); dt.Columns.Add("Phone_Number"); dt.Columns.Add("Registerdate"); while (DR.Read()) { DataRow row = dt.NewRow(); row["AdminID"] = DR["AdminID"]; row["FristName"] = DR["FristName"]; row["LastName"] = DR["LastName"]; row["Email"] = DR["Email"]; row["UserPassword"] = DR["UserPassword"]; row["gender"] = DR["gender"]; row["Adress"] = DR["Adress"]; row["Phone_Number"] = DR["Phone_Number"]; row["Registerdate"] = DR["Registerdate"]; dt.Rows.Add(row); } dataGridViewUpdateAdmin.DataSource = dt; } catch (Exception ex) { MessageBox.Show(ex.Message); } // clear text filed textBoxFristName.Text = ""; textBoxLastName.Text = ""; textBoxEmail.Text = ""; textBoxPassword.Text = ""; textBoxConfirmpassword.Text = ""; richTextBoxAdress.Text = ""; textBoxPhonenumber.Text = ""; }
//Adding admin details admin table public void addNewAdmin(AdminDB obj) { String SQL = "insert into Administrator values('" + obj.NICNumber + "','" + obj.FristName + "','" + obj.LastName + "','" + obj.Email + "','" + obj.password + "','" + obj.Gender + "','" + obj.Address + "','" + obj.Phonenumber + "','" + obj.regdate.ToString("yyyy-MM-dd") + "')"; DBConnection mycon = new DBConnection(); mycon.addvalues(SQL); }
private void dataGridViewUpdateAdmin_CellClick(object sender, DataGridViewCellEventArgs e) { //setting table value textfileds try { String NICNO; NICNO = dataGridViewUpdateAdmin.SelectedCells[0].Value.ToString(); AdminDB obj = new AdminDB(); SqlDataReader DR = obj.getupdateAdminInfo(NICNO); DataTable dt = new DataTable(); dt.Columns.Add("AdminID"); dt.Columns.Add("FristName"); dt.Columns.Add("LastName"); dt.Columns.Add("Email"); dt.Columns.Add("UserPassword"); dt.Columns.Add("gender"); dt.Columns.Add("Adress"); dt.Columns.Add("Phone_Number"); // dt.Columns.Add("Registerdate"); //dt.Columns.Add("Registationfee"); while (DR.Read()) { DataRow row = dt.NewRow(); // row["MemberID"] = DR["MemberID"]; textBoxFristName.Text = DR["FristName"].ToString(); textBoxLastName.Text = DR["LastName"].ToString(); textBoxEmail.Text = DR["Email"].ToString(); textBoxPassword.Text = DR["UserPassword"].ToString(); textBoxConfirmpassword.Text = DR["UserPassword"].ToString(); comboBoxGender.Text = DR["gender"].ToString(); richTextBoxAdress.Text = DR["Adress"].ToString(); textBoxPhonenumber.Text = DR["Phone_Number"].ToString(); // textBoxRegistraionFee.Text = DR["Registationfee"].ToString(); dt.Rows.Add(row); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void UpdateAdmin_Load(object sender, EventArgs e) { //geting all admin details admin table try { AdminDB obj = new AdminDB(); SqlDataReader DR = obj.getAdminInfo(); DataTable dt = new DataTable(); dt.Columns.Add("AdminID"); dt.Columns.Add("FristName"); dt.Columns.Add("LastName"); dt.Columns.Add("Email"); dt.Columns.Add("UserPassword"); dt.Columns.Add("gender"); dt.Columns.Add("Adress"); dt.Columns.Add("Phone_Number"); dt.Columns.Add("Registerdate"); while (DR.Read()) { DataRow row = dt.NewRow(); row["AdminID"] = DR["AdminID"]; row["FristName"] = DR["FristName"]; row["LastName"] = DR["LastName"]; row["Email"] = DR["Email"]; row["UserPassword"] = DR["UserPassword"]; row["gender"] = DR["gender"]; row["Adress"] = DR["Adress"]; row["Phone_Number"] = DR["Phone_Number"]; row["Registerdate"] = DR["Registerdate"]; dt.Rows.Add(row); } dataGridViewUpdateAdmin.DataSource = dt; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void textBoxSearchMember_KeyUp(object sender, KeyEventArgs e) { try { AdminDB obj = new AdminDB(); SqlDataReader DR = obj.SearchAdmin(textBoxSearchMember.Text); DataTable dt = new DataTable(); dt.Columns.Add("AdminID"); dt.Columns.Add("FristName"); dt.Columns.Add("LastName"); dt.Columns.Add("Email"); dt.Columns.Add("UserPassword"); dt.Columns.Add("gender"); dt.Columns.Add("Adress"); dt.Columns.Add("Phone_Number"); dt.Columns.Add("Registerdate"); while (DR.Read()) { DataRow row = dt.NewRow(); row["AdminID"] = DR["AdminID"]; row["FristName"] = DR["FristName"]; row["LastName"] = DR["LastName"]; row["Email"] = DR["Email"]; row["UserPassword"] = DR["UserPassword"]; row["gender"] = DR["gender"]; row["Adress"] = DR["Adress"]; row["Phone_Number"] = DR["Phone_Number"]; row["Registerdate"] = DR["Registerdate"]; dt.Rows.Add(row); } dataGridViewUpdateAdmin.DataSource = dt; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ButtonSave_Click(object sender, EventArgs e) { if (textBoxNICNumber.Text == "") { MessageBox.Show("Insert NIC Number", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxFristName.Text == "") { MessageBox.Show("Insert Frist Name", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxLastName.Text == "") { MessageBox.Show("Insert Last Name", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxEmail.Text == "") { MessageBox.Show("Insert Email", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPassword.Text == "") { MessageBox.Show("Insert password", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxConfirmpassword.Text == "") { MessageBox.Show("Insert Confirm Password", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (richTextBoxAdress.Text == "") { MessageBox.Show("Insert Adress", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPhonenumber.Text == "") { MessageBox.Show("Insert PhoneNumber", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { AdminDB objt = new AdminDB(); //obj.NICNumber1 = textBoxNICNumber.Text; SqlDataReader DR = objt.SearchDuplicatevalues(textBoxNICNumber.Text); SqlCommand cmd = new SqlCommand(); int count = 0; while (DR.Read()) { count += 1; } if (count == 1) { MessageBox.Show("This ID is Alradey in the database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else {//inserting data AdminDB obj = new AdminDB(); obj.NICNumber1 = textBoxNICNumber.Text; obj.FristName1 = textBoxFristName.Text; obj.LastName1 = textBoxLastName.Text; obj.Email1 = textBoxEmail.Text; obj.Password = textBoxConfirmpassword.Text; obj.Gender1 = Gender; obj.Address1 = richTextBoxAdress.Text; obj.Phonenumber1 = Convert.ToInt32(textBoxPhonenumber.Text); obj.Regdate = DateTime.Now; obj.addNewAdmin(obj); } } catch (Exception ex) { MessageBox.Show(ex.Message); } // sending user password via gmail try { SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("*****@*****.**", "ishpvi928280"); MailMessage mail = new MailMessage("*****@*****.**", textBoxEmail.Text, "You Register as admin !Your loinid is Your NIC Number and password given bellow ", textBoxConfirmpassword.Text); mail.Priority = MailPriority.High; smtp.Send(mail); MessageBox.Show("Mail Send"); } catch (Exception ex) { MessageBox.Show(ex.Message); } // clear text fileds textBoxNICNumber.Text = ""; textBoxFristName.Text = ""; textBoxLastName.Text = ""; textBoxEmail.Text = ""; textBoxPassword.Text = ""; textBoxConfirmpassword.Text = ""; richTextBoxAdress.Text = ""; textBoxPhonenumber.Text = ""; //textBoxRegistraionFee.Text = ""; } }
private void ButtonUpdate_Click(object sender, EventArgs e) {//Update button coding if (textBoxFristName.Text == "") { MessageBox.Show("Frist Name cant be Empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxLastName.Text == "") { MessageBox.Show("Last Name cant be Empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxEmail.Text == "") { MessageBox.Show("Email year cant be Empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPassword.Text == "") { MessageBox.Show("Password cant be Empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxConfirmpassword.Text == "") { MessageBox.Show("Confirm Password cant be Empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (richTextBoxAdress.Text == "") { MessageBox.Show("Adress cant be Empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPhonenumber.Text == "") { MessageBox.Show("Phone number cant be Empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //updatecoding AdminDB obj = new AdminDB(); String NICNO; NICNO = dataGridViewUpdateAdmin.SelectedCells[0].Value.ToString(); obj.NICNumber1 = NICNO; obj.FristName1 = textBoxFristName.Text; obj.LastName1 = textBoxLastName.Text; obj.Email1 = textBoxEmail.Text; obj.Password = textBoxPassword.Text; obj.Gender1 = comboBoxGender.Text; obj.Address1 = richTextBoxAdress.Text; obj.Phonenumber1 = Convert.ToInt32(textBoxPhonenumber.Text); obj.enterupdaeAdmin(obj); // refersh table try { AdminDB obcj = new AdminDB(); SqlDataReader DR = obcj.getAdminInfo(); DataTable dt = new DataTable(); dt.Columns.Add("AdminID"); dt.Columns.Add("FristName"); dt.Columns.Add("LastName"); dt.Columns.Add("Email"); dt.Columns.Add("UserPassword"); dt.Columns.Add("gender"); dt.Columns.Add("Adress"); dt.Columns.Add("Phone_Number"); dt.Columns.Add("Registerdate"); while (DR.Read()) { DataRow row = dt.NewRow(); row["AdminID"] = DR["AdminID"]; row["FristName"] = DR["FristName"]; row["LastName"] = DR["LastName"]; row["Email"] = DR["Email"]; row["UserPassword"] = DR["UserPassword"]; row["gender"] = DR["gender"]; row["Adress"] = DR["Adress"]; row["Phone_Number"] = DR["Phone_Number"]; row["Registerdate"] = DR["Registerdate"]; dt.Rows.Add(row); } dataGridViewUpdateAdmin.DataSource = dt; } catch (Exception ex) { MessageBox.Show(ex.Message); } // send email try { SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("*****@*****.**", "ishpvi928280"); MailMessage mail = new MailMessage("*****@*****.**", textBoxEmail.Text, "Your detalis has been updated get mor info please contact administor!!Your loinid is Your NIC Number and password given bellow ", textBoxConfirmpassword.Text); mail.Priority = MailPriority.High; smtp.Send(mail); MessageBox.Show("Mail Send"); } catch (Exception ex) { MessageBox.Show(ex.Message); } // clear text filed textBoxFristName.Text = ""; textBoxLastName.Text = ""; textBoxEmail.Text = ""; textBoxPassword.Text = ""; textBoxConfirmpassword.Text = ""; richTextBoxAdress.Text = ""; textBoxPhonenumber.Text = ""; } }