public int DisplayTodayDeletes()
 {
     ClearDataGrid(Viewer.DataGridView_Delete);
     DeleteList = Logic.GetTodayDeletes().ToList();
     foreach (var delete in DeleteList)
     {
         Viewer.AddToDeleteGrid(delete);
     }
     return(DeleteList.Count());
 }
 private void RemoveIteminDb()
 {
     for (int i = 0; i < DeleteList.Count(); i++)
     {
         foreach (var item in Model.DataProvider.Ins.DB.KHACHHANGs.ToList())
         {
             while (item == DeleteList[i])
             {
                 item.IsDeleted = true;
                 Model.DataProvider.Ins.DB.SaveChanges();
                 break;
             }
         }
     }
 }
 private void RemoveIteminDb()
 {
     for (int i = 0; i < DeleteList.Count(); i++)
     {
         foreach (var item in Model.DataProvider.Ins.DB.TAIKHOANs)
         {
             while (item == DeleteList[i])
             {
                 Model.DataProvider.Ins.DB.TAIKHOANs.Remove(item);
                 break;
             }
         }
     }
     Model.DataProvider.Ins.DB.SaveChanges();
 }
Exemple #4
0
 private void Capnhat_dboTaiKhoan()
 {
     for (int i = 0; i < DeleteList.Count(); i++)
     {
         foreach (var item in Model.DataProvider.Ins.DB.TAIKHOANs.ToList())
         {
             while (item.NHANVIEN == DeleteList[i])
             {
                 item.IsDeleted = true;
                 Model.DataProvider.Ins.DB.SaveChanges();
                 break;
             }
         }
     }
 }
        public Khachhang_ViewModel()
        {
            List       = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));
            DeleteList = new ObservableCollection <Model.KHACHHANG>();

            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;
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List       = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));
                DeleteList = new ObservableCollection <Model.KHACHHANG>();

                Active = false;
                IsOpen = false;
            });

            #region Phan them
            Insert_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Tenkhachhang) || string.IsNullOrEmpty(Sodienthoai) || string.IsNullOrEmpty(Diachi))
                {
                    return(false);
                }

                long i = 0;
                if (!long.TryParse(Sodienthoai, out i))
                {
                    return(false);
                }

                var check = Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.ten_khachhang == Tenkhachhang);
                if (check == null || check.Count() != 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = null;

                Model.KHACHHANG newItem = new Model.KHACHHANG()
                {
                    ma_khachhang  = Guid.NewGuid().ToString(),
                    ten_khachhang = Tenkhachhang,
                    diachi        = Diachi,
                    sodienthoai   = Sodienthoai,
                    IsDeleted     = false
                };

                Model.Khachhang_Service.Insert(newItem);

                List.Insert(0, newItem);
                SelectedItem = newItem;

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

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

                long i = 0;
                if (!long.TryParse(Sodienthoai, out i))
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(Tenkhachhang) || string.IsNullOrEmpty(Sodienthoai) || string.IsNullOrEmpty(Diachi))
                {
                    return(false);
                }

                var check = Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.ten_khachhang == Tenkhachhang && x.diachi == Diachi && x.sodienthoai == Sodienthoai);
                if (check == null || check.Count() != 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Model.KHACHHANG UpdateItem = new Model.KHACHHANG()
                {
                    ten_khachhang = Tenkhachhang,
                    sodienthoai   = Sodienthoai,
                    diachi        = Diachi
                };
                Model.Khachhang_Service.Update(UpdateItem, Makhachhang);

                for (int i = 0; i < List.Count(); i++)
                {
                    if (List[i] == SelectedItem)
                    {
                        List[i] = new Model.KHACHHANG()
                        {
                            ma_khachhang  = Makhachhang,
                            ten_khachhang = Tenkhachhang,
                            diachi        = Diachi,
                            sodienthoai   = Sodienthoai
                        };
                        break;
                    }
                }
                //MessageBox.Show("Chỉnh sửa thành công", "THÔNG BÁO");

                SelectedItem = null;
                Tenkhachhang = "";
                Sodienthoai  = "";
                Diachi       = "";

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

            #region Phan xoa

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

                return(true);
            }, p =>
            {
                IsOpen  = true;
                Content = "  Xóa các bản ghi được chọn ???";
            });


            AddDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Add(List.Where(x => x.ma_khachhang == p.Uid.ToString()).SingleOrDefault());
            });

            RemoveDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Remove(List.Where(x => x.ma_khachhang == 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.KHACHHANG>();
                IsOpen       = false;
                SelectedItem = null;
            });
            #endregion

            #region Tao moi
            Reset_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                SelectedItem = null;
                Tenkhachhang = "";
                Diachi       = "";
                Sodienthoai  = "";
            });
            #endregion

            #region Phan sap xep

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.KHACHHANG> chkList = new ObservableCollection <Model.KHACHHANG>(List.OrderByDescending(x => x.ten_khachhang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.KHACHHANG>(List.OrderBy(x => x.ten_khachhang));
                }
                else
                {
                    List = new ObservableCollection <Model.KHACHHANG>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.KHACHHANG> chkList = new ObservableCollection <Model.KHACHHANG>(List.OrderByDescending(x => x.diachi));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.KHACHHANG>(List.OrderBy(x => x.diachi));
                }
                else
                {
                    List = new ObservableCollection <Model.KHACHHANG>(chkList);
                }
            });

            #endregion
        }
