using CommonFunc; using CommonFunc.Tools; using COSMO.IM.LanJu.Index; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Timers; 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.Navigation; using System.Windows.Shapes; using XGL.Data.DBService; using XGL.Models.Model.FoamingMac; namespace XGL.Views { /// /// LanJu_Operator.xaml 的交互逻辑 /// public partial class LanJu_Operator : UserControl { FormingMachineService formingMachineService = new FormingMachineService(); public static LanJu_Operator lanJu_Operator; Frame frame = new Frame() { Content = new Views.LanJu_InOut()}; string deviceCode = Utils.GetAppSetting("DeviceCode"); List orderList = new List(); FoamingMacModel order = new FoamingMacModel(); Timer timerDeciveState = new Timer(); public enum WindowID { frame } public LanJu_Operator() { InitializeComponent(); WindowChange(WindowID.frame); timerDeciveState.Interval = Utils.GetAppSetting("GetDeviceStateInterval") == "" ? 15000 : Convert.ToInt32(Utils.GetAppSetting("GetDeviceStateInterval")); timerDeciveState.Elapsed += TimerDeciveState_Elapsed; timerDeciveState.Start(); } private void TimerDeciveState_Elapsed(object sender, ElapsedEventArgs e) { DataTable dt = formingMachineService.GetFormingMachineState(deviceCode); if (dt == null) return; // 使用Dispatcher来在UI线程上更新UI this.Dispatcher.Invoke( new Action(() => { LbDeviceState.Content = dt.Rows[0][0].ToString() == "1" ? "正常" : "异常"; } ), System.Windows.Threading.DispatcherPriority.Render); } public void WindowChange(WindowID windowID) { Window1.Content = frame; } private void InOut_Click(object sender, RoutedEventArgs e) { LanJu_InOut lanJu_InOut = new LanJu_InOut(); Window1.Content = new Frame { Content = lanJu_InOut }; } private void Complete_Click(object sender, RoutedEventArgs e) { LanJu_Complete lanJu_Complete = new LanJu_Complete(); Window1.Content = new Frame { Content = lanJu_Complete }; } private void DeviceItems_Click(object sender, RoutedEventArgs e) { LanJu_DeviceItems lanJu_DeviceItems = new LanJu_DeviceItems(); Window1.Content = new Frame { Content = lanJu_DeviceItems }; } private void Paused_Click(object sender, RoutedEventArgs e) { LanJu_Paused lanJu_Paused = new LanJu_Paused(); Window1.Content= new Frame { Content = lanJu_Paused }; } /// /// 上部按钮 /// /// /// private void Flow_Click(object sender, RoutedEventArgs e) { LanJu_Flow lanJu_Flow = new LanJu_Flow(); LanJu_Flow.jump = 1; Window2.Content = new Frame { Content= lanJu_Flow }; } private void Material_Click(object sender, RoutedEventArgs e) { LanJu_Material lanJu_Material = new LanJu_Material(); Window2.Content = new Frame { Content = lanJu_Material }; } private void UCOperator_Loaded(object sender, RoutedEventArgs e) { GetWorkOrderInfo(); } private void GetWorkOrderInfo() { try { //modelWareHouse = new List(); //userDbWareHouse = new DBService(); DataTable dt = formingMachineService.GetFormingMachineInfo(deviceCode); if (dt == null) return; foreach (DataRow i in dt.Rows) { order.workorder_code = i["workorder_code"].ToString(); order.product_name = i["product_name"].ToString(); order.product_code = i["product_code"].ToString(); order.car_num = Convert.ToInt32(i["car_num"].ToString()); order.begin = Convert.ToDateTime(i["begin"].ToString()); order.status = i["status"].ToString(); orderList.Add(order); } this.dgWorkOrderInfo.ItemsSource = orderList; } catch (Exception ex) { LogHelper.instance.log.Error("获取工单准备信息时发生异常:" + ex.Message); } } private void btnPause_Click(object sender, RoutedEventArgs e) { var selectedRow = dgWorkOrderInfo.SelectedItem as FoamingMacModel; var workordercode = selectedRow.workorder_code; formingMachineService.PauseWorkOrder(workordercode); GetWorkOrderInfo(); } } }