using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; 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.Navigation; using System.Windows.Shapes; using XHandler.Class.DataEx; using XImagingXhandler.XDAL; using static XHandler.Controls.MultiComboBox; using XCore; using System.Runtime.Remoting.Channels; using XHandler.Controls; using XHandler.View.MethodProperty; using XCommon.Log; using DataEntity.Share; namespace XHandler.View.BacteriaProperty { /// /// CaptureProperty.xaml 的交互逻辑 /// public partial class CaptureProperty : UserControl, IMethodProperty { ObservableCollection bacteriaList = new ObservableCollection(); BacteriaBll bacteriaBll = new BacteriaBll(); int mark = 0; #region 全局变量 string isrun = ""; string status = ""; string name = ""; string label = ""; int ismanualconfig = 0; string bacteriaids = ""; string paramfilepath = ""; string gapValue = ""; string colorText = ""; string colorValue = ""; int choicemode = 0; int choiceTimes = 0; string coatingLabwareText = ""; // 涂布耗材名称文本 string coatingLabwareValue = ""; // 涂布耗材名称Id private int coatingLabwareGotFocus = 0; #endregion public MethodTakePhoto methodTakePhoto { get; set; } public MethodTakePhoto currmethodTakePhoto = null; public CaptureProperty() { InitializeComponent(); } public CaptureProperty(MethodEx method) { mark = 0; InitializeComponent(); methodTakePhoto = new MethodTakePhoto(); methodTakePhoto.name = method.method_name; methodTakePhoto.label = method.method_name; methodTakePhoto.status = (method.isEnabled == true ? "enable" : "disable"); methodTakePhoto.strIndex = method.strIndex; this.DataContext = methodTakePhoto; if (methodTakePhoto.ismanualconfig == 1) radioBtnManualConfig.IsChecked = true; else radioBtnAutoConfig.IsChecked = true; if (methodTakePhoto.identification == 1) radioBtnManual.IsChecked = true; else radioBtnAuto.IsChecked = true; if (methodTakePhoto.choiceTimes == 1) radioBtnTimes1.IsChecked = true; else radioBtnTimes2.IsChecked = true; ObservableCollection bacterias = DataModule.getInstance().GetBacterias(); foreach (Bacteria b in bacterias) { MultiCbxBaseData data = new MultiCbxBaseData(); data.ID = b.bacteria_id; data.ViewName = b.bacteria_name; data.IsCheck = false; bacteriaList.Add(data); } mcbBacteria.ItemsSource = bacteriaList; ObservableCollection colorList = bacteriaBll.GetBacteriaColorList(); mcbBacteriaBackColor.ItemsSource = colorList; mcbBacteriaBackColor.SelectedIndex = 0; methodTakePhoto.bacteriaids = ""; methodTakePhoto.gapValue = "0"; methodTakePhoto.colorText = ""; methodTakePhoto.colorValue = ""; methodTakePhoto.identification = 0; if (method.tag != null) { methodTakePhoto = (MethodTakePhoto)method.tag; currmethodTakePhoto = methodTakePhoto; isrun = methodTakePhoto.isrun; status = methodTakePhoto.status; name = methodTakePhoto.name; label = methodTakePhoto.label; ismanualconfig = methodTakePhoto.ismanualconfig; bacteriaids = methodTakePhoto.bacteriaids; paramfilepath = methodTakePhoto.paramfilepath; gapValue = methodTakePhoto.gapValue; colorText = methodTakePhoto.colorText; colorValue = methodTakePhoto.colorValue; choicemode = methodTakePhoto.identification; choiceTimes = methodTakePhoto.choiceTimes; coatingLabwareText = methodTakePhoto.coatingLabwareText; coatingLabwareValue = methodTakePhoto.coatingLabwareValue; } radioBtnManualConfig.IsChecked = true; radioBtnAutoConfig.Visibility = Visibility.Hidden; imgTips.Visibility = Visibility.Hidden; tbxParamFromCentWidthralControl.Visibility = Visibility.Hidden; radioBtnManual.IsChecked = true; //tBoxIdentification.Visibility = Visibility.Collapsed; //radioBtnAuto.Visibility = Visibility.Hidden; } private void radioBtnManualConfig_Checked(object sender, RoutedEventArgs e) { if (methodTakePhoto == null) return; methodTakePhoto.ismanualconfig = 1; gridManual.Visibility = Visibility.Visible; } private void radioBtnAutoConfig_Checked(object sender, RoutedEventArgs e) { if (methodTakePhoto == null) return; methodTakePhoto.ismanualconfig = 2; gridManual.Visibility = Visibility.Collapsed; } private void radioBtnManual_Checked(object sender, RoutedEventArgs e) { if (methodTakePhoto == null) return; methodTakePhoto.identification = 1; } private void radioBtnAuto_Checked(object sender, RoutedEventArgs e) { if (methodTakePhoto == null) return; methodTakePhoto.identification = 0; } /// /// 菌落选择只能选择一个 /// /// /// private void mcbBacteria_SelectionChanged(object sender, SelectionChangedEventArgs e) { //string ids = ""; //foreach(var item in mcbBacteria.ChekedItems) //{ // if (string.IsNullOrEmpty(ids)) // ids = item.ID; // else // ids += "," + item.ID; //} methodTakePhoto.bacteriaids = mcbBacteria.SelectedValue.ToString(); } private void mcbBacteriaBackColor_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (mark == 1) { if (mcbBacteriaBackColor.SelectedItem == null) return; BacteriaColor bacteriaColor = mcbBacteriaBackColor.SelectedItem as BacteriaColor; if (methodTakePhoto != null) { methodTakePhoto.colorText = bacteriaColor.bacteria_color_name; methodTakePhoto.colorValue = bacteriaColor.bacteria_color_id.ToString(); } } else { if (mcbBacteriaBackColor.SelectedItem == null) return; BacteriaColor bacteriaColor = mcbBacteriaBackColor.SelectedItem as BacteriaColor; methodTakePhoto.colorText = bacteriaColor.bacteria_color_name; methodTakePhoto.colorValue = bacteriaColor.bacteria_color_id.ToString(); } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e) { try { if (mark == 1) { //methodTakePhoto.name = tbxCommandName.Text; } else { methodTakePhoto.name = tbxCommandName.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxDistanceOfBothBacteria_TextChanged(object sender, TextChangedEventArgs e) { try { if (mark == 1) { //methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text; if(!string.IsNullOrEmpty(tbxDistanceOfBothBacteria.Text)) { if (methodTakePhoto != null) { methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text; } } } else { methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #region 界面加载完成事件 private void UserControl_Loaded(object sender, RoutedEventArgs e) { mark += 1; try { if (mark > 2) { return; } if (!string.IsNullOrEmpty(label)) { tbxCommandLabel.Text = label; tbxCommandName.Text = name; if (ismanualconfig == 1) { radioBtnManualConfig.IsChecked = true; gridManual.Visibility = Visibility.Visible; // 设置菌落下拉框默认选中值 BindingBacteriaData(methodTakePhoto.bacteriaids); tbxDistanceOfBothBacteria.Text = gapValue; mcbBacteriaBackColor.SelectedValue = colorValue; // 加载涂布耗材数据 string[] coatingLabwareValues = coatingLabwareValue.Split(','); string[] coatingLabwareTexts = coatingLabwareText.Split(','); for (int iCoatingLabwareValueIndex = 0; iCoatingLabwareValueIndex < coatingLabwareValues.Length; iCoatingLabwareValueIndex++) { PromptTextBox textBox = iCoatingLabwareValueIndex == 0 ? coatingLabwareA : coatingLabwareB; textBox.Tag = coatingLabwareValues[iCoatingLabwareValueIndex]; textBox.Text = coatingLabwareTexts[iCoatingLabwareValueIndex]; } if (choicemode == 1) { radioBtnManual.IsChecked = true; } else if (choicemode == 0) { radioBtnAuto.IsChecked = true; } if (choiceTimes == 1) { radioBtnTimes1.IsChecked = true; } else if (choiceTimes == 2) { radioBtnTimes2.IsChecked = true; } } else if (ismanualconfig == 2) { radioBtnAutoConfig.IsChecked = true; gridManual.Visibility = Visibility.Hidden; } } else { radioBtnAutoConfig.IsChecked = true; gridManual.Visibility = Visibility.Hidden; } radioBtnManualConfig.IsChecked = true; // 参数配置:手动 } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion /// /// 设置菌落下拉框默认选中值 /// /// public void BindingBacteriaData(string bacteriaids) { if (bacteriaids != null) { // 只会有一个菌种被选择 //mcbBacteria.ChekedItems.Clear(); //string[] subBacteria = bacteriaids.Split(','); mcbBacteria.SelectedValue = bacteriaids; //ObservableCollection s = (ObservableCollection)mcbBacteria.ItemsSource; //for (int i = 0; i < s.Count; i++) //{ // MultiCbxBaseData bacteria = s[i]; // if (string.IsNullOrEmpty(bacteria.ViewName)) // continue; // if (subBacteria.Contains(bacteria.ID.ToString())) // { // bacteria.IsCheck = true; // } // else // { // bacteria.IsCheck = false; // } //} //mcbBacteria.ItemsSource = s; //mcbBacteria.OnApplyTemplate(); } } #region 条形码 删除 //private void tbxBarCodeBacteria_TextChanged(object sender, TextChangedEventArgs e) //{ // try // { // //if (mark == 1) // //{ // // //methodTakePhoto.gapValue = tbxDistanceOfBothBacteria.Text; // // if (!string.IsNullOrEmpty(tbxBarCodeBacteria.Text)) // // { // // if (methodTakePhoto != null) // // { // // methodTakePhoto.barcode = tbxBarCodeBacteria.Text; // // } // // } // //} // //else // //{ // // methodTakePhoto.barcode = tbxBarCodeBacteria.Text; // //} // } // catch (Exception ex) // { // } //} #endregion public void SetTableName(string tableName, Labware lb) { if (lb == null) return; if (gridManual.Visibility == Visibility.Visible) { if (methodTakePhoto != null) { //methodTakePhoto.coatingLabwareText = lb.labware_name; //methodTakePhoto.coatingLabwareValue = lb.labware_id; if (coatingLabwareGotFocus == 0) { coatingLabwareA.Tag = lb.labware_id; coatingLabwareA.Text = lb.labware_name; } else { coatingLabwareB.Tag = lb.labware_id; coatingLabwareB.Text = lb.labware_name; } } } } #region 涂布耗材 /// /// 涂布耗材类型A文字变更事件 /// /// /// private void coatingLabwareA_TextChanged(object sender, TextChangedEventArgs e) { PromptTextBox textBox = (PromptTextBox)sender; // 涂布耗材类型文字变更共用方法 CoatingLabwareTextChange(textBox); } /// /// 涂布耗材类型B文字变更事件 /// /// /// private void coatingLabwareB_TextChanged(object sender, TextChangedEventArgs e) { PromptTextBox textBox = (PromptTextBox)sender; // 涂布耗材类型文字变更共用方法 CoatingLabwareTextChange(textBox); } /// /// 涂布耗材类型文字变更共用方法 /// /// private void CoatingLabwareTextChange(PromptTextBox textBox) { if (mark == 1) { if (!string.IsNullOrEmpty(textBox.Text)) { if (methodTakePhoto != null) { // 设置涂布耗材信息 GetCoatingLabwareTextChange(); } } } else { // 设置涂布耗材信息 GetCoatingLabwareTextChange(); } } /// /// 设置涂布耗材信息 /// private void GetCoatingLabwareTextChange() { methodTakePhoto.coatingLabwareText = string.Format("{0},{1}", coatingLabwareA.Text, coatingLabwareB.Text); methodTakePhoto.coatingLabwareValue = string.Format("{0},{1}", coatingLabwareA.Tag.ToString(), coatingLabwareB.Tag.ToString()); } private void coatingLabwareA_GotFocus(object sender, RoutedEventArgs e) { coatingLabwareGotFocus = 0; } private void coatingLabwareB_GotFocus(object sender, RoutedEventArgs e) { coatingLabwareGotFocus = 1; } #endregion #region 涂布接种次数 private void radioBtnTimes1_Checked(object sender, RoutedEventArgs e) { // 根据涂布次数表示涂布耗材B RadioBtnTimesChange(); } private void radioBtnTimes2_Checked(object sender, RoutedEventArgs e) { // 根据涂布次数表示涂布耗材B RadioBtnTimesChange(); } /// /// 根据涂布次数表示涂布耗材B /// private void RadioBtnTimesChange() { if (radioBtnTimes1.IsChecked == true) { coatingLabwareBTitle.Visibility = coatingLabwareB.Visibility = Visibility.Hidden; methodTakePhoto.choiceTimes = 1; } else if(radioBtnTimes2.IsChecked == true) { coatingLabwareBTitle.Visibility = coatingLabwareB.Visibility = Visibility.Visible; methodTakePhoto.choiceTimes = 2; } } #endregion } }