示例#1
0
        private void btnEditarUser_Click(object sender, RoutedEventArgs e)
        {
            EditUser edituser = new EditUser();

            this.Close();
            edituser.ShowDialog();
        }
示例#2
0
        private void ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            EditUser a = new EditUser(logg, true);

            a.Text = "Definições da Conta";
            a.ShowDialog();
        }
 /// <summary>
 /// Executes the edit command
 /// </summary>
 public void EditUserExecute()
 {
     try
     {
         EditUser editUser = new EditUser(LoggedUser.CurrentUser);
         editUser.ShowDialog();
         InfoText();
         UserList = service.GetAllUsers().ToList();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#4
0
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            Button   button      = sender as System.Windows.Controls.Button;
            User     user        = button.DataContext as User;
            EditUser inputDialog = new EditUser(user.Id, user.Name, user.Email, user.Contact, user.Role, user.Station);

            if (inputDialog.ShowDialog() == true)
            {
                lblName.Text = inputDialog.Answer;
            }
            lblName.Visibility = System.Windows.Visibility.Visible;
            alert.Visibility   = System.Windows.Visibility.Visible;
            RefreshUserList();
        }
示例#5
0
        private void EditUserAction(object obj)
        {
            if (obj == null)
            {
                return;
            }
            var selectedUser = obj as User;
            EditUserViewModel editUserViewModel = new EditUserViewModel();

            editUserViewModel.newUser = selectedUser;
            EditUser newEdit = new EditUser();

            newEdit.DataContext = editUserViewModel;
            //App.Current.MainWindow = newEdit;
            //App.Current.MainWindow.Show();
            newEdit.ShowDialog();
        }
        /// <summary>
        /// This method checks if username and password are valid.
        /// </summary>
        /// <param name="password">User input for password.</param>
        public void LogInExecute(object obj)
        {
            CurrentUser.password = (obj as PasswordBox).Password;
            bool registered = service.IsRegisteredUser(currentUser.username);

            if (registered)
            {
                tblUser anUser = service.GetUserByUsernameAndPass(currentUser.username, currentUser.password);
                if (anUser != null)
                {
                    if (PasswordHasher.Verify(CurrentUser.password, anUser.password))
                    {
                        MessageBox.Show("Invalid password. Try again");
                    }
                    else
                    {
                        User userview = new User(anUser);
                        login.Close();
                        userview.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("Invalid password. Try again");
                }
            }
            else
            {
                if (validation.PasswordChecker(currentUser.password) == true)
                {
                    tblUser newUser = service.AddUser(currentUser.username, currentUser.password);
                    UserList = service.GetAllUsers();
                    MessageBox.Show("Successful registration.", "Notification");
                    EditUser edit = new EditUser(newUser);
                    edit.ShowDialog();
                    User userview = new User(newUser);
                    login.Close();
                    userview.ShowDialog();
                }
                else
                {
                    MessageBox.Show("The password must have minimum 5 characters.", "Notification");
                }
            }
        }
示例#7
0
        private void buttonEditUser_Click(object sender, EventArgs e)
        {
            //Si esta selec
            User user_selected = null;

            foreach (User user in parent.users)
            {
                if (dataGridViewUsers.CurrentRow.Cells[1].Value.ToString() == user.name)
                {
                    user_selected = user;
                    break;
                }
            }
            Form settings = new EditUser(user_selected, parent);

            settings.ShowDialog(this);
            Fill_dataGridViewUsers();
            //save xml
            parent.toXML();
        }
示例#8
0
 private void bbiEdit_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (uIDSelected != "")
     {
         EditUser eu = new EditUser();
         var      db = new PetStoreEntities();
         var      u  = db.Users.Find(int.Parse(uIDSelected));
         eu.txt_uID.Text      = u.u_id.ToString();
         eu.txt_uName.Text    = u.u_name;
         eu.txt_uGender.Text  = u.u_gender;
         eu.txt_uMail.Text    = u.u_email;
         eu.txt_uPhone.Text   = u.u_phone;
         eu.txt_uAddress.Text = u.u_address;
         eu.txt_uStatus.Text  = u.u_status;
         //epf.te_FoodImage.Text = pf.pf_image;
         eu.ShowDialog();
     }
     else
     {
         XtraMessageBox.Show("Please choose an user item to edit !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
示例#9
0
        public UsersViewModel()
        {
            users        = new ObservableCollection <User>();
            UserService  = new UserService();
            EditUserData = new User();
            AddUserData  = new User();

            //分页数据
            page = new PageHelper <User>();

            //获取总页数和总记录数
            page.AllItemCount = UserService.GetAllItemCount();
            page.GetAllPageCount();

            //获取页面数据
            UserService.GetPage(page.CurPage, page.PerPageItem).ToList().ForEach(i => {
                page.Items.Add(i);
            });

            var list = UserService.Query();

            list.ForEach(u =>
            {
                u.IsSelected = false;
                users.Add(u);
            }
                         );

            //添加用户
            addUserDiaCommand = new DelegateCommand();
            addUserDiaCommand.ExcuteAction = new Action <object>(o =>
            {
                List <object> objs = o as List <object>;
                //使用{Binding} 获取到的是HomeViewModel
                var vm    = objs[0] as HomeViewModel;
                var add   = new AddUser();
                var data  = add.DataContext as UsersViewModel;
                data.page = objs[1] as PageHelper <User>;
                //设置当前窗体的父窗体
                add.Owner = vm.Home;
                add.ShowDialog();
            });

            closeCommand.ExcuteAction = new Action <object>(o =>
            {
                Window win = o as Window;
                //Utils.ClearImageSource(win);//清除图片资源内存
                win.Close();
                //FlushMemory.Flush();
            });

            //moveCommand.ExcuteAction = new Action<object>(o =>
            //  {
            //      (o as Window).DragMove();
            //  });

            //跳转到第几页
            gotoCommand.ExcuteAction = new Action <object>(o =>
            {
                string gotoPage = o as string;
                if (gotoPage != null)
                {
                    int index = 1;
                    int.TryParse(gotoPage, out index);
                    if (index > page.AllPageCount)
                    {
                        index = page.AllPageCount;
                    }
                    UpdateDataGrid(searchText);
                }
            });

            //首页
            firstCommand.ExcuteAction = new Action <object>(o => {
                page.CurPage = 1;
                UpdateDataGrid(searchText);
            });

            //尾页
            lastCommand.ExcuteAction = new Action <object>(o =>
            {
                page.CurPage = page.AllPageCount;
                UpdateDataGrid(searchText);
            });

            //下一页
            nextCommand.ExcuteAction = new Action <object>(o =>
            {
                if ((page.CurPage += 1) > page.AllPageCount)
                {
                    page.CurPage = page.AllPageCount;
                }
                UpdateDataGrid(searchText);
            });

            //上一页
            prevCommand.ExcuteAction = new Action <object>(o =>
            {
                if ((page.CurPage -= 1) < 1)
                {
                    page.CurPage = 1;
                }
                UpdateDataGrid(searchText);
            });

            //双击
            dataGirdDouClickCommand.ExcuteAction = new Action <object>(o =>
            {
                List <object> items = o as List <object>;
                if (list != null)
                {
                    //获取选中行的数据
                    var selectItem    = items[0] as User;
                    var home          = items[1] as HomeViewModel;
                    EditUser editUser = new EditUser();
                    //重新查询,防止在编辑过程中,表格的数据跟着改变
                    (editUser.DataContext as UsersViewModel).EditUserData = UserService.QueryById(selectItem.Id);
                    editUser.Owner = home.Home;
                    editUser.ShowDialog();
                }
            });

            //保存修改
            saveEditCommand = new DelegateCommand();
            saveEditCommand.ExcuteAction = new Action <object>(o =>
            {
                editUserData.IsEdit = true;
                //保存前,再验证全部属性是否通过
                var dic = ValidationHelper.ValidationObject(editUserData);
                if (dic.Count > 0)
                {
                    ShowTip("请输入正确的信息", o as Window);
                    return;
                }
                if (UserService.Modify(editUserData))
                {
                    UpdateDataGrid();
                    ShowTip("修改成功", o as EditUser);
                    page.Items.Clear();
                    //添加成功,关闭窗体
                    CloseDialog(o as Window);
                }
                else
                {
                    ShowTip("修改失败", o as EditUser);
                }
            });

            //新增用户
            addUserCommand = new DelegateCommand();
            addUserCommand.ExcuteAction = new Action <object>(o =>
            {
                //保存前,再验证全部属性是否通过
                var dic = ValidationHelper.ValidationObject(addUserData);
                if (dic.Count > 0)
                {
                    ShowTip("请输入正确的信息", o as Window);
                    return;
                }
                var result = UserService.Add(addUserData);
                if (result)
                {
                    isQuery = false;
                    UpdateDataGrid();
                    ShowTip("添加成功", o as Window);
                    //添加成功,关闭窗体
                    CloseDialog(o as Window);
                }
                else
                {
                    ShowTip("添加失败", o as Window);
                }
            });

            //删除用户
            deleteCommand.ExcuteAction = new Action <object>(o =>
            {
                List <User> delUser = new List <User>();
                foreach (var item in page.Items)
                {
                    if (item.IsSelected)
                    {
                        delUser.Add(item);
                    }
                }
                foreach (var item in delUser)
                {
                    if (UserService.Del(item))
                    {
                        ShowTip("删除成功");
                    }
                    else
                    {
                        ShowTip("删除失败");
                    }
                }
                UpdateDataGrid(searchText);
            });

            //查询
            searchCommand.ExcuteAction = new Action <object>(o =>
            {
                page.CurPage = 1;
                if (!string.IsNullOrEmpty(searchText))
                {
                    isQuery = true;
                    UpdateDataGrid(searchText);
                }
                else
                {
                    isQuery = false;
                    UpdateDataGrid();
                }
            });

            //更新每页条数
            updatePerPageItemCommand = new DelegateCommand();
            updatePerPageItemCommand.ExcuteAction = new Action <object>(o =>
            {
                var text = o as string;
                if (!string.IsNullOrEmpty(text))
                {
                    page.PerPageItem = Convert.ToInt32(text);
                    page.CurPage     = 1;
                    UpdateDataGrid(searchText);
                }
            });
        }
示例#10
0
        //编辑用户信息
        private void Edit_User(object sender, RoutedEventArgs e)
        {
            EditUser        editUser = new EditUser();;
            var             a        = this.userData.SelectedItem;
            var             b        = a as DataRowView;
            int             userId   = Convert.ToInt32(b.Row[0]);
            Users           user     = new Users();
            MySqlDataReader reader   = user.queryUser(userId);

            if (reader.Read())
            {
                editUser.userId.Content = reader["ID"];
                editUser.account.Text   = reader["ACCOUNT"].ToString();
                editUser.userName.Text  = reader["USER_NAME"].ToString();
                if ((int)reader["TYPE"] == 1)
                {
                    editUser.userType.SelectedIndex = 1;
                }
                else
                {
                    editUser.userType.SelectedIndex = 0;
                }
                editUser.userPhone.Text     = reader["PHONE"].ToString();
                editUser.createTime.Content = Convert.ToDateTime(reader["CREATE_TIME"]).ToString("yyyy-MM-dd hh:mm");
            }

            ComboBox hasStatus = editUser.status;

            if (hasStatus.HasItems)
            {
                hasStatus.Items.Clear();
            }

            if ((int)reader["STATUS"] == 0)
            {
                ComboBox     status = editUser.status;
                ComboBoxItem check  = new ComboBoxItem();
                check.Tag        = 0;
                check.Content    = "未激活";
                check.IsSelected = true;
                status.Items.Add(check);
                check         = new ComboBoxItem();
                check.Tag     = 1;
                check.Content = "激  活";
                status.Items.Add(check);
            }
            else if ((int)reader["STATUS"] == 1)
            {
                ComboBox     status = editUser.status;
                ComboBoxItem check  = new ComboBoxItem();
                check.Tag        = 1;
                check.Content    = "已激活";
                check.IsSelected = true;
                status.Items.Add(check);
                check         = new ComboBoxItem();
                check.Tag     = 2;
                check.Content = "禁  用";
                status.Items.Add(check);
            }
            else
            {
                ComboBox     status = editUser.status;
                ComboBoxItem check  = new ComboBoxItem();
                check.Tag        = 2;
                check.Content    = "禁  用";
                check.IsSelected = true;
                status.Items.Add(check);
                check         = new ComboBoxItem();
                check.Tag     = 1;
                check.Content = "激 活";
                status.Items.Add(check);
            }
            editUser.createName.Content = reader["CREATE_USER"];
            editUser.Owner = Window.GetWindow(this);
            editUser.ShowDialog();
        }