仓库管理系统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.mfbz.cn/a/764549.html

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

相关文章

《单片机》期末考试复习-学习笔记总结

题型 问答题(15分)编程题(65分)编程题1(20分)编程题2(45分)设计题(20分)一、问答题 1.1.单片机概念和特点 1.2. 51单片机的中断结构 1.3.主从式多机通讯的概念及其工作原理 多机通信是指两台以上计算机之间的数据传输,主从式多机通信是多机通信系统中最简单的一种,…

springboot个体快餐订单系统-计算机毕业设计源码13441

目 录 摘要 1 绪论 1.1 研究背景 1.2研究意义 1.3论文结构与章节安排 2 个体快餐订单系统系统分析 2.1 可行性分析 2.2 系统流程分析 2.2.1 数据流程 3.3.2 业务流程 2.3 系统功能分析 2.3.1 功能性分析 2.3.2 非功能性分析 2.4 系统用例分析 2.5本章小结 3 个…

MySQL常用操作命令大全

文章目录 一、连接与断开数据库1.1 连接数据库1.2 选择数据库1.3 断开数据库 二、数据库操作2.1 创建数据库2.2 查看数据库列表2.3 删除数据库 三、表操作3.1 创建表3.2 查看表结构3.3 修改表结构3.3.1 添加列3.3.2 删除列3.3.3 修改列数据类型 3.4 删除表 四、数据操作4.1 插入…

Java UU跑腿同城跑腿小程序源码快递代取帮买帮送源码小程序+H5+公众号跑腿系统

&#x1f680;【同城生活小助手】&#x1f680; &#x1f3c3;‍♂️【同城跑腿&#xff0c;即刻送达的便利生活】&#x1f3c3;‍♀️ 在快节奏的都市生活中&#xff0c;时间成了最宝贵的资源。UU跑腿小程序&#xff0c;作为同城生活的得力助手&#xff0c;让你轻松解决生活…

校园卡手机卡怎么注销?

校园手机卡的注销流程可以根据不同的运营商和具体情况有所不同&#xff0c;但一般来说&#xff0c;以下是注销校园手机卡的几种常见方式&#xff0c;我将以分点的方式详细解释&#xff1a; 一、线上注销&#xff08;通过手机APP或官方网站&#xff09; 下载并打开对应运营商的…

百度AI使用-图像文字识别

前言 百度AI接口可以免费试用&#xff0c;本文描述如何申请使用该资源&#xff0c;以及在QT-Demo下使用百度AI接口&#xff0c;实现图像文字识别功能。 一、百度AI资源申请使用 1.浏览器访问&#xff1a;https://apis.baidu.com&#xff0c; 注册百度智能云账号 2.可以购买试…

AI的价值——不再那么“废”人,保险行业用AI人员流失减少20%

最近有个热点挺让人唏嘘的&#xff0c;某咖啡店员工对顾客泼咖啡粉&#xff0c;我们对于这个事件不予评价。但是对员工这种情绪崩溃&#xff0c;我们所接触的行业中也有不少例子&#xff0c;比如保险行业&#xff0c;相信大家经常会被打保险电话&#xff0c;这类电话很容易就被…

【鸿蒙学习笔记】Image迭代完备

Image Image($r(app.media.zhibo)).width(96) // 图片宽度.height(96) // 图片高度.borderRadius(12) // 图片圆曲度.objectFit(ImageFit.Fill) // 不明objectFit Column({ space: 20 }) {Row() {Image($r(app.media.startIcon)).width(66).height(66).borderRadius(12)}.bac…

软考高级之系统分析师及系统架构设计师备考过程记录

0x00 前言 考了两次系分&#xff0c;一次架构&#xff0c;今年系分终于上岸。 在此记录备考过程和一些体会 先说我自己的情况&#xff0c;我本硕都是计算机科班出身&#xff0c;本科的时候搞Java后端开发&#xff0c;硕士搞python和深度学习&#xff0c;但工作之后就基本没碰过…

工业实时操作系统对比:鸿道Intewell跟rt-linux有啥区别

