コード例 #1
0
        private void ButSave_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                DataModel.Model.User bindingUser = _userRepository.GetByUserId(_userId);

                bindingUser.CashTotal   = _memberCard.TotalSurplusMoney += _savedMoneyModel.SavedMoney + _savedMoneyModel.PresentedMoney;
                bindingUser.CashBalance = _memberCard.PrincipalSurplusMoney += _savedMoneyModel.SavedMoney;
                bindingUser.CashFee     = _memberCard.FavorableSurplusMoney += _savedMoneyModel.PresentedMoney;

                _memberCard.MemberCardlogs.Add(new DataModel.Model.MemberCardLog
                {
                    FavorableMoney = _savedMoneyModel.PresentedMoney,
                    PrincipalMoney = _savedMoneyModel.SavedMoney,
                    LogType        = (sbyte)DataType.MemberCardLogType.Saved,
                    ChangedBy      = ResourcesHelper.CurrentUser.Name,
                    DateChanged    = DateTime.Now,
                    NewValue       = string.Format(ResourcesHelper.MemberCardLogFormat,
                                                   ComboLogType.Text,
                                                   bindingUser.Name,
                                                   _savedMoneyModel.SavedMoney.ToString("F2"),
                                                   _savedMoneyModel.PresentedMoney.ToString("F2"),
                                                   _memberCard.TotalSurplusMoney.ToString("F2"))
                });
                _memberCardRepository.Update(_memberCard);

                bindingUser.Userlogs.Add(new Userlog
                {
                    LogType     = (sbyte)DataType.MemberCardLogType.Saved,
                    ChangedBy   = ResourcesHelper.CurrentUser.Name,
                    DateChanged = DateTime.Now,
                    NewValue    = string.Format(ResourcesHelper.UserLogMemberCardFormat,
                                                ComboLogType.Text,
                                                _savedMoneyModel.SavedMoney.ToString("F2"),
                                                _savedMoneyModel.PresentedMoney.ToString("F2"),
                                                _memberCard.TotalSurplusMoney.ToString("F2"))
                });
                _userRepository.Update(bindingUser);

                _unitOfWork.Commit();

                MessageBox.Show("充值成功!", Properties.Resources.SystemName,
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteLog(ex.ToString());

                MessageBox.Show("充值失败!", Properties.Resources.SystemName,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }

            _user.ExecuteSearchText();
            Close();
        }
コード例 #2
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _memberCards.Where(x => !string.IsNullOrEmpty(x.MemberCard.Name) &&
                                   !string.IsNullOrEmpty(x.MemberCard.MemberCardNo)).ForEach(x =>
                {
                    if (x.MemberCard.MemberCardId > 0)
                    {
                        if (!x.MemberCard.RelateUserId.HasValue)
                        {
                            x.MemberCard.TotalSurplusMoney     = x.MemberCard.MemberMoney;
                            x.MemberCard.PrincipalSurplusMoney = x.MemberCard.MemberMoney;
                        }
                        CommonHelper.UpdateModifiedOnAndDate(ResourcesHelper.CurrentUser, _memberCards);
                        _memberCardRepository.Update(x.MemberCard);
                    }
                    else
                    {
                        x.MemberCard.TotalSurplusMoney     = x.MemberCard.MemberMoney;
                        x.MemberCard.PrincipalSurplusMoney = x.MemberCard.MemberMoney;
                        _memberCardRepository.Create(x.MemberCard);
                    }
                });

                _unitOfWork.Commit();

                MessageBox.Show("保存成功!", SmallHoneybee.Wpf.Properties.Resources.SystemName,
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteLog(ex.ToString());

                MessageBox.Show("保存失败!", SmallHoneybee.Wpf.Properties.Resources.SystemName,
                                MessageBoxButton.OK, MessageBoxImage.Error);
                ExecuteSearchText();
            }
        }
