261 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			261 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using AIMS;
 | ||
| using AIMSBLL;
 | ||
| using AIMSExtension;
 | ||
| using AIMSModel;
 | ||
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.ComponentModel;
 | ||
| using System.Data;
 | ||
| using System.Drawing;
 | ||
| using System.Linq;
 | ||
| using System.Text;
 | ||
| using System.Windows.Forms;
 | ||
| 
 | ||
| namespace DataDictionary.UI
 | ||
| {
 | ||
|     public partial class frmAnaesthesiaMethod : Form
 | ||
|     {
 | ||
|         /// <summary>
 | ||
|         /// 麻醉字典集合
 | ||
|         /// </summary>
 | ||
|         private List<AnaesthesiaMethod> list;
 | ||
|         private EditState state = EditState.BROWSE;
 | ||
|         /// <summary>
 | ||
|         /// 编号
 | ||
|         /// </summary>
 | ||
|         public int pid;
 | ||
|         public frmAnaesthesiaMethod()
 | ||
|         {
 | ||
|             InitializeComponent();
 | ||
|         }
 | ||
| 
 | ||
|         private void frmAnaesthesiaMethod_Load(object sender, EventArgs e)
 | ||
|         {
 | ||
|             Initial();
 | ||
|             //FullTreeView(list);
 | ||
|             ControlExtension.EnabledControl(panel1, false);
 | ||
|         }
 | ||
|         /// <summary>
 | ||
|         /// 初始化TreeView
 | ||
|         /// </summary>
 | ||
|         private void Initial()
 | ||
|         {
 | ||
|             list = BAnaesthesiaMethod.Select("  IsValid=1 ", new ParameterList(), RecursiveType.None, 0);
 | ||
|             tvDictionary.Nodes.Clear();
 | ||
|             //设置根节点
 | ||
|             TreeNode rootNode = new TreeNode("麻醉方式");
 | ||
|             FillTvTreeNode(rootNode, 0);
 | ||
|             tvDictionary.Nodes.Add(rootNode);
 | ||
|             tvDictionary.Nodes[0].Expand();
 | ||
|             //初始化ComboBox
 | ||
|             List<AnaesthesiaMethod> sList = list;
 | ||
|             sList.Insert(0, new AnaesthesiaMethod() { Id = -1, Name = "" });
 | ||
|             cboDict.DataSource = sList;
 | ||
|             cboDict.DisplayMember = "Name";
 | ||
|             cboDict.ValueMember = "Id";
 | ||
|         }
 | ||
| 
 | ||
|         private void FillTvTreeNode(TreeNode node, int ParentId)
 | ||
|         {
 | ||
|             foreach (AnaesthesiaMethod sAnaes in list)
 | ||
|             {
 | ||
|                 if (sAnaes.ParentId == ParentId)
 | ||
|                 {
 | ||
|                     TreeNode sNode = new TreeNode(sAnaes.Name);
 | ||
|                     sNode.Tag = sAnaes;
 | ||
|                     FillTvTreeNode(sNode, sAnaes.Id.Value);
 | ||
|                     node.Nodes.Add(sNode);
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void tsbExit_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             this.Close();
 | ||
|         }
 | ||
|         private void FullDgv(AnaesthesiaMethod anaes)
 | ||
|         {
 | ||
|             cboDict.Text = anaes.Name;
 | ||
|             dgvDictionary.AutoGenerateColumns = false;
 | ||
|             dgvDictionary.Rows.Clear();
 | ||
|             int num = 1;
 | ||
|             anaes.Children = list.Where(a => a.ParentId == anaes.Id).ToList();
 | ||
|             foreach (AnaesthesiaMethod sAnaes in anaes.Children)
 | ||
|             {
 | ||
|                 int index = this.dgvDictionary.Rows.Add();
 | ||
|                 this.dgvDictionary.Rows[index].Cells["Id"].Value = sAnaes.Id;
 | ||
|                 this.dgvDictionary.Rows[index].Cells["Index"].Value = num;
 | ||
|                 num++;
 | ||
|                 this.dgvDictionary.Rows[index].Cells["aName"].Value = sAnaes.Name;
 | ||
|                 this.dgvDictionary.Rows[index].Cells["HCode"].Value = sAnaes.HelpCode;
 | ||
|                 this.dgvDictionary.Rows[index].Cells["pName"].Value = anaes.Name;
 | ||
|                 this.dgvDictionary.Rows[index].Cells["UseRate"].Value = sAnaes.UseRate;
 | ||
|                 this.dgvDictionary.Rows[index].Cells["IsValid"].Value = sAnaes.IsValid == 1 ? "有效" : "无效";
 | ||
|                 this.dgvDictionary.Rows[index].Cells["Explain"].Value = sAnaes.Explain;
 | ||
|             }
 | ||
|         }
 | ||
|         private void tsbAdd_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (tvDictionary.SelectedNode == null)
 | ||
|             {
 | ||
|                 MessageBox.Show("请选择麻醉目录");
 | ||
|                 return;
 | ||
|             }
 | ||
|             state = EditState.ADD;
 | ||
|             chkIsValid.Checked = true;
 | ||
|             if (tvDictionary.SelectedNode.Level == 0)
 | ||
|             {
 | ||
|                 lblts.Text = "当前状态为:添加新麻醉类型";
 | ||
|                 ControlExtension.EnabledControl(panel1, true);
 | ||
|                 cboDict.Enabled = false;
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 lblts.Text = "当前状态为:为" + tvDictionary.SelectedNode.Text + "添加新麻醉方式";
 | ||
|                 ControlExtension.EnabledControl(panel1, true);
 | ||
|                 cboDict.Enabled = false;
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void tsbModify_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (dgvDictionary.SelectedRows.Count < 1)
 | ||
|             {
 | ||
|                 MessageBox.Show("请从列表中选择要修改的麻醉方式!");
 | ||
|                 return;
 | ||
|             }
 | ||
|             state = EditState.EDIT;
 | ||
|             pid = Convert.ToInt32(dgvDictionary.SelectedRows[0].Cells["Id"].Value);
 | ||
|             txtName.Text = dgvDictionary.SelectedRows[0].Cells["aName"].Value.ToString();
 | ||
|             txtHCode.Text = dgvDictionary.SelectedRows[0].Cells["HCode"].Value.ToString();
 | ||
|             if (dgvDictionary.SelectedRows[0].Cells["Explain"].Value != null)
 | ||
|                 txtHqms.Text = dgvDictionary.SelectedRows[0].Cells["Explain"].Value.ToString();
 | ||
|             chkIsValid.Checked = dgvDictionary.SelectedRows[0].Cells["IsValid"].Value.ToString() == "有效" ? true : false;
 | ||
|             intDepOrder.Text = dgvDictionary.SelectedRows[0].Cells["UseRate"].Value.ToString();
 | ||
|             txtName.Enabled = true;
 | ||
|             txtHCode.Enabled = true;
 | ||
|             intDepOrder.Enabled = true;
 | ||
|             chkIsValid.Enabled = true;
 | ||
|             txtHqms.Enabled = true;
 | ||
|         }
 | ||
| 
 | ||
|         private void tsbCancel_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             ControlExtension.EnabledControl(panel1, false);
 | ||
|             ControlExtension.ClearControl(panel1);
 | ||
|             lblts.Text = "";
 | ||
|             state = EditState.BROWSE;
 | ||
|         }
 | ||
| 
 | ||
|         private void tsbSave_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             foreach (DataGridViewRow row in dgvDictionary.Rows)
 | ||
|             {
 | ||
|                 if (state != EditState.EDIT && (row.Cells["aName"].Value.ToString() == txtName.Text.Trim()))
 | ||
|                 {
 | ||
|                     MessageBox.Show("麻醉方式已存在,请重新输入");
 | ||
|                     txtName.Text = "";
 | ||
|                     txtName.Focus();
 | ||
|                     return;
 | ||
|                 }
 | ||
|             }
 | ||
|             if (ValidInput())
 | ||
|             {
 | ||
|                 AnaesthesiaMethod anaes = new AnaesthesiaMethod();
 | ||
|                 string nodeName = cboDict.Text.Trim();
 | ||
|                 if (Convert.ToInt32(cboDict.SelectedValue) > 0)
 | ||
|                 {
 | ||
|                     anaes.ParentId = Convert.ToInt32(cboDict.SelectedValue);
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     anaes.ParentId = 0;
 | ||
|                 }
 | ||
|                 anaes.Name = txtName.Text.Trim();
 | ||
|                 anaes.HelpCode = txtHCode.Text.Trim();
 | ||
|                 anaes.IsValid = chkIsValid.Checked == true ? 1 : 0;
 | ||
|                 if (intDepOrder.Text.Trim().Length > 0)
 | ||
|                 {
 | ||
|                     anaes.UseRate = int.Parse(intDepOrder.Text.Trim());
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     anaes.UseRate = 0;
 | ||
|                 }
 | ||
|                 anaes.Explain = txtHqms.Text.Trim();
 | ||
|                 anaes.OperatorNo = PublicMethod.OperatorNo;
 | ||
|                 anaes.OperatorName = PublicMethod.OperatorName;
 | ||
|                 anaes.OperateDate = DateTime.Now;
 | ||
|                 int n = 0;
 | ||
|                 if (state == EditState.ADD)
 | ||
|                 {
 | ||
|                     n = BAnaesthesiaMethod.Insert(anaes);
 | ||
|                 }
 | ||
|                 else if (state == EditState.EDIT)
 | ||
|                 {
 | ||
|                     anaes.Id = pid;
 | ||
|                     n = BAnaesthesiaMethod.Update(anaes);
 | ||
|                 }
 | ||
|                 if (n > 0)
 | ||
|                 {
 | ||
|                     MessageBox.Show("保存成功!");
 | ||
|                     ControlExtension.EnabledControl(panel1, false);
 | ||
|                     ControlExtension.ClearControl(panel1);
 | ||
|                 }
 | ||
|                 Initial();
 | ||
|                 state = EditState.BROWSE;
 | ||
|                 foreach (TreeNode node in tvDictionary.Nodes[0].Nodes)
 | ||
|                 {
 | ||
|                     if (node.Text == nodeName)
 | ||
|                     {
 | ||
|                         AnaesthesiaMethod sbd = node.Tag as AnaesthesiaMethod;
 | ||
|                         FullDgv(sbd);
 | ||
|                         break;
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
|         /// <summary>
 | ||
|         /// 输入字典名称时为助记码文本框赋值
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         private void txtName_TextChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             txtHCode.Text = PublicMethod.GetFirstLetter(txtName.Text);
 | ||
|         }
 | ||
|         /// <summary>
 | ||
|         /// 输入验证
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         private bool ValidInput()
 | ||
|         {
 | ||
|             bool key = false;
 | ||
|             if (txtName.Text.Trim().Length < 1)
 | ||
|             {
 | ||
|                 MessageBox.Show("请输入名称!");
 | ||
|             }
 | ||
|             else if (txtHCode.Text.Trim().Length < 1)
 | ||
|             {
 | ||
|                 MessageBox.Show("请输入助记码!");
 | ||
|             }
 | ||
|             else if (txtHqms.Text.Trim().Length < 1)
 | ||
|             {
 | ||
|                 MessageBox.Show("请输HQMS编码!");
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 key = true;
 | ||
|             }
 | ||
|             return key;
 | ||
|         }
 | ||
| 
 | ||
|         private void tvDictionary_AfterSelect(object sender, TreeViewEventArgs e)
 | ||
|         {
 | ||
|             if (tvDictionary.SelectedNode.Level <= 0) return;
 | ||
|             AnaesthesiaMethod bd = tvDictionary.SelectedNode.Tag as AnaesthesiaMethod;
 | ||
|             FullDgv(bd);
 | ||
|         }
 | ||
|     }
 | ||
| }
 |