革博士V2程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

127 righe
4.4 KiB

  1. using CCWin.SkinControl;
  2. using GeBoShi.SysCtrl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace GeBoShi.UI.Product
  13. {
  14. public partial class MesSelectPdt : Form
  15. {
  16. Service.ProductService PdtService = new Service.ProductService();
  17. public MesSelectPdt(string mfid)
  18. {
  19. InitializeComponent();
  20. UIStyle.SetUIStyle(this);
  21. this.uiTitel1.FatherForm = this;
  22. tbMFID.Text = mfid;
  23. var list = PdtService.GetListNav();
  24. //添加产品
  25. LoadPdtList(SysMgr.Instance.ProductCodeList);
  26. }
  27. private string[] pdtlistData;
  28. private void LoadPdtList(List<string> list)
  29. {
  30. this.cbDefectCode.Items.Clear();
  31. while (true)
  32. {
  33. bool bk = true;
  34. for (int i = 0; i < list.Count; i++)
  35. {
  36. if (list[i] == null || string.IsNullOrEmpty(list[i]))
  37. {
  38. list.Remove(list[i]);
  39. bk = false;
  40. }
  41. }
  42. if (bk)
  43. {
  44. break;
  45. }
  46. }
  47. this.pdtlistData = list.ToArray();
  48. cbDefectCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些
  49. cbDefectCode.TextUpdate += cobList_TextUpdate;//重新绑定事件
  50. cbDefectCode.KeyDown += CobList_KeyDown;
  51. this.cbDefectCode.Text = "";
  52. cbDefectCode.Focus();
  53. cbDefectCode.SelectAll();
  54. }
  55. private void CobList_KeyDown(object sender, KeyEventArgs e)
  56. {
  57. ComboBox ctrl = sender as ComboBox;
  58. if (e.KeyCode == Keys.Enter)
  59. {
  60. if (ctrl.Items.Count == 1)
  61. ctrl.Text = ctrl.Items[0].ToString();
  62. }
  63. }
  64. private void cobList_TextUpdate(object sender, EventArgs e)
  65. {
  66. ComboBox ctrl = sender as ComboBox;
  67. if (ctrl.Text != null)
  68. {
  69. string str = ctrl.Text; //获取cb_material控件输入内
  70. //清空combobox
  71. ctrl.DataSource = null;
  72. ctrl.Items.Clear();
  73. string[] workOrderFiltered;
  74. workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  75. ctrl.Items.AddRange(workOrderFiltered);//比使用DataSource速度要快一些
  76. // 不存在符合条件时
  77. //设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  78. ctrl.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置
  79. if (workOrderFiltered.Length > 0)
  80. {
  81. if (!ctrl.DroppedDown)
  82. ctrl.DroppedDown = true; // 自动弹出下拉框
  83. }
  84. ctrl.SelectionStart = str.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  85. }
  86. }
  87. /// <summary>
  88. /// 绑定检测标准
  89. /// </summary>
  90. /// <param name="sender"></param>
  91. /// <param name="e"></param>
  92. private void skinButton1_Click(object sender, EventArgs e)
  93. {
  94. var model = PdtService.GetModelNavByName(cbDefectCode.Text);
  95. if(model == null)
  96. {
  97. MessageBox.Show("获取检测流程失败!","错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  98. this.DialogResult = DialogResult.Cancel;
  99. }
  100. else
  101. {
  102. if (string.IsNullOrEmpty(model.Spec))
  103. model.Spec = tbMFID.Text;
  104. else
  105. {
  106. model.Spec = model.Spec + "," +tbMFID.Text;
  107. }
  108. PdtService.UpdateNav(model);
  109. this.DialogResult = DialogResult.OK;
  110. }
  111. }
  112. }
  113. }