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.

456 lines
14 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 System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
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 Admin.Core.IService;
using Microsoft.Extensions.DependencyInjection;
using Aucma.Core.SheetMetal.Common;
using static SkiaSharp.HarfBuzz.SKShaper;
/*
* 首页信息
*
*/
namespace Aucma.Core.SheetMetal.ViewModels
{
public partial class IndexPageViewModel : ObservableObject
{
private readonly Random _r = new();
private PilotInfo[] _modelData;
protected readonly ISmTaskExecutionServices? _taskExecutionServices;
public IndexPageViewModel()
{
_taskExecutionServices = App.ServiceProvider.GetService<ISmTaskExecutionServices>();
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();
LoadData();
}
#region 计划列表
#region 加载DataGrid数据
private async void LoadData()
{
var list= await _taskExecutionServices.QueryAsync();
var execList= list.OrderBy(d=>d.TaskSort);
foreach (var item in execList)
{
PlanInfoDataGrid.Add(new TaskExecModel() { ID= item.ObjId.ToString(), PlanCode = item.PlanCode, OrderCode = item.OrderCode, MaterialCode= item.MaterialCode, MaterialName = item.MaterialName, TaskAmount = item.TaskAmount, CompleteAmount = item.CompleteAmount, BeginTime = item.CreateTime, IsExec= item.IsExec });
}
}
#endregion
#region 向上
/// <summary>
/// 向上
/// </summary>
[RelayCommand]
private async Task MoveUp(string info)
{
bool result= await _taskExecutionServices.PlanMoveUp(info);
if (result)
{
PlanInfoDataGrid.Clear();
LoadData();
}
}
#endregion
#region 向下
/// <summary>
/// 向下
/// </summary>
[RelayCommand]
private async Task MoveDown(string info)
{
bool result=await _taskExecutionServices.PlanMoveDown(info);
if (result)
{
PlanInfoDataGrid.Clear();
LoadData();
}
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
[RelayCommand]
private async Task DeletePlan(string info)
{
bool result = await _taskExecutionServices.PlanDelete(info);
if (result)
{
PlanInfoDataGrid.Clear();
LoadData();
MessageBox.Show("执行计划删除成功","系统信息");
}
else
{
MessageBox.Show("执行计划删除失败", "系统信息");
}
}
#endregion
#region 下传计划
/// <summary>
/// 下传计划
/// </summary>
[RelayCommand]
private async Task NextPass(string info)
{
var list = await _taskExecutionServices.QueryAsync(d=>d.ObjId==int.Parse(info));
var model=list.FirstOrDefault();
if (model.IsExec == 1)
{
MessageBox.Show("该计划正在执行中,请勿重复下传", "系统信息");
}
else
{
var result = _taskExecutionServices.PlanNextPass(model);
if (result != null)
{
//刷新列表
MessageBox.Show("执行计划已下达", "系统信息");
}
else
{
MessageBox.Show("执行计划下达失败", "系统信息");
}
}
}
#endregion
#region 初始化datagrid
private ObservableCollection<TaskExecModel> planInfoDataGrid = new ObservableCollection<TaskExecModel>();
public ObservableCollection<TaskExecModel> PlanInfoDataGrid
{
get { return planInfoDataGrid; }
set
{
planInfoDataGrid = value;
OnPropertyChanged();//属性通知
}
}
#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
}
}