コード例 #1
0
        protected override void btnNew_Clicked(object o, EventArgs args)
        {
            selectedId = null;

            // Added transaction to ensure that we are connected to the same server in case of
            // master-slave replication
            using (new DbMasterScope(BusinessDomain.DataAccessProvider)) {
                User user;
                using (EditNewUser dialog = new EditNewUser(null, selectedGroupId)) {
                    if (dialog.Run() != ResponseType.Ok)
                    {
                        ReinitializeGrid(true, null);
                        return;
                    }

                    user       = dialog.GetUser().CommitChanges();
                    selectedId = user.Id;
                }

                OnEntitiesChanged(user.GroupId);
            }
        }
コード例 #2
0
        protected override void btnEdit_Clicked(object o, EventArgs args)
        {
            int selectedRow = grid.FocusedRow;

            if (selectedRow < 0)
            {
                return;
            }

            User user = entities [selectedRow];

            selectedId = user.Id;

            if (user.Id == User.DefaultId)
            {
                MessageError.ShowDialog(string.Format(Translator.GetString("Cannot edit the default user \"{0}\"!"), user.Name), "Icons.User16.png");
                return;
            }

            if (!user.CanEdit())
            {
                MessageError.ShowDialog(Translator.GetString("Editing users with access level higher or equal of the current\'s one is not allowed!"));
                return;
            }

            // Added transaction to ensure that we are connected to the same server in case of
            // master-slave replication
            using (new DbMasterScope(BusinessDomain.DataAccessProvider)) {
                UserAccessLevel oldUserLevel = user.UserLevel;
                using (EditNewUser dialog = new EditNewUser(user, selectedGroupId)) {
                    if (dialog.Run() != ResponseType.Ok)
                    {
                        ReinitializeGrid(true, null);
                        return;
                    }

                    user       = dialog.GetUser().CommitChanges();
                    selectedId = user.Id;

                    bool refreshRestrictions = false;
                    if (oldUserLevel != user.UserLevel)
                    {
                        if (Message.ShowDialog(Translator.GetString("Reset Permissions"), null,
                                               Translator.GetString("The access level of the user was changed. " +
                                                                    "Do you want to reset the permissions of this user to the default ones for the new access level?"), "Icons.Question32.png",
                                               MessageButtons.YesNo) == ResponseType.Yes)
                        {
                            BusinessDomain.RestrictionTree.ResetLevelRestrictions(user.Id, user.UserLevel);
                            BusinessDomain.RestrictionTree.SaveRestrictions();
                            refreshRestrictions = true;
                        }
                    }

                    if (BusinessDomain.LoggedUser.Id == user.Id)
                    {
                        PresentationDomain.RefreshMainFormStatusBar();
                        if (refreshRestrictions)
                        {
                            PresentationDomain.RefreshMainFormRestrictions();
                        }
                    }
                }

                OnEntitiesChanged(user.Deleted ? UsersGroup.DeletedGroupId : user.GroupId);
            }
        }