Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int      userId        = ResourcesHelper.CurrentUser.UserId;
            DateTime startDateTime = DateTime.Now.Date;
            DateTime endDateTime   = DateTime.Now.Date.AddDays(1);
            int      maxTodayId    = _saleOrderRepository.Query()
                                     .Count(x => x.DateOriginated >= startDateTime && x.DateOriginated < endDateTime) + 1;
            string saleOrderNo = string.Format("{0}{1}{2}",
                                               DateTime.Now.ToString("yyyyMMddHH"),
                                               userId,
                                               maxTodayId.ToString().PadLeft(4, '0'));

            var saleOrderForm = new SaleOrderForm(this, new DataModel.Model.SaleOrder
            {
                DateOriginated = DateTime.Now,
                SaleOrderNo    = saleOrderNo,
                OriginUserId   = userId
            });

            saleOrderForm.ShowDialog();
        }
Ejemplo n.º 2
0
        public void ExecuteSearchText()
        {
            _unitOfWork          = UnityInit.UnitOfWork;
            _saleOrderRepository = _unitOfWork.GetRepository <SaleOrderRepository>();

            _saleOrders.Clear();
            IQueryable <DataModel.Model.SaleOrder> saleOrders = _saleOrderRepository.Query();

            if (ResourcesHelper.CurrentUser.UserType < (byte)DataType.UserType.FactoryPriceManger)
            {
                saleOrders =
                    saleOrders.Where(x => x.OriginUserUser.UserType < (byte)DataType.UserType.FactoryPriceManger);
            }

            DateTime?startDate = DateStartDate.SelectedDate;
            DateTime?endDate   = DateEndDate.SelectedDate;

            if (startDate.HasValue && endDate.HasValue)
            {
                endDate    = endDate.Value.AddDays(1);
                saleOrders = saleOrders.Where(x => x.DateOriginated >= startDate &&
                                              x.DateOriginated < endDate);
            }
            else if (startDate.HasValue)
            {
                saleOrders = saleOrders.Where(x => x.DateOriginated >= startDate);
            }
            else if (endDate.HasValue)
            {
                endDate = endDate.Value.AddDays(1);

                saleOrders = saleOrders.Where(x => x.DateOriginated < endDate);
            }

            if (ComboHowBalance.SelectedValue != null)
            {
                sbyte howBalance = (sbyte)ComboHowBalance.SelectedValue;
                saleOrders = saleOrders.Where(x => x.HowBalance == howBalance);
            }

            saleOrders
            .OrderByDescending(x => x.DateOriginated)
            .Where(x => x.SaleOrderNo.Contains(TxtSearchBox.Text) ||
                   x.Name.Contains(TxtSearchBox.Text))
            .ToList()
            .ForEach(x => _saleOrders.Add(x));

            var totalInfo = _saleOrders.Where(x => x.SaleOrderStatus == (byte)DataType.SaleOrderStatus.Balanced)
                            .Select(x => new { x, Group1 = 1 })
                            .GroupBy(x => x.Group1)
                            .Select(m => new
            {
                TotalCount             = m.Count(),
                TotalQuantity          = m.Sum(y => y.x.SOProduces.Sum(s => s.Quantity)),
                TotalPrice             = m.Sum(y => y.x.TotalCost),
                TotalMemberCardPrice   = m.Where(y => y.x.HowBalance == (sbyte)DataType.SaleOrderBalancedMode.MemberCard).Sum(s => s.x.TotalCost),
                TotalCashPrice         = m.Where(y => y.x.HowBalance == (sbyte)DataType.SaleOrderBalancedMode.Cash).Sum(s => s.x.TotalCost),
                TotalUnitUnionPayPrice = m.Where(y => y.x.HowBalance == (sbyte)DataType.SaleOrderBalancedMode.UnitUnionPay).Sum(s => s.x.TotalCost)
            }).FirstOrDefault();

            TxtTotalInfo.Text = string.Format("共计 {0} 条记录, 共计 {1} 件商品, 现金: {2}, 银联: {3}, 购物卡: {4}, 总计 {5}",
                                              totalInfo != null ? totalInfo.TotalCount : 0,
                                              (totalInfo != null ? totalInfo.TotalQuantity ?? 0.0F : 0.0F).ToString("F2"),
                                              (totalInfo != null ? totalInfo.TotalCashPrice ?? 0.0F : 0.0F).ToString("F2"),
                                              (totalInfo != null ? totalInfo.TotalUnitUnionPayPrice ?? 0.0F : 0.0F).ToString("F2"),
                                              (totalInfo != null ? totalInfo.TotalMemberCardPrice ?? 0.0F : 0.0F).ToString("F2"),
                                              (totalInfo != null ? totalInfo.TotalPrice ?? 0.0F : 0.0F).ToString("F2"));
        }
