仓库管理系统25--数据导出

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

1、添加用户控件

 

<UserControl x:Class="West.StoreMgr.View.DataExportView"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=DataExport}"d:DesignHeight="450" d:DesignWidth="800"><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 Height="auto"/></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><!--Tabcontrol--><Grid Grid.Row="1" Margin="20"><TabControl ItemsSource="{Binding TabItems}"/></Grid><!--button--><Grid Grid.Row="2" Margin="10 10 10 10"><Button  Height="36" Width="120" Grid.Row="3" HorizontalAlignment="Right"Content="一键导出" Style="{StaticResource ButtonStyle}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=local:DataExportView}}"Command="{Binding BackupCommand}"/></Grid></Grid>
</UserControl>

 2、添加viewmodel

using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using System.IO;
using GalaSoft.MvvmLight.Command;
using West.StoreMgr.Service;
using West.StoreMgr.Control;
using West.StoreMgr.Helper;
using West.StoreMgr.Model;namespace West.StoreMgr.ViewModel
{/// <summary>/// 数据导出viewmodel/// </summary>public class DataExportViewModel : ViewModelBase{private List<Customer> customers = new List<Customer>();private List<Goods> goods = new List<Goods>();private List<GoodsType> goodsTypes = new List<GoodsType>();private List<InStore> inStores = new List<InStore>();private List<Inventory> inventories = new List<Inventory>();private List<OutStore> outStores = new List<OutStore>();private List<OutStore_temp> outStoresTemp = new List<OutStore_temp>();private List<Spec> specs = new List<Spec>();private List<Store> stores = new List<Store>();private List<Supplier> suppliers = new List<Supplier>();private List<UserInfo> userInfos = new List<UserInfo>();private ObservableCollection<TabItem> tabItems = new ObservableCollection<TabItem>();/// <summary>/// tab选项集合/// </summary>public ObservableCollection<TabItem> TabItems{get { return tabItems; }set { tabItems = value; RaisePropertyChanged(); }}public RelayCommand LoadCommand{get{return new RelayCommand(() =>{customers = new CustomerService().Select();goods = new GoodsService().Select();goodsTypes = new GoodsTypeService().Select();inStores = new InStoreService().Select();inventories = new InventoryService().Select();outStores = new OutStoreService().Select();outStoresTemp = BuildList(outStores);specs = new SpecService().Select();stores = new StoreService().Select();suppliers = new SupplierService().Select();userInfos = new UserInfoService().Select();tabItems.Add(new TabItem { Header = "客户表", Content = new TableControl { DataContext = customers } });tabItems.Add(new TabItem { Header = "物资表", Content = new TableControl { DataContext = goods } });tabItems.Add(new TabItem { Header = "物资类别表", Content = new TableControl { DataContext = goodsTypes } });tabItems.Add(new TabItem { Header = "入库表", Content = new TableControl { DataContext = inStores } });tabItems.Add(new TabItem { Header = "盘存表", Content = new TableControl { DataContext = inventories } });tabItems.Add(new TabItem { Header = "出库表", Content = new TableControl { DataContext = outStoresTemp } });tabItems.Add(new TabItem { Header = "规格表", Content = new TableControl { DataContext = specs } });tabItems.Add(new TabItem { Header = "仓库表", Content = new TableControl { DataContext = stores } });tabItems.Add(new TabItem { Header = "供应商表", Content = new TableControl { DataContext = suppliers } });tabItems.Add(new TabItem { Header = "用户表", Content = new TableControl { DataContext = userInfos } });});}}/// <summary>/// 构建新的出库实体(原实体具有扩展属性,这是不必要的)/// </summary>/// <param name="outStores"></param>/// <returns></returns>List<OutStore_temp> BuildList(List<OutStore> outStores){List<OutStore_temp> list = new List<OutStore_temp>();foreach(OutStore item in outStores){OutStore_temp temp = new OutStore_temp();temp.Id = item.Id;temp.GoodsSerial = item.GoodsSerial;temp.Name = item.Name;temp.StoreId = item.StoreId;temp.StoreName = item.StoreName;temp.CustomerId = item.CustomerId;temp.CustomerName = item.CustomerName;temp.Unit = item.Unit;temp.Number = item.Number;temp.Price = item.Price;temp.InsertDate = item.InsertDate;temp.GoodsTypeId = item.GoodsTypeId;temp.UserInfoId = item.UserInfoId;temp.UserInfoName = item.UserInfoName;temp.Tag = item.Tag;temp.IsInventory = item.IsInventory; list.Add(temp); }return list;}/// <summary>/// 导出命令/// </summary>public RelayCommand BackupCommand{get{return new RelayCommand(() =>{Backup(customers, "customers");Backup(goods, "goods");Backup(goodsTypes, "goodsTypes");Backup(inStores, "inStores");Backup(inventories, "inventories");Backup(outStoresTemp, "outStores");Backup(specs, "specs");Backup(stores, "stores");Backup(suppliers, "suppliers");Backup(userInfos, "userInfos");});}}/// <summary>/// 导出数据/// </summary>/// <param name="array">列表对象</param>/// <param name="filename">文件名称</param>/// <exception cref="NotImplementedException"></exception>private void Backup<T>(List<T> array, string name){var t = typeof(T);var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);var contents = new StringBuilder();//标题foreach (var item in properties){//得到第一个自定义属性的参数的值,即属性描述var desc = item.CustomAttributes.ToList()[0].ConstructorArguments[0].Value.ToString();  contents.Append(desc);contents.Append(",");} contents.Append("\r\n");//换行//内容foreach (var model in array){var row = new StringBuilder();foreach (var property in properties){var val = property.GetValue(model);row.Append(val);row.Append(",");}contents.Append(row.ToString());contents.Append("\r\n");}//finename -> 表格+日期var date = $"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}";var filename = $"c:\\{name}{date}.csv";//保存File.WriteAllText(filename, contents.ToString(),Encoding.UTF8);//以utf-8的格式保存成csv格式MsgWinHelper.ShowMessage("数据导出完成");}}
}

