仓库管理系统15--规格设置

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

1、添加用户控件 

在 WPF 中,如果想要复用 Xaml 代码,最先想到的肯定是用户控件(UserControl)

 

<UserControl x:Class="West.StoreMgr.View.SpecView"
             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"
             mc:Ignorable="d" 
             DataContext="{Binding Source={StaticResource Locator},Path=Spec}"
             d:DesignHeight="450" d:DesignWidth="800">
    <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="Horizontal" VerticalAlignment="Center">
                <TextBlock Margin="0 0 10 0" Text="规格名称:" VerticalAlignment="Center"/>
                <TextBox Margin="0 0 10 0" Text="{Binding Spec.Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="100" Height="30" />
                <TextBlock Margin="0 0 10 0" Text="备注:" VerticalAlignment="Center"/>
                <TextBox Margin="0 0 10 0" Text="{Binding Spec.Tag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="200" Height="30" />
                <!--button-->
                <Button Margin="18 0 0 0" Height="36" Width="199" Grid.Row="3" 
                        Content="增加" Style="{StaticResource ButtonStyle}" 
                        CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:SpecView}}"
                        Command="{Binding AddCommand}"/>
            </StackPanel>
        </Grid>

        <!--浏览-->
        <Grid Grid.Row="2" Margin="10 0 10 10">
            <DataGrid ItemsSource="{Binding SpecList}" CanUserAddRows="False" AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="序号" Binding="{Binding Id}"/>
                    <DataGridTextColumn Header="物资类型" Binding="{Binding Name}"/>
                    <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:SpecView},Path=DataContext.EditCommand}"
                                            CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" 
                                            Tag="{Binding}" 
                                            Style="{StaticResource DataGridButtonStyle}" />
                                    <Button Content="删除" 
                                            Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:SpecView},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.Service;
using CommonServiceLocator;
using West.StoreMgr.Windows;
using static West.StoreMgr.Windows.MsgBoxWindow;


namespace West.StoreMgr.ViewModel
{
    /// <summary>
    /// 规格viewmodel
    /// </summary>
    public class SpecViewModel : ViewModelBase
    {
        public SpecViewModel()
        {
            SpecList = new SpecService().Select();
        }

        private Spec spec = new Spec();
        public Spec Spec
        {
            get { return spec; }
            set { spec = value; RaisePropertyChanged(); }
        }

        private List<Spec> specList = new List<Spec>();

        public List<Spec> SpecList
        {
            get { return specList; }
            set { specList = value; RaisePropertyChanged(); }
        }

        //添加
        public RelayCommand AddCommand
        {
            get
            {
                var command = new RelayCommand(() =>
                {
                    if (string.IsNullOrEmpty(Spec.Name) == true)
                    {
                        MsgWinHelper.ShowError("不能为空");
                        return;
                    }

                    Spec.InsertDate = DateTime.Now;

                    var service = new SpecService();
                    int count = service.Insert(Spec);
                    if (count > 0)
                    {
                        SpecList = service.Select();
                        MsgWinHelper.ShowMessage("操作成功");
                        Spec = new Spec();
                    }
                    else
                    {
                        MsgWinHelper.ShowError("操作失败");
                    }
                });

                return command;
            }
        }

        //修改
        public RelayCommand<Button> EditCommand
        {
            get
            {
                var command = new RelayCommand<Button>((view) =>
                {
                    var old = view.Tag as Spec;
                    if (old == null) return;
                    var model = ServiceLocator.Current.GetInstance<EditSpecViewModel>();
                    model.Spec = old;
                    var window = new EditSpecWindow();
                    window.ShowDialog();
                    SpecList = new SpecService().Select();
                });

                return command;
            }
        }

        //删除
        public RelayCommand<Button> DeleteCommand
        {
            get
            {
                var command = new RelayCommand<Button>((view) =>
                {
                    if (MsgWinHelper.ShowQuestion("您确定要删除该物资规格吗?") == CustomMessageBoxResult.OK)
                    {
                        var old = view.Tag as Spec;
                        if (old == null) return;

                        var service = new SpecService();
                        int count = service.Delete(old);
                        if (count > 0)
                        {
                            SpecList = service.Select();
                            MsgWinHelper.ShowMessage("操作成功");
                        }
                        else
                        {
                            MsgWinHelper.ShowError("操作失败");
                        }
                    }
                });

                return command;
            }
        }
    }
}

 3、运行效果

 

 

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

