private void btnAdd_Click(object sender, EventArgs e) { if (this.txtStudentId.Text != "") { int id = Convert.ToInt32(this.txtStudentId.Text); string fname = txtFirstName.Text; string lname = txtLastName.Text; DateTime bdt = dateBirthDay.Value; string phone = txtPhone.Text; string adr = txtAddress.Text; string gender = "Male"; if (radioFemale.Checked == true) { gender = "Female"; } MemoryStream pic = new MemoryStream(); pictureStudent.Image.Save(pic, pictureStudent.Image.RawFormat); DTO_Student student = new DTO_Student(id, lname, fname, bdt, phone, adr, gender, pic); if (BUSstudent.verifyStudent(student) == true && student.verif() == true) { if (BUSstudent.insertStudent(student) == true) { MessageBox.Show("New Student Added", "Add Student", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Add Error", "Add Student", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public bool updateStudent(DTO_Student student) { try { SqlCommand command = new SqlCommand("UPDATE std SET fname=@fn, lname=@ln, bdate=@bdt, gender=@gdr, phone=@phn, address=@adr, picture=@pic WHERE id =@id", this.getConnection); command.Parameters.Add("@id", SqlDbType.Int).Value = student.id; command.Parameters.Add("@fn", SqlDbType.VarChar).Value = student.fname; command.Parameters.Add("@ln", SqlDbType.VarChar).Value = student.lname; command.Parameters.Add("@gdr", SqlDbType.VarChar).Value = student.gender; command.Parameters.Add("@bdt", SqlDbType.DateTime).Value = student.birthdate; command.Parameters.Add("@phn", SqlDbType.VarChar).Value = student.phone; command.Parameters.Add("@adr", SqlDbType.VarChar).Value = student.address; command.Parameters.Add("@pic", SqlDbType.Image).Value = student.picture.ToArray(); this.openConnection(); if (command.ExecuteNonQuery() == 1) { this.closeConnection(); return(true); } else { this.closeConnection(); return(false); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
private void btnEdit_Click(object sender, EventArgs e) { try { int id = Convert.ToInt32(this.txtID.Text); string fname = this.txtFirstName.Text; string lname = txtLastName.Text; DateTime bdt = (DateTime)this.dateBirthDay.Value; string phone = this.txtPhone.Text; string adr = this.txtAddress.Text; string gender = "Male"; if (this.radioFemale.Checked == true) { gender = "Female"; } MemoryStream pic = new MemoryStream(); this.pictureStudent.Image.Save(pic, pictureStudent.Image.RawFormat); DTO_Student student = new DTO_Student(id, lname, fname, bdt, phone, adr, gender, pic); if (student.verif()) { if (BUSstudent.updateStudent(student) == true) { MessageBox.Show("Student Updated", "Update Student", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Update Error", "Update Student", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { MessageBox.Show("Please enter a valid ID", "Student Edit", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool insertStudent(DTO_Student student) { try { SqlCommand command = new SqlCommand("INSERT INTO std (id, fname, lname, bdate, gender, phone, address, picture)" + "VALUES (@id, @fn, @ln, @bdt, @gdr, @phn, @adr, @pic)", this.getConnection); command.Parameters.Add("@id", SqlDbType.Int).Value = student.id; command.Parameters.Add("@fn", SqlDbType.VarChar).Value = student.fname; command.Parameters.Add("@ln", SqlDbType.VarChar).Value = student.lname; command.Parameters.Add("@bdt", SqlDbType.DateTime).Value = student.birthdate; command.Parameters.Add("@gdr", SqlDbType.VarChar).Value = student.gender; command.Parameters.Add("@phn", SqlDbType.VarChar).Value = student.phone; command.Parameters.Add("@adr", SqlDbType.VarChar).Value = student.address; command.Parameters.Add("@pic", SqlDbType.Image).Value = student.picture.ToArray(); this.openConnection(); if (command.ExecuteNonQuery() == 1) { this.closeConnection(); return(true); } else { this.closeConnection(); return(false); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public bool verifyStudent(DTO_Student student) { SqlDataAdapter adapter = new SqlDataAdapter(); DataTable table = new DataTable(); SqlCommand cmd = new SqlCommand("SELECT * FROM std WHERE id = @id", this.getConnection); cmd.Parameters.Add("@id", SqlDbType.Int).Value = student.id; adapter.SelectCommand = cmd; adapter.Fill(table); if (table.Rows.Count > 0) { MessageBox.Show("ID is exsited", "Add Student", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { return(true); } }
public bool updateStudent(DTO_Student student) { return(DALstudent.updateStudent(student)); }
public bool verifyStudent(DTO_Student student) { return(DALstudent.verifyStudent(student)); }
public bool insertStudent(DTO_Student student) { return(DALstudent.insertStudent(student)); }