Пример #1
0
        private void AddNewUser()
        {
            Users    user = new Users();
            UserForm form = new UserForm(user, awards);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                //Users user = new Users();
                user.Name     = form.Name;
                user.Surname  = form.Surname;
                user.Birthday = form.BD;
                user.Awards   = form.userAwards;
                user.Id       = userId++;

                users.Add(user);

                UserWithAward userWithAward = new UserWithAward();
                userWithAward = UserWithAward.ModelMaker(user);

                _users.Add(userWithAward);

                //RABOTAY(userWithAward);
                refreshUsersGrid();
            }
        }
Пример #2
0
        private void EditSelectedUser()
        {
            if (ctlUsers.SelectedCells.Count > 0)
            {
                UserWithAward user     = (UserWithAward)ctlUsers.SelectedCells[0].OwningRow.DataBoundItem;
                Users         editUser = null;
                int           id       = 0;
                foreach (var item in users)
                {
                    if (item.Id == user.Id)
                    {
                        editUser = item;
                    }
                    else
                    {
                        id++;
                    }
                }


                UserForm form = new UserForm(editUser, awards);
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    editUser.Name     = form.Name;
                    editUser.Surname  = form.Surname;
                    editUser.Birthday = form.BD;
                    editUser.Awards   = form.userAwards;
                    users[id]         = editUser;
                    user = UserWithAward.ModelMaker(editUser);
                    //id = 0;
                    BindingList <UserWithAward> temp = new BindingList <UserWithAward>(_users);

                    for (int i = 0; i < temp.Count; i++)
                    {
                        if (temp[i].Id == user.Id)
                        {
                            _users[i] = user;
                        }
                    }
                }
            }
        }
Пример #3
0
        private void dropAwardFromUsers(Awards award)
        {
            List <Users> temp = new List <Users>(users);
            BindingList <UserWithAward> tempView = new BindingList <UserWithAward>(_users);

            for (int i = 0; i < temp.Count; i++)
            {
                users[i].Awards.Remove(award);

                for (int k = 0; k < tempView.Count; k++)
                {
                    if (temp[i].Id == tempView[k].Id)
                    {
                        _users[k] = UserWithAward.ModelMaker(users[i]);
                    }

                    refreshUsersGrid();
                }
            }
        }