using DataEntity.Share;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.Data;
|
using System.Diagnostics;
|
using System.Linq;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Input;
|
using System.Windows.Media;
|
using XImagingXhandler.XDAL;
|
using DataGrid = System.Windows.Controls.DataGrid;
|
using TextBox = System.Windows.Controls.TextBox;
|
|
namespace XHandler.View.MethodProperty
|
{
|
/// <summary>
|
/// 补充目标板时输入条码界面
|
/// </summary>
|
public partial class SetBarcodeDlgForAddConsumables : Window
|
{
|
/// <summary>
|
/// 运行界面
|
/// </summary>
|
public RunWnd launchView = null;
|
|
/// <summary>
|
/// 文件涂布数据
|
/// </summary>
|
public DataTable dtCoatingFile = null;
|
|
/// <summary>
|
/// 目标板编号开始替换Index
|
/// </summary>
|
public int StartIndex = 0;
|
|
/// <summary>
|
/// 输入的条码数据
|
/// </summary>
|
private ObservableCollection<InputBarcode> inputDatas = new ObservableCollection<InputBarcode>();
|
|
/// <summary>
|
/// 提示消息内容
|
/// </summary>
|
private string msg = string.Empty;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="msg"></param>
|
public SetBarcodeDlgForAddConsumables(string strMsg)
|
{
|
InitializeComponent();
|
msg = strMsg;
|
this.Owner = (Window)Shared.Main;
|
}
|
|
/// <summary>
|
/// 初始化事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
{
|
// 初始化控件
|
InitControl(msg);
|
}
|
|
private bool IsOnBatch(bool isNewPlateBatch, int iChoiceIndex, int iStartIndex)
|
{
|
if (isNewPlateBatch)
|
{
|
if ((launchView.choiceTimes == 1 || launchView.choiceTimes == 2) && (iChoiceIndex == StartIndex))
|
{
|
return true;
|
}
|
else if (launchView.choiceTimes == 2 && (iChoiceIndex == StartIndex + 1))
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
else
|
{
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
/// <param name="msg"></param>
|
private void InitControl(string msg)
|
{
|
List<string> lstLatticeNum = new List<string>();
|
if (dtCoatingFile != null)
|
{
|
for (int iChoiceIndex = StartIndex; iChoiceIndex < dtCoatingFile.Rows.Count; iChoiceIndex++)
|
{
|
string strDesPlateName = dtCoatingFile.Rows[iChoiceIndex]["TargetB"].ToString();
|
string strTargetBarcode = dtCoatingFile.Rows[iChoiceIndex]["TargetBarcode"].ToString();
|
bool isNewPlateBatch = bool.Parse(dtCoatingFile.Rows[iChoiceIndex]["IsNewPlateBatch"].ToString());
|
if (!IsOnBatch(isNewPlateBatch, iChoiceIndex, StartIndex))
|
{
|
break;
|
}
|
|
if (!lstLatticeNum.Contains(strDesPlateName))
|
{
|
lstLatticeNum.Add(strDesPlateName);
|
inputDatas.Add(new InputBarcode()
|
{
|
lattice_num = strDesPlateName,
|
targetplate_barcode = strTargetBarcode
|
});
|
}
|
}
|
}
|
|
dgInputBarcode.DataContext = inputDatas;
|
dgInputBarcode.ItemsSource = inputDatas;
|
textblockMsg.Text = msg;
|
}
|
|
/// <summary>
|
/// 确定
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnOK_Click(object sender, RoutedEventArgs e)
|
{
|
if (dtCoatingFile != null)
|
{
|
for (int iChoiceIndex = StartIndex; iChoiceIndex < dtCoatingFile.Rows.Count; iChoiceIndex++)
|
{
|
string strDesPlateName = dtCoatingFile.Rows[iChoiceIndex]["TargetB"].ToString();
|
bool isNewPlateBatch = bool.Parse(dtCoatingFile.Rows[iChoiceIndex]["IsNewPlateBatch"].ToString());
|
if (!IsOnBatch(isNewPlateBatch, iChoiceIndex, StartIndex))
|
{
|
break;
|
}
|
|
InputBarcode brcodeItem = inputDatas.FirstOrDefault(it => it.lattice_num.Equals(strDesPlateName));
|
if (brcodeItem != null)
|
{
|
dtCoatingFile.Rows[iChoiceIndex]["TargetBarcode"] = brcodeItem.targetplate_barcode;
|
}
|
}
|
}
|
|
DialogResult = true;
|
}
|
|
/// <summary>
|
/// 关闭
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
{
|
DialogResult = false;
|
}
|
|
#region DataGrid事件
|
private void dgCoatingData_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
|
{
|
//如果点击了放弃按钮或ESC
|
if (e.EditAction == DataGridEditAction.Cancel)
|
{
|
return;
|
}
|
//获取编辑模式显示的元素,因为使用了模板,因此这里是ContentPresenter类型
|
ContentPresenter cp = e.EditingElement as ContentPresenter;
|
if (cp != null && VisualTreeHelper.GetChildrenCount(cp) > 0)
|
{
|
//找到编辑框
|
TextBox textBox = VisualTreeHelper.GetChild(cp, 0) as TextBox;
|
//如果找到
|
if (textBox != null)
|
{
|
var a = inputDatas;
|
|
var dataGrid = sender as DataGrid;
|
dataGrid.BeginEdit();
|
}
|
}
|
}
|
|
private void DataGridCell_PreviewMouseMove(object sender, MouseEventArgs e)
|
{
|
if (e.OriginalSource is System.Windows.Shapes.Path)
|
{
|
Cursor = Cursors.Cross;
|
}
|
else
|
{
|
Cursor = Cursors.Arrow;
|
}
|
}
|
|
private void DataGridCell_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
{
|
Debug.WriteLine("Double click");
|
DataGridCell cell = sender as DataGridCell;
|
if ((cell.Column.DisplayIndex == 1) || (cell.Column.DisplayIndex == 2) || (cell.Column.DisplayIndex == 5)
|
|| (cell.Column.DisplayIndex == 6) || (cell.Column.DisplayIndex == 7))
|
{
|
cell.Column.IsReadOnly = false;
|
}
|
cell.Focus();
|
cell.IsSelected = true;
|
dgInputBarcode.BeginEdit();
|
e.Handled = true;
|
}
|
#endregion
|
|
#region 拖动窗体
|
/// <summary>
|
/// 拖动窗体
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
|
{
|
if (e.ChangedButton == MouseButton.Left)
|
{
|
this.DragMove();
|
}
|
}
|
#endregion
|
}
|
}
|