public Taikhoan_ViewModel() { List = new ObservableCollection <Model.TAIKHOAN>(Model.DataProvider.Ins.DB.TAIKHOANs.Where(x => x.IsDeleted == false).ToList().OrderBy(x => x.NHANVIEN.ma_quyen)); TaoDSNhanvien(); DeleteList = new ObservableCollection <Model.TAIKHOAN>(); Active = false; IsOpen = false; Active_Command = new RelayCommand <object>(p => { if (Active == false) { return(false); } return(true); }, p => { Active = false; }); CloseDialog_Command = new RelayCommand <object>(p => { return(true); }, p => { IsOpen = false; }); #region Trang quan tri he thong #region Load trang quan tri Load_Command = new RelayCommand <object>(p => { return(true); }, p => { List = new ObservableCollection <Model.TAIKHOAN>(Model.DataProvider.Ins.DB.TAIKHOANs.Where(x => x.IsDeleted == false).ToList().OrderBy(x => x.NHANVIEN.ma_quyen)); TaoDSNhanvien(); DeleteList = new ObservableCollection <Model.TAIKHOAN>(); }); #endregion #region Them tai khoan GetPassword_Command = new RelayCommand <PasswordBox>(p => { if (p.Password.Length < 5) { return(false); } return(true); }, p => { Matkhautaikhoan = p.Password; }); GetRePassword_Command = new RelayCommand <PasswordBox>(p => { if (p.Password.Length < 5) { return(false); } return(true); }, p => { Matkhauxacnhan = p.Password; }); Insert_Command = new RelayCommand <object>(p => { if (string.IsNullOrEmpty(Tentaikhoan) || string.IsNullOrEmpty(Emailkhoiphuc) || string.IsNullOrEmpty(Matkhautaikhoan) || string.IsNullOrEmpty(Matkhauxacnhan)) { return(false); } if (SNhanvien == null) { return(false); } if (MyStaticMethods.CheckEmail(Emailkhoiphuc) == false) { return(false); } return(true); }, p => { if (Matkhauxacnhan == Matkhautaikhoan) { if (!Kiemtratendangnhap(Tentaikhoan)) { Model.TAIKHOAN newItem = new Model.TAIKHOAN() { ma_taikhoan = MyStaticMethods.RandomInt(10), ten_taikhoan = Tentaikhoan, email = Emailkhoiphuc, matkhau = MyStaticMethods.MD5Hash(MyStaticMethods.Base64Encode(Matkhautaikhoan)), NHANVIEN = SNhanvien, IsDeleted = false, IsLogin = false }; Model.DataProvider.Ins.DB.TAIKHOANs.Add(newItem); Model.DataProvider.Ins.DB.SaveChanges(); List.Insert(0, newItem); TaoDSNhanvien(); SelectedItem = newItem; Active = true; Message = "Thêm mới thành công !!!"; } else { Active = true; Message = "Tên đăng nhập đã tồn tại !!!"; } } else { Active = true; Message = "Mật khẩu và xác nhận mật khẩu không trùng khớp !!!"; } }); #endregion #region Tao moi Reset_Command = new RelayCommand <object>(p => { return(true); }, p => { Tentaikhoan = ""; Matkhautaikhoan = ""; Matkhauxacnhan = ""; Emailkhoiphuc = ""; SNhanvien = null; SelectedItem = null; }); #endregion #region Xoa tai khoan DeleteShow_Command = new RelayCommand <object>(p => { if (DeleteList.Count() == 0) { return(false); } if (IsOpen == true) { return(false); } return(true); }, p => { IsOpen = true; Content = " Xóa vĩnh viễn các bản ghi được chọn ???"; }); AddDeleteList_Command = new RelayCommand <CheckBox>(p => { return(true); }, p => { DeleteList.Add(List.Where(x => x.ma_taikhoan == p.Uid.ToString()).SingleOrDefault()); }); RemoveDeleteList_Command = new RelayCommand <CheckBox>(p => { return(true); }, p => { DeleteList.Remove(List.Where(x => x.ma_taikhoan == p.Uid.ToString()).SingleOrDefault()); }); Delete_Command = new RelayCommand <object>(p => { if (DeleteList.Count() == 0) { return(false); } return(true); }, p => { RemoveIteminDb(); RemoveIteminList(); DeleteList = new ObservableCollection <Model.TAIKHOAN>(); Tentaikhoan = ""; Matkhautaikhoan = ""; Emailkhoiphuc = ""; SNhanvien = null; TaoDSNhanvien(); IsOpen = false; }); #endregion #endregion #region Trang dang nhap #region Dang nhap LoadDangnhap_Command = new RelayCommand <Window>(p => { return(true); }, p => { Matkhau = string.Empty; CheckRemember(p); }); getCurrentPass_Command = new RelayCommand <PasswordBox>(p => { return(true); }, p => { Matkhau = p.Password; }); Login_Command = new RelayCommand <Button>(p => { if (string.IsNullOrEmpty(Matkhau) || string.IsNullOrEmpty(Tendangnhap)) { return(false); } return(true); }, p => { if (Kiemtrataikhoan(Tendangnhap, Matkhau)) { string mk = MyStaticMethods.MD5Hash(MyStaticMethods.Base64Encode(Matkhau)); var current_user = Model.DataProvider.Ins.DB.TAIKHOANs.Where(x => x.ten_taikhoan == Tendangnhap && x.matkhau == mk).SingleOrDefault(); if (current_user.NHANVIEN.ma_quyen == 1) { View.View_Quanly.Manhinhchinh view = new View.View_Quanly.Manhinhchinh(); view.Show(); //MessageBox.Show("Đăng nhập thành công", "THÔNG BÁO"); } else { View.View_Thukho.Manhinhchinh view = new View.View_Thukho.Manhinhchinh(); view.Show(); //MessageBox.Show("Đăng nhập thành công", "THÔNG BÁO"); } CurrentUser = current_user; IsRemember(); Window w = getWindowParent(p) as Window; if (p != null) { w.Close(); } Chuyentrangthai_Mo(CurrentUser); } else { Active = true; Message = "Vui lòng kiểm tra lại tên đăng nhập và mật khẩu !!!"; } }); #endregion #region Khoi phuc Send_Command = new RelayCommand <Button>(p => { return(true); }, p => { if (!string.IsNullOrEmpty(Tendangnhap)) { var result = Model.DataProvider.Ins.DB.TAIKHOANs.Where(x => x.ten_taikhoan == Tendangnhap).Count(); if (result != 0) { Model.TAIKHOAN TK = Model.DataProvider.Ins.DB.TAIKHOANs.Where(x => x.ten_taikhoan == Tendangnhap).SingleOrDefault(); try { Makhoiphuc = GuiMail(TK); Khoiphuctk view = new Khoiphuctk(); view.Show(); Window w = getWindowParent(p) as Window; if (w != null) { w.Close(); } Active = true; Message = "Đã gửi mã xác thực !!! Vui lòng kiểm tra email "; } catch (Exception) { Active = true; Message = "Không thể gửi mã !!! "; } } else { Active = true; Message = "Tên đăng nhập không tồn tại !!!"; } } else { Active = true; Message = "Vui lòng điền tên đăng nhập !!!"; } }); Check_Command = new RelayCommand <Button>(p => { if (string.IsNullOrEmpty(Tendangnhap) || string.IsNullOrEmpty(Maxacthuc)) { return(false); } return(true); }, p => { Model.TAIKHOAN TK = Model.DataProvider.Ins.DB.TAIKHOANs.Where(x => x.ten_taikhoan == Tendangnhap).SingleOrDefault(); if (Maxacthuc == Makhoiphuc) { if (TK.NHANVIEN.ma_quyen == 1) { View.View_Quanly.Manhinhchinh view = new View.View_Quanly.Manhinhchinh(); view.Show(); //MessageBox.Show("Đăng nhập thành công", "THÔNG BÁO"); } else { View.View_Thukho.Manhinhchinh view = new View.View_Thukho.Manhinhchinh(); view.Show(); //MessageBox.Show("Đăng nhập thành công", "THÔNG BÁO"); } CurrentUser = TK; Makhoiphuc = ""; Maxacthuc = ""; Window w = getWindowParent(p) as Window; if (w != null) { w.Close(); } Chuyentrangthai_Mo(CurrentUser); } else { Active = true; Message = "Mã xác thực sai"; } }); #endregion #endregion #region Thay doi thong tin getNewCurrentPass_Command = new RelayCommand <PasswordBox>(p => { if (p.Password.Length < 5) { return(false); } if (string.IsNullOrEmpty(p.Password)) { return(false); } return(true); }, p => { Matkhaumoi = p.Password; }); getNewCurrentRePass_Command = new RelayCommand <PasswordBox>(p => { if (p.Password.Length < 5) { return(false); } if (string.IsNullOrEmpty(p.Password)) { return(false); } return(true); }, p => { XacnhanMatkhaumoi = p.Password; }); Update_Command = new RelayCommand <Button>(p => { if (string.IsNullOrEmpty(Tentkmoi) || string.IsNullOrEmpty(CurrentUser.email) || string.IsNullOrEmpty(CurrentUser.NHANVIEN.ten_nhanvien)) { return(false); } if (!MyStaticMethods.CheckEmail(CurrentUser.email)) { return(false); } return(true); }, p => { if (!Kiemtratendangnhap(Tentkmoi)) { if (!string.IsNullOrEmpty(Matkhaumoi) && !string.IsNullOrEmpty(XacnhanMatkhaumoi)) { if (Matkhaumoi == XacnhanMatkhaumoi) { CurrentUser.matkhau = MyStaticMethods.MD5Hash(MyStaticMethods.Base64Encode(Matkhaumoi)); } } CurrentUser.ten_taikhoan = Tentkmoi; Model.DataProvider.Ins.DB.SaveChanges(); Active = true; Message = "Đã cập nhật thông tin !!!"; } else { if (!string.IsNullOrEmpty(Matkhaumoi) && !string.IsNullOrEmpty(XacnhanMatkhaumoi)) { if (Matkhaumoi == XacnhanMatkhaumoi) { CurrentUser.matkhau = MyStaticMethods.MD5Hash(MyStaticMethods.Base64Encode(Matkhaumoi)); } } Model.DataProvider.Ins.DB.SaveChanges(); Active = true; Message = "Đã cập nhật thông tin !!! Không sửa tên đăng nhập"; } }); Back_Command = new RelayCommand <Button>(p => { return(true); }, p => { Window w = getWindowParent(p) as Window; if (w != null) { CurrentUser = Model.DataProvider.Ins.DB.TAIKHOANs.Where(x => x.ma_taikhoan == CurrentUser.ma_taikhoan).SingleOrDefault(); w.Close(); } }); #endregion #region Phan tinh trang Status_Command = new RelayCommand <object>(p => { return(true); }, p => { View.View_Quanly.Tinhtrang_nguoidung view = new View.View_Quanly.Tinhtrang_nguoidung(); view.WindowStartupLocation = WindowStartupLocation.CenterScreen; view.ShowDialog(); }); Refesh_State_Command = new RelayCommand <object>(p => { return(true); }, p => { Capnhattrangthai(); }); #endregion #region Phan sap xep OrderbyTennhanvien_Command = new RelayCommand <object>(p => { if (List.Count() == 0) { return(false); } return(true); }, p => { if (p == null) { ObservableCollection <Model.TAIKHOAN> chkList = new ObservableCollection <Model.TAIKHOAN>(List.OrderByDescending(x => x.NHANVIEN.ten_nhanvien)); if (List[0] == chkList[0]) { List = new ObservableCollection <Model.TAIKHOAN>(List.OrderBy(x => x.NHANVIEN.ten_nhanvien)); } else { List = new ObservableCollection <Model.TAIKHOAN>(chkList); } } else if (p != null) { ObservableCollection <Model.TAIKHOAN> chkList = new ObservableCollection <Model.TAIKHOAN>(List_Tinhtrang.OrderByDescending(x => x.NHANVIEN.ten_nhanvien)); if (List_Tinhtrang[0] == chkList[0]) { List_Tinhtrang = new ObservableCollection <Model.TAIKHOAN>(List_Tinhtrang.OrderBy(x => x.NHANVIEN.ten_nhanvien)); } else { List_Tinhtrang = new ObservableCollection <Model.TAIKHOAN>(chkList); } } }); OrderbyTentaikhoan_Command = new RelayCommand <object>(p => { if (List.Count() == 0) { return(false); } return(true); }, p => { if (p == null) { ObservableCollection <Model.TAIKHOAN> chkList = new ObservableCollection <Model.TAIKHOAN>(List.OrderByDescending(x => x.ten_taikhoan)); if (List[0] == chkList[0]) { List = new ObservableCollection <Model.TAIKHOAN>(List.OrderBy(x => x.ten_taikhoan)); } else { List = new ObservableCollection <Model.TAIKHOAN>(chkList); } } else if (p != null) { ObservableCollection <Model.TAIKHOAN> chkList = new ObservableCollection <Model.TAIKHOAN>(List_Tinhtrang.OrderByDescending(x => x.ten_taikhoan)); if (List_Tinhtrang[0] == chkList[0]) { List_Tinhtrang = new ObservableCollection <Model.TAIKHOAN>(List_Tinhtrang.OrderBy(x => x.ten_taikhoan)); } else { List_Tinhtrang = new ObservableCollection <Model.TAIKHOAN>(chkList); } } }); OrderbyTinhtrang_Command = new RelayCommand <object>(p => { if (List_Tinhtrang.Count() == 0) { return(false); } return(true); }, p => { ObservableCollection <Model.TAIKHOAN> chkList = new ObservableCollection <Model.TAIKHOAN>(List_Tinhtrang.OrderByDescending(x => x.IsLogin)); if (List_Tinhtrang[0] == chkList[0]) { List_Tinhtrang = new ObservableCollection <Model.TAIKHOAN>(List.OrderBy(x => x.IsLogin)); } else { List_Tinhtrang = new ObservableCollection <Model.TAIKHOAN>(chkList); } }); #endregion }
public LowControlBar_ViewModel() { ToMain_Command = new RelayCommand <UserControl>(p => { return(true); }, p => { Window windowparent = getParent(p) as Window; if (p.Uid.ToString() == "QL") { View.View_Quanly.Manhinhchinh view = new View.View_Quanly.Manhinhchinh(); view.WindowState = windowparent.WindowState; view.WindowStartupLocation = WindowStartupLocation.CenterScreen; view.Show(); } else if (p.Uid.ToString() == "TK") { View.View_Thukho.Manhinhchinh view = new View.View_Thukho.Manhinhchinh(); view.WindowState = windowparent.WindowState; view.WindowStartupLocation = WindowStartupLocation.CenterScreen; view.Show(); } windowparent.Close(); }); Account_Command = new RelayCommand <UserControl>(p => { return(true); }, p => { if (p.Uid.ToString() == "QL") { View.View_Quanly.Thongtin_taikhoan view = new View.View_Quanly.Thongtin_taikhoan(); view.ShowDialog(); } else if (p.Uid.ToString() == "TK") { View.View_Thukho.Thongtin_taikhoan view = new View.View_Thukho.Thongtin_taikhoan(); view.ShowDialog(); } }); Logout_Command = new RelayCommand <UserControl>(p => { return(true); }, p => { if (ViewModel.Taikhoan_ViewModel.Glo_CurrentUser != null) { ViewModel.Taikhoan_ViewModel.Chuyentrangthai_Dong(ViewModel.Taikhoan_ViewModel.Glo_CurrentUser); } Dangnhap dangnhap = new Dangnhap(); dangnhap.Show(); Window windowparent = getParent(p) as Window; if (windowparent != null) { windowparent.Close(); } }); }