예제 #1
0
        public SearchBar_ViewModel()
        {
            Search_Command = new RelayCommand <TextBox>(p =>
            {
                return(true);
            }, p =>
            {
                Texts     = p.Text;
                Window wd = getParent(p) as Window;

                if (wd != null)
                {
                    #region tim view thu kho

                    if ((wd.GetType() == typeof(View.View_Thukho.Mathang)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_mathang;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }


                    if ((wd.GetType() == typeof(View.View_Thukho.Donvi)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_donvi;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Thukho.Loaimathang)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_loaihang;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Thukho.Nhaphang)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_nhap;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Thukho.Xuathang)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_xuat;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Thukho.Thongke)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_thongke;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    #endregion

                    #region tim view quan ly

                    if (wd.GetType() == typeof(View.View_Quanly.Mathang))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_thongke;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Quanly.Khachhang)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_khachhang;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Quanly.Nhacungcap)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_nhacungcap;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Quanly.Nhanvien)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_nhanvien;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    if ((wd.GetType() == typeof(View.View_Quanly.Quantrihethong)))
                    {
                        foreach (ListView item in MySource.MyStaticMethods.FindVisualChildren <ListView>(wd))
                        {
                            CollectionView viewfilter = (CollectionView)CollectionViewSource.GetDefaultView(item.ItemsSource);
                            viewfilter.Filter         = Search_taikhoan;
                            CollectionViewSource.GetDefaultView(item.ItemsSource).Refresh();

                            break;
                        }
                    }

                    #endregion
                }
            });

            Load_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                Texts = string.Empty;
            });
        }
예제 #2
0
        public Donvi_ViewModel()
        {
            List       = new ObservableCollection <Model.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
            DeleteList = new ObservableCollection <Model.DONVITINH>();

            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.DONVITINH>(Model.DataProvider.Ins.DB.DONVITINHs.Where(x => x.IsDeleted == false));
                DeleteList = new ObservableCollection <Model.DONVITINH>();

                Active = false;
                IsOpen = false;
            });

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

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

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

                Model.DONVITINH newItem = new Model.DONVITINH()
                {
                    ma_donvi  = MyStaticMethods.RandomString(5, false),
                    ten_donvi = Tendonvi,
                    mota      = (string.IsNullOrEmpty(Mota)) ? null : Mota,
                    IsDeleted = false
                };

                Model.Donvitinh_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(Tendonvi))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Model.DONVITINH UpdateItem = new Model.DONVITINH()
                {
                    ten_donvi = Tendonvi,
                    mota      = string.IsNullOrEmpty(Mota) ? null : Mota
                };
                Model.Donvitinh_Service.Update(UpdateItem, Madonvi);

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

                SelectedItem = null;
                Tendonvi     = "";
                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_donvi == p.Uid.ToString()).SingleOrDefault());
            });

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

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

            #region Phan sap xep

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

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

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

            #endregion
        }