You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

960 lines
38 KiB
C#

using CentralControl.App_Code;
using CommonFunc;
using CommonFunc.Tools;
using HandyControl.Tools.Extension;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using XGL.Data.DBService;
using XGL.Models;
namespace XGLFinishPro.Views
{
public partial class Lanju_Daily_Check_Report : Window
{
private string belong_to = string.Empty;
private List<MesTableSelfDetialModel> 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");
string productName = string.Empty;
private string shiftCode = "";
private string shiftName = "";
private string product_code = string.Empty;
private readonly List<string> _hours = new List<string>() { "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<string> _minutes = new List<string> { "00", "05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55" };
private string LineStr = "";
private readonly List<string> teamGroup = new List<string>() { "白班", "中班", "晚班"};
public Lanju_Daily_Check_Report()
{
InitializeComponent();
this.date = LoginUser.WorkDate;
shiftCode = LoginUser.ShiftCode;
shiftName = dbService.GetShiftById(shiftCode);
}
private List<ConveterData> list = new List<ConveterData>();
private string date;
private MesTableSelf mesTableSelf;
private List<MesTableSelfDetialModel> mesTableSelfDetialList;
public List<BaseDictData> 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("secutity_production").ToList();
var baseMainDictDatas = dbService.GetSelfCheckInfo("secutity_production_result").ToList();
Dictionary<string, List<string>> mainDict = new Dictionary<string, List<string>>();
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());
if (!list.Any(t => t.label == baseDictDatas[i].dict_label))
{
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"));//开头插入"A"
mesTableSelf = dbService.GetMesTableSelf(deviceCode, null, date, "SecurityProduction"+ shiftName);
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 = "SecurityProduction" + shiftName
};
dbService.InsertMesTableSelf(mesTableSelf);
}
belong_to = mesTableSelf.id;
// 获取当天该班次的记录
data = dbService.GetMesTableSelfDetialByShiftCode(mesTableSelf.id, shiftCode, baseDictDatas.Count);
if (data.Count == 0) // 如果不存在记录,创建新记录
{
data = new List<MesTableSelfDetialModel>();
foreach (var item in baseDictDatas)
{
var newModel = new MesTableSelfDetialModel
{
id = Guid.NewGuid().ToString(),
belong_to = mesTableSelf.id,
info_name = item.dict_label,
info_code = item.dict_code,
check_result = "", // 初始化为空字符串
bz = "", // 初始化为空字符串
remark = shiftCode,
table_line = 1, // 设置默认值
index = 0, // 设置默认值
del_flag = "0" // 设置为未删除
};
// 插入新记录到数据库
dbService.InsertMesTableSelfDetial(newModel);
// 添加到内存中的列表
data.Add(newModel);
}
}
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 < 1; i++)
//{
//}
foreach (var item in baseDictDatas)
{
bool hasData = data.Where(t => t.info_name == item.dict_label && t.remark == shiftCode).Any();
if (!hasData)
{
int tableLine = 1;
MesTableSelfDetialModel mesTableSelfDetialModel = data.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()
{
table_line = tableLine,
info_name = item.dict_label,
remark = shiftCode,
info_code = DictDatas.FirstOrDefault(t => t.dict_label == item.dict_label)?.dict_code,
});
}
}
Dictionary<string, Dictionary<int, MesTableSelfDetialModel>> dic = new Dictionary<string, Dictionary<int, MesTableSelfDetialModel>>();
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();
// 使用GroupBy和ToDictionary来处理可能的重复index
var dictionary = mesTableSelfDetialModels
.GroupBy(t => t.index)
.ToDictionary(
g => g.Key,
g => g.First() // 如果有重复的index取第一个记录
);
dic.Add(item.info_name, dictionary);
if (!list.Any(t => t.label == item.info_name))
{
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;
comboBox.Height = lineHeight - 10;
comboBox.IsEnabled = !mesTableSelf.IsFinal;
}
if (item is TextBox textBox)
{
textBox.Width = Width = (this.MainGrid.GetValidWidth()) /
(this.MainGrid.ColumnDefinitions.Count + 3.2) * 5 - 10;
textBox.Height = this.MainGrid.GetValidHeight() / MainGrid.RowDefinitions.Count - 5;
textBox.IsEnabled = !mesTableSelf.IsFinal;
}
}
this.Commit.Visibility = mesTableSelf.IsFinal ? Visibility.Collapsed : Visibility.Visible;
this.IsFinalSubmit.Visibility = this.Commit.Visibility;
}
catch
{
}
}
private void MakeMainData(List<BaseDictData> baseDictDatas, Dictionary<string, List<string>> mainDict, Dictionary<string, Dictionary<int, MesTableSelfDetialModel>> 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 < 1; 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]?.Distinct(),
SelectedItem = data.Where(t => t.info_name == baseDictDatas[i].dict_label && t.index == j).Select(t => t.check_result).FirstOrDefault(),
Width = 50 // 设置宽度为100可以根据需要调整
};
comboBox.SelectionChanged += SelectionChanged;
Grid.SetRow(comboBox, i + 3);
Grid.SetColumn(comboBox, column);
Grid.SetColumnSpan(comboBox, 2);
this.MainGrid.Children.Add(comboBox);
index++;
}
}
//存在问题输入文本框
for (int i = 0; i < baseDictDatas.Count; i++)
{
index = 1;
for (int j = 0; j < 1; j++) // 只保留一列检查结果
{
int column = 5 + (j * 2);
TextBox textBox = new TextBox()
{
Name = list.First(t => t.label == baseDictDatas[i].dict_label).value + index,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
//Width = (this.MainGrid.GetValidWidth())/(this.MainGrid.ColumnDefinitions.Count + 3.2)*5-10,
//Height = this.MainGrid.GetValidHeight()/ MainGrid.RowDefinitions.Count-5,
FontSize = 18,
Text = data.Where(t => t.info_name == baseDictDatas[i].dict_label && t.index == j)
.Select(t => t.bz)
.FirstOrDefault() // 显示已有的BZ值
};
textBox.TextChanged += TextBox_TextChanged;
Grid.SetRow(textBox, i + 3);
Grid.SetColumn(textBox, column);
Grid.SetColumnSpan(textBox, 6);
this.MainGrid.Children.Add(textBox);
index++;
}
}
// 添加三列空白列
for (int i = 0; i < baseDictDatas.Count; i++)
{
for (int j = 0; j < 3; j++)
{
int column = 5 + (j * 2);
TextBlock emptyBlock = new TextBlock()
{
Text = "",
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
};
Grid.SetRow(emptyBlock, i + 3);
Grid.SetColumn(emptyBlock, column);
Grid.SetColumnSpan(emptyBlock, 2);
this.MainGrid.Children.Add(emptyBlock);
}
}
}
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 = shiftCode.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 TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (isUpdate)
{
return;
}
if (sender is TextBox textBox)
{
var key = list.First(t => t.value == textBox.Name.Substring(0, textBox.Name.Length - 1)).label;
var index = int.Parse(textBox.Name.Substring(textBox.Name.Length - 1, 1));
MesTableSelfDetialModel mesTableSelfDetialModel = data.Where(t => t.info_name == key && t.index == index - 1).First();
mesTableSelfDetialModel.bz = textBox.Text;
if (string.IsNullOrEmpty(mesTableSelfDetialModel.id))
{
mesTableSelfDetialModel.id = Guid.NewGuid().ToString();
mesTableSelfDetialModel.belong_to = belong_to;
}
}
}
private void MakeHeaderData()
{
#region 画线
for (int i = 0; i < 11; i++)
{
double width = 1.0;
if (i == 0)
{
width = 1.2;
}
if (i == 1)
{
width = 1.5;
}
if (i == 2)
{
width = 6.0;
}
if (i == 3)
{
width = 0.8;
}
if (i == 4)
{
width = 0.8;
}
this.MainGrid.ColumnDefinitions.Add(new ColumnDefinition()
{
Width = new GridLength(width, GridUnitType.Star)
});
}
#region 画表格竖线
for (int i = 0; i < 11; i++)
{
// ✅ 跳过第3行索引2第6~11列索引6~11之间的竖线
if ((i < 4 || i % 2 == 1) && !(i >= 6 && i <= 11))
{
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);
}
this.MainGrid.Children.Add(line);
}
}
// 添加最后一列右边的边界线
Line boundaryLine = new Line()
{
Name = "BoundaryLine",
Stroke = Brushes.Black,
StrokeThickness = 1,
Y1 = 1,
Stretch = Stretch.Fill,
HorizontalAlignment = HorizontalAlignment.Right, // 让它靠右对齐
};
// 设置它在第 11 列(超出当前最大列)
Grid.SetColumn(boundaryLine, 11);
Grid.SetRow(boundaryLine, 0);
Grid.SetRowSpan(boundaryLine, 99); // 让它跨 99 行,确保足够高
this.MainGrid.Children.Add(boundaryLine);
#endregion
#region 画表格横线
for (int i = 0; i <= 2; i++)
{
this.MainGrid.RowDefinitions.Add(new RowDefinition()
{
Height = new GridLength(1, GridUnitType.Star)
});
// 跳过第 1 行,不画线
if (i == 1)
continue;
Line line = new Line()
{
Name = $"XLine{i}",
Stroke = Brushes.Black,
StrokeThickness = 1,
X1 = 1,
Stretch = Stretch.Fill,
VerticalAlignment = VerticalAlignment.Top,
};
Grid.SetColumn(line, 0);
Grid.SetRow(line, i);
Grid.SetColumnSpan(line, 11);
this.MainGrid.Children.Add(line);
// 仅在最后一行i == 2添加底部边界线
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
#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 = LineStr,
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);
StackPanel stackPanel = new StackPanel
{
Orientation = Orientation.Horizontal,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
};
TextBlock textBlock2 = new TextBlock()
{
Text = "日期:",
FontSize = 18,
FontWeight = FontWeights.Bold,
};
stackPanel.Children.Add(textBlock2);
var datePicker = new DatePicker()
{
FontSize = 18,
FontWeight = FontWeights.Bold,
SelectedDate = DateTime.Parse(date)
};
datePicker.SelectedDateChanged += (s, e) =>
{
date = ((DatePicker)s).SelectedDate.Value.ToString("yyyy-MM-dd");
LoadData();
};
stackPanel.Children.Add(datePicker);
// ✅ 让 StackPanel 跨两行
Grid.SetColumn(stackPanel, 2);
Grid.SetRow(stackPanel, 0);
Grid.SetRowSpan(stackPanel, 2); // ✅ 这里改成对 stackPanel 设置 RowSpan
this.MainGrid.Children.Add(stackPanel);
textBlock = new TextBlock()
{
Text = "班次",
FontSize = 18,
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Grid.SetColumn(textBlock, 3);
Grid.SetRow(textBlock, 0);
Grid.SetRowSpan(textBlock, 2);
Grid.SetColumnSpan(textBlock, 2);
this.MainGrid.Children.Add(textBlock);
int index = 1;
// 假设这是返回的集合
textBlock = new TextBlock()
{
Text = shiftName,
FontSize = 18,
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Grid.SetColumn(textBlock, 5);
Grid.SetRow(textBlock, 0);
Grid.SetRowSpan(textBlock, 2);
Grid.SetColumnSpan(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, 7);
Grid.SetRow(textBlock, 0);
Grid.SetRowSpan(textBlock, 2);
Grid.SetColumnSpan(textBlock, 2);
this.MainGrid.Children.Add(textBlock);
// 在"点检人"左侧(列索引 7添加竖线
Line lineLeft = new Line()
{
Stroke = Brushes.Black, // 你可以改成 Black
StrokeThickness = 1, // 线条加粗
Y1 = 1,
Stretch = Stretch.Fill,
HorizontalAlignment = HorizontalAlignment.Left,
};
Grid.SetColumn(lineLeft, 7);
Grid.SetRow(lineLeft, 0);
Grid.SetRowSpan(lineLeft, 2);
this.MainGrid.Children.Add(lineLeft);
// 在"点检人"右侧(列索引 8添加竖线
Line lineRight = new Line()
{
Stroke = Brushes.Black, // 你可以改成 Black
StrokeThickness = 1, // 线条加粗
Y1 = 1,
Stretch = Stretch.Fill,
HorizontalAlignment = HorizontalAlignment.Right,
};
Grid.SetColumn(lineRight, 8);
Grid.SetRow(lineRight, 0);
Grid.SetRowSpan(lineRight, 2);
this.MainGrid.Children.Add(lineRight);
textBlock = new TextBlock()
{
Text = LoginUser.UserName,
FontSize = 18,
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Grid.SetColumn(textBlock, 9);
Grid.SetRow(textBlock, 0);
Grid.SetRowSpan(textBlock, 2);
Grid.SetColumnSpan(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 < 4; 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);
}
}
textBlock = new TextBlock()
{
Text = "存在问题",
FontSize = 18,
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
// 设置到第3行索引2
Grid.SetRow(textBlock, 2);
// 从第6列索引5开始
Grid.SetColumn(textBlock, 5);
// **合并6到11列索引5到10共6列**
Grid.SetColumnSpan(textBlock, 6);
this.MainGrid.Children.Add(textBlock);
#endregion
}
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)
{
string isFinal = "0";
if (sender is Button button)
{
isFinal = button.Content.ToString() == "最终提交" ? "1" : "0";
}
if (isFinal == "1")
{
var result = MessageBox.Show("是否将报表最终提交?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result != MessageBoxResult.Yes)
{
return;
}
}
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, isFinal);
MessageBox.Show("保存成功");
LoadData();
}
private void Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}