| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- using LocalhostMES.Controller;
- using LocalhostMES.Core;
- using LocalhostMES.DataBase;
- using LocalhostMES.Models;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using Unity;
- namespace LocalhostMES.Views
- {
- /// <summary>
- /// MainView.xaml 的交互逻辑
- /// </summary>
- public partial class MainView : Window
- {
- private TrayIconManager trayIconManager;
- public MainView()
- {
- InitializeComponent();
-
- // 设置窗体不可见
- this.WindowState = WindowState.Minimized;
- this.ShowInTaskbar = false;
- this.Visibility = Visibility.Hidden;
- InitializeManagers();
- }
- private void InitializeManagers()
- {
- try
- {
- // 初始化托盘图标
- trayIconManager = new TrayIconManager();
- trayIconManager.OnExit += OnExit;
- trayIconManager.OnSettings += OnSettings;
- trayIconManager.Show();
- }
- catch ( Exception ex )
- {
- LogHelper.WriteLogError("启动托盘失败", ex);
- }
- }
- private void OnSettings(object sender, EventArgs e)
- {
- this.WindowState = WindowState.Normal;
- this.Show();
- }
- private void OnExit(object sender, EventArgs e)
- {
- trayIconManager?.Dispose();
- this.Close();
- }
- #region Tab 1: 接口测试
- //private async void BtnTestWorkOrder_Click(object sender, RoutedEventArgs e)
- //{
- // try
- // {
-
- // AddLog("=== 测试工单下发接口 ===");
- // var request = new WorkOrderRequest
- // {
- // WorkOrderNo = "TEST-" + DateTime.Now.ToString("yyyyMMddHHmmss"),
- // MaterialCode = "T03GCD",
- // MaterialName = "T03贯穿灯",
- // OrderNo = "ORD-" + DateTime.Now.ToString("yyyyMMdd"),
- // SequenceNo = "001",
- // WorkOrderNum = "100",
- // PlanOnlineTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- // PlanOfflineTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"),
- // Status = "2", // 已发布
- // FrozenStatus = "0",
- // ReleaseStatus = "1",
- // LineCode = "RSC01"
- // };
- // AddLog("请求参数:");
- // AddLog(JsonConvert.SerializeObject(request, Formatting.Indented));
- // var response = await _apiClient.SendWorkOrderAsync(request);
- // AddLog("响应结果:");
- // AddLog(JsonConvert.SerializeObject(response, Formatting.Indented));
- // ShowMessage("工单下发测试完成", false);
- // }
- // catch ( Exception ex )
- // {
- // AddLog($"错误: {ex.Message}");
- // ShowMessage($"测试失败: {ex.Message}", true);
- // }
- //}
- #endregion
- }
- // 工单对话框
- public partial class WorkOrderDialog : Window
- {
- public WorkOrderInfo WorkOrder { get; private set; }
- public WorkOrderDialog()
- {
- InitializeComponent();
- WorkOrder = new WorkOrderInfo
- {
- WorkOrderNo = "WO-" + DateTime.Now.ToString("yyyyMMddHHmmss"),
- Status = "2",
- LineCode = "RSC01",
- CreateTime = DateTime.Now,
- PlannedQuantity = 100,
- StartTime=DateTime.Now,
- EndTime=DateTime.Now
- };
- DataContext = WorkOrder;
- }
- private void InitializeComponent()
- {
- if (WorkOrder == null)
- {
- WorkOrder = new WorkOrderInfo();
- }
- Width = 400;
- Height = 450;
- WindowStartupLocation = WindowStartupLocation.CenterOwner;
- Title = "创建新工单";
- var grid = new Grid();
- grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition());
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
- grid.RowDefinitions.Add(new RowDefinition());
- // 添加控件
- int row = 0;
- AddLabeledTextBox(grid, "工单号:", nameof(WorkOrder.WorkOrderNo), row++);
- AddLabeledTextBox(grid, "物料编码:", nameof(WorkOrder.MaterialCode), row++);
- AddLabeledTextBox(grid, "物料名称:", nameof(WorkOrder.MaterialName), row++);
- AddLabeledTextBox(grid, "计划数量:", nameof(WorkOrder.PlannedQuantity), row++);
- AddLabeledTextBox(grid, "线体编码:", nameof(WorkOrder.LineCode), row++);
- // 工单状态选择
- var statusLabel = new Label { Content = "工单状态:" };
- Grid.SetRow(statusLabel, row);
- Grid.SetColumn(statusLabel, 0);
- var statusComboBox = new ComboBox
- {
- ItemsSource = new[]
- {
- new { Value = "0", Display = "已创建" },
- new { Value = "1", Display = "已排产" },
- new { Value = "2", Display = "已发布" },
- new { Value = "3", Display = "关闭" },
- new { Value = "4", Display = "已锁定" },
- new { Value = "5", Display = "已开工" },
- new { Value = "6", Display = "已完成" },
- new { Value = "7", Display = "异常完工" }
- },
- DisplayMemberPath = "Display",
- SelectedValuePath = "Value",
- SelectedValue = WorkOrder.Status
- };
- statusComboBox.SetBinding(ComboBox.SelectedValueProperty, "Status");
- Grid.SetRow(statusComboBox, row);
- Grid.SetColumn(statusComboBox, 1);
- grid.Children.Add(statusLabel);
- grid.Children.Add(statusComboBox);
- row++;
- // 按钮
- var buttonPanel = new StackPanel
- {
- Orientation = Orientation.Horizontal,
- HorizontalAlignment = HorizontalAlignment.Right,
- Margin = new Thickness(0, 20, 0, 0)
- };
- var okButton = new Button
- {
- Content = "确定",
- Width = 80,
- Margin = new Thickness(5)
- };
- okButton.Click += (s, e) => { DatabaseHelper.InsertWorkOrderInfo(WorkOrder); DialogResult = true; Close(); };
- var cancelButton = new Button
- {
- Content = "取消",
- Width = 80,
- Margin = new Thickness(5)
- };
- cancelButton.Click += (s, e) => { DialogResult = false; Close(); };
- buttonPanel.Children.Add(okButton);
- buttonPanel.Children.Add(cancelButton);
- Grid.SetRow(buttonPanel, row);
- Grid.SetColumnSpan(buttonPanel, 2);
- grid.Children.Add(buttonPanel);
- Content = grid;
- }
- private void AddLabeledTextBox(Grid grid, string label, string bindingPath, int row)
- {
- var labelControl = new Label { Content = label };
- Grid.SetRow(labelControl, row);
- Grid.SetColumn(labelControl, 0);
- var textBox = new TextBox();
- textBox.SetBinding(TextBox.TextProperty, bindingPath);
- Grid.SetRow(textBox, row);
- Grid.SetColumn(textBox, 1);
- grid.Children.Add(labelControl);
- grid.Children.Add(textBox);
- }
- }
- // 结果颜色转换器
- public class ResultColorConverter : System.Windows.Data.IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- if ( value is string result )
- {
- return result == "OK" ? Brushes.Green : Brushes.Red;
- }
- return Brushes.Black;
- }
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|