using CommonFunc; using System; using System.Collections.Generic; using System.Data; using System.Windows; using System.Windows.Controls; using XGL.Data.DBService; using XGL.Models.Model.FoamingMac; namespace XGLFinishPro.Views { /// /// LanJu_InOut.xaml 的交互逻辑 /// public partial class LanJu_InOut : UserControl { FormingMachineService formingMachineService = new FormingMachineService(); string _workOrderCode = ""; string _deviceCode = ""; public event EventHandler ValueSelected; public List SFCCodeList { get; private set; } = new List(); public LanJu_InOut() { InitializeComponent(); } public LanJu_InOut(string workOrderCode, string deviceCode) { InitializeComponent(); _workOrderCode = workOrderCode; _deviceCode = deviceCode; } private void UserControl_Loaded(object sender, RoutedEventArgs e) { GetInOutRecordInfo(); } public void GetInOutRecordInfo() { try { List orderList = new List(); int currHour = DateTime.Now.Hour; int currMinute = DateTime.Now.Minute; //modelWareHouse = new List(); //userDbWareHouse = new DBService(); int shiftId = 0; DataTable shiftlist = formingMachineService.GetShiftList(); string endTimeRecord = ""; string startTimeRecord = ""; foreach (DataRow shift in shiftlist.Rows) { string[] timeStart = shift["Shift_Start_Time"].ToString().Split(':'); string[] timeEnd = shift["Shift_End_Time"].ToString().Split(':'); // 创建两个不带日期的时间点 TimeSpan currTime = new TimeSpan(currHour, currMinute, 0); // 获取当前小时+分钟数 TimeSpan startTime = new TimeSpan(Convert.ToInt32(timeStart[0]), Convert.ToInt32(timeStart[1]), 0); // 表示9小时45分钟0秒 TimeSpan endTime = new TimeSpan(Convert.ToInt32(timeEnd[0]), Convert.ToInt32(timeEnd[1]), 0); // 比较当前时间点和班次开始的时间点 int comparisonResultStart = TimeSpan.Compare(currTime, startTime); // 比较当前时间点和班次结束的时间点 int comparisonResultEnd = TimeSpan.Compare(currTime, endTime); //if (comparisonResultStart > 0) { Console.WriteLine("time1 大于 time2"); } if (comparisonResultStart >= 0 && comparisonResultEnd < 0) { endTimeRecord = shift["Shift_Start_Time"].ToString(); startTimeRecord = shift["Shift_End_Time"].ToString(); shiftId = Convert.ToInt32(shift["shift_id"].ToString()); break; } else if (comparisonResultStart >= 0 || comparisonResultEnd < 0) { endTimeRecord = shift["Shift_Start_Time"].ToString(); startTimeRecord = shift["Shift_End_Time"].ToString(); shiftId = Convert.ToInt32(shift["shift_id"].ToString()); break; } //if (Convert.ToInt32(timeStart[0]) <= currHourWithDecimal && currHourWithDecimal < Convert.ToInt32(timeEnd[0])) //{ // shiftId = shift.shiftId; // break; //} //else if (currHourWithDecimal >= Convert.ToInt32(timeStart[0]) || currHourWithDecimal < Convert.ToInt32(timeEnd[0])) //{ // shiftId = shift.shiftId; // break; //} } string[] endTimeReally = endTimeRecord.Split(':'); string[] startTimeReally = startTimeRecord.Split(':'); DateTime currShiftDate = DateTime.Now.Date; TimeSpan currTimeNew = new TimeSpan(currHour, currMinute, 0); // 获取当前小时+分钟数 TimeSpan startTimeNew = new TimeSpan(Convert.ToInt32(startTimeReally[0]), Convert.ToInt32(startTimeReally[1]), 0); // 表示9小时45分钟0秒 TimeSpan endTimeNew = new TimeSpan(Convert.ToInt32(endTimeReally[0]), Convert.ToInt32(endTimeReally[1]), 0); // 表示9小时45分钟0秒 //计算白夜班工作日期用 int resultstart = TimeSpan.Compare(currTimeNew, startTimeNew); // 比较当前时间点和班次结束的时间点 int resultEnd = TimeSpan.Compare(currTimeNew, endTimeNew); //夜班、 if (resultstart < 0 && resultEnd < 0) { currShiftDate = DateTime.Now.Date.AddDays(-1); } DataTable dt = formingMachineService.GetInOutHistoryList(_workOrderCode, _deviceCode, currShiftDate.ToString()); if (dt == null) return; foreach (DataRow i in dt.Rows) { FoamingMacModel order = new FoamingMacModel(); order.workorder_code = i["workorder_code"].ToString(); order.begin = Convert.ToDateTime(i["begin"].ToString()); //order.beout = Convert.ToDateTime(i["beout"].ToString()); order.product_code = i["product_code"].ToString(); order.product_name = i["product_name"].ToString(); order.car_num = Convert.ToInt32(i["car_num"].ToString()); order.product_date = i["plan_time"].ToString(); order.update_time = i["update_time"].ToString(); order.status = i["status"].ToString(); order.work_batch_code = i["work_batch_code"].ToString(); order.attr1 = i["attr1"].ToString(); order.taskcode = i["taskcode"].ToString(); order.rfid = i["rfid"].ToString(); orderList.Add(order); } this.dgInOutRecord.ItemsSource = null; this.dgInOutRecord.ItemsSource = orderList; } catch (Exception ex) { LogHelper.instance.log.Error("获取出入记录信息时发生异常:" + ex.Message); } } private void dgInOutRecord_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = (e.Row.GetIndex() + 1).ToString(); } private void dgInOutRecord_SelectionChanged(object sender, SelectionChangedEventArgs e) { SFCCodeList.Clear(); if (SFCCodeList.Count >= 2) { } SFCCodeList.Add("123"); SFCCodeList.Add("456"); ValueSelected?.Invoke(this, EventArgs.Empty); } } }