|
|
using CentralControl.App_Code;
|
|
|
using CommonFunc;
|
|
|
using CommonFunc.Tools;
|
|
|
using HandyControl.Controls;
|
|
|
using HandyControl.Tools.Extension;
|
|
|
using MaterialDesignThemes.Wpf;
|
|
|
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 Xceed.Wpf.Toolkit.Primitives;
|
|
|
using XGL.Data.DBService;
|
|
|
using XGL.Models;
|
|
|
using XGL.Models.Model.OrderPrepare;
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ExplorerBar;
|
|
|
using ComboBox = System.Windows.Controls.ComboBox;
|
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
using TextBox = System.Windows.Controls.TextBox;
|
|
|
namespace XGLFinishPro.Views
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// LanJu_First_Inspection_Reprot.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
public partial class LanJu_First_Inspection_Reprot : System.Windows.Window
|
|
|
{
|
|
|
private string leftbelong_to = string.Empty;
|
|
|
private string rightbelong_to = string.Empty;
|
|
|
FormingMachineService dbService = new FormingMachineService();
|
|
|
private static double LineWidth = 65;
|
|
|
private static double LineHeight = 30;
|
|
|
private static double MainLineWidth = 80;
|
|
|
private static double MainLineHeight = 50;
|
|
|
string deviceCode = Utils.GetAppSetting("DeviceCode");
|
|
|
private string LProductName = string.Empty;
|
|
|
private string product_code = string.Empty;
|
|
|
private bool isUpdate = false;
|
|
|
private List<string> DefaultTypeDic = new List<string>() { string.Empty, "√", "x" };
|
|
|
private List<MesTableSelfDetialModel> leftData;
|
|
|
private List<MesTableSelfDetialModel> rightData;
|
|
|
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 List<ConveterData> list = new List<ConveterData>();
|
|
|
private readonly List<string> _minutes = new List<string> { "00", "05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55" };
|
|
|
|
|
|
private string workId = string.Empty;
|
|
|
|
|
|
private string date = string.Empty;
|
|
|
private string shiftName = string.Empty;
|
|
|
private string shiftCode = LoginUser.ShiftCode;
|
|
|
|
|
|
public LanJu_First_Inspection_Reprot()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//this.RightNickName.Text = LoginUser.UserName;
|
|
|
this.LeftNickName.Text = LoginUser.UserName;
|
|
|
try
|
|
|
{
|
|
|
this.LeftCheckDate.SelectedDate = DateTime.Parse(LoginUser.WorkDate);
|
|
|
shiftName = dbService.GetShiftById(shiftCode);
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
//this.RightCheckDate.Text = DateTime.Parse(this.LeftCheckDate.Text).AddDays(1).ToString("yyyy/MM/dd");
|
|
|
this.LeftLine.Text = dbService.GetBaseEquipment(Utils.GetAppSetting("DeviceCode"));
|
|
|
//this.RightLine.Text = this.LeftLine.Text;
|
|
|
product_code = string.Empty;
|
|
|
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
LoadData();
|
|
|
}
|
|
|
|
|
|
private void LoadData(bool addLine = false)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
isUpdate = true;
|
|
|
list.Clear();
|
|
|
DataTable dataTable = dbService.GetProOrderWorkorder(workId);
|
|
|
if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
{
|
|
|
Console.WriteLine("[Error] 未获取到工单信息,workId: " + workId);
|
|
|
LogHelper.instance.log.Error("[Error] 未获取到工单信息,workId: " + workId);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (dataTable.Rows.Count > 0)
|
|
|
{
|
|
|
product_code = dataTable.Rows[0]["product_code"].ToString();
|
|
|
}
|
|
|
}
|
|
|
var leftHearList = dbService.GetSelfCheckInfo("first_inspection_left").OrderBy(t => t.dict_sort).ToList();
|
|
|
if (leftHearList == null || !leftHearList.Any())
|
|
|
{
|
|
|
Console.WriteLine("[Error] 未获取到左侧检查信息。");
|
|
|
LogHelper.instance.log.Error("[Error] 未获取到左侧检查信息。");
|
|
|
}
|
|
|
var leftMainList = dbService.GetSelfCheckInfo("first_inspection_left_info").OrderBy(t => t.dict_sort).ToList();
|
|
|
if (leftMainList == null || !leftMainList.Any())
|
|
|
{
|
|
|
Console.WriteLine("[Error] 未获取到左侧主检查信息。");
|
|
|
LogHelper.instance.log.Error("[Error] 未获取到左侧主检查信息。");
|
|
|
}
|
|
|
var rightHearList = dbService.GetSelfCheckInfo("first_inspection_right").OrderBy(t => t.dict_sort).ToList();
|
|
|
if (rightHearList == null || !rightHearList.Any())
|
|
|
{
|
|
|
Console.WriteLine("[Error] 未获取到右侧检查信息。");
|
|
|
LogHelper.instance.log.Error("[Error] 未获取到右侧检查信息。");
|
|
|
}
|
|
|
var rightMainList = dbService.GetSelfCheckInfo("first_inspection_right_info").OrderBy(t => t.dict_sort).ToList();
|
|
|
if (rightMainList == null || !rightMainList.Any())
|
|
|
{
|
|
|
Console.WriteLine("[Error] 未获取到右侧主检查信息。");
|
|
|
LogHelper.instance.log.Error("[Error] 未获取到右侧主检查信息。");
|
|
|
}
|
|
|
|
|
|
GetMesTableSeft();
|
|
|
leftData = dbService.GetMesTableSelfDetial(leftbelong_to, 6);
|
|
|
if (leftData == null || !leftData.Any())
|
|
|
{
|
|
|
Console.WriteLine("[Error] 未获取到左侧详细检查数据。");
|
|
|
LogHelper.instance.log.Error("[Error] 未获取到左侧详细检查数据。");
|
|
|
}
|
|
|
rightData = dbService.GetMesTableSelfDetial(rightbelong_to, 6);
|
|
|
if (rightData == null || !rightData.Any())
|
|
|
{
|
|
|
Console.WriteLine("[Error] 未获取到右侧详细检查数据。");
|
|
|
LogHelper.instance.log.Error("[Error] 未获取到右侧详细检查数据。");
|
|
|
}
|
|
|
|
|
|
if (addLine)
|
|
|
{
|
|
|
int leftLine = leftData.Max(t => t.table_line) + 1;
|
|
|
leftData.ForEach(t => { t.index++; });
|
|
|
leftData.Insert(0, new MesTableSelfDetialModel() { index = 0 });
|
|
|
leftData.RemoveAll(t => t.index == 6);
|
|
|
|
|
|
int rightLine = rightData.Max(t => t.table_line) + 1;
|
|
|
rightData.ForEach(t => { t.index++; });
|
|
|
rightData.Insert(0, new MesTableSelfDetialModel() { index = 0 });
|
|
|
rightData.RemoveAll(t => t.index == 6);
|
|
|
}
|
|
|
|
|
|
for (var i = 0; i < 7; i++)
|
|
|
{
|
|
|
foreach (var item in leftHearList)
|
|
|
{
|
|
|
bool hasData = leftData.Where(t => t.index == i && t.info_name == item.dict_label).Any();
|
|
|
if (!hasData)
|
|
|
{
|
|
|
int tableLine = 0;
|
|
|
MesTableSelfDetialModel mesTableSelfDetialModel = leftData.Where(t => t.index == i).Where(t => t.table_line != 0).FirstOrDefault();
|
|
|
if (mesTableSelfDetialModel != null)
|
|
|
{
|
|
|
tableLine = mesTableSelfDetialModel.table_line;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
tableLine = leftData.Max(t => t.table_line) + 1;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
leftData.Add(new MesTableSelfDetialModel()
|
|
|
{
|
|
|
index = i,
|
|
|
table_line = tableLine,
|
|
|
info_name = item.dict_label,
|
|
|
info_code = leftHearList.FirstOrDefault(t => t.dict_label == item.dict_label)?.dict_code,
|
|
|
});
|
|
|
list.Add(new ConveterData()
|
|
|
{
|
|
|
label = item.dict_label,
|
|
|
value = MD5Provider.Hash(item.dict_label),
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach (var item in rightHearList)
|
|
|
{
|
|
|
bool hasData = rightData.Where(t => t.index == i && t.info_name == item.dict_label).Any();
|
|
|
if (!hasData)
|
|
|
{
|
|
|
int tableLine = 0;
|
|
|
MesTableSelfDetialModel mesTableSelfDetialModel = rightData.Where(t => t.index == i).Where(t => t.table_line != 0).FirstOrDefault();
|
|
|
if (mesTableSelfDetialModel != null)
|
|
|
{
|
|
|
tableLine = mesTableSelfDetialModel.table_line;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
tableLine = rightData.Max(t => t.table_line) + 1;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
rightData.Add(new MesTableSelfDetialModel()
|
|
|
{
|
|
|
index = i,
|
|
|
table_line = tableLine,
|
|
|
info_name = item.dict_label,
|
|
|
info_code = rightHearList.FirstOrDefault(t => t.dict_label == item.dict_label)?.dict_code,
|
|
|
});
|
|
|
list.Add(new ConveterData()
|
|
|
{
|
|
|
label = item.dict_label,
|
|
|
value = MD5Provider.Hash(item.dict_label),
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
var leftDic = new Dictionary<string, Dictionary<int, MesTableSelfDetialModel>>();
|
|
|
foreach (var item in leftData)
|
|
|
{
|
|
|
if (item.info_name == null || leftDic.Keys.Contains(item.info_name))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
var mesTableSelfDetialModels = leftData.Where(t => t.info_name == item.info_name).ToList();
|
|
|
var dictionary = mesTableSelfDetialModels.ToDictionary(t => t.index);
|
|
|
leftDic.Add(item.info_name, dictionary);
|
|
|
}
|
|
|
|
|
|
var rightDic = new Dictionary<string, Dictionary<int, MesTableSelfDetialModel>>();
|
|
|
foreach (var item in rightData)
|
|
|
{
|
|
|
if (item.info_name == null || rightDic.Keys.Contains(item.info_name))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
var mesTableSelfDetialModels = rightData.Where(t => t.info_name == item.info_name).ToList();
|
|
|
var dictionary = mesTableSelfDetialModels.ToDictionary(t => t.index);
|
|
|
rightDic.Add(item.info_name, dictionary);
|
|
|
}
|
|
|
list.ForEach(t => t.value.Remove(9, 11));
|
|
|
list.ForEach(t => t.value = t.value.Insert(0, "A"));
|
|
|
MakeHeaderData(this.Left);
|
|
|
//MakeHeaderData(this.Right);
|
|
|
|
|
|
var leftTypeDic = new Dictionary<string, List<string>>();
|
|
|
foreach (var item in leftHearList)
|
|
|
{
|
|
|
var defaultDic = leftMainList.Where(t => string.IsNullOrEmpty(t.remark)).Select(t => t.dict_value).ToList();
|
|
|
var typeDic = leftMainList.Where(t => t.remark == item.dict_label).Select(t => t.dict_value).ToList();
|
|
|
defaultDic.AddRange(typeDic);
|
|
|
if (!leftTypeDic.ContainsKey(item.dict_label))
|
|
|
{
|
|
|
leftTypeDic.Add(item.dict_label, defaultDic);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var rightTypeDic = new Dictionary<string, List<string>>();
|
|
|
foreach (var item in rightHearList)
|
|
|
{
|
|
|
var defaultDic = rightMainList.Where(t => string.IsNullOrEmpty(t.remark)).Select(t => t.dict_value).ToList();
|
|
|
var typeDic = rightMainList.Where(t => t.remark == item.dict_label).Select(t => t.dict_value).ToList();
|
|
|
defaultDic.AddRange(typeDic);
|
|
|
if (!rightTypeDic.ContainsKey(item.dict_label))
|
|
|
{
|
|
|
rightTypeDic.Add(item.dict_label, defaultDic);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
MainValueData(this.Left, leftHearList, leftDic, leftTypeDic);
|
|
|
//MainValueData(this.Right, rightHearList, rightDic, rightTypeDic);
|
|
|
|
|
|
UpdateUi(this.Left);
|
|
|
//UpdateUi(this.Right);
|
|
|
isUpdate = false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.instance.log.Error("[Error] 加载数据异常!" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
private MesTableSelf leftmesTableSelf;
|
|
|
private void GetMesTableSeft()
|
|
|
{
|
|
|
leftmesTableSelf = dbService.GetMesTableSelf(deviceCode, LProductName, this.LeftCheckDate.Text, "ConversionReportLeft"+ shiftName);
|
|
|
if (leftmesTableSelf == null)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(LProductName))
|
|
|
{
|
|
|
leftmesTableSelf = new MesTableSelf()
|
|
|
{
|
|
|
id = Guid.NewGuid().ToString(),
|
|
|
line_code = deviceCode,
|
|
|
product_name = LProductName,
|
|
|
check_date = this.LeftCheckDate.Text,
|
|
|
product_code = product_code,
|
|
|
factory_code = Utils.GetAppSetting("SiteCode"),
|
|
|
del_flag = "0",
|
|
|
product_date = this.LeftCheckDate.Text,
|
|
|
bz = string.Empty,
|
|
|
report_name = "ConversionReportLeft"+ shiftName
|
|
|
};
|
|
|
}
|
|
|
dbService.InsertMesTableSelf(leftmesTableSelf);
|
|
|
}
|
|
|
//7c9070ea-75f9-42ad-bf6b-3638f4745141
|
|
|
leftbelong_to = leftmesTableSelf.id;
|
|
|
|
|
|
//MesTableSelf rightmesTableSelf = dbService.GetMesTableSelf(deviceCode, LProductName, this.RightCheckDate.Text, "ConversionReportRight");
|
|
|
//if (rightmesTableSelf == null)
|
|
|
//{
|
|
|
// rightmesTableSelf = new MesTableSelf()
|
|
|
// {
|
|
|
// id = Guid.NewGuid().ToString(),
|
|
|
// line_code = deviceCode,
|
|
|
// product_name = LProductName,
|
|
|
// //check_date = this.RightCheckDate.Text,
|
|
|
// product_code = product_code,
|
|
|
// factory_code = Utils.GetAppSetting("SiteCode"),
|
|
|
// del_flag = "0",
|
|
|
// //product_date = this.RightCheckDate.Text,
|
|
|
// bz = string.Empty,
|
|
|
// report_name = "ConversionReportRight"
|
|
|
// };
|
|
|
// dbService.InsertMesTableSelf(rightmesTableSelf);
|
|
|
//}
|
|
|
//rightbelong_to = rightmesTableSelf.id;
|
|
|
}
|
|
|
|
|
|
private void MainValueData(Grid grid, List<BaseDictData> HearListDic, Dictionary<string, Dictionary<int, MesTableSelfDetialModel>> data, Dictionary<string, List<string>> typeList)
|
|
|
{
|
|
|
List<string> hearList = HearListDic.Select(t => t.dict_label).ToList();
|
|
|
for (var i = 2; i < hearList.Count + 2; i++)
|
|
|
{
|
|
|
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1.0, GridUnitType.Star) });
|
|
|
var line = new Line()
|
|
|
{
|
|
|
Name = $"{grid.Name}XLine{i + 1}",
|
|
|
X1 = 1.0,
|
|
|
VerticalAlignment = VerticalAlignment.Bottom,
|
|
|
Stroke = Brushes.Black,
|
|
|
StrokeThickness = 1.0,
|
|
|
Stretch = Stretch.Fill,
|
|
|
};
|
|
|
if (i == 2)
|
|
|
{
|
|
|
var line2 = new Line()
|
|
|
{
|
|
|
Name = $"{grid.Name}XLine{i}",
|
|
|
X1 = 1.0,
|
|
|
VerticalAlignment = VerticalAlignment.Top,
|
|
|
Stroke = Brushes.Black,
|
|
|
StrokeThickness = 1.0,
|
|
|
Stretch = Stretch.Fill,
|
|
|
};
|
|
|
Grid.SetRow(line2, i);
|
|
|
Grid.SetColumnSpan(line2, 99);
|
|
|
grid.Children.Add(line2);
|
|
|
}
|
|
|
Grid.SetRow(line, i);
|
|
|
Grid.SetColumnSpan(line, 99);
|
|
|
grid.Children.Add(line);
|
|
|
string key = hearList.ToList()[i - 2];
|
|
|
|
|
|
bool hasType = typeList.TryGetValue(key, out var type);
|
|
|
if (data.TryGetValue(key, out var value))
|
|
|
{
|
|
|
for (var j = 0; j < value.Count; j++)
|
|
|
{
|
|
|
if (j > 6)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
string Hour = "00";
|
|
|
string Minute = "00";
|
|
|
try
|
|
|
{
|
|
|
if (value[j].check_time_s != null)
|
|
|
{
|
|
|
string[] startTime = value[j].check_time_s.Split(':');
|
|
|
Hour = startTime[0];
|
|
|
Minute = startTime[1];
|
|
|
}
|
|
|
|
|
|
foreach (var item in grid.Children)
|
|
|
{
|
|
|
if (item is StackPanel stackPanel)
|
|
|
{
|
|
|
foreach (var child in stackPanel.Children)
|
|
|
{
|
|
|
if (child is ComboBox comboBox2)
|
|
|
{
|
|
|
if (comboBox2.Name.Contains($"Hour{j + 1}") && comboBox2.SelectedIndex == 0)
|
|
|
{
|
|
|
comboBox2.SelectedItem = Hour;
|
|
|
}
|
|
|
if (comboBox2.Name.Contains($"Minute{j + 1}") && comboBox2.SelectedIndex == 0)
|
|
|
{
|
|
|
comboBox2.SelectedItem = Minute;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
var textBlock = new TextBlock()
|
|
|
{
|
|
|
Text = key.Replace("___", "/"),
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
FontSize = 20,
|
|
|
TextWrapping = TextWrapping.Wrap,
|
|
|
};
|
|
|
Grid.SetRow(textBlock, i);
|
|
|
Grid.SetColumn(textBlock, 0);
|
|
|
grid.Children.Add(textBlock);
|
|
|
}
|
|
|
for (var j = 1; j <= 6; j++)
|
|
|
{
|
|
|
string SelectedItem = string.Empty;
|
|
|
if (value.TryGetValue(j - 1, out var model))
|
|
|
{
|
|
|
SelectedItem = model.check_result;
|
|
|
}
|
|
|
if (key.Contains("灌装量"))
|
|
|
{
|
|
|
TextBox textBox = new TextBox()
|
|
|
{
|
|
|
Name = $"{grid.Name}{list.First(t => t.label == key).value}{j}",
|
|
|
Text = SelectedItem,
|
|
|
Width = MainLineWidth,
|
|
|
Height = MainLineHeight,
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
FontSize = 20,
|
|
|
TextWrapping = TextWrapping.Wrap,
|
|
|
AcceptsReturn = true,
|
|
|
};
|
|
|
textBox.LostFocus += TextBox_LostFocus;
|
|
|
Grid.SetRow(textBox, i);
|
|
|
Grid.SetColumn(textBox, j);
|
|
|
grid.Children.Add(textBox);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ComboBox comboBox = new ComboBox()
|
|
|
{
|
|
|
Name = $"{grid.Name}{list.First(t => t.label == key).value}{j}",
|
|
|
ItemsSource = hasType ? type.Distinct() : DefaultTypeDic.Distinct(),
|
|
|
SelectedItem = SelectedItem,
|
|
|
Width = MainLineWidth,
|
|
|
Height = MainLineHeight
|
|
|
};
|
|
|
comboBox.SelectionChanged += SelectionChanged;
|
|
|
Grid.SetRow(comboBox, i);
|
|
|
Grid.SetColumn(comboBox, j);
|
|
|
grid.Children.Add(comboBox);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<string> batchCodes = dbService.GetBatchCode(workId);
|
|
|
foreach (var item in this.Left.Children)
|
|
|
{
|
|
|
if (item is ComboBox box)
|
|
|
{
|
|
|
string label = list.Where(t => t.value == box.Name.Substring(0, box.Name.Length - 1).Replace("Left", "").Replace("Right", "")).First().label;
|
|
|
if (label.Contains("日期码") || label.Contains("生产批号"))
|
|
|
{
|
|
|
box.ItemsSource = batchCodes.Distinct();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach (var item in this.Right.Children)
|
|
|
{
|
|
|
if (item is ComboBox box)
|
|
|
{
|
|
|
string v = box.Name.Substring(0, box.Name.Length - 1);
|
|
|
string label = list.Where(t => t.value == box.Name.Substring(0, box.Name.Length - 1).Replace("Left", "").Replace("Right", "")).First().label;
|
|
|
if (label.Contains("日期码") || label.Contains("生产批号"))
|
|
|
{
|
|
|
box.ItemsSource = batchCodes.Distinct();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (isUpdate)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
if (sender is TextBox textBox)
|
|
|
{
|
|
|
string name = textBox.Name.Replace("Left", "").Replace("Right", "");
|
|
|
string index = name.Substring(name.Length - 1, 1);
|
|
|
string key = list.First(t => t.value == name.Substring(0, name.Length - 1)).label;
|
|
|
var mesTableSelfDetialModel = leftData.Where(t => t.info_name == key && t.index == int.Parse(index) - 1).FirstOrDefault();
|
|
|
if (mesTableSelfDetialModel != null)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(mesTableSelfDetialModel.id))
|
|
|
{
|
|
|
mesTableSelfDetialModel.id = Guid.NewGuid().ToString();
|
|
|
mesTableSelfDetialModel.belong_to = leftbelong_to;
|
|
|
}
|
|
|
mesTableSelfDetialModel.check_result = textBox.Text;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void UpdateUi(Grid grid)
|
|
|
{
|
|
|
Dispatcher.Invoke(() =>
|
|
|
{
|
|
|
double width = grid.GetValidWidth();
|
|
|
double widthCount = grid.ColumnDefinitions.Count;
|
|
|
var lineWidth = width / widthCount;
|
|
|
double height = grid.GetValidHeight();
|
|
|
double heightCount = grid.RowDefinitions.Count;
|
|
|
var lineHeight = height / heightCount;
|
|
|
foreach (var item in grid.Children)
|
|
|
{
|
|
|
if (item is ComboBox comboBox)
|
|
|
{
|
|
|
comboBox.Width = lineWidth - 10;
|
|
|
comboBox.Height = lineHeight - 10;
|
|
|
if (string.IsNullOrEmpty(LProductName))
|
|
|
{
|
|
|
comboBox.IsEnabled = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
comboBox.IsEnabled = !leftmesTableSelf.IsFinal;
|
|
|
}
|
|
|
}
|
|
|
if (item is TextBox textBox)
|
|
|
{
|
|
|
textBox.Width = lineWidth - 10;
|
|
|
textBox.Height = lineHeight - 10;
|
|
|
if (string.IsNullOrEmpty(LProductName))
|
|
|
{
|
|
|
textBox.IsReadOnly = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
textBox.IsEnabled = !leftmesTableSelf.IsFinal;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
this.Commit.Visibility = leftmesTableSelf.IsFinal ? Visibility.Collapsed : Visibility.Visible;
|
|
|
this.IsFinalSubmit.Visibility = this.Commit.Visibility;
|
|
|
this.Add.Visibility = this.Commit.Visibility;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void ToggleButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (((ToggleButton)sender).TemplatedParent is ComboBox comboBox)
|
|
|
{
|
|
|
comboBox.IsDropDownOpen = !comboBox.IsDropDownOpen;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void MakeHeaderData(Grid grid)
|
|
|
{
|
|
|
grid.Children.Clear();
|
|
|
grid.ColumnDefinitions.Clear();
|
|
|
grid.RowDefinitions.Clear();
|
|
|
for (var i = 0; i <= 7; i++)
|
|
|
{
|
|
|
if (i != 7)
|
|
|
{
|
|
|
grid.ColumnDefinitions.Add(new ColumnDefinition()
|
|
|
{
|
|
|
Width = new GridLength(1.0, GridUnitType.Star)
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (var i = 0; i <= 2; i++)
|
|
|
{
|
|
|
if (i != 2)
|
|
|
{
|
|
|
grid.RowDefinitions.Add(new RowDefinition()
|
|
|
{
|
|
|
Height = new GridLength(1.0, GridUnitType.Star)
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
for (var i = 0; i <= 7; i++)
|
|
|
{
|
|
|
var line = new Line()
|
|
|
{
|
|
|
Name = $"{grid.Name}YLine{i}",
|
|
|
Y1 = 1.0,
|
|
|
HorizontalAlignment = i == 7 ? HorizontalAlignment.Right : HorizontalAlignment.Left,
|
|
|
Stroke = Brushes.Black,
|
|
|
StrokeThickness = 1.0,
|
|
|
Stretch = Stretch.Fill,
|
|
|
};
|
|
|
Grid.SetColumn(line, i);
|
|
|
Grid.SetRowSpan(line, 99);
|
|
|
grid.Children.Add(line);
|
|
|
}
|
|
|
for (var i = 0; i <= 2; i++)
|
|
|
{
|
|
|
var line = new Line()
|
|
|
{
|
|
|
Name = $"{grid.Name}XLine{i}",
|
|
|
X1 = 1.0,
|
|
|
VerticalAlignment = i == 2 ? VerticalAlignment.Bottom : VerticalAlignment.Top,
|
|
|
Stroke = Brushes.Black,
|
|
|
StrokeThickness = 1.0,
|
|
|
Stretch = Stretch.Fill,
|
|
|
};
|
|
|
Grid.SetRow(line, i);
|
|
|
if (i == 1)
|
|
|
{
|
|
|
Grid.SetColumn(line, 1);
|
|
|
Grid.SetColumnSpan(line, 99);
|
|
|
}
|
|
|
|
|
|
Grid.SetColumnSpan(line, 99);
|
|
|
grid.Children.Add(line);
|
|
|
}
|
|
|
|
|
|
var productBlock = new TextBlock()
|
|
|
{
|
|
|
Text = "项目",
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
FontSize = 20
|
|
|
};
|
|
|
Grid.SetColumn(productBlock, 0);
|
|
|
Grid.SetRow(productBlock, 0);
|
|
|
Grid.SetRowSpan(productBlock, 2);
|
|
|
grid.Children.Add(productBlock);
|
|
|
|
|
|
double timeHeight = LineHeight;
|
|
|
double timeWidth = LineWidth;
|
|
|
for (var i = 1; i <= 6; i++)
|
|
|
{
|
|
|
var hearBlock = new TextBlock()
|
|
|
{
|
|
|
Text = "检查时间",
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
FontSize = 20
|
|
|
};
|
|
|
Grid.SetColumn(hearBlock, i);
|
|
|
Grid.SetRow(hearBlock, 0);
|
|
|
grid.Children.Add(hearBlock);
|
|
|
#region 头部
|
|
|
var stackPanel = new StackPanel()
|
|
|
{
|
|
|
Orientation = Orientation.Horizontal,
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
Margin = new Thickness(0, 0, 0, 0)
|
|
|
};
|
|
|
|
|
|
var startHour = new ComboBox()
|
|
|
{
|
|
|
Name = $"{grid.Name}Hour{i}",
|
|
|
ItemsSource = _hours,
|
|
|
SelectedIndex = 0,
|
|
|
FontSize = 15,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
Margin = new Thickness(0, 0, 0, 0)
|
|
|
};
|
|
|
startHour.SelectionChanged += SelectionChanged;
|
|
|
stackPanel.Children.Add(startHour);
|
|
|
|
|
|
var startBlock = new TextBlock()
|
|
|
{
|
|
|
Text = ":",
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
FontSize = 20
|
|
|
};
|
|
|
stackPanel.Children.Add(startBlock);
|
|
|
|
|
|
var startMinute = new ComboBox()
|
|
|
{
|
|
|
Name = $"{grid.Name}Minute{i}",
|
|
|
ItemsSource = _minutes,
|
|
|
SelectedIndex = 0,
|
|
|
FontSize = 15,
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
Margin = new Thickness(0, 0, 0, 0)
|
|
|
};
|
|
|
startMinute.SelectionChanged += SelectionChanged;
|
|
|
stackPanel.Children.Add(startMinute);
|
|
|
|
|
|
Grid.SetColumn(stackPanel, i);
|
|
|
Grid.SetRow(stackPanel, 1);
|
|
|
grid.Children.Add(stackPanel);
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (isUpdate)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
if (sender is ComboBox comboBox)
|
|
|
{
|
|
|
string name = comboBox.Name.Replace("Left", "").Replace("Right", "");
|
|
|
string index = name.Substring(name.Length - 1, 1);
|
|
|
string Hour = "00";
|
|
|
string Minute = "00";
|
|
|
if (comboBox.Name.Contains("Hour") || comboBox.Name.Contains("Minute"))
|
|
|
{
|
|
|
if (comboBox.Name.Contains("Left"))
|
|
|
{
|
|
|
foreach (var item in Left.Children)
|
|
|
{
|
|
|
if (item is StackPanel stackPanel)
|
|
|
{
|
|
|
foreach (var child in stackPanel.Children)
|
|
|
{
|
|
|
if (child is ComboBox childComboBox)
|
|
|
{
|
|
|
if (childComboBox.Name.Contains("Hour") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
Hour = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
else if (childComboBox.Name.Contains("Minute") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
Minute = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
leftData.Where(t => t.index == int.Parse(index) - 1).ForEach(t =>
|
|
|
{
|
|
|
t.check_time_s = Hour + ":" + Minute;
|
|
|
});
|
|
|
}
|
|
|
else if (comboBox.Name.Contains("Left"))
|
|
|
{
|
|
|
foreach (var item in Right.Children)
|
|
|
{
|
|
|
if (item is StackPanel stackPanel)
|
|
|
{
|
|
|
foreach (var child in stackPanel.Children)
|
|
|
{
|
|
|
if (child is ComboBox childComboBox)
|
|
|
{
|
|
|
if (childComboBox.Name.Contains("Hour") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
Hour = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
else if (childComboBox.Name.Contains("Minute") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
Minute = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
rightData.Where(t => t.index == int.Parse(index) - 1).ForEach(t =>
|
|
|
{
|
|
|
t.check_time_s = Hour + ":" + Minute;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string key = list.First(t => t.value == name.Substring(0, name.Length - 1)).label;
|
|
|
if (comboBox.Name.Contains("Left"))
|
|
|
{
|
|
|
var mesTableSelfDetialModel = leftData.Where(t => t.info_name == key && t.index == int.Parse(index) - 1).FirstOrDefault();
|
|
|
if (mesTableSelfDetialModel != null)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(mesTableSelfDetialModel.id))
|
|
|
{
|
|
|
mesTableSelfDetialModel.id = Guid.NewGuid().ToString();
|
|
|
mesTableSelfDetialModel.belong_to = leftbelong_to;
|
|
|
}
|
|
|
mesTableSelfDetialModel.check_result = comboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
string hour = string.Empty;
|
|
|
string minute = string.Empty;
|
|
|
foreach (var item in Left.Children)
|
|
|
{
|
|
|
if (item is StackPanel stackPanel)
|
|
|
{
|
|
|
foreach (var child in stackPanel.Children)
|
|
|
{
|
|
|
if (child is ComboBox childComboBox)
|
|
|
{
|
|
|
if (childComboBox.Name.Contains("Hour") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
hour = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
else if (childComboBox.Name.Contains("Minute") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
minute = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
leftData.Where(t => t.index == int.Parse(index) - 1).ForEach(t =>
|
|
|
{
|
|
|
t.check_time_s = hour + ":" + minute;
|
|
|
});
|
|
|
}
|
|
|
else if (comboBox.Name.Contains("Left"))
|
|
|
{
|
|
|
var mesTableSelfDetialModel = rightData.Where(t => t.info_name == key && t.index == int.Parse(index)).FirstOrDefault();
|
|
|
if (mesTableSelfDetialModel != null)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(mesTableSelfDetialModel.id))
|
|
|
{
|
|
|
mesTableSelfDetialModel.id = Guid.NewGuid().ToString();
|
|
|
mesTableSelfDetialModel.belong_to = rightbelong_to;
|
|
|
}
|
|
|
mesTableSelfDetialModel.check_result = comboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
string hour = string.Empty;
|
|
|
string minute = string.Empty;
|
|
|
foreach (var item in Left.Children)
|
|
|
{
|
|
|
if (item is StackPanel stackPanel)
|
|
|
{
|
|
|
foreach (var child in stackPanel.Children)
|
|
|
{
|
|
|
if (child is ComboBox childComboBox)
|
|
|
{
|
|
|
if (childComboBox.Name.Contains("Hour") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
hour = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
else if (childComboBox.Name.Contains("Minute") && childComboBox.Name.Contains(index))
|
|
|
{
|
|
|
minute = childComboBox.SelectedItem.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
rightData.Where(t => t.index == int.Parse(index) - 1).ForEach(t =>
|
|
|
{
|
|
|
t.check_time_s = hour + ":" + minute;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
{
|
|
|
bool isSuccess = false;
|
|
|
string isFinal = "0";
|
|
|
if (sender is Button button)
|
|
|
{
|
|
|
isFinal = button.Content == "最终提交" ? "1" : "0";
|
|
|
}
|
|
|
if (isFinal == "1")
|
|
|
{
|
|
|
var result = MessageBox.Show("是否将报表最终提交?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
if(result != MessageBoxResult.Yes)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var tempLeftData = dbService.GetMesTableSelfDetial(leftbelong_to, 6);
|
|
|
var tempRightData = dbService.GetMesTableSelfDetial(rightbelong_to, 6);
|
|
|
leftData.ForEach(t =>
|
|
|
{
|
|
|
t.info_name = t.info_name.Replace("___", "/");
|
|
|
});
|
|
|
rightData.ForEach(t =>
|
|
|
{
|
|
|
t.info_name = t.info_name.Replace("___", "/");
|
|
|
});
|
|
|
foreach (var item in leftData)
|
|
|
{
|
|
|
int resultLeft = 0;
|
|
|
if (item.table_line == 0)
|
|
|
{
|
|
|
item.table_line = 1;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(item.id))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
var mesTableSelfDetialModel = tempLeftData.FirstOrDefault(t => t.id == item.id);
|
|
|
if (mesTableSelfDetialModel == null)
|
|
|
{
|
|
|
resultLeft = dbService.InsertMesTableSelfDetial(item);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
resultLeft = dbService.UpdateMesTableSelfDetial(item);
|
|
|
}
|
|
|
if (resultLeft > 0)
|
|
|
{
|
|
|
isSuccess = true;
|
|
|
}
|
|
|
}
|
|
|
foreach (var item in rightData)
|
|
|
{
|
|
|
int resultRight = 0;
|
|
|
if (item.table_line == 0)
|
|
|
{
|
|
|
item.table_line = 1;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(item.id))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
var mesTableSelfDetialModel = tempRightData.FirstOrDefault(t => t.id == item.id);
|
|
|
if (mesTableSelfDetialModel == null)
|
|
|
{
|
|
|
resultRight = dbService.InsertMesTableSelfDetial(item);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
resultRight = dbService.UpdateMesTableSelfDetial(item);
|
|
|
}
|
|
|
if (resultRight > 0)
|
|
|
{
|
|
|
isSuccess = true;
|
|
|
}
|
|
|
}
|
|
|
dbService.UpdateMesTableSelf(leftbelong_to, "", LoginUser.UserName, isFinal);
|
|
|
//dbService.UpdateMesTableSelf(rightbelong_to, "", LoginUser.UserName);
|
|
|
if (isSuccess)
|
|
|
{
|
|
|
MessageBox.Show("保存成功!");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("保存失败!");
|
|
|
LogHelper.instance.log.Error("[Error] 保存失败!");
|
|
|
}
|
|
|
|
|
|
LoadData();
|
|
|
}
|
|
|
|
|
|
private void Close_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
this.Close();
|
|
|
}
|
|
|
|
|
|
//private void LeftCheckDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
|
|
|
//{
|
|
|
// if (sender is DatePicker date)
|
|
|
// {
|
|
|
// this.LeftCheckDate.Text = date.SelectedDate.Value.ToString("yyyy/MM/dd");
|
|
|
// //this.RightCheckDate.Text = DateTime.Parse(this.LeftCheckDate.Text).AddDays(1).ToString("yyyy/MM/dd");
|
|
|
// LoadData();
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
private void LeftCheckDate_SelectedDateChanged_1(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
this.date = this.LeftCheckDate.SelectedDate.Value.ToString("yyyy-MM-dd");
|
|
|
DataTable dataTable = dbService.GetProOrderWorkorder(deviceCode, date);
|
|
|
List<OrderWork> orderWorks = new List<OrderWork>();
|
|
|
if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
{
|
|
|
LogHelper.instance.log.Error("没有查询到工单信息!");
|
|
|
MessageBox.Show("没有查询到工单信息!");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (DataRow row in dataTable.Rows)
|
|
|
{
|
|
|
if (orderWorks.Where(t => t.WorkName == row["product_name"].ToString()).Any())
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
orderWorks.Add(new OrderWork()
|
|
|
{
|
|
|
WorkId = row["workorder_id"].ToString(),
|
|
|
WorkName = row["product_name"].ToString(),
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
this.LeftProductName.ItemsSource = orderWorks.Distinct();
|
|
|
this.LeftProductName.Items.Refresh();
|
|
|
this.workId = string.Empty;
|
|
|
this.LProductName = string.Empty;
|
|
|
LoadData();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.instance.log.Error("首检记录获取工单出现异常!" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void LeftProductName_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
if (sender is ComboBox comboBox)
|
|
|
{
|
|
|
if (comboBox.SelectedItem is OrderWork orderWork)
|
|
|
{
|
|
|
this.workId = orderWork.WorkId;
|
|
|
this.LProductName = orderWork.WorkName;
|
|
|
}
|
|
|
}
|
|
|
LoadData();
|
|
|
}
|
|
|
}
|
|
|
}
|