### 数据库课程设计中仓库管理系统的功能需求分析和设计方案 #### 功能需求分析 仓库管理系统的主要目标是对企业的商品、库房以及职工的信息进行全面而高效的管理。以下是基于已有资料的功能需求分析: 1. **商品信息管理** 商品信息的维护是系统的重要组成部分,需支持对商品信息的增删改查操作。商品信息通常包括但不限于商品号、品名、类别、规格、单价和计量单位等[^2]。 2. **库房信息管理** 库房信息同样需要具备完整的增删改查功能。库房信息一般包含库房号、库名、地点和面积等内容。此外,还需考虑到不同库房可能存储多种商品的情况。 3. **职工信息管理** 职工信息的管理也是一项核心功能,主要包括职工的工号、姓名、性别和电话等基础信息的维护。每位职工可能会负责多个库房的工作,并参与多类商品的出入库操作[^2]。 4. **商品出入库管理** 出入库操作是仓库管理的关键环节之一,每一次操作都需要详细记录相关信息,如出入库的操作类型、商品的具体名称及其数量、存放位置(即对应的库房)、经手人员以及具体的日期等。 5. **查询统计功能** 系统应当提供灵活且强大的查询能力,允许用户依据特定条件检索符合条件的商品信息或其他相关内容。这有助于提高工作效率并满足多样化的业务需求[^1]。 #### 设计方案概述 为了实现上述功能需求,下面给出一种可行的设计方案框架: 1. **数据库表结构设计** - **商品表 (Product)** 字段建议设置为 `product_id`(商品编号),`name`(品名),`category`(类别),`specification`(规格),`price`(单价),`unit`(计量单位)等。 - **库房表 (Warehouse)** 主要字段可设为 `warehouse_id`(库房编号),`location_name`(库名),`address`(地点),`area`(面积)等。 - **职工表 (Employee)** 包含字段如 `employee_id`(工号),`full_name`(姓名),`gender`(性别),`phone_number`(电话号码)等。 - **出入库记录表 (Inventory_Record)** 记录每次出入库详情,字段推荐有 `record_id`(记录ID),`operation_type`(操作类型:入/出库),`quantity`(数量),`date_time`(时间戳),外键关联至对应商品 (`product_id`) 和库房 (`warehouse_id`) 的 ID 列。 下面是一个简单的 SQL 表创建语句示例: ```sql CREATE TABLE Product ( product_id INT PRIMARY KEY, name VARCHAR(255), category VARCHAR(100), specification TEXT, price DECIMAL(10, 2), unit VARCHAR(50) ); CREATE TABLE Warehouse ( warehouse_id INT PRIMARY KEY, location_name VARCHAR(255), address VARCHAR(255), area FLOAT ); CREATE TABLE Employee ( employee_id INT PRIMARY KEY, full_name VARCHAR(255), gender ENUM('M', 'F'), phone_number VARCHAR(15) ); CREATE TABLE Inventory_Record ( record_id INT AUTO_INCREMENT PRIMARY KEY, operation_type ENUM('IN', 'OUT') NOT NULL, quantity INT NOT NULL, date_time DATETIME DEFAULT CURRENT_TIMESTAMP, product_id INT, warehouse_id INT, FOREIGN KEY (product_id) REFERENCES Product(product_id), FOREIGN KEY (warehouse_id) REFERENCES Warehouse(warehouse_id) ); ``` 2. **界面交互设计** 用户界面应直观易用,便于管理员执行各项任务。例如,可以通过表格形式展示当前库存状态,利用下拉菜单或输入框完成新数据录入等工作流。 3. **权限控制机制** 对不同类型用户提供差异化的访问权限,保障敏感数据的安全性和隐私保护措施到位。比如只有授权管理人员才能修改重要参数设定或者查看某些特殊报表内容。 --- 问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hqwest

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

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

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

打赏作者

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

抵扣说明:

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

余额充值