コード例 #3
0
        private void ButBalance_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                _saleOrder.HowBalance = RadBanlanceModeCash.IsChecked.HasValue && RadBanlanceModeCash.IsChecked.Value
                    ? (SByte)DataType.SaleOrderBalancedMode.Cash
                    : RadBanlanceModeCard.IsChecked.HasValue && RadBanlanceModeCard.IsChecked.Value
                        ? (SByte)DataType.SaleOrderBalancedMode.MemberCard
                        : (SByte)DataType.SaleOrderBalancedMode.UnitUnionPay;

                foreach (var soProduceDomainModel in _soProduceDomainModels)
                {
                    if (soProduceDomainModel.SOProduce.Quantity < 0 &&
                        string.IsNullOrEmpty(soProduceDomainModel.SOProduce.Description))
                    {
                        MessageBox.Show(string.Format("商品'{0}'数量小于零,确认数量或填写备注说明。", soProduceDomainModel.SOProduce.Produce.Name),
                                        Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                    else if (ResourcesHelper.CurrentUserRolePermission.SaleOrderFavorableLimitCost &&
                             soProduceDomainModel.SOProduce.DiscountRate <
                             soProduceDomainModel.SOProduce.Produce.LowestDiscountRate)
                    {
                        MessageBox.Show(string.Format("商品'{0}'折扣过低, 要赔钱了!", soProduceDomainModel.SOProduce.Produce.Name),
                                        Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                }

                if (_balanceDomainModel.DiscountPrice > 0)
                {
                    if (!ResourcesHelper.CurrentUserRolePermission.SaleOrderFavorableCost &&
                        _balanceDomainModel.DiscountPrice > float.Parse(ResourcesHelper.SystemSettings[(short)DataType.SystemSettingCode.SOProduceGeneralMangerMaxDiscountPrice]))
                    {
                        MessageBox.Show("结算失败, 优惠金额超过上限, 要赔钱卖了!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }

                    if (_balanceDomainModel.DiscountPrice > _balanceDomainModel.TotalPrice)
                    {
                        MessageBox.Show("结算失败, 优惠金额大于应收金额, 要赔钱卖了!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                }

                if (RadBanlanceModeCash.IsChecked != null && (bool)RadBanlanceModeCash.IsChecked)
                {
                    if ((_balanceDomainModel.ReturnedPrice < 0))
                    {
                        MessageBox.Show("结算失败, 实收金额小于应收金额, 要多找钱了!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }

                    if (_user.UserId > 0)
                    {
                        _user.Userlogs.Add(new Userlog
                        {
                            ChangedBy   = ResourcesHelper.CurrentUser.Name,
                            LogType     = (sbyte)DataType.MemberCardLogType.Consumption,
                            DateChanged = DateTime.Now,
                            NewValue    = string.Format(
                                ResourcesHelper.UserLogSaleOrderFormat,
                                _saleOrder.SaleOrderNo,
                                CommonHelper.Enumerate <DataType.SaleOrderBalancedMode>().First(x => x.Key == _saleOrder.HowBalance).Value,
                                _balanceDomainModel.ReceivedPrice.ToString("F2"),
                                _balanceDomainModel.CurrentMemberPoints.ToString("F2"),
                                (_balanceDomainModel.SurplusPrice > 0 ? _balanceDomainModel.SurplusPrice : 0).ToString("F2"),
                                (_balanceDomainModel.CurrentMemberPoints + _balanceDomainModel.MemberPoints).ToString("F2"))
                        });

                        _saleOrder.PurchaseOrderUserId = _user.UserId == 0 ? (int?)null : _user.UserId;
                        _user.MemberPoints            += _balanceDomainModel.ReceivedPrice * float.Parse(ResourcesHelper.SystemSettings[(short)DataType.SystemSettingCode.MemberPointsRate]);

                        _userRepository.Update(_user);
                    }
                }
                else if (RadBanlanceModeCard.IsChecked != null && (bool)RadBanlanceModeCard.IsChecked)
                {
                    if (_memberCard.MemberCardId > 0)
                    {
                        if (_balanceDomainModel.SurplusPrice < 0 ||
                            _memberCard.TotalSurplusMoney - _balanceDomainModel.ReceivedPrice < 0)
                        {
                            MessageBox.Show("结算失败, 购物卡余额不足, 请用充值或现金结算!", Properties.Resources.SystemName,
                                            MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }

                        InputPassword inputPassword = new InputPassword(_memberCard.MemberCardId);
                        inputPassword.ShowDialog();
                        if (!inputPassword.IsCheckOK)
                        {
                            return;
                        }

                        float saveMoney = _balanceDomainModel.ReceivedPrice *
                                          (_memberCard.PrincipalSurplusMoney / _memberCard.TotalSurplusMoney);

                        if (_memberCard.FavorableSurplusMoney >= (_balanceDomainModel.ReceivedPrice - saveMoney))
                        {
                            _memberCard.FavorableSurplusMoney -= (_balanceDomainModel.ReceivedPrice - saveMoney);
                            _memberCard.PrincipalSurplusMoney -= saveMoney;
                        }
                        else
                        {
                            _memberCard.PrincipalSurplusMoney -= _balanceDomainModel.ReceivedPrice -
                                                                 _memberCard.FavorableSurplusMoney;
                            _memberCard.FavorableSurplusMoney -= _memberCard.FavorableSurplusMoney;
                        }
                        _memberCard.TotalSurplusMoney -= _balanceDomainModel.ReceivedPrice;

                        _memberCard.MemberCardlogs.Add(new DataModel.Model.MemberCardLog
                        {
                            FavorableMoney = (_balanceDomainModel.ReceivedPrice - saveMoney),
                            PrincipalMoney = saveMoney,
                            LogType        = (sbyte)DataType.MemberCardLogType.Consumption,
                            ChangedBy      = ResourcesHelper.CurrentUser.Name,
                            DateChanged    = DateTime.Now,
                            NewValue       = string.Format(ResourcesHelper.MemberCardLogSaleOrderFormat,
                                                           _saleOrder.SaleOrderNo,
                                                           CommonHelper.Enumerate <DataType.SaleOrderBalancedMode>()
                                                           .First(x => x.Key == _saleOrder.HowBalance)
                                                           .Value,
                                                           _balanceDomainModel.ReceivedPrice.ToString("F2"),
                                                           _balanceDomainModel.CurrentMemberPoints.ToString("F2"),
                                                           (_balanceDomainModel.SurplusPrice > 0 ? _balanceDomainModel.SurplusPrice : 0)
                                                           .ToString("F2"),
                                                           (_balanceDomainModel.CurrentMemberPoints + _balanceDomainModel.MemberPoints)
                                                           .ToString("F2"))
                        });
                        _memberCardRepository.Update(_memberCard);
                    }

                    if (_user.UserId > 0)
                    {
                        float saveMoney = _balanceDomainModel.ReceivedPrice *
                                          (_user.CashBalance / _user.CashTotal);

                        if (_user.CashFee >= (_balanceDomainModel.ReceivedPrice - saveMoney))
                        {
                            _user.CashFee     -= (_balanceDomainModel.ReceivedPrice - saveMoney);
                            _user.CashBalance -= saveMoney;
                        }
                        else
                        {
                            _user.CashBalance -= _balanceDomainModel.ReceivedPrice - _user.CashFee;
                            _user.CashFee     -= _user.CashFee;
                        }
                        _user.CashTotal -= _balanceDomainModel.ReceivedPrice;

                        _user.Userlogs.Add(new Userlog
                        {
                            ChangedBy   = ResourcesHelper.CurrentUser.Name,
                            DateChanged = DateTime.Now,
                            LogType     = (sbyte)DataType.MemberCardLogType.Consumption,
                            NewValue    = string.Format(
                                ResourcesHelper.UserLogSaleOrderFormat,
                                _saleOrder.SaleOrderNo,
                                CommonHelper.Enumerate <DataType.SaleOrderBalancedMode>()
                                .First(x => x.Key == _saleOrder.HowBalance)
                                .Value,
                                _balanceDomainModel.ReceivedPrice.ToString("F2"),
                                _balanceDomainModel.CurrentMemberPoints.ToString("F2"),
                                (_balanceDomainModel.SurplusPrice > 0 ? _balanceDomainModel.SurplusPrice : 0).ToString(
                                    "F2"),
                                (_balanceDomainModel.CurrentMemberPoints + _balanceDomainModel.MemberPoints).ToString(
                                    "F2"))
                        });

                        _saleOrder.PurchaseOrderUserId = _user.UserId == 0 ? (int?)null : _user.UserId;
                        _user.MemberPoints            += _balanceDomainModel.ReceivedPrice *
                                                         float.Parse(
                            ResourcesHelper.SystemSettings[
                                (short)DataType.SystemSettingCode.MemberPointsRate]);

                        _userRepository.Update(_user);
                    }
                }
                else
                {
                    _balanceDomainModel.RealPrice = _balanceDomainModel.ReceivedPrice;
                    if (_user.UserId > 0)
                    {
                        _user.Userlogs.Add(new Userlog
                        {
                            ChangedBy   = ResourcesHelper.CurrentUser.Name,
                            DateChanged = DateTime.Now,
                            LogType     = (sbyte)DataType.MemberCardLogType.Consumption,
                            NewValue    = string.Format(
                                ResourcesHelper.UserLogSaleOrderFormat,
                                _saleOrder.SaleOrderNo,
                                CommonHelper.Enumerate <DataType.SaleOrderBalancedMode>().First(x => x.Key == _saleOrder.HowBalance).Value,
                                _balanceDomainModel.ReceivedPrice.ToString("F2"),
                                _balanceDomainModel.CurrentMemberPoints.ToString("F2"),
                                (_balanceDomainModel.SurplusPrice > 0 ? _balanceDomainModel.SurplusPrice : 0).ToString("F2"),
                                (_balanceDomainModel.CurrentMemberPoints + _balanceDomainModel.MemberPoints).ToString("F2"))
                        });

                        _saleOrder.PurchaseOrderUserId = _user.UserId == 0 ? (int?)null : _user.UserId;
                        _user.MemberPoints            += _balanceDomainModel.ReceivedPrice * float.Parse(ResourcesHelper.SystemSettings[(short)DataType.SystemSettingCode.MemberPointsRate]);

                        _userRepository.Update(_user);
                    }
                }

                SaveSaleOrder(DataType.SaleOrderStatus.Balanced);

                _saleOrder.FavorableCost = _balanceDomainModel.DiscountPrice;
                _saleOrder.TotalCost     = _balanceDomainModel.ReceivedPrice;
                _saleOrder.SOProduces.ForEach(x =>
                {
                    x.Produce.Quantity -= (x.Quantity ?? 0);
                    x.Produce.Producelogs.Add(new Producelog
                    {
                        ChangedBy   = ResourcesHelper.CurrentUser.Name,
                        DateChanged = DateTime.Now,
                        NewValue    = string.Format(ResourcesHelper.ProduceLogSaleOrderFormat,
                                                    _saleOrder.SaleOrderNo,
                                                    (x.Quantity ?? 0).ToString("F2"),
                                                    (x.CostPerUnit ?? 0).ToString("F2"),
                                                    x.Produce.Quantity.ToString("F2"))
                    });
                });
                _saleOrder.SaleOrderStatus = (sbyte)DataType.SaleOrderStatus.Balanced;
                _unitOfWork.Commit();

                if (ResourcesHelper.CurrentUser.UserType != (byte)DataType.UserType.Admin)
                {
                    try
                    {
                        SaleOrderReportPrint.Print(_saleOrder);

                        MessageBox.Show("结算成功!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.WriteLog(ex.ToString());

                        MessageBox.Show("结算成功, 打印小票失败!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }

                SaleOrderWindow.ExecuteSearchText();
                Close();
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteLog(ex.ToString());
                MessageBox.Show("结算失败, 请重新新建零售记录!", SmallHoneybee.Wpf.Properties.Resources.SystemName,
                                MessageBoxButton.OK, MessageBoxImage.Error);

                SaleOrderWindow.ExecuteSearchText();
                Close();
            }
        }
コード例 #4
0
        private void SaveUserWithMemberCard()
        {
            if (_memberCard != null)
            {
                DataModel.Model.User bindingUser = _userRepository.GetByUserId(_userId);

                if (_memberCard.RelateUserId.HasValue)
                {
                    try
                    {
                        if (!ComparePasswordEqual())
                        {
                            return;
                        }
                        SaltedHash saltedHash = SaltedHash.Create(txtFirstPassWord.Password);
                        _memberCard.PasswordHash = saltedHash.Hash;
                        _memberCard.PasswordSalt = saltedHash.Salt;

                        _memberCard.MemberCardlogs.Add(new DataModel.Model.MemberCardLog
                        {
                            ChangedBy   = ResourcesHelper.CurrentUser.Name,
                            DateChanged = DateTime.Now,
                            NewValue    = string.Format("会员: {0}与购物卡: {1}重新设置密码!", bindingUser.Name, _memberCard.MemberCardNo)
                        });

                        _memberCardRepository.Update(_memberCard);

                        _unitOfWork.Commit();

                        MessageBox.Show("密码设置成功!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.WriteLog(ex.ToString());

                        MessageBox.Show("密码设置失败!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    try
                    {
                        if (!ComparePasswordEqual())
                        {
                            return;
                        }
                        SaltedHash saltedHash = SaltedHash.Create(txtFirstPassWord.Password);
                        _memberCard.PasswordHash     = saltedHash.Hash;
                        _memberCard.PasswordSalt     = saltedHash.Salt;
                        _memberCard.DispatchUserId   = ResourcesHelper.CurrentUser.UserId;
                        _memberCard.RelateUserId     = _userId;
                        _memberCard.MemberCardStatus = (sbyte)DataType.MemberCardStatus.Active;

                        _memberCard.MemberCardlogs.Add(new DataModel.Model.MemberCardLog
                        {
                            ChangedBy      = ResourcesHelper.CurrentUser.Name,
                            DateChanged    = DateTime.Now,
                            PrincipalMoney = _memberCard.PrincipalSurplusMoney,
                            FavorableMoney = _memberCard.FavorableSurplusMoney,
                            LogType        = (sbyte)DataType.MemberCardLogType.Saved,
                            NewValue       = string.Format(ResourcesHelper.MemberCardLogUserFormat,
                                                           bindingUser.Name,
                                                           _memberCard.MemberCardNo,
                                                           _memberCard.PrincipalSurplusMoney.ToString("F2"))
                        });
                        _memberCardRepository.Update(_memberCard);

                        DataModel.Model.User user = _userRepository.GetByUserId(_userId);
                        user.CashTotal   = _memberCard.TotalSurplusMoney;
                        user.CashFee     = _memberCard.FavorableSurplusMoney;
                        user.CashBalance = _memberCard.PrincipalSurplusMoney;
                        _userRepository.Update(user);

                        _unitOfWork.Commit();

                        MessageBox.Show("购物卡绑定成功!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    catch (Exception ex)
                    {
                        Log4NetHelper.WriteLog(ex.ToString());

                        MessageBox.Show("购物卡绑定失败!", Properties.Resources.SystemName,
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }

                _user.ExecuteSearchText();
                Close();
            }
        }