public SelectCustomerViewModel(Window window) { BindData(); CloseCommand = new DelegateCommand(() => { window.Close(); CheckedList = SOURCE.Where(s => s.IsChecked).FirstOrDefault(); }); SearchCommand = new DelegateCommand(() => { var s = SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0); PageIndex = 0; CustomerColletion = new ObservableCollection <Customer>(s.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchName) ? false : true); }); AllCommand = new DelegateCommand(() => { SearchName = ""; CustomerColletion = new ObservableCollection <Customer>(SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchName) ? false : true); }); PreviousCommand = new DelegateCommand(() => { PageIndex--; CustomerColletion = new ObservableCollection <Customer>(SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(PageIndex > 0 ? true : false); }); NextCommand = new DelegateCommand(() => { PageIndex++; CustomerColletion = new ObservableCollection <Customer>(SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((PageIndex + 1) * PAGESIZE < SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Count() ? true : false); }); SelectCommand = new DelegateCommand <Customer>(s => { if (s != null) { s.IsChecked = !s.IsChecked; } SOURCE.Where(t => t.Id != s.Id).ToList().ForEach(t => t.IsChecked = false); }); }
public SelectItemMasterViewModel(Window window) { BindData(); CloseCommand = new DelegateCommand(() => { window.Close(); CheckedList = SOURCE.Where(s => s.IsChecked && s.StockCount > 0).ToList(); }); SearchCommand = new DelegateCommand(() => { var s = SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0); PageIndex = 0; ItemMasterColletion = new ObservableCollection <ItemMaster>(s.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchItemId) ? false : true); }); AllCommand = new DelegateCommand(() => { SearchItemId = ""; ItemMasterColletion = new ObservableCollection <ItemMaster>(SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchItemId) ? false : true); }); PreviousCommand = new DelegateCommand(() => { PageIndex--; ItemMasterColletion = new ObservableCollection <ItemMaster>(SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(PageIndex > 0 ? true : false); }); NextCommand = new DelegateCommand(() => { PageIndex++; ItemMasterColletion = new ObservableCollection <ItemMaster>(SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((PageIndex + 1) * PAGESIZE < SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Count() ? true : false); }); SelectCommand = new DelegateCommand <ItemMaster>(s => { if (s != null) { s.IsChecked = !s.IsChecked; } }); }
/// <summary> /// /// </summary> /// <param name="windwow"></param> public CustomerViewModel(Window window) { InsertCommandVisibility = Visibility.Visible; UpdateCommandVisibility = Visibility.Collapsed; DepositIsReadOnly = false; BindData(); CloseCommand = new DelegateCommand(() => { window.Close(); }); InsertCommand = new DelegateCommand(() => { var customer = new Customer() { Id = Guid.NewGuid().ToString(), Name = Name, Phone = Phone, IM = IM, Deposit = string.IsNullOrEmpty(Deposit)? 0: decimal.Parse(Deposit), Discount = Discount, Remark = Remark, UpdateTime = DateTime.Now }; if (SqlServerCompactService.InsertCustomer(customer)) { InitialControlValue(); BindData(); } }, CanExcute); UpdateCommand = new DelegateCommand(() => { var item = new Customer() { Id = Id, Name = Name, Phone = Phone, IM = IM, Discount = Discount, Deposit = string.IsNullOrEmpty(Deposit) ? 0 : decimal.Parse(Deposit), Remark = Remark, UpdateTime = DateTime.Now }; if (SqlServerCompactService.UpdateCustomer(item)) { InitialControlValue(); BindData(); } }, CanExcute); SelectCommand = new DelegateCommand <Customer>(s => { if (s != null) { InsertCommandVisibility = Visibility.Collapsed; UpdateCommandVisibility = Visibility.Visible; DepositIsReadOnly = true; Id = s.Id; Name = s.Name; Phone = s.Phone; IM = s.IM; Discount = s.Discount; Deposit = s.Deposit.ToString(); Remark = s.Remark; IsPhoneRepeat = false; IsIMRepeat = false; } }); AddDepositCommand = new DelegateCommand(() => { PopupIsOpen = !PopupIsOpen; }); UpdateDepositCommand = new DelegateCommand(() => { decimal j = 0; decimal.TryParse(Deposit, out j); if (SqlServerCompactService.TopUpCustomerDeposit(Id, j)) { BindData(); PopupIsOpen = false; InitialControlValue(); } }, () => { var ret = false; decimal j = 0; if (!string.IsNullOrEmpty(Deposit) && decimal.TryParse(Deposit, out j)) { if (j > 0) { ret = true; } } return(ret); }); DeleteCommand = new DelegateCommand <Customer>(s => { if (s != null) { if (MessageBox.Show(window, "是否确认删除该客户?", "确认删除点“Yes”,否则点“No”", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.Yes) { SqlServerCompactService.DeleteCustomer(s); BindData(); InitialControlValue(); } } }); ViewCommand = new DelegateCommand <Customer>(s => { ViewCustomerDetailWindow w = new ViewCustomerDetailWindow(); ViewCustomerDetailViewModel model = new ViewCustomerDetailViewModel(w, s); w.DataContext = model; w.Owner = App.Current.MainWindow; w.ShowDialog(); }); ClearCommand = new DelegateCommand(() => { InitialControlValue(); }); PreviousCommand = new DelegateCommand(() => { PageIndex--; CustomerColletion = new ObservableCollection <Customer>(SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(PageIndex > 0 ? true : false); }); NextCommand = new DelegateCommand(() => { PageIndex++; CustomerColletion = new ObservableCollection <Customer>(SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((PageIndex + 1) * PAGESIZE < SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Count() ? true : false); }); SearchCommand = new DelegateCommand(() => { var s = SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0); PageIndex = 0; CustomerColletion = new ObservableCollection <Customer>(s.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchName) ? false : true); }); AllCommand = new DelegateCommand(() => { SearchName = ""; CustomerColletion = new ObservableCollection <Customer>(SOURCE.Where(t => t.Name.IndexOf(SearchName, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchName) ? false : true); }); }
/// <summary> /// /// </summary> /// <param name="window"></param> public StockViewModel(Window window) { ItemTypeCollection = new ObservableCollection <ItemTypeModel>(ItemTypeModel.ItemTypeModelList); ItemType = ItemTypeCollection.FirstOrDefault(); InsertCommandVisibility = Visibility.Visible; UpdateCommandVisibility = Visibility.Collapsed; BindData(); CloseCommand = new DelegateCommand(() => { window.Close(); }); InsertCommand = new DelegateCommand(() => { var item = new ItemMaster() { Id = Guid.NewGuid().ToString(), ItemId = ItemId, ItemName = ItemName, ItemSize = int.Parse(ItemSize), ItemType = ItemType.Type, StockCount = Count, StockPrice = decimal.Parse(StockPrice), Price = decimal.Parse(Price), UpdateTime = DateTime.Now, Color = Color }; if (SqlServerCompactService.InsertItemMaster(item)) { InitialControlValue(); BindData(); } }, CanExcute); UpdateCommand = new DelegateCommand(() => { var item = new ItemMaster() { Id = Id, ItemId = ItemId, ItemName = ItemName, ItemSize = int.Parse(ItemSize), ItemType = ItemType.Type, StockCount = Count, StockPrice = decimal.Parse(StockPrice), Price = decimal.Parse(Price), UpdateTime = DateTime.Now, Color = Color }; if (SqlServerCompactService.UpdateItemMaster(item)) { InitialControlValue(); BindData(); InsertCommandVisibility = Visibility.Visible; UpdateCommandVisibility = Visibility.Collapsed; } }, CanExcute); ClearCommand = new DelegateCommand(() => { InitialControlValue(); }); PreviousCommand = new DelegateCommand(() => { PageIndex--; ItemMasterColletion = new ObservableCollection <ItemMaster>(SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(PageIndex > 0 ? true : false); }); NextCommand = new DelegateCommand(() => { PageIndex++; ItemMasterColletion = new ObservableCollection <ItemMaster>(SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((PageIndex + 1) * PAGESIZE < SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Count() ? true : false); }); SearchCommand = new DelegateCommand(() => { var s = SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0); PageIndex = 0; ItemMasterColletion = new ObservableCollection <ItemMaster>(s.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchItemId) ? false : true); }); AllCommand = new DelegateCommand(() => { SearchItemId = ""; ItemMasterColletion = new ObservableCollection <ItemMaster>(SOURCE.Where(t => t.ItemId.IndexOf(SearchItemId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchItemId) ? false : true); }); SelectCommand = new DelegateCommand <ItemMaster>(s => { if (s != null) { InsertCommandVisibility = Visibility.Collapsed; UpdateCommandVisibility = Visibility.Visible; Id = s.Id; ItemId = s.ItemId; ItemName = s.ItemName; ItemSize = s.ItemSize.ToString(); ItemType = ItemTypeCollection.FirstOrDefault(t => t.Type == s.ItemType); StockPrice = s.StockPrice.ToString(); Price = s.Price.ToString(); Count = s.StockCount; Color = s.Color; IsRepeat = false; } }); DeleteCommand = new DelegateCommand <ItemMaster>(s => { if (s != null) { if (MessageBox.Show(window, "是否确认删除该货品?", "确认删除点“Yes”,否则点“No”", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.Yes) { SqlServerCompactService.DeleteItemMaster(s); BindData(); InitialControlValue(); } } }); }