Intewell和RT-Linux是两种不同的实时操作系统&#xff08;RTOS&#xff09;&#xff0c;它们具有各自独特的特点和优势。以下是Intewell操作系统的一些关键特性&#xff0c;以及与RT-Linux的比较&#xff1a; 自主研发&#xff1a;Intewell是由科东软件自主研发的工业嵌入式实…

【基于R语言群体遗传学】-3-计算等位基因频率

书接上文&#xff0c;我们讲完了哈代温伯格基因型频率&#xff0c;也使用数据进行了拟合&#xff0c;那么接下来就是考虑一些计算的问题&#xff1a; 【基于R语言群体遗传学】-1-哈代温伯格基因型比例-CSDN博客 【基于R语言群体遗传学】-2-模拟基因型&#xff08;simulating …

PyGithub,一个超酷的 Python 库!

更多资料获取 &#x1f4da; 个人网站&#xff1a;ipengtao.com 大家好&#xff0c;今天为大家分享一个超酷的 Python 库 - pygithub。 Github地址&#xff1a;https://github.com/pygithub/pygithub GitHub 是目前最流行的代码托管平台之一&#xff0c;提供了丰富的API接口来…

“仓库寻物难”该如何解决?

我们都知道&#xff0c;现代仓库面积庞大&#xff0c;存储的物品种类和数量繁多&#xff0c;“寻物难”是传统仓库管理的一大痛点。以往出入库和拣货主要依赖人工寻找&#xff0c;效率低下的同时还很容易出错&#xff0c;终将引发管理困难和损失。“闪灯”是直观实用的提示方式…

买超声波清洗机注意什么?四大高分超声波清洗机种草,别错过!

相信大家都知道超声波清洗机&#xff0c;每次眼镜脏的时候&#xff0c;去眼镜店里让老板帮忙清洗&#xff0c;她们用的就是超声波清洗机&#xff0c;通过超声波的原理深入物品深处清洁&#xff0c;清洁效果非常好。下面给大家分享几款市面上比较火的超声波清洗机&#xff0c;感…

PHP验证日本固定电话号码

日本电话号码格式众多&#xff0c;验证起来比较头大&#xff0c;现在咱们来一个简单的总结哈 为了简单起见&#xff0c;使用PCRE 函数preg_match通过匹配正则表达式来实现验证。 function checkGdTelLandline(string $str): int|false {return preg_match("/\A0(\d{1}[-…

WPF自定义控件,实现含有箭头的文本或内容控件

文章目录 背景效果预览方案设计分析基本布局添加控件自定义属性添加属性值监听获取点数据 全部代码HorizontalLineContent.xamlHorizontalLineContent.xaml.csDirectionAlignment.csContentDirectionAlignment.cs 使用方法 背景 因为项目开发需要&#xff0c;要在WPF上绘制TCP…

vue选择上下周,拖拽列表,随机背景色

安装拖拽插件 npm install vuedraggable <template><!--排产计划--><div class"app-container"><div class"mainbox"><div class"table-container table-fullscreen"><div class"title-name">…

打假“AI换脸”,外滩大会·全球Deepfake攻防挑战赛启动报名

近日&#xff0c;外滩大会全球Deepfake攻防挑战赛正式启动报名。该赛事提供百万级的数据集&#xff0c;针对“AI换脸”的欺诈风险进行攻防实战演练&#xff0c;并设立100万元人民币的奖金池&#xff0c;鼓励推动AI向善的技术人才。 大赛由蚂蚁集团主办、蚂蚁数科承办&#xff0…

JeecgFlow定时器

概念 定时器事件&#xff08;Timer Events&#xff09;是由定义的计时器触发的事件。它们可以用作启动事件、中间事件或边界事件。边界事件可以中断&#xff0c;也可以不中断。 Camunda定时器事件包括&#xff1a;Timer Start Event&#xff08;定时启动事件&#xff09;、Time…

Unity解决报错:Execution failed for task ‘:unityLibrary:BuildIl2CppTask‘

目录 编辑器版本2020.3.33f1 及 2021.3.15f1 直接导出apk或aar报错(虽然会自动生成temp的AS工程&#xff0c;经过打开验证 也是无解的)&#xff1b; 唯一解决办法&#xff1a;Unity导出As工程没问题&#xff1b; 编辑器版本2020.3.33f1 及 2021.3.15f1 直接导出apk或aar报…