You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
7.8 KiB
C#

using Aucma.Core.Palletiz.Models;
using Aucma.Core.Palletiz.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Metrics;
using System.Drawing.Imaging;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView.Extensions;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
using LiveChartsCore.ConditionalDraw;
using LiveChartsCore.Drawing;
using System.Linq;
using System.Threading.Tasks;
using LiveChartsCore.Themes;
using System.Collections;
using log4net;
using Admin.Core.Tasks;
using Aucma.Core.Palletiz.Common;
/*
*
*
*/
namespace Aucma.Core.Palletiz.ViewModels
{
public partial class IndexPageViewModel : ObservableObject
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel));
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
private readonly Random _r = new();
private PilotInfo[] _modelData;
public IndexPageViewModel()
{
1 year ago
StationName = "成品分垛入库";
MaterialName = "SC-AUCMA-农夫山泉SC 门体";
OrderNo = "8512365486";
BeginTime = DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss");
#region 每日产量
//var paints = new SolidColorPaint[]
//{
// //new(SKColors.Blue)
//};
var series = new ColumnSeries<int>
{
Values = new[] { 2, 5, 4, 6, 8, 3, 2, 4, 6 },
DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)),
DataLabelsPosition = DataLabelsPosition.Top
}.OnPointMeasured(point =>
{
// this method is called for each point in the series
// we can customize the visual here
if (point.Visual is null) return;
// get a paint from the array
//var paint = paints[point.Index % paints.Length];
// set the paint to the visual
///point.Visual.Fill = paint;
});
Series = new ISeries[] { series };
//TextPaint = new SolidColorPaint()
//{
// Color = SKColors.DarkSlateGray,
// SKTypeface = SKFontManager.Default.MatchCharacter('汉')
//};
//TextPaint2 = new SolidColorPaint()
//{
// Color = SKColors.DarkSlateGray,
// SKTypeface = SKFontManager.Default.MatchCharacter('汉')
//};
#endregion
LoadModel();
}
#region 扫描信息
#region 物料条码
private string _stationName;
public string StationName
{
get { return _stationName; }
set
{
_stationName = value;
SetProperty(ref _stationName, value);
}
}
#endregion
#region 物料名称
private string _materialName;
public string MaterialName
{
get { return _materialName; }
set
{
_materialName = value;
SetProperty(ref _materialName, value);
}
}
#endregion
#region 订单信息
private string _orderNo;
public string OrderNo
{
get { return _orderNo; }
set
{
_orderNo = value;
SetProperty(ref _orderNo, value);
}
}
#endregion
#region 开始时间
private string _beginTime;
public string BeginTime
{
get { return _beginTime; }
set
{
_beginTime = value;
SetProperty(ref _beginTime, value);
}
}
#endregion
#endregion
#region 当日产量
public ISeries[] Series { get; set; }
public Axis[] XAxes { get; set; } =
{
new Axis
{
//Name = "每日产量",
NamePaint = new SolidColorPaint { Color = SKColors.Red },
// 对命名标签或静态标签使用labels属性
Labels = new string[] { "Sergio", "Lando", "Lewis", "Lewis", "Lewis", "Lewis", "Lewis", "Lewis", "Lewis", "Lewis" },
LabelsRotation = 15
}
};
//[ObservableProperty]
//private IPaint<LiveChartsCore.SkiaSharpView.Drawing.SkiaSharpDrawingContext> textPaint2;
//private IPaint<LiveChartsCore.SkiaSharpView.Drawing.SkiaSharpDrawingContext> textPaint;
//public IPaint<LiveChartsCore.SkiaSharpView.Drawing.SkiaSharpDrawingContext> TextPaint { get => textPaint; set => SetProperty(ref textPaint, value); }
#endregion
#region 型号统计
public void LoadModel()
{
// generate some paints for each pilot:
var paints = Enumerable.Range(0, 7)
.Select(i => new SolidColorPaint(ColorPalletes.MaterialDesign500[i].AsSKColor()))
.ToArray();
// generate some data for each pilot:
_modelData = new PilotInfo[]
{
new("Tsunoda", 500, paints[0]),
new("Sainz", 450, paints[1]),
new("Riccardo", 520, paints[2]),
new("Bottas", 550, paints[3]),
new("Perez", 660, paints[4]),
new("Verstapen", 920, paints[5]),
new("Hamilton", 1000, paints[6])
};
var rowSeries = new RowSeries<PilotInfo>
{
Values = _modelData.OrderBy(x => x.Value).ToArray(),
DataLabelsPaint = new SolidColorPaint(new SKColor(245, 245, 245)),
DataLabelsPosition = DataLabelsPosition.End,
DataLabelsTranslate = new(-1, 0),
DataLabelsFormatter = point => $"{point.Model!.Name} {point.Coordinate.PrimaryValue}",
MaxBarWidth = 50,
Padding = 10,
}.OnPointMeasured(point =>
{
if (point.Visual is null) return;
point.Visual.Fill = point.Model!.Paint;
});
//.OnPointMeasured(point =>
//{
// // assign a different color to each point
// if (point.Visual is null) return;
// point.Visual.Fill = point.Model!.Paint;
//});
_modelSeries = new[] { rowSeries };
_ = StartRace();
}
[ObservableProperty]
private ISeries[] _modelSeries;
[ObservableProperty]
private Axis[] _xModelAxes = { new Axis { SeparatorsPaint = new SolidColorPaint(new SKColor(220, 220, 220)) } };
[ObservableProperty]
private Axis[] _yModelAxes = { new Axis { IsVisible = false } };
public bool IsReading { get; set; } = true;
public async Task StartRace()
{
await Task.Delay(1000);
// to keep this sample simple, we run the next infinite loop
// in a real application you should stop the loop/task when the view is disposed
//while (IsReading)
//{
//do a random change to the data
foreach (var item in _modelData)
item.Value += _r.Next(0, 100);
ModelSeries[0].Values =
_modelData.OrderBy(x => x.Value).ToArray();
await Task.Delay(100);
//}
}
#endregion
}
}