예제 #1
0
        private void btnSearchTrainee_Click(object sender, EventArgs e)
        {
            BusinessLogic.TraineeManager        traineeManager = new BusinessLogic.TraineeManager();
            List <BusinessEntity.TraineeEntity> traineeEntities;

            traineeEntities = traineeManager.GetAll();
            if (cboSearchGender.Text != string.Empty && cboSearchGender.Text != "All")
            {
                traineeEntities = traineeEntities.Where(x => x.GenderEntity.Title == cboSearchGender.Text).ToList();
            }

            if (txtSearchFullname.Text != string.Empty)
            {
                traineeEntities = traineeEntities.Where(x => x.Fullname.ToLower().Contains(txtSearchFullname.Text.ToLower())).ToList();
            }

            listViewTrainee.Items.Clear();
            if (traineeEntities == null)
            {
                MessageBox.Show("Sorry database error occured, please try again.");
            }
            else
            {
                foreach (BusinessEntity.TraineeEntity traineeEntity in traineeEntities)
                {
                    ListViewItem item = new ListViewItem(traineeEntity.ID.ToString());
                    item.SubItems.Add(traineeEntity.Fullname);
                    item.SubItems.Add(traineeEntity.PhoneNumber);

                    listViewTrainee.Items.Add(item);
                }
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (listViewTrainee.SelectedItems.Count > 0)
            {
                try
                {
                    DialogResult result = MessageBox.Show("Are you sure you want to delete the selected record?", "Training Information Management System", MessageBoxButtons.YesNo);
                    if (result == DialogResult.OK)
                    {
                        int traineeID = int.Parse(listViewTrainee.SelectedItems[0].SubItems[0].Text);
                        BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
                        BusinessEntity.TraineeEntity oldTrainee     = traineeManager.GetSingle(traineeID);

                        traineeManager.Delete(oldTrainee);
                        MessageBox.Show("Trainee Information Deleted Successfully.");
                        LoadTrainees();
                    }
                }
                catch (Exception ex)
                {
                    //save to log table
                    MessageBox.Show("Delete Failed, Please try again.");
                }
            }
            else
            {
                MessageBox.Show("Please select trainee from the list first.");
            }
        }
        private void LoadTrainees()
        {
            BusinessLogic.TraineeManager        traineeManager  = new BusinessLogic.TraineeManager();
            List <BusinessEntity.TraineeEntity> traineeEntities = traineeManager.GetAll();

            listViewTrainee.Items.Clear();
            if (traineeEntities == null)
            {
                MessageBox.Show("Sorry database error occured, please try again.");
            }
            else
            {
                foreach (BusinessEntity.TraineeEntity traineeEntity in traineeEntities)
                {
                    ListViewItem item = new ListViewItem(traineeEntity.ID.ToString());
                    item.SubItems.Add(traineeEntity.Fullname);
                    item.SubItems.Add(traineeEntity.BirthDate.ToString());
                    item.SubItems.Add(traineeEntity.GenderEntity.Title);
                    item.SubItems.Add(traineeEntity.AcademicLevelEntity.Title);
                    item.SubItems.Add(traineeEntity.BranchEntity.Name);
                    item.SubItems.Add(traineeEntity.Address);
                    item.SubItems.Add(traineeEntity.PhoneNumber);

                    listViewTrainee.Items.Add(item);
                }
            }
        }
        public void UpdateTraineePhoto(int traineeID, string fileName)
        {
            Image img = Image.FromFile(fileName);

            byte[] buffer = this.ImageToByteArray(img);

            BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
            BusinessEntity.TraineeEntity trainee        = traineeManager.GetSingle(traineeID);
            trainee.Photo = buffer;
            traineeManager.Update(trainee);
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (listViewTrainee.SelectedItems.Count > 0)
            {
                try
                {
                    if (IsValid())
                    {
                        int traineeID = int.Parse(listViewTrainee.SelectedItems[0].SubItems[0].Text);
                        BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
                        BusinessEntity.TraineeEntity oldTrainee     = traineeManager.GetSingle(traineeID);

                        BusinessEntity.TraineeEntity newTrainee = new BusinessEntity.TraineeEntity();

                        newTrainee.ID                     = traineeID;
                        newTrainee.Fullname               = txtFullname.Text;
                        newTrainee.BirthDate              = dtpBirthDate.Value;
                        newTrainee.GenderEntity           = new BusinessEntity.GenderEntity();
                        newTrainee.GenderEntity.ID        = int.Parse(cboGender.SelectedValue.ToString());
                        newTrainee.AcademicLevelEntity    = new BusinessEntity.AcademicLevelEntity();
                        newTrainee.AcademicLevelEntity.ID = int.Parse(cboAcademicLevel.SelectedValue.ToString());
                        newTrainee.BranchEntity           = new BusinessEntity.BranchEntity();
                        newTrainee.BranchEntity.ID        = int.Parse(cboBranch.SelectedValue.ToString());
                        newTrainee.Address                = txtAddress.Text;
                        newTrainee.PhoneNumber            = txtPhoneNumber.Text;
                        newTrainee.CreatedBy              = oldTrainee.CreatedBy;
                        newTrainee.CreatedDate            = oldTrainee.CreatedDate;
                        newTrainee.UpdatedBy              = this.Tag.ToString();
                        newTrainee.UpdatedDate            = DateTime.Now;

                        traineeManager.Update(newTrainee);
                        if (txtPhotoLocation.Text != string.Empty)
                        {
                            UpdateTraineePhoto(newTrainee.ID, txtPhotoLocation.Text);
                        }

                        MessageBox.Show("Trainee Information Updated Successfully.");
                        LoadTrainees();
                    }
                }
                catch (Exception ex)
                {
                    //save to log table
                    MessageBox.Show("Update Failed, Please try again.");
                }
            }
            else
            {
                MessageBox.Show("Please select trainee from the list first.");
            }
        }
예제 #6
0
        private void listViewTrainee_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewTrainee.SelectedItems.Count > 0)
            {
                int traineeID = int.Parse(listViewTrainee.SelectedItems[0].SubItems[0].Text);

                BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
                BusinessEntity.TraineeEntity trainee        = traineeManager.GetSingle(traineeID);

                txtFullname.Text      = trainee.Fullname;
                dtpBirthDate.Text     = trainee.BirthDate.ToString();
                cboGender.Text        = trainee.GenderEntity.Title;
                cboAcademicLevel.Text = trainee.AcademicLevelEntity.Title;
                txtAddress.Text       = trainee.Address;
                txtPhoneNumber.Text   = trainee.PhoneNumber;

                this.pictureBoxPhoto.Image    = this.GetDataToImage(trainee.Photo);
                this.pictureBoxPhoto.SizeMode = PictureBoxSizeMode.Zoom;
            }
        }
