123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using ComponentFactory.Krypton.Toolkit;
- using System.Reflection;
- namespace NXWMS.Client.FrmCustom
- {
- /// <summary>
- /// DataGridView列操作控件
- /// </summary>
- [ToolboxBitmap(typeof(System.Windows.Forms.Panel))]
- public partial class ColumnControl : UserControl
- {
- /// <summary>
- /// 字段值
- /// </summary>
- [Description("字段操作对象")]
- public class ControlFieldValue
- {
- public string Code { get; set; }
- public string Name { get; set; }
- }
- [Description("被绑定的数据视图")]
- public DataGridView ToDataGridView { get; set; }
- [Description("数据视图中指定操作的列")]
- public DataGridViewColumn ItemColumn { get; set; }
- [Description("当前操作单元格矩形长宽坐标")]
- public Rectangle CellRectangle { get; set; }
- [Description("系统屏幕矩形长宽坐标")]
- public Rectangle ScreenRectangle { get; set; }
- [Description("选择按钮")]
- public KryptonButton ButtonSelect { get; set; }
- [Description("控件标题")]
- public string Title { get; set; } = "";
- [Description("绑定控件对象")]
- public Control ItemControl { get; set; }
- [Description("是否允许输入(针对选择控件)")]
- public bool IsAllowInput { get; set; } = false;
- [Description("绑定控件对象类型")]
- public ControlType ItemControlType { get; set; }
- [Description("绑定控件对象数据")]
- public DataTable ItemControlData { get; set; }
- [Description("数据表格中查询显示列名称")]
- public Dictionary<string, string> ItemColumnDic { get; set; }
- [Description("数据表格对应筛选字段")]
- public List<ConditionColumnMode> ConditionColumnList { get; set; }
- [Description("弹窗数据视图条件")]
- public string ConditionColumnCode { get; set; }
- [Description("显示数据视图字段")]
- public string ShowColumns { get; set; }
- [Description("选择返回的字典编码")]
- public string ResultColumn { get; set; }
- [Description("设定弹出框位置(针对数据对象)")]
- public LocationType SetLocationType { get; set; }
- [Description("输入控件小数点长度(只针对浮点控件)")]
- public int InputDecimalLength { get; set; } = 0;
- [Description("输入控件最大值限制(只针对浮点控件)")]
- public int InputDecimalMax { get; set; } = 999999;
- [Description("输入控件最小值限制(只针对浮点控件)")]
- public int InputDecimalMin { get; set; } = 0;
- [Description("弹窗对象")]
- public Form ShowForm { get; set; }
- [Description("弹窗对象相对于屏幕显示的比例")]
- public double ShowFormProportion { get; set; } = 0.5;
- [Description("绑定控件对象类型")]
- public enum ControlType
- {
- ComboBox,
- Text,
- NumericUpDown,
- CheckBox,
- DataTime,
- Source,
- }
- public enum LocationType
- {
- Cell,
- ScreenCenter,
- }
- public enum OperationDataType
- {
- Selectd,
- Input,
- Other
- }
- /// <summary>
- /// 条件字段模型
- /// </summary>
- public class ConditionColumnMode
- {
- public string Name { get; set; }
- public string Describe { get; set; }
- }
- /// <summary>
- /// 是否新增了选择列
- /// </summary>
- private bool IsAddCheck { get; set; }
- /// <summary>
- /// 选择行索引列表
- /// </summary>
- [Description("选择行索引列表")]
- public List<int> CheckRowIndexList;
- [Description("最终操作是否未拖动")]
- public bool IsNoScroll = false;
- [Description("当前正在操作的单元格")]
- public DataGridViewCell CurrentDataGridViewCell;
- /// <summary>
- /// 数据视图控件模型
- /// </summary>
- public class ControlDataViewModel
- {
- /// <summary>
- /// 数据控件名称
- /// </summary>
- public string Name { get; set; } = Guid.NewGuid().ToString();
- /// <summary>
- /// 数据控件描述
- /// </summary>
- public string Describe { get; set; }
- /// <summary>
- /// 数据控件绑定对象
- /// </summary>
- public DataGridView DataGridView { get; set; }
- /// <summary>
- /// 数据控件绑定对象中的列
- /// </summary>
- public DataGridViewColumn DataGridViewColumn { get; set; }
- /// <summary>
- /// 数据控件绑定类型
- /// </summary>
- public ControlType ControlType { get; set; } = ControlType.Text;
- /// <summary>
- /// 数据控件数据
- /// </summary>
- public DataTable ControlData { get; set; }
- /// <summary>
- /// 数据视图筛选条件
- /// </summary>
- public List<ConditionColumnMode> ConditionColumnList { get; set; }
- /// <summary>
- /// 选择字段单元格显示
- /// </summary>
- public string CellColumn { get; set; }
- /// <summary>
- /// 显示列
- /// </summary>
- public Dictionary<string, string> ItemColumnDic { get; set; }
- /// <summary>
- /// 结果字段
- /// </summary>
- public string ResultColumn { get; set; }
- }
- /// <summary>
- /// 控件数据事件
- /// </summary>
- /// <param name="column">操作列</param>
- /// <param name="inData">对应列数据</param>
- /// <param name="operationDataType">该控件操作数据类型</param>
- /// <returns></returns>
- public delegate string ControlGetValueHandler(DataGridViewCell dataGridCell, object inData, OperationDataType operationDataType);
- public event ControlGetValueHandler ControlGetValueEvent;
- /// <summary>
- /// 按钮选择事件
- /// </summary>
- /// <param name="selectColumn">选择列</param>
- /// <param name="selectRow">选择行</param>
- /// <param name="resultColumnName">结果列名</param>
- /// <returns></returns>
- public delegate string ButtonSelectHandler(DataGridViewColumn selectColumn, DataGridViewRow selectRow, string resultColumnName);
- public event ButtonSelectHandler ButtonSelectEvent;
- /// <summary>
- /// 当有选择列时,单独选择事件
- /// </summary>
- /// <param name="selectColumn">选择列</param>
- /// <param name="selectRow">选择行</param>
- /// <param name="resultColumnName">结果列名</param>
- /// <returns></returns>
- public delegate string ControlCheckHandler(DataGridViewColumn selectColumn, DataGridViewRow selectRow, string resultColumnName);
- public event ControlCheckHandler ControlCheckEvent;
- /// <summary>
- /// 当有选择列时,去除选择事件
- /// </summary>
- /// <param name="selectColumn">选择列</param>
- /// <param name="selectRow">选择行</param>
- /// <param name="resultColumnName">结果列名</param>
- /// <returns></returns>
- public delegate string ControlNoCheckHandler(DataGridViewColumn selectColumn, DataGridViewRow selectRow, string resultColumnName);
- public event ControlNoCheckHandler ControlNoCheckEvent;
- public event EventHandler ButtonExitEvent;
- public ColumnControl()
- {
- InitializeComponent();
- Visible = false;
- LostFocus += new EventHandler(ColumnControl_LostFocus);
- this.Text = Title;
- }
- /// <summary>
- /// 组装
- /// </summary>
- /// <param name="controlDataViewModel">控件数据模型</param>
- public void Build(ControlDataViewModel controlDataViewModel)
- {
- ConditionColumnList = controlDataViewModel.ConditionColumnList; //条件列表
- ConditionColumnCode = controlDataViewModel.CellColumn; //单元格显示
- ResultColumn = controlDataViewModel.ResultColumn;
- ItemControlData = controlDataViewModel.ControlData;
- ItemControlType = controlDataViewModel.ControlType;
- ToDataGridView = controlDataViewModel.DataGridView;
- ItemColumn = controlDataViewModel.DataGridViewColumn;
- ItemColumnDic = controlDataViewModel.ItemColumnDic;
-
- Build();
- }
- /// <summary>
- /// 组装
- /// </summary>
- private void Build()
- {
- ToDataGridView.CurrentCellChanged += new EventHandler(this.ToDataGridView_CurrentCellChanged);
- ToDataGridView.Scroll += new ScrollEventHandler(this.ToDataGridView_Scroll);
- ToDataGridView.ColumnWidthChanged += new DataGridViewColumnEventHandler(this.ToDataGridView_ColumnWidthChanged);
- ToDataGridView.CurrentCellDirtyStateChanged += new System.EventHandler(this.TodataGridView_CurrentCellDirtyStateChanged);
- ToDataGridView.SizeChanged += new System.EventHandler(this.ToDataGridView_SizeChanged);
- switch (ItemControlType)
- {
- case ControlType.CheckBox:
- ItemControl = new KryptonCheckBox();
- ItemControl.KeyDown += new KeyEventHandler(ItemControl_KeyDown);
- ItemControl.Visible = false;
- break;
- case ControlType.ComboBox:
- ItemControl = new KryptonComboBox();
- ItemControl.KeyDown += new KeyEventHandler(ItemControl_KeyDown);
- ItemControl.Visible = false;
- var fieldList = new List<ControlFieldValue>();
- foreach (DataRow item in ItemControlData.Rows)
- {
- fieldList.Add(new ControlFieldValue
- {
- Code = item[ResultColumn].ToString(),
- Name = item[ConditionColumnCode].ToString()
- });
- }
- (ItemControl as KryptonComboBox).AutoCompleteCustomSource.AddRange(fieldList.Select(s => s.Name).ToArray());
- (ItemControl as KryptonComboBox).AutoCompleteSource = AutoCompleteSource.ListItems;
- (ItemControl as KryptonComboBox).AutoCompleteMode = AutoCompleteMode.SuggestAppend;
- (ItemControl as KryptonComboBox).DataSource = fieldList;
- (ItemControl as KryptonComboBox).DisplayMember = "Name";
- (ItemControl as KryptonComboBox).ValueMember = "Code";
- (ItemControl as KryptonComboBox).SelectedIndex = -1;
- if (!IsAllowInput)
- (ItemControl as KryptonComboBox).DropDownStyle = ComboBoxStyle.DropDownList;
- else
- (ItemControl as KryptonComboBox).DropDownStyle = ComboBoxStyle.DropDown;
- break;
- case ControlType.DataTime:
- ItemControl = new KryptonDateTimePicker();
- ItemControl.KeyDown += new KeyEventHandler(ItemControl_KeyDown);
- ItemControl.Visible = false;
- break;
- case ControlType.NumericUpDown:
- ItemControl = new KryptonNumericUpDown();
- ItemControl.KeyDown += new KeyEventHandler(ItemControl_KeyDown);
- ItemControl.Visible = false;
- (ItemControl as KryptonNumericUpDown).DecimalPlaces = InputDecimalLength;
- break;
- case ControlType.Text:
- ItemControl = new KryptonTextBox();
- ItemControl.KeyDown += new KeyEventHandler(ItemControl_KeyDown);
- ItemControl.Visible = false;
- break;
- case ControlType.Source:
- ItemControl = this;
- ButtonSelect = new KryptonButton();
- ButtonSelect.Visible = false;
- SetPanelCondition(ConditionColumnList);
- ButtonSelect.Click += new EventHandler(ShowPanelSelect_Click);
- ToDataGridView.Controls.Add(ButtonSelect);
- break;
- }
- ToDataGridView.Controls.Add(ItemControl);
- ToDataGridView.Controls.SetChildIndex(ItemControl, 99999);
- }
-
- private void ItemControl_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 13)
- {
- ItemControl_LostFocus(null, null);
- }
- }
- private void SetPanelCondition(List<ConditionColumnMode> conditionColumnList)
- {
- //建立条件框
- if (conditionColumnList.Any())
- {
- tableLayoutPanelCondtion.Visible = true;
- for (int i = 0; i < conditionColumnList.Count; i++)
- {
- var lbCol = tableLayoutPanelCondtion.Controls.Find("lbCondition" + (i + 1).ToString(), true)[0];
- if (lbCol != null)
- {
- var col = lbCol as KryptonLabel;
- col.Text = conditionColumnList[i].Describe;
- col.Visible = true;
- }
- var txtCol = tableLayoutPanelCondtion.Controls.Find("txtCondition" + (i + 1).ToString(), true)[0];
- if (txtCol != null)
- {
- var col = txtCol as KryptonTextBox;
- col.Tag = conditionColumnList[i].Name;
- txtCol.TextChanged += new EventHandler(Condition_TextChanged);
- col.Visible = true;
- }
- }
- }
- }
- private void ToDataGridView_SizeChanged(object sender, EventArgs e)
- {
- ToDataGridView_CurrentCellChanged(null, null);
- }
- private void ToDataGridView_Scroll(object sender, ScrollEventArgs e)
- {
- if (ItemControlType == ControlType.Source)
- {
- Visible = false;
- ButtonSelect.Visible = false;
- }
- else
- {
- ItemControl.Visible = false;
- }
- ToDataGridView.ClearSelection();
- IsNoScroll = true;
- }
- private void ToDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- if (IsNoScroll)
- {
- ToDataGridView_CurrentCellChanged(null, null);
- }
- }
- public void ToDataGridView_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
- {
- if (ItemControlType == ControlType.Source)
- {
- ToDataGridView_CurrentCellChanged(null, null);
- }
- }
- private void ToDataGridView_CurrentCellChanged(object sender, EventArgs e)
- {
- CurrentDataGridViewCell = ToDataGridView.CurrentCell;
- if (CurrentDataGridViewCell == null)
- return;
- var value = string.Empty;
- if (CurrentDataGridViewCell.Value == null)
- value = "";
- else
- value = CurrentDataGridViewCell.Value.ToString();
- if (CurrentDataGridViewCell != null && CurrentDataGridViewCell.RowIndex < ToDataGridView.Rows.Count && CurrentDataGridViewCell.OwningColumn.Name == ItemColumn.Name)
- {
- IsNoScroll = false;
- CellRectangle = ToDataGridView.GetCellDisplayRectangle(CurrentDataGridViewCell.ColumnIndex, CurrentDataGridViewCell.RowIndex, true);
- switch (ItemControlType)
- {
- case ControlType.CheckBox:
- ItemControl.Visible = true;
- (ItemControl as KryptonCheckBox).Text = ItemColumn.HeaderText;
- (ItemControl as KryptonCheckBox).Checked = Convert.ToBoolean(string.IsNullOrWhiteSpace(value) ? "FALSE" : value);
- break;
- case ControlType.ComboBox:
- (ItemControl as KryptonComboBox).Text = value;
- (ItemControl as KryptonComboBox).Focus();
- break;
- case ControlType.DataTime:
- ItemControl.Visible = true;
- if (string.IsNullOrWhiteSpace(value))
- {
- (ItemControl as KryptonDateTimePicker).Checked = false;
- }
- else
- {
- (ItemControl as KryptonDateTimePicker).Checked = true;
- (ItemControl as KryptonDateTimePicker).Value = DateTime.Parse(value);
- }
- (ItemControl as KryptonDateTimePicker).Focus();
- break;
- case ControlType.NumericUpDown:
- ItemControl.Visible = true;
- if (string.IsNullOrWhiteSpace(value))
- {
- (ItemControl as KryptonNumericUpDown).Value = 0;
- }
- else
- {
- (ItemControl as KryptonNumericUpDown).Value = Convert.ToDecimal(value);
- }
- (ItemControl as KryptonNumericUpDown).Maximum = InputDecimalMax;
- (ItemControl as KryptonNumericUpDown).Minimum = InputDecimalMin;
- (ItemControl as KryptonNumericUpDown).Focus();
- break;
- case ControlType.Text:
- ItemControl.Visible = true;
- (ItemControl as KryptonTextBox).Text = Convert.ToString(value);
- (ItemControl as KryptonTextBox).Focus();
- break;
- case ControlType.Source:
- ButtonSelect.Top = CellRectangle.Top;
- ButtonSelect.StateCommon.Content.ShortText.Font = new Font("宋体", 7.5f);
- ButtonSelect.Text = "..";
- ButtonSelect.Left = CellRectangle.Left + CellRectangle.Size.Width - 30;
- ButtonSelect.Size = new Size(30, CellRectangle.Size.Height);
- ButtonSelect.Visible = true;
- return;
- }
- ItemControl.Size = CellRectangle.Size;
- ItemControl.Top = CellRectangle.Top;
- ItemControl.Left = CellRectangle.Left;
- ItemControl.Visible = true;
- ItemControl.LostFocus += new EventHandler(ItemControl_LostFocus);
- ItemControl.GotFocus += new EventHandler(ItemControl_GostFocus);
- }
- else
- {
- if (ButtonSelect != null)
- {
- ButtonSelect.Visible = false;
- }
- ItemControl.Visible = false;
- }
- }
- public void AddMultipleCheck(int index)
- {
- if (ItemControlType == ControlType.Source)
- {
- IsAddCheck = true;
- ItemControlData.Columns.Add("#SELECTED", typeof(bool));
- }
- }
- private void TodataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
- {
- CurrentDataGridViewCell.Value = "";
- }
- private void dataGridViewSelect_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.RowIndex >= 0 && e.ColumnIndex == 0)
- {
- if (this.dataGridViewSelect.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
- {
- if (!CheckRowIndexList.Where(s => s == e.RowIndex).Any())
- {
- CheckRowIndexList.Add(e.RowIndex);
- }
- ControlCheckEvent?.Invoke(ItemColumn, dataGridViewSelect.SelectedRows[0], ResultColumn);
- this.dataGridViewSelect.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
- }
- else if (dataGridViewSelect.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
- {
- if (CheckRowIndexList.Where(s => s == e.RowIndex).Any())
- {
- CheckRowIndexList.Remove(e.RowIndex);
- }
- ControlNoCheckEvent?.Invoke(ItemColumn, dataGridViewSelect.SelectedRows[0], ResultColumn);
- this.dataGridViewSelect.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
- }
- else
- {
- if (!CheckRowIndexList.Where(s => s == e.RowIndex).Any())
- {
- CheckRowIndexList.Add(e.RowIndex);
- }
- ControlCheckEvent?.Invoke(ItemColumn, dataGridViewSelect.SelectedRows[0], ResultColumn);
- this.dataGridViewSelect.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
- }
- }
- }
- private void ShowPanelSelect_Click(object sender, EventArgs e)
- {
- if (dataGridViewSelect.Columns.Count == 0)
- {
- dataGridViewSelect.DataSource = ItemControlData;
- if (ConditionColumnList.Any())
- {
- foreach (DataGridViewColumn item in dataGridViewSelect.Columns)
- {
- item.Visible = false;
- }
- foreach (var item in ConditionColumnList)
- {
- if (dataGridViewSelect.Columns.Contains(item.Name))
- {
- dataGridViewSelect.Columns[item.Name].Visible = true;
- dataGridViewSelect.Columns[item.Name].HeaderText = item.Describe;
- dataGridViewSelect.Columns[item.Name].ReadOnly = true;
- }
- }
- }
- if (IsAddCheck)
- {
- dataGridViewSelect.CellClick += new DataGridViewCellEventHandler(dataGridViewSelect_CellClick);
- dataGridViewSelect.Columns["#SELECTED"].DisplayIndex = 0;
- dataGridViewSelect.Columns["#SELECTED"].Visible = true;
- dataGridViewSelect.Columns["#SELECTED"].ReadOnly = false;
- dataGridViewSelect.Columns["#SELECTED"].HeaderText = "选择";
- dataGridViewSelect.Columns["#SELECTED"].Resizable = DataGridViewTriState.False;
- dataGridViewSelect.Columns["#SELECTED"].Frozen = false;
- //dataGridViewSelect.Columns["#SELECTED"].Width = 20;
- dataGridViewSelect.Columns["#SELECTED"].ReadOnly = false;
- dataGridViewSelect.Columns["#SELECTED"].DefaultCellStyle.ForeColor = Color.Red;
- }
- else
- {
- ToDataGridView.CellDoubleClick += new DataGridViewCellEventHandler(this.dataGridViewSelect_CellDoubleClick);
- }
- }
- var cellHeight = ToDataGridView.GetCellDisplayRectangle(ToDataGridView.CurrentCell.ColumnIndex,
- ToDataGridView.CurrentCell.RowIndex, true).Height;
- this.Size = new Size(497, 337);
- switch (SetLocationType)
- {
- case LocationType.ScreenCenter:
- ScreenRectangle = Screen.GetWorkingArea(this);
- this.Location = new Point((ScreenRectangle.Width - Width) / 2,
- (ScreenRectangle.Height - Height) / 2);
- break;
- default:
- ItemControl.Top = CellRectangle.Top + cellHeight;
- ItemControl.Left = CellRectangle.Left;
- break;
- }
- if (SetLocationType == LocationType.Cell)
- {
- ToDataGridView.Controls.Add(ButtonSelect);
- this.Visible = true;
- }
- else
- {
- this.Visible = true;
- AddFormShow();
- ShowForm.ShowDialog();
- }
- }
- private void AddFormShow()
- {
- this.Visible = true;
- this.Dock = DockStyle.Fill;
- var newUserControl = this;
- newUserControl.Dock = DockStyle.Fill;
- ShowForm = new Form();
- ShowForm.Name = "ShowDiagion";
- ShowForm.StartPosition = FormStartPosition.CenterScreen;
- ShowForm.MaximizeBox = true;
- ShowForm.MinimizeBox = false;
- ShowForm.Location = newUserControl.Location;
- ShowForm.Size = new Size
- {
- Height = Convert.ToInt32(ScreenRectangle.Height * ShowFormProportion),
- Width = Convert.ToInt32(ScreenRectangle.Width * ShowFormProportion),
- };
- ShowForm.Text = newUserControl.Title;
- ShowForm.Controls.Add(newUserControl);
- }
- private void ItemControl_LostFocus(object sender, EventArgs e)
- {
- OperationDataType operationTemp;
- object value = null;
- switch (ItemControlType)
- {
- case ControlType.CheckBox:
- CurrentDataGridViewCell.Style.ForeColor = Color.Red;
- CurrentDataGridViewCell.Value = (ItemControl as KryptonCheckBox).Checked;
- ControlGetValueEvent?.Invoke(CurrentDataGridViewCell, (ItemControl as KryptonCheckBox).Checked, OperationDataType.Selectd);
- break;
- case ControlType.ComboBox:
- CurrentDataGridViewCell.Style.ForeColor = Color.Red;
- if ((ItemControl as KryptonComboBox).SelectedValue == null)
- {
- value = (ItemControl as KryptonComboBox).Text;
- operationTemp = OperationDataType.Input;
- }
- else
- {
- value = (ItemControl as KryptonComboBox).SelectedValue.ToString();
- operationTemp = OperationDataType.Selectd;
- }
- CurrentDataGridViewCell.Value = (ItemControl as KryptonComboBox).Text;
- CurrentDataGridViewCell.Tag = value;
- ControlGetValueEvent?.Invoke(CurrentDataGridViewCell, value, operationTemp);
- break;
- case ControlType.DataTime:
- CurrentDataGridViewCell.Style.ForeColor = Color.Red;
- if ((ItemControl as KryptonDateTimePicker).Checked)
- {
- value = (ItemControl as KryptonDateTimePicker).Value;
- CurrentDataGridViewCell.Value = value;
- }
- operationTemp = OperationDataType.Input;
- ControlGetValueEvent?.Invoke(CurrentDataGridViewCell, value, OperationDataType.Input);
- break;
- case ControlType.NumericUpDown:
- CurrentDataGridViewCell.Style.ForeColor = Color.Red;
- CurrentDataGridViewCell.Value = (ItemControl as KryptonNumericUpDown).Value;
- ControlGetValueEvent?.Invoke(CurrentDataGridViewCell, (ItemControl as KryptonNumericUpDown).Value, OperationDataType.Input);
- break;
- case ControlType.Text:
- CurrentDataGridViewCell.Style.ForeColor = Color.Red;
- CurrentDataGridViewCell.Value = (ItemControl as KryptonTextBox).Text;
- ControlGetValueEvent?.Invoke(CurrentDataGridViewCell, (ItemControl as KryptonTextBox).Text, OperationDataType.Input);
- break;
- case ControlType.Source:
- kryptonButtonSelect_Click(null, null);
- break;
- }
- }
- private void ItemControl_GostFocus(object sender, EventArgs e)
- {
- }
- private void ColumnControl_LostFocus(object sender, EventArgs e)
- {
- if (this.Visible)
- {
- this.Visible = false;
- ItemControl_LostFocus(null, null);
- }
- }
- private void kryptonButtonSelect_Click(object sender, EventArgs e)
- {
- if (dataGridViewSelect.SelectedRows.Count == 0)
- {
- return;
- }
- var selectIndex = dataGridViewSelect.SelectedRows[0].Index;
- if (selectIndex >= 0)
- {
- CurrentDataGridViewCell.Value = ItemControlData.Rows[selectIndex][ResultColumn];
- CurrentDataGridViewCell.Tag = string.IsNullOrWhiteSpace(ConditionColumnCode) ?
- ItemControlData.Rows[selectIndex][ConditionColumnList.FirstOrDefault().Name] :
- ItemControlData.Rows[selectIndex][ResultColumn];
- ButtonSelect.Visible = false;
- ButtonSelectEvent?.Invoke(ItemColumn, dataGridViewSelect.SelectedRows[0], ResultColumn);
- ShowForm.Hide();
- }
- else
- {
- KryptonMessageBox.Show($"请选择!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private void kryptonButtonExit_Click(object sender, EventArgs e)
- {
- if (ItemControlType == ControlType.Source)
- {
- this.Visible = false;
- ButtonSelect.Visible = false;
- ShowForm.Close();
- }
- else
- {
- ItemControl.Visible = false;
- }
- ButtonExitEvent?.Invoke(sender, e);
- }
- private void dataGridViewSelect_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- if (ShowForm.Visible)
- {
- kryptonButtonSelect_Click(null, null);
- }
- }
- private void ColumnControl_Resize(object sender, EventArgs e)
- {
- }
- private void Condition_TextChanged(object sender, EventArgs e)
- {
- var txtCol = sender as KryptonTextBox;
- var likeSql = $"`{txtCol.Tag}` like '%{txtCol.Text}%'";
- DataRow[] dataRows = ItemControlData.Select(likeSql);
- if (dataRows == null || !dataRows.Any())
- {
- var dataTemp = ItemControlData.Copy();
- dataTemp.Rows.Clear();
- dataGridViewSelect.DataSource = dataTemp;
- }
- else
- {
- var result = dataRows.CopyToDataTable();
- dataGridViewSelect.DataSource = result;
- }
- }
- }
- }
|