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

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.mfbz.cn/a/759013.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

sqlserver开启CDC

1、背景 由于需要学习flink cdc&#xff0c;并且数据选择sqlserver&#xff0c;所以这里记录sqlserver的cdc开启操作步骤。 2、基础前提 官方介绍地址&#xff1a;https://learn.microsoft.com/zh-cn/sql/relational-databases/track-changes/enable-and-disable-change-dat…

Ubuntu22.04 源码安装 PCL13+VTK-9.3+Qt6,踩坑记录

Ubuntu 22.04LTS;cmake-3.25.0;VTK-9.3;PCL-1.13;Qt6.6 PCL可以通过 apt 命令直接安装(sudo apt install libpcl-dev),apt 命令安装的 VTK 是简略版,没有对 Qt 支持的包,所以笔者使用源码安装 PCL 和 VTK。 1. 安装 VTK 1) 安装 ccmake 和 VTK 依赖项: sudo apt-g…

DataWhale-吃瓜教程学习笔记 (五)

学习视频&#xff1a;第4章-决策树_哔哩哔哩_bilibili 西瓜书对应章节&#xff1a; 第四章 4.1&#xff1b;4.2 文章目录 决策树算法原理- 逻辑角度- 几何角度 ID3 决策树- 自信息- 信息熵 &#xff08;自信息的期望&#xff09;- 条件熵 &#xff08; Y 的信息熵关于概率分布 …

从万里长城防御体系看软件安全体系建设@安全历史03

长城&#xff0c;是中华民族的一张重要名片&#xff0c;是中华民族坚韧不屈、自强不息的精神象征&#xff0c;被联合国教科文组织列入世界文化遗产名录。那么在古代&#xff0c;长城是如何以其复杂的防御体系&#xff0c;一次次抵御外族入侵&#xff0c;而这些防御体系又能给软…

HarmonyOS Next开发学习手册——创建轮播 (Swiper)

Swiper 组件提供滑动轮播显示的能力。Swiper本身是一个容器组件&#xff0c;当设置了多个子组件后&#xff0c;可以对这些子组件进行轮播显示。通常&#xff0c;在一些应用首页显示推荐的内容时&#xff0c;需要用到轮播显示的能力。 针对复杂页面场景&#xff0c;可以使用 Sw…

C++ sizeof的各种

C sizeof的各种 1. 含有虚函数的类对象的空间大小2. 虚拟继承的类对象的空间大小3. 普通变量所占空间大小4. 复合数据类型&#xff08;结构体和类&#xff09;5. 数组6. 类型别名7. 动态分配内存8. 指针9. 静态变量10. 联合体11. 结构体使用#program pack 1. 含有虚函数的类对象…

firewalld防火墙转发流量到其他端口forward port rules

假设云主机eth0: 47.93.27.106 tun0: inet 10.8.0.1 netmask 255.255.255.0 Show rules for a specific zone (public) sudo firewall-cmd --zonepublic --list-all Add the tun0 interface to the public zone: sudo firewall-cmd --zonepublic --add-interfacetun0 --…

关于图片大小问题造成的QPixmap或QImage读取图片失败的解决办法

今天碰到一个奇怪又离谱的问题 : 图片加载失败。明明路径是正确的&#xff0c;图片也实实在在存在。。。 经过比对&#xff0c;发现如下问题&#xff1a; 我就齐了怪了 这大小怎么差这么多&#xff1f;会不会是这里除了问题。秉持着怀疑的态度&#xff0c;我试着用GIMP重新导出…

机械设计简单介绍

机械设计简单介绍 1 介绍1.1 概述1.2 机械机构设计基本步骤1.3 关键1.3.1 静力学1.3.2 动力学1.3.3 运动学1.3.4 刚度学 1.4 示例【机械臂】 2 资料2.1 知识体系2.2 博客类汇总2.3 免费CAD模型获取2.4 3D打印2.5 SolidWorks 3 具备能力3.1 熟练翻阅 机械设计手册3.2 知道 N 家常…

【01-02】Mybatis的配置文件与基于XML的使用

