using CommonFunc;
using CommonFunc.Tools;
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;
namespace XGLFinishPro.Views
{
///
/// FirstInspectionReport.xaml 的交互逻辑
///
public partial class FirstInspectionReport : Window
{
string deviceCode = Utils.GetAppSetting("DeviceCode");
public List ReportModels = new List();
FormingMachineService formingMachineService = new FormingMachineService();
public static 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"
};
public static List Minutes = new List()
{
"00","05","10","15","20","25","30","35","40","45","50","55"
};
public FirstInspectionReport()
{
InitializeComponent();
}
private void ComboBox_Change(object sender, SelectionChangedEventArgs e)
{
try
{
if (sender is ComboBox comboBox)
{
string proName = comboBox.Name.Substring(0, comboBox.Name.Length - 2);
string index = comboBox.Name.Substring(comboBox.Name.Length - 1, 1);
int currentIndex = int.Parse(index) - 1;
var firstInspectionReportModel = ReportModels[currentIndex];
firstInspectionReportModel.WorkDateLeft = CheckDate1.Text;
firstInspectionReportModel.UserName = LoginUser.UserName;
firstInspectionReportModel.WorkDateRight = CheckDate2.Text;
//根据proName的值获取对应的属性,并且赋值
switch (proName)
{
case "InspectionTime":
firstInspectionReportModel.InspectionTime = comboBox.SelectedItem?.ToString();
break;
case "CheckTimeLeft":
string time = "";
if (FindName("HourLeft" + index) is ComboBoxItem item)
{
time += item.Content.ToString();
time += ":";
}
if (FindName("MintueLeft" + index) is ComboBoxItem item2)
{
time += item2.Content.ToString();
}
firstInspectionReportModel.CheckTimeLeft = time;
break;
case "CheckTimeRight":
string time2 = "";
if (FindName("HourRight" + index) is ComboBoxItem item3)
{
time2 += item3.Content.ToString();
time2 += ":";
}
if (FindName("MintueRight" + index) is ComboBoxItem item4)
{
time2 += item4.Content.ToString();
}
firstInspectionReportModel.CheckTimeRight = time2;
break;
case "MaterialLeft":
firstInspectionReportModel.MaterialLeft = comboBox.SelectedItem?.ToString();
break;
case "MaterialRight":
firstInspectionReportModel.MaterialRight = comboBox.SelectedItem?.ToString();
break;
case "AppearanceLeft":
firstInspectionReportModel.AppearanceLeft = comboBox.SelectedItem?.ToString();
break;
case "AppearanceRight":
firstInspectionReportModel.AppearanceRight = comboBox.SelectedItem?.ToString();
break;
case "StampLeft":
firstInspectionReportModel.StampLeft = comboBox.SelectedItem?.ToString();
break;
case "StampRight":
firstInspectionReportModel.StampRight = comboBox.SelectedItem?.ToString();
break;
case "SprayLeft":
firstInspectionReportModel.SprayLeft = comboBox.SelectedItem?.ToString();
break;
case "SprayRight":
firstInspectionReportModel.SprayRight = comboBox.SelectedItem?.ToString();
break;
case "PackageLeft":
firstInspectionReportModel.PackageLeft = comboBox.SelectedItem?.ToString();
break;
case "PackageRight":
firstInspectionReportModel.PackageRight = comboBox.SelectedItem?.ToString();
break;
case "GenerateLeft":
firstInspectionReportModel.GenerateLeft = comboBox.SelectedItem?.ToString();
break;
case "GenerateRight":
firstInspectionReportModel.GenerateRight = comboBox.SelectedItem?.ToString();
break;
case "DeviceLeft":
firstInspectionReportModel.DeviceLeft = comboBox.SelectedItem?.ToString();
break;
case "DeviceRight":
firstInspectionReportModel.DeviceRight = comboBox.SelectedItem?.ToString();
break;
case "WorkLeft":
firstInspectionReportModel.WorkLeft = comboBox.SelectedItem?.ToString();
break;
case "WorkRight":
firstInspectionReportModel.WorkRight = comboBox.SelectedItem?.ToString();
break;
case "OtherLeft":
firstInspectionReportModel.OtherLeft = comboBox.SelectedItem?.ToString();
break;
case "OtherRight":
firstInspectionReportModel.OtherRight = comboBox.SelectedItem?.ToString();
break;
case "OverLeft":
firstInspectionReportModel.OverLeft = comboBox.SelectedItem?.ToString();
break;
case "OverRight":
firstInspectionReportModel.OverRight = comboBox.SelectedItem?.ToString();
break;
}
}
}
catch
{
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
foreach (var item in this.MainGrid.Children)
{
if (item is StackPanel panel)
{
foreach (var item2 in panel.Children)
{
if (item2 is ComboBox comboBox)
{
if (comboBox.Name.Contains("Hour"))
{
comboBox.ItemsSource = Hours;
}
else if (comboBox.Name.Contains("Mintue"))
{
comboBox.ItemsSource = Minutes;
}
}
}
}
else
{
if (item is ComboBox comboBox)
{
comboBox.ItemsSource = new List { string.Empty, "√", "×" };
}
}
CheckDate1.Text = LoginUser.WorkDate;
CheckDate2.Text = DateTime.Parse(LoginUser.WorkDate).AddDays(1).ToString("yyyy-MM-dd");
}
}
catch
{
}
GetData();
}
private void GetData()
{
ReportModels = formingMachineService.GetFirstInspectionReportModels(LoginUser.UserName, LoginUser.WorkDate);
DataTable dataTable = formingMachineService.GetProOrderWorkorder(deviceCode, LoginUser.WorkDate);
if (dataTable != null)
{
this.ProductName1.Text = dataTable.Rows[0]["product_name"].ToString();
this.ProductName2.Text = dataTable.Rows[0]["product_name"].ToString();
}
UpdateUI();
}
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
if (((ToggleButton)sender).TemplatedParent is ComboBox comboBox)
{
comboBox.IsDropDownOpen = !comboBox.IsDropDownOpen;
}
}
private void UpdateUI()
{
try
{
NickName1.Text = ReportModels[0].UserName;
NickName2.Text = ReportModels[1].UserName;
for (int i = 0; i < ReportModels.Count; i++)
{
if (FindName("MaterialLeft") is ComboBox box)
{
box.SelectedItem = ReportModels[i].MaterialLeft;
}
if (FindName("MaterialRight") is ComboBox box2)
{
box2.SelectedItem = ReportModels[i].MaterialRight;
}
if (FindName("AppearanceLeft") is ComboBox box3)
{
box3.SelectedItem = ReportModels[i].AppearanceLeft;
}
if (FindName("AppearanceRight") is ComboBox box4)
{
box4.SelectedItem = ReportModels[i].AppearanceRight;
}
if (FindName("StampLeft") is ComboBox box5)
{
box5.SelectedItem = ReportModels[i].StampLeft;
}
if (FindName("StampRight") is ComboBox box6)
{
box6.SelectedItem = ReportModels[i].StampRight;
}
if (FindName("SprayLeft") is ComboBox box7)
{
box7.SelectedItem = ReportModels[i].SprayLeft;
}
if (FindName("SprayRight") is ComboBox box8)
{
box8.SelectedItem = ReportModels[i].SprayRight;
}
if (FindName("PackageLeft") is ComboBox box9)
{
box9.SelectedItem = ReportModels[i].PackageLeft;
}
if (FindName("PackageRight") is ComboBox box10)
{
box10.SelectedItem = ReportModels[i].PackageRight;
}
if (FindName("GenerateLeft") is ComboBox box11)
{
box11.SelectedItem = ReportModels[i].GenerateLeft;
}
if (FindName("GenerateRight") is ComboBox box12)
{
box12.SelectedItem = ReportModels[i].GenerateRight;
}
if (FindName("DeviceLeft") is ComboBox box13)
{
box13.SelectedItem = ReportModels[i].DeviceLeft;
}
if (FindName("DeviceRight") is ComboBox box14)
{
box14.SelectedItem = ReportModels[i].DeviceRight;
}
if (FindName("WorkLeft") is ComboBox box15)
{
box15.SelectedItem = ReportModels[i].WorkLeft;
}
if (FindName("WorkRight") is ComboBox box16)
{
box16.SelectedItem = ReportModels[i].WorkRight;
}
if (FindName("OtherLeft") is ComboBox box17)
{
box17.SelectedItem = ReportModels[i].OtherLeft;
}
if (FindName("OtherRight") is ComboBox box18)
{
box18.SelectedItem = ReportModels[i].OtherRight;
}
if (FindName("OverLeft") is ComboBox box19)
{
box19.SelectedItem = ReportModels[i].OverLeft;
}
if (FindName("OverRight") is ComboBox box20)
{
box20.SelectedItem = ReportModels[i].OverRight;
}
if (FindName("InspectionTime") is ComboBox box21)
{
box21.SelectedItem = ReportModels[i].InspectionTime;
}
if (FindName("CheckTimeLeft") is ComboBox box22)
{
string[] times = ReportModels[i].CheckTimeLeft.Split(':');
if (times.Length == 2)
{
if (FindName("HourLeft" + (i + 1)) is ComboBoxItem item)
{
item.Content = times[0];
}
if (FindName("MintueLeft" + (i + 1)) is ComboBoxItem item2)
{
item2.Content = times[1];
}
}
}
if (FindName("CheckTimeRight") is ComboBox box23)
{
string[] times = ReportModels[i].CheckTimeRight.Split(':');
if (times.Length == 2)
{
if (FindName("HourRight" + (i + 1)) is ComboBoxItem item3)
{
item3.Content = times[0];
}
if (FindName("MintueRight" + (i + 1)) is ComboBoxItem item4)
{
item4.Content = times[1];
}
}
}
}
}
catch
{
}
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
GetData();
}
private void Add_Click(object sender, RoutedEventArgs e)
{
ReportModels = formingMachineService.GetFirstInspectionReportModels(LoginUser.UserName, LoginUser.WorkDate);
ReportModels.Insert(0, new FirstInspectionReportModel());
ReportModels.Remove(ReportModels.Last());
UpdateUI();
}
private void Submit_Click(object sender, RoutedEventArgs e)
{
try
{
foreach (var item in ReportModels)
{
if (string.IsNullOrEmpty(item.Id))
{
if (!string.IsNullOrEmpty(item.UserName))
{
formingMachineService.AddFirstInspectionReportModel(item);
}
}
else
{
formingMachineService.UpdateFirstInspectionReportModel(item);
}
}
MessageBox.Show("提交成功!");
}
catch
{
}
GetData();
}
private void Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}