仓库管理系统11--物资设置

news2024/10/5 14:25:01

1、添加用户控件 

 

<UserControl x:Class="West.StoreMgr.View.GoodsTypeView"
             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=GoodsType}"
             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 GoodsType.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 GoodsType.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:GoodsTypeView}}"
                     Command="{Binding AddCommand}"/>
            </StackPanel>
        </Grid>

        <!--浏览-->
        <Grid Grid.Row="2" Margin="10 0 10 10">
            <DataGrid ItemsSource="{Binding GoodsTypeList}" 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:GoodsTypeView},Path=DataContext.EditCommand}"
                                         CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" 
                                         Tag="{Binding}" 
                                         Style="{StaticResource DataGridButtonStyle}" />
                                    <Button Content="删除" 
                                         Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:GoodsTypeView},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、添加视图模型

 

 

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;
using System.Windows;

namespace West.StoreMgr.ViewModel
{
    /// <summary>
    /// 物资类别视图模型
    /// </summary>
    public class GoodsTypeViewModel : ViewModelBase
    {
        public GoodsTypeViewModel()
        {
            GoodsTypeList = new GoodsTypeService().Select();
        }
        private GoodsType goodsType = new GoodsType();
        /// <summary>
        /// 物资类别
        /// </summary>
        public GoodsType GoodsType
        {
            get { return goodsType; }
            set { goodsType = value; RaisePropertyChanged(); }
        }

        private List<GoodsType> goodsTypeList = new List<GoodsType>();
        /// <summary>
        /// 物资类别列表
        /// </summary>
        public List<GoodsType> GoodsTypeList
        {
            get { return goodsTypeList; }
            set { goodsTypeList = value; RaisePropertyChanged(); }
        }

        /// <summary>
        /// 增加命令
        /// </summary>
        public RelayCommand<UserControl> AddCommand
        {
            get
            {
                var command = new RelayCommand<UserControl>((view) =>
                {
                    if (string.IsNullOrEmpty(GoodsType.Name) == true)
                    { 
                        MsgWinHelper.ShowError("不能为空!");
                        return;
                    }

                    GoodsType.InsertDate = DateTime.Now;

                    GoodsTypeService service = new GoodsTypeService();
                    int count = service.Insert(GoodsType);
                    if (count > 0)
                    {
                        GoodsTypeList = service.Select(); 
                        MsgWinHelper.ShowMessage("操作成功!");
                        GoodsType = new GoodsType();
                    }
                    else
                    { 
                        MsgWinHelper.ShowError("操作失败!");
                    }
                });

                return command;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        public RelayCommand<Button> EditCommand
        {
            get
            {
                var command = new RelayCommand<Button>((view) =>
                {
                    var old = view.Tag as GoodsType;
                    if (old == null) return;
                    var model = ServiceLocator.Current.GetInstance<EditGoodsTypeViewModel>();
                    model.GoodsType = old;
                    var window = new EditGoodsTypeWindow();
                    window.ShowDialog();
                    GoodsTypeList = new GoodsTypeService().Select();
                });

                return command;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public RelayCommand<Button> DeleteCommand
        {
            get
            {
                var command = new RelayCommand<Button>((view) =>
                { 
                    if (MsgWinHelper.ShowQuestion("您确定要删除该空运详情单吗?") == CustomMessageBoxResult.OK)
                    {
                        var old = view.Tag as GoodsType;
                        if (old == null) return;

                        GoodsTypeService service = new GoodsTypeService();
                        int count = service.Delete(old);
                        if (count > 0)
                        {
                            GoodsTypeList = service.Select();
                            MsgWinHelper.ShowMessage("删除成功!");
                        }
                        else
                        { 
                            MsgWinHelper.ShowError("删除失败!");
                        }
                    } 
                });

                return command;
            }
        }
    }
}

3、运行效果

 

4、编辑物资类别

 1)添加窗体EditGoodsTypeWindow.xaml

<Window x:Class="West.StoreMgr.Windows.EditGoodsTypeWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:West.StoreMgr.Windows"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen"
        DataContext="{Binding Source={StaticResource Locator},Path=EditGoodsType}"
        Title="修改物资类别" Height="350" Width="700">
    <Grid Background="#E4ECEF">
        <Grid Grid.Row="0" 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   HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center"  Margin="0 0 10 0" Text="{Binding GoodsType.Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="100" Height="30" />
                <TextBlock Margin="0 0 10 0" Text="备注:" VerticalAlignment="Center"/>
                <TextBox  HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Left" VerticalContentAlignment="Center" Margin="0 0 10 0" Text="{Binding GoodsType.Tag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="200" Height="30" />
                <!--button-->
                <Button Margin="18 0 0 0" Height="36" Width="200" Grid.Row="3" FontSize="22"
                 Content="修 改" Style="{StaticResource ButtonStyle}" 
                 CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:EditGoodsTypeWindow}}"
                 Command="{Binding EditCommand}"/>
            </StackPanel>
        </Grid>
    </Grid>
</Window>

2)添加viewmodel

 

3)运行效果

 

