using CommonFunc.Tools; using System; using System.Collections.Generic; using System.Linq; 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.Shapes; using XGL.Data.DBService; using XGL.Models; namespace XGL.Views { /// /// ReportForm.xaml 的交互逻辑 /// public partial class ReportForm : Window { /// /// 数据库交互 /// FormingMachineService formingMachineService = new FormingMachineService(); private report editReport; private List reports; private Timer timer; private readonly string OpenLineCheckBox = "OpenLineCheckBox"; private readonly string ReplaceLineCheckBox = "ReplaceLineCheckBox"; /// /// 上一任务不良品是否处理并放置在不合格品区域 /// private readonly string unqualified = "unqualified"; /// /// 涉及内容物转换,上一任务内容物是否清理干净 /// private readonly string clear = "clear"; /// /// 上一任务剩余包材/内容物是否做好防护、标识并放在指定位置 /// private readonly string residue = "residue"; /// /// 流水线是否清理干净,无与当班次生产无关的东西存处 /// private readonly string lineClear = "lineClear"; /// /// 作业员是否清楚当班次操作 /// private readonly string UserKnow = "UserKnow"; /// /// 该班次内容物、包材是否符合 /// private readonly string qualified = "qualified"; /// /// 班次现场使用的设备是否可以正常工作 /// private readonly string equipStatus = "equipStatus"; /// /// 该班次生产批号是否正确 /// private readonly string StampCorrect = "StampCorrect"; /// /// 不良品是否处理干净并放置在不合格品区域 /// private readonly string isClear = "isClear"; /// /// 剩余包材/内容物是否做好防护并放在指定位置 /// private readonly string positionCorrect = "positionCorrect"; /// /// 流水线是否清理干净 /// private readonly string isLineClear = "isLineClear"; /// /// 班次 /// private readonly string team = "team"; public ReportForm() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { this.Workshop.Text = string.Empty; this.line.Text = string.Empty; this.date.Text = string.Empty; this.Workshop.Text = Utils.GetAppSetting("SiteCode"); this.line.Text= Utils.GetAppSetting("LineCode"); for (int i = 1; i <= 6; i++) { if (FindName(team + i) is TextBlock text11) { text11.Text = string.Empty; } if (FindName(unqualified + i) is TextBlock text) { text.Text = string.Empty; } if (FindName(clear + i) is TextBlock text1) { text1.Text = string.Empty; } if (FindName(residue + i) is TextBlock text2) { text2.Text = string.Empty; } if (FindName(lineClear + i) is TextBlock text3) { text3.Text = string.Empty; } if (FindName(UserKnow + i) is TextBlock text4) { text4.Text = string.Empty; } if (FindName(qualified + i) is TextBlock text5) { text5.Text = string.Empty; } if (FindName(equipStatus + i) is TextBlock text6) { text6.Text = string.Empty; } if (FindName(StampCorrect + i) is TextBlock text7) { text7.Text = string.Empty; } if (FindName(isClear + i) is TextBlock text8) { text8.Text = string.Empty; } if (FindName(positionCorrect + i) is TextBlock text9) { text9.Text = string.Empty; } if (FindName(isLineClear + i) is TextBlock text10) { text10.Text = string.Empty; } } GetData(); timer = new Timer(10000); timer.Elapsed += Timer_Elapsed; timer.Start(); } private void Timer_Elapsed(object sender, ElapsedEventArgs e) { GetData(); } private void GetData() { try { reports = formingMachineService.GetReportData(""); Dispatcher.Invoke(() => { this.date.Text = DateTime.Now.ToString("yyyy-MM-dd"); for (int i = 0; i < reports.Count; i++) { if (FindName(unqualified + (i + 1)) is TextBlock text) { text.Text = reports[i].unqualified; } if (FindName(clear + (i + 1)) is TextBlock text1) { text1.Text = reports[i].clear; } if (FindName(residue + (i + 1)) is TextBlock text2) { text2.Text = reports[i].residue; } if (FindName(lineClear + (i + 1)) is TextBlock text3) { text3.Text = reports[i].lineClear; } if (FindName(UserKnow + (i + 1)) is TextBlock text4) { text4.Text = reports[i].UserKnow; } if (FindName(qualified + (i + 1)) is TextBlock text5) { text5.Text = reports[i].qualified; } if (FindName(equipStatus + (i + 1)) is TextBlock text6) { text6.Text = reports[i].equipStatus; } if (FindName(StampCorrect + (i + 1)) is TextBlock text7) { text7.Text = reports[i].StampCorrect; } if (FindName(isClear + (i + 1)) is TextBlock text8) { text8.Text = reports[i].isClear; } if (FindName(positionCorrect + (i + 1)) is TextBlock text9) { text9.Text = reports[i].positionCorrect; } if (FindName(isLineClear + (i + 1)) is TextBlock text10) { text10.Text = reports[i].isLineClear; } if (FindName(team + (i + 1)) is TextBlock text11) { text11.Text = reports[i].team == "2" ? "夜班" : "白班"; } if (FindName(OpenLineCheckBox + (i + 1)) is CheckBox checkBox) { checkBox.IsChecked = (reports[i].OpenLineCheckBox == "√"); } if (FindName(ReplaceLineCheckBox + (i + 1)) is CheckBox checkBox1) { checkBox1.IsChecked = (reports[i].ReplaceLineCheckBox == "√"); } } }); } catch { } } private void Add_Click(object sender, RoutedEventArgs e) { new AddReportFrom("Add").ShowDialog(); GetData(); } private void Close_Click(object sender, RoutedEventArgs e) { this.Close(); } private void Edit_Click(object sender, RoutedEventArgs e) { new AddReportFrom("Edit", editReport).ShowDialog(); GetData(); } private void ContextMenu_Opened(object sender, RoutedEventArgs e) { //获取鼠标位置 Point mousePosition = Mouse.GetPosition(this); Point top = this.TopLine.TransformToVisual(this).Transform(new Point(0, this.TopLine.Y1)); Point bottom = this.BottomLine.TransformToVisual(this).Transform(new Point(0, this.BottomLine.Y1)); if (mousePosition.Y > top.Y && mousePosition.Y < bottom.Y) { Point firstPoint = this.FirstLine.TransformToVisual(this).Transform(new Point(this.FirstLine.X1, 0)); Point secondPoint = this.SecondLine.TransformToVisual(this).Transform(new Point(this.SecondLine.X1, 0)); Point thirdLine = this.ThirdLine.TransformToVisual(this).Transform(new Point(this.ThirdLine.X1, 0)); Point fourthLine = this.FourthLine.TransformToVisual(this).Transform(new Point(this.FourthLine.X1, 0)); Point fifthLine = this.FifthLine.TransformToVisual(this).Transform(new Point(this.FifthLine.X1, 0)); Point sixthLine = this.SixthLine.TransformToVisual(this).Transform(new Point(this.SixthLine.X1, 0)); Point SeventhLine = this.SixthLine.TransformToVisual(this).Transform(new Point(this.SeventhLine.X1, 0)); if (mousePosition.X > firstPoint.X && mousePosition.X < SeventhLine.X) { this.EditButton.Visibility = Visibility.Visible; if (mousePosition.X > firstPoint.X && mousePosition.X < secondPoint.X) { editReport = reports[0]; } else if (mousePosition.X > secondPoint.X && mousePosition.X < thirdLine.X) { editReport = reports[1]; } else if (mousePosition.X > thirdLine.X && mousePosition.X < fourthLine.X) { editReport = reports[2]; } else if (mousePosition.X > fourthLine.X && mousePosition.X < fifthLine.X) { editReport = reports[3]; } else if (mousePosition.X > fifthLine.X && mousePosition.X < sixthLine.X) { editReport = reports[4]; } else if (mousePosition.X > sixthLine.X && mousePosition.X < SeventhLine.X) { editReport = reports[5]; } if (string.IsNullOrEmpty(editReport.Id)) { this.EditButton.Visibility = Visibility.Collapsed; } } else { this.EditButton.Visibility = Visibility.Collapsed; } } else { this.EditButton.Visibility = Visibility.Collapsed; } } private void Window_Closed(object sender, EventArgs e) { timer.Stop(); } } }