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 { /// /// 补充目标板时输入条码界面 /// public partial class SetBarcodeDlgForAddConsumables : Window { /// /// 运行界面 /// public RunWnd launchView = null; /// /// 文件涂布数据 /// public DataTable dtCoatingFile = null; /// /// 目标板编号开始替换Index /// public int StartIndex = 0; /// /// 输入的条码数据 /// private ObservableCollection inputDatas = new ObservableCollection(); /// /// 提示消息内容 /// private string msg = string.Empty; /// /// 构造函数 /// /// public SetBarcodeDlgForAddConsumables(string strMsg) { InitializeComponent(); msg = strMsg; this.Owner = (Window)Shared.Main; } /// /// 初始化事件 /// /// /// 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; } } /// /// 初始化控件 /// /// private void InitControl(string msg) { List lstLatticeNum = new List(); 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; } /// /// 确定 /// /// /// 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; } /// /// 关闭 /// /// /// 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 拖动窗体 /// /// 拖动窗体 /// /// /// private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { this.DragMove(); } } #endregion } }