Beispiel #1
0
        private void GetOrderDetails(object para)
        {
            var dates     = para.ToString().Split('|');
            var startDate = DateTime.Parse(dates[0]).Date;
            var endDate   = DateTime.Parse(dates[1]).Date.AddDays(1);

            try
            {
                using (var context = new OneShopEntities())
                {
                    context.Database.Connection.ConnectionString = this.conn;
                    OrderDetailsNameModels = Common <OrderDetailsNameModel> .QueryJoin(context, startDate, endDate);
                }
                RaisePropertyChanged("OrderDetailsNameModels");
                RaisePropertyChanged("TotalPrice");
                RaisePropertyChanged("TotalActualPrice");
                RaisePropertyChanged("TotalPriceWechat");
                RaisePropertyChanged("TotalPriceAlipay");
                RaisePropertyChanged("TotalPriceCash");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #2
0
        public static IList <OrderDetailsNameModel> QuerySumJoin(OneShopEntities context, DateTime startDate, DateTime endDate)
        {
            var b = QueryJoin(context, startDate, endDate);

            var a = b.GroupBy(x => new { x.ItemBarcode, x.UnitPrice, x.ItemName }).Select(gb => new {
                gb.Key.ItemBarcode,
                gb.Key.UnitPrice,
                gb.Key.ItemName,
                DetailPrice = gb.Sum(f => f.DetailPrice),
                ItemCount   = gb.Sum(c => c.ItemCount),
                ActualPrice = gb.Sum(f => f.ActualPrice)
            }).ToList();

            IList <OrderDetailsNameModel> tmp = new List <OrderDetailsNameModel>();

            a.ForEach(x => tmp.Add(new OrderDetailsNameModel()
            {
                ItemBarcode = x.ItemBarcode,
                ItemCount   = x.ItemCount,
                ItemName    = x.ItemName,
                UnitPrice   = x.UnitPrice,
                DetailPrice = x.DetailPrice,
                ActualPrice = x.ActualPrice
            }));

            return(tmp);
        }
Beispiel #3
0
 public StockListModel(string barcode, string con)
 {
     using (var context = new OneShopEntities())
     {
         context.Database.Connection.ConnectionString = con;
         try
         {
             this.Stock = context.Stocks.FirstOrDefault(x => x.ItemBarcode.Equals(barcode));
             if (Stock != null)
             {
                 detailSalePrice        = (decimal)Stock.SalePrice;
                 detailPrice            = (decimal)Stock.ItemPrice;
                 this.discountViewModel = new DiscountViewModel(con);
             }
         }
         catch (System.Data.Entity.Core.MetadataException ex)
         {
             throw;
         }
         catch (Exception ex1)
         {
             var msg = ex1.Message;
             OneLog.WriteLog(ex1.Message);
             OneLog.WriteLog(ex1.StackTrace);
         }
     }
 }
Beispiel #4
0
 public StockNewViewModel(string conStr)
 {
     entity = new OneShopEntities();
     entity.Database.Connection.ConnectionString = conStr;
     QueryStockListCommand = new DelegateCommand(this.QueryStockListPage, this.IsExistsStock);
     stocks        = new ObservableCollection <Stock>();
     this.PageSize = 20000;
 }
Beispiel #5
0
 public StockNewViewModel(string conStr, string barcode = "")
 {
     entity = new OneShopEntities();
     entity.Database.Connection.ConnectionString = conStr;
     Stock              = new Stock();
     stocks             = new ObservableCollection <Stock>();
     AddNewStockCommand = new DelegateCommand(this.AddOrEditStocks, this.IsExistsStock);
 }
Beispiel #6
0
        public static IList <OrderDetailsNameModel> QueryJoin(OneShopEntities context, DateTime startDate, DateTime endDate)
        {
            var b = context.OrderDetails.Join(
                context.Stocks,
                od => od.ItemBarcode,
                s => s.ItemBarcode,
                (od, s) => new {
                od.DetailID,
                od.ItemBarcode,
                od.OrderID,
                s.ItemName,
                od.UnitPrice,
                od.DetailPrice,
                od.ActualPrice,
                od.Discount,
                od.DatailDate,
                od.ItemCount,
                od.IsValid
            }).Where(
                od => od.DatailDate > startDate &&
                od.DatailDate < endDate
                ).Join(context.Orders,
                       od => od.OrderID,
                       o => o.OrderID,
                       (od, o) => new {
                od.DetailID,
                od.ItemBarcode,
                od.OrderID,
                od.ItemName,
                od.UnitPrice,
                od.DetailPrice,
                od.ActualPrice,
                od.Discount,
                od.DatailDate,
                od.ItemCount,
                od.IsValid,
                o.Remarks
            }).ToList();

            IList <OrderDetailsNameModel> tmp = new List <OrderDetailsNameModel>();

            b.ForEach(x => tmp.Add(new OrderDetailsNameModel()
            {
                DetailID    = x.DetailID,
                ItemBarcode = x.ItemBarcode,
                ItemCount   = x.ItemCount,
                ItemName    = x.ItemName,
                UnitPrice   = x.UnitPrice,
                Discount    = x.Discount,
                DatailDate  = x.DatailDate,
                IsValid     = x.IsValid,
                DetailPrice = x.DetailPrice,
                Remarks     = x.Remarks,
                ActualPrice = x.ActualPrice
            }));
            return(tmp);
        }
Beispiel #7
0
 private void GetOrder(object para)
 {
     using (var context = new OneShopEntities())
     {
         context.Database.Connection.ConnectionString = this.conn;
         OrderDetailsNameModels = Common <OrderDetailsNameModel> .QueryJoin(context, para.ToString());
     }
     RaisePropertyChanged("OrderDetailsNameModels");
     RaisePropertyChanged("TotalPrice");
     RaisePropertyChanged("TotalPriceWechat");
     RaisePropertyChanged("TotalPriceAlipay");
     RaisePropertyChanged("TotalPriceCash");
 }
Beispiel #8
0
        public static IList <OrderDetailsNameModel> QueryJoin(OneShopEntities context, string serial)
        {
            var list = context.OrderDetails.Join(
                context.Orders,
                o => o.OrderID,
                od => od.OrderID,
                (o, od) => new
            {
                o.DetailID,
                od.SerialNumber,
                o.ItemBarcode,
                o.UnitPrice,
                o.DetailPrice,
                o.Discount,
                o.DatailDate,
                o.ItemCount,
                o.IsValid
            }).Where(o => o.SerialNumber.Equals(serial)).Join(
                context.Stocks,
                od => od.ItemBarcode,
                s => s.ItemBarcode,
                (od, s) => new
            {
                od.DetailID,
                s.ItemName,
                od.ItemBarcode,
                od.UnitPrice,
                od.DetailPrice,
                od.Discount,
                od.DatailDate,
                od.ItemCount,
                od.IsValid
            }).ToList();

            IList <OrderDetailsNameModel> tmp = new List <OrderDetailsNameModel>();

            list.ForEach(x => tmp.Add(new OrderDetailsNameModel()
            {
                DetailID    = x.DetailID,
                ItemBarcode = x.ItemBarcode,
                ItemCount   = x.ItemCount,
                ItemName    = x.ItemName,
                UnitPrice   = x.UnitPrice,
                Discount    = x.Discount,
                DatailDate  = x.DatailDate,
                IsValid     = x.IsValid,
                DetailPrice = x.DetailPrice
            }));
            return(tmp);
        }
Beispiel #9
0
        public void SaveOrder(out string stockNotEnough, string payMethod)
        {
            stockNotEnough = string.Empty;

            using (var context = new OneShopEntities())
            {
                context.Database.Connection.ConnectionString = this.ConnectionString;
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        PrepareOrderDetail();
                        this.objOrder.SerialNumber = this.GenerateSerialNumber();
                        this.objOrder.OrderDate    = DateTime.Now;
                        this.objOrder.ModBy        = DateTime.Now;
                        this.objOrder.Remarks      = payMethod;

                        context.Orders.Add(this.objOrder);
                        context.SaveChanges();

                        foreach (var item in objOrderDetail)
                        {
                            item.OrderID = this.objOrder.OrderID;
                            item.IsValid = 0 > item.ItemCount ? false : true;
                            context.OrderDetails.Add(item);
                            var stockItem = context.Stocks.FirstOrDefault(x => x.ItemBarcode.Equals(item.ItemBarcode));
                            stockItem.ItemCount -= item.ItemCount;
                            if (stockItem.ItemCount < 0)
                            {
                                stockNotEnough = $"[{stockItem.ItemName}] 库存不足";
                                this.objOrderDetail.Clear();
                                transaction.Rollback();
                                return;
                            }
                            context.Set <Stock>().Attach(stockItem);
                            context.Entry(stockItem).State = System.Data.Entity.EntityState.Modified;
                        }
                        context.SaveChanges();

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                    }
                }
            }
        }
Beispiel #10
0
        public DiscountViewModel(string con)
        {
            using (var context = new OneShopEntities())
            {
                context.Database.Connection.ConnectionString = con;

                try
                {
                    discounts = context.Discounts.ToList();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Beispiel #11
0
        private void GetDailySummary(object para)
        {
            var firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            try
            {
                using (var context = new OneShopEntities())
                {
                    context.Database.Connection.ConnectionString = this.conn;

                    var sum = context.OrderDetails
                              .GroupBy(x => DbFunctions.TruncateTime(x.DatailDate))
                              .Select(f => new { SumDate = f.Key, Rows = f.Count(), DailySum = f.Sum(w => w.DetailPrice) })
                              .Where(w => w.SumDate > firstDay && w.SumDate < DateTime.Now);
                    var list = sum.ToList();
                    this.DailyMax = list.Max(x => x.DailySum) + 500m;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }