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.

433 lines
16 KiB
C#

using CommonFunc;
using CommonFunc.Tools;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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
{
/// <summary>
/// SelfInspectionForm.xaml 的交互逻辑
/// </summary>
public partial class SelfInspectionForm : Window
{
bool canRefresh = true;
bool isUpdate = false;
List<SelfInspectionModel> models = new List<SelfInspectionModel>();
string deviceCode = Utils.GetAppSetting("DeviceCode");
FormingMachineService formingMachineService = new FormingMachineService();
public static 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"
};
public static List<string> Minutes = new List<string>()
{
"00","05","10","15","20","25","30","35","40","45","50","55"
};
public ObservableCollection<string> ComboItems = new ObservableCollection<string>() { "", "√", "x" };
public SelfInspectionForm()
{
InitializeComponent();
this.NickName.Text = LoginUser.UserName;
this.CheckDate.Text = LoginUser.WorkDate;
try
{
this.Line.Text = formingMachineService.GetBaseEquipment(Utils.GetAppSetting("SiteCode"));
}
catch
{
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
foreach (var item in this.MainGrid.Children)
{
if (item is ComboBox box)
{
box.ItemsSource = ComboItems;
box.SelectedIndex = 0;
}
if (item is StackPanel panel)
{
foreach (var child in panel.Children)
{
if (child is ComboBox box2)
{
if (box2.Name.Contains("Hour"))
{
box2.ItemsSource = Hours;
box2.SelectedIndex = 0;
}
else if (box2.Name.Contains("Mintue"))
{
box2.ItemsSource = Minutes;
box2.SelectedIndex = 0;
}
}
}
}
}
canRefresh = true;
GetData();
}
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
var comboBox = ((ToggleButton)sender).TemplatedParent as ComboBox;
if (comboBox != null)
{
comboBox.IsDropDownOpen = !comboBox.IsDropDownOpen;
}
}
private void Close_Click(object sender, RoutedEventArgs e)
{
if (!canRefresh)
{
MessageBoxResult messageBoxResult = MessageBox.Show("还有未保存的数据,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.No)
{
return;
}
}
this.Close();
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
GetData();
}
private void GetData()
{
if (!canRefresh)
{
MessageBoxResult messageBoxResult = MessageBox.Show("还有未保存的数据,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.No)
{
return;
}
}
DataTable dataTable = formingMachineService.GetProOrderWorkorder(deviceCode, LoginUser.WorkDate);
if (dataTable != null)
{
this.ProductName.Text=dataTable.Rows[0]["product_name"].ToString();
models = formingMachineService.GetSelfInspections(deviceCode, LoginUser.WorkDate, LoginUser.UserName, dataTable.Rows[0]["workorder_id"].ToString());
UpdateUI(models);
}
else
{
MessageBox.Show($"当前产线{deviceCode}未查询到订单");
this.Close();
}
}
private void UpdateUI(List<SelfInspectionModel> models)
{
isUpdate = true;
try
{
if (models.Count < 7)
{
for (int i = 0; i < 7 - models.Count; i++)
{
models.Add(new SelfInspectionModel());
}
}
else
{
while (models.Count > 7)
{
models.RemoveAt(models.Count - 1);
}
}
ExceptionHandling.Text = models[0].Reason;
for (int i = 0; i < 7; i++)
{
if (FindName($"MissingTie{i + 1}") is ComboBox box)
{
box.SelectedItem = models[i].MissingTie;
}
if (FindName($"Package{i + 1}") is ComboBox box2)
{
box2.SelectedItem = models[i].Package;
}
if (FindName($"DateCode{i + 1}") is ComboBox box3)
{
box3.SelectedItem = models[i].DateCode;
}
if (FindName($"PackageGood{i + 1}") is ComboBox box4)
{
box4.SelectedItem = models[i].PackageGood;
}
if (FindName($"LeakProduct{i + 1}") is ComboBox box5)
{
box5.SelectedItem = models[i].LeakProduct;
}
if (FindName($"NormalOpen{i + 1}") is ComboBox box6)
{
box6.SelectedItem = models[i].NormalOpen;
}
if (FindName($"BoxQuantity{i + 1}") is ComboBox box7)
{
box7.SelectedItem = models[i].BoxQuantity;
}
if (FindName($"Other{i + 1}") is ComboBox box8)
{
box8.SelectedItem = models[i].Other;
}
try
{
string[] strings = models[i].InspectionTime.Split('-');
if (strings.Length == 2)
{
if (FindName($"StartHour{i + 1}") is ComboBox box9)
{
box9.SelectedItem = strings[0].Split(':')[0];
}
if (FindName($"StartMintues{i + 1}") is ComboBox box10)
{
box10.SelectedItem = strings[0].Split(':')[1];
}
if (FindName($"EndHour{i + 1}") is ComboBox box11)
{
box11.SelectedItem = strings[1].Split(':')[0];
}
if (FindName($"EndMintues{i + 1}") is ComboBox box12)
{
box12.SelectedItem = strings[1].Split(':')[1];
}
}
else
{
if (FindName($"StartHour{i + 1}") is ComboBox box9)
{
box9.SelectedIndex = 0;
}
if (FindName($"StartMintues{i + 1}") is ComboBox box10)
{
box10.SelectedIndex = 0;
}
if (FindName($"EndHour{i + 1}") is ComboBox box11)
{
box11.SelectedIndex = 0;
}
if (FindName($"EndMintues{i + 1}") is ComboBox box12)
{
box12.SelectedIndex = 0;
}
}
}
catch
{
if (FindName($"StartHour{i + 1}") is ComboBox box9)
{
box9.SelectedIndex = 0;
}
if (FindName($"StartMintues{i + 1}") is ComboBox box10)
{
box10.SelectedIndex = 0;
}
if (FindName($"EndHour{i + 1}") is ComboBox box11)
{
box11.SelectedIndex = 0;
}
if (FindName($"EndMintues{i + 1}") is ComboBox box12)
{
box12.SelectedIndex = 0;
}
}
}
}
catch
{
}
//DataTable dt = formingMachineService.GetProOrderWorkorder(deviceCode, LoginUser.WorkDate);
//if (dt == null || dt.Rows.Count == 0)
//{
// MessageBox.Show($"当前产线{deviceCode}未查询到订单");
// return;
//}
//this.ProductName.Text = dt.Rows[0]["product_name"]?.ToString();
isUpdate = false;
}
private void Add_Click(object sender, RoutedEventArgs e)
{
if (!canRefresh)
{
MessageBoxResult messageBoxResult = MessageBox.Show("还有未保存的数据,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.No)
{
return;
}
}
DataTable dataTable = formingMachineService.GetProOrderWorkorder(deviceCode, LoginUser.WorkDate);
if (dataTable != null)
{
this.ProductName.Text = dataTable.Rows[0]["product_name"].ToString();
models.Insert(0, new SelfInspectionModel());
models.Remove(models.Last());
models = formingMachineService.GetSelfInspections(deviceCode, LoginUser.WorkDate, LoginUser.UserName, dataTable.Rows[0]["workorder_id"].ToString());
UpdateUI(models);
}
else
{
MessageBox.Show($"当前产线{deviceCode}未查询到订单");
this.Close();
}
}
private void Submit_Click(object sender, RoutedEventArgs e)
{
models[0].Reason = this.ExceptionHandling.Text;
foreach (var item in models)
{
if (string.IsNullOrEmpty(item.Id))
{
if (!string.IsNullOrEmpty(item.Inspector))
{
item.Id = Guid.NewGuid().ToString();
item.deviceCode = deviceCode;
item.workDate = LoginUser.WorkDate;
formingMachineService.AddSelfInspection(item);
}
}
else
{
formingMachineService.EditSelfInspection(item);
}
}
canRefresh = true;
MessageBox.Show("提交成功");
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
}
private void MissingTie1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (isUpdate)
{
return;
}
try
{
if (sender is ComboBox box)
{
try
{
canRefresh = false;
string indexStr = box.Name.Substring(box.Name.Length - 1, 1);
int index = int.Parse(indexStr);
string name = box.Name.Substring(0, box.Name.Length - 1);
if (name.Contains("Hour") || name.Contains("Mintue"))
{
if (box.SelectedItem != null)
{
string time = "";
if (FindName("StartHour" + indexStr) is ComboBox box1)
{
time += box1.SelectedItem;
time += ":";
}
if (FindName("StartMintues" + indexStr) is ComboBox box2)
{
time += box2.SelectedItem;
time += "-";
}
if (FindName("EndHour" + indexStr) is ComboBox box3)
{
time += box3.SelectedItem;
time += ":";
}
if (FindName("EndMintues" + indexStr) is ComboBox box4)
{
time += (box4.SelectedItem);
}
models[index - 1].InspectionTime = time;
}
}
else
{
if (string.IsNullOrEmpty(models[index - 1].Inspector))
{
models[index - 1].Inspector = LoginUser.UserName;
}
if (name == "MissingTie")
{
models[index - 1].MissingTie = box.SelectedItem?.ToString();
}
else if (name == "Package")
{
models[index - 1].Package = box.SelectedItem?.ToString();
}
else if (name == "DateCode")
{
models[index - 1].DateCode = box.SelectedItem?.ToString();
}
else if (name == "PackageGood")
{
models[index - 1].PackageGood = box.SelectedItem?.ToString();
}
else if (name == "LeakProduct")
{
models[index - 1].LeakProduct = box.SelectedItem?.ToString();
}
else if (name == "NormalOpen")
{
models[index - 1].NormalOpen = box.SelectedItem?.ToString();
}
else if (name == "BoxQuantity")
{
models[index - 1].BoxQuantity = box.SelectedItem?.ToString();
}
else if (name == "Other")
{
models[index - 1].Other = box.SelectedItem?.ToString();
}
}
}
catch
{
}
}
}
catch
{
}
}
}
}