|
|
@@ -1,1001 +1,75 @@
|
|
|
-using LocalhostMES.Controller;
|
|
|
-using LocalhostMES.Core;
|
|
|
using LocalhostMES.DataBase;
|
|
|
-using LocalhostMES.Models;
|
|
|
-using LocalhostMES.Views;
|
|
|
-using Newtonsoft.Json;
|
|
|
-using Newtonsoft.Json.Linq;
|
|
|
+using LocalhostMES.ViewModels.Services;
|
|
|
using Prism.Commands;
|
|
|
-using Prism.Ioc;
|
|
|
using Prism.Mvvm;
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Collections.ObjectModel;
|
|
|
using System.ComponentModel;
|
|
|
-using System.ComponentModel.Composition.Primitives;
|
|
|
-using System.Drawing;
|
|
|
-using System.Linq;
|
|
|
-using System.Net;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using System.Web.UI.WebControls;
|
|
|
-using System.Windows;
|
|
|
-using System.Windows.Threading;
|
|
|
-using System.Xml.Linq;
|
|
|
-
|
|
|
namespace LocalhostMES.ViewModels
|
|
|
{
|
|
|
- public class MainViewModel:BindableBase
|
|
|
+ /// <summary>
|
|
|
+ /// 主窗口壳:初始化/释放共享会话与 Web API 宿主。
|
|
|
+ /// </summary>
|
|
|
+ public class MainViewModel : BindableBase
|
|
|
{
|
|
|
- IContainerProvider _container;
|
|
|
- private Management management;
|
|
|
-
|
|
|
- private bool _isServiceRunning = false;
|
|
|
-
|
|
|
- #region 属性
|
|
|
- private int _ServerPort=8081;
|
|
|
- public int ServerPort { get => _ServerPort; set { SetProperty(ref _ServerPort, value); } }
|
|
|
-
|
|
|
- private string _ApiUrl ="http://localhost:5000";
|
|
|
- public string ApiUrl { get => _ApiUrl; set { SetProperty(ref _ApiUrl, value); } }
|
|
|
- private string _AppKey = "API_XXM";
|
|
|
- public string AppKey { get => _AppKey; set { SetProperty(ref _AppKey, value); } }
|
|
|
- private string _Token = "7c5766afa3ca82f8a21af120f9b1cca6d";
|
|
|
- public string Token { get => _Token; set { SetProperty(ref _Token, value); } }
|
|
|
-
|
|
|
-
|
|
|
- private ObservableCollection<string> _Logs=new ObservableCollection<string>();
|
|
|
- public ObservableCollection<string> Logs { get => _Logs; set { SetProperty(ref _Logs, value); } }
|
|
|
-
|
|
|
-
|
|
|
- private ObservableCollection<WorkOrderInfo> _dgWorkOrders =new ObservableCollection<WorkOrderInfo>();
|
|
|
- public ObservableCollection<WorkOrderInfo> DgWorkOrders { get => _dgWorkOrders; set { SetProperty(ref _dgWorkOrders, value); } }
|
|
|
-
|
|
|
- private WorkOrderInfo _SelectWorkOrderInfo;
|
|
|
- public WorkOrderInfo SelectWorkOrderInfo { get => _SelectWorkOrderInfo; set { SetProperty(ref _SelectWorkOrderInfo, value); } }
|
|
|
-
|
|
|
- private ObservableCollection<SnInfo> _dgSns =new ObservableCollection<SnInfo>();
|
|
|
- public ObservableCollection<SnInfo> DgSns { get => _dgSns; set { SetProperty(ref _dgSns, value); } }
|
|
|
-
|
|
|
- private SnInfo _SelectSnInfo;
|
|
|
- public SnInfo SelectSnInfo { get => _SelectSnInfo; set { SetProperty(ref _SelectSnInfo, value); } }
|
|
|
-
|
|
|
- private ObservableCollection<BindRecord> _dgBindRecords =new ObservableCollection<BindRecord>();
|
|
|
- public ObservableCollection<BindRecord> DgBindRecords { get => _dgBindRecords; set { SetProperty(ref _dgBindRecords, value); } }
|
|
|
-
|
|
|
- private BindRecord _SelectBindRecord;
|
|
|
- public BindRecord SelectBindRecord { get => _SelectBindRecord; set { SetProperty(ref _SelectBindRecord, value); } }
|
|
|
-
|
|
|
- private ObservableCollection<ProcessRecord> _dgProcessRecords =new ObservableCollection<ProcessRecord>();
|
|
|
- public ObservableCollection<ProcessRecord> DgProcessRecords { get => _dgProcessRecords; set { SetProperty(ref _dgProcessRecords, value); } }
|
|
|
-
|
|
|
- private ProcessRecord _SelectProcessRecord;
|
|
|
- public ProcessRecord SelectProcessRecord { get => _SelectProcessRecord; set { SetProperty(ref _SelectProcessRecord, value); } }
|
|
|
-
|
|
|
- private ObservableCollection<LocalhostPartInfo> _PartInfos = new ObservableCollection<LocalhostPartInfo>();
|
|
|
- public ObservableCollection<LocalhostPartInfo> PartInfos { get => _PartInfos; set { SetProperty(ref _PartInfos, value); } }
|
|
|
-
|
|
|
- private LocalhostPartInfo _NewPart = new LocalhostPartInfo();
|
|
|
- public LocalhostPartInfo NewPart { get => _NewPart; set { SetProperty(ref _NewPart, value); } }
|
|
|
-
|
|
|
- private LocalhostPartInfo _SelectPart = new LocalhostPartInfo();
|
|
|
- public LocalhostPartInfo SelectPart { get => _SelectPart; set { SetProperty(ref _SelectPart, value); } }
|
|
|
-
|
|
|
-
|
|
|
- private string _SearchWorkOrder;
|
|
|
- public string SearchWorkOrder { get => _SearchWorkOrder; set { SetProperty(ref _SearchWorkOrder, value); } }
|
|
|
-
|
|
|
-
|
|
|
- private string _ServiceStatus="服务状态: 已停止";
|
|
|
-
|
|
|
- private Brush _Servicebrushes = Brushes.Green;
|
|
|
-
|
|
|
-
|
|
|
- private bool _StartServiceEnable=true;
|
|
|
-
|
|
|
- private bool _StopServiceEnable=true;
|
|
|
-
|
|
|
- public string ServiceStatus { get => _ServiceStatus; set { SetProperty(ref _ServiceStatus, value); } }
|
|
|
- public Brush Servicebrushes { get => _Servicebrushes; set { SetProperty(ref _Servicebrushes, value); } }
|
|
|
- public bool StartServiceEnable { get => _StartServiceEnable; set { SetProperty(ref _StartServiceEnable, value); } }
|
|
|
- public bool StopServiceEnable { get => _StopServiceEnable; set { SetProperty(ref _StopServiceEnable, value); } }
|
|
|
-
|
|
|
- private string _StatusTxt;
|
|
|
- public string StatusTxt { get => _StatusTxt; set { SetProperty(ref _StatusTxt, value); } }
|
|
|
-
|
|
|
- private Brush _StatusForeground=Brushes.Green;
|
|
|
- public Brush StatusForeground { get => _StatusForeground; set { SetProperty(ref _StatusForeground, value); } }
|
|
|
-
|
|
|
-
|
|
|
- #region 零件
|
|
|
-
|
|
|
- private ObservableCollection<ParkingLot> _parkingLots=new ObservableCollection<ParkingLot>();
|
|
|
- public ObservableCollection<ParkingLot> ParkingLots
|
|
|
- {
|
|
|
- get => _parkingLots;
|
|
|
- set => SetProperty(ref _parkingLots, value);
|
|
|
- }
|
|
|
-
|
|
|
- private ParkingLot _currentParkingLot=new ParkingLot();
|
|
|
- public ParkingLot CurrentParkingLot
|
|
|
- {
|
|
|
- get => _currentParkingLot;
|
|
|
- set => SetProperty(ref _currentParkingLot, value);
|
|
|
- }
|
|
|
-
|
|
|
- private ParkingLot _selectedParkingLot;
|
|
|
- public ParkingLot SelectedParkingLot
|
|
|
- {
|
|
|
- get => _selectedParkingLot;
|
|
|
- set => SetProperty(ref _selectedParkingLot, value);
|
|
|
- }
|
|
|
-
|
|
|
- private bool _isEditMode;
|
|
|
- public bool IsEditMode
|
|
|
- {
|
|
|
- get => _isEditMode;
|
|
|
- set => SetProperty(ref _isEditMode, value);
|
|
|
- }
|
|
|
- // 命令
|
|
|
- public DelegateCommand AddCommand { get; private set; }
|
|
|
- public DelegateCommand UpdateCommand { get; private set; }
|
|
|
- public DelegateCommand<ParkingLot> DeleteCommand { get; private set; }
|
|
|
- public DelegateCommand<ParkingLot> EditCommand { get; private set; }
|
|
|
- public DelegateCommand ClearFormCommand { get; private set; }
|
|
|
- public DelegateCommand CancelEditCommand { get; private set; }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #endregion
|
|
|
- #endregion
|
|
|
- #region 命令
|
|
|
- private DelegateCommand _LoadedCommand;
|
|
|
- public DelegateCommand LoadedCommand =>
|
|
|
- _LoadedCommand ?? ( _LoadedCommand = new DelegateCommand(ExecuteLoadedCommand) );
|
|
|
-
|
|
|
- private DelegateCommand _ClosedCommand;
|
|
|
- public DelegateCommand ClosedCommand =>
|
|
|
- _ClosedCommand ?? ( _ClosedCommand = new DelegateCommand(ExecuteClosedCommand) );
|
|
|
-
|
|
|
- private DelegateCommand _TestSnPrintCommand;
|
|
|
- public DelegateCommand TestSnPrintCommand =>
|
|
|
- _TestSnPrintCommand ?? ( _TestSnPrintCommand = new DelegateCommand(TestSnPrint) );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private DelegateCommand _TestSnComponentCommand;
|
|
|
- public DelegateCommand TestSnComponentCommand =>
|
|
|
- _TestSnComponentCommand ?? ( _TestSnComponentCommand = new DelegateCommand(TestSnComponent) );
|
|
|
-
|
|
|
- private DelegateCommand _TestProcessParamsCommand;
|
|
|
- public DelegateCommand TestProcessParamsCommand =>
|
|
|
- _TestProcessParamsCommand ?? ( _TestProcessParamsCommand = new DelegateCommand(TestProcessParams) );
|
|
|
-
|
|
|
-
|
|
|
- private DelegateCommand _ClearLogCommand;
|
|
|
- public DelegateCommand ClearLogCommand =>
|
|
|
- _ClearLogCommand ?? ( _ClearLogCommand = new DelegateCommand(ClearLog) );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private DelegateCommand _RefreshWorkOrdersCommand;
|
|
|
- public DelegateCommand RefreshWorkOrdersCommand =>
|
|
|
- _RefreshWorkOrdersCommand ?? ( _RefreshWorkOrdersCommand = new DelegateCommand(RefreshWorkOrders) );
|
|
|
-
|
|
|
- private DelegateCommand _AddWorkOrderCommand;
|
|
|
- public DelegateCommand AddWorkOrderCommand =>
|
|
|
- _AddWorkOrderCommand ?? ( _AddWorkOrderCommand = new DelegateCommand(AddWorkOrder) );
|
|
|
- private DelegateCommand _DeleteWorkOrderCommand;
|
|
|
- public DelegateCommand DeleteWorkOrderCommand =>
|
|
|
- _DeleteWorkOrderCommand ?? ( _DeleteWorkOrderCommand = new DelegateCommand(DeleteWorkOrder) );
|
|
|
-
|
|
|
-
|
|
|
- private DelegateCommand _SearchSnsCommand;
|
|
|
- public DelegateCommand SearchSnsCommand =>
|
|
|
- _SearchSnsCommand ?? ( _SearchSnsCommand = new DelegateCommand(SearchSns) );
|
|
|
-
|
|
|
+ private readonly IMesWorkspace _workspace;
|
|
|
|
|
|
- private DelegateCommand _RefreshBindRecordsCommand;
|
|
|
- public DelegateCommand RefreshBindRecordsCommand =>
|
|
|
- _RefreshBindRecordsCommand ?? ( _RefreshBindRecordsCommand = new DelegateCommand(RefreshBindRecords) );
|
|
|
- private DelegateCommand _ClearBindRecordsCommand;
|
|
|
- public DelegateCommand ClearBindRecordsCommand =>
|
|
|
- _ClearBindRecordsCommand ?? ( _ClearBindRecordsCommand = new DelegateCommand(ClearBindRecords) );
|
|
|
-
|
|
|
- private DelegateCommand _RefreshProcessRecordsCommand;
|
|
|
- public DelegateCommand RefreshProcessRecordsCommand =>
|
|
|
- _RefreshProcessRecordsCommand ?? ( _RefreshProcessRecordsCommand = new DelegateCommand(RefreshProcessRecords) );
|
|
|
- private DelegateCommand _ClearProcessRecordsCommand;
|
|
|
- public DelegateCommand ClearProcessRecordsCommand =>
|
|
|
- _ClearProcessRecordsCommand ?? ( _ClearProcessRecordsCommand = new DelegateCommand(ClearProcessRecords) );
|
|
|
- private DelegateCommand _StartServiceCommand;
|
|
|
- public DelegateCommand StartServiceCommand =>
|
|
|
- _StartServiceCommand ?? ( _StartServiceCommand = new DelegateCommand(StartService) );
|
|
|
-
|
|
|
- private DelegateCommand _StopServiceCommand;
|
|
|
- public DelegateCommand StopServiceCommand =>
|
|
|
- _StopServiceCommand ?? ( _StopServiceCommand = new DelegateCommand(StopService) );
|
|
|
- private DelegateCommand _SaveSettingsCommand;
|
|
|
- public DelegateCommand SaveSettingsCommand =>
|
|
|
- _SaveSettingsCommand ?? ( _SaveSettingsCommand = new DelegateCommand(SaveSettings) );
|
|
|
-
|
|
|
- private DelegateCommand _AddPartInfoCommand;
|
|
|
- public DelegateCommand AddPartInfoCommand =>
|
|
|
- _AddPartInfoCommand ?? (_AddPartInfoCommand = new DelegateCommand(AddPartInfo));
|
|
|
-
|
|
|
- private DelegateCommand _RefPartInfoCommand;
|
|
|
- public DelegateCommand RefPartInfoCommand =>
|
|
|
- _RefPartInfoCommand ?? (_RefPartInfoCommand = new DelegateCommand(RefPartInfo));
|
|
|
-
|
|
|
-
|
|
|
- private DelegateCommand _DeletePartInfoCommand;
|
|
|
- public DelegateCommand DeletePartInfoCommand =>
|
|
|
- _DeletePartInfoCommand ?? (_DeletePartInfoCommand = new DelegateCommand(DeletePartInfo));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public Management Management { get => management; set { SetProperty(ref management, value); } }
|
|
|
- #endregion
|
|
|
- public MainViewModel(IContainerProvider container)
|
|
|
+ public MainViewModel(IMesWorkspace workspace)
|
|
|
{
|
|
|
- _container= container;
|
|
|
- Management = Management.GetManagement();
|
|
|
- AddCommand = new DelegateCommand(AddParkingLot);
|
|
|
- UpdateCommand = new DelegateCommand(UpdateParkingLot, CanUpdate)
|
|
|
- .ObservesProperty(() => IsEditMode);
|
|
|
-
|
|
|
- DeleteCommand = new DelegateCommand<ParkingLot>(DeleteParkingLot);
|
|
|
-
|
|
|
-
|
|
|
- EditCommand = new DelegateCommand<ParkingLot>(EditParkingLot);
|
|
|
- ClearFormCommand = new DelegateCommand(ClearForm);
|
|
|
- CancelEditCommand = new DelegateCommand(CancelEdit);
|
|
|
- //// 初始化服务
|
|
|
- //management.WebApiService = new WebApiService();
|
|
|
- //management.WebApiService.Init(8081);
|
|
|
- //management.WebApiService.StartAsync();
|
|
|
- // 初始化数据
|
|
|
-
|
|
|
- InitializeDataGrids();
|
|
|
-
|
|
|
- LogHelper.logChangHandler += AddLog;
|
|
|
- }
|
|
|
-
|
|
|
- private void ExecuteLoadedCommand()
|
|
|
- {
|
|
|
- UpdateServiceStatus();
|
|
|
- }
|
|
|
-
|
|
|
- private async void ExecuteClosedCommand()
|
|
|
- {
|
|
|
- if ( _isServiceRunning )
|
|
|
- {
|
|
|
- await Management.WebApiService.StopAsync();
|
|
|
- }
|
|
|
- }
|
|
|
- private async void TestSnPrint()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (Management.ApiClient == null )
|
|
|
- {
|
|
|
- ShowMessage("请先启动服务并配置API客户端", true);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- AddLog("=== 测试SN打印请求接口 ===");
|
|
|
-
|
|
|
- var request = new SnPrintRequest
|
|
|
- {
|
|
|
- plant = "1211",
|
|
|
- workShop = "附件工厂",
|
|
|
- line = DgWorkOrders[0].LineCode,
|
|
|
- station = "ST01",
|
|
|
- site = "ST01-01",
|
|
|
- equipment = "PRINTER001",
|
|
|
- orderNo = null,
|
|
|
- workOrderNo = DgWorkOrders[0].WorkOrderNo,
|
|
|
- count = 2,
|
|
|
- printType = 1,
|
|
|
- messageTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
- };
|
|
|
-
|
|
|
- AddLog("请求参数:");
|
|
|
- AddLog(JsonConvert.SerializeObject(request, Formatting.Indented));
|
|
|
- var response = await Management.ApiClient.RequestSnPrintAsync(request);
|
|
|
- AddLog("响应结果:");
|
|
|
- LogHelper.WriteLogInfo(JsonConvert.SerializeObject(response, Formatting.Indented));
|
|
|
- // AddLog(JsonConvert.SerializeObject(response, Formatting.Indented));
|
|
|
- ShowMessage("SN打印请求测试完成", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- AddLog($"错误: {ex.Message}");
|
|
|
- ShowMessage($"测试失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private async void TestSnComponent()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (Management.ApiClient== null )
|
|
|
- {
|
|
|
- ShowMessage("请先启动服务并配置API客户端", true);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- AddLog("=== 测试SN关键件绑定接口 ===");
|
|
|
- List<SnInfo> infos = new List<SnInfo>();
|
|
|
-
|
|
|
- infos = DatabaseHelper.SelectSnInfo(DgWorkOrders[0].WorkOrderNo,true,false);
|
|
|
-
|
|
|
- if (infos.Count != 0)
|
|
|
- {
|
|
|
- var request = new SnKeyComponentRequest
|
|
|
- {
|
|
|
- businessTpye = "SCAN_TASK",
|
|
|
- plant = "1",
|
|
|
- workShop = "ZPCJ",
|
|
|
- lineCode = "ZPX-01",
|
|
|
- stationCode = "ZPX-01-01",
|
|
|
- positionCode = "ZPX-01-01-01",
|
|
|
- barcodeBoundProcInfo = "1",
|
|
|
- equipment = "SCANNER001",
|
|
|
- scanTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
- taskCode = "TASK-001",
|
|
|
- scanTpye = "1",
|
|
|
- sn = infos[0].Sn,
|
|
|
- gbCode = "GB123456",
|
|
|
- snStatus = "1",
|
|
|
- employee = "张三",
|
|
|
- part = new List<PartInfo>
|
|
|
- {
|
|
|
- new PartInfo
|
|
|
- {
|
|
|
- partNum = "5120101-ZE02-001",
|
|
|
- partQty = 1,
|
|
|
- materialCode = "MAT-001",
|
|
|
- oldPartNum = "",
|
|
|
- materialType = "1",
|
|
|
- positionNo = "P001"
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- AddLog("请求参数:");
|
|
|
- AddLog(JsonConvert.SerializeObject(request, Formatting.Indented));
|
|
|
-
|
|
|
- var response = await Management.ApiClient.SendSnComponentAsync(request);
|
|
|
-
|
|
|
- AddLog("响应结果:");
|
|
|
- AddLog(JsonConvert.SerializeObject(response, Formatting.Indented));
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- AddLog("无可用SN");
|
|
|
- }
|
|
|
- ShowMessage("SN关键件绑定测试完成", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- AddLog($"错误: {ex.Message}");
|
|
|
- ShowMessage($"测试失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- private async void TestProcessParams()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if ( Management.ApiClient == null )
|
|
|
- {
|
|
|
- ShowMessage("请先启动服务并配置API客户端", true);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- AddLog("=== 测试加工参数上报接口 ===");
|
|
|
- List<SnInfo> infos = new List<SnInfo>();
|
|
|
-
|
|
|
- infos = DatabaseHelper.SelectSnInfo(DgWorkOrders[0].WorkOrderNo, true, false);
|
|
|
-
|
|
|
- if (infos.Count != 0)
|
|
|
- {
|
|
|
- var request = new ProcessParameterRequest
|
|
|
- {
|
|
|
- businessTpye = "SCAN_TASK",
|
|
|
- plant = "1211",
|
|
|
- workShop = "ZPCJ",
|
|
|
- line = "ZPX-01",
|
|
|
- station = "ZPX-01-01",
|
|
|
- site = "ZPX-01-01-01",
|
|
|
- sn = infos[0].Sn,
|
|
|
- barcode = "PART-001",
|
|
|
- materialCode = "T03GCD",
|
|
|
- equipment = "EQUIP001",
|
|
|
- overallResult = "OK",
|
|
|
- tightenResultDetail = new List<TightenResult>
|
|
|
- {
|
|
|
- new TightenResult
|
|
|
- {
|
|
|
- point_num = 1,
|
|
|
- pset = 1,
|
|
|
- torque = 45.08m,
|
|
|
- angle = 44.0m,
|
|
|
- tighten_status = "OK",
|
|
|
- tighten_dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
- }
|
|
|
- },
|
|
|
- stepResultDetail = new List<StepResult>
|
|
|
- {
|
|
|
- new StepResult
|
|
|
- {
|
|
|
- tagCode = "TEST_PRESSURE",
|
|
|
- tagValue = "3.0",
|
|
|
- tagRage = "2.7-3.3",
|
|
|
- tagResult = "OK",
|
|
|
- tagUnit = "kg",
|
|
|
- ngCode = new List<NgCodeInfo>()
|
|
|
- }
|
|
|
- },
|
|
|
- reservedField1 = "",
|
|
|
- reservedField2 = "",
|
|
|
- reservedField3 = "",
|
|
|
- messageTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
- };
|
|
|
-
|
|
|
- AddLog("请求参数:");
|
|
|
- AddLog(JsonConvert.SerializeObject(request, Formatting.Indented));
|
|
|
-
|
|
|
- var response = await Management.ApiClient.SendProcessParametersAsync(request);
|
|
|
-
|
|
|
- AddLog("响应结果:");
|
|
|
- AddLog(JsonConvert.SerializeObject(response, Formatting.Indented));
|
|
|
- infos[0].IsUsed = true;
|
|
|
- DatabaseHelper.UpdateSnInfo(infos[0]);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- AddLog("无可用SN");
|
|
|
- var request = new ProcessParameterRequest
|
|
|
- {
|
|
|
- businessTpye = "SCAN_TASK",
|
|
|
- plant = "1211",
|
|
|
- workShop = "ZPCJ",
|
|
|
- line = "ZPX-01",
|
|
|
- station = "ZPX-01-01",
|
|
|
- site = "ZPX-01-01-01",
|
|
|
- sn = "LingPao",
|
|
|
- barcode = "PART-001",
|
|
|
- materialCode = "T03GCD",
|
|
|
- equipment = "EQUIP001",
|
|
|
- overallResult = "OK",
|
|
|
- tightenResultDetail = new List<TightenResult>
|
|
|
- {
|
|
|
- new TightenResult
|
|
|
- {
|
|
|
- point_num = 1,
|
|
|
- pset = 1,
|
|
|
- torque = 45.08m,
|
|
|
- angle = 44.0m,
|
|
|
- tighten_status = "OK",
|
|
|
- tighten_dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
- }
|
|
|
- },
|
|
|
- stepResultDetail = new List<StepResult>
|
|
|
- {
|
|
|
- new StepResult
|
|
|
- {
|
|
|
- tagCode = "TEST_PRESSURE",
|
|
|
- tagValue = "3.0",
|
|
|
- tagRage = "2.7-3.3",
|
|
|
- tagResult = "OK",
|
|
|
- tagUnit = "kg",
|
|
|
- ngCode = new List<NgCodeInfo>()
|
|
|
- }
|
|
|
- },
|
|
|
- reservedField1 = "",
|
|
|
- reservedField2 = "",
|
|
|
- reservedField3 = "",
|
|
|
- messageTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
- };
|
|
|
- AddLog("请求参数:");
|
|
|
- AddLog(JsonConvert.SerializeObject(request, Formatting.Indented));
|
|
|
-
|
|
|
- var response = await Management.ApiClient.SendProcessParametersAsync(request);
|
|
|
-
|
|
|
- AddLog("响应结果:");
|
|
|
- AddLog(JsonConvert.SerializeObject(response, Formatting.Indented));
|
|
|
-
|
|
|
- }
|
|
|
- ShowMessage("加工参数上报测试完成", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- AddLog($"错误: {ex.Message}");
|
|
|
- ShowMessage($"测试失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- private void ClearLog()
|
|
|
- {
|
|
|
- Logs.Clear();
|
|
|
- }
|
|
|
-
|
|
|
- #region Tab 2: 工单管理
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private async void RefreshWorkOrders()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- DgWorkOrders =new ObservableCollection<WorkOrderInfo>( DatabaseHelper.SelectWorkOrderInfo()) ;
|
|
|
- ShowMessage($"已加载 {DgWorkOrders.Count} 个工单", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"刷新失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private async void AddWorkOrder()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- // 创建新工单对话框
|
|
|
- var dialog = new WorkOrderDialog();
|
|
|
- if ( dialog.ShowDialog() == true )
|
|
|
- {
|
|
|
- // 创建或更新工单信息
|
|
|
- var workOrder = dialog.WorkOrder;
|
|
|
- if ( DatabaseHelper.InsertWorkOrderInfo(workOrder) )
|
|
|
- {
|
|
|
- ShowMessage("工单创建成功", false);
|
|
|
- RefreshWorkOrders();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ShowMessage($"创建失败", true);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"创建失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void DeleteWorkOrder()
|
|
|
- {
|
|
|
-
|
|
|
- if ( SelectWorkOrderInfo == null )
|
|
|
- {
|
|
|
- ShowMessage("请先选择要删除的工单", true);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var result = MessageBox.Show($"确定要删除工单 {SelectWorkOrderInfo.WorkOrderNo} 吗?",
|
|
|
- "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
|
|
-
|
|
|
- if ( result == MessageBoxResult.Yes )
|
|
|
+ _workspace = workspace;
|
|
|
+ LoadedCommand = new DelegateCommand(OnLoaded);
|
|
|
+ ClosedCommand = new DelegateCommand(OnClosed);
|
|
|
+ if (_workspace is INotifyPropertyChanged npc)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- // 从内存中删除(实际应该调用API)
|
|
|
- DatabaseHelper.DeleteWorkOrderInfo(SelectWorkOrderInfo);
|
|
|
- ShowMessage("工单已删除", false);
|
|
|
- RefreshWorkOrders();
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"删除失败: {ex.Message}", true);
|
|
|
- }
|
|
|
+ npc.PropertyChanged += OnWorkspacePropertyChanged;
|
|
|
}
|
|
|
}
|
|
|
- #endregion
|
|
|
|
|
|
- #region Tab 3: SN管理
|
|
|
+ public DelegateCommand LoadedCommand { get; }
|
|
|
|
|
|
+ public DelegateCommand ClosedCommand { get; }
|
|
|
|
|
|
- private async void SearchSns()
|
|
|
+ public int SelectedTabIndex
|
|
|
{
|
|
|
- try
|
|
|
+ get => _workspace.SelectedTabIndex;
|
|
|
+ set
|
|
|
{
|
|
|
- DgSns.Clear();
|
|
|
- var workOrderNo = SearchWorkOrder.Trim();
|
|
|
- if ( string.IsNullOrEmpty(workOrderNo) )
|
|
|
+ if (_workspace.SelectedTabIndex == value)
|
|
|
{
|
|
|
- ShowMessage("请输入工单号", true);
|
|
|
return;
|
|
|
}
|
|
|
- var response = DatabaseHelper.SelectSnInfo(workOrderNo);
|
|
|
- if ( response.Count != 0 )
|
|
|
- {
|
|
|
- DgSns =new ObservableCollection<SnInfo>(response);
|
|
|
- ShowMessage($"已加载 {response.Count} 个SN", false);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ShowMessage($"加载失败: {response.Count}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"查询失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region Tab 4: 绑定记录
|
|
|
- private async void RefreshBindRecords()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var response = DatabaseHelper.SelectBindRecord();
|
|
|
- if ( response.Count!=0 )
|
|
|
- {
|
|
|
- DgBindRecords=new ObservableCollection<BindRecord>(response);
|
|
|
- ShowMessage($"已加载 {response.Count} 条绑定记录", false);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ShowMessage($"加载失败: {response.Count}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"刷新失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- private void ClearBindRecords()
|
|
|
- {
|
|
|
- var result = MessageBox.Show("确定要清空所有绑定记录吗?",
|
|
|
- "确认清空", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
|
|
-
|
|
|
- if ( result == MessageBoxResult.Yes )
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- DatabaseHelper.DeleteBindRecord();
|
|
|
- DgBindRecords.Clear();
|
|
|
- ShowMessage("绑定记录已清空", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"清空失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region Tab 5: 加工记录
|
|
|
- private async void RefreshProcessRecords()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var response = DatabaseHelper.SelectProcessRecord();
|
|
|
- if ( response.Count!=0 )
|
|
|
- {
|
|
|
- DgProcessRecords=new ObservableCollection<ProcessRecord>(response);
|
|
|
- ShowMessage($"已加载 {response.Count} 条加工记录", false);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ShowMessage($"加载失败: {response.Count}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"刷新失败: {ex.Message}", true);
|
|
|
+ _workspace.SelectedTabIndex = value;
|
|
|
+ RaisePropertyChanged();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private void ClearProcessRecords()
|
|
|
+ private void OnLoaded()
|
|
|
{
|
|
|
- var result = MessageBox.Show("确定要清空所有加工记录吗?",
|
|
|
- "确认清空", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
|
|
-
|
|
|
- if ( result == MessageBoxResult.Yes )
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- DatabaseHelper.DeleteProcessRecord();
|
|
|
- DgProcessRecords.Clear();
|
|
|
- ShowMessage("加工记录已清空", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"清空失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
+ _workspace.Initialize();
|
|
|
}
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region Tab 6: 系统设置
|
|
|
|
|
|
-
|
|
|
- private async void StartService()
|
|
|
+ private async void OnClosed()
|
|
|
{
|
|
|
+ _workspace.Shutdown();
|
|
|
try
|
|
|
{
|
|
|
- if ( ServerPort < 1 || ServerPort > 65535 )
|
|
|
- {
|
|
|
- ShowMessage("请输入有效的端口号(1-65535)", true);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (Management.WebApiService == null)
|
|
|
+ var svc = _workspace.MesManagement.WebApiService;
|
|
|
+ if (svc?.IsRunning == true)
|
|
|
{
|
|
|
- Management.WebApiService = _container.Resolve<WebApiService>();
|
|
|
+ await svc.StopAsync();
|
|
|
}
|
|
|
- if (Management.WebApiService.IsRunning )
|
|
|
- Management.WebApiService.Dispose();
|
|
|
-
|
|
|
-
|
|
|
- Management.WebApiService.Init(ServerPort);
|
|
|
- await Management.WebApiService.StartAsync();
|
|
|
-
|
|
|
- _isServiceRunning = true;
|
|
|
- UpdateServiceStatus();
|
|
|
- ShowMessage($"Web API服务已启动,端口: {ServerPort}", false);
|
|
|
}
|
|
|
- catch ( Exception ex )
|
|
|
+ catch
|
|
|
{
|
|
|
- ShowMessage($"服务启动失败: {ex.Message}", true);
|
|
|
+ // 忽略关闭时异常
|
|
|
}
|
|
|
}
|
|
|
- private async void StopService()
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- await Management.WebApiService.StopAsync();
|
|
|
- _isServiceRunning = false;
|
|
|
- UpdateServiceStatus();
|
|
|
|
|
|
- ShowMessage("Web API服务已停止", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"服务停止失败: {ex.Message}", true);
|
|
|
- }
|
|
|
- }
|
|
|
- private void SaveSettings()
|
|
|
+ private void OnWorkspacePropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
{
|
|
|
- try
|
|
|
+ if (e.PropertyName == nameof(IMesWorkspace.SelectedTabIndex))
|
|
|
{
|
|
|
- var apiUrl = ApiUrl.Trim();
|
|
|
- var appKey = AppKey.Trim();
|
|
|
- var token = Token.Trim();
|
|
|
-
|
|
|
- if ( string.IsNullOrEmpty(apiUrl) )
|
|
|
- {
|
|
|
- ShowMessage("请输入API地址", true);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Management.ApiClient = new MesApiClient(apiUrl, appKey, token);
|
|
|
- ShowMessage("API客户端配置已保存", false);
|
|
|
- }
|
|
|
- catch ( Exception ex )
|
|
|
- {
|
|
|
- ShowMessage($"保存失败: {ex.Message}", true);
|
|
|
+ RaisePropertyChanged(nameof(SelectedTabIndex));
|
|
|
}
|
|
|
}
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 零件
|
|
|
-
|
|
|
- private void AddParkingLot()
|
|
|
- {
|
|
|
- if (!ValidateParkingLot())
|
|
|
- return;
|
|
|
-
|
|
|
- // 创建新对象(避免引用问题)
|
|
|
- var newParkingLot = new ParkingLot
|
|
|
- {
|
|
|
- FormulaType = CurrentParkingLot.FormulaType,
|
|
|
- SerialNumber = CurrentParkingLot.SerialNumber,
|
|
|
- PartNumber = CurrentParkingLot.PartNumber,
|
|
|
- PartName = CurrentParkingLot.PartName,
|
|
|
- PlanNum = CurrentParkingLot.PlanNum,
|
|
|
- UseNum = CurrentParkingLot.UseNum,
|
|
|
- CompletedNum = CurrentParkingLot.CompletedNum
|
|
|
- };
|
|
|
- DatabaseHelper.InsertParkingLot(newParkingLot);
|
|
|
- ParkingLots = new ObservableCollection<ParkingLot>(DatabaseHelper.SelectParkingLot(CurrentParkingLot.FormulaType));
|
|
|
- MessageBox.Show("添加成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- }
|
|
|
-
|
|
|
- private void EditParkingLot(ParkingLot parkingLot)
|
|
|
- {
|
|
|
- if (parkingLot == null)
|
|
|
- return;
|
|
|
-
|
|
|
- // 复制数据到表单
|
|
|
- CurrentParkingLot = new ParkingLot
|
|
|
- {
|
|
|
- FormulaType = parkingLot.FormulaType,
|
|
|
- SerialNumber = parkingLot.SerialNumber,
|
|
|
- PartNumber = parkingLot.PartNumber,
|
|
|
- PartName = parkingLot.PartName,
|
|
|
- PlanNum = parkingLot.PlanNum,
|
|
|
- UseNum = parkingLot.UseNum,
|
|
|
- CompletedNum = parkingLot.CompletedNum
|
|
|
- };
|
|
|
-
|
|
|
- IsEditMode = true;
|
|
|
- SelectedParkingLot = parkingLot;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void UpdateParkingLot()
|
|
|
- {
|
|
|
- if (!ValidateParkingLot() || SelectedParkingLot == null)
|
|
|
- return;
|
|
|
-
|
|
|
- // 更新选中项的数据
|
|
|
- SelectedParkingLot.FormulaType = CurrentParkingLot.FormulaType;
|
|
|
- SelectedParkingLot.SerialNumber = CurrentParkingLot.SerialNumber;
|
|
|
- SelectedParkingLot.PartNumber = CurrentParkingLot.PartNumber;
|
|
|
- SelectedParkingLot.PartName = CurrentParkingLot.PartName;
|
|
|
- SelectedParkingLot.PlanNum = CurrentParkingLot.PlanNum;
|
|
|
- SelectedParkingLot.UseNum = CurrentParkingLot.UseNum;
|
|
|
- SelectedParkingLot.CompletedNum = CurrentParkingLot.CompletedNum;
|
|
|
-
|
|
|
- CancelEdit();
|
|
|
- MessageBox.Show("更新成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- }
|
|
|
-
|
|
|
- private bool CanUpdate()
|
|
|
- {
|
|
|
- return IsEditMode;
|
|
|
- }
|
|
|
-
|
|
|
- private void DeleteParkingLot(ParkingLot parkingLot)
|
|
|
- {
|
|
|
- if (parkingLot == null)
|
|
|
- return;
|
|
|
-
|
|
|
- var result = MessageBox.Show($"确定要删除站点 '{parkingLot.FormulaType}' 的记录吗?",
|
|
|
- "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
|
|
-
|
|
|
- if (result == MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- ParkingLots.Remove(parkingLot);
|
|
|
-
|
|
|
- if (IsEditMode && SelectedParkingLot == parkingLot)
|
|
|
- {
|
|
|
- CancelEdit();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void ClearForm()
|
|
|
- {
|
|
|
- CurrentParkingLot = new ParkingLot();
|
|
|
- }
|
|
|
-
|
|
|
- private void CancelEdit()
|
|
|
- {
|
|
|
- IsEditMode = false;
|
|
|
- ClearForm();
|
|
|
- SelectedParkingLot = null;
|
|
|
- }
|
|
|
-
|
|
|
- private bool ValidateParkingLot()
|
|
|
- {
|
|
|
- //if (CurrentParkingLot.FormulaType)
|
|
|
- //{
|
|
|
- // MessageBox.Show("站点名称不能为空!", "验证错误", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
- // return false;
|
|
|
- //}
|
|
|
-
|
|
|
- // 验证已完成数量是否为数字
|
|
|
- if (!int.TryParse(CurrentParkingLot.PlanNum, out _) && !string.IsNullOrWhiteSpace(CurrentParkingLot.PlanNum))
|
|
|
- {
|
|
|
- MessageBox.Show("计划数量必须为数字!", "验证错误", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!int.TryParse(CurrentParkingLot.UseNum, out _) && !string.IsNullOrWhiteSpace(CurrentParkingLot.UseNum))
|
|
|
- {
|
|
|
- MessageBox.Show("使用数量必须为数字!", "验证错误", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 辅助方法
|
|
|
- private void UpdateServiceStatus()
|
|
|
- {
|
|
|
- if ( _isServiceRunning )
|
|
|
- {
|
|
|
- ServiceStatus = "服务状态: 运行中";
|
|
|
- Servicebrushes = Brushes.Green;
|
|
|
- StartServiceEnable = false;
|
|
|
- StopServiceEnable = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ServiceStatus = "服务状态: 已停止";
|
|
|
- Servicebrushes = Brushes.Red;
|
|
|
- StartServiceEnable = true;
|
|
|
- StopServiceEnable = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void AddLog(string message)
|
|
|
- {
|
|
|
- System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
|
|
- {
|
|
|
-
|
|
|
- Logs.Add($"[{DateTime.Now:HH:mm:ss}] {message}\n");
|
|
|
- }));
|
|
|
- }
|
|
|
-
|
|
|
- private void ShowMessage(string message, bool isError)
|
|
|
- {
|
|
|
- System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
|
|
- {
|
|
|
- StatusTxt = message;
|
|
|
- StatusForeground = isError ? Brushes.Red : Brushes.Green;
|
|
|
- }));
|
|
|
- }
|
|
|
-
|
|
|
- private void InitializeDataGrids()
|
|
|
- {
|
|
|
- DatabaseHelper.CreataDataTable();
|
|
|
- // 初始化工单列表
|
|
|
- DgWorkOrders=new ObservableCollection<WorkOrderInfo>( DatabaseHelper.SelectWorkOrderInfo());
|
|
|
- // 初始化绑定记录
|
|
|
- DgBindRecords = new ObservableCollection<BindRecord>(DatabaseHelper.SelectBindRecord());
|
|
|
- // 初始化加工记录
|
|
|
- DgProcessRecords = new ObservableCollection<ProcessRecord>(DatabaseHelper.SelectProcessRecord());
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void AddPartInfo()
|
|
|
- {
|
|
|
-
|
|
|
- if (DatabaseHelper.InsertPartInfo(NewPart))
|
|
|
- {
|
|
|
- ShowMessage("工单创建成功", false);
|
|
|
- RefreshWorkOrders();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ShowMessage($"创建失败", true);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void RefPartInfo()
|
|
|
- {
|
|
|
-
|
|
|
- PartInfos = new ObservableCollection<LocalhostPartInfo>(DatabaseHelper.SelectPartInfo(NewPart.FormulaType));
|
|
|
-
|
|
|
- }
|
|
|
- public void DeletePartInfo()
|
|
|
- {
|
|
|
- DatabaseHelper.DeletePartInfo(SelectPart.FormulaType, SelectPart.MaterialCode);
|
|
|
- }
|
|
|
-
|
|
|
- public void SetMesState()
|
|
|
- {
|
|
|
- Management.IsLocalhostMode = true;
|
|
|
- }
|
|
|
}
|
|
|
}
|