仓库管理系统18--出库管理

原创不易,打字不易,截图不易,多多点赞,送人玫瑰,留有余香,财务自由明日实现。 

1、创建用户控件OutStoreView

 

<UserControl x:Class="West.StoreMgr.View.OutStoreView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:West.StoreMgr.View"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             mc:Ignorable="d" 
             DataContext="{Binding Source={StaticResource Locator},Path=OutStore}"   >
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction Command="{Binding LoadCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <!--标题-->
        <StackPanel Background="#EDF0F6" Orientation="Horizontal">
            <TextBlock Margin="10 0 0 0" Text="&#xf015;" FontSize="20" FontFamily="/Fonts/#FontAwesome" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="#797672"/>
            <TextBlock Margin="10 0 0 0" Text="首页 > 物资出库" FontSize="20" FontFamily="/Fonts/#FontAwesome" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="#797672"/>
        </StackPanel>

        <!--增加-->
        <Grid Grid.Row="1" Margin="20">
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border Background="#72BBE5">
                <TextBlock Text="添加出库数据" FontSize="18" VerticalAlignment="Center" Foreground="#1F3C4C" Margin="0 0 10 0"/>
            </Border>
            <StackPanel Grid.Row="1" Orientation="Vertical" VerticalAlignment="Center"  Margin="0 10 0 10">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                    <TextBlock Margin="0 0 10 0" Text="选择仓库:" VerticalAlignment="Center" Width="80"/>
                    <ComboBox x:Name="comboboxGoodsType" Margin="0 0 10 0" ItemsSource="{Binding StoreList}" SelectedItem="{Binding Store}" DisplayMemberPath="Name" SelectedValuePath="Id" Width="150" Height="30" />
                    <TextBlock Margin="0 0 10 0" Text="选择客户:" VerticalAlignment="Center" Width="80"/>
                    <ComboBox x:Name="comboboxSpec" Margin="0 0 10 0" ItemsSource="{Binding CustomerList}" SelectedItem="{Binding Customer}" DisplayMemberPath="Name" SelectedValuePath="Id" Width="150" Height="30" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center"  Margin="0 10 0 10">
                    <Button Background="BlanchedAlmond" FontFamily="微软雅黑" FontSize="15" Content="选择出库物资" Command="{Binding OpenSelectGoodsWindow}"/>
                    <TextBlock Margin="10 0 10 0" Text=" 序号:" VerticalAlignment="Center" Width="80"/>
                    <TextBox  Background="#E4ECEF" IsReadOnly="True" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center"   Margin="0 0 10 0" Text="{Binding OutStore.GoodsSerialEx,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="150" Height="30" />
                    <TextBlock Margin="0 0 10 0" Text="物资名称:" VerticalAlignment="Center" Width="80"/>
                    <TextBox  Background="#E4ECEF" IsReadOnly="True" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center"   Margin="0 0 10 0" Text="{Binding OutStore.NameEx,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="150" Height="30" />
                    <TextBlock Margin="7 0 10 0" Text="单位:" VerticalAlignment="Center" Width="auto"/>
                    <TextBox HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center" Margin="0 0 10 0" Text="{Binding OutStore.UnitEx,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="170" Height="30" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center"  Margin="0 10 0 10">
                    <TextBlock Margin="0 0 10 0" Text="出库数量:" VerticalAlignment="Center" Width="80"/>
                    <TextBox HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center" Margin="0 0 10 0" Text="{Binding OutStore.NumberEx,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="150" Height="30" />
                    <TextBlock Margin="0 0 10 0" Text="出库价格:" VerticalAlignment="Center" Width="80"/>
                    <TextBox HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center" Margin="0 0 10 0" Text="{Binding OutStore.PriceEx,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="150" Height="30" />
                    <TextBlock Margin="0 0 10 0" Text="备注:" VerticalAlignment="Center" Width="80"/>
                    <TextBox HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center" Margin="0 0 10 0" Text="{Binding OutStore.TagEx,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="230" Height="30" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0 10 0 10">                   
                    <Button Margin="542 0 0 0" Height="36" Width="199" FontSize="20"
                        Content="增 加" Style="{StaticResource ButtonStyle}" 
                        CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:OutStoreView}}"
                        Command="{Binding AddCommand}"/>
                </StackPanel>
            </StackPanel>
        </Grid>

        <!--浏览-->
        <Grid Grid.Row="2" Margin="10 -10 10 10">
            <DataGrid ItemsSource="{Binding OutStoreList}" CanUserDeleteRows="False" CanUserAddRows="False" AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="序号" Binding="{Binding GoodsSerial}"/>
                    <DataGridTextColumn Header="名称" Binding="{Binding Name}"/>
                    <DataGridTextColumn Header="仓库" Binding="{Binding StoreName}"/>
                    <DataGridTextColumn Header="客户" Binding="{Binding CustomerName}"/>
                    <DataGridTextColumn Header="出库数量" Binding="{Binding Number}"/>
                    <DataGridTextColumn Header="出库价格" Binding="{Binding Price}" IsReadOnly="True"/>
                    <DataGridTextColumn Header="备注" Binding="{Binding Tag}"/>
                    <DataGridTextColumn Header="出库日期" Binding="{Binding InsertDate}"/>
                    <DataGridTemplateColumn  Header="操作">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Button Content="编辑" 
                                            Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:GoodsView},Path=DataContext.EditCommand}"
                                            CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" 
                                            Tag="{Binding}" 
                                            Style="{StaticResource DataGridButtonStyle}" />
                                    <Button Content="删除" 
                                            Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:GoodsView},Path=DataContext.DeleteCommand}"
                                            CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}"
                                            Tag="{Binding}" 
                                            Style="{StaticResource DataGridButtonStyle}" />
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </Grid>
</UserControl>

 2、创建出库viewmodel

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using West.StoreMgr.Helper;
using West.StoreMgr.View;
using West.StoreMgr.Service;

