using DrawGraph; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using static System.Net.Mime.MediaTypeNames; namespace DrawGraph { public class SelectDictText { private volatile static SelectDictText _instance = null; private static readonly object lockHelper = new object(); public delegate void SetValueHandler(string Value, AbleEditPackObj aEdit); public static event SetValueHandler SetValue; private SelectDictText() { } public static SelectDictText CreateInstance() { if (_instance == null) { lock (lockHelper) { if (_instance == null) { _instance = new SelectDictText(); System.Windows.Forms.DataGridViewTextBoxColumn id = new System.Windows.Forms.DataGridViewTextBoxColumn(); id.HeaderText = "id"; id.Name = "id"; id.DataPropertyName = "id"; id.ReadOnly = true; id.Visible = false; System.Windows.Forms.DataGridViewTextBoxColumn Name = new System.Windows.Forms.DataGridViewTextBoxColumn(); Name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; Name.HeaderText = "名称"; Name.Name = "Name"; Name.DataPropertyName = "Name"; Name.ReadOnly = true; System.Windows.Forms.DataGridViewTextBoxColumn Code = new System.Windows.Forms.DataGridViewTextBoxColumn(); Code.HeaderText = "编码"; Code.Name = "Code"; Code.DataPropertyName = "Code"; Code.ReadOnly = true; Code.Visible = false; dgvZd = new System.Windows.Forms.DataGridView(); dgvZd.AllowUserToAddRows = false; dgvZd.AllowUserToDeleteRows = false; dgvZd.BackgroundColor = System.Drawing.Color.White; DataGridViewCellStyle dgvStyle1 = new DataGridViewCellStyle(); dgvStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dgvStyle1.BackColor = System.Drawing.Color.White; dgvStyle1.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dgvStyle1.ForeColor = System.Drawing.SystemColors.WindowText; dgvStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dgvStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dgvStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dgvZd.ColumnHeadersDefaultCellStyle = dgvStyle1; dgvZd.ColumnHeadersHeight = 30; dgvZd.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { id, Name, Code}); DataGridViewCellStyle dgvStyle2 = new DataGridViewCellStyle(); dgvStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dgvStyle2.BackColor = System.Drawing.SystemColors.Window; dgvStyle2.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dgvStyle2.ForeColor = System.Drawing.Color.Black; dgvStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; dgvStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dgvStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; dgvZd.DefaultCellStyle = dgvStyle2; dgvZd.EnableHeadersVisualStyles = false; dgvZd.Name = "dgvZd"; dgvZd.ReadOnly = true; dgvZd.RowHeadersVisible = false; dgvZd.RowTemplate.Height = 30; dgvZd.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; dgvZd.Size = new System.Drawing.Size(200, 290); dgvZd.TabIndex = 17; dgvZd.AllowUserToResizeRows = false; dgvZd.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgvZd_CellClick); } } } return _instance; } public static System.Windows.Forms.DataGridView dgvZd; static AbleEditPackObj aEdit; static string type; public static TemplateManage template; public static object OpeRecord; public static string Value; public static bool isRadio; public void Show(TemplateManage _template, object _OpeRecord, AbleEditPackObj _aEdit, string _type, bool _isRadio) { type = _type; aEdit = _aEdit; template = _template; isRadio = _isRadio; OpeRecord = _OpeRecord; if (aEdit == null) return; Value = aEdit.PackText; DataTable dt = DBManage.GetDictDataTable((OpeRecord as OperationRecord), "", aEdit.ControlTitleText, type.ToString(), ""); dgvZd.DataSource = dt; dgvZd.Columns[1].HeaderText = aEdit.ControlTitleText + ""; System.Drawing.Point point = new System.Drawing.Point(aEdit.CControl.Location.X, aEdit.CControl.Location.Y + aEdit.CControl.Height); dgvZd.Size = new System.Drawing.Size(aEdit.CControl.Width < 100 ? 99 : aEdit.CControl.Width, dgvZd.Height); if (_aEdit.RealEndY > 0.8) point = new System.Drawing.Point(aEdit.CControl.Location.X, aEdit.CControl.Location.Y - 300); dgvZd.Location = point; dgvZd.Columns[2].Visible = false; if (dgvZd.Parent == null) aEdit.CControl.Parent.Controls.Add(dgvZd); else { aEdit.CControl.Parent.Controls.Remove(dgvZd); aEdit.CControl.Parent.Controls.Add(dgvZd); } dgvZd.Visible = true; dgvZd.BringToFront(); } public void ShowSel(Control CControl, object _OpeRecord) { OpeRecord = _OpeRecord; if (aEdit == null) return; if (dgvZd.Visible == false) return; Value = aEdit.PackText; string text = CControl.Text; text = text.Replace(Value + ",", ""); DataTable dt = DBManage.GetDictDataTable((OpeRecord as OperationRecord), text, aEdit.ControlTitleText, type.ToString(), ""); dgvZd.DataSource = dt; dgvZd.BringToFront(); } public void DelSel(Control CControl, object _OpeRecord) { OpeRecord = _OpeRecord; if (aEdit == null) return; if (CControl.Text.Trim() != "" && CControl.Text != Value) { string[] strs = CControl.Text.Split(','); string[] names = Value.Split(','); List namevalue = new List(); List idvalue = new List(); for (int i = 0; i < strs.Length; i++) { for (int j = 0; j < names.Length; j++) { if (strs[i] == names[j] && !namevalue.Contains(names[j])) { namevalue.Add(names[j]); } } } if (idvalue.Count > 0) { Value = string.Join(",", namevalue); } else { Value = ""; } dgvZd.Visible = false; //aEdit.IsVisible = !aEdit.IsVisible; //设置属性的值 template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Value, Value, true); } else { Value = ""; dgvZd.Visible = false; //aEdit.IsVisible = !aEdit.IsVisible; //设置属性的值 template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Value, Value, true); } } public static void Hidden(bool isShow = false) { try { if (aEdit != null && aEdit.CControl.Parent != null) { aEdit.CControl.Parent.Controls.Remove(dgvZd); dgvZd.Visible = false; //aEdit.IsVisible =false; } } catch (Exception) { } } static void dgvZd_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { SetContent(e.RowIndex); } } public static void SetContent(int index) { if (dgvZd.Rows[index].Cells["Name"].EditedFormattedValue.ToString() != "") { int id = int.Parse(dgvZd.Rows[index].Cells["id"].Value.ToString()); string name = dgvZd.Rows[index].Cells["Name"].Value.ToString(); string code = dgvZd.Rows[index].Cells["code"].Value.ToString(); if (isRadio == true) { Value = name; } else { Value = Value + "," + name; } index = 0; dgvZd.Visible = false; //设置属性的值 //aEdit.IsVisible = !aEdit.IsVisible; //template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Value, true); aEdit.PackValue = Value; aEdit.PackText = Value; SetValue(Value, aEdit); } } } }