242 lines
9.5 KiB
C#
242 lines
9.5 KiB
C#
using AIMSBLL;
|
||
using AIMSModel;
|
||
using AIMSExtension;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Windows.Forms;
|
||
|
||
namespace AIMS.PublicUI.UI
|
||
{
|
||
public partial class frmSelectDictionary : Form
|
||
{
|
||
/// <summary>
|
||
/// 传递取值控件
|
||
/// </summary>
|
||
public TextBox _controlName;
|
||
/// <summary>
|
||
/// 字典名称
|
||
/// </summary>
|
||
public string _dictionaryName;
|
||
public List<string> _arrayId = new List<string>();
|
||
public List<string> _arrayName = new List<string>();
|
||
public BasicDictionary bd;
|
||
public bool isRadio = false;
|
||
public bool isAddItem = false;
|
||
|
||
public frmSelectDictionary()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
private void frmSelectDictionary_Load(object sender, EventArgs e)
|
||
{
|
||
LoadDate();
|
||
this.dgvDictionary.ShowCellToolTips = true;
|
||
this.dgvDictionary.CellMouseEnter += new DataGridViewCellEventHandler(dgvDictionary_CellMouseEnter);
|
||
}
|
||
/// <summary>
|
||
/// 鼠标移到单元格时,设置当前单元格的ToolTipText属性内容为当前单元格内容
|
||
/// 解决tip内容显示不全的问题
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
void dgvDictionary_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0 || dgvDictionary.Rows.Count <= 0) return;
|
||
dgvDictionary.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = (dgvDictionary.Rows[e.RowIndex].Cells[e.ColumnIndex].Value ?? string.Empty).ToString();
|
||
}
|
||
|
||
private void LoadDate()
|
||
{
|
||
dgvDictionary.AutoGenerateColumns = false;
|
||
btnAdd.Visible = isAddItem;
|
||
if (_dictionaryName.Length > 0)
|
||
{
|
||
this.Text = "选择" + _dictionaryName;
|
||
//this.lblName.Text = this.lblName.Text + _dictionaryName;
|
||
bd = BBasicDictionary.GetBasicDictionaryByName(_dictionaryName);
|
||
}
|
||
_arrayId = new List<string>();
|
||
_arrayName = new List<string>();
|
||
if (_controlName.Tag != null && _controlName.Tag.ToString() != "" && _controlName.Text.ToString().Trim() != "")
|
||
{
|
||
string[] id = _controlName.Tag.ToString().Split(',');
|
||
string[] name = _controlName.Text.Trim().Split(',');
|
||
_arrayId = id.ToList();
|
||
_arrayName = name.ToList();
|
||
}
|
||
FullDgv(_arrayId);
|
||
}
|
||
private void FullDgv(List<string> list)
|
||
{
|
||
if (list.Count > 0)
|
||
{
|
||
List<BasicDictionary> anaslist = new List<BasicDictionary>();
|
||
bd.SubItem.ForEach((anas) =>
|
||
{
|
||
if (list.Contains(anas.Id.Value.ToString()))
|
||
anaslist.Add(anas);
|
||
});
|
||
bd.SubItem.ForEach((anas) =>
|
||
{
|
||
if (!list.Contains(anas.Id.Value.ToString()))
|
||
anaslist.Add(anas);
|
||
});
|
||
dgvDictionary.DataSource = anaslist;
|
||
foreach (string id in list)
|
||
{
|
||
foreach (DataGridViewRow row in dgvDictionary.Rows)
|
||
{
|
||
if (row.Cells["Id"].Value.ToString() == id)
|
||
{
|
||
row.Cells["Select"].Value = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
dgvDictionary.DataSource = bd.SubItem;
|
||
}
|
||
if (_dictionaryName == "ASA分级")
|
||
{
|
||
dgvDictionary.Columns["aName"].Width = 65;
|
||
dgvDictionary.Columns["Explain"].Width = 350;
|
||
this.Width += 100;
|
||
}
|
||
if (_dictionaryName == "特殊情况" || _dictionaryName == "术中合并症" || _dictionaryName == "麻醉后随访情况" || _dictionaryName == "手术中特殊问题处理")
|
||
{
|
||
dgvDictionary.Columns["aName"].Width = 350;
|
||
dgvDictionary.Columns["Explain"].Width = 65;
|
||
dgvDictionary.Columns["Explain"].Visible = false;
|
||
}
|
||
}
|
||
private void btnCancel_Click(object sender, EventArgs e)
|
||
{
|
||
this.Close();
|
||
}
|
||
|
||
private void btnEnter_Click(object sender, EventArgs e)
|
||
{
|
||
string names = string.Join(",", _arrayName);
|
||
string ids = string.Join(",", _arrayId);
|
||
_controlName.Text = names;
|
||
_controlName.Tag = ids;
|
||
|
||
|
||
this.Close();
|
||
}
|
||
|
||
private void txtQuery_TextChanged(object sender, EventArgs e)
|
||
{
|
||
DataTable dt = BBasicDictionary.GetBasicDictionaryByKeyName(_dictionaryName, txtQuery.Text);
|
||
dgvDictionary.AutoGenerateColumns = false;
|
||
dgvDictionary.DataSource = dt;
|
||
}
|
||
|
||
private void txtQuery_KeyPress(object sender, KeyPressEventArgs e)
|
||
{
|
||
if (e.KeyChar == 39)
|
||
{
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
|
||
|
||
private void dgvDictionary_CellClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (dgvDictionary.CurrentRow == null) return;
|
||
string id = dgvDictionary.CurrentRow.Cells["Id"].Value.ToString();
|
||
string name = dgvDictionary.CurrentRow.Cells["aName"].Value.ToString();
|
||
if (dgvDictionary.CurrentRow.Cells["Select"].EditedFormattedValue.ToString() == "True")
|
||
{
|
||
dgvDictionary.CurrentRow.Cells["Select"].Value = false;
|
||
if (_arrayId.Contains(id))
|
||
{
|
||
_arrayId.Remove(id);
|
||
}
|
||
if (_arrayName.Contains(name))
|
||
{
|
||
_arrayName.Remove(name);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
dgvDictionary.CurrentRow.Cells["Select"].Value = true;
|
||
if (isRadio == false)
|
||
{
|
||
if (!_arrayId.Contains(id))
|
||
_arrayId.Add(id);
|
||
if (!_arrayName.Contains(name))
|
||
_arrayName.Add(name);
|
||
}
|
||
else
|
||
{
|
||
foreach (DataGridViewRow item in dgvDictionary.Rows)
|
||
{
|
||
DataGridViewCell senderdgvr = item.Cells["Select"];
|
||
if (senderdgvr.EditedFormattedValue.ToString() == "True" && item.Cells["ID"].Value.ToString() != id)
|
||
{
|
||
item.Cells["Select"].Value = false;
|
||
}
|
||
}
|
||
_arrayId = new List<string>();
|
||
_arrayId.Add(id);
|
||
_arrayName = new List<string>();
|
||
_arrayName.Add(name);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void frmSelectDictionary_KeyPress(object sender, KeyPressEventArgs e)
|
||
{
|
||
if (txtQuery.Focused == false)
|
||
{
|
||
txtQuery.Focus();
|
||
txtQuery.Text = "";
|
||
txtQuery.ForeColor = Color.Black;
|
||
if (e.KeyChar > 33 && e.KeyChar < 126)
|
||
{
|
||
txtQuery.Text = e.KeyChar.ToString();
|
||
txtQuery.Select(1, 1);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnAdd_Click(object sender, EventArgs e)
|
||
{
|
||
if (txtQuery.Text == null || txtQuery.Text.Trim() == "")
|
||
{
|
||
MessageBox.Show("名称不能为空!", "系统提示");
|
||
return;
|
||
}
|
||
if (txtQuery.Text.Contains('+') || txtQuery.Text.Contains('-') || txtQuery.Text.Contains(',') || txtQuery.Text.Contains('‘') || txtQuery.Text.Contains('\'') || txtQuery.Text.Contains('\"') || txtQuery.Text.Contains('/') || txtQuery.Text.Contains('*') || txtQuery.Text.Contains('\\') || txtQuery.Text.Contains('?') || txtQuery.Text.Contains('<') || txtQuery.Text.Contains('>') || txtQuery.Text.Contains('|'))
|
||
{
|
||
MessageBox.Show("名称不能包含下列任何字符:\n\r ,\\/:*?\"\'<>|+- ", "系统提示");
|
||
return;
|
||
}
|
||
BasicDictionary basicDictionary = BBasicDictionary.SelectSingle(" name='" + txtQuery.Text.Trim() + "' and parentid='" + bd.Id + "'", null, RecursiveType.None, 0);
|
||
if (basicDictionary == null || basicDictionary.Id == null)
|
||
{
|
||
basicDictionary = new BasicDictionary();
|
||
basicDictionary.ParentId = bd.Id;
|
||
basicDictionary.Name = txtQuery.Text.Trim();
|
||
basicDictionary.HelpCode = PublicMethod.GetFirstLetter(txtQuery.Text.Trim());
|
||
basicDictionary.IsValid = 1;
|
||
basicDictionary.Order = 0;
|
||
basicDictionary.Remark = "";
|
||
basicDictionary.OperatorNo = PublicMethod.OperatorNo;
|
||
basicDictionary.OperatorName = PublicMethod.OperatorName;
|
||
basicDictionary.OperateDate = DateTime.Now;
|
||
basicDictionary.Id = BBasicDictionary.Insert(basicDictionary);
|
||
}
|
||
_controlName.Text = basicDictionary.Name;
|
||
_controlName.Tag = basicDictionary.Id;
|
||
this.Close();
|
||
}
|
||
}
|
||
}
|