Ejemplo n.º 1
0
        protected override void Archive()
        {
            base.Archive();
            DB.ORG_Contact orgContact = (DB.ORG_Contact)BindingSource.DataSource;
            DB.SYS_Person  sysPerson  = BL.SYS.SYS_Person.Load(orgContact.PersonId, DataContext);

            sysPerson.Archived = !sysPerson.Archived;
            btnArchive.Caption = sysPerson.Archived ? "Un-Archive" : "Archive";
            try
            {
                using (TransactionScope transaction = DataContext.GetTransactionScope())
                {
                    DataContext.SaveChangesEntitySystemContext();
                    DataContext.CompleteTransaction(transaction);
                }
                DataContext.EntitySystemContext.AcceptAllChanges();
            }
            catch (Exception ex)
            {
                DataContext.EntitySystemContext.RejectChanges();
                HasErrors = true;
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 2
0
 private void ddlSystemUser_EditValueChanged(object sender, EventArgs e)
 {
     if (ddlSystemUser.EditValue != null && ddlSystemUser.EditValue != DBNull.Value && Convert.ToInt64(ddlSystemUser.EditValue) != 0)
     {
         sysPerson = BL.SYS.SYS_Person.Load((long)ddlSystemUser.EditValue, DataContext);
         BindData();
         ValidateLayout();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// The binding source is bound to a new instance of an ORG Entity. This is for the instances where a new record is to be created.
 /// </summary>
 /// <remarks>Created: Theo Crous 17/11/2011</remarks>
 protected override void OnNewRecord()
 {
     try
     {
         base.OnNewRecord();
         orgContact = BL.ORG.ORG_Contact.New;
         sysContact = BL.SYS.SYS_Person.New;
     }
     catch (Exception ex)
     {
         if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
         {
             throw ex;
         }
     }
 }
Ejemplo n.º 4
0
        internal static String Save(DB.SYS_Person entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntitySystemContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntitySystemContext.SYS_Person.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Open a Employee record from the database.
 /// </summary>
 /// <param name="Id">The id (primary key) of the Employee to open.</param>
 /// <remarks>Created: Werner Scheffer 24/07/2012</remarks>
 public override void OpenRecord(Int64 Id)
 {
     try
     {
         base.OpenRecord(Id);
         hrsEmployee = BL.HRS.HRS_Employee.Load(Id, DataContext);
         sysPerson   = BL.SYS.SYS_Person.Load(hrsEmployee.PersonId.Value, DataContext);
     }
     catch (Exception ex)
     {
         if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
         {
             throw ex;
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// The binding source is bound to a new instance of an Employee. This is for the instances where a new record is to be created.
 /// </summary>
 /// <remarks>Created: Werner Scheffer 24/07/2012</remarks>
 protected override void OnNewRecord()
 {
     try
     {
         base.OnNewRecord();
         hrsEmployee = BL.HRS.HRS_Employee.New;
         sysPerson   = BL.SYS.SYS_Person.New;
         txtDateOfBirth.EditValue = DateTime.Now;
     }
     catch (Exception ex)
     {
         if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
         {
             throw ex;
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Open an ORG Entity record from the database.
        /// </summary>
        /// <param name="Id">The id (primary key) of the ORG Entity to open.</param>
        /// <remarks>Created: Theo Crous 14/11/2011</remarks>
        public override void OpenRecord(Int64 Id)
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    base.OpenRecord(Id);

                    orgContact = BL.ORG.ORG_Contact.Load(Id, DataContext);
                    sysContact = BL.SYS.SYS_Person.Load(orgContact.PersonId, DataContext);
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 8
0
 public static DB.SYS_Person GetPreviousItem(DB.SYS_Person SYS_Person, DataContext dataContext)
 {
     return(dataContext.EntitySystemContext.SYS_Person.OrderByDescending(o => o.Fullname).FirstOrDefault(n => n.Fullname.CompareTo(SYS_Person.Fullname) < 0 && n.Fullname.CompareTo(SYS_Person.Fullname) != 0));
 }
Ejemplo n.º 9
0
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();
                    if (!IsValid)
                    {
                        return(false);
                    }

                    DB.SEC_User            secUser       = (DB.SEC_User)BindingSource.DataSource;
                    DB.SYS_Person          sys_person    = (DB.SYS_Person)BindingSourcePerson.DataSource;
                    List <DB.SEC_UserRole> current       = secUser.SEC_UserRole.Select(n => n as DB.SEC_UserRole).ToList();
                    List <DB.SEC_Role>     selectedroles = lstRoles.CheckedItems.Cast <DB.SEC_Role>().ToList();
                    // Get all the roles that have been added to the user.
                    List <Int64> roleidsrequired = selectedroles.Where(n => !current.Select(m => m.RoleId).Contains(n.Id)).Select(n => n.Id).ToList();
                    foreach (Int64 id in roleidsrequired)
                    {
                        DB.SEC_UserRole userrole = BL.SEC.SEC_UserRole.New;
                        userrole.UserId = secUser.Id;
                        userrole.RoleId = id;
                        secUser.SEC_UserRole.Add(userrole);
                    }
                    try
                    {
                        using (TransactionScope transaction = DataContext.GetTransactionScope())
                        {
                            BL.EntityController.SaveSYS_Person(sys_person, DataContext);
                            DataContext.SaveChangesEntitySystemContext();
                            secUser.PersonId = sys_person.Id;
                            BL.EntityController.SaveSEC_User(secUser, DataContext);
                            if (RollHasChanged)
                            {
                                // Remove the roles that are on the user and not in the checked list.
                                List <DB.SEC_UserRole> roleidsdeleted = current.Where(n => !selectedroles.Select(m => m.Id).Contains(n.RoleId)).ToList();

                                foreach (DB.SEC_UserRole ur in roleidsdeleted)
                                {
                                    BL.SEC.SEC_UserRole.DeleteUserRole(ur, DataContext);
                                }

                                //TODO : Remove this when log system is added
                                //BL.SEC.SEC_User.UpdateRoleModifiedFlags(secUser, DataContext);
                            }
                            DataContext.SaveChangesEntitySecurityContext();
                            DataContext.SaveChangesEntitySystemContext();
                            DataContext.CompleteTransaction(transaction);
                        }
                        DataContext.EntitySecurityContext.AcceptAllChanges();
                        DataContext.EntitySystemContext.AcceptAllChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        DataContext.EntitySecurityContext.RejectChanges();
                        DataContext.EntitySystemContext.RejectChanges();
                        HasErrors = true;
                        if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                        {
                            throw ex;
                        }
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }