protected void ShowInTextBoxes( Student student ) { regNoTextBox.Text = student.StudentRegNo; regNoTextBox.Enabled = false; nameTextBox.Text = student.StudentName; addressTextBox.Text = student.Address; phoneNoTextBox.Text = student.Phone; }
protected void saveButton_Click( object sender, EventArgs e ) { string studentName = nameTextBox.Text; string studentRegNo = regNoTextBox.Text; string studentPhone = phoneNoTextBox.Text; string studentAddress = addressTextBox.Text; string saveMessage; if(saveButton.Text == "Save") { Student student = new Student(studentName, studentRegNo, studentPhone, studentAddress); saveMessage = objStudentManager.SaveStudentInfo(student); messageLabel.Text = saveMessage; } else if(saveButton.Text == "Update") { int idToChange = Convert.ToInt32(this.idToChange.Value); Student student = new Student(idToChange, studentName, studentRegNo, studentPhone, studentAddress); saveMessage = objStudentManager.UpdateStudent(student); messageLabel.Text = saveMessage; saveButton.Text = "Save"; } else if(saveButton.Text == "Delete") { int idToChange = Convert.ToInt32(this.idToChange.Value); Student student = new Student(idToChange, studentName, studentRegNo, studentPhone, studentAddress); saveMessage = objStudentManager.DeleteStudentRecord(student); messageLabel.Text = saveMessage; saveButton.Text = "Save"; } //Just to show the gridview Data ShowAllStudents(); }
public string DeleteStudentRecord(Student objStudent) { int affectedRowAfterDelete = objStudentGateway.DeleteStudent(objStudent); if (affectedRowAfterDelete > 0) { return "Student Record Deleted"; } return "Delete Failed!"; }
public string UpdateStudent( Student objStudent ) { if(!(CheckStudentByRegNo(objStudent.StudentRegNo))) { return "Student record doesn't exist!"; } int affectedRowAfterUpdate = objStudentGateway.UpdateStudent(objStudent); if(affectedRowAfterUpdate > 0) { return "Update Successfull"; } return "Update Failed"; }
public int InsertStudentInfo( Student objStudent ) { SqlConnection connection = new SqlConnection(_connectionString); string insertQuery = @"INSERT INTO Students VALUES ('" + objStudent.StudentRegNo + "', '" + objStudent.StudentName + "', '" + objStudent.Address + "', '" + objStudent.Phone + "' )"; connection.Open(); SqlCommand insertCommand = new SqlCommand(insertQuery, connection); int affectedRow = insertCommand.ExecuteNonQuery(); connection.Close(); return affectedRow; }
public string SaveStudentInfo( Student objStudent ) { string message = null; bool isStudentExists = CheckStudentByRegNo(objStudent.StudentRegNo); if(isStudentExists) { message = "Student Already Exists"; return message; } int affectedRow = objStudentGateway.InsertStudentInfo(objStudent); if(affectedRow > 0) { message = "Student Info Saved Successfully"; } return message; }
public List<Student> GetAllStudent() { SqlConnection connection = new SqlConnection(_connectionString); string selectAllQuery = "SELECT * FROM Students"; SqlCommand selectCommand = new SqlCommand(selectAllQuery, connection); connection.Open(); SqlDataReader objReader = selectCommand.ExecuteReader(); List<Student> listOfStudents = new List<Student>(); while(objReader.Read()) { Student objStudent = new Student(); objStudent.Id = Convert.ToInt32(objReader["Id"]); objStudent.StudentName = Convert.ToString(objReader["Name"]); objStudent.StudentRegNo = Convert.ToString(objReader["RegNo"]); objStudent.Address = Convert.ToString(objReader["Address"]); objStudent.Phone = Convert.ToString(objReader["Phone"]); listOfStudents.Add(objStudent); } objReader.Close(); connection.Close(); return listOfStudents; }
public Student GetStudentById(int studentId) { SqlConnection connection = new SqlConnection(_connectionString); string getQuery = "SELECT * FROM Students WHERE Id="+studentId; connection.Open(); SqlCommand getCommand = new SqlCommand(getQuery,connection); SqlDataReader objReader = getCommand.ExecuteReader(); if (objReader.Read()) { Student objStudent=new Student(); objStudent.StudentName = Convert.ToString(objReader["Name"]); objStudent.StudentRegNo = Convert.ToString(objReader["RegNo"]); objStudent.Address = Convert.ToString(objReader["Address"]); objStudent.Phone = Convert.ToString(objReader["Phone"]); objStudent.Id = Convert.ToInt32(objReader["Id"]); connection.Close(); return objStudent; } objReader.Close(); connection.Close(); return null; }
public int DeleteStudent(Student objStudent) { SqlConnection connection = new SqlConnection(_connectionString); string deleteQuery = "DELETE FROM Students WHERE Id="+objStudent.Id; SqlCommand deleteCommand = new SqlCommand(deleteQuery,connection); connection.Open(); int affectedRowAfterDelete = deleteCommand.ExecuteNonQuery(); return affectedRowAfterDelete; }
public int UpdateStudent( Student objStudent ) { SqlConnection connection = new SqlConnection(_connectionString); string updateQuery = "UPDATE Students SET Name='" + objStudent.StudentName + "', Address='" + objStudent.Address + " ', Phone='" + objStudent.Phone + "' WHERE Id="+objStudent.Id; SqlCommand updateCommand = new SqlCommand(updateQuery, connection); connection.Open(); int affectedRowAfterUpdate = updateCommand.ExecuteNonQuery(); return affectedRowAfterUpdate; }