Ejemplo n.º 1
0
 protected void ShowInTextBoxes( Student student ) {
     regNoTextBox.Text = student.StudentRegNo;
     regNoTextBox.Enabled = false;
     nameTextBox.Text = student.StudentName;
     addressTextBox.Text = student.Address;
     phoneNoTextBox.Text = student.Phone;
 }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
 public string DeleteStudentRecord(Student objStudent) {
     int affectedRowAfterDelete = objStudentGateway.DeleteStudent(objStudent);
     if (affectedRowAfterDelete > 0) {
         return "Student Record Deleted";
     }
     return "Delete Failed!";
 }
Ejemplo n.º 4
0
 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";
 }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 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;
 }