AIMS/DrawGraph/AreaManage/SelectWorkerValue.cs

262 lines
11 KiB
C#

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 SelectWorkerValue
{
private volatile static SelectWorkerValue _instance = null;
private static readonly object lockHelper = new object();
public static bool isUpdate = true;
private SelectWorkerValue() { }
public static SelectWorkerValue CreateInstance()
{
if (_instance == null)
{
lock (lockHelper)
{
if (_instance == null)
{
_instance = new SelectWorkerValue();
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;
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 void Show(TemplateManage _template, object _OpeRecord, AbleEditPackObj _aEdit, string _type, bool _isUpdate = true)
{
isUpdate = _isUpdate;
type = _type;
aEdit = _aEdit;
template = _template;
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;
//System.Drawing.Point point = new System.Drawing.Point(aEdit.CControl.Location.X, aEdit.CControl.Location.Y - aEdit.CControl.Height);
//if (_type == "手术" || _type == "诊断")
//{
// dgvZd.Size = new System.Drawing.Size(400, 210);
// if (_aEdit.RealEndY > 0.8)
// point = new System.Drawing.Point(aEdit.CControl.Location.X, aEdit.CControl.Location.Y - 220);
//}
//else
//{
// dgvZd.Size = new System.Drawing.Size(200, 290);
// if (_aEdit.RealEndY > 0.8)
// point = new System.Drawing.Point(aEdit.CControl.Location.X, aEdit.CControl.Location.Y - 300);
//}
//dgvZd.Location = point;
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 < 200 ? 199 : 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;
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;
string text = CControl.Text;
text = text.Replace(Value + ",", "");
DataTable dt = DBManage.GetDictDataTable((OpeRecord as OperationRecord), text, 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<string> namevalue = new List<string>();
List<string> idvalue = new List<string>();
for (int i = 0; i < strs.Length; i++)
{
for (int j = 0; j < names.Length; j++)
{
if (strs[i] == 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.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 (Key != null && Key.Trim() != "")
{
Key = Key + "," + id;
Value = Value + "," + name;
}
else
{
Key = id.ToString();
Value = name;
}
index = 0;
dgvZd.Visible = false;
if (isUpdate == true)
{
//设置属性的值
aEdit.IsVisible = !aEdit.IsVisible;
}
template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Value, Key, isUpdate);
}
}
}
}