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.

213 lines
7.2 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.Configuration;
namespace XGL.FormItem
{
/// <summary>
/// FormHandUp.xaml 的交互逻辑
/// </summary>
public partial class FormDownLineBoard1 : Window
{
PlcHelper plchelper = null;
string ipaddress = "";
List<LineCatchArea> listCatchAreas = new List<LineCatchArea>();
List<CarRealInfo> listCarreals = new List<CarRealInfo>();
/// <summary>
/// 前面跳过的数量, 因为两个站台之间的数量有差异
/// </summary>
int ShowPageNumber = 5;
/// <summary>
/// 时间刷新
/// </summary>
private DispatcherTimer dispatcherTimer;
/// <summary>
/// UI数据刷新
/// </summary>
private DispatcherTimer RefreshUITimer;
/// <summary>
/// 上件区小车列表
/// </summary>
ObservableCollection<basedata_carrealinfoModel> Cars = new ObservableCollection<basedata_carrealinfoModel>();
public FormDownLineBoard1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
this.ipaddress = ConfigurationManager.AppSettings["plcIp"];
this.plchelper = new PlcHelper();
bool connectionState = this.plchelper.Connection(ipaddress);
if (!connectionState)
{
MessageBox.Show("PLC连接失败,重新连接");
return;
}
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(1000);
dispatcherTimer.Tick += DispatcherTimer_Tick;
dispatcherTimer.IsEnabled = true;
dispatcherTimer.Start();
RefreshUITimer = new DispatcherTimer();
RefreshUITimer.Interval = TimeSpan.FromSeconds(15);
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()
{
PlcSetting plcdata = new PlcSetting();
plcdata.PlcValueLength = "2";
plcdata.PlcAddress = "DB10.DBW78";
object ret= plchelper.Read(plcdata);
if(ret!=null)
{
this.ShowPageNumber = Convert.ToInt32(ret);
}
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
DataTable dt = DBService.GetOffLocatorMaterialView("");
List<CarInfo> list = new List<CarInfo>();
int i = 0;
string carno = "";
foreach (DataRow dr in dt.Rows)
{
CarInfo car = new CarInfo();
car.MaterialNo = dr["TrayCode"].ToString();
car.MaterialBarNo = dr["ProductBarNo"].ToString();
car.CarNo = dr["carcode"].ToString();
if (dr["HadNumber"] == DBNull.Value)
{
car.LineAreaId = 0;
}
else
{
car.LineAreaId = Convert.ToInt32(dr["HadNumber"]);
}
//car.OptDt = Convert.ToDateTime(dr["createtime"]).ToString("yyyy-MM-dd HH:mm:ss");
if(carno!=car.CarNo)
{
i++;
}
carno = car.CarNo;
if (i > this.ShowPageNumber)
{
list.Add(car);
}
}
gridMaterial.ItemsSource = list;
gridMaterial.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.LineAreaId > 0)
{
e.Row.Background = new SolidColorBrush(Colors.IndianRed);
}
}
}
}