private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                RewardAndPunishments aRewardAndPunishments = new RewardAndPunishments();
                aRewardAndPunishments.ID = ID_Old;
                aRewardAndPunishments.IDSystemUser = Convert.ToInt16(lueIDSystemUser.EditValue);
                aRewardAndPunishments.NumberDecision = txtNumberDecision.Text;
                aRewardAndPunishments.Subject = txtSubject.Text;
                aRewardAndPunishments.DecisionLevel = txtDecisionLevel.Text;
                aRewardAndPunishments.Description = txtDescription.Text;
                aRewardAndPunishments.CreatedDate = Convert.ToDateTime(dtpCreatedDate.Text);
                aRewardAndPunishments.DecisionDate = Convert.ToDateTime(dtpDecisionDate.Text);
                aRewardAndPunishments.Type = int.Parse(cbbType.Text);
                aRewardAndPunishments.Status = int.Parse(cbbStatus.Text);
                aRewardAndPunishments.Disable = bool.Parse(cbbDisable.Text);
                aRewardAndPunishmentsBO.Update(aRewardAndPunishments);
                if (this.afrmLst_RewardAndPunishments_Old != null)
                {
                    this.afrmLst_RewardAndPunishments_Old.Reload();
                }

                MessageBox.Show("Sửa thành công !", "Success ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmUpd_RewardAndPunishments.btnEdit_Click\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
 //Author : LinhTing
 //Function : Insert RewardAndPunishments
 public int Insert(RewardAndPunishments aRewardAndPunishments)
 {
     try
     {
         aDatabaseDA.RewardAndPunishments.Add(aRewardAndPunishments);
         return aDatabaseDA.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("RewardAndPunishmentsBO.Insert :"+ ex.Message.ToString()));
     }
 }
        //Hiennv
        private void btnAddRewardAndPunishments_Click(object sender, EventArgs e)
        {
            try
            {
                List<RewardAndPunishments> aListTemps = aSystemUsersEN.aListRewardAndPunishments.Where(r => r.ID == RewardAndPunishmentsID).ToList();
                if (aListTemps.Count > 0)
                {
                    RewardAndPunishments aTemps = aSystemUsersEN.aListRewardAndPunishments.Where(r => r.ID == RewardAndPunishmentsID).ToList()[0];
                    aSystemUsersEN.aListRewardAndPunishments.Remove(aTemps);
                }

                RewardAndPunishments aRewardAndPunishments = new RewardAndPunishments();
                Count = Count + 1;

                aRewardAndPunishments.ID = Count;

                aRewardAndPunishments.Subject = String.IsNullOrEmpty(txtRewardAndPunishmentsSubject.Text) == true ? String.Empty : txtRewardAndPunishmentsSubject.Text;

                aRewardAndPunishments.Type = cboRewardAndPunishmentsType.EditValue == null ? 0 : cboRewardAndPunishmentsType.SelectedIndex + 1;

                if (dtpRewardAndPunishments_CreateDate.EditValue != null)
                {
                    aRewardAndPunishments.CreatedDate = dtpRewardAndPunishments_CreateDate.DateTime;
                }

                if (dtpRewardAndPunishments_DecisionDate.EditValue != null)
                {
                    aRewardAndPunishments.DecisionDate = dtpRewardAndPunishments_DecisionDate.DateTime;
                }

                aRewardAndPunishments.NumberDecision = String.IsNullOrEmpty(txtRewardAndPunishmentsNumberDecision.Text) == true ? String.Empty : txtRewardAndPunishmentsNumberDecision.Text;
                aRewardAndPunishments.DecisionLevel = String.IsNullOrEmpty(txtRewardAndPunishmentsDecisionLevel.Text) == true ? String.Empty : txtRewardAndPunishmentsDecisionLevel.Text;
                aRewardAndPunishments.Description = String.IsNullOrEmpty(txaRewardAndPunishmentsDesctiption.Text) == true ? String.Empty : txaRewardAndPunishmentsDesctiption.Text;

                aRewardAndPunishments.Status = cboRewardAndPunishmentsStatus.EditValue == null ? 0 : cboRewardAndPunishmentsStatus.SelectedIndex + 1;
                aRewardAndPunishments.Disable = cboRewardAndPunishmentsDisable.EditValue == null ? false : Convert.ToBoolean(cboRewardAndPunishmentsDisable.Text);

                aSystemUsersEN.aListRewardAndPunishments.Add(aRewardAndPunishments);

                dgvRewardAndPunishments.DataSource = aSystemUsersEN.aListRewardAndPunishments;
                dgvRewardAndPunishments.RefreshDataSource();

                txtRewardAndPunishmentsSubject.Text = "";
                txaRewardAndPunishmentsDesctiption.Text = "";
                dtpRewardAndPunishments_CreateDate.EditValue = null;
                dtpRewardAndPunishments_DecisionDate.EditValue = null;
                txtRewardAndPunishmentsNumberDecision.Text = "";
                txtRewardAndPunishmentsDecisionLevel.Text = "";
                cboRewardAndPunishmentsType.SelectedIndex = 0;
                cboRewardAndPunishmentsStatus.SelectedIndex = 0;
                cboRewardAndPunishmentsDisable.SelectedIndex = 0;
                cboRewardAndPunishmentsType.SelectedIndex = -1;

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_SystemUser_Infromation.btnAddRewardAndPunishments_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Author : Hiennv
        public void UpdateSystemUserInformation(SystemUsersEN aSystemUsersEN)
        {
            int status = -1;
            SystemUsersBO aSystemUsersBO = new SystemUsersBO();
            SystemUsers aSystemUsers_Old = new SystemUsers();
            SystemUsers aSystemUsers = new SystemUsers();

            SystemUserExtsBO aSystemUserExtsBO = new SystemUserExtsBO();
            //SystemUserExts aSystemUserExts = new SystemUserExts();
            SystemUserExts aSystemUserExts_Old = new SystemUserExts();
            try
            {

                aSystemUsers = aSystemUsersBO.Select_ByID(aSystemUsersEN.ID);
                aSystemUsers_Old = aSystemUsers;

                aSystemUsers.UserGroup = aSystemUsersEN.UserGroup;
                aSystemUsers.Email = aSystemUsersEN.Email;
                aSystemUsers.Username = aSystemUsersEN.Username;
                aSystemUsers.Name = aSystemUsersEN.Name;
                aSystemUsers.Password = aSystemUsersEN.Password;
                aSystemUsers.Birthday = aSystemUsersEN.Birthday;
                aSystemUsers.Identifier1 = aSystemUsersEN.Identifier1;
                aSystemUsers.Identifier2 = aSystemUsersEN.Identifier2;
                aSystemUsers.Identifier3 = aSystemUsersEN.Identifier3;
                aSystemUsers.Image = aSystemUsersEN.Image;
                aSystemUsers.Gender = aSystemUsersEN.Gender;
                aSystemUsers.IDRefAnotherSystem = aSystemUsersEN.IDRefAnotherSystem;
                aSystemUsers.IDRefMailSystem = aSystemUsersEN.IDRefMailSystem;
                aSystemUsers.Type = aSystemUsersEN.Type;
                aSystemUsers.Status = aSystemUsersEN.Status;
                aSystemUsers.Disable = aSystemUsersEN.Disable;
                aSystemUsers.Identifier1CreatedDate = aSystemUsersEN.Identifier1CreatedDate;
                aSystemUsers.Identifier2CreatedDate = aSystemUsersEN.Identifier2CreatedDate;
                aSystemUsers.Identifier3CreatedDate = aSystemUsersEN.Identifier3CreatedDate;
                aSystemUsers.PlaceOfIssue1 = aSystemUsersEN.PlaceOfIssue1;
                aSystemUsers.PlaceOfIssue2 = aSystemUsersEN.PlaceOfIssue2;
                aSystemUsers.PlaceOfIssue3 = aSystemUsersEN.PlaceOfIssue3;

                status = aSystemUsersBO.Update(aSystemUsers);

                if (status > 0)
                {

                    SystemUserExts aSystemUserExts = aSystemUserExtsBO.Select_ByID(aSystemUsersEN.aSystemUserExts.ID);
                    //aSystemUserExts_Old = aSystemUserExts;

                    if (aSystemUserExts != null)
                    {
                        aSystemUserExts.BirthPlace = aSystemUsersEN.aSystemUserExts.BirthPlace;
                        aSystemUserExts.Hometown = aSystemUsersEN.aSystemUserExts.Hometown;
                        aSystemUserExts.Address = aSystemUsersEN.aSystemUserExts.Address;
                        aSystemUserExts.InsuranceNumber = aSystemUsersEN.aSystemUserExts.InsuranceNumber;
                        aSystemUserExts.YearJob = aSystemUsersEN.aSystemUserExts.YearJob;
                        aSystemUserExts.YearDepartment = aSystemUsersEN.aSystemUserExts.YearDepartment;
                        aSystemUserExts.YearPayroll = aSystemUsersEN.aSystemUserExts.YearPayroll;
                        aSystemUserExts.YearUnemploymentInsurance = aSystemUsersEN.aSystemUserExts.YearUnemploymentInsurance;
                        aSystemUserExts.DifferenceContact = aSystemUsersEN.aSystemUserExts.DifferenceContact;
                        aSystemUserExts.Type = aSystemUsersEN.aSystemUserExts.Type;
                        aSystemUserExts.Status = aSystemUsersEN.aSystemUserExts.Status;
                        aSystemUserExts.Disable = aSystemUsersEN.aSystemUserExts.Disable;
                        aSystemUserExts.IDSystemUser = aSystemUsers.ID;
                        aSystemUserExts.Recruitment = aSystemUsersEN.aSystemUserExts.Recruitment;
                        aSystemUserExts.PermanentResidence = aSystemUsersEN.aSystemUserExts.PermanentResidence;
                        aSystemUserExts.CommunistPartyDate = aSystemUsersEN.aSystemUserExts.CommunistPartyDate;
                        aSystemUserExts.YouthUnionDate = aSystemUsersEN.aSystemUserExts.YouthUnionDate;
                        aSystemUserExts.EnlistmentDate = aSystemUsersEN.aSystemUserExts.EnlistmentDate;
                        aSystemUserExts.DemobilizedDate = aSystemUsersEN.aSystemUserExts.DemobilizedDate;
                        aSystemUserExts.MartyrsFamily = aSystemUsersEN.aSystemUserExts.MartyrsFamily;
                        aSystemUserExts.WoundedFamily = aSystemUsersEN.aSystemUserExts.WoundedFamily;
                        aSystemUserExts.LaborFamily = aSystemUsersEN.aSystemUserExts.LaborFamily;
                        aSystemUserExts.HightestAppellation = aSystemUsersEN.aSystemUserExts.HightestAppellation;
                        status = aSystemUserExtsBO.Update(aSystemUserExts);

                    }
                    else
                    {
                        aSystemUserExts = new SystemUserExts();
                        aSystemUserExts.BirthPlace = aSystemUsersEN.aSystemUserExts.BirthPlace;
                        aSystemUserExts.Hometown = aSystemUsersEN.aSystemUserExts.Hometown;
                        aSystemUserExts.Address = aSystemUsersEN.aSystemUserExts.Address;
                        aSystemUserExts.InsuranceNumber = aSystemUsersEN.aSystemUserExts.InsuranceNumber;
                        aSystemUserExts.YearJob = aSystemUsersEN.aSystemUserExts.YearJob;
                        aSystemUserExts.YearDepartment = aSystemUsersEN.aSystemUserExts.YearDepartment;
                        aSystemUserExts.YearPayroll = aSystemUsersEN.aSystemUserExts.YearPayroll;
                        aSystemUserExts.YearUnemploymentInsurance = aSystemUsersEN.aSystemUserExts.YearUnemploymentInsurance;
                        aSystemUserExts.DifferenceContact = aSystemUsersEN.aSystemUserExts.DifferenceContact;
                        aSystemUserExts.Type = aSystemUsersEN.aSystemUserExts.Type;
                        aSystemUserExts.Status = aSystemUsersEN.aSystemUserExts.Status;
                        aSystemUserExts.Disable = aSystemUsersEN.aSystemUserExts.Disable;
                        aSystemUserExts.IDSystemUser = aSystemUsers.ID;
                        aSystemUserExts.Recruitment = aSystemUsersEN.aSystemUserExts.Recruitment;
                        aSystemUserExts.PermanentResidence = aSystemUsersEN.aSystemUserExts.PermanentResidence;
                        aSystemUserExts.CommunistPartyDate = aSystemUsersEN.aSystemUserExts.CommunistPartyDate;
                        aSystemUserExts.YouthUnionDate = aSystemUsersEN.aSystemUserExts.YouthUnionDate;
                        aSystemUserExts.EnlistmentDate = aSystemUsersEN.aSystemUserExts.EnlistmentDate;
                        aSystemUserExts.DemobilizedDate = aSystemUsersEN.aSystemUserExts.DemobilizedDate;
                        aSystemUserExts.MartyrsFamily = aSystemUsersEN.aSystemUserExts.MartyrsFamily;
                        aSystemUserExts.WoundedFamily = aSystemUsersEN.aSystemUserExts.WoundedFamily;
                        aSystemUserExts.LaborFamily = aSystemUsersEN.aSystemUserExts.LaborFamily;
                        aSystemUserExts.HightestAppellation = aSystemUsersEN.aSystemUserExts.HightestAppellation;
                        status = aSystemUserExtsBO.Insert(aSystemUserExts);
                    }

                    FamilyMembersBO aFamilyMembersBO = new FamilyMembersBO();
                    foreach (FamilyMembers familyMembers in aSystemUsersEN.aListFamilyMembersExtEN)
                    {
                        FamilyMembers aFamilyMembers = aFamilyMembersBO.Select_ByID(familyMembers.ID);
                        if (aFamilyMembers == null)
                        {
                            aFamilyMembers = new FamilyMembers();
                            aFamilyMembers.Name = familyMembers.Name;
                            aFamilyMembers.Birthday = familyMembers.Birthday;
                            aFamilyMembers.RelationType = familyMembers.RelationType;
                            aFamilyMembers.Info = familyMembers.Info;
                            aFamilyMembers.IDSystemUser = aSystemUsers.ID;

                            int a = aFamilyMembersBO.Insert(aFamilyMembers);
                            if (a <= 0)
                            {
                                throw new Exception("Lỗi khi thêm dữ liệu thành viên gia đình");
                            }
                        }
                        else
                        {
                            aFamilyMembers.Name = familyMembers.Name;
                            aFamilyMembers.Birthday = familyMembers.Birthday;
                            aFamilyMembers.RelationType = familyMembers.RelationType;
                            aFamilyMembers.Info = familyMembers.Info;
                            aFamilyMembers.IDSystemUser = familyMembers.IDSystemUser;
                            aFamilyMembersBO.Update(aFamilyMembers);
                        }
                    }
                    SystemUsers_CertificatesBO aSystemUsers_CertificatesBO = new SystemUsers_CertificatesBO();
                    foreach (SystemUsers_Certificates systemUsers_Certificates in aSystemUsersEN.aListSystemUsers_CertificatesEN)
                    {
                        SystemUsers_Certificates aSystemUsers_Certificates = aSystemUsers_CertificatesBO.Select_ByID(systemUsers_Certificates.ID);
                        if (aSystemUsers_Certificates == null)
                        {
                            aSystemUsers_Certificates = new SystemUsers_Certificates();
                            aSystemUsers_Certificates.Level = systemUsers_Certificates.Level;
                            aSystemUsers_Certificates.CreatedDate = systemUsers_Certificates.CreatedDate;
                            aSystemUsers_Certificates.ExpirationDate = systemUsers_Certificates.ExpirationDate;
                            aSystemUsers_Certificates.Organization = systemUsers_Certificates.Organization;
                            aSystemUsers_Certificates.TrainingType = systemUsers_Certificates.TrainingType;
                            aSystemUsers_Certificates.IDCertificate = systemUsers_Certificates.IDCertificate;
                            aSystemUsers_Certificates.IDSystemUser = aSystemUsers.ID;
                            aSystemUsers_CertificatesBO.Insert(aSystemUsers_Certificates);
                        }
                        else
                        {
                            aSystemUsers_Certificates.Level = systemUsers_Certificates.Level;
                            aSystemUsers_Certificates.CreatedDate = systemUsers_Certificates.CreatedDate;
                            aSystemUsers_Certificates.ExpirationDate = systemUsers_Certificates.ExpirationDate;
                            aSystemUsers_Certificates.Organization = systemUsers_Certificates.Organization;
                            aSystemUsers_Certificates.TrainingType = systemUsers_Certificates.TrainingType;
                            aSystemUsers_Certificates.IDCertificate = systemUsers_Certificates.IDCertificate;
                            aSystemUsers_Certificates.IDSystemUser = systemUsers_Certificates.IDSystemUser;
                            aSystemUsers_CertificatesBO.Update(aSystemUsers_Certificates);
                        }
                    }

                    AuditHistoriesBO aAuditHistoriesBO = new AuditHistoriesBO();

                    foreach (AuditHistories auditHistories in aSystemUsersEN.aListAuditHistories)
                    {
                        AuditHistories aAuditHistories = aAuditHistoriesBO.Select_ByID(auditHistories.ID);
                        if (aAuditHistories == null)
                        {
                            aAuditHistories = new AuditHistories();
                            aAuditHistories.From = auditHistories.From;
                            aAuditHistories.To = auditHistories.To;
                            aAuditHistories.Note = auditHistories.Note;
                            aAuditHistories.Type = auditHistories.Type;
                            aAuditHistories.IDSystemUser = aSystemUsers.ID;
                            aAuditHistoriesBO.Insert(aAuditHistories);
                        }
                        else
                        {
                            aAuditHistories.From = auditHistories.From;
                            aAuditHistories.To = auditHistories.To;
                            aAuditHistories.Note = auditHistories.Note;
                            aAuditHistories.Type = auditHistories.Type;
                            aAuditHistories.IDSystemUser = auditHistories.IDSystemUser;
                            aAuditHistoriesBO.Update(aAuditHistories);
                        }

                    }

                    RewardAndPunishmentsBO aRewardAndPunishmentsBO = new RewardAndPunishmentsBO();

                    foreach (RewardAndPunishments rewardAndPunishments in aSystemUsersEN.aListRewardAndPunishments)
                    {
                        RewardAndPunishments aRewardAndPunishments = aRewardAndPunishmentsBO.Select_ByID(rewardAndPunishments.ID);
                        if (aRewardAndPunishments == null)
                        {
                            aRewardAndPunishments = new RewardAndPunishments();
                            aRewardAndPunishments.Type = rewardAndPunishments.Type;
                            aRewardAndPunishments.Subject = rewardAndPunishments.Subject;
                            aRewardAndPunishments.Description = rewardAndPunishments.Description;
                            aRewardAndPunishments.CreatedDate = rewardAndPunishments.CreatedDate;
                            aRewardAndPunishments.DecisionDate = rewardAndPunishments.DecisionDate;
                            aRewardAndPunishments.NumberDecision = rewardAndPunishments.NumberDecision;
                            aRewardAndPunishments.DecisionLevel = rewardAndPunishments.DecisionLevel;
                            aRewardAndPunishments.Status = rewardAndPunishments.Status;
                            aRewardAndPunishments.Disable = rewardAndPunishments.Disable;
                            aRewardAndPunishments.IDSystemUser = aSystemUsers.ID;
                            aRewardAndPunishmentsBO.Insert(aRewardAndPunishments);
                        }
                        else
                        {
                            aRewardAndPunishments.Type = rewardAndPunishments.Type;
                            aRewardAndPunishments.Subject = rewardAndPunishments.Subject;
                            aRewardAndPunishments.Description = rewardAndPunishments.Description;
                            aRewardAndPunishments.CreatedDate = rewardAndPunishments.CreatedDate;
                            aRewardAndPunishments.DecisionDate = rewardAndPunishments.DecisionDate;
                            aRewardAndPunishments.NumberDecision = rewardAndPunishments.NumberDecision;
                            aRewardAndPunishments.DecisionLevel = rewardAndPunishments.DecisionLevel;
                            aRewardAndPunishments.Status = rewardAndPunishments.Status;
                            aRewardAndPunishments.Disable = rewardAndPunishments.Disable;
                            aRewardAndPunishments.IDSystemUser = rewardAndPunishments.IDSystemUser;
                            aRewardAndPunishmentsBO.Update(aRewardAndPunishments);
                        }
                    }

                    DocumentSystemUsersBO aDocumentSystemUsersBO = new DocumentSystemUsersBO();
                    foreach (DocumentSystemUsers documentSystemUsers in aSystemUsersEN.aListDocumentSystemUsers)
                    {
                        DocumentSystemUsers aDocumentSystemUsers = aDocumentSystemUsersBO.Select_ByID(documentSystemUsers.ID);
                        if (aDocumentSystemUsers == null)
                        {
                            aDocumentSystemUsers = new DocumentSystemUsers();
                            aDocumentSystemUsers.Name = documentSystemUsers.Name;
                            aDocumentSystemUsers.FileData = documentSystemUsers.FileData;
                            aDocumentSystemUsers.Note = documentSystemUsers.Note;
                            aDocumentSystemUsers.Type = documentSystemUsers.Type;
                            aDocumentSystemUsers.Status = documentSystemUsers.Status;
                            aDocumentSystemUsers.Disable = documentSystemUsers.Disable;
                            aDocumentSystemUsers.IDSystemUser = aSystemUsers.ID;
                            aDocumentSystemUsersBO.Insert(aDocumentSystemUsers);
                        }
                        else
                        {
                            aDocumentSystemUsers.Name = documentSystemUsers.Name;
                            aDocumentSystemUsers.FileData = documentSystemUsers.FileData;
                            aDocumentSystemUsers.Note = documentSystemUsers.Note;
                            aDocumentSystemUsers.Type = documentSystemUsers.Type;
                            aDocumentSystemUsers.Status = documentSystemUsers.Status;
                            aDocumentSystemUsers.Disable = documentSystemUsers.Disable;
                            aDocumentSystemUsers.IDSystemUser = documentSystemUsers.IDSystemUser;
                            aDocumentSystemUsersBO.Update(aDocumentSystemUsers);
                        }
                    }

                }

            }
            catch (Exception ex)
            {

                aSystemUsersBO.Update(aSystemUsers_Old);
                aSystemUserExtsBO.Update(aSystemUserExts_Old);

                throw new Exception(string.Format("ReceptionTaskBO.UpdateSystemUserInformation :" + ex.Message.ToString()));
            }
        }