namespace West.StoreMgr.ViewModel
{
    /// <summary>
    /// 出库viewmodel
    /// </summary>
    public class OutStoreViewModel : ViewModelBase
    {
        //添加 
        public RelayCommand<UserControl> AddCommand
        {
            get
            {
                var command = new RelayCommand<UserControl>((obj) =>
                {
                    if (!(obj is OutStoreView view)) return;
                    if (string.IsNullOrEmpty(OutStore.Name) == true
                    || string.IsNullOrEmpty(OutStore.GoodsSerial) == true)
                    {
                        MsgWinHelper.ShowError("序号和名字不能为空");
                        return;
                    }

                    OutStore.InsertDate = DateTime.Now;
                    OutStore.UserInfoId = AppData.Instance.User.Id;

                    if (Store.Id == 0)
                    {
                        MsgWinHelper.ShowError("仓库不能为空");
                        return;
                    }

                    if (Customer.Id == 0)
                    {
                        MsgWinHelper.ShowError("客户不能为空");
                        return;
                    }

                    if (Goods.Quant < OutStore.Number)
                    {
                        MsgWinHelper.ShowError("存库不足");
                        return;
                    }

                    OutStore.StoreId = Store.Id;
                    OutStore.StoreName = Store.Name;
                    OutStore.CustomerId = Customer.Id;
                    OutStore.CustomerName = Customer.Name;


                    var service = new OutStoreService();
                    int count = service.Insert(OutStore);
                    if (count > 0)
                    {
                        //及时更新当前物资的存量
                        if (Goods != null)
                        {
                            Goods.Quant -= OutStore.Number;
                            GoodsService goodsService = new GoodsService();
                            count = goodsService.Update(this.Goods);
                        }
                        OutStoreList = new OutStoreService().Select();
                        OutStore = new OutStore();
                        MsgWinHelper.ShowMessage("操作成功");

                    }
                    else
                    {
                        MsgWinHelper.ShowError("操作失败");
                    }
                });

                return command;
            }
        }

        //加载数据
        public RelayCommand LoadCommand
        {
            get
            {
                return new RelayCommand(() =>
                {
                    StoreList = new StoreService().Select();
                    CustomerList = new CustomerService().Select();
                    OutStoreList = new OutStoreService().Select();
                });
            }
        }

        private Store store = new Store();
        /// <summary>
        /// 当前仓库
        /// </summary>
        public Store Store
        {
            get { return store; }
            set { store = value; RaisePropertyChanged(); }
        }

        private List<Store> storeList = new List<Store>();
        /// <summary>
        /// 仓库集合
        /// </summary>
        public List<Store> StoreList
        {
            get { return storeList; }
            set { storeList = value; RaisePropertyChanged(); }
        } 

        private Customer customer = new Customer();
        /// <summary>
        /// 当前客户
        /// </summary>
        public Customer Customer
        {
            get { return customer; }
            set { customer = value; RaisePropertyChanged(); }
        } 

        private List<Customer> customerList = new List<Customer>();
        /// <summary>
        /// 客户集合
        /// </summary>
        public List<Customer> CustomerList
        {
            get { return customerList; }
            set { customerList = value; RaisePropertyChanged(); }
        }


        private OutStore outstore = new OutStore();
        /// <summary>
        /// 出库
        /// </summary>
        public OutStore OutStore
        {
            get { return outstore; }
            set { outstore = value; RaisePropertyChanged(); }
        }

        private List<OutStore> outStoreList = new List<OutStore>();
        /// <summary>
        /// 出库历史记录
        /// </summary>
        public List<OutStore> OutStoreList
        {
            get { return outStoreList; }
            set { outStoreList = value; RaisePropertyChanged(); }
        }
         
        private Goods goods = new Goods();
        /// <summary>
        /// 当前选择的资物对象
        /// </summary>
        public Goods Goods
        {
            get { return goods; }
            set { goods = value; RaisePropertyChanged(); }
        }

        /// <summary>
        /// 选择出库物资命令
        /// </summary>
        public RelayCommand OpenSelectGoodsWindow
        {
            get
            {
                return new RelayCommand(() =>
                {
                    var window = new SelectGoodsWindow();
                    var result = window.ShowDialog();
                    if (result.HasValue && result.Value == true)
                    {
                        var vm = window.DataContext as SelectGoodsViewModel;
                        OutStore.GoodsSerialEx = vm.Goods.Serial;
                        OutStore.NameEx = vm.Goods.Name;
                        this.Goods = vm.Goods;
                    }
                });
            }
        }
    }
}

 3、运行效果

 

 

原创不易,打字不易,截图不易,多多点赞,送人玫瑰,留有余香,财务自由明日实现

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hqwest

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值