예제 #7
0
        private void frmTraineeCourse_Load(object sender, EventArgs e)
        {
            this.Tag = "Bereket";

            LoadTraineeCourses();

            BusinessLogic.TraineeManager        traineeManager = new BusinessLogic.TraineeManager();
            List <BusinessEntity.TraineeEntity> trainees       = traineeManager.GetAll();

            cboTrainee.DataSource    = trainees;
            cboTrainee.ValueMember   = "ID";
            cboTrainee.DisplayMember = "Fullname";

            BusinessLogic.CourseManager        courseManager = new BusinessLogic.CourseManager();
            List <BusinessEntity.CourseEntity> courses       = courseManager.GetAll();

            cboCourse.DataSource    = courses;
            cboCourse.ValueMember   = "ID";
            cboCourse.DisplayMember = "Title";
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsValid())
                {
                    BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
                    BusinessEntity.TraineeEntity trainee        = new BusinessEntity.TraineeEntity();
                    trainee.Fullname               = txtFullname.Text;
                    trainee.BirthDate              = dtpBirthDate.Value;
                    trainee.GenderEntity           = new BusinessEntity.GenderEntity();
                    trainee.GenderEntity.ID        = int.Parse(cboGender.SelectedValue.ToString());
                    trainee.AcademicLevelEntity    = new BusinessEntity.AcademicLevelEntity();
                    trainee.AcademicLevelEntity.ID = int.Parse(cboAcademicLevel.SelectedValue.ToString());
                    trainee.BranchEntity           = new BusinessEntity.BranchEntity();
                    trainee.BranchEntity.ID        = int.Parse(cboBranch.SelectedValue.ToString());
                    trainee.Address     = txtAddress.Text;
                    trainee.PhoneNumber = txtPhoneNumber.Text;
                    trainee.CreatedBy   = this.Tag.ToString();
                    trainee.CreatedDate = DateTime.Now;

                    int traineeID = traineeManager.Save(trainee);
                    if (txtPhotoLocation.Text != string.Empty)
                    {
                        UpdateTraineePhoto(traineeID, txtPhotoLocation.Text);
                    }

                    MessageBox.Show("Trainee Information Saved Successfully.");
                    LoadTrainees();
                }
            }
            catch (Exception ex)
            {
                //save to log table
                MessageBox.Show("Save Failed, Please try again.");
            }
        }
