Пример #1
0
 /// <summary>
 /// 增加进程信息。
 /// </summary>
 /// <param name="task">
 /// 进程信息。
 /// </param>
 /// <param name="taskType">
 /// 进程信息类型。
 /// </param>
 /// <returns>
 /// True为添加成功。
 /// False为添加失败。
 /// </returns>
 public bool AddTask(string task, TASK_TYPE_FLAGS taskType)
 {
     if (AddList.Any(tmp => string.Equals(tmp, task, StringComparison.CurrentCultureIgnoreCase)))
     {
         return(false);
     }
     if (DelList.Any(tmp => string.Equals(tmp, task, StringComparison.CurrentCultureIgnoreCase)))
     {
         DelList.Remove(task);
         return(true);
     }
     if (OriginList.Any(tmp =>
                        string.Equals(tmp, task, StringComparison.CurrentCultureIgnoreCase)))
     {
         return(false);
     }
     AddList.AddLast(task);
     return(true);
 }
Пример #2
0
 /// <summary>
 /// 修改进程信息。
 /// </summary>
 /// <param name="frmTask">
 /// 需修改的进程信息。
 /// </param>
 /// <param name="nowTask">
 /// 修改为的进程信息。
 /// </param>
 /// <param name="taskType">
 /// 进程信息类型。
 /// </param>
 /// <returns>
 /// True为修改成功。
 /// False为修改失败。
 /// </returns>
 public bool ModifyTask(string frmTask, string nowTask, TASK_TYPE_FLAGS taskType)
 {
     if (AddList.Any(tmp => string.Equals(tmp, nowTask, StringComparison.CurrentCultureIgnoreCase)))
     {
         return(false);
     }
     if (DelList.Any(tmp => string.Equals(tmp, nowTask, StringComparison.CurrentCultureIgnoreCase)))
     {
         DelList.AddLast(frmTask);
         DelList.Remove(nowTask);
         return(true);
     }
     if (OriginList.Any(tmp =>
                        string.Equals(tmp, nowTask, StringComparison.CurrentCultureIgnoreCase)))
     {
         return(false);
     }
     DelList.AddLast(frmTask);
     AddList.AddLast(nowTask);
     return(true);
 }
