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.

457 lines
15 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Aucma.Core.SheetMetal.Models;
using Aucma.Core.SheetMetal.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;
/*
* 首页信息
*
*/
namespace Aucma.Core.SheetMetal.ViewModels
{
public partial class IndexPageViewModel : ObservableObject
{
private readonly Random _r = new();
private PilotInfo[] _modelData;
//protected readonly IEEquipmentCategoryServices? _quipmentCategoryServices;
public IndexPageViewModel()
{
//_quipmentCategoryServices = App.ServiceProvider.GetService<IEEquipmentCategoryServices>();
LoadData();
StationName = "U壳/侧板半径生产";
OrderCode = "8512365486";
PlanCode = "8659452123";
ProductModel = "SC-AUCMA-农夫山泉SC";
BeginTime = DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss");
PlanNum = 80;
RealQuantity = 50;
DiffQuantity = 30;
CompletionRate = 0.3;
#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 加载DataGrid数据
private void LoadData()
{
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
PlanInfoDataGrid.Add(new OrderInfo() { ExecutePlanCode = "8512365486", ProductPlanCode = "8659452123", MaterialName = "SC-AUCMA-农夫山泉SC", PlanAmount = 50, CompleteAmount = 10, BeginTime = "2023-10-07 14:29:33" });
}
#endregion
#region 向上
/// <summary>
/// 向上
/// </summary>
[RelayCommand]
private void MoveUp(string materialName)
{
MessageBox.Show("向上");
}
#endregion
#region 向下
/// <summary>
/// 向下
/// </summary>
[RelayCommand]
private void MoveDown(string materialName)
{
MessageBox.Show("向下");
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
[RelayCommand]
private void DeletePlan(string materialName)
{
MessageBox.Show("删除");
}
#endregion
#region 下传计划
/// <summary>
/// 下传计划
/// </summary>
[RelayCommand]
private void NextPass(string materialName)
{
MessageBox.Show("下传计划");
}
#endregion
#region 初始化datagrid
private ObservableCollection<OrderInfo> planInfoDataGrid = new ObservableCollection<OrderInfo>();
public ObservableCollection<OrderInfo> PlanInfoDataGrid
{
get { return planInfoDataGrid; }
set
{
planInfoDataGrid = value;
OnPropertyChanged();//属性通知
}
}
#endregion
#region 获取当前行数据 赋值到textbox
private OrderInfo selectedCells;
public OrderInfo SelectedCells
{
get { return selectedCells; }
set
{
selectedCells = value;
SetProperty(ref selectedCells, value);
}
}
#endregion
#region 计划拆分执行
/// <summary>
/// 计划拆分执行
/// </summary>
[RelayCommand]
private void SplitPlan()
{
SplitPlanView split=new SplitPlanView();
split.ShowDialog();
}
#endregion
#endregion
#region 执行计划
#region 工位名称
private string _stationName;
public string StationName
{
get { return _stationName; }
set
{
_stationName = value;
SetProperty(ref _stationName, value);
}
}
#endregion
#region 订单编号
private string _orderCode;
public string OrderCode
{
get { return _orderCode; }
set
{
_orderCode = value;
SetProperty(ref _orderCode, value);
}
}
#endregion
#region 计划编号
private string _planCode;
public string PlanCode
{
get { return _planCode; }
set
{
_planCode = value;
SetProperty(ref _planCode, value);
}
}
#endregion
#region 产品型号
private string _productModel;
public string ProductModel
{
get { return _productModel; }
set
{
_productModel = value;
SetProperty(ref _productModel, value);
}
}
#endregion
#region 开始时间
private string _beginTime;
public string BeginTime
{
get { return _beginTime; }
set
{
_beginTime = value;
SetProperty(ref _beginTime, value);
}
}
#endregion
#region 计划数量
private int _planNum;
public int PlanNum
{
get { return _planNum; }
set
{
_planNum = value;
SetProperty(ref _planNum, value);
}
}
#endregion
#region 实际数量
private int _realQuantity;
public int RealQuantity
{
get { return _realQuantity; }
set
{
_realQuantity = value;
SetProperty(ref _realQuantity, value);
}
}
#endregion
#region 差异数量
private int _diffQuantity;
public int DiffQuantity
{
get { return _diffQuantity; }
set
{
_diffQuantity = value;
SetProperty(ref _diffQuantity, value);
}
}
#endregion
#region 完成率
private double _completionRate;
public double CompletionRate
{
get { return _completionRate; }
set
{
_completionRate = value;
SetProperty(ref _completionRate, value);
}
}
#endregion
public IEnumerable<ISeries> Plan_Num { get; set; } =
GaugeGenerator.BuildSolidGauge(
new GaugeItem(
80, // the gauge value
series => // the series style
{
series.DataLabelsSize = 20;
series.MaxRadialColumnWidth = 20;
series.MaxRadialColumnWidth = 10;
series.DataLabelsSize = 12;
}));
#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
}
/// <summary>
/// 型号统计
/// </summary>
public class PilotInfo : ObservableValue
{
public PilotInfo(string name, int value, SolidColorPaint paint)
{
Name = name;
Paint = paint;
// the ObservableValue.Value property is used by the chart
Value = value;
}
public string Name { get; set; }
public SolidColorPaint Paint { get; set; }
}
}