Exemple #6
0
        public Loaimathang_ViewModel()
        {
            List       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
            DeleteList = new ObservableCollection <Model.LOAIHANG>();

            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;
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
                DeleteList = new ObservableCollection <Model.LOAIHANG>();

                Active = false;
                IsOpen = false;
            });

            #region Phan them
            Insert_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Tenloaihang))
                {
                    return(false);
                }

                var check = Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.ten_loaihang == Tenloaihang);
                if (check == null || check.Count() != 0)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = null;

                Model.LOAIHANG newItem = new Model.LOAIHANG()
                {
                    ma_loaihang  = MyStaticMethods.RandomString(5, false),
                    ten_loaihang = Tenloaihang,
                    mota         = (string.IsNullOrEmpty(Mota)) ? null : Mota,
                    IsDeleted    = false
                };

                Model.Loaimathang_Service.Insert(newItem);

                List.Insert(0, newItem);
                SelectedItem = newItem;

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

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

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

                return(true);
            }, p =>
            {
                Model.LOAIHANG UpdateItem = new Model.LOAIHANG()
                {
                    ten_loaihang = Tenloaihang,
                    mota         = string.IsNullOrEmpty(Mota) ? null : Mota
                };
                Model.Loaimathang_Service.Update(UpdateItem, Maloaihang);

                for (int i = 0; i < List.Count(); i++)
                {
                    if (List[i] == SelectedItem)
                    {
                        List[i] = new Model.LOAIHANG()
                        {
                            ma_loaihang  = Maloaihang,
                            ten_loaihang = Tenloaihang,
                            mota         = (string.IsNullOrEmpty(Mota)) ? null : Mota
                        };
                        break;
                    }
                }
                //MessageBox.Show("Chỉnh sửa thành công", "THÔNG BÁO");

                SelectedItem = null;
                Tenloaihang  = "";
                Mota         = "";

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

            #region Phan xoa
            AddDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Add(List.Where(x => x.ma_loaihang == p.Uid.ToString()).SingleOrDefault());
            });

            RemoveDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Remove(List.Where(x => x.ma_loaihang == p.Uid.ToString()).SingleOrDefault());
            });

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

                return(true);
            }, p =>
            {
                IsOpen  = true;
                Content = "  Xóa các bản ghi được chọn ???";
            });

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

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

                DeleteList   = new ObservableCollection <Model.LOAIHANG>();
                IsOpen       = false;
                SelectedItem = null;
            });
            #endregion

            #region Tao moi
            Reset_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                SelectedItem = null;
                Tenloaihang  = "";
                Mota         = "";
            });
            #endregion

            #region Phan sap xep

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.LOAIHANG> chkList = new ObservableCollection <Model.LOAIHANG>(List.OrderByDescending(x => x.ten_loaihang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.LOAIHANG>(List.OrderBy(x => x.ten_loaihang));
                }
                else
                {
                    List = new ObservableCollection <Model.LOAIHANG>(chkList);
                }
            });

            #endregion
        }
        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 Nhaphang_ViewModel()
        {
            TaoDS_nhap();
            DeleteList  = new ObservableCollection <Model.CHITIETPHIEUNHAP>();
            ListMathang = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));

            ListNCC_Print = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));

            Active        = false;
            IsOpen        = false;
            IsOpen_insert = false;
            IsOpen_Filter = false;
            IsOpen_prt    = 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_prt = false;
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                TaoDS_nhap();
                DeleteList  = new ObservableCollection <Model.CHITIETPHIEUNHAP>();
                ListMathang = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));

                ListNCC_Print = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));

                ListLoai_Filter       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
                ListMathang_Filter    = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                ListNhacungcap_Filter = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));

                Active        = false;
                IsOpen        = false;
                IsOpen_insert = false;
                IsOpen_Filter = false;
                IsOpen_prt    = false;
            });

            #region Tao moi
            Reset_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                SMathang        = null;
                Soluongnhap     = "";
                Soluongthucnhap = "";
                Dongianhap      = "";
                Dongiaxuat      = "";
                Phantram        = "";
                SelectedItem    = null;
            });
            #endregion

            #region Phan them

            GetvalueTextbox_Command = new RelayCommand <TextBox>(p =>
            {
                double d;
                if (!double.TryParse((p.Text), out d))
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(p.Text))
                {
                    return(false);
                }

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

                if (string.IsNullOrEmpty(Soluongnhap) || string.IsNullOrEmpty(Soluongthucnhap) || string.IsNullOrEmpty(Dongianhap))
                {
                    return(false);
                }

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

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

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

                return(true);
            }, p =>
            {
                Dongiaxuat = String.Empty;

                double phantram   = Convert.ToDouble(Phantram) / 100;
                double dongianhap = Convert.ToDouble(Dongianhap.Replace(" ", String.Empty));
                double dongiaxuat = ((phantram * dongianhap) + dongianhap);

                Dongiaxuat = dongiaxuat.ToString();
            });

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

                if (string.IsNullOrEmpty(Soluongnhap) || string.IsNullOrEmpty(Soluongthucnhap) ||
                    string.IsNullOrEmpty(Dongiaxuat) || string.IsNullOrEmpty(Dongianhap) || string.IsNullOrEmpty(Phantram))
                {
                    return(false);
                }

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

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

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

                try
                {
                    if (Convert.ToInt32(Soluongnhap) <= 0 || Convert.ToInt32(Soluongthucnhap) <= 0)
                    {
                        return(false);
                    }

                    if (Convert.ToInt32(Dongianhap) <= 0 || Convert.ToDouble(Phantram) < 0)
                    {
                        return(false);
                    }

                    if (Convert.ToInt32(Dongiaxuat) <= 0)
                    {
                        return(false);
                    }
                }
                catch (Exception) { /*Try catch de sua loi FormatException*/ }


                if (IsOpen_insert == true || IsOpen == true)
                {
                    return(false);
                }

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

                string date_str = MyStaticMethods.ConvertDate2Vn_Today();
                Ngay            = date_str;
            });

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

                if (string.IsNullOrEmpty(Soluongnhap) || string.IsNullOrEmpty(Soluongthucnhap) ||
                    string.IsNullOrEmpty(Dongiaxuat) || string.IsNullOrEmpty(Dongianhap) || string.IsNullOrEmpty(Phantram))
                {
                    return(false);
                }

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

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

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

                return(true);
            }, p =>
            {
                string date_str       = MyStaticMethods.ConvertDate2Vn_Today();
                Model.PHIEUNHAP Phieu = CheckPhieunhap(date_str);

                Model.CHITIETPHIEUNHAP newPhieu = new Model.CHITIETPHIEUNHAP()
                {
                    ma_ctphieunhap = MyStaticMethods.RandomInt(5) + "-" + SMathang.ma_mathang,
                    MATHANG        = SMathang,
                    ma_phieunhap   = Phieu.ma_phieunhap,

                    soluongnhap = Convert.ToInt32(Soluongnhap.Replace(" ", String.Empty)),
                    soluongthuc = Convert.ToInt32(Soluongthucnhap.Replace(" ", String.Empty)),
                    soluongton  = Convert.ToInt32(Soluongthucnhap.Replace(" ", String.Empty)),

                    gianhap = Convert.ToDouble(Dongianhap.Replace(" ", String.Empty)),
                    giaxuat = Convert.ToDouble(Dongiaxuat.Replace(" ", String.Empty)),

                    nguoitao  = getCurrentUser(),
                    ghichu    = Ghichu != "" ? Ghichu : null,
                    IsDeleted = false,
                };

                Model.Nhaphang_Service.Insert(newPhieu);

                List.Insert(0, newPhieu);
                SelectedItem = newPhieu;

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

            #endregion

            #region Phan xoa

            AddDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Add(List.Where(x => x.ma_ctphieunhap == p.Uid.ToString()).SingleOrDefault());
            });

            RemoveDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Remove(List.Where(x => x.ma_ctphieunhap == p.Uid.ToString()).SingleOrDefault());
            });

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

                if (IsOpen_insert == true || IsOpen == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                IsOpen  = true;
                Content = "  Xóa các bản ghi được chọn ???";
            });


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

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


                DeleteList   = new ObservableCollection <Model.CHITIETPHIEUNHAP>();
                IsOpen       = false;
                SelectedItem = null;
            });
            #endregion

            #region Phan loc

            ListLoai_Filter       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
            ListMathang_Filter    = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
            ListNhacungcap_Filter = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));

            FilterLoai_Command = new RelayCommand <ComboBox>(p =>
            {
                return(true);
            }, p =>
            {
                if (SLoai_Filter != null)
                {
                    string ma = SLoai_Filter.ma_loaihang;
                    FilterMathangby_Loai(ma);
                }
                else
                {
                    ListMathang_Filter = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                }
            });

            OpenFilter_Command = new RelayCommand <object>(p =>
            {
                if (IsOpen_Filter == true || IsOpen == true || IsOpen_insert == true || IsOpen_prt == true)
                {
                    return(false);
                }

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

            ResetFilter_Command = new RelayCommand <Button>(p =>
            {
                return(true);
            }, p =>
            {
                ListLoai_Filter       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
                ListMathang_Filter    = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                ListNhacungcap_Filter = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));

                SNhacungcap_Filter = null;
                SMathang_Filter    = null;
                SLoai_Filter       = null;
                Date_Start         = String.Empty;
                Date_End           = String.Empty;

                TaoDS_nhap();

                IsOpen_Filter = false;
            });

            Filter_Command = new RelayCommand <Button>(p =>
            {
                if (string.IsNullOrEmpty(Date_Start) || string.IsNullOrEmpty(Date_End))
                {
                    return(false);
                }

                DateTime date_start = Convert.ToDateTime(Date_Start);
                DateTime date_end   = Convert.ToDateTime(Date_End);
                if ((date_start > date_end) && DateTime.TryParse(Date_Start, out date_start) && DateTime.TryParse(Date_End, out date_end))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(Model.DataProvider.Ins.DB.CHITIETPHIEUNHAPs.Where(x => x.IsDeleted == false).OrderByDescending(x => x.ma_phieunhap));

                DateTime date_start = Convert.ToDateTime(Date_Start);
                DateTime date_end   = Convert.ToDateTime(Date_End);

                FindByDate(date_start, date_end);

                if (SMathang_Filter != null)
                {
                    FindByMH(SMathang_Filter.ma_mathang);
                }

                if (SNhacungcap_Filter != null)
                {
                    FindByNCC(SNhacungcap_Filter.ma_nhacungcap);
                }

                if (SLoai_Filter != null)
                {
                    FindByLOAI(SLoai_Filter.ma_loaihang);
                }

                IsOpen_Filter = false;
            });
            #endregion

            #region Phan sap xep

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUNHAP> chkList = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderByDescending(x => x.MATHANG.ten_mathang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderBy(x => x.MATHANG.ten_mathang));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUNHAP> chkList = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderByDescending(x => x.MATHANG.NHACUNGCAP.ten_nhacungcap));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderBy(x => x.MATHANG.NHACUNGCAP.ten_nhacungcap));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUNHAP> chkList = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderByDescending(x => MyStaticMethods.ConvertStringtoDate(x.PHIEUNHAP.ngaynhap)));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderBy(x => MyStaticMethods.ConvertStringtoDate(x.PHIEUNHAP.ngaynhap)));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUNHAP> chkList = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderByDescending(x => x.MATHANG.DONVITINH.ten_donvi));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.OrderBy(x => x.MATHANG.DONVITINH.ten_donvi));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUNHAP>(chkList);
                }
            });

            #endregion

            #region Printer

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

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

                return(true);
            }, p =>
            {
                List_Print = new ObservableCollection <Model.CHITIETPHIEUNHAP>(List.Where(x => x.MATHANG.NHACUNGCAP == SNhacungcapPrint &&
                                                                                          x.PHIEUNHAP.ngaynhap == MyStaticMethods.FormatDateString(DayPrint)));

                var list_chk = new ObservableCollection <Model.CHITIETPHIEUNHAP>();

                ItemsCount = 0;
                Tongtien   = 0;

                foreach (var item in List_Print)
                {
                    Tongtien += (double)(item.gianhap * item.soluongthuc);

                    if (list_chk.Where(x => x.MATHANG == item.MATHANG).Count() == 0)
                    {
                        list_chk.Add(item);
                    }
                }

                ItemsCount = list_chk.Count();


                DayPrintVN = MyStaticMethods.FormatDateString(DayPrint);

                View.View_Thukho.In_Nhap w = new View.View_Thukho.In_Nhap();
                w.ShowDialog();
            });

            OpenPrintDialog_Command = new RelayCommand <object>(p =>
            {
                if (IsOpen == true)
                {
                    return(false);
                }

                if (IsOpen_insert == true)
                {
                    return(false);
                }

                if (IsOpen_Filter == true)
                {
                    return(false);
                }

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

            Print_Command = new RelayCommand <Grid>(p =>
            {
                return(true);
            }, p =>
            {
                try
                {
                    PrintDialog printDialog = new PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(p, "invoice");
                    }

                    MessageBox.Show("Thành công !!!", "THÔNG BÁO");
                }
                catch (Exception) { MessageBox.Show("Có lỗi xảy ra !!!", "THÔNG BÁO"); };
            });

            PrinterFormClose_Command = new RelayCommand <Window>(p =>
            {
                return(true);
            }, p =>
            {
                if (p != null)
                {
                    p.Close();
                    IsOpen_prt = false;
                }
            });

            #endregion
        }
        public Thongke_ViewModel()
        {
            List       = new ObservableCollection <Model.Thongke>();
            DeleteList = new ObservableCollection <Model.Thongke>();

            List_nhacungcap       = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));
            FilterList_nhacungcap = new ObservableCollection <Model.NHACUNGCAP>();

            List_loaihang       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
            FilterList_loaihang = new ObservableCollection <Model.LOAIHANG>();

            List_donvi       = new ObservableCollection <Model.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
            FilterList_donvi = new ObservableCollection <Model.DONVITINH>();

            IscheckAll = true;
            IsOpen     = false;


            CloseDialog_Command = new RelayCommand <MaterialDesignThemes.Wpf.DialogHost>(p =>
            {
                return(true);
            }, p =>
            {
                p.IsOpen = false;
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List       = new ObservableCollection <Model.Thongke>();
                DeleteList = new ObservableCollection <Model.Thongke>();

                List_nhacungcap       = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));
                FilterList_nhacungcap = new ObservableCollection <Model.NHACUNGCAP>();

                List_loaihang       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
                FilterList_loaihang = new ObservableCollection <Model.LOAIHANG>();

                List_donvi       = new ObservableCollection <Model.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
                FilterList_donvi = new ObservableCollection <Model.DONVITINH>();

                IsOpen = false;
            });

            #region Them / xoa khoi FilterList_nhacungcap

            AddtoFilterNCC_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                string id = p.Uid.ToString();
                var item  = List_nhacungcap.Where(x => x.ma_nhacungcap == id).SingleOrDefault();

                FilterList_nhacungcap.Add(item);
            });

            DeletefromFilterNCC_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                string id = p.Uid.ToString();
                var item  = List_nhacungcap.Where(x => x.ma_nhacungcap == id).SingleOrDefault();

                FilterList_nhacungcap.Remove(item);
            });

            #endregion

            #region Them / xoa khoi FilterList_loaihang

            AddtoFilterLH_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                string id = p.Uid.ToString();
                var item  = List_loaihang.Where(x => x.ma_loaihang == id).SingleOrDefault();

                FilterList_loaihang.Add(item);
            });

            DeletefromFilterLH_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                string id = p.Uid.ToString();
                var item  = List_loaihang.Where(x => x.ma_loaihang == id).SingleOrDefault();

                FilterList_loaihang.Remove(item);
            });

            #endregion

            #region Them / xoa khoi FilterList_donvi

            AddtoFilterDV_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                string id = p.Uid.ToString();
                var item  = List_donvi.Where(x => x.ma_donvi == id).SingleOrDefault();

                FilterList_donvi.Add(item);
            });

            DeletefromFilterDV_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                string id = p.Uid.ToString();
                var item  = List_donvi.Where(x => x.ma_donvi == id).SingleOrDefault();

                FilterList_donvi.Remove(item);
            });

            #endregion

            #region Phan xoa

            AddDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Add(List.Where(x => x.mathang.ma_mathang == p.Uid.ToString()).SingleOrDefault());
            });

            RemoveDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Remove(List.Where(x => x.mathang.ma_mathang == p.Uid.ToString()).SingleOrDefault());
            });

            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 các bản ghi được chọn ???";
            });

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

                return(true);
            }, p =>
            {
                for (int i = 0; i < List.Count(); i++)
                {
                    while (DeleteList.Where(x => x == List[i]).Count() != 0)
                    {
                        if (List[i] == List[List.Count() - 1])
                        {
                            List.Remove(List[i]);
                            break;
                        }
                        else
                        {
                            List.Remove(List[i]);
                        }
                    }
                    ;
                }

                DeleteList = new ObservableCollection <Model.Thongke>();
                IsOpen     = false;
            });

            #endregion

            #region Thong ke
            Statistic_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Date_Start) || string.IsNullOrEmpty(Date_End))
                {
                    return(false);
                }

                DateTime date_start = Convert.ToDateTime(Date_Start);
                DateTime date_end   = Convert.ToDateTime(Date_End);
                if ((date_start > date_end) && DateTime.TryParse(Date_Start, out date_start) && DateTime.TryParse(Date_End, out date_end))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                List = new ObservableCollection <Model.Thongke>();
                Filter_ngaythang(MyStaticMethods.FormatDateString(Date_Start), MyStaticMethods.FormatDateString(Date_End));

                if (IscheckAll == false)
                {
                    UncheckAll_Filter();
                }

                if (FilterList_nhacungcap.Count() != 0)
                {
                    Filter_nhacungcap();
                }

                if (FilterList_loaihang.Count() != 0)
                {
                    Filter_loaimathang();
                }

                if (FilterList_donvi.Count() != 0)
                {
                    Filter_donvi();
                }
            });
            #endregion

            #region Xuat Excel

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

                return(true);
            }, p =>
            {
                string filePath = "*.xlsx";
                // tạo SaveFileDialog để lưu file excel
                SaveFileDialog dialogs = new SaveFileDialog();

                // chỉ lọc ra các file có định dạng Excel
                dialogs.Filter = "Excel | *.xlsx | Excel 2003 | *.xls";

                // Nếu mở file và chọn nơi lưu file thành công sẽ lưu đường dẫn lại dùng
                if (dialogs.ShowDialog() == true)
                {
                    filePath = dialogs.FileName;
                }

                // nếu đường dẫn null hoặc rỗng thì báo không hợp lệ và return hàm
                if (string.IsNullOrEmpty(filePath))
                {
                    MessageBox.Show("Đường dẫn báo cáo không hợp lệ");
                    return;
                }
                try
                {
                    using (ExcelPackage pk = new ExcelPackage())
                    {
                        // đặt tên người tạo file
                        pk.Workbook.Properties.Author = ViewModel.Taikhoan_ViewModel.getCurrent();

                        // đặt tiêu đề cho file
                        pk.Workbook.Properties.Title = "Báo cáo thống kê";

                        //Tạo một sheet để làm việc trên đó
                        pk.Workbook.Worksheets.Add("BCTK sheet");

                        // lấy sheet vừa add ra để thao tác
                        ExcelWorksheet ws = pk.Workbook.Worksheets[1];

                        // đặt tên cho sheet
                        ws.Name = "BCTK sheet";
                        // fontsize mặc định cho cả sheet
                        ws.Cells.Style.Font.Size = 11;
                        // font family mặc định cho cả sheet
                        ws.Cells.Style.Font.Name = "Calibri";

                        // Tạo danh sách các column header
                        string[] arrColumnHeader =
                        {
                            (Date_Start + " - " + Date_End),
                            "Mã mặt hàng",
                            "Tên mặt hàng",
                            "Loại mặt hàng",
                            "Nhà cung cấp",
                            "Số lượng nhập",
                            "Số lượng xuất",
                            "Số lượng tồn",
                            "Đơn vị tính"
                        };

                        // lấy ra số lượng cột cần dùng dựa vào số lượng header
                        var countColHeader = arrColumnHeader.Count();

                        // merge các column lại từ column 1 đến số column header
                        // gán giá trị cho cell vừa merge là Thống kê thông tni User Kteam
                        ws.Cells[1, 1].Value = "Thống kê hàng hóa";
                        ws.Cells[1, 1, 1, countColHeader].Merge = true;
                        // in đậm
                        ws.Cells[1, 1, 1, countColHeader].Style.Font.Bold = true;
                        // căn giữa
                        ws.Cells[1, 1, 1, countColHeader].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                        int colIndex = 1;
                        int rowIndex = 2;

                        //tạo các header từ column header đã tạo từ bên trên
                        foreach (var item in arrColumnHeader)
                        {
                            var cell = ws.Cells[rowIndex, colIndex];

                            //set màu thành gray
                            var fill         = cell.Style.Fill;
                            fill.PatternType = ExcelFillStyle.Solid;
                            fill.BackgroundColor.SetColor(System.Drawing.Color.LightBlue);

                            //căn chỉnh các border
                            var border                     = cell.Style.Border;
                            border.Bottom.Style            =
                                border.Top.Style           =
                                    border.Left.Style      =
                                        border.Right.Style = ExcelBorderStyle.Thin;

                            //gán giá trị
                            cell.Value = item;

                            colIndex++;
                        }

                        // lấy ra danh sách UserInfo từ ItemSource của DataGrid
                        List <Model.Thongke> userList = List.Cast <Model.Thongke>().ToList();

                        // với mỗi item trong danh sách sẽ ghi trên 1 dòng
                        foreach (var item in userList)
                        {
                            // bắt đầu ghi từ cột 1. Excel bắt đầu từ 1 không phải từ 0
                            colIndex = 1;

                            // rowIndex tương ứng từng dòng dữ liệu
                            rowIndex++;

                            //gán giá trị cho từng cell
                            ws.Cells[rowIndex, colIndex++].Value = "";

                            ws.Cells[rowIndex, colIndex++].Value = item.mathang.ma_mathang;

                            ws.Cells[rowIndex, colIndex++].Value = item.mathang.ten_mathang;

                            ws.Cells[rowIndex, colIndex++].Value = item.mathang.LOAIHANG.ten_loaihang;

                            ws.Cells[rowIndex, colIndex++].Value = item.mathang.NHACUNGCAP.ten_nhacungcap;

                            ws.Cells[rowIndex, colIndex++].Value = item.soluongnhap;

                            ws.Cells[rowIndex, colIndex++].Value = item.soluongxuat;

                            ws.Cells[rowIndex, colIndex++].Value = item.tonkho;

                            ws.Cells[rowIndex, colIndex++].Value = item.mathang.DONVITINH.ten_donvi;
                        }

                        //Lưu file lại
                        Byte[] bin = pk.GetAsByteArray();
                        File.WriteAllBytes(filePath, bin);
                    }
                    MessageBox.Show("Thành công !!!", "THÔNG BÁO");
                    Process.Start(filePath);
                }
                catch (Exception)
                {
                    MessageBox.Show("Có lỗi khi lưu file !!!", "THÔNG BÁO");
                }
            });

            #endregion

            #region Sap xep

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.Thongke> chkList = new ObservableCollection <Model.Thongke>(List.OrderByDescending(x => x.soluongnhap));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.Thongke>(List.OrderBy(x => x.soluongnhap));
                }
                else
                {
                    List = new ObservableCollection <Model.Thongke>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.Thongke> chkList = new ObservableCollection <Model.Thongke>(List.OrderByDescending(x => x.soluongxuat));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.Thongke>(List.OrderBy(x => x.soluongxuat));
                }
                else
                {
                    List = new ObservableCollection <Model.Thongke>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.Thongke> chkList = new ObservableCollection <Model.Thongke>(List.OrderByDescending(x => x.tonkho));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.Thongke>(List.OrderBy(x => x.tonkho));
                }
                else
                {
                    List = new ObservableCollection <Model.Thongke>(chkList);
                }
            });


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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.Thongke> chkList = new ObservableCollection <Model.Thongke>(List.OrderByDescending(x => x.mathang.ten_mathang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.Thongke>(List.OrderBy(x => x.mathang.ten_mathang));
                }
                else
                {
                    List = new ObservableCollection <Model.Thongke>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.Thongke> chkList = new ObservableCollection <Model.Thongke>(List.OrderByDescending(x => x.mathang.NHACUNGCAP.ten_nhacungcap));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.Thongke>(List.OrderBy(x => x.mathang.NHACUNGCAP.ten_nhacungcap));
                }
                else
                {
                    List = new ObservableCollection <Model.Thongke>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.Thongke> chkList = new ObservableCollection <Model.Thongke>(List.OrderByDescending(x => x.mathang.LOAIHANG.ten_loaihang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.Thongke>(List.OrderBy(x => x.mathang.LOAIHANG.ten_loaihang));
                }
                else
                {
                    List = new ObservableCollection <Model.Thongke>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.Thongke> chkList = new ObservableCollection <Model.Thongke>(List.OrderByDescending(x => x.mathang.DONVITINH.ten_donvi));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.Thongke>(List.OrderBy(x => x.mathang.DONVITINH.ten_donvi));
                }
                else
                {
                    List = new ObservableCollection <Model.Thongke>(chkList);
                }
            });

            #endregion
        }
        public Xuathang_ViewModel()
        {
            List       = new ObservableCollection <Model.CHITIETPHIEUXUAT>(Model.DataProvider.Ins.DB.CHITIETPHIEUXUATs.Where(x => x.IsDeleted == false).ToList().OrderByDescending(x => MyStaticMethods.ConvertStringtoDate(x.PHIEUXUAT.ngayxuat)));
            DeleteList = new ObservableCollection <Model.CHITIETPHIEUXUAT>();

            ListMathang   = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
            ListKhachhang = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));
            ListPhieunhap = new ObservableCollection <Model.CHITIETPHIEUNHAP>();

            ListKH_Print = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));

            ListSoluong = new ObservableCollection <string>();

            Active        = false;
            IsOpen        = false;
            IsOpen_insert = false;
            IsOpen_Filter = false;
            IsOpen_prt    = 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_prt = false;
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List       = new ObservableCollection <Model.CHITIETPHIEUXUAT>(Model.DataProvider.Ins.DB.CHITIETPHIEUXUATs.Where(x => x.IsDeleted == false).ToList().OrderByDescending(x => MyStaticMethods.ConvertStringtoDate(x.PHIEUXUAT.ngayxuat)));
                DeleteList = new ObservableCollection <Model.CHITIETPHIEUXUAT>();

                ListMathang   = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                ListKhachhang = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));
                ListPhieunhap = new ObservableCollection <Model.CHITIETPHIEUNHAP>();

                ListSoluong = new ObservableCollection <string>();

                Active        = false;
                IsOpen        = false;
                IsOpen_insert = false;
                IsOpen_Filter = false;
                IsOpen_prt    = false;

                ListLoai_Filter      = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
                ListMathang_Filter   = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                ListKhachhang_Filter = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));

                ListKH_Print = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));
            });

            #region Lua chon mat hang va phieu nhap

            Select_mathang_Command = new RelayCommand <ComboBox>(p =>
            {
                if (SMathang == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                ListPhieunhap = new ObservableCollection <Model.CHITIETPHIEUNHAP>();
                foreach (var item in Model.DataProvider.Ins.DB.CHITIETPHIEUNHAPs.Where(x => x.IsDeleted == false))
                {
                    while (item.MATHANG == SMathang)
                    {
                        ListPhieunhap.Add(item);
                        break;
                    }
                }
            });

            Select_phieunhap_Command = new RelayCommand <ComboBox>(p =>
            {
                if (SMathang == null || SPhieunhap == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Dongiaxuat = SPhieunhap.giaxuat.ToString();

                ListSoluong = new ObservableCollection <string>();
                for (int i = 1; i <= SPhieunhap.soluongton; i++)
                {
                    ListSoluong.Add(i.ToString());
                }
            });

            #endregion

            #region Them moi

            InsertShow_Command = new RelayCommand <object>(p =>
            {
                if (SPhieunhap == null || SKhachhang == null || SMathang == null)
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(Soluongxuat) || string.IsNullOrEmpty(Soluongthucxuat))
                {
                    return(false);
                }

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

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

                if (IsOpen_insert == true || IsOpen == true)
                {
                    return(false);
                }

                if (Convert.ToInt32(Dongiaxuat) <= 0 || Convert.ToInt32(Soluongxuat) <= 0 || Convert.ToInt32(Soluongthucxuat) <= 0)
                {
                    return(false);
                }

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

                string date_str = MyStaticMethods.ConvertDate2Vn_Today();
                Ngay            = date_str;
            });

            Insert_Command = new RelayCommand <object>(p =>
            {
                if (SPhieunhap == null || SKhachhang == null || SMathang == null)
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(Soluongxuat) || string.IsNullOrEmpty(Soluongthucxuat))
                {
                    return(false);
                }

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

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

                return(true);
            }, p =>
            {
                string date_str       = MyStaticMethods.ConvertDate2Vn_Today();
                Model.PHIEUXUAT Phieu = CheckPhieuxuat(date_str);

                Model.CHITIETPHIEUXUAT newPhieu = new Model.CHITIETPHIEUXUAT()
                {
                    ma_ctphieuxuat   = MyStaticMethods.RandomInt(5) + "-" + SPhieunhap.MATHANG.ma_mathang,
                    CHITIETPHIEUNHAP = SPhieunhap,
                    KHACHHANG        = SKhachhang,
                    PHIEUXUAT        = Phieu,

                    soluongxuat     = Convert.ToInt32(Soluongxuat),
                    soluongthucxuat = Convert.ToInt32(Soluongthucxuat),

                    nguoitao  = getCurrentUser(),
                    ghichu    = Ghichu != "" ? Ghichu : null,
                    IsDeleted = false,
                };

                Model.Xuathang_Service.Insert(newPhieu);

                Update_luonghang(Convert.ToInt32(Soluongthucxuat), newPhieu.ma_ctphieunhap);

                List.Insert(0, newPhieu);
                SelectedItem = newPhieu;

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

                IsOpen_insert = false;
            });

            #endregion

            #region Phan xoa

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

                if (IsOpen_insert == true || IsOpen == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                IsOpen  = true;
                Content = "  Xóa các bản ghi được chọn ???";
            });

            AddDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Add(List.Where(x => x.ma_ctphieuxuat == p.Uid.ToString()).SingleOrDefault());
            });

            RemoveDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Remove(List.Where(x => x.ma_ctphieuxuat == 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.CHITIETPHIEUXUAT>();
                IsOpen       = false;
                SelectedItem = null;
            });
            #endregion

            #region Tao moi
            Reset_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                SMathang        = null;
                SPhieunhap      = null;
                SKhachhang      = null;
                Soluongxuat     = "";
                Soluongthucxuat = "";
                Dongiaxuat      = "";
                SelectedItem    = null;

                ListMathang   = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                ListKhachhang = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));
                ListPhieunhap = new ObservableCollection <Model.CHITIETPHIEUNHAP>();

                ListSoluong = new ObservableCollection <string>();
            });
            #endregion

            #region Phan loc

            ListLoai_Filter      = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
            ListMathang_Filter   = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
            ListKhachhang_Filter = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));

            OpenFilter_Command = new RelayCommand <object>(p =>
            {
                if (IsOpen_Filter == true || IsOpen_insert == true || IsOpen_prt == true || IsOpen == true)
                {
                    return(false);
                }

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

            FilterLoai_Command = new RelayCommand <ComboBox>(p =>
            {
                return(true);
            }, p =>
            {
                if (SLoai_Filter != null)
                {
                    FilterMathangby_Loai(SLoai_Filter.ma_loaihang);
                }
                else
                {
                    ListMathang_Filter = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                }
            });

            ResetFilter_Command = new RelayCommand <Button>(p =>
            {
                return(true);
            }, p =>
            {
                ListLoai_Filter      = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
                ListMathang_Filter   = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                ListKhachhang_Filter = new ObservableCollection <Model.KHACHHANG>(Model.DataProvider.Ins.DB.KHACHHANGs.Where(x => x.IsDeleted == false));

                SKhachhang_Filter = null;
                SMathang_Filter   = null;
                SLoai_Filter      = null;
                Date_Start        = String.Empty;
                Date_End          = String.Empty;

                List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(Model.DataProvider.Ins.DB.CHITIETPHIEUXUATs.Where(x => x.IsDeleted == false).OrderByDescending(x => x.ma_phieuxuat));

                IsOpen_Filter = false;
            });

            Filter_Command = new RelayCommand <Button>(p =>
            {
                if (string.IsNullOrEmpty(Date_Start) || string.IsNullOrEmpty(Date_End))
                {
                    return(false);
                }

                DateTime date_start = Convert.ToDateTime(Date_Start);
                DateTime date_end   = Convert.ToDateTime(Date_End);
                if ((date_start > date_end) && DateTime.TryParse(Date_Start, out date_start) && DateTime.TryParse(Date_End, out date_end))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(Model.DataProvider.Ins.DB.CHITIETPHIEUXUATs.Where(x => x.IsDeleted == false).ToList().OrderByDescending(x => MyStaticMethods.ConvertStringtoDate(x.PHIEUXUAT.ngayxuat)));

                DateTime date_start = Convert.ToDateTime(Date_Start);
                DateTime date_end   = Convert.ToDateTime(Date_End);

                FindByDate(date_start, date_end);

                if (SMathang_Filter != null)
                {
                    FindByMH(SMathang_Filter.ma_mathang);
                }

                if (SKhachhang_Filter != null)
                {
                    FindByKH(SKhachhang_Filter.ma_khachhang);
                }

                if (SLoai_Filter != null)
                {
                    FindByLOAI(SLoai_Filter.ma_loaihang);
                }

                IsOpen_Filter = false;
            });

            #endregion

            #region Phan sap xep

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUXUAT> chkList = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderByDescending(x => x.CHITIETPHIEUNHAP.MATHANG.ten_mathang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderBy(x => x.CHITIETPHIEUNHAP.MATHANG.ten_mathang));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUXUAT> chkList = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderByDescending(x => x.CHITIETPHIEUNHAP.MATHANG.NHACUNGCAP.ten_nhacungcap));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderBy(x => x.CHITIETPHIEUNHAP.MATHANG.NHACUNGCAP.ten_nhacungcap));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUXUAT> chkList = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderByDescending(x => MyStaticMethods.ConvertStringtoDate(x.PHIEUXUAT.ngayxuat)));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderBy(x => MyStaticMethods.ConvertStringtoDate(x.PHIEUXUAT.ngayxuat)));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.CHITIETPHIEUXUAT> chkList = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderByDescending(x => x.CHITIETPHIEUNHAP.MATHANG.DONVITINH.ten_donvi));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.OrderBy(x => x.CHITIETPHIEUNHAP.MATHANG.DONVITINH.ten_donvi));
                }
                else
                {
                    List = new ObservableCollection <Model.CHITIETPHIEUXUAT>(chkList);
                }
            });

            #endregion

            #region Printer

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

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

                return(true);
            }, p =>
            {
                List_Print = new ObservableCollection <Model.CHITIETPHIEUXUAT>(List.Where(x => x.KHACHHANG == SKhachhangPrint &&
                                                                                          x.PHIEUXUAT.ngayxuat == MyStaticMethods.FormatDateString(DayPrint)));

                var list_chk = new ObservableCollection <Model.CHITIETPHIEUXUAT>();

                ItemsCount = 0;
                Tongtien   = 0;

                foreach (var item in List_Print)
                {
                    Tongtien += (double)(item.CHITIETPHIEUNHAP.giaxuat * item.soluongthucxuat);

                    if (list_chk.Where(x => x.CHITIETPHIEUNHAP.MATHANG == item.CHITIETPHIEUNHAP.MATHANG).Count() == 0)
                    {
                        list_chk.Add(item);
                    }
                }

                ItemsCount = list_chk.Count();


                DayPrintVN = MyStaticMethods.FormatDateString(DayPrint);

                View.View_Thukho.In_Xuat w = new View.View_Thukho.In_Xuat();
                w.ShowDialog();
            });

            OpenPrintDialog_Command = new RelayCommand <object>(p =>
            {
                if (IsOpen == true)
                {
                    return(false);
                }

                if (IsOpen_insert == true)
                {
                    return(false);
                }

                if (IsOpen_Filter == true)
                {
                    return(false);
                }

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

            Print_Command = new RelayCommand <Grid>(p =>
            {
                return(true);
            }, p =>
            {
                try
                {
                    PrintDialog printDialog = new PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(p, "invoice");
                    }

                    MessageBox.Show("Thành công !!!", "THÔNG BÁO");
                }
                catch (Exception) { MessageBox.Show("Có lỗi xảy ra !!!", "THÔNG BÁO"); };
            });

            PrinterFormClose_Command = new RelayCommand <Window>(p =>
            {
                return(true);
            }, p =>
            {
                if (p != null)
                {
                    p.Close();
                    IsOpen_prt = false;
                }
            });

            #endregion
        }