3、运行效果

 

 

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

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

相关文章

全年免费!环信发布出海创新版,助力泛娱乐创业者扬帆起航

目前&#xff0c;以陌生人社交、直播、语聊、电商等热门场景为代表的社交泛娱乐出海正发展得如火如荼&#xff0c;成为企业新的增长曲线。但随着出海企业增多&#xff0c;海外市场争夺、资源竞争与技术博弈也愈加激烈。 为了让更多创业者与创新者获得支持&#xff0c;快速高效…

onCreateOptionsMenu()和onOptionsItemSelected()的使用

书籍 《第一行代码 Android》第三版 开发 环境 Android Studio Jellyfish | 2023.3.1 创建Menu资源 在《第一行代码 Android》中的3.2.5 在Activity中使用Menu章节中,根据书中指引,在res/目录下创建menu目录,然后在menu目录下创建main.xml的布局资源. menu&#xff1a;必选…

PPT文件中,母版视图与修改权限的区别

在PPT&#xff08;PowerPoint&#xff09;制作过程中&#xff0c;母版视图和修改权限是两个重要的概念&#xff0c;它们各自在演示文稿的编辑、管理和分发中扮演着不同的角色。本文将从定义、功能、使用场景及区别等方面详细探讨PPT母版视图与修改权限的异同。 PPT母版视图 定…

解锁EggJS魅力:为什么它成为企业级应用首选?

在Node.js生态中&#xff0c;阿里开源的EggJS框架自问世以来&#xff0c;便凭借其针对企业级应用的深度定制和高度可扩展性&#xff0c;赢得了开发者们的广泛赞誉。本文将从设计理念、核心特性、实战应用以及与其他框架的对比四个方面&#xff0c;深入探讨EggJS的优势与不足&am…

六西格玛培训:不只是理论,更是实战中的利器——张驰咨询

六西格玛作为一种强大的流程改进和质量管理工具&#xff0c;其应用范围已经远远超出了传统制造业的界限&#xff0c;逐步渗透到金融业、互联网以及新能源等前沿领域。以下张驰咨询将结合之前的分析&#xff0c;展示六西格玛培训在这些行业中的成功案例及其带来的深远影响。 制造…

(2024)docker-compose实战 (4)部署redis

前言 本次仅搭建单一的redis服务.如果不确定镜像的配置文件目录, 可以通过 docker inspect 镜像名 来查看具体的配置信息.使用docker-compose.yaml时, 请自行去除注释. 目录结构 web/ /web/目录 | ├─ redis/ redis目录 | ├─ conf/ 配置文件目录 |…

Keysight 是德 EXR604A 实时示波器

Keysight 是德 EXR604A 实时示波器 EXR604A Infiniium EXR 系列示波器&#xff1a;6 GHz&#xff0c;4 通道 全部 4 个通道均可提供 6 GHz 带宽&#xff0c;强大的 8 合 1 仪器&#xff0c;出色的硬件加速绘图功能&#xff0c;并且支持全面升级&#xff0c;可升级到 8 个通道…

ERP系统中有哪些模块?有哪些具体实现方案呢?

对于许多初次接触ERP系统的企业来说&#xff0c;可能会对系统中包含的模块和功能感到困惑。本文将详细介绍ERP系统中的主要模块&#xff0c;需要明确的是&#xff0c;ERP系统是一个庞大的系统&#xff0c;包含了多个模块&#xff0c;每个模块都有其独特的功能和作用。这些模块涵…

