using DrawGraph; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace DrawGraph { public class SelectDictValue { private volatile static SelectDictValue _instance = null; private static readonly object lockHelper = new object(); private SelectDictValue() { } public static SelectDictValue CreateInstance() { if (_instance == null) { lock (lockHelper) { if (_instance == null) { _instance = new SelectDictValue(); 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); //dgvZd.KeyDown += new System.Windows.Forms.KeyEventHandler(dgvZd_KeyDown); //dgvZd.KeyPress += new System.Windows.Forms.KeyPressEventHandler(dgvZd_KeyPress); //dgvZd.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(dgvZd_PreviewKeyDown); } } } 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 Key; public static string Value; public static bool isRadio; public static string ChageText = ""; 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; Key = aEdit.PackValue; Value = aEdit.PackText; DataTable dt = DBManage.GetDictDataTable((OpeRecord as OperationRecord), "", aEdit.ControlTitleText, type.ToString(), Key); dgvZd.DataSource = dt; dgvZd.Columns[1].HeaderText = aEdit.ControlTitleText; dgvZd.Location = 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.ControlTitleText == "人员" || aEdit.ControlTitleText == "手术" || aEdit.ControlTitleText == "诊断") { dgvZd.Columns[2].Visible = true; } 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; Key = aEdit.PackValue; Value = aEdit.PackText; if (Value == null || Value == "") ChageText = CControl.Text; else if (CControl.Text.Contains(",")) ChageText = CControl.Text.Substring(CControl.Text.LastIndexOf(",") + 1, CControl.Text.Length - CControl.Text.LastIndexOf(",") - 1); DataTable dt = DBManage.GetDictDataTable((OpeRecord as OperationRecord), ChageText, aEdit.ControlTitleText, type.ToString(), Key); 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(','); string[] ids = Key.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]); idvalue.Add(ids[j]); } } } if (idvalue.Count > 0) { Value = string.Join(",", namevalue); Key = string.Join(",", idvalue); } else { Value = ""; Key = ""; } dgvZd.Visible = false; aEdit.IsVisible = !aEdit.IsVisible; //设置属性的值 template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Value, Key, true); } else { Value = ""; Key = ""; dgvZd.Visible = false; aEdit.IsVisible = !aEdit.IsVisible; //设置属性的值 template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Value, Key, 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) { Key = id.ToString(); Value = name; } else { if (Key != null && Key.Trim() != "") { Key = Key + "," + id; Value = Value + "," + name; } else { Key = id.ToString(); Value = name; } } index = 0; dgvZd.Visible = false; //设置属性的值 aEdit.IsVisible = !aEdit.IsVisible; template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Value, Key, true); } } } }