Exemple #11
0
        public Mathang_ViewModel()
        {
            List       = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
            DeleteList = new ObservableCollection <Model.MATHANG>();

            List_Loai       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
            List_Donvi      = new ObservableCollection <Model.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
            List_Nhacungcap = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));

            Active        = false;
            IsOpen        = false;
            IsOpen_Filter = 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;
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List       = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));
                DeleteList = new ObservableCollection <Model.MATHANG>();

                List_Loai       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
                List_Donvi      = new ObservableCollection <Model.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
                List_Nhacungcap = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));

                Active        = false;
                IsOpen        = false;
                IsOpen_Filter = false;

                ListDonvi_Filter      = new ObservableCollection <Model.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
                ListNhacungcap_Filter = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));
                ListLoai_Filter       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));
            });

            #region Tao moi
            Reset_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                SelectedItem = null;
                Tenmathang   = "";
                Dong         = "";
                Hang         = "";
                SNhacungcap  = null;
                SLoai        = null;
                SDonvi       = null;
                Mota         = "";
            });
            #endregion

            #region Phan them
            Insert_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Tenmathang) || string.IsNullOrEmpty(Hang) || string.IsNullOrEmpty(Dong))
                {
                    return(false);
                }

                if (SDonvi == null || SNhacungcap == null || SLoai == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                SelectedItem = null;

                Model.MATHANG newItem = new Model.MATHANG()
                {
                    ma_mathang  = MyStaticMethods.RandomInt(10),
                    ten_mathang = Tenmathang,
                    dong        = Dong,
                    hang        = Hang,
                    LOAIHANG    = SLoai,
                    DONVITINH   = SDonvi,
                    NHACUNGCAP  = SNhacungcap,
                    mota        = (string.IsNullOrEmpty(Mota)) ? null : Mota,
                    IsDeleted   = false
                };

                Model.Mathang_Service.Insert(newItem);

                List.Insert(0, newItem);
                SelectedItem = newItem;

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

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

                if (string.IsNullOrEmpty(Tenmathang) || string.IsNullOrEmpty(Hang) || string.IsNullOrEmpty(Dong))
                {
                    return(false);
                }

                if (SDonvi == null || SNhacungcap == null || SLoai == null)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Model.MATHANG UpdateItem = new Model.MATHANG()
                {
                    ten_mathang = Tenmathang,
                    dong        = _Dong,
                    hang        = _Hang,
                    LOAIHANG    = SLoai,
                    NHACUNGCAP  = SNhacungcap,
                    DONVITINH   = SDonvi,
                    mota        = (string.IsNullOrEmpty(Mota)) ? null : Mota
                };
                Model.Mathang_Service.Update(UpdateItem, Mamathang);

                for (int i = 0; i < List.Count(); i++)
                {
                    if (List[i] == SelectedItem)
                    {
                        List[i] = new Model.MATHANG()
                        {
                            ma_mathang  = Mamathang,
                            ten_mathang = Tenmathang,
                            dong        = Dong,
                            hang        = Hang,
                            NHACUNGCAP  = SNhacungcap,
                            DONVITINH   = SDonvi,
                            LOAIHANG    = SLoai,
                            mota        = (string.IsNullOrEmpty(Mota)) ? null : Mota
                        };
                        break;
                    }
                }
                //MessageBox.Show("Chỉnh sửa thành công", "THÔNG BÁO");

                SelectedItem = null;
                Tenmathang   = "";
                Dong         = "";
                Hang         = "";
                SNhacungcap  = null;
                SLoai        = null;
                SDonvi       = null;
                Mota         = "";

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

            #region Phan xoa
            AddDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Add(List.Where(x => x.ma_mathang == p.Uid.ToString()).SingleOrDefault());
            });

            RemoveDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Remove(List.Where(x => x.ma_mathang == p.Uid.ToString()).SingleOrDefault());
            });

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

                return(true);
            }, p =>
            {
                IsOpen  = true;
                Content = "  Xóa các bản ghi được chọn ???";
            });

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

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

                DeleteList   = new ObservableCollection <Model.MATHANG>();
                IsOpen       = false;
                SelectedItem = null;
            });
            #endregion

            #region Phan loc

            ListDonvi_Filter      = new ObservableCollection <Model.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
            ListNhacungcap_Filter = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false));
            ListLoai_Filter       = new ObservableCollection <Model.LOAIHANG>(Model.DataProvider.Ins.DB.LOAIHANGs.Where(x => x.IsDeleted == false));

            OpenFilter_Command = new RelayCommand <object>(p =>
            {
                if (IsOpen == true || IsOpen_Filter == true)
                {
                    return(false);
                }

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

            ResetFilter_Command = new RelayCommand <Button>(p =>
            {
                return(true);
            }, p =>
            {
                List = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));

                SLoai_Filter       = null;
                SNhacungcap_Filter = null;
                SDonvi_Filter      = null;

                IsOpen_Filter = false;
            });

            Filter_Command = new RelayCommand <Button>(p =>
            {
                return(true);
            }, p =>
            {
                List = new ObservableCollection <Model.MATHANG>(Model.DataProvider.Ins.DB.MATHANGs.Where(x => x.IsDeleted == false));

                if (SLoai_Filter != null)
                {
                    FilterbyLoaihang(SLoai_Filter.ma_loaihang);
                }
                if (SNhacungcap_Filter != null)
                {
                    FilterbyNhacungcap(SNhacungcap_Filter.ma_nhacungcap);
                }
                if (SDonvi_Filter != null)
                {
                    FilterbyDonvi(SDonvi_Filter.ma_donvi);
                }

                IsOpen_Filter = false;
            });

            #endregion

            #region Phan sap xep

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.MATHANG> chkList = new ObservableCollection <Model.MATHANG>(List.OrderByDescending(x => x.ten_mathang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.MATHANG>(List.OrderBy(x => x.ten_mathang));
                }
                else
                {
                    List = new ObservableCollection <Model.MATHANG>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.MATHANG> chkList = new ObservableCollection <Model.MATHANG>(List.OrderByDescending(x => x.NHACUNGCAP.ten_nhacungcap));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.MATHANG>(List.OrderBy(x => x.NHACUNGCAP.ten_nhacungcap));
                }
                else
                {
                    List = new ObservableCollection <Model.MATHANG>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.MATHANG> chkList = new ObservableCollection <Model.MATHANG>(List.OrderByDescending(x => x.LOAIHANG.ten_loaihang));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.MATHANG>(List.OrderBy(x => x.LOAIHANG.ten_loaihang));
                }
                else
                {
                    List = new ObservableCollection <Model.MATHANG>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.MATHANG> chkList = new ObservableCollection <Model.MATHANG>(List.OrderByDescending(x => x.DONVITINH.ten_donvi));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.MATHANG>(List.OrderBy(x => x.DONVITINH.ten_donvi));
                }
                else
                {
                    List = new ObservableCollection <Model.MATHANG>(chkList);
                }
            });

            #endregion
        }