Ejemplo n.º 3
0
        public SaleOrderForm(SaleOrder saleOrderWindow, DataModel.Model.SaleOrder saleOrder)
        {
            InitializeComponent();

            TxtUserNoOrPhone.Focus();

            _unitOfWork           = UnityInit.UnitOfWork;
            _saleOrderRepository  = _unitOfWork.GetRepository <SaleOrderRepository>();
            _soProduceRepository  = _unitOfWork.GetRepository <SOProduceRepository>();
            _produceRepository    = _unitOfWork.GetRepository <ProduceRepository>();
            _userRepository       = _unitOfWork.GetRepository <UserRepository>();
            _memberCardRepository = _unitOfWork.GetRepository <IMemberCardRepository>();

            SaleOrderWindow = saleOrderWindow;

            if (saleOrder.SaleOrderId > 0)
            {
                _saleOrder = _saleOrderRepository.Query()
                             .Single(x => x.SaleOrderId == saleOrder.SaleOrderId);
                _saleOrder.SOProduces.ForEach(x => _soProduceDomainModels.Add(new SOProduceDomainModel
                {
                    SOProduce      = x,
                    CostPerUnit    = x.CostPerUnit,
                    SOProduceTotal = (x.CostPerUnit ?? 0) * x.Quantity ?? 0
                }));

                if (_saleOrder.PurchaseOrderUserId.HasValue)
                {
                    _user       = _userRepository.GetByUserId(_saleOrder.PurchaseOrderUserId.Value);
                    _memberCard =
                        _memberCardRepository.Query()
                        .FirstOrDefault(x => x.IsEnable && x.RelateUserId == _saleOrder.PurchaseOrderUserId);
                    if (_memberCard == null)
                    {
                        _memberCard = new DataModel.Model.MemberCard();
                    }
                }
            }
            else
            {
                _saleOrder = saleOrder;
            }

            if (_saleOrder.SaleOrderStatus == (byte)DataType.SaleOrderStatus.Balanced)
            {
                ButSave.IsEnabled    = false;
                ButBalance.IsEnabled = false;
            }

            if (_saleOrder.HowBalance == (sbyte)DataType.SaleOrderBalancedMode.Cash)
            {
                TabItemCash.IsSelected        = true;
                RadBanlanceModeCash.IsChecked = true;
            }
            else if (_saleOrder.HowBalance == (sbyte)DataType.SaleOrderBalancedMode.MemberCard)
            {
                RadBanlanceModeCard.IsChecked = true;
                TabItemCard.IsSelected        = true;
            }
            else
            {
                RadBanlanceModeUnionPay.IsChecked = true;
                TabItemUnionPay.IsSelected        = true;
            }

            _balanceDomainModel = new BalanceDomainModel
            {
                TotalPrice    = saleOrder.TotalCost ?? 0,
                DiscountPrice = saleOrder.FavorableCost ?? 0,
                CashTotal     = _user.CashTotal,
                RealPrice     = saleOrder.UserRealPrice ?? 0,
                ReturnedPrice = saleOrder.UserReturnedPrice ?? 0
            };

            DataContext = new
            {
                SaleOrder = _saleOrder,
                SOProduceDomainModels,
                ResourcesHelper.CurrentUserRolePermission,
                BalanceDomainModel = _balanceDomainModel,
            };

            TxtDiscount.Text  = _balanceDomainModel.DiscountPrice.ToString();
            TxtRealPrice.Text = _balanceDomainModel.RealPrice.ToString();

            _soProduceDomainModels.CollectionChanged += (sender, e) => SetTotalNameberText();

            SetTotalNameberText();
            SetUserInfo();

            RadBanlanceModeCard.Click += (s, e) =>
            {
                TabItemCard.IsSelected = true;
            };
            RadBanlanceModeCash.Click += (s, e) =>
            {
                TabItemCash.IsSelected = true;
            };
            RadBanlanceModeUnionPay.Click += (s, e) =>
            {
                TabItemUnionPay.IsSelected = true;
            };
        }