Пример #3
0
        public Danhmuc_ViewModel()
        {
            List    = new ObservableCollection <Model.Danhmuc>(Model.DataProvider.Ins.DB.Danhmucs);
            DelList = new ObservableCollection <Model.Danhmuc>();

            OpenInsert      = false;
            OpenUpdate      = false;
            OpenDelete      = false;
            OpenMultiDelete = false;
            IsActive        = false;

            CloseDialog_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                OpenInsert      = false;
                OpenUpdate      = false;
                OpenDelete      = false;
                OpenMultiDelete = false;

                SelectedItem = null;
            });

            CloseAlert_Command = new RelayCommand <object>(p =>
            {
                return(true);
            },
                                                           p =>
            {
                IsActive = false;
            });

            #region Load

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List    = new ObservableCollection <Model.Danhmuc>(Model.DataProvider.Ins.DB.Danhmucs);
                DelList = new ObservableCollection <Model.Danhmuc>();

                OpenInsert      = false;
                OpenUpdate      = false;
                OpenDelete      = false;
                OpenMultiDelete = false;
                IsActive        = false;

                SelectedItem = null;
            });

            #endregion

            #region Search

            Search_Command = new RelayCommand <TextBox>(p =>
            {
                return(true);
            }, p =>
            {
                if (p.Text != string.Empty)
                {
                    List = new ObservableCollection <Model.Danhmuc>(List.Where(x => x.ten_danhmuc.ToLower().Contains(p.Text.ToLower())));
                }
                else
                {
                    List = new ObservableCollection <Model.Danhmuc>(Model.DataProvider.Ins.DB.Danhmucs);
                }
            });

            #endregion

            #region Sort

            SortbyName_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Danhmuc>(List.OrderByDescending(x => x.ten_danhmuc));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Danhmuc>(List.OrderBy(x => x.ten_danhmuc));
                }
                else
                {
                    List = chk_list;
                }
            });

            #endregion

            #region Insert

            OpenformInsert_Command = new RelayCommand <object>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenDelete == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                OpenInsert = true;
            });

            Insert_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Tendanhmuc) || string.IsNullOrEmpty(Mota))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Model.Danhmuc item = new Model.Danhmuc()
                {
                    ma_danhmuc   = Src.MyStaticMethods.RandomString(10, false),
                    ten_danhmuc  = Tendanhmuc,
                    mota_danhmuc = Mota
                };

                Model.DataProvider.Ins.DB.Danhmucs.Add(item);
                Model.DataProvider.Ins.DB.SaveChanges();

                List.Insert(0, item);
                OpenInsert = false;

                IsActive = true;
                Message  = "Thêm mới thành công !!!";
            });

            #endregion

            #region Update

            OpenformUpdate_Command = new RelayCommand <Button>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenDelete == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = Model.DataProvider.Ins.DB.Danhmucs.Where(x => x.ma_danhmuc == (p.Uid)).SingleOrDefault();

                OpenUpdate = true;
            });

            Update_Command = new RelayCommand <object>(p =>
            {
                if (SelectedItem == null)
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(SelectedItem.ten_danhmuc))
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(SelectedItem.mota_danhmuc))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                var item = Model.DataProvider.Ins.DB.Danhmucs.Where(x => x.ma_danhmuc == SelectedItem.ma_danhmuc).SingleOrDefault();

                item.ten_danhmuc  = SelectedItem.ten_danhmuc;
                item.mota_danhmuc = SelectedItem.mota_danhmuc;
                Model.DataProvider.Ins.DB.SaveChanges();

                List = new ObservableCollection <Model.Danhmuc>(Model.DataProvider.Ins.DB.Danhmucs);

                OpenUpdate = false;

                SelectedItem = null;

                IsActive = true;
                Message  = "Chỉnh sửa thành công !!!";
            });

            #endregion

            #region Delete

            OpenformDelete_Command = new RelayCommand <Button>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenDelete == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = Model.DataProvider.Ins.DB.Danhmucs.Where(x => x.ma_danhmuc == (p.Uid)).SingleOrDefault();

                OpenDelete = true;
            });

            Delete_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                Model.Danhmuc item = Model.DataProvider.Ins.DB.Danhmucs.Where(x => x.ma_danhmuc == (SelectedItem.ma_danhmuc)).SingleOrDefault();
                Model.DataProvider.Ins.DB.Danhmucs.Remove(item);
                Model.DataProvider.Ins.DB.SaveChanges();

                OpenDelete = false;

                List.Remove(item);

                IsActive = true;
                Message  = "Xóa thành công !!!";
            });

            #endregion

            #region MultiDelete

            OpenformMultiDelete_Command = new RelayCommand <object>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenMultiDelete == true || OpenDelete == true)
                {
                    return(false);
                }

                if (DelList.Count() == 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                OpenMultiDelete = true;
            });

            AddDelList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DelList.Add(List.Where(x => x.ma_danhmuc == (p.Uid)).SingleOrDefault());
            });

            RemoveDelList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DelList.Remove(List.Where(x => x.ma_danhmuc == (p.Uid)).SingleOrDefault());
            });

            MultiDelete_Command = new RelayCommand <object>(p =>
            {
                if (DelList.Count() == 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Removeforever_IteminDb();
                RemoveIteminList();

                DelList         = new ObservableCollection <Model.Danhmuc>();
                OpenMultiDelete = false;

                IsActive = true;
                Message  = "Xóa thành công !!!";
            });

            #endregion
        }
