仓库管理系统24--统计报表

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

1、引用LiveCharts

2、创建LiveChartViewModel

cs 复制代码
using GalaSoft.MvvmLight;
using LiveCharts.Wpf;
using LiveCharts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.Command;
using West.StoreMgr.Service;

namespace West.StoreMgr.ViewModel
{
    /// <summary>
    /// 柱状图viewmodel
    /// </summary>
    public class LiveChartViewModel : ViewModelBase
    {
        //物资库存柱状
        private IChartValues goodsChartValues = new ChartValues<double>();
        public IChartValues GoodsChartValues
        {
            get { return goodsChartValues; }
            set { goodsChartValues = value; RaisePropertyChanged(); }
        }

        private List<string> goodsLabes = new List<string>();
        /// <summary>
        /// 物资标签
        /// </summary>
        public List<string> GoodsLabes
        {
            get { return goodsLabes; }
            set { goodsLabes = value; RaisePropertyChanged(); }
        }

        //物资入库流水折线
        public SeriesCollection GoodsInStoreSeries { get; set; } = new SeriesCollection();
        public AxesCollection GoodsInStoreAxis { get; set; } = new AxesCollection();

        //物资出库流水折线
        public SeriesCollection GoodsOutStoreSeries { get; set; } = new SeriesCollection();
        public AxesCollection GoodsOutStoreAxis { get; set; } = new AxesCollection();

        //客户出库饼图
        public SeriesCollection CustomerPieSeries { get; set; } = new SeriesCollection();
        /// <summary>
        /// 加载命令
        /// </summary>
        public RelayCommand LoadCommand
        {
            get
            {
                return new RelayCommand(() =>
                { 
                    GoodsChartValues.Clear();
                    GoodsLabes.Clear();
                    var goodsList = new GoodsService().Select();
                    var instoreList = new InStoreService().Select();
                    var outstoreList = new OutStoreService().Select();
                    var customers = new CustomerService().Select();
                    goodsList.ForEach(goods =>
                    {
                        //物资库存柱状
                        GoodsChartValues.Add(goods.Quant);
                        GoodsLabes.Add(goods.Name);

                        //物资入库流水折线
                        var instores = instoreList.FindAll(item => item.GoodsSerial == goods.Serial);
                        var inserise = new LineSeries() { Title = goods.Name, Values = new ChartValues<double>() };
                        instores.ForEach(item =>
                        {
                            inserise.Values.Add(item.Number);
                        });
                        GoodsInStoreSeries.Add(inserise);

                        //物资出库流水折线
                        var outstores = outstoreList.FindAll(item => item.GoodsSerial == goods.Serial);
                        var outserise = new LineSeries() { Title = goods.Name, Values = new ChartValues<double>() };
                        outstores.ForEach(item =>
                        {
                            outserise.Values.Add(item.Number);
                        });
                        GoodsOutStoreSeries.Add(outserise);
                    });

                    CustomerPieSeries.Clear();
                    customers.ForEach(item =>
                    {
                        var list = outstoreList.FindAll(outstore => outstore.CustomerId == item.Id);
                        var sum = list.Sum(t => t.Number);
                        var pieSeries = new PieSeries
                        {
                            Title = item.Name,
                            Values = new ChartValues<double>() { sum }
                        };
                        CustomerPieSeries.Add(pieSeries);
                    }); 
                });
            }
        }
    }
}

3、创建LiveChartView用户控件