예제 #9
0
        private void PopulateCombobox()
        {
            //populate gender
            BusinessLogic.GenderManager        genderManager = new BusinessLogic.GenderManager();
            List <BusinessEntity.GenderEntity> genders       = genderManager.GetAll();

            genders.Add(new BusinessEntity.GenderEntity()
            {
                ID = 0, Title = "All"
            });

            cboGender.DataSource    = genders.OrderBy(x => x.ID).ToList();
            cboGender.ValueMember   = "ID";
            cboGender.DisplayMember = "Title";

            //populate academic level
            BusinessLogic.AcademicLevelManager        academicLevelManager = new BusinessLogic.AcademicLevelManager();
            List <BusinessEntity.AcademicLevelEntity> academicLevels       = academicLevelManager.GetAll();

            academicLevels.Add(new BusinessEntity.AcademicLevelEntity()
            {
                ID = 0, Title = "All"
            });

            cboAcademicLevel.DataSource    = academicLevels.OrderBy(x => x.ID).ToList();
            cboAcademicLevel.ValueMember   = "ID";
            cboAcademicLevel.DisplayMember = "Title";

            //populate trainee
            BusinessLogic.TraineeManager        traineeManager = new BusinessLogic.TraineeManager();
            List <BusinessEntity.TraineeEntity> trainees       = traineeManager.GetAll();

            trainees.Add(new BusinessEntity.TraineeEntity()
            {
                ID = 0, Fullname = "All"
            });

            cboTrainee.DataSource    = trainees.OrderBy(x => x.ID).ToList();
            cboTrainee.ValueMember   = "ID";
            cboTrainee.DisplayMember = "Fullname";

            cboTraineePayment.DataSource    = trainees.OrderBy(x => x.ID).ToList();
            cboTraineePayment.ValueMember   = "ID";
            cboTraineePayment.DisplayMember = "Fullname";

            //populate course
            BusinessLogic.CourseManager        courseManager = new BusinessLogic.CourseManager();
            List <BusinessEntity.CourseEntity> courses       = courseManager.GetAll();

            courses.Add(new BusinessEntity.CourseEntity()
            {
                ID = 0, Title = "All"
            });

            cboCourse.DataSource    = courses.OrderBy(x => x.ID).ToList();
            cboCourse.ValueMember   = "ID";
            cboCourse.DisplayMember = "Title";

            cboCoursePayment.DataSource    = courses.OrderBy(x => x.ID).ToList();
            cboCoursePayment.ValueMember   = "ID";
            cboCoursePayment.DisplayMember = "Title";
        }