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; using Admin.Core.Model.Model_New; using Admin.Core.Tasks; using CommunityToolkit.Mvvm.Messaging; /* * 首页信息 * */ namespace Aucma.Core.SheetMetal.ViewModels { public partial class IndexPageViewModel : ObservableObject { private readonly Random _r = new(); private PilotInfo[] _modelData; protected readonly IExecutePlanInfoServices? _taskExecutionServices; int k = 100; public IndexPageViewModel() { _taskExecutionServices = App.ServiceProvider.GetService(); PlanMaxNum = 100; 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; Job_SheetMetalTask_Quartz.SmDelegateEvent += LoadData; #region 每日产量 //var paints = new SolidColorPaint[] //{ // //new(SKColors.Blue) //}; var series = new ColumnSeries { 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(); WeakReferenceMessenger.Default.Register(this, Recive); GaugeItem gi = new GaugeItem(PlanMaxNum, // the gauge value series => // the series style { series.DataLabelsSize = 20; series.MaxRadialColumnWidth = 20; series.MaxRadialColumnWidth = 10; series.DataLabelsSize = 12; }); Plan_Num = GaugeGenerator.BuildSolidGauge(gi); } #region 计划列表 #region 加载DataGrid数据 private async void LoadData() { var list= await _taskExecutionServices.QueryAsync(d=>d.ProductLineCode.Equals("1001")); var execList= list.OrderBy(d=>d.ExecuteOrder); foreach (var item in execList) { PlanInfoDataGrid.Add(new TaskExecModel() { ID = item.ObjId.ToString(), OrderCode = item.OrderCode, MaterialCode = item.MaterialCode, MaterialName = item.MaterialName, TaskAmount = item.PlanAmount, CompleteAmount = item.CompleteAmount, BeginTime = item.BeginTime, IsExec = item.ExecuteStatus }); } } #endregion #region 向上 /// /// 向上 /// [RelayCommand] private async Task MoveUp(string info) { string station = "1001"; bool result = await _taskExecutionServices.PlanMoveUp(info, station); if (result) { PlanInfoDataGrid.Clear(); LoadData(); } } #endregion #region 向下 /// /// 向下 /// [RelayCommand] private async Task MoveDown(string info) { string station = "1001"; bool result = await _taskExecutionServices.PlanMoveDown(info, station); if (result) { PlanInfoDataGrid.Clear(); LoadData(); } } #endregion #region 删除 /// /// 删除 /// [RelayCommand] private async Task DeletePlan(string info) { MessageBoxResult msg = MessageBox.Show("确定要删除吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (MessageBoxResult.Yes == msg) { bool result = await _taskExecutionServices.ExecPlanDelete(info); if (result) { PlanInfoDataGrid.Clear(); LoadData(); MessageBox.Show("执行计划删除成功", "系统信息"); } else { MessageBox.Show("执行计划删除失败", "系统信息"); } } } #endregion #region 下传计划 /// /// 下传计划 /// [RelayCommand] private async Task NextPass(string info) { MessageBoxResult msg = MessageBox.Show("确定要下发计划吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (MessageBoxResult.Yes != msg) return; var list = await _taskExecutionServices.QueryAsync(d => d.ObjId == int.Parse(info)); var model = list.FirstOrDefault(); if (model.ExecuteStatus == 2) { MessageBox.Show("该计划正在执行中,请勿重复下传", "系统信息"); } else { var result = _taskExecutionServices.PlanNextPass(model); if (result != null) { //刷新列表 MessageBox.Show("执行计划已下达", "系统信息"); } else { MessageBox.Show("执行计划下达失败", "系统信息"); } } } #endregion #region 初始化datagrid private ObservableCollection planInfoDataGrid = new ObservableCollection(); public ObservableCollection PlanInfoDataGrid { get { return planInfoDataGrid; } set { planInfoDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion #region 计划拆分执行 /// /// 计划拆分执行 /// [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); } } private int _planMaxNum; public int PlanMaxNum { get { return _planMaxNum; } set { _planMaxNum = value; SetProperty(ref _planMaxNum, 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 plan_Num; public IEnumerable Plan_Num { get { return plan_Num; } set { plan_Num = value; SetProperty(ref plan_Num, value); } } //GaugeGenerator.BuildSolidGauge( // new GaugeItem( // k, // 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 textPaint2; //private IPaint textPaint; //public IPaint 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 { 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 #region 刷新列表-其他界面刷新该方法 /// /// 刷新列表 /// /// /// private void Recive(object recipient, object message) { PlanInfoDataGrid.Clear(); LoadData(); } #endregion #region 计划拆分执行 /// /// 计划拆分执行 /// [RelayCommand] private void Test() { int option = 30; option++; System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { GaugeItem gi = new GaugeItem(option, // the gauge value series => // the series style { series.DataLabelsSize = 20; series.MaxRadialColumnWidth = 20; series.MaxRadialColumnWidth = 10; series.DataLabelsSize = 12; }); Plan_Num = GaugeGenerator.BuildSolidGauge(gi); })); } #endregion } }