 5、删除物资类别 

 1)删除命令

2)执行效果

6、小结

 这节实现了页面上数据的增加,删除,修改,查询,前端通过属性命令绑定,后台通过ef自带的方法实现的

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1876953.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[小试牛刀-习题练]《计算机组成原理》之计算机系统概述【详解过程】

【计算机系统概述】 1、【冯诺伊曼结构】计算机中数据采用二进制编码表示&#xff0c;其主要原因是&#xff08;D&#xff09; I、二进制运算规则简单II、制造两个稳态的物理器件较为容易III、便于逻辑门电路实现算术运算 A.仅I、Ⅱ B.仅I、Ⅲ C.仅Ⅱ、Ⅲ D. I、Ⅱ、Ⅲ I…

redis 单节点数据如何平滑迁移到集群中

目的 如何把一个redis单节点的数据迁移到 redis集群中 方案&#xff1a; 使用命令redis-cli --cluster import 导入数据至集群 --cluster-from <arg>--cluster-from-user <arg> 数据源用户--cluster-from-pass <arg> 数据源密码--cluster-from-askpass--c…

Linux开发讲课20--- QSPI

SPI 是英语 Serial Peripheral interface 的缩写&#xff0c;顾名思义就是串行外围设备接口&#xff0c;一种高速的&#xff0c;全双工&#xff0c;同步的通信总线&#xff0c;并且在芯片的管脚上只占用四根线&#xff0c;节约了芯片的管脚&#xff0c;为 PCB 的布局上节省空间…

《SpringBoot+Vue》Chapter04 SpringBoot整合Web开发

返回JSON数据 默认实现 依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>在springboot web依赖中加入了jackson-databind作为JSON处理器 创建一个实体类对象…

为什么Modbus链接/从机不通?From 摩尔信使MThings

为了回应用户平日里关于摩尔信使&#xff08;MThings&#xff09;使用过程中最常见的问题&#xff0c;包括“网络链接连不上”、“为什么不能增加串口”和“为什么从机不通”&#xff0c;我们在此统一介绍解决方法。 1、具备哪些通信能力 支持串口和网络两种通信方式。 需要…

我们后端程序员不是操作MyBatis的CRUD Boy

大家好&#xff0c;我是南哥。 一个对Java程序员进阶成长颇有研究的人&#xff0c;今天我们接着新的一篇Java进阶指南。 为啥都戏称后端是CRUD Boy&#xff1f;难道就因为天天怼着数据库CRUD吗&#xff1f;要我说&#xff0c;是这个岗位的位置要的就是你CRUD&#xff0c;你不…

FastAPI教程II

本文参考FastAPI教程https://fastapi.tiangolo.com/zh/tutorial Cookie参数 定义Cookie参数与定义Query和Path参数一样。 具体步骤如下&#xff1a; 导入Cookie&#xff1a;from fastapi import Cookie声明Cookie参数&#xff0c;声明Cookie参数的方式与声明Query和Path参数…

Hi3861 OpenHarmony嵌入式应用入门--LiteOS MessageQueue

CMSIS 2.0接口中的消息&#xff08;Message&#xff09;功能主要涉及到实时操作系统&#xff08;RTOS&#xff09;中的线程间通信。在CMSIS 2.0标准中&#xff0c;消息通常是通过消息队列&#xff08;MessageQueue&#xff09;来进行处理的&#xff0c;以实现不同线程之间的信息…

650V 1200V 碳化硅MOS TO247 封装 内阻30毫欧 40 80毫欧

650V 1200V 碳化硅MOS TO247 封装 内阻30毫欧 40 80毫欧

Java的IO体系

