|
- using CCWin.SkinControl;
- using GeBoShi.SysCtrl;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace GeBoShi.UI.Product
- {
- public partial class MesSelectPdt : Form
- {
- Service.ProductService PdtService = new Service.ProductService();
-
- public MesSelectPdt(string mfid)
- {
- InitializeComponent();
- UIStyle.SetUIStyle(this);
- this.uiTitel1.FatherForm = this;
-
- tbMFID.Text = mfid;
-
- var list = PdtService.GetListNav();
-
- //添加产品
- LoadPdtList(SysMgr.Instance.ProductCodeList);
- }
-
- private string[] pdtlistData;
- private void LoadPdtList(List<string> list)
- {
- this.cbDefectCode.Items.Clear();
- while (true)
- {
- bool bk = true;
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i] == null || string.IsNullOrEmpty(list[i]))
- {
- list.Remove(list[i]);
- bk = false;
- }
- }
- if (bk)
- {
- break;
- }
- }
- this.pdtlistData = list.ToArray();
-
- cbDefectCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些
- cbDefectCode.TextUpdate += cobList_TextUpdate;//重新绑定事件
- cbDefectCode.KeyDown += CobList_KeyDown;
- this.cbDefectCode.Text = "";
- cbDefectCode.Focus();
- cbDefectCode.SelectAll();
- }
- private void CobList_KeyDown(object sender, KeyEventArgs e)
- {
- ComboBox ctrl = sender as ComboBox;
- if (e.KeyCode == Keys.Enter)
- {
- if (ctrl.Items.Count == 1)
- ctrl.Text = ctrl.Items[0].ToString();
- }
- }
-
- private void cobList_TextUpdate(object sender, EventArgs e)
- {
- ComboBox ctrl = sender as ComboBox;
- if (ctrl.Text != null)
- {
- string str = ctrl.Text; //获取cb_material控件输入内
- //清空combobox
- ctrl.DataSource = null;
- ctrl.Items.Clear();
-
- string[] workOrderFiltered;
-
- workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
- ctrl.Items.AddRange(workOrderFiltered);//比使用DataSource速度要快一些
-
- // 不存在符合条件时
- //设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
- ctrl.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置
- if (workOrderFiltered.Length > 0)
- {
- if (!ctrl.DroppedDown)
- ctrl.DroppedDown = true; // 自动弹出下拉框
- }
-
- ctrl.SelectionStart = str.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
- }
- }
-
- /// <summary>
- /// 绑定检测标准
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void skinButton1_Click(object sender, EventArgs e)
- {
- var model = PdtService.GetModelNavByName(cbDefectCode.Text);
- if(model == null)
- {
- MessageBox.Show("获取检测流程失败!","错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- this.DialogResult = DialogResult.Cancel;
- }
- else
- {
- if (string.IsNullOrEmpty(model.Spec))
- model.Spec = tbMFID.Text;
- else
- {
- model.Spec = model.Spec + "," +tbMFID.Text;
- }
- PdtService.UpdateNav(model);
- this.DialogResult = DialogResult.OK;
- }
- }
- }
- }
|