如何用python语言从json数据中获取自己想过的值?

&#x1f3c6;本文收录于《CSDN问答解答》专栏&#xff0c;主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案&#xff0c;希望能够助你一臂之力&#xff0c;帮你早日登顶实现财富自由&#x1f680;&#xff1b;同时&#xff0c;欢迎大家关注&&收藏&…

【408考点之数据结构】图的遍历

图的遍历 图的遍历是指从图中的某个顶点出发&#xff0c;按照一定的规则访问图中所有顶点&#xff0c;并使每个顶点仅被访问一次。图的遍历包括两种主要方法&#xff1a;深度优先搜索&#xff08;DFS&#xff09;和广度优先搜索&#xff08;BFS&#xff09;。这两种遍历方法在…

通用Makefile详解

分析一个Makefile的代码。主要是几个函数的使用 CROSS_COMPILE ? arm-linux-gnueabihf- TARGET ? ledcCC : $(CROSS_COMPILE)gcc LD : $(CROSS_COMPILE)ld OBJCOPY : $(CROSS_COMPILE)objcopy OBJDUMP : $(CROSS_COMPILE)objdumpINCUDIRS : imx6u \bs…

要不要从单片机转Linux?进来看看大神怎么说

在开始前刚好我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「单片机的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“888”之后私信回复“888”&#xff0c;全部无偿共享给大家&#xff01;&#xff01;&#xff01;究竟要不要从单片机转Linu…

二维正态结论

关于二维正态分布&#xff0c;需掌握如下结论&#xff1a; &#xff08;1&#xff09;二维正态分布的两个边缘分布均为一维正态分布。 即由&#xff08;X&#xff0c;Y&#xff09;~N&#xff08;μ1&#xff0c;μ2&#xff0c;σ1&#xff0c;σ2&#xff0c;ρ&#xff09…

RabbitMq 消息确认和退回机制

一、Rabbit中消息确认和退回机制 1、发布确认 生产者将信道设置成 confirm 模式&#xff0c;一旦信道进入 confirm 模式&#xff0c;所有在该信道上面发布的消息都将会被指派一个唯一的 ID (从 1 开始)&#xff0c;一旦消息被投递到所有匹配的队列之后&#xff0c;broker 就会…

【面试题】网络 IO多路复用模型 select

目录 1.概念 使用select模型的步骤 select模型特点&#xff1a; Windows 和Linux 有什么区别&#xff1f; 为什么要引入select模型呢 同步阻塞问题我们可以利用多线程 或者把socket改成非阻塞 当我们要接受数据的时候我们要来回查看接受缓冲区有没有数据这样我们就要来回切…

英伟达被“压制”的25年

十九世纪中叶的美国西部&#xff0c;掀起了一场轰轰烈烈的淘金热&#xff0c;但最终赚到钱的&#xff0c;并不是拿命去赌的淘金者。一个名叫萨姆布瑞南的商人&#xff0c;通过向淘金者出售铲子&#xff0c;成了加州历史上第一位百万富翁。 每一次风口出现时&#xff0c;总有企…

使用Qt Installer Framework在centos7中打包

文章目录 步骤 1: 安装Qt和Qt Installer Framework安装Qt安装Qt Installer Framework步骤 2: 创建项目目录结构步骤 3: 编写安装脚本配置文件(config/config.xml)Package 信息meta/package.xmldata 目录步骤 4: 编写安装脚本步骤 5: 生成安装程序总结在CentOS 7中使用Qt Inst…

k8s自动清理节点服务

要在 Kubernetes 中实现当某个节点的 CPU 或内存使用超过 90% 时清理该节点上的服务&#xff0c;你可以使用以下几种方法&#xff1a; 自定义脚本和 cron job&#xff1a;编写一个脚本监控节点的资源使用情况&#xff0c;并在超过阈值时触发清理操作。使用 DaemonSet 运行监控…

互联网下的扭蛋机小程序开发:探索其独特优势

随着互联网技术的飞速发展&#xff0c;小程序作为一种新兴的轻量级应用形式&#xff0c;已经在各个领域展现出强大的生命力和广泛的应用前景。在娱乐和零售行业&#xff0c;扭蛋机作为一种经典的随机性消费体验方式&#xff0c;结合小程序进行开发&#xff0c;带来了诸多独特优…

每日一更 EFK日志分析系统

需要docker和docker-compose环境 下面时docker-compose.yaml文件 [rootnode1 docker-EFK]# cat docker-compose.yaml version: 3.3services:elasticsearch:image: "docker.elastic.co/elasticsearch/elasticsearch:7.17.5"container_name: elasticsearchrestart: …