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 System.Linq; using System.Threading.Tasks; using Admin.Core.IService; using Microsoft.Extensions.DependencyInjection; using Aucma.Core.SheetMetal.Common; using LiveCharts; using LiveCharts.Wpf; using Admin.Core.Model; using System.Windows.Media; using Admin.Core.Common; using LiveCharts.Defaults; using Aucma.Core.SheetMetal.Business; using Admin.Core.Model.ViewModels; using log4net; using Aucma.Core.HwPLc; using System.Text; using System.Threading; using Admin.Core.Model.Model_New; using Aucma.Core.SheetMetalTasks; /* * 首页信息 */ namespace Aucma.Core.SheetMetal.ViewModels { public partial class IndexPageViewModel : ObservableObject { private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel)); #region 初始化接口 protected readonly IExecutePlanInfoServices? _taskExecutionPlanInfoServices; protected readonly IRecordBackPanelComplateServices _recordBackPanelComplateServices; protected readonly IRecordSidePanelComplateServices _recordSidePanelComplateServices; protected readonly IExecutePlanInfoServices? _executePlanInfoServices; protected readonly IBaseBomInfoServices _baseBomInfoServices; private readonly ISysUserInfoServices _sysUserInfoServices; private readonly IRecordInStoreServices _recordInstoreServices; private readonly IBaseOrderInfoServices _baseOrderInfoServices; #endregion #region 初始化下拉数据 private AppConfigHelper appConfig = new AppConfigHelper();//读取保存的文本数据 List selectList = new List() { new SelectModel() { ID=1, TypeName="手动" }, new SelectModel() { ID=2, TypeName="自动" }}; #endregion #region 定义对象和定义字段 public Func Formatter { get; set; } public HwPLc.PlcModel obj = null; #endregion #region 构造函数 public IndexPageViewModel() { _stationName = Appsettings.app("StationInfo", "StationName");//工位名称 _baseOrderInfoServices = App.ServiceProvider.GetService(); _executePlanInfoServices = App.ServiceProvider.GetService(); _taskExecutionPlanInfoServices = App.ServiceProvider.GetService(); _recordBackPanelComplateServices = App.ServiceProvider.GetService(); _recordSidePanelComplateServices = App.ServiceProvider.GetService(); _baseBomInfoServices = App.ServiceProvider.GetService(); _sysUserInfoServices = App.ServiceProvider.GetService(); _recordInstoreServices = App.ServiceProvider.GetService(); Task.WaitAll(LoadData()); AddSelectData();//添加下拉菜单 RefreshHourAmount();//小时产量 RefreshMaterialStats();//型号产量 //——测试—— //InitEveryDayMethod();//小时产量 //InitExecMethod();//执行列表 //LoadDataTest(); //——测试 end—— AucamSheetMetalTaskService.RefreshCurrentPlanInfoEvent += RefreshCurrentPlanInfo; QuantityIssuedViewModel.RefreshCretaePlanInfoEvent += LoadData; AucamSheetMetalTaskService.RefreshCreatePlanInfoEvent += LoadData; AucamSheetMetalTaskService.RefreshChatEvent += RefreshChat; AucamSheetMetalTaskService.RefreshPlanInfoEvent += RefreshPlanShow; } #endregion #region 更新前端数据 public Task RefreshChat() { RefreshHourAmountChart();//小时产量 RefreshMaterialChart();//型号产量 return Task.CompletedTask; } #endregion #region 下拉 public void AddSelectData() { foreach (var item in selectList) { LocationSource.Add(item); } SelectLocation = ReadFile(); } #endregion #region 订单统计 private void InitExecMethod() { //string station = Appsettings.app("StationInfo", "StationCode"); //ExecutePlanInfo info = await _taskExecutionPlanInfoServices.FirstAsync(d => d.ProductLineCode.Equals(station) && d.ExecuteStatus == 2); //if (info == null) return; OrderCode="11245376";//订单 MesOrderCode = "2401101789";//Mes订单 ProductModel = "BCD-162CST"; BeginTime = "2024-01-16"; PlanMaxNum = 500; RealQuantity = 20; DiffQuantity = 480; //CompletionRate = (_realQuantity / _planMaxNum).ToString("0%"); CompletionRate = double.Parse((RealQuantity / PlanMaxNum).ToString("F3")); } #endregion #region ——测试 /// /// 每日生产 /// /// private Task InitEveryDayMethod() { #region 按时间统计 ChartValues achievement = new ChartValues { new ObservablePoint(0, 75), new ObservablePoint(1, 121), new ObservablePoint(2, 105), new ObservablePoint(3,0), new ObservablePoint(4,0), new ObservablePoint(5,0), new ObservablePoint(6,0), new ObservablePoint(7,0), new ObservablePoint(8,0), new ObservablePoint(9,0), new ObservablePoint(10,0), new ObservablePoint(11,0) }; var column = new ColumnSeries(); column.DataLabels = true; column.Title = "前板"; column.ScalesYAt = 0; column.Values = achievement; column.Foreground = Brushes.White; column.FontSize = 18; //柱子宽度 //column.Width = 30; //column.MaxColumnWidth = 30; //column.LabelsPosition = BarLabelPosition.Perpendicular; //column.Fill = new SolidColorBrush(Color.FromRgb(34, 139, 34)); //柱状图颜色填充 //column.LabelPoint = p => p.Y.ToString(); //柱状图数据显示位置 ProductionHourList = new List() { "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00" }; //Formatter = value => value.ToString("N"); Achievement.Add(column); Achievement.Add(new ColumnSeries { DataLabels = true, Title = "后板", Values = achievement, Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)), Foreground = Brushes.CadetBlue, FontSize = 18 }); #endregion #region 按类型统计 //ChartValues achievement2 = new ChartValues(); ChartValues achievement2 = new ChartValues { new ObservablePoint(0,15), new ObservablePoint(1,106), new ObservablePoint(2,66), new ObservablePoint(3,46) }; var column2 = new ColumnSeries(); column2.DataLabels = true; column2.Title = "前板"; column2.Values = achievement2; column2.Foreground = Brushes.White; column2.FontSize = 18; ModelStatistics.Add(column2); ModelStatistics.Add(new ColumnSeries() { DataLabels = true, Title = "后板", Values = achievement2, Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)), Foreground = Brushes.White, FontSize = 18 }); MaterialNameList = new List() { "BCD-162CST", "BCD-212CHG", "BCD-211CHG", "BC/BD-310NF" }; #endregion return Task.CompletedTask; } private void LoadDataTest() { List taskList = new List(); TaskExecModel task = new TaskExecModel(); task.No = 1; task.ID = ""; task.OrderCode = "11245376"; task.MaterialCode = "9000008460"; task.MaterialName = "BCD-162CST"; task.TaskAmount = 20; task.CompleteAmount = 15; task.BeginTime = Convert.ToDateTime("2024-01-16"); task.IsExec =2;//执行状态 task.PlanType = "前后板联动"; task.Recipe = "BCD-162CST"; task.SidePanelAmount =15; task.BackPanelAmount = 15; task.TaskCode = "24011017890003"; task.ExecuteStatus = 2;//执行状态 PlanInfoDataGrid.Add(task); TaskExecModel task2 = new TaskExecModel(); task2.No = 2; task2.ID = ""; task2.OrderCode = "11244891"; task2.MaterialCode = "9000004738"; task2.MaterialName = "BCD-162CST"; task2.TaskAmount = 20; task2.CompleteAmount = 50; task2.BeginTime = Convert.ToDateTime("2024-01-16"); task2.IsExec = 2;//执行状态 task2.PlanType = "前后板联动"; task2.Recipe = "BCD-162CST"; task2.SidePanelAmount = 50; task2.BackPanelAmount = 50; task2.TaskCode = "24011300010005"; task2.ExecuteStatus = 3;//执行状态 PlanInfoDataGrid.Add(task2); TaskExecModel task3 = new TaskExecModel(); task3.No = 3; task3.ID = ""; task3.OrderCode = "11244793"; task3.MaterialCode = "9000004738"; task3.MaterialName = "BCD-212CHG"; task3.TaskAmount = 60; task3.CompleteAmount = 60; task3.BeginTime = Convert.ToDateTime("2024-01-16"); task3.IsExec = 2;//执行状态 task3.PlanType = "前后板联动"; task3.Recipe = "BCD-162CST"; task3.SidePanelAmount = 60; task3.BackPanelAmount = 60; task3.TaskCode = "24011200020003"; task3.ExecuteStatus = 3;//执行状态 PlanInfoDataGrid.Add(task3); TaskExecModel task4 = new TaskExecModel(); task4.No =4; task4.ID = ""; task4.OrderCode = "11244784"; task4.MaterialCode = "9000008460"; task4.MaterialName = "BC/BD-310NF"; task4.TaskAmount = 40; task4.CompleteAmount = 40; task4.BeginTime = Convert.ToDateTime("2024-01-16"); task4.IsExec = 3;//执行状态 task4.PlanType = "前后板联动"; task4.Recipe = "BC/BD-310NF"; task4.SidePanelAmount = 40; task4.BackPanelAmount = 40; task4.TaskCode = "24011017840008"; task4.ExecuteStatus = 3;//执行状态 PlanInfoDataGrid.Add(task4); } #endregion #region 计划列表 #region 加载DataGrid数据 private async Task LoadData() { try { string stationCode = Appsettings.app("StationInfo", "StationCode"); CurrentTeamTimeView view = GetTeamHour(); var executePlanInfoList =await _executePlanInfoServices.QuerySheetMetalSendPlanData("1001"); if (executePlanInfoList == null) return; List execList = executePlanInfoList.Where(d =>Convert.ToDateTime(d.BeginTime) > view.StartTime || d.ExecuteStatus == 1 || d.ExecuteStatus == 2).ToList(); execList= execList.OrderByDescending(d => d.ExecuteOrder).ToList(); if (execList == null) return; int i = 1; System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { PlanInfoDataGrid.Clear(); foreach (var item in execList) { TaskExecModel task = new TaskExecModel(); task.No = i; task.ID = item.ObjId.ToString(); task.OrderCode = item.OrderCode; task.MaterialCode = item.MaterialCode; task.MaterialName = item.MaterialName; task.TaskAmount = item.PlanAmount; task.CompleteAmount = item.CompleteAmount; task.BeginTime =Convert.ToDateTime(item.BeginTime); task.IsExec = item.ExecuteStatus;//执行状态 if (item.PlanType == 1) { task.PlanType = "前后板联动"; } if (item.PlanType == 2) { task.PlanType = "前板计划"; } if (item.PlanType == 3) { task.PlanType = "后板计划"; } task.Recipe = item.MaterialSpecificatons; task.SidePanelAmount = item.SidePanelAmount; task.BackPanelAmount = item.BackPanelAmount; task.TaskCode = item.TaskCode; task.ExecuteStatus = item.ExecuteStatus;//执行状态 PlanInfoDataGrid.Add(task); i++; } })); } catch (Exception ex) { log.Error("钣金首页数据加载:"+ex.Message); } } #endregion #region 刷新计划执行 public async void RefreshPlanShow(SheetMetaSendPlanInfoView execPlan) { string stationCode = Appsettings.app("StationInfo", "StationCode"); var planInfoList = _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Contains(stationCode)).Result; if (planInfoList == null || planInfoList.Count == 0) return; var list = (from d in planInfoList group d by d.OrderCode into g select new { OrderCode = g.Key, CompleteAmount = g.Sum(d => d.CompleteAmount) }).OrderBy(t => t.OrderCode).ToList(); //更新首页显示信息 BaseOrderInfo orderPlan =await _baseOrderInfoServices.FirstAsync(d => d.OrderCode == execPlan.OrderCode); var orderInfo=list.FirstOrDefault(d=>d.OrderCode == execPlan.OrderCode); if (orderPlan != null) { OrderCode = execPlan.OrderCode; MesOrderCode = execPlan.ProductPlanCode; ProductModel = execPlan.MaterialName; BeginTime = string.IsNullOrEmpty(execPlan.BeginTime)?"": execPlan.BeginTime.ToString(); PlanMaxNum = orderPlan.OrderAmount;//显示SAP订单数,而不是拆分订单计划数 RealQuantity = orderInfo.CompleteAmount; double diff = orderPlan.OrderAmount - RealQuantity; DiffQuantity = int.Parse(diff.ToString()); //CompletionRate = (_realQuantity/_planMaxNum).ToString("0%"); CompletionRate = double.Parse((RealQuantity / orderPlan.OrderAmount).ToString("F3")); } else { OrderCode = string.Empty; MesOrderCode = string.Empty; ProductModel = string.Empty; BeginTime = string.Empty; PlanMaxNum = 0; RealQuantity = 0.0; DiffQuantity = 0; CompletionRate = 0; } } #endregion #region 向上 /// /// 向上 /// [RelayCommand] private async Task MoveUp(string Id) { string stationCode = Appsettings.app("StationInfo", "StationCode"); bool result = await _taskExecutionPlanInfoServices.PlanMoveDown(Id, stationCode); if (result) { await LoadData(); } } #endregion #region 向下 /// /// 向下 /// [RelayCommand] private async Task MoveDown(string Id) { string stationCode = Appsettings.app("StationInfo", "StationCode"); bool result = await _taskExecutionPlanInfoServices.PlanMoveUp(Id, stationCode); if (result) { await LoadData(); } } #endregion #region 删除 /// /// 删除 /// [RelayCommand] private async Task DeletePlan(string Id) { MessageBoxResult msg = MessageBox.Show("确定要删除吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (MessageBoxResult.Yes == msg) { try { int id = Convert.ToInt32(Id); ExecutePlanInfo executionPlanInfo = _taskExecutionPlanInfoServices.FirstAsync(s => s.ObjId == id).Result; if (executionPlanInfo.PlanAmount == executionPlanInfo.CompleteAmount) { MessageBox.Show("执行计划已经完成,不可以删除!", "系统信息"); return; } if (executionPlanInfo.PlanType == 1) { var obj_sidePanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc")); var obj_backPanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC")); string taskSideCode = this.GetSidePlanCode(obj_sidePanel); string taskBackCode = this.GetBackPlanCode(obj_backPanel); if (taskSideCode.Equals(executionPlanInfo.TaskCode)) { obj_sidePanel.plc.WriteInt16("D6021", "5"); } if (taskBackCode.Equals(executionPlanInfo.TaskCode)) { obj_backPanel.plc.WriteInt16("D4021", "5"); } var backPanelList = _recordBackPanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result; int backPanelCount = backPanelList.Sum(d => d.OutPutAmount); var sidePanelList = _recordSidePanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result; int sidePanelCount = sidePanelList.Sum(d => d.OutPutAmount); if (backPanelCount == 0&& sidePanelCount==0) { executionPlanInfo.IsFlag =0; } else { executionPlanInfo.IsFlag = 1; } } if (executionPlanInfo.PlanType == 2) { var obj_sidePanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc")); string taskSideCode = this.GetSidePlanCode(obj_sidePanel); if (taskSideCode.Equals(executionPlanInfo.TaskCode)) { obj_sidePanel.plc.WriteInt16("D6021", "5"); } var sidePanelList = _recordSidePanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result; int sidePanelCount = sidePanelList.Sum(d => d.OutPutAmount); if (sidePanelCount == 0) { executionPlanInfo.IsFlag = 0; } else { executionPlanInfo.IsFlag = 1; } } if (executionPlanInfo.PlanType == 3) { var obj_backPanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC")); string taskBackCode = this.GetBackPlanCode(obj_backPanel); if (taskBackCode.Equals(executionPlanInfo.TaskCode)) { obj_backPanel.plc.WriteInt16("D4021", "5"); } var backPanelList = _recordBackPanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result; int backPanelCount = backPanelList.Sum(d => d.OutPutAmount); if (backPanelCount == 0) { executionPlanInfo.IsFlag = 0; } else { executionPlanInfo.IsFlag = 1; } } bool result= false; if (executionPlanInfo.IsFlag == 0) { result = await _taskExecutionPlanInfoServices.DeleteAsync(executionPlanInfo); } else { result = await _taskExecutionPlanInfoServices.UpdateAsync(executionPlanInfo); } if (result) { PlanInfoDataGrid.Clear(); await LoadData(); MessageBox.Show("执行计划删除成功", "系统信息"); } else { MessageBox.Show("执行计划删除失败", "系统信息"); } } catch (Exception ex) { log.Error("钣金取消计划异常:"+ex.Message); } } } #endregion #region 下传计划 /// /// 下传计划 /// [RelayCommand] private async Task NextPass(string Id) { MessageBoxResult msg = MessageBox.Show("确定要下发计划吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (MessageBoxResult.Yes != msg) return; var model = await _taskExecutionPlanInfoServices.FirstAsync(d => d.ObjId == int.Parse(Id)); if (model.ExecuteStatus == 2) { MessageBox.Show("该计划正在执行中,请勿重复下传", "系统信息"); } else { var result = _taskExecutionPlanInfoServices.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 #region 物料库存 /// /// 物料库存 /// [RelayCommand] private void InventoryStatistics() { MaterialStatisticsView model = new MaterialStatisticsView(); model.ShowDialog(); } #endregion #endregion #region 执行计划 #region 工位名称 private string _stationName; public string StationName { get => _stationName; set => SetProperty(ref _stationName, value); } #endregion #region 订单编号 private string _orderCode; public string OrderCode { get => _orderCode; set => SetProperty(ref _orderCode, value); } #endregion #region 计划编号 private string _mesOrderCode; public string MesOrderCode { get => _mesOrderCode; set => SetProperty(ref _mesOrderCode, value); } #endregion #region 成品型号 private string _productModel; public string ProductModel { get => _productModel; set => SetProperty(ref _productModel, value); } #endregion #region 开始时间 private string _beginTime; public string BeginTime { get => _beginTime; set => SetProperty(ref _beginTime, value); } #endregion #region 计划数量 private int _planNum; public int PlanNum { get => _planNum; set => SetProperty(ref _planNum, value); } /// /// 计划最大值 /// private double _planMaxNum; public double PlanMaxNum { get => _planMaxNum; set => SetProperty(ref _planMaxNum, value); } #endregion #region 实际数量 private double _realQuantity; public double RealQuantity { get => _realQuantity; set => SetProperty(ref _realQuantity, value); } #endregion #region 差异数量 private int _diffQuantity; public int DiffQuantity { get => _diffQuantity; set => SetProperty(ref _diffQuantity, value); } #endregion #region 完成率 private double _completionRate; public double CompletionRate { get => _completionRate; set => SetProperty(ref _completionRate, value); } #endregion #endregion #region 当日产量 #region 日产量柱状图X轴日期 /// /// 日产量柱状图X轴日期 /// private List productionHourList; public List ProductionHourList { get { return productionHourList; } set { productionHourList = value; } } #endregion /// /// 日产量柱状图 /// private SeriesCollection achievement = new SeriesCollection(); public SeriesCollection Achievement { get { return achievement; } set { achievement = value; } } #endregion #region 型号统计 #region 型号统计柱状图x轴物料类型 /// /// 型号统计柱状图x轴物料类型 /// private List materialNameList; public List MaterialNameList { get { return materialNameList; } set { materialNameList = value; } } #endregion #region 型号统计柱状图 /// /// 型号统计柱状图 /// private SeriesCollection modelStatistics = new SeriesCollection(); public SeriesCollection ModelStatistics { get { return modelStatistics; } set { modelStatistics = value; } } #endregion #endregion #region 下拉框 选择执行状态 /// /// 下拉框 选择执行状态 /// private string materialTypeCombox; public string MaterialTypeCombox { get { return materialTypeCombox; } set { materialTypeCombox = value; SetProperty(ref materialTypeCombox, value); } } /// /// 当ComboBox选中项更改时发生 /// private SelectModel _selectLocation; public SelectModel SelectLocation { get { return this._selectLocation; } set { this._selectLocation = value; //这里操作更改变化的值 //MessageBox.Show(_selectLocation.ID); if (_selectLocation != null) { WriteFile(_selectLocation.ID); } SetProperty(ref _selectLocation, value); } } private ObservableCollection _locationRoad = new ObservableCollection(); /// /// 集合数据 /// public ObservableCollection LocationSource { get { return this._locationRoad; } set { SetProperty(ref _locationRoad, value); } } #endregion #region 刷新界面显示数据 /// /// 刷新界面显示数据 /// /// /// public async Task UpdatePlanSHow() { string stationCode = Appsettings.app("StationInfo", "StationCode"); var info = await _taskExecutionPlanInfoServices.FirstAsync(d => d.ExecuteStatus == 3 && d.ProductLineCode == stationCode); if (info == null) return; //info= info.First(d => d.ExecuteStatus == 3 && d.ProductLineCode == stationCode); System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { //PlanMaxNum = info.PlanAmount; //OrderCode = info.OrderCode; //MesMOrderCode = info.ProductPlanCode; //ProductModel = info.MaterialName; //BeginTime = info.BeginTime.ToString(); })); } #endregion #region 读写文件 public void WriteFile(int obj) { //写入到配置文件中 appConfig.queryExec = obj.ToString(); } public SelectModel ReadFile() { //读取入到配置文件中 var queryExec = appConfig.queryExec; var model = selectList.FirstOrDefault(d => d.ID == int.Parse(queryExec)); return model; } #endregion #region 刷新当前执行的计划进度 /// /// 刷新当前执行的计划进度 /// /// private void RefreshCurrentPlanInfo() { App.Current.Dispatcher.BeginInvoke((Action)(() => { PlanInfoDataGrid.Clear(); LoadData(); })); } #endregion #region 刷新小时产量统计 /// /// 刷新小时产量统计 /// private void RefreshHourAmount() { App.Current.Dispatcher.Invoke((Action)(() => { //获取小时产量 string stationCode = Appsettings.app("StationInfo", "StationCode"); var hourAmount = _sysUserInfoServices.GetSheetMetaHourData(stationCode).Result; if (hourAmount != null) { if (Achievement.Count != 0) Achievement.Clear(); ProductionHourList = new List(); ChartValues hourAchievement1 = new ChartValues(); ChartValues hourAchievement2 = new ChartValues(); int hour = 0; foreach (var item in hourAmount) { hourAchievement1.Add(new ObservablePoint(hour,Convert.ToDouble(item.FrontPlateAmount))); hourAchievement2.Add(new ObservablePoint(hour,Convert.ToDouble(item.RearPanelAmount))); ProductionHourList.Add(item.HourTime); hour++; } #region 按时间统计 var column = new ColumnSeries(); column.DataLabels = true; column.Title = "前板"; column.ScalesYAt = 0; column.Values = hourAchievement1; column.Foreground = Brushes.White; column.FontSize = 18; Achievement.Add(column); Achievement.Add(new ColumnSeries { DataLabels = true, Title = "后板", ScalesYAt = 0, Values = hourAchievement2, Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)), Foreground = Brushes.CadetBlue, FontSize = 18 }); #endregion } })); } #endregion #region 更新小时产量统计 /// /// 更新小时产量统计 /// private void RefreshHourAmountChart() { App.Current.Dispatcher.Invoke((Action)(() => { //获取小时产量 string stationCode = Appsettings.app("StationInfo", "StationCode"); var hourAmount = _sysUserInfoServices.GetSheetMetaHourData(stationCode).Result; if (hourAmount != null) { int hour = 0; for (int i = 0; i < hourAmount.Count; i++) { Achievement[0].Values[i] = new ObservablePoint(hour, Convert.ToDouble(hourAmount[i].FrontPlateAmount)); Achievement[1].Values[i] = new ObservablePoint(hour, Convert.ToDouble(hourAmount[i].RearPanelAmount)); hour++; } } })); } #endregion #region 刷新物料型号统计 /// /// 刷新物料型号统计 /// private void RefreshMaterialStats() { App.Current.Dispatcher.Invoke((Action)(() => { //获取物料型号统计 string stationCode = Appsettings.app("StationInfo", "StationCode"); var sheetMetalTypeList = _sysUserInfoServices.GetSheetMetalTypeData(stationCode).Result; if (sheetMetalTypeList != null) { #region 按类型统计 ChartValues achievement1 = new ChartValues(); ChartValues achievement2 = new ChartValues(); if (ModelStatistics.Count != 0) { ModelStatistics.Clear(); } MaterialNameList = new List(); foreach (var item in sheetMetalTypeList) { achievement1.Add(Convert.ToInt32(item.FrontPlateAmount)); achievement2.Add(Convert.ToInt32(item.RearPanelAmount)); MaterialNameList.Add(item.MaterialName); } var column2 = new ColumnSeries(); column2.DataLabels = true; column2.Title = "前板"; column2.ScalesYAt = 0; column2.Values = achievement1; column2.Foreground = Brushes.White; column2.FontSize = 18; ModelStatistics.Add(column2); ModelStatistics.Add(new ColumnSeries() { DataLabels = true, Title = "后板", Values = achievement2, ScalesYAt = 0, Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)), Foreground = Brushes.White, FontSize = 18 }); #endregion } })); } #endregion #region 刷新物料型号统计 /// /// 刷新物料型号统计 /// private void RefreshMaterialChart() { App.Current.Dispatcher.Invoke((Action)(() => { //获取物料型号统计 string stationCode = Appsettings.app("StationInfo", "StationCode"); var sheetMetalTypeList = _sysUserInfoServices.GetSheetMetalTypeData(stationCode).Result; if (sheetMetalTypeList != null) { #region 按类型统计 ChartValues achievement1 = new ChartValues(); ChartValues achievement2 = new ChartValues(); for (int i = 0; i < sheetMetalTypeList.Count; i++) { if (ModelStatistics.Count==0) { RefreshMaterialStats(); } else { if (sheetMetalTypeList.Count()>0) { //RefreshMaterialStats(); try { double frontPlateAmount = Convert.ToDouble(sheetMetalTypeList[i].FrontPlateAmount); ModelStatistics[0].Values[i] = frontPlateAmount; double rearPanelAmount = Convert.ToDouble(sheetMetalTypeList[i].RearPanelAmount); ModelStatistics[1].Values[i] = rearPanelAmount; MaterialNameList[i] = sheetMetalTypeList[i].MaterialName; } catch (Exception) { RefreshMaterialStats(); } } else { RefreshMaterialStats(); } } } #endregion } })); } #endregion #region 获取当前班组时间 public CurrentTeamTimeView GetTeamHour() { try { List obj = _sysUserInfoServices.GetTeamData().Result; if (obj != null) { CurrentTeamTimeView view = new CurrentTeamTimeView(); view.TeamName = obj.FirstOrDefault(d => d.Seq == 1).TeamName; view.StartTime = obj.Min(d => d.StartTime); view.EndTime = obj.Max(d => d.EndTime); return view; } } catch (Exception ex) { log.Error($"获取当前班组时间异常:{ex.Message}"); } return null; } #endregion #region PLC存储的当前正在执行的前后板计划编号 public string GetSidePlanCode(PlcModel obj) { bool flag = true; string planCode = string.Empty; try { do { byte[] info = obj.plc.Read("D6030", 59); if (info == null) { Thread.Sleep(1000); continue; } //计划编号 planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim(); if (!string.IsNullOrEmpty(planCode)) flag = false; } while (flag); } catch (Exception ex) { log.Error($"获取前板传入的计划编号:{ex.Message}"); } return planCode; } public string GetBackPlanCode(PlcModel obj) { string planCode = string.Empty; try { bool flag = true; do { byte[] info = obj.plc.Read("D4030", 59); if (info == null) { Thread.Sleep(1000); continue; } //计划编号 planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim(); if (!string.IsNullOrEmpty(planCode)) flag = false; } while (flag); } catch (Exception ex) { log.Error($"获取后板传入的计划编号:{ex.Message}"); } return planCode; } #endregion } }