Exemple #12
0
        public Nhanvien_ViewModel()
        {
            List       = new ObservableCollection <Model.NHANVIEN>(Model.DataProvider.Ins.DB.NHANVIENs.Where(x => x.IsDeleted == false));
            DeleteList = new ObservableCollection <Model.NHANVIEN>();

            List_Quyen = new ObservableCollection <Model.QUYEN>(Model.DataProvider.Ins.DB.QUYENs);

            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;
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                List       = new ObservableCollection <Model.NHANVIEN>(Model.DataProvider.Ins.DB.NHANVIENs.Where(x => x.IsDeleted == false));
                DeleteList = new ObservableCollection <Model.NHANVIEN>();

                List_Quyen = new ObservableCollection <Model.QUYEN>(Model.DataProvider.Ins.DB.QUYENs);

                Active = false;
                IsOpen = false;
            });

            #region Tao moi
            Reset_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                SelectedItem = null;
                Tennhanvien  = "";
                Diachi       = "";
                Sodienthoai  = "";
                Ngaysinh     = "";
                SQuyen       = null;
            });
            #endregion

            #region Phan them
            Insert_Command = new RelayCommand <object>(p =>
            {
                if (string.IsNullOrEmpty(Tennhanvien) || string.IsNullOrEmpty(Sodienthoai) || string.IsNullOrEmpty(Diachi) || string.IsNullOrEmpty(Ngaysinh))
                {
                    return(false);
                }

                long i = 0;
                if (!long.TryParse(Sodienthoai, out i))
                {
                    return(false);
                }

                int count = Model.DataProvider.Ins.DB.NHANVIENs.Where(x => x.sodienthoai == Sodienthoai).Count();
                if (count != 0)
                {
                    return(false);
                }

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

                return(true);
            }, p =>
            {
                SelectedItem = null;

                Model.NHANVIEN newItem = new Model.NHANVIEN()
                {
                    ma_nhanvien  = MyStaticMethods.RandomInt(10),
                    ten_nhanvien = Tennhanvien,
                    ngaysinh     = MyStaticMethods.FormatDateString(Ngaysinh),
                    QUYEN        = SQuyen,
                    diachi       = Diachi,
                    sodienthoai  = Sodienthoai,
                    IsDeleted    = false
                };

                Model.Nhanvien_Service.Insert(newItem);

                List.Insert(0, newItem);
                SelectedItem = newItem;

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

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

                if (string.IsNullOrEmpty(Tennhanvien) || string.IsNullOrEmpty(Sodienthoai) || string.IsNullOrEmpty(Diachi) || string.IsNullOrEmpty(Ngaysinh))
                {
                    return(false);
                }

                long i = 0;
                if (!long.TryParse(Sodienthoai, out i))
                {
                    return(false);
                }

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

                return(true);
            }, p =>
            {
                Model.NHANVIEN UpdateItem = new Model.NHANVIEN()
                {
                    ten_nhanvien = Tennhanvien,
                    ngaysinh     = MyStaticMethods.FormatDateString(Ngaysinh),
                    QUYEN        = SQuyen,
                    diachi       = Diachi,
                    sodienthoai  = Sodienthoai
                };
                Model.Nhanvien_Service.Update(UpdateItem, Manhanvien);

                for (int i = 0; i < List.Count(); i++)
                {
                    if (List[i] == SelectedItem)
                    {
                        List[i] = new Model.NHANVIEN()
                        {
                            ma_nhanvien  = Manhanvien,
                            ten_nhanvien = Tennhanvien,
                            diachi       = Diachi,
                            sodienthoai  = Sodienthoai,
                            ngaysinh     = MyStaticMethods.FormatDateString(Ngaysinh),
                            QUYEN        = _SQuyen
                        };
                        break;
                    }
                }

                //MessageBox.Show("Chỉnh sửa thành công", "THÔNG BÁO");

                SelectedItem = null;
                Tennhanvien  = "";
                Diachi       = "";
                Sodienthoai  = "";
                Ngaysinh     = "";
                SQuyen       = null;

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

            #region Phan xoa

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

                return(true);
            }, p =>
            {
                IsOpen  = true;
                Content = "  Xóa các bản ghi được chọn ???";
            });

            AddDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Add(List.Where(x => x.ma_nhanvien == p.Uid.ToString()).SingleOrDefault());
            });

            RemoveDeleteList_Command = new RelayCommand <CheckBox>(p =>
            {
                return(true);
            }, p =>
            {
                DeleteList.Remove(List.Where(x => x.ma_nhanvien == p.Uid.ToString()).SingleOrDefault());
            });

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

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

                DeleteList   = new ObservableCollection <Model.NHANVIEN>();
                IsOpen       = false;
                SelectedItem = null;
            });
            #endregion

            #region Sap xep

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.NHANVIEN> chkList = new ObservableCollection <Model.NHANVIEN>(List.OrderByDescending(x => x.ten_nhanvien));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.NHANVIEN>(List.OrderBy(x => x.ten_nhanvien));
                }
                else
                {
                    List = new ObservableCollection <Model.NHANVIEN>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.NHANVIEN> chkList = new ObservableCollection <Model.NHANVIEN>(List.OrderByDescending(x => x.diachi));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.NHANVIEN>(List.OrderBy(x => x.diachi));
                }
                else
                {
                    List = new ObservableCollection <Model.NHANVIEN>(chkList);
                }
            });

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

                return(true);
            }, p =>
            {
                ObservableCollection <Model.NHANVIEN> chkList = new ObservableCollection <Model.NHANVIEN>(List.OrderByDescending(x => x.QUYEN.ma_quyen));

                if (List[0] == chkList[0])
                {
                    List = new ObservableCollection <Model.NHANVIEN>(List.OrderBy(x => x.QUYEN.ma_quyen));
                }
                else
                {
                    List = new ObservableCollection <Model.NHANVIEN>(chkList);
                }
            });

            #endregion
        }