private void addStudent_Click(object sender, EventArgs e)
        {
            try
            {

                String first_name  = this.textbox_firstname.Text;
                String last_name   = this.textbox_lastname.Text;
                String middle_name = this.textbox_middlename.Text;
                String student_no  = this.textbox_studentno.Text;
                String reg_no      = this.textbox_regno.Text;
                String course      = this.textbox_course.Text;
                String dob         = this.combobox_day.Text + "/" + this.combobox_month.Text + "/" +this.combobox_year.Text;
                String gender      = this.combobox_gender.Text;

                if (String.IsNullOrEmpty(first_name) || String.IsNullOrEmpty(last_name) || String.IsNullOrEmpty(student_no) || String.IsNullOrEmpty(reg_no) || String.IsNullOrEmpty(course)||photos.Count<MIN_PHOTOS_PER_STUDENT)
                {

                    label_status.Visible   = true;
                    label_status.Text      = "Please fill in all the fields and pick atleast 5 pictures of the student:"+photos.Count();
                    return;
                }

                Student student            = new Student(first_name, middle_name, last_name, student_no, reg_no, course, dob, gender, photos.ToArray());

                if (StudentsManager.Save(student))
                {
                    MessageBox.Show("Student Added Successfully");
                    this.Close();
                }
                else
                {
                    label_status.Visible   = true;
                    label_status.Text      ="Operation Not Successfully\n Please try again";
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        public static bool Update(Student student)
        {
            try
            {
                String update_sql              = "UPDATE " + TABLE_NAME + " SET FIRSTNAME=@firstname ,MIDDLENAME=@middlename,LASTNAME=@lastname ,STUDENT_NO=@student_no ,REG_NO=@reg_no ,DATE_OF_BIRTH=@dob ,COURSE=@course ,GENDER=@gender,PHOTOS_PATH=@path WHERE ID=@id";
                String path                    = "";

                //Sql command
                sql_command                    = new MySqlCommand();
                sql_command.Connection         = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText        = update_sql;

                sql_command.Parameters.AddWithValue("@id", student.id);
                sql_command.Parameters.AddWithValue("@firstname", student.firstName);
                sql_command.Parameters.AddWithValue("@middlename", student.middleName);
                sql_command.Parameters.AddWithValue("@lastname", student.lastName);
                sql_command.Parameters.AddWithValue("@student_no", student.studentNo);
                sql_command.Parameters.AddWithValue("@reg_no", student.regNo);
                sql_command.Parameters.AddWithValue("@dob", student.DOB);
                sql_command.Parameters.AddWithValue("@path", path);
                sql_command.Parameters.AddWithValue("@course", student.course);

                sql_command.Parameters.AddWithValue("@gender", student.gender);

                sql_command.Prepare();

                //execute command
                database.Update(sql_command);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                CloseDatabaseConnection();
            }
        }
Beispiel #3
0
        public static bool Save(Student student)
        {
            try
            {
                //insert sql
                String insert_sql              = "INSERT INTO " + TABLE_NAME + " (firstname,middlename,lastname,student_no,reg_no,course,date_of_birth,gender) VALUES(@firstname,@middlename,@lastname,@studentno,@regno,@course,@dob,@gender)";

                //Sql command
                sql_command                    = new MySqlCommand();
                sql_command.Connection         = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText        = insert_sql;

                sql_command.Parameters.AddWithValue("@firstname", student.firstName);
                sql_command.Parameters.AddWithValue("@middlename", student.middleName);
                sql_command.Parameters.AddWithValue("@lastname", student.lastName);
                sql_command.Parameters.AddWithValue("@studentno", student.studentNo);
                sql_command.Parameters.AddWithValue("@regno", student.regNo);
                sql_command.Parameters.AddWithValue("@course", student.course);
                sql_command.Parameters.AddWithValue("@dob", student.DOB);
                sql_command.Parameters.AddWithValue("@gender", student.gender);

                sql_command.Prepare();

                //insert into db
                database.Insert(sql_command);

                student.id                     = Convert.ToInt32(sql_command.LastInsertedId);

                //create students folder based on the students id
                string photo_path              = PATH_TO_IMAGES + student.id + @"\";

                //create folder for the perpetrator images
                FileManager.CreateFolderIfMissing(photo_path);

                //save each image
                for (int i                     = 0; i < student.photos.Length; i++)
                {
                    //save using the perps name plus a unique number
                    FileManager.SaveImage(photo_path + student.id + " " + i + ".png", student.photos[i]);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                CloseDatabaseConnection();
            }
        }
Beispiel #4
0
        public static Student GetStudent(int id)
        {
            List<Student> students             = new List<Student>();
            try
            {
                //select sql
                String select_sql              = "SELECT * FROM " + TABLE_NAME + " WHERE REG_NO=@id OR STUDENT_NO=@id OR ID=@id";

                //sql command
                sql_command                    = new MySqlCommand();
                sql_command.Connection         = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText        = select_sql;
                sql_command.Parameters.AddWithValue("@id", id);
                sql_command.Prepare();

                //get results in enum object
                data_reader                    = database.Select(sql_command);

                //loop thru em
                if (data_reader.Read())
                {
                    //create new student
                    int std_id                 = data_reader.GetInt32(ID);
                    String first_name          = data_reader.GetString(FIRST_NAME);
                    String last_name           = data_reader.GetString(LAST_NAME);
                    String middle_name         = data_reader.GetString(MIDDLE_NAME);
                    String student_number      = data_reader.GetString(STUDENT_NUMBER);
                    String reg_number          = data_reader.GetString(REGISTRATION_NUMBER);
                    String course              = data_reader.GetString(COURSE);
                    String dob                 = data_reader.GetString(D_O_B);
                    String gender              = data_reader.GetString(GENDER);
                    Image<Bgr, byte>[] photos = GetStudentPhotos(std_id);

                    Student student            = new Student(std_id, first_name, middle_name, last_name, student_number, reg_number, course, dob, gender, photos);

                    //add student to list
                    students.Add(student);
                }

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            finally
            {
                CloseDatabaseConnection();
            }

            //return array of results
            return students.ToArray()[0];
        }
 //constructor called when u want to display student details
 public StudentDetailsForm(Student student)
 {
     InitializeComponent();
     SetStudentDetails(student);
     DisableControls();
 }
 private void SetStudentDetails(Student student)
 {
     textbox_firstname.Text            = student.firstName;
     textbox_lastname.Text             = student.lastName;
     textbox_middlename.Text           = student.middleName;
     textbox_studentno.Text            = student.studentNo;
     textbox_regno.Text                = student.regNo;
     textbox_course.Text               = student.course;
     picturebox_studentPic.Image       = student.photos[0].ToBitmap();
     combobox_gender.SelectedIndex     = student.gender.Equals("Male") ? 0 : 1;
     label_status.Text                 = "Perpetrator has been identified as a student".ToUpper();
 }