cs 复制代码
<UserControl x:Class="West.StoreMgr.View.LiveChartView"
             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" 
             xmlns:wpf="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             mc:Ignorable="d" 
             DataContext="{Binding Source={StaticResource Locator},Path=LiveChart}"
             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 Height="auto"/>
            <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="10">

        </Grid>

        <!--报表-->
        <Grid Grid.Row="2" Margin="10 0 10 10" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            
            <!--物资库存柱状图-->
            <TextBlock Text="物资库存柱状图" Grid.Row="0" Grid.Column="0" Margin="150 -20 0 0" FontSize="15" FontFamily="微软雅黑" ></TextBlock>
            <Border Grid.Row="0" Grid.Column="0" BorderBrush="BurlyWood"  BorderThickness="0.5">
                <wpf:CartesianChart  Margin="10">
                    <wpf:CartesianChart.Series>
                        <wpf:ColumnSeries Values="{Binding GoodsChartValues}"/>
                    </wpf:CartesianChart.Series>
                    <wpf:CartesianChart.AxisX>
                        <wpf:Axis ShowLabels="True" Labels="{Binding GoodsLabes}">
                            <wpf:Axis.Separator>
                                <wpf:Separator Step="1" IsEnabled="False"/>
                            </wpf:Axis.Separator>
                        </wpf:Axis>
                    </wpf:CartesianChart.AxisX>
                </wpf:CartesianChart>
            </Border>
           
            <!--客户出库统计饼图-->
            <TextBlock Text="客户出库统计饼图" Grid.Row="0" Grid.Column="1" Margin="150 -20 0 0" FontSize="15" FontFamily="微软雅黑"></TextBlock>
            <Border Grid.Row="0" Grid.Column="1"  BorderBrush="BurlyWood"  BorderThickness="0.5">
                <wpf:PieChart LegendLocation="Right" Hoverable="True" InnerRadius="30" Series="{Binding CustomerPieSeries}">
                    <wpf:PieChart.ChartLegend>
                        <wpf:DefaultLegend Foreground="Green"/>
                    </wpf:PieChart.ChartLegend>
                </wpf:PieChart> 
            </Border> 
            
            <!--物资入库流水记录-->
            <TextBlock  Text="物资入库流水记录" Grid.Row="1" Grid.Column="0"  Margin="150 0 0 0" FontSize="15" FontFamily="微软雅黑"></TextBlock>
            <Border Grid.Row="1" Grid.Column="0" BorderBrush="BurlyWood"  BorderThickness="0.5"> 
                <wpf:CartesianChart  Series="{Binding GoodsInStoreSeries}" AxisX="{Binding GoodsInStoreAxis}"/>
            </Border>

            <!--物资出库流水记录-->
            <TextBlock Text="物资出库流水记录" Grid.Row="1" Grid.Column="1" Margin="150 0 0 0" FontSize="15" FontFamily="微软雅黑" ></TextBlock>
            <Border Grid.Row="1" Grid.Column="1"  BorderBrush="BurlyWood"  BorderThickness="0.5"> 
            <wpf:CartesianChart Margin="10" Series="{Binding GoodsOutStoreSeries}" AxisX="{Binding GoodsOutStoreAxis}"/>
            </Border>
        </Grid>
    </Grid>
</UserControl>

4、运行效果

相关推荐
染指11103 小时前
45.第二阶段x86游戏实战2-hook监控实时抓取游戏lua
汇编·c++·windows·反游戏外挂·游戏逆向
我是苏苏16 小时前
Web开发:ABP框架6——appsetting.json的读取以及实例的注入
前端·windows·json
TPCloud17 小时前
windows 11编译安装ffmpeg(包含ffplay)
windows·ffmpeg·源码安装·mysys
password大鸭梨17 小时前
一个简单ASP.NET购物车设计
windows·microsoft·asp.net
Aniay_ivy19 小时前
Java中的不可变集合:性能与安全并重的最佳实践
java·windows·安全
积跬步至千里-积滴水成江海19 小时前
如何查看电脑关机时间
windows·系统安全
喜欢打篮球的普通人19 小时前
Rust面向对象特性
开发语言·windows·rust
晨曦_子画19 小时前
C#中:Any() 与 Count,选择哪一个??
开发语言·windows·c#
醇氧21 小时前
【Windows】CMD命令学习——系统命令
windows
人生の三重奏21 小时前
windows虚拟环境搭建
windows·python·虚拟环境