public int Insert(int IDSystemUser)
 {
     this.IDSystemUser_Old = IDSystemUser;
     SystemUsers_Certificates aSystemUsers_Certificates = new SystemUsers_Certificates();
     aSystemUsers_Certificates.IDCertificate = Convert.ToInt32(lueCertificateType.EditValue);
     aSystemUsers_Certificates.IDSystemUser = IDSystemUser_Old;
     aSystemUsers_Certificates.Level = cbbLevel.Text;
     aSystemUsers_Certificates.ExpirationDate = dtpExpirationDate.Value;
     aSystemUsers_Certificates.CreatedDate = dtpCreatedDate.Value;
     aSystemUsers_Certificates.Organization = txtOrganization.Text;
     return aSystemUsers_CertificatesBO.Insert(aSystemUsers_Certificates);
 }
 //Author : LinhTing
 public int Insert(SystemUsers_Certificates aSystemUsers_Certificates)
 {
     try
     {
        aSystemUsers_Certificates =  aDatabaseDA.SystemUsers_Certificates.Add(aSystemUsers_Certificates);
        aDatabaseDA.SaveChanges();
        return aSystemUsers_Certificates.ID;
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("SystemUsers_CertificatesBO.Insert :"+ ex.Message.ToString()));
     }
 }
        //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()));
            }
        }
 //Author : Hiennv
 public int Update(SystemUsers_Certificates aSystemUsers_Certificates)
 {
     try
     {
         aDatabaseDA.SystemUsers_Certificates.AddOrUpdate(aSystemUsers_Certificates);
         return aDatabaseDA.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("SystemUsers_CertificatesBO.Update :"+ ex.Message.ToString()));
     }
 }