using CentralControl.App_Code; using CommonFunc; using CommonFunc.Tools; using HandyControl.Tools.Extension; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; 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; using XGL.Models.Model.OrderPrepare; using static System.Windows.Forms.LinkLabel; using static System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar; namespace XGLFinishPro.Views { /// /// LanJu_Check_Report.xaml 的交互逻辑 /// public partial class LanJu_Check_Report : Window { private string belong_to = string.Empty; private List data; FormingMachineService dbService = new FormingMachineService(); private static double LineWidth = 30; private static double LineHeight = 30; private static double MainLineWidth = 150; private static double MainLineHeight = 50; string deviceCode = Utils.GetAppSetting("DeviceCode"); private string product_code = string.Empty; private readonly List _hours = new List() { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }; private bool isUpdate = false; private readonly List _minutes = new List { "00", "05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55" }; private string LineStr = ""; private readonly List teamGroup = new List() { "A", "B", "C", "D", "E", "F" }; public LanJu_Check_Report(string date) { InitializeComponent(); this.date = date; } private List list = new List(); private string date; private MesTableSelf mesTableSelf; public List DictDatas { get; private set; } private void Window_Loaded(object sender, RoutedEventArgs e) { this.NickName.Text = LoginUser.UserName; LineStr = dbService.GetBaseEquipment(Utils.GetAppSetting("DeviceCode")); LoadData(); } private void LoadData(bool addLine = false) { isUpdate = true; list.Clear(); this.MainGrid.Children.Clear(); this.MainGrid.RowDefinitions.Clear(); this.MainGrid.ColumnDefinitions.Clear(); DictDatas = dbService.GetConversionReportType(); var baseDictDatas = dbService.GetSelfCheckInfo("finished_production_check").ToList(); var baseMainDictDatas = dbService.GetSelfCheckInfo("finished_production_check_info").ToList(); Dictionary> mainDict = new Dictionary>(); for (int i = 0; i < baseDictDatas.Count; i++) { mainDict.Add(baseDictDatas[i].dict_label, baseMainDictDatas.Where(t => t.remark == baseDictDatas[i].remark || string.IsNullOrEmpty(t.remark)).Select(t => t.dict_value).ToList()); list.Add(new ConveterData() { label = baseDictDatas[i].dict_label, value = MD5Provider.Hash(baseDictDatas[i].dict_label), }); } list.ForEach(t => t.value = t.value.Insert(0, "A")); mesTableSelf = dbService.GetMesTableSelf(deviceCode, null, date, "CheckReport"); if (mesTableSelf == null) { mesTableSelf = new MesTableSelf() { id = Guid.NewGuid().ToString(), line_code = deviceCode, check_date = date, product_code = product_code, factory_code = Utils.GetAppSetting("SiteCode"), del_flag = "0", product_date = date, bz = string.Empty, report_name = "CheckReport" }; dbService.InsertMesTableSelf(mesTableSelf); } belong_to = mesTableSelf.id; data = dbService.GetMesTableSelfDetial(belong_to, 6); if (addLine) { int maxLine = data.Max(t => t.table_line) + 1; data.ForEach(t => { t.index++; }); data.Insert(0, new MesTableSelfDetialModel() { index = 0 }); data.RemoveAll(t => t.index == 7); } for (var i = 0; i < 6; i++) { foreach (var item in baseDictDatas) { bool hasData = data.Where(t => t.index == i && t.info_name == item.dict_label).Any(); if (!hasData) { int tableLine = 1; MesTableSelfDetialModel mesTableSelfDetialModel = data.Where(t => t.index == i).Where(t => t.table_line != 0).FirstOrDefault(); if (mesTableSelfDetialModel != null) { tableLine = mesTableSelfDetialModel.table_line; } else { try { tableLine = data.Max(t => t.table_line) + 1; } catch { } } data.Add(new MesTableSelfDetialModel() { index = i, table_line = tableLine, info_name = item.dict_label, info_code = DictDatas.FirstOrDefault(t => t.dict_label == item.dict_label)?.dict_code, }); } } } Dictionary> dic = new Dictionary>(); foreach (var item in data) { if (item.info_name == null || dic.Keys.Contains(item.info_name)) { continue; } var mesTableSelfDetialModels = data.Where(t => t.info_name == item.info_name).ToList(); var dictionary = mesTableSelfDetialModels.ToDictionary(t => t.index); dic.Add(item.info_name, dictionary); list.Add(new ConveterData() { label = item.info_name, value = MD5Provider.Hash(item.info_name), }); } list.ForEach(t => t.value = t.value.Insert(0, "A")); MakeHeaderData(); MakeMainData(baseDictDatas, mainDict, dic); UpdateUI(); isUpdate = false; } private void UpdateUI() { try { double width = this.MainGrid.GetValidWidth(); double widthCount = this.MainGrid.ColumnDefinitions.Count; var lineWidth = width / (widthCount + 3.2); double height = this.MainGrid.GetValidHeight(); double heightCount = this.MainGrid.RowDefinitions.Count; var lineHeight = height / heightCount; foreach (var item in this.MainGrid.Children) { if (item is ComboBox comboBox) { comboBox.Width = (lineWidth - 10) * 2; comboBox.Height = lineHeight - 10; } } } catch { } } private void MakeMainData(List baseDictDatas, Dictionary> mainDict, Dictionary> dic) { string name = baseDictDatas.FirstOrDefault()?.remark; for (int i = 0; i < baseDictDatas.Count; i++) { this.MainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1.0, GridUnitType.Star) }); } for (int i = 3; i < baseDictDatas.Count + 3; i++) { Line line; if (i == baseDictDatas.Count + 2) { line = new Line() { VerticalAlignment = VerticalAlignment.Bottom, X1 = 1, Stretch = Stretch.Fill, StrokeThickness = 1, Stroke = Brushes.Black, }; Grid.SetColumn(line, 0); Grid.SetRow(line, i); Grid.SetColumnSpan(line, 99); this.MainGrid.Children.Add(line); continue; } line = new Line() { VerticalAlignment = VerticalAlignment.Bottom, X1 = 1, Stretch = Stretch.Fill, StrokeThickness = 1, Stroke = Brushes.Black, }; Grid.SetColumn(line, 0); Grid.SetRow(line, i); Grid.SetColumnSpan(line, 1); this.MainGrid.Children.Add(line); line = new Line() { VerticalAlignment = VerticalAlignment.Bottom, X1 = 1, Stretch = Stretch.Fill, StrokeThickness = 1, Stroke = Brushes.Black, }; Grid.SetColumn(line, 2); Grid.SetRow(line, i); Grid.SetColumnSpan(line, 99); this.MainGrid.Children.Add(line); if (name != baseDictDatas[i - 3].remark) { line = new Line() { VerticalAlignment = VerticalAlignment.Top, X1 = 1, Stretch = Stretch.Fill, StrokeThickness = 1, Stroke = Brushes.Black, }; Grid.SetColumn(line, 1); Grid.SetRow(line, i); Grid.SetColumnSpan(line, 1); this.MainGrid.Children.Add(line); } name = baseDictDatas[i - 3].remark; } for (int i = 0; i < baseDictDatas.Count; i++) { if (name != baseDictDatas[i].remark) { TextBlock textBlock2 = new TextBlock() { Text = baseDictDatas[i].remark, FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Grid.SetColumn(textBlock2, 1); Grid.SetRow(textBlock2, i + 3); Grid.SetRowSpan(textBlock2, baseDictDatas.Where(t => t.remark == baseDictDatas[i].remark).Count()); this.MainGrid.Children.Add(textBlock2); } name = baseDictDatas[i].remark; TextBlock textBlock = new TextBlock() { Text = i + 1 + "", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 18, FontWeight = FontWeights.Bold, }; Grid.SetColumn(textBlock, 0); Grid.SetRow(textBlock, i + 3); this.MainGrid.Children.Add(textBlock); textBlock = new TextBlock() { Text = baseDictDatas[i].dict_label.Replace("___", "/"), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 18, FontWeight = FontWeights.Bold, TextWrapping = TextWrapping.Wrap, }; Grid.SetColumn(textBlock, 2); Grid.SetRow(textBlock, i + 3); this.MainGrid.Children.Add(textBlock); } int index = 1; for (int i = 0; i < baseDictDatas.Count; i++) { index = 1; for (int j = 0; j < 6; j++) { int column = 3 + (j * 2); ComboBox comboBox = new ComboBox() { Name = list.First(t => t.label == baseDictDatas[i].dict_label).value + index, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, ItemsSource = mainDict[baseDictDatas[i].dict_label], SelectedItem = data.Where(t => t.info_name == baseDictDatas[i].dict_label && t.index == j).Select(t => t.check_result).FirstOrDefault(), }; comboBox.SelectionChanged += SelectionChanged; Grid.SetRow(comboBox, i + 3); Grid.SetColumn(comboBox, column); Grid.SetColumnSpan(comboBox, 2); this.MainGrid.Children.Add(comboBox); index++; } } foreach (var item in dic) { string key = list.First(t => t.label == item.Key).value; for (int i = 1; i <= 6; i++) { if (item.Value[i - 1].bz == "1") { foreach (var item2 in this.MainGrid.Children) { if (item2 is CheckBox checkBox && checkBox.Name == $"开线{i}") { checkBox.IsChecked = true; break; } } } else if (item.Value[i - 1].bz == "2") { foreach (var item2 in this.MainGrid.Children) { if (item2 is CheckBox checkBox && checkBox.Name == $"清换线{i}") { checkBox.IsChecked = true; break; } } } if (item.Value[i - 1].remark != null) { foreach (var item2 in this.MainGrid.Children) { if (item2 is StackPanel stackPanel) { foreach (var item3 in stackPanel.Children) { if (item3 is ComboBox comboBox) { if (comboBox.Name == $"班组{i}") { comboBox.SelectedItem = item.Value[i - 1].remark; break; } } } } } } } } } private void SelectionChanged(object sender, SelectionChangedEventArgs e) { if (isUpdate) { return; } if (sender is ComboBox comboBox) { if (comboBox.Name.Contains("班组")) { var index = int.Parse(comboBox.Name.Substring(comboBox.Name.Length - 1, 1)); data.Where(t => t.index == index - 1).ForEach(t => t.remark = comboBox.SelectedItem?.ToString()); } else { var key = list.First(t => t.value == comboBox.Name.Substring(0, comboBox.Name.Length - 1)).label; var index = int.Parse(comboBox.Name.Substring(comboBox.Name.Length - 1, 1)); MesTableSelfDetialModel mesTableSelfDetialModel = data.Where(t => t.info_name == key && t.index == index - 1).First(); mesTableSelfDetialModel.check_result = comboBox.SelectedItem.ToString(); if (string.IsNullOrEmpty(mesTableSelfDetialModel.id)) { mesTableSelfDetialModel.id = Guid.NewGuid().ToString(); mesTableSelfDetialModel.belong_to = belong_to; } foreach (var item in this.MainGrid.Children) { if (item is StackPanel stackPanel) { foreach (var item2 in stackPanel.Children) { if (item2 is ComboBox comboBox1) { if (comboBox1.Name == $"班组{index}") { data.Where(t => t.index == index - 1).ForEach(t => t.remark = comboBox1.SelectedItem?.ToString()); } } } } } } } } private void MakeHeaderData() { #region 画线 for (int i = 0; i < 15; i++) { double width = 1.0; if (i == 0) { width = 0.8; } if (i == 1) { width = 1.5; } if (i == 2) { width = 4.0; } this.MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(width, GridUnitType.Star) }); } for (int i = 0; i < 15; i++) { Line line = new Line() { Name = $"YLine{i}", Stroke = Brushes.Black, StrokeThickness = 1, Y1 = 1, Stretch = Stretch.Fill, HorizontalAlignment = HorizontalAlignment.Left, }; Grid.SetColumn(line, i); Grid.SetRow(line, 0); if (i >= 4 && i % 2 == 0) { Grid.SetRowSpan(line, 1); } else { Grid.SetRowSpan(line, 99); } if (i == 14) { Line line1 = new Line() { Stroke = Brushes.Black, StrokeThickness = 1, Y1 = 1, Stretch = Stretch.Fill, HorizontalAlignment = HorizontalAlignment.Right, }; Grid.SetColumn(line1, i); Grid.SetRow(line1, 0); Grid.SetRowSpan(line1, 99); this.MainGrid.Children.Add(line1); } this.MainGrid.Children.Add(line); } for (int i = 0; i <= 2; i++) { this.MainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); Line line = new Line() { Name = $"XLine{i}", Stroke = Brushes.Black, StrokeThickness = 1, X1 = 1, Stretch = Stretch.Fill, VerticalAlignment = VerticalAlignment.Top, }; if (i == 1) { Grid.SetColumn(line, 2); } else { Grid.SetColumn(line, 0); } Grid.SetRow(line, i); Grid.SetColumnSpan(line, 15); this.MainGrid.Children.Add(line); if (i == 2) { Line line1 = new Line() { Stroke = Brushes.Black, StrokeThickness = 1, X1 = 1, Stretch = Stretch.Fill, VerticalAlignment = VerticalAlignment.Bottom, }; Grid.SetColumn(line1, 0); Grid.SetRow(line1, i); Grid.SetColumnSpan(line1, 15); this.MainGrid.Children.Add(line1); } } #endregion #region 画表头 TextBlock textBlock = new TextBlock() { Text = "车间", FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Grid.SetColumn(textBlock, 0); Grid.SetRow(textBlock, 0); Grid.SetRowSpan(textBlock, 2); this.MainGrid.Children.Add(textBlock); textBlock = new TextBlock() { Text = "序号", FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Grid.SetColumn(textBlock, 0); Grid.SetRow(textBlock, 2); this.MainGrid.Children.Add(textBlock); textBlock = new TextBlock() { Text = "点检项目", FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Grid.SetColumn(textBlock, 1); Grid.SetRow(textBlock, 2); this.MainGrid.Children.Add(textBlock); textBlock = new TextBlock() { Text = "黑蚊香", FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Grid.SetColumn(textBlock, 1); Grid.SetRow(textBlock, 0); Grid.SetRowSpan(textBlock, 2); this.MainGrid.Children.Add(textBlock); textBlock = new TextBlock() { Text = "点检内容", FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Grid.SetColumn(textBlock, 2); Grid.SetRow(textBlock, 2); this.MainGrid.Children.Add(textBlock); for (int i = 3; i < 15; i++) { if (i % 2 == 1) { textBlock = new TextBlock() { Text = "点检结果", FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Grid.SetColumn(textBlock, i); Grid.SetRow(textBlock, 2); Grid.SetColumnSpan(textBlock, 2); this.MainGrid.Children.Add(textBlock); } } StackPanel stackPanel = new StackPanel { Orientation = Orientation.Horizontal, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(10, 0, 0, 0), }; textBlock = new TextBlock() { Text = "产线:", FontSize = 18, FontWeight = FontWeights.Bold, }; stackPanel.Children.Add(textBlock); textBlock = new TextBlock() { Text = LineStr, FontSize = 18, FontWeight = FontWeights.Bold, }; stackPanel.Children.Add(textBlock); Grid.SetColumn(stackPanel, 2); Grid.SetRow(stackPanel, 0); this.MainGrid.Children.Add(stackPanel); stackPanel = new StackPanel { Orientation = Orientation.Horizontal, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(10, 0, 0, 0), }; textBlock = new TextBlock() { Text = "日期:", FontSize = 18, FontWeight = FontWeights.Bold, }; stackPanel.Children.Add(textBlock); textBlock = new TextBlock() { Text = date, FontSize = 18, FontWeight = FontWeights.Bold, }; stackPanel.Children.Add(textBlock); Grid.SetColumn(stackPanel, 2); Grid.SetRow(stackPanel, 1); this.MainGrid.Children.Add(stackPanel); #endregion int index = 1; for (int i = 3; i < 15; i++) { CheckBox checkBox; if (i % 2 == 1) { checkBox = new CheckBox() { Content = "开线", Name = $"开线{index}", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 18, }; } else { checkBox = new CheckBox() { Content = "清换线", Name = $"清换线{index}", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 18, }; index++; } checkBox.Checked += CheckBox_Checked; Grid.SetColumn(checkBox, i); Grid.SetRow(checkBox, 0); this.MainGrid.Children.Add(checkBox); } index = 1; for (int i = 3; i < 15; i++) { if (i % 2 == 1) { StackPanel stackPanel2 = new StackPanel { Orientation = Orientation.Horizontal, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, }; textBlock = new TextBlock() { Text = "班组:", FontSize = 18, FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; stackPanel2.Children.Add(textBlock); ComboBox comboBox2 = new ComboBox() { Name = $"班组{index}", FontSize = 18, ItemsSource = teamGroup, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; comboBox2.SelectionChanged += SelectionChanged; stackPanel2.Children.Add(comboBox2); Grid.SetColumn(stackPanel2, i); Grid.SetRow(stackPanel2, 1); Grid.SetColumnSpan(stackPanel2, 2); this.MainGrid.Children.Add(stackPanel2); index++; } } } private void CheckBox_Checked(object sender, RoutedEventArgs e) { if (sender is CheckBox checkBox) { int index = int.Parse(checkBox.Name.Substring(checkBox.Name.Length - 1, 1)); if (checkBox.Name.Contains("开线")) { if (checkBox.IsChecked != null && checkBox.IsChecked.Value) { data.Where(t => t.index == index - 1).ForEach(t => t.bz = "1"); foreach (var item in this.MainGrid.Children) { if (item is CheckBox checkBox2 && checkBox2.Name == $"清换线{index}") { data.Where(t => t.index == index - 1).ForEach(t => t.bz = "1"); checkBox2.IsChecked = false; break; } } } else { data.Where(t => t.index == index - 1).ForEach(t => t.bz = ""); } } else { if (checkBox.IsChecked != null && checkBox.IsChecked.Value) { data.Where(t => t.index == index - 1).ForEach(t => t.bz = "0"); foreach (var item in this.MainGrid.Children) { if (item is CheckBox checkBox1 && checkBox1.Name == $"开线{index}") { data.Where(t => t.index == index - 1).ForEach(t => t.bz = "2"); checkBox1.IsChecked = false; break; } } } else { data.Where(t => t.index == index - 1).ForEach(t => t.bz = ""); } } } } private void ToggleButton_Click(object sender, RoutedEventArgs e) { if (((ToggleButton)sender).TemplatedParent is ComboBox comboBox) { comboBox.IsDropDownOpen = !comboBox.IsDropDownOpen; } } private void Refresh_Click(object sender, RoutedEventArgs e) { LoadData(); } private void Add_Click(object sender, RoutedEventArgs e) { LoadData(true); } private void Submit_Click(object sender, RoutedEventArgs e) { foreach (var item in data) { if (!string.IsNullOrEmpty(item.belong_to)) { var mesTableSelf = dbService.GetMesTableSelfDetialById(item.id); if (mesTableSelf != null) { dbService.UpdateMesTableSelfDetial(item); } else if (mesTableSelf == null) { dbService.InsertMesTableSelfDetial(item); } } } mesTableSelf.create_by = LoginUser.UserName; dbService.UpdateMesTableSelf(belong_to,"",LoginUser.UserName); MessageBox.Show("保存成功"); LoadData(); } private void Close_Click(object sender, RoutedEventArgs e) { this.Close(); } } }