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.

286 lines
11 KiB
C#

using CommonFunc;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
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 System.Windows.Threading;
using XGL.Data;
using XGL.Models;
using XGL.UControl;
using Thrift.Protocol;
using Thrift.Server;
using Thrift.Transport;
using CentralControl.BaseData;
using CentralControl.DBDAO;
using XGL.Thrift;
using System.Threading;
using System.Speech.Synthesis;
namespace XGL.FormItem
{
/// <summary>
/// FormHandUp.xaml 的交互逻辑
/// </summary>
public partial class FormBoxBoard : Window
{
string ScanStr { get; set; }
string ScanNo { get; set; }
SpeechSynthesizer speech = new SpeechSynthesizer();
List<LineCatchArea> listCatchAreas = new List<LineCatchArea>();
List<CarRealInfo> listCarreals = new List<CarRealInfo>();
/// <summary>
/// 时间刷新
/// </summary>
private DispatcherTimer dispatcherTimer;
/// <summary>
/// UI数据刷新
/// </summary>
private DispatcherTimer RefreshUITimer;
/// <summary>
/// 上件区小车列表
/// </summary>
ObservableCollection<basedata_carrealinfoModel> Cars = new ObservableCollection<basedata_carrealinfoModel>();
public FormBoxBoard()
{
InitializeComponent();
ScanStr = "";
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(1000);
dispatcherTimer.Tick += DispatcherTimer_Tick;
dispatcherTimer.IsEnabled = true;
dispatcherTimer.Start();
RefreshUITimer = new DispatcherTimer();
RefreshUITimer.Interval = TimeSpan.FromSeconds(2);
RefreshUITimer.Tick += RefreshUITimer_Tick;
RefreshUITimer.IsEnabled = true;
RefreshUITimer.Start();
txtTime.Content = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
BindLocatorViewList();
}
catch (Exception ex)
{
MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod();
Common.Log.Error(method.DeclaringType.FullName + "-" + method.Name + "\r\n" + ex.Message + "\r\n" + ex.StackTrace);
}
}
/// <summary>
/// 绑定左侧库位图形列表
/// </summary>
private void BindLocatorViewList()
{
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
DataTable dt = DBService.GetLocatorMaterialGroup("");
List<CarInfo> list1 = new List<CarInfo>();
List<CarInfo> list2 = new List<CarInfo>();
int i = 1;
foreach (DataRow dr in dt.Rows)
{
CarInfo car = new CarInfo();
//car.MaterialNo = dr["MaterialNo"].ToString();
//car.MaterialBarNo = dr["MaterialBarNo"].ToString();
//car.CarNo = dr["carno"].ToString();
if (i <= 10)
{
car.LineAreaId = i;
car.MaterialNo = dr["materialno"].ToString();
car.MaterialBarNo = dr["MaterialBarNo"].ToString();
//car.OptDt = dr["total"].ToString();
car.CarNo = dr["number"].ToString();
list1.Add(car);
}
else
{
car.LineAreaId = i;
car.MaterialNo = dr["materialno"].ToString();
car.MaterialBarNo = dr["MaterialBarNo"].ToString();
//car.OptDt = dr["total"].ToString();
car.CarNo = dr["number"].ToString();
list2.Add(car);
}
i++;
}
gridMaterial1.ItemsSource = list1;
gridMaterial1.Items.Refresh();
gridMaterial2.ItemsSource = list2;
gridMaterial2.Items.Refresh();
}));
}
private void RefreshUITimer_Tick(object sender, EventArgs e)
{
try
{
BindLocatorViewList();
}
catch (Exception ex)
{
CommonFunc.Logger logger = new CommonFunc.Logger();
logger.Error("系统刷新数据上件点异常:" + ex.Message + ex.StackTrace);
}
}
private void DispatcherTimer_Tick(object sender, EventArgs e)
{
txtTime.Content = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
}
private void btnExit_Click(object sender, RoutedEventArgs e)
{
try
{
if (MessageBox.Show("是否确认关闭当前窗口", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No)
{
return;
}
else
{
Environment.Exit(System.Environment.ExitCode);
}
}
catch (Exception ex)
{
MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod();
Common.Log.Error(method.DeclaringType.FullName + "-" + method.Name + "\r\n" + ex.Message + "\r\n" + ex.StackTrace);
}
}
private void GridMaterial_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + 1;
var carinfo = e.Row.Item as CarInfo;
if (carinfo.MaterialNo == this.ScanNo)
{
e.Row.Background = new SolidColorBrush(Color.FromRgb(0x1f, 0xb0, 0x8e));
}
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
try
{
if (ScanStr == "111111111")
{
DBService.ClearScanOffMaterialDetailList();
lblScanMaterialNo.Content = ScanStr;
lblScanMaterialNm.Content = "清空扫描数据成功";
return;
}
//speech.SpeakAsync("成功");
if (ScanStr.Length >= 9)
{
string materialno = ScanStr.Substring(0, 9);
string serno = ScanStr.Substring(ScanStr.Length - 3, 3);
int sercode = 0;
//为了测试 解锁
if(true) // if (int.TryParse(serno, out sercode))
{
MaterialInfo materinfo = DBService.GetMaterialInfoList(" and materialno='" + materialno + "'").FirstOrDefault();
if (materinfo != null)
{
//启用 和关闭 重复扫描出库信息
OffLineMaterialList offmal = DBService.getOffLineMaterialLists(" and productbarno='" + ScanStr.Trim() + "' ").FirstOrDefault();
if(false) // if (offmal != null)
{
lblScanMaterialNo.Content = ScanStr;
lblScanMaterialNm.Content = "重复扫描的条码";
}
else
{
lblScanMaterialNo.Content = ScanStr;
lblScanMaterialNm.Content = materinfo.MaterialNm;
ScanNo = materialno;
OffLineMaterialList offmaterial = new OffLineMaterialList();
offmaterial.Number = 1;
offmaterial.ProductBarNo = ScanStr;
offmaterial.CreateTime = DateTime.Now;
offmaterial.MaterialNo = materialno;
offmaterial.MaterialDes = materinfo.MaterialNm;
offmaterial.IsOver = 0;
DBService.AddOffLineMaterialHistoryList(offmaterial);
DBService.AddOffLineMaterialDetailList(offmaterial);
DBService.AddOffLineMaterialList(offmaterial);
speech.SpeakAsync("成功");
}
}
else
{
lblScanMaterialNo.Content = ScanStr;
lblScanMaterialNm.Content = "未匹配到符合的成品型号";
}
}
else
{
lblScanMaterialNo.Content = ScanStr;
lblScanMaterialNm.Content = "扫描条码格式不正确,后4位为数字";
}
}
else
{
lblScanMaterialNo.Content = ScanStr;
lblScanMaterialNm.Content = "未扫描到正确的条码";
}
}
catch (Exception ex)
{
Logger logger = new Logger();
logger.Error("扫描箱体异常:" + ex.Message + ex.StackTrace);
}
ScanStr = "";
}
else if (e.Key.ToString().Length == 2)
{
ScanStr += e.Key.ToString().Trim('D');
}
else if (e.Key.ToString().Length == 1)
{
ScanStr += e.Key.ToString();
}
}
}
}