1、引入日志 在这里我们引入SLF4J的日志门面&#xff0c;使用logback的具体日志实现&#xff1b;引入相关依赖&#xff1a; <!--日志的依赖--><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version&g…

Part 8.3.3 最近公共祖先

两个点的最近公共祖先&#xff0c;即两个点的所有公共祖先中&#xff0c;离根节点最远的一个节点。 【模板】最近公共祖先&#xff08;LCA&#xff09; 题目描述 如题&#xff0c;给定一棵有根多叉树&#xff0c;请求出指定两个点直接最近的公共祖先。 输入格式 第一行包含…

VMware虚拟机安装CentOS7.9 Oracle 11.2.0.4 RAC+单节点RAC ADG

目录 一、参考资料 二、RAC环境配置清单 1.主机环境 2.共享存储 3.IP地址 4.虚拟机 三、系统参数配置 1. 配置网卡 1.1 配置NAT网卡 1.2 配置HostOnly网卡 2. 修改主机名 3. 配置/etc/hosts 4. 关闭防火墙 5. 关闭Selinux 6. 配置内核参数 7. 配置grid、oracle…

vue3:星星评分组件

一、效果 二、代码 子组件stars.vue&#xff1a; <template><div class"stars"><div class"star" v-for"star in stars" :key"star" click"setScore(star)"><svgt"1719659437525"class&qu…

贪心算法题目总结

1. 整数替换 看到这道题目&#xff0c;我们首先能想到的方法就应该是递归解法&#xff0c;我们来画个图 此时我们出现了重复的子问题&#xff0c;就可以使用递归&#xff0c;只要我们遇到偶数&#xff0c;直接将n除以2递归下去&#xff0c;如果是奇数&#xff0c;选出加1和减1中…

面试框架一些小结

springcloud的⼯作原理 springcloud由以下⼏个核⼼组件构成&#xff1a; Eureka&#xff1a;各个服务启动时&#xff0c;Eureka Client都会将服务注册到Eureka Server&#xff0c;并且Eureka Client还可以反过来从Eureka Server拉取注册表&#xff0c; 从⽽知道其他服务在哪⾥ …

Java+JSP+Mysql+Tomcat实现Web图书管理系统

简介&#xff1a; 本项目是基于springspringmvcJdbcTemplate实现的图书馆管理系统&#xff0c;包含基本的增删改查功能&#xff0c;可作为JavaWeb初学者的入门学习案例。 环境要求&#xff1a; java8 mysql5.7及以下 eclipse最新版 项目目录 模块设计 页面设计 1. 登录页…

【Spring Boot】认识 JPA 的接口

认识 JPA 的接口 1.JPA 接口 JpaRepository2.分页排序接口 PagingAndSortingRepository3.数据操作接口 CrudRepository4.分页接口 Pageable 和 Page5.排序类 Sort JPA 提供了操作数据库的接口。在开发过程中继承和使用这些接口&#xff0c;可简化现有的持久化开发工作。可以使 …

汽车尾灯(转向灯)电路设计

即当汽车进行转弯时,司机打开转向灯,尾灯会根据转向依次被点亮,经过一定的间隔后,再全部被消灭。不停地重复,直到司机关闭转向灯。 该效果可由以下电路实现: 完整电路图: 02—电路设计要点 延时电路的要点主要有两个: 一、当转向开关被按下时,LED需要逐个亮起; 二、LED被逐…

【AI编译器】triton学习:编程模型

介绍 动机 在过去十年里&#xff0c;深度神经网络 (DNNs) 已成为机器学习 (ML) 模型的一个重要分支&#xff0c;能够实现跨领域多种应用中的最佳性能。这些模型由一系列包括参数化&#xff08;如滤波器&#xff09;和非参数化&#xff08;如缩小值函数&#xff09;元件组成的…

STM32 HAL库里 串口中断回调函数是在怎么被调用的?

跟着正点原子学习的HAL库写串口接收程序的时候一直有困惑&#xff0c;使用HAL_UART_Receive_IT开启接收中断后&#xff0c;为啥处理函数要写在HAL_UART_RxCpltCallback里&#xff0c;中断发生的时候是怎么到这个回调函数里去的&#xff1f; void MX_USART1_UART_Init(void) {h…
最新文章