예제 #1
0
 public new void Loaded()
 {
     Dispatcher.Invoke(new Action(delegate
     {
         Close();
         Window window = new StockWindow();
         window.Show();
     }));
 }
예제 #2
0
 public static void StartUp()
 {
     DevExpress.Xpf.Core.DXGridDataController.DisableThreadingProblemsDetection = true;
     MainWindow           = new StockWindow();
     MainWindow.MinWidth  = 1024;
     MainWindow.MinHeight = 720;
     MainWindow.Content   = StockLayout;
     MainWindow.Title     = "Egyészségügyi Betegnyilvántartó Rendszer";
     MainWindow.Closing  += ShutDown;
     MainWindow.Show();
 }
예제 #3
0
        /// <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); });
        }