/// <summary> /// /// </summary> /// <param name="window"></param> public SalesItemViewModel(Window window) { SOURCE = new ObservableCollection <ItemSales>(SqlServerCompactService.GetItemSales(DateTime.Now, 0)); TotalCount = SOURCE.Count.ToString(); TotalProfit = SOURCE.Sum(s => s.SoldPirce - (s.SalesCount * s.StockPrice)).ToString(); ItemSalesColletion = new ObservableCollection <ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); CloseCommand = new DelegateCommand(() => { window.Close(); }); AnalyseCommand = new DelegateCommand <string>(s => { ItemSalesColletion.Clear(); int t = 0; switch (s) { case "0": t = 0; break; case "1": t = 1; break; case "2": t = 2; break; } SOURCE = new ObservableCollection <ItemSales>(SqlServerCompactService.GetItemSales(SelectedDate, t)); TotalCount = SOURCE.Count.ToString(); TotalProfit = SOURCE.Sum(k => k.SoldPirce - (k.SalesCount * k.StockPrice)).ToString(); ItemSalesColletion = new ObservableCollection <ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }); PreviousCommand = new DelegateCommand(() => { PageIndex--; ItemSalesColletion = new ObservableCollection <ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(PageIndex > 0 ? true : false); }); NextCommand = new DelegateCommand(() => { PageIndex++; ItemSalesColletion = new ObservableCollection <ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((PageIndex + 1) * PAGESIZE < SOURCE.Count() ? true : false); }); }
public void Execute() { var dt = SqlServerCompactService.GetData("UserAccount"); var useraccount = from user in dt.AsEnumerable() where user.Field <string>("UserName") == UserName && user.Field <string>("Password") == Password select user; if (useraccount.ToList().Count == 0) { UserName = "******"; } else { SalesWindow window = new SalesWindow(); SalesWindowViewModel model = new SalesWindowViewModel(window); model.AfterLogoutHandler += (s, e) => { UserName = ""; Password = ""; }; window.DataContext = model; window.Owner = Application.Current.MainWindow; window.ShowDialog(); } }
/// <summary> /// /// </summary> /// <param name="window"></param> public SalesWindowViewModel(Window window) { //ItemSalesColletion.CollectionChanged += (s, e) => //{ // if (e.Action != System.Collections.Specialized.NotifyCollectionChangedAction.Reset) // { // decimal amount = 0; // foreach (ItemSales item in e.NewItems) // { // item.PropertyChanged += (ss, ee) => // { // if (ee.PropertyName == "SoldPirce") // { // var sss = (ItemSales)ss; // } // }; // amount += item.SoldPirce; // MessageBox.Show(amount.ToString()); // } // } //}; SalesDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Timer timer = new Timer(1000); timer.Elapsed += (s, e) => { SalesDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); }; timer.Start(); WINDOW = window; LogoutCommand = new DelegateCommand(Execute, () => { return(true); }); CloseCommand = new DelegateCommand(() => { Application.Current.Shutdown(); }); SelectItemMasterCommand = new DelegateCommand(() => { SelectItemMasterWindow w = new SelectItemMasterWindow(); SelectItemMasterViewModel model = new SelectItemMasterViewModel(w); w.DataContext = model; w.Owner = App.Current.MainWindow; w.ShowDialog(); //SOURCE = new ObservableCollection<ItemSales>(model.CheckedList); SOURCE.Clear(); model.CheckedList.ForEach(s => { SOURCE.Add(new ItemSales { Id = s.Id, ItemId = s.ItemId, ItemName = s.ItemName, ItemSize = s.ItemSize, ItemType = s.ItemType, StockCount = s.StockCount, SalesType = 1, SalesCount = 1, StockPrice = s.StockPrice, Price = s.Price, SoldPirce = s.Price }); }); //ItemSalesColletion = new ObservableCollection<ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); ItemSalesColletion.Clear(); SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE).ToList().ForEach(ItemSalesColletion.Add); }); SelectCustomerCommand = new DelegateCommand(() => { SelectCustomerWindow w = new SelectCustomerWindow(); SelectCustomerViewModel model = new SelectCustomerViewModel(w); w.DataContext = model; w.Owner = App.Current.MainWindow; w.ShowDialog(); if (model.CheckedList != null) { CustomerId = model.CheckedList.Id; CustomerName = model.CheckedList.Name; Phone = model.CheckedList.Phone; IM = model.CheckedList.IM; Deposit = model.CheckedList.Deposit; DiscountRate = model.CheckedList.Discount; ItemSalesColletion.ToList().ForEach(s => { s.SoldPirce = s.SoldPirce * DiscountRate / 100; }); if (SelectedItemSales != null) { SoldPirce = SelectedItemSales.SoldPirce; } } }); ClearCustomerCommand = new DelegateCommand(() => { ClearCustomer(); ItemSalesColletion.ToList().ForEach(s => { s.SoldPirce = s.Price * s.SalesCount; }); if (SelectedItemSales != null) { SoldPirce = SelectedItemSales.Price * Count; } DiscountRate = 100; }); SelectCommand = new DelegateCommand <ItemSales>(s => { if (s != null) { SelectedItemSales = s; ItemId = s.ItemId; ItemName = s.ItemName; ItemSize = s.ItemSize; ItemType = s.ItemType; StockPrice = s.StockPrice; Price = s.Price; Count = s.SalesCount; SliderMaximum = s.StockCount; SoldPirce = s.SoldPirce; } }); RemoveCommand = new DelegateCommand <ItemSales>(s => { SOURCE.Remove(s); ItemSalesColletion = new ObservableCollection <ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); ItemId = ""; ItemName = ""; ItemSize = 0; ItemType = 0; StockPrice = 0; Price = 0; Count = 1; }); //ItemMasterColletion = new ObservableCollection<ItemMaster>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); PreviousCommand = new DelegateCommand(() => { PageIndex--; ItemSalesColletion = new ObservableCollection <ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(PageIndex > 0 ? true : false); }); NextCommand = new DelegateCommand(() => { PageIndex++; ItemSalesColletion = new ObservableCollection <ItemSales>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((PageIndex + 1) * PAGESIZE < SOURCE.Count() ? true : false); }); SalesItemCommand = new DelegateCommand(() => { SalesItemWindow w = new SalesItemWindow(); SalesItemViewModel model = new SalesItemViewModel(w); w.DataContext = model; w.Owner = App.Current.MainWindow; w.ShowDialog(); }); CustomerCommand = new DelegateCommand(() => { CustomerWindow w = new CustomerWindow(); CustomerViewModel model = new CustomerViewModel(w); w.DataContext = model; w.Owner = App.Current.MainWindow; w.ShowDialog(); }, () => { return(string.IsNullOrEmpty(CustomerName)); }); StockCommand = new DelegateCommand(() => { StockWindow w = new StockWindow(); StockViewModel model = new StockViewModel(w); w.DataContext = model; w.Owner = App.Current.MainWindow; w.ShowDialog(); }, () => { return(ItemSalesColletion == null || ItemSalesColletion.Count == 0); }); VoidCommand = new DelegateCommand(() => { VoidWindow w = new VoidWindow(); VoidWindowViewModel model = new VoidWindowViewModel(w); w.DataContext = model; w.Owner = App.Current.MainWindow; w.ShowDialog(); }); SoldCommand = new DelegateCommand(() => { StringBuilder message = new StringBuilder(); if (!string.IsNullOrEmpty(CustomerName)) { var ned = Deposit - ItemSalesColletion.Sum(s => s.SoldPirce); if (ned < 0) { message.Append("注意!!!"); message.Append(Environment.NewLine); message.Append("客户余额不足,还差:" + ned + "元"); message.Append(Environment.NewLine); } } message.Append("是否确认售出?"); if (MessageBox.Show(window, message.ToString(), "确认售出点“Yes”,否则点“No”", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.Yes) { if (!string.IsNullOrEmpty(CustomerId)) { ItemSalesColletion.ToList().ForEach(s => { s.CustomerId = CustomerId; s.DepositForUpdate = Deposit; }); } if (SqlServerCompactService.InsertItemSales(ItemSalesColletion.ToList())) { message.Clear(); message.Append("本次共计售出:" + ItemSalesColletion.Sum(s => s.SalesCount) + "件,赚得:" + (ItemSalesColletion.Sum(s => s.SoldPirce) - ItemSalesColletion.Sum(s => s.StockPrice * s.SalesCount)) + "元!"); MessageBox.Show(message.ToString()); ClearItem(); ClearCustomer(); ItemSalesColletion.Clear(); } else { message.Clear(); message.Append("销售失败,请重试!!!"); MessageBox.Show(message.ToString()); } } }, () => { return(ItemSalesColletion != null && ItemSalesColletion.Count > 0); }); }
private void BindData() { SOURCE = new ObservableCollection <Customer>(SqlServerCompactService.GetData("Customer").Cast <Customer>()); SOURCE = new ObservableCollection <Customer>(SOURCE.OrderByDescending(s => s.UpdateTime)); CustomerColletion = new ObservableCollection <Customer>(SOURCE.Skip(PageIndex * PAGESIZE).Take(PAGESIZE)); }
public ViewCustomerDetailViewModel(Window window, Customer customer) { CloseCommand = new DelegateCommand(() => { window.Close(); }); //ITEMSALESSOURCE = new ObservableCollection<ItemSales>(SqlServerCompactService.GetItemSales()); //ItemSalesColletion = new ObservableCollection<ItemSales>(ITEMSALESSOURCE.Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); //ItemSalesPreviousCommand = new DelegateCommand(() => //{ // ItemSalesPageIndex--; // ItemSalesColletion = new ObservableCollection<ItemSales>(ITEMSALESSOURCE.Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); //}, () => { return ItemSalesPageIndex > 0 ? true : false; }); //ItemSalesNextCommand = new DelegateCommand(() => //{ // ItemSalesPageIndex++; // ItemSalesColletion = new ObservableCollection<ItemSales>(ITEMSALESSOURCE.Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); //}, () => { return (ItemSalesPageIndex + 1) * PAGESIZE < ITEMSALESSOURCE.Count() ? true : false; }); ITEMSALESSOURCE = new ObservableCollection <ItemSales>(SqlServerCompactService.GetItemSales(customer.Id)); ItemSalesColletion = new ObservableCollection <ItemSales>(ITEMSALESSOURCE.Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); SearchCommand = new DelegateCommand(() => { var s = ITEMSALESSOURCE.Where(t => t.ItemSalesId.IndexOf(SearchItemSalesId, StringComparison.OrdinalIgnoreCase) >= 0); ItemSalesPageIndex = 0; ItemSalesColletion = new ObservableCollection <ItemSales>(s.Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchItemSalesId) ? false : true); }); AllCommand = new DelegateCommand(() => { SearchItemSalesId = ""; ItemSalesColletion = new ObservableCollection <ItemSales>(ITEMSALESSOURCE.Where(t => t.ItemSalesId.IndexOf(SearchItemSalesId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(string.IsNullOrEmpty(SearchItemSalesId) ? false : true); }); ItemSalesPreviousCommand = new DelegateCommand(() => { ItemSalesPageIndex--; ItemSalesColletion = new ObservableCollection <ItemSales>(ITEMSALESSOURCE.Where(t => t.ItemSalesId.IndexOf(SearchItemSalesId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(ItemSalesPageIndex > 0 ? true : false); }); ItemSalesNextCommand = new DelegateCommand(() => { ItemSalesPageIndex++; ItemSalesColletion = new ObservableCollection <ItemSales>(ITEMSALESSOURCE.Where(t => t.ItemSalesId.IndexOf(SearchItemSalesId, StringComparison.OrdinalIgnoreCase) >= 0).Skip(ItemSalesPageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((ItemSalesPageIndex + 1) * PAGESIZE < ITEMSALESSOURCE.Where(t => t.ItemSalesId.IndexOf(SearchItemSalesId, StringComparison.OrdinalIgnoreCase) >= 0).Count() ? true : false); }); DEPOSITDETAILSOURCE = new ObservableCollection <DepositDetail>(SqlServerCompactService.GetDepositDetail(customer.Id)); DepositDetailColletion = new ObservableCollection <DepositDetail>(DEPOSITDETAILSOURCE.Skip(DepositDetailPageIndex * PAGESIZE).Take(PAGESIZE)); DepositDetailPreviousCommand = new DelegateCommand(() => { DepositDetailPageIndex--; DepositDetailColletion = new ObservableCollection <DepositDetail>(DEPOSITDETAILSOURCE.Skip(DepositDetailPageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return(DepositDetailPageIndex > 0 ? true : false); }); DepositDetailNextCommand = new DelegateCommand(() => { DepositDetailPageIndex++; DepositDetailColletion = new ObservableCollection <DepositDetail>(DEPOSITDETAILSOURCE.Skip(DepositDetailPageIndex * PAGESIZE).Take(PAGESIZE)); }, () => { return((DepositDetailPageIndex + 1) * PAGESIZE < ITEMSALESSOURCE.Count() ? true : false); }); }
/// <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); }); }
static ItemTypeModel() { ItemTypeModelList = SqlServerCompactService.GetData("ItemTypeModel").Cast <ItemTypeModel>().ToList(); }
/// <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(); } } }); }