目录 1、Java的IO体系2、IO的常用方法3、Java中为什么要分为字节流和字符流4、File和RandomAccessFile5、Java对象的序列化和反序列化6、缓冲流7、Java 的IO流中涉及哪些设计模式 1、Java的IO体系 IO 即为 input 输入 和 output输出 Java的IO体系主要分为字节流和字符流两大类…

MySQL中的redo log 和 undo log

undo log和redo log 先引入两个概念&#xff1a; 当我们做了一些操作 (update/delete/insert)&#xff0c;提交事务后要操作MySql中的数据。 为了能够提升性能&#xff0c;引入了两块区域&#xff1a;内存结构和磁盘结构。 磁盘结构&#xff1a; 主要存储的就是数据页&#x…

LeetCode 算法:二叉搜索树中第K小的元素 c++

原题链接&#x1f517;&#xff1a;二叉搜索树中第K小的元素 难度&#xff1a;中等⭐️⭐️ 题目 给定一个二叉搜索树的根节点 root &#xff0c;和一个整数 k &#xff0c;请你设计一个算法查找其中第 k 小的元素&#xff08;从1开始计数&#xff09;。 示例 1&#xff1a;…

页面开发感想

页面开发 1、 前端预览 2、一些思路 2.1、首页自定义element-plus的走马灯 :deep(.el-carousel__arrow){border-radius: 0%;height: 10vh; }需要使用:deep(标签)才能修改样式 或者 ::v-deep 标签 2.2、整体设计思路 <template><div class"card" style&…

机器学习第四十五周周报 SAM优化器

文章目录 week45 SAM优化器摘要Abstract1. 题目2. Abstract3. 锐度感知最小化3.1 问题提出3.2 方法提出 4. 文献解读4.1 Introduction4.2 创新点4.3 实验过程 5. 结论6.代码复现小结参考文献 week45 SAM优化器 摘要 本周阅读了题为Sharpness-Aware Minimization for Efficien…

! Warning: `flutter` on your path resolves to

目录 项目场景&#xff1a; 问题描述 原因分析&#xff1a; 解决方案&#xff1a; 1. 检查并更新.bash_profile或.zshrc文件 2.添加Flutter路径到环境变量 3. 加载配置文件 4.验证Flutter路径 5.重新启动终端 项目场景&#xff1a; 今天重新安装了AndroidStudio,并配置…

Postman设置请求间自动保存返回参数,方便后续请求调用,减少复制粘贴

postman中常常出现&#xff1a;有两个请求&#xff0c;一个请求首先获取验证码或者token&#xff0c;再由得到的验证码或token编写body发送另一个请求。如何设置两个请求间自动关联相关数据呢&#xff1f; 通过环境存储全局变量 现在有两个请求如下图&#xff0c;生成验证码是…

如何制作鼠标悬浮后伸缩的搜索框

引言 许多博客都在使用的伸缩搜索框制作教程 成品展示&#xff08;颜色自行搭配&#xff09; 初步布局 居中盒子&&初始化样式 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewpo…

进程间通信简介-I.MX6U嵌入式Linux C应用编程学习笔记基于正点原子阿尔法开发板

进程间通信简介 进程间通信简介 进程间进程简称IPC(interprocess communication)&#xff0c;进程间通信就是在不同进程之间传递信息或交换信息 进程间通信的目的 数据传输&#xff1a;一个进程需要将它的数据发送给另一个进程 资源共享&#xff1a;多个进程之间共享同样的…

【Docker】集群容器监控和统计 CAdvisor+lnfluxDB+Granfana的基本用法

集群容器监控和统计组合&#xff1a;CAdvisorlnfluxDBGranfana介绍 CAdvisor&#xff1a;数据收集lnfluxDB&#xff1a;数据存储Granfana&#xff1a;数据展示 ‘三剑客’ 安装 通过使用compose容器编排&#xff0c;进行安装。特定目录下新建文件docker-compose.yml文件&am…

使用Vercel 搭建自己的Dashy导航页

背景 Dashy 是一个开源的自托管导航页面配置服务&#xff0c;它具有易于使用的可视化编辑器、状态检查、小工具和主题等功能。用户可以利用 Dashy 将自己常用的一些网站聚合起来&#xff0c;形成一个个性化的导航页面。 同类的竞品还有Heimdall, Flare 等。 可以通过Docker 等…