private async void DeleteEmp(int?obj) { try { dc = new DialogContent() { Content = "Bạn muốn xóa tài khoản này ?", Tilte = "Thông Báo" }; var dialogYS = new DialogYesNo() { DataContext = dc }; var result = (bool)await DialogHost.Show(dialogYS, DialogHostId); if (result) { if (obj != null) { if (await employee_Repo.Remove((int)obj)) { ListAccount.Remove(ListAccount.SingleOrDefault(t => t.EmpID == (int)obj)); dc = new DialogContent() { Content = "Xóa Thành Công", Tilte = "Thông Báo" }; dialog = new DialogOk() { DataContext = dc }; await DialogHost.Show(dialog, DialogHostId); } else { dc = new DialogContent() { Content = "Xóa Thất Bại", Tilte = "Thông Báo" }; dialog = new DialogOk() { DataContext = dc }; await DialogHost.Show(dialog, DialogHostId); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public AccountMngVM() { AddAccountCmd = new RelayCommand <Button>((p) => { return(true); }, (p) => { IsAdding = true; IsEnabledUserNameTextBox = true; IsEnabledTextBox = true; }); EditCommand = new RelayCommand <Button>((p) => { return(SelectedAccount == null ? false : true); }, (p) => { IsAdding = false; IsEnabledUserNameTextBox = false; IsEnabledTextBox = true; }); SaveCommand = new RelayCommand <Button>((p) => { if (IsEnabledTextBox && ((Password != null && Password2 != null && IsAdding) || !IsAdding)) { return(true); } else { return(false); } }, (p) => { IsEnabledTextBox = false; IsEnabledUserNameTextBox = false; if (!IsAdding) { var account = DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == SelectedAccount.TENTK).SingleOrDefault(); if (account == null) { MessageBoxWindow mess2 = new MessageBoxWindow(); mess2.Tag = "Không tìm thấy tài khoản này"; mess2.ShowDialog(); // MessageBox.Show("Không tìm thấy tài khoản này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (Img != null) { Image = ByteToImageConverter.Ins.ImageToByte(Img); account.HINHANH = Image; } else { account.HINHANH = null; } account.TENTK = AccountName; account.TENHIENTHI = DisplayName; account.LOAITK = TypeAccount.IDType; if (Password != null) { if (Password != Password2) { MessageBoxWindow mess2 = new MessageBoxWindow(); mess2.Tag = "Nhập lại mật khẩu không khớp với mật khẩu đã nhập!"; mess2.ShowDialog(); // MessageBox.Show("Nhập lại mật khẩu không khớp với mật khẩu đã nhập!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); } else { account.MATKHAU = Password; } } else { account.MATKHAU = DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == SelectedAccount.TENTK).SingleOrDefault().MATKHAU; } DataProvider.Ins.DB.SaveChanges(); Password2 = Password = null; IsAdding = true; } else { if (Img != null) { Image = ByteToImageConverter.Ins.ImageToByte(Img); } else { Image = null; } var account = new TAIKHOAN() { TENTK = AccountName, TENHIENTHI = DisplayName, HINHANH = Image, LOAITK = TypeAccount.IDType, MATKHAU = Password }; if (DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == account.TENTK).Count() > 0) { MessageBoxWindow mess2 = new MessageBoxWindow(); mess2.Tag = "Tài khoản đã tồn tại!"; mess2.ShowDialog(); //MessageBox.Show("Tài khoản đã tồn tại!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (Password != Password2) { MessageBoxWindow mess2 = new MessageBoxWindow(); mess2.Tag = "Nhập lại mật khẩu không khớp với mật khẩu đã nhập!"; mess2.ShowDialog(); //MessageBox.Show("Nhập lại mật khẩu không khớp với mật khẩu đã nhập!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); } else { DataProvider.Ins.DB.TAIKHOANs.Add(account); DataProvider.Ins.DB.SaveChanges(); ListAccount.Add(account); } } } }); DeleteCommand = new RelayCommand <Button>((p) => { return(true); }, (p) => { var account = DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == SelectedAccount.TENTK).SingleOrDefault(); DataProvider.Ins.DB.TAIKHOANs.Remove(account); DataProvider.Ins.DB.SaveChanges(); ListAccount.Remove(SelectedAccount); }); SearchCmd = new RelayCommand <TextBox>((p) => { return(true); }, (p) => { if (p.Text != "") { var newList = new ObservableCollection <TAIKHOAN>(DataProvider.Ins.DB.Database.SqlQuery <TAIKHOAN>("USP_TIMTKTHEOTEN @TEN", new SqlParameter("TEN", p.Text))); ListAccount = newList; } else { var newList = new ObservableCollection <TAIKHOAN>(DataProvider.Ins.DB.TAIKHOANs); ListAccount = newList; } }); PasswordChangedCommand = new RelayCommand <PasswordBox>((p) => { return(true); }, (p) => { Password = p.Password; }); Password2ChangedCommand = new RelayCommand <PasswordBox>((p) => { return(true); }, (p) => { Password2 = p.Password; }); ListAccount = new ObservableCollection <TAIKHOAN>(DataProvider.Ins.DB.TAIKHOANs); ListTypeAccount = new ObservableCollection <TypeAccount>() { new TypeAccount(0), new TypeAccount(1) }; }