Пример #4
0
        public Taikhoan_ViewModel()
        {
            List    = new ObservableCollection <Model.Taikhoan>(Model.DataProvider.Ins.DB.Taikhoans);
            DelList = new ObservableCollection <Model.Taikhoan>();

            List_Quyen = new ObservableCollection <Model.Quyentruycap>(Model.DataProvider.Ins.DB.Quyentruycaps);
            SQuyen     = List_Quyen.First();

            OpenInsert      = false;
            OpenMultiDelete = false;
            IsActive        = false;

            CloseDialog_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                OpenInsert      = false;
                OpenMultiDelete = false;
                OpenUpdate      = false;
            });

            CloseAlert_Command = new RelayCommand <object>(p =>
            {
                return(true);
            },
                                                           p =>
            {
                IsActive = false;
            });

            #region Load

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List    = new ObservableCollection <Model.Taikhoan>(Model.DataProvider.Ins.DB.Taikhoans);
                DelList = new ObservableCollection <Model.Taikhoan>();

                List_Quyen = new ObservableCollection <Model.Quyentruycap>(Model.DataProvider.Ins.DB.Quyentruycaps);
            });

            #endregion

            #region Insert

            OpenformInsert_Command = new RelayCommand <object>(p =>
            {
                if (OpenInsert == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                OpenInsert = true;
            });

            PasswordChange_Command = new RelayCommand <PasswordBox>(p =>
            {
                if (p.Password == string.Empty)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Matkhau = p.Password;
            });

            RePasswordChange_Command = new RelayCommand <PasswordBox>(p =>
            {
                if (p.Password == string.Empty)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Nhaplaimatkhau = p.Password;
            });

            Insert_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Tendangnhap) || string.IsNullOrEmpty(Tennhanvien) ||
                    string.IsNullOrEmpty(Matkhau) || string.IsNullOrEmpty(Nhaplaimatkhau) || string.IsNullOrEmpty(Sodienthoai))
                {
                    return(false);
                }

                if (SQuyen == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                if (Matkhau == Nhaplaimatkhau)
                {
                    if (Model.DataProvider.Ins.DB.Taikhoans.Where(x => x.ten_dangnhap == Tendangnhap).Count() == 0)
                    {
                        Model.Taikhoan item = new Model.Taikhoan()
                        {
                            ma_taikhoan  = Guid.NewGuid().ToString(),
                            ten_dangnhap = Tendangnhap,
                            matkhau      = Src.MyStaticMethods.MD5Hash(Matkhau),
                            tennhanvien  = Tennhanvien,
                            sodienthoai  = Sodienthoai,
                            ma_quyen     = SQuyen.ma_quyen
                        };

                        Model.DataProvider.Ins.DB.Taikhoans.Add(item);
                        Model.DataProvider.Ins.DB.SaveChanges();

                        List.Insert(0, item);

                        OpenInsert = false;

                        IsActive = true;
                        Message  = "Thêm mới thành công !!!";
                    }
                    else
                    {
                        OpenInsert = false;

                        IsActive = true;
                        Message  = "Tên đăng nhập đã tồn tại !!!";
                    }
                }
                else
                {
                    OpenInsert = false;

                    IsActive = true;
                    Message  = "Mật khẩu và xác nhận mật khẩu không trùng khớp !!!";
                }
            });

            #endregion

            #region Search

            Search_Command = new RelayCommand <TextBox>(p =>
            {
                return(true);
            }, p =>
            {
                if (p.Text != string.Empty)
                {
                    List = new ObservableCollection <Model.Taikhoan>(List.Where(x => (x.ten_dangnhap.ToLower().Contains(p.Text.ToLower())) || (x.tennhanvien.ToLower().Contains(p.Text.ToLower())) || (x.sodienthoai.Contains(p.Text))));
                }
                else
                {
                    List = new ObservableCollection <Model.Taikhoan>(Model.DataProvider.Ins.DB.Taikhoans);
                }
            });

            #endregion

            #region Sort

            SortbyUserName_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Taikhoan>(List.OrderByDescending(x => x.ten_dangnhap));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Taikhoan>(List.OrderBy(x => x.ten_dangnhap));
                }
                else
                {
                    List = chk_list;
                }
            });

            SortbyRealName_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Taikhoan>(List.OrderByDescending(x => x.tennhanvien));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Taikhoan>(List.OrderBy(x => x.tennhanvien));
                }
                else
                {
                    List = chk_list;
                }
            });

            SortbyRole_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Taikhoan>(List.OrderByDescending(x => x.Quyentruycap.ten_quyen));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Taikhoan>(List.OrderBy(x => x.Quyentruycap.ten_quyen));
                }
                else
                {
                    List = chk_list;
                }
            });

            #endregion

            #region MultiDelete

            OpenformMultiDelete_Command = new RelayCommand <object>(p =>
            {
                if (OpenInsert == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                if (DelList.Count() == 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                OpenMultiDelete = true;
            });

            AddDelList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DelList.Add(List.Where(x => x.ma_taikhoan == (p.Uid)).SingleOrDefault());
            });

            RemoveDelList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DelList.Remove(List.Where(x => x.ma_taikhoan == (p.Uid)).SingleOrDefault());
            });

            MultiDelete_Command = new RelayCommand <object>(p =>
            {
                if (DelList.Count() == 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Removeforever_IteminDb();
                RemoveIteminList();

                DelList         = new ObservableCollection <Model.Taikhoan>();
                OpenMultiDelete = false;

                IsActive = true;
                Message  = "Xóa thành công !!!";
            });

            #endregion

            #region Login

            LoadLoginform_Command = new RelayCommand <Window>(p =>
            {
                return(true);
            }, p =>
            {
                LoginUsername = string.Empty;
                LoginPass     = string.Empty;

                if (!File.Exists("Pass.txt"))
                {
                    FileStream fs;
                    fs = new FileStream("Pass.txt", FileMode.Create);
                    StreamWriter sWriter = new StreamWriter(fs, Encoding.UTF8);

                    sWriter.WriteLine("Hello World!");
                    sWriter.Flush();
                    fs.Close();
                }

                string[] lines = File.ReadAllLines("Pass.txt");
                if (lines[lines.Length - 1] == "1")
                {
                    LoginUsername   = Src.MyStaticMethods.Base64Decode(lines[lines.Length - 3]);
                    LoginPass       = Src.MyStaticMethods.Base64Decode(lines[lines.Length - 2]);
                    RememberChecked = true;
                }

                foreach (PasswordBox pb in Src.MyStaticMethods.FindVisualChildren <PasswordBox>(p))
                {
                    if (pb.Name == "pb_pass")
                    {
                        pb.Password = LoginPass;
                    }
                }
            });

            GetPassLogin_Command = new RelayCommand <PasswordBox>(p =>
            {
                if (p.Password == string.Empty)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                LoginPass = p.Password;
            });

            Login_Command = new RelayCommand <Button>(p =>
            {
                if (string.IsNullOrEmpty(LoginUsername) || string.IsNullOrEmpty(LoginPass))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                var pass      = Src.MyStaticMethods.MD5Hash(LoginPass);
                int itemcount = Model.DataProvider.Ins.DB.Taikhoans.Where(x => x.ten_dangnhap == LoginUsername && x.matkhau == pass).Count();

                if (itemcount != 0)
                {
                    CheckRemember();

                    View.Manhinhchinh mahinhchinh = new View.Manhinhchinh();
                    mahinhchinh.Show();

                    Window wd = Src.MyStaticMethods.getWindowParent(p) as Window;
                    if (wd != null)
                    {
                        wd.Close();
                    }

                    CurrentUser = Model.DataProvider.Ins.DB.Taikhoans.Where(x => x.ten_dangnhap == LoginUsername && x.matkhau == pass).SingleOrDefault();
                }
                else
                {
                    IsActive = true;
                    Message  = "Kiểm tra lại tên đăng nhập và mật khẩu";
                }
            });

            CloseLoginform_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                Application.Current.Shutdown();
            });

            #endregion

            #region Change

            LoadInfor_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                Tendnmoi = CurrentUser.ten_dangnhap;
            });

            CurPasswordChange_Command = new RelayCommand <PasswordBox>(p =>
            {
                if (p.Password == string.Empty)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                CurPass = p.Password;
            });

            CurRePasswordChange_Command = new RelayCommand <PasswordBox>(p =>
            {
                if (p.Password == string.Empty)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                CurrePass = p.Password;
            });

            ChangeInfor_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(CurrentUser.ten_dangnhap) || string.IsNullOrEmpty(CurrentUser.sodienthoai))
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(Tendnmoi))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Model.Taikhoan tk = Model.DataProvider.Ins.DB.Taikhoans.Where(x => x.ma_taikhoan == CurrentUser.ma_taikhoan).SingleOrDefault();
                tk.tennhanvien    = CurrentUser.tennhanvien;
                tk.sodienthoai    = CurrentUser.sodienthoai;

                Model.DataProvider.Ins.DB.SaveChanges();


                if (Model.DataProvider.Ins.DB.Taikhoans.Where(x => x.ten_dangnhap == Tendnmoi).Count() == 0)
                {
                    tk.ten_dangnhap = CurrentUser.ten_dangnhap;
                    Model.DataProvider.Ins.DB.SaveChanges();
                }

                if (!string.IsNullOrEmpty(CurPass))
                {
                    if (!string.IsNullOrEmpty(CurrePass) && CurrePass == CurrePass)
                    {
                        tk.matkhau = Src.MyStaticMethods.MD5Hash(CurPass);
                        Model.DataProvider.Ins.DB.SaveChanges();
                    }
                    else
                    {
                        IsActive = true;
                        Message  = "Mật khẩu và xác nhận mật khẩu không trùng khớp !!!";
                    }
                }

                IsActive = true;
                Message  = "Đã cập nhật thông tin !!!";
            });

            #endregion

            #region Update Role

            OpenformUpdate_Command = new RelayCommand <Button>(p =>
            {
                if (OpenInsert == true || OpenMultiDelete == true || OpenUpdate == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = Model.DataProvider.Ins.DB.Taikhoans.Where(x => x.ma_taikhoan == (p.Uid)).SingleOrDefault();

                OpenUpdate = true;
            });

            Update_Command = new RelayCommand <object>(p =>
            {
                if (SelectedItem == null)
                {
                    return(false);
                }

                if (SelectedItem.Quyentruycap == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                var item = Model.DataProvider.Ins.DB.Taikhoans.Where(x => x.ma_taikhoan == SelectedItem.ma_taikhoan).SingleOrDefault();

                item.Quyentruycap = SelectedItem.Quyentruycap;
                Model.DataProvider.Ins.DB.SaveChanges();

                OpenUpdate = false;

                IsActive = true;
                Message  = "Đã cập nhật quyền truy cập !!!";

                List = new ObservableCollection <Model.Taikhoan>(Model.DataProvider.Ins.DB.Taikhoans);
            });

            #endregion
        }
Пример #5
0
        public Doan_ViewModel()
        {
            List         = new ObservableCollection <Model.Sanpham>(Model.DataProvider.Ins.DB.Sanphams);
            DelList      = new ObservableCollection <Model.Sanpham>();
            List_Danhmuc = new ObservableCollection <Model.Danhmuc>(Model.DataProvider.Ins.DB.Danhmucs);

            OpenInsert      = false;
            OpenUpdate      = false;
            OpenDelete      = false;
            OpenMultiDelete = false;
            IsActive        = false;

            CloseDialog_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                OpenInsert      = false;
                OpenUpdate      = false;
                OpenDelete      = false;
                OpenMultiDelete = false;

                SelectedItem = null;
            });

            CloseAlert_Command = new RelayCommand <object>(p =>
            {
                return(true);
            },
                                                           p =>
            {
                IsActive = false;
            });

            #region Load

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List    = new ObservableCollection <Model.Sanpham>(Model.DataProvider.Ins.DB.Sanphams);
                DelList = new ObservableCollection <Model.Sanpham>();

                List_Danhmuc = new ObservableCollection <Model.Danhmuc>(Model.DataProvider.Ins.DB.Danhmucs);

                OpenInsert      = false;
                OpenUpdate      = false;
                OpenDelete      = false;
                OpenMultiDelete = false;
                IsActive        = false;

                SelectedItem = null;
            });

            #endregion

            #region Insert

            OpenformInsert_Command = new RelayCommand <object>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenDelete == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                OpenInsert = true;
            });

            Insert_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Ten) || string.IsNullOrEmpty(Gia) || string.IsNullOrEmpty(Mota))
                {
                    return(false);
                }

                int dongianhap = 0;
                if (!int.TryParse(Gia.Replace(" ", String.Empty), out dongianhap))
                {
                    return(false);
                }

                if (SDanhmuc == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Model.Sanpham item = new Model.Sanpham()
                {
                    ma_sanpham   = ((Src.MyStaticMethods.RandomString(2, false)) + (Src.MyStaticMethods.RandomInt(4))),
                    Danhmuc      = SDanhmuc,
                    ten_sanpham  = Ten,
                    dongia       = Convert.ToDouble(Gia.Replace(" ", String.Empty)),
                    mota_sanpham = Mota,
                    tendonvi     = Tendonvi
                };

                Model.DataProvider.Ins.DB.Sanphams.Add(item);
                Model.DataProvider.Ins.DB.SaveChanges();

                List.Insert(0, item);

                OpenInsert = false;

                IsActive = true;
                Message  = "Thêm mới thành công !!!";
            });

            #endregion

            #region Update

            OpenformUpdate_Command = new RelayCommand <Button>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenDelete == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = Model.DataProvider.Ins.DB.Sanphams.Where(x => x.ma_sanpham == (p.Uid)).SingleOrDefault();

                OpenUpdate = true;
            });

            Update_Command = new RelayCommand <object>(p =>
            {
                if (SelectedItem == null)
                {
                    return(false);
                }

                int dongianhap = 0;
                if (!int.TryParse(SelectedItem.dongia.ToString().Replace(" ", String.Empty), out dongianhap))
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(SelectedItem.ten_sanpham) || string.IsNullOrEmpty(SelectedItem.mota_sanpham) || string.IsNullOrEmpty(SelectedItem.dongia.ToString()))
                {
                    return(false);
                }

                if (SelectedItem.Danhmuc == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Model.Sanpham item = Model.DataProvider.Ins.DB.Sanphams.Where(x => x.ma_sanpham == SelectedItem.ma_sanpham).SingleOrDefault();

                item.Danhmuc      = SelectedItem.Danhmuc;
                item.ten_sanpham  = SelectedItem.ten_sanpham;
                item.dongia       = SelectedItem.dongia;
                item.mota_sanpham = SelectedItem.mota_sanpham;
                item.tendonvi     = SelectedItem.tendonvi;

                Model.DataProvider.Ins.DB.SaveChanges();

                List = new ObservableCollection <Model.Sanpham>(Model.DataProvider.Ins.DB.Sanphams);

                OpenUpdate = false;

                SelectedItem = null;

                IsActive = true;
                Message  = "Chỉnh sửa thành công !!!";
            });

            #endregion

            #region Search

            Search_Command = new RelayCommand <TextBox>(p =>
            {
                return(true);
            }, p =>
            {
                if (p.Text != string.Empty)
                {
                    List = new ObservableCollection <Model.Sanpham>(List.Where(x => (x.ten_sanpham.ToLower().Contains(p.Text.ToLower())) || (x.Danhmuc.ten_danhmuc.ToLower().Contains(p.Text.ToLower()))));
                }
                else
                {
                    List = new ObservableCollection <Model.Sanpham>(Model.DataProvider.Ins.DB.Sanphams);
                }
            });

            #endregion

            #region Sort

            SortbyName_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Sanpham>(List.OrderByDescending(x => x.ten_sanpham));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Sanpham>(List.OrderBy(x => x.ten_sanpham));
                }
                else
                {
                    List = chk_list;
                }
            });

            SortbyPrice_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Sanpham>(List.OrderByDescending(x => x.dongia));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Sanpham>(List.OrderBy(x => x.dongia));
                }
                else
                {
                    List = chk_list;
                }
            });

            SortbyUnit_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Sanpham>(List.OrderByDescending(x => x.tendonvi));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Sanpham>(List.OrderBy(x => x.tendonvi));
                }
                else
                {
                    List = chk_list;
                }
            });


            SortbyCategory_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                var chk_list = new ObservableCollection <Model.Sanpham>(List.OrderByDescending(x => x.Danhmuc.ten_danhmuc));

                if (chk_list[0] == List[0])
                {
                    List = new ObservableCollection <Model.Sanpham>(List.OrderBy(x => x.Danhmuc.ten_danhmuc));
                }
                else
                {
                    List = chk_list;
                }
            });

            #endregion

            #region Delete

            OpenformDelete_Command = new RelayCommand <Button>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenDelete == true || OpenMultiDelete == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = Model.DataProvider.Ins.DB.Sanphams.Where(x => x.ma_sanpham == (p.Uid)).SingleOrDefault();

                OpenDelete = true;
            });

            Delete_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                Model.Sanpham item = Model.DataProvider.Ins.DB.Sanphams.Where(x => x.ma_sanpham == (SelectedItem.ma_sanpham)).SingleOrDefault();
                Model.DataProvider.Ins.DB.Sanphams.Remove(item);
                Model.DataProvider.Ins.DB.SaveChanges();

                OpenDelete = false;

                List.Remove(item);

                IsActive = true;
                Message  = "Xóa thành công !!!";
            });

            #endregion

            #region MultiDelete

            OpenformMultiDelete_Command = new RelayCommand <object>(p =>
            {
                if (Taikhoan_ViewModel.CurrentUser.ma_quyen != 1)
                {
                    return(false);
                }

                if (OpenInsert == true || OpenUpdate == true || OpenMultiDelete == true || OpenDelete == true)
                {
                    return(false);
                }

                if (DelList.Count() == 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                OpenMultiDelete = true;
            });

            AddDelList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DelList.Add(List.Where(x => x.ma_sanpham == (p.Uid)).SingleOrDefault());
            });

            RemoveDelList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DelList.Remove(List.Where(x => x.ma_sanpham == (p.Uid)).SingleOrDefault());
            });

            MultiDelete_Command = new RelayCommand <object>(p =>
            {
                if (DelList.Count() == 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Removeforever_IteminDb();
                RemoveIteminList();

                DelList         = new ObservableCollection <Model.Sanpham>();
                OpenMultiDelete = false;

                IsActive = true;
                Message  = "Xóa thành công !!!";
            });

            #endregion

            #region Filter

            Filter_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                if (SDanhmuc_Filter != null)
                {
                    List = new ObservableCollection <Model.Sanpham>(List.Where(x => x.Danhmuc == SDanhmuc_Filter));
                }
                else
                {
                    List = new ObservableCollection <Model.Sanpham>(Model.DataProvider.Ins.DB.Sanphams);
                }
            });

            #endregion
        }