using DataEntity.Share; using DataRWDAL; using Microsoft.Win32; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using XCommon.Log; using XCore; using XHandler.Class; using XHandler.Class.DataEx; using XHandler.View.MethodProperty; using XImagingXhandler.XDAL; namespace XHandler.View.BacteriaProperty { /// /// PickProperty.xaml 的交互逻辑 /// public partial class PickProperty : UserControl, IMethodProperty { TransferFileBll transferFileBll = new TransferFileBll(); Labware selectedLabware; public MethodChoice currMethodChoice = null; #region 全局属性变量 string isrun = ""; string status = ""; string name = ""; string label = ""; string armText = ""; string armValue = ""; string headType = ""; private int[] channels = Shared.ChannelsId; string positionText = ""; string positionValue = ""; string bacteriaText = ""; string bacteriaValue = ""; string filePath = ""; int beginLine = 0; DataTable transferDataTable = new DataTable(); string sourceLabware = ""; string sourceWell = ""; int startPos = 0; int choiceMode = 0; static int mark = 0; int curArmSelectedIndex = -1; #endregion public MethodChoice methodChoice { get; set; } public PickProperty() { InitializeComponent(); } #region 界面类构造初始化函数 public PickProperty(MethodEx method) { InitializeComponent(); mark = 0; methodChoice = new MethodChoice(); methodChoice.label = method.method_name; methodChoice.name = method.method_name; methodChoice.status = (method.isEnabled == true ? "enable" : "disable"); this.DataContext = methodChoice; List armList = DataModule.getInstance().GetDeviceArm(); cbArm.ItemsSource = armList; if (armList.Count == 2) //只有一个臂的情况下默认选中该臂 cbArm.SelectedIndex = 1; else cbArm.SelectedIndex = 0; ObservableCollection bacteriaList = DataModule.getInstance().GetBacterias(); cbBacteria.ItemsSource = bacteriaList; cbBacteria.SelectedIndex = 0; methodChoice.bacteriaText = cbBacteria.Text; methodChoice.bacteriaValue = cbBacteria.SelectedValue.ToString(); ObservableCollection choiceModeList = DataModule.getInstance().GetChoiceMode(Shared.SoftwareInformation.software_device_number); cbPickMode.ItemsSource = choiceModeList; cbPickMode.SelectedIndex = 0; List list = new List(); List lattices = DataModule.getInstance().GetLattices(); for (int i = 0; i < Shared.SoftwareInformation.columns; i++) { for (int j = 0; j < Shared.SoftwareInformation.rows; j++) { int tmp = i * Shared.SoftwareInformation.rows + j; Lattice latt = lattices[tmp]; if (latt.is_trash == 1) continue; list.Add(latt.lattice_num); } } list.Insert(0, Properties.Resources.strPleaseSelect); comboboxTablePos.ItemsSource = list; if (method.tag == null) comboboxTablePos.SelectedIndex = 0; else { comboboxTablePos.SelectedItem = methodChoice.positionText; } if (Shared.ChannelCount > 1) { tipsChannel.CanEdit = true; } methodChoice.strIndex = method.strIndex; if (method.tag != null) { methodChoice = (MethodChoice)method.tag; currMethodChoice = methodChoice; isrun = methodChoice.isrun; status = methodChoice.status; name = methodChoice.name; label = methodChoice.label; armText = methodChoice.armText; armValue = methodChoice.armValue; headType = methodChoice.headType; positionText = methodChoice.positionText; positionValue = methodChoice.positionValue; bacteriaText = methodChoice.bacteriaText; bacteriaValue = methodChoice.bacteriaValue; channels = methodChoice.channels; filePath = methodChoice.filePath; beginLine = Convert.ToInt32(methodChoice.beginLine); transferDataTable = methodChoice.transferDataTable; sourceLabware = methodChoice.sourceLabware; sourceWell = methodChoice.sourceWell; startPos = Convert.ToInt32(methodChoice.startPos); choiceMode = methodChoice.choiceMode; } } #endregion #region 臂下拉选择事件 private void cbArm_SelectionChanged(object sender, SelectionChangedEventArgs e) { // 臂未选择 if (cbArm.SelectedIndex < 0 || cbArm.SelectedIndex == 0) { methodChoice.armText = ""; methodChoice.armValue = ""; textboxArmHead.Text = ""; tipsChannel.SetTotalChannelCount(0); tipsChannel.SelectedChannels = new List(); tipsChannel.SetSelectedChannels(); tipsChannel_SelectedChangedEvent(null, null); return; } curArmSelectedIndex = cbArm.SelectedIndex; string armName = ((DeviceArm)cbArm.SelectedItem).device_arm_name.ToString(); tipsChannel.SelectedChannels = Shared.ChannelsId.ToList(); tipsChannel.SetTotalChannelCount(Shared.ChannelCount); tipsChannel.SetSelectedChannels(); tipsChannel_SelectedChangedEvent(null, null); DeviceArm arm = cbArm.SelectedItem as DeviceArm; methodChoice.armText = arm.device_arm_name; methodChoice.armValue = arm.device_arm_id.ToString(); methodChoice.headType = arm.head_type; textboxArmHead.Text = arm.head_type; } #endregion #region 菌名称下拉选择事件 private void cbBacteria_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cbBacteria.SelectedIndex < 0) return; if (methodChoice == null) return; Bacteria bacteria = cbBacteria.SelectedItem as Bacteria; methodChoice.bacteriaValue = bacteria.bacteria_id; methodChoice.bacteriaText = bacteria.bacteria_name; } #endregion #region 加载文件按钮事件 private void btnSelectFile_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "请选择Excel文件"; dlg.FileName = string.Empty; dlg.FilterIndex = 1; dlg.RestoreDirectory = true; dlg.Filter = "excel files(*.xls)|*.xls|csv files(*.csv)|*.csv|All files(*.*)|*.*"; dlg.Multiselect = false; if (dlg.ShowDialog() == true) { string fullPath = dlg.FileName; tbExcelFile.Text = fullPath; methodChoice.filePath = fullPath; SelectFile(fullPath); } } private void tbExcelFile_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { if (!string.IsNullOrEmpty(tbExcelFile.Text.Trim())) { if (System.IO.Path.HasExtension(tbExcelFile.Text.Trim())) { if (System.IO.File.Exists(tbExcelFile.Text.Trim())) { SelectFile(tbExcelFile.Text.Trim()); } } } } } private void SelectFile(string file) { string ext = System.IO.Path.GetExtension(file); DataTable transferData = null; if (string.Compare(ext, ".csv", true) == 0) transferData = ExcelAndCsvHelper.GetDataTableFromCsvFile(file); else transferData = ExcelAndCsvHelper.GetDataTableFromExcelFile(file, true); if (transferData != null) { methodChoice.transferDataTable = transferData; dgTransferFileData.ItemsSource = transferData.DefaultView; List transferFileHeaders = transferFileBll.GetTransferFileHeaders(transferData); cbSourceBoard.ItemsSource = transferFileHeaders; cbMachineCoordinate.ItemsSource = transferFileHeaders; cbSourceBoard.SelectedIndex = 0; cbMachineCoordinate.SelectedIndex = 0; } } #endregion #region 挑选模式下拉选择事件 private void cbPickMode_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cbPickMode.SelectedIndex < 0) return; if (methodChoice == null) return; DropdownName gpd = (DropdownName)cbPickMode.SelectedItem; methodChoice.choiceMode = Convert.ToInt32(gpd.dropdown_id); } #endregion #region 设置已选择的台面数据 public void SetTableName(string tableName, Labware lb) { if (lb == null) return; if (string.IsNullOrEmpty(lb.labware_id)) return; if(string.IsNullOrEmpty(methodChoice.armValue)) { MessageBox.Show(Properties.Resources.msgPlsSelectArm, "Tips"); return; } selectedLabware = lb; List latticeList = LatticeDB.GetLatticeDataFromdb(Shared.SoftwareInformation.software_device_number, Convert.ToInt32(methodChoice.armValue)); Lattice lattice = latticeList.Find(s => s.lattice_num == tableName); if (lattice == null) { LoggerHelper.InfoLog("Error: Can't find lattice with lattice_num=" + tableName); return; } comboboxTablePos.SelectedItem = tableName; methodChoice.positionText = tableName; methodChoice.positionValue = lattice.lattice_id; methodChoice.labwareText = lb.labware_name; methodChoice.labwareValue = lb.labware_id; } #endregion #region 台面下拉选择事件 private void comboboxTablePos_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (mark == 0) { } else { if (comboboxTablePos.SelectedItem == null) return; string name = comboboxTablePos.SelectedItem as string; SetTableName(name, selectedLabware); } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 方法标签文件更改事件 private void tbxCommandLabel_TextChanged(object sender, TextChangedEventArgs e) { try { if (mark == 0) { } else { methodChoice.label = tbxCommandLabel.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 方法名称更改事件 private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e) { try { if (mark == 0) { } else { methodChoice.name = tbxCommandName.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 开始行更改事件 private void tbxbeginLine_TextChanged(object sender, TextChangedEventArgs e) { try { if (mark == 0) { } else { methodChoice.beginLine = tbxbeginLine.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 皿坐标列名下拉更改事件 private void cbMachineCoordinate_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (mark == 0) { } else { if (cbMachineCoordinate.SelectedItem != null) { TransferFileHeader transferFileHeader = cbMachineCoordinate.SelectedItem as TransferFileHeader; methodChoice.sourceWell = transferFileHeader.header_name.ToString(); } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 来源皿列名下拉更改事件 private void cbSourceBoard_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (mark == 0) { } else { if (cbSourceBoard.SelectedItem != null) { TransferFileHeader transferFileHeader = cbSourceBoard.SelectedItem as TransferFileHeader; methodChoice.sourceLabware = transferFileHeader.header_name.ToString(); } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 开始执行行更改事件 private void tbxStartPos_TextChanged(object sender, TextChangedEventArgs e) { try { if (mark == 0) { } else { methodChoice.startPos = tbxStartPos.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 界面加载完成事件 private void UserControl_Loaded(object sender, RoutedEventArgs e) { mark += 1; try { if (mark > 1) { return; } if (!string.IsNullOrEmpty(armText)) { tbxCommandName.Text = name; cbArm.SelectedValue = armValue; cbBacteria.SelectedValue = bacteriaValue; DeviceArm arm = cbArm.SelectedItem as DeviceArm; textboxArmHead.Text = arm.head_type; // 通道 tipsChannel.SelectedChannels = channels.ToList(); tipsChannel_SelectedChangedEvent(null, null); comboboxTablePos.SelectedItem = positionText; dgTransferFileData.ItemsSource = transferDataTable.DefaultView; tbExcelFile.Text = filePath; //更新所有下拉列表 List transferFileHeaders = transferFileBll.GetTransferFileHeaders(transferDataTable); cbSourceBoard.ItemsSource = transferFileHeaders; cbMachineCoordinate.ItemsSource = transferFileHeaders; cbSourceBoard.Text = sourceLabware; cbMachineCoordinate.Text = sourceWell; tbxbeginLine.Text = beginLine.ToString(); tbxStartPos.Text = startPos.ToString(); cbPickMode.SelectedValue = choiceMode.ToString(); if (currMethodChoice != null) { methodChoice = currMethodChoice; } } else { cbArm.SelectedIndex = 0; DeviceArm arm = cbArm.SelectedItem as DeviceArm; if (arm != null) { textboxArmHead.Text = arm.head_type; } if (currMethodChoice != null) { methodChoice = currMethodChoice; } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion #region 可用通道鼠标选择变更事件 /// /// 可用通道鼠标选择变更事件 /// /// /// private void tipsChannel_SelectedChangedEvent(object sender, EventArgs e) { methodChoice.channels = tipsChannel.SelectedChannels.ToArray(); } #endregion } }