AIMS/AIMS.UI/DataDictionary/frmAppliance.cs
2023-08-13 21:05:09 +08:00

299 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
using AIMSBLL;
using AIMSExtension;
using AIMSModel;
namespace AIMS.PublicUI.UI
{
public partial class frmAppliance : Form
{
/// <summary>
/// 器械集合全部
/// </summary>
public List<Appliance> list;
/// <summary>
/// 器械集合有效
/// </summary>
public List<Appliance> validlist;
/// <summary>
/// 声明保存数据时的状态
/// </summary>
public EditState _state;
/// <summary>
/// 编号
/// </summary>
public int numberId;
public frmAppliance()
{
InitializeComponent();
}
private void frmAppliance_Load(object sender, EventArgs e)
{
Initial();
chkAll_CheckedChanged(null, null);
txtName.Enabled = true;
txtName.TextChanged += new EventHandler(txtName_TextChanged);
}
private void Initial()
{
ControlExtension.EnabledControl(panel1, false);
chkAll.Enabled = true;
list = BAppliance.Select();
}
/// <summary>
/// 为DataGridView绑定数据
/// </summary>
private void BindDgv(List<Appliance> list)
{
dgvAppliance.AutoGenerateColumns = false;
dgvAppliance.Rows.Clear();
int num = 1;
foreach (Appliance item in list)
{
int index = this.dgvAppliance.Rows.Add();
this.dgvAppliance.Rows[index].Cells["Id"].Value = item.Id;
this.dgvAppliance.Rows[index].Cells["Index"].Value = num;
num++;
this.dgvAppliance.Rows[index].Cells["oName"].Value = item.Name;
this.dgvAppliance.Rows[index].Cells["HCode"].Value = item.HCode;
this.dgvAppliance.Rows[index].Cells["Type"].Value = GetTypeNameByCode(Convert.ToInt32(item.ApplianceType));
this.dgvAppliance.Rows[index].Cells["UseRate"].Value = item.UseRate;
this.dgvAppliance.Rows[index].Cells["IsValid"].Value = item.IsValid == 1 ? "有效" : "无效";
}
}
/// <summary>
/// 根据器械类型编码得到器械类型名称
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
private string GetTypeNameByCode(int code)
{
string typeName = string.Empty;
switch (code)
{
case 0:
typeName = "器械";
break;
case 1:
typeName = "敷料";
break;
case 9:
typeName = "其它";
break;
}
return typeName;
}
/// <summary>
/// 根据器械类型名称得到器械类型编码
/// </summary>
/// <param name="typeName"></param>
/// <returns></returns>
private int GetCodeByTypeName(string typeName)
{
int code = 0;
switch (typeName)
{
case "器械":
code = 0;
break;
case "敷料":
code = 1;
break;
case "其它":
code = 9;
break;
}
return code;
}
/// <summary>
/// 退出事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbExit_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// 新增事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbAdd_Click(object sender, EventArgs e)
{
//设置状态为新增
_state = EditState.ADD;
txtName.TextChanged -= new EventHandler(txtName_TextChanged);
txtName.TextChanged += new EventHandler(txtName_TextChanged_1);
ControlExtension.ClearControl(panel1);
ControlExtension.EnabledControl(panel1, true);
chkIsValid.Checked = true;
cboType.Text = "器械";
}
/// <summary>
/// 修改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbModify_Click(object sender, EventArgs e)
{
//设置状态为修改
_state = EditState.EDIT;
if (!(dgvAppliance.SelectedRows.Count > 0))
{
MessageBox.Show("请选择列表中的一项!");
return;
}
txtName.TextChanged -= new EventHandler(txtName_TextChanged);
txtName.TextChanged -= new EventHandler(txtName_TextChanged);
txtName.TextChanged += new EventHandler(txtName_TextChanged_1);
//ControlExtension.ClearControl(panel1);
ControlExtension.EnabledControl(panel1, true);
numberId = Convert.ToInt32(dgvAppliance.SelectedRows[0].Cells["Id"].Value);
txtName.Text = dgvAppliance.SelectedRows[0].Cells["oName"].Value.ToString();
txtHCode.Text = dgvAppliance.SelectedRows[0].Cells["HCode"].Value.ToString();
cboType.Text = dgvAppliance.SelectedRows[0].Cells["Type"].Value.ToString();
chkIsValid.Checked = dgvAppliance.SelectedRows[0].Cells["IsValid"].Value.ToString() == "有效" ? true : false;
}
/// <summary>
/// 取消事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbCancel_Click(object sender, EventArgs e)
{
ControlExtension.ClearControl(panel1);
ControlExtension.EnabledControl(panel1, false);
txtName.Enabled = true;
chkAll.Enabled = true;
txtName.TextChanged -= new EventHandler(txtName_TextChanged_1);
txtName.TextChanged -= new EventHandler(txtName_TextChanged);
txtName.TextChanged += new EventHandler(txtName_TextChanged);
chkAll_CheckedChanged(null, null);
}
/// <summary>
/// 保存数据事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbSave_Click(object sender, EventArgs e)
{
if (!ValidInput())
{
return;
}
if (_state == EditState.ADD && dgvAppliance.Rows.Count > 0 && ControlExtension.ValidDataGridViewExistsItemName(dgvAppliance, "oName", txtName.Text.Trim()))
{
MessageBox.Show("该器械名称已存在,请重新输入!/r/n或选择器械使用类型后保存");
txtName.Focus();
return;
}
Appliance app = new Appliance();
app.Name = txtName.Text.Trim();
app.HCode = txtHCode.Text.Trim();
app.ApplianceType = GetCodeByTypeName(cboType.Text);
app.IsValid = chkIsValid.Checked == true ? 1 : 0;
app.OperatorId = PublicMethod.OperatorId;
app.OperatorTime = DateTime.Now;
int num = 0;
if (_state == EditState.ADD)
{
app.UseRate = 0;
num = BAppliance.Insert(app);
if (num > 0)
{
MessageBox.Show("保存成功!");
tsbCancel_Click(null, null);
}
}
else if (_state == EditState.EDIT)
{
app.Id = numberId;// Convert.ToInt32(dgvAppliance.SelectedRows[0].Cells["Id"].Value);
app.UseRate = Convert.ToInt32(dgvAppliance.SelectedRows[0].Cells["UseRate"].Value);
num = BAppliance.Update(app);
if (num > 0)
{
MessageBox.Show("修改成功!");
dgvAppliance.SelectedRows[0].Cells["oName"].Value = txtName.Text.ToString();
dgvAppliance.SelectedRows[0].Cells["HCode"].Value = txtHCode.Text.ToString();
dgvAppliance.SelectedRows[0].Cells["Type"].Value = cboType.Text.ToString();
dgvAppliance.SelectedRows[0].Cells["IsValid"].Value = chkIsValid.Checked == true ? "有效" : "无效";
ControlExtension.ClearControl(panel1);
ControlExtension.EnabledControl(panel1, false);
txtName.Enabled = true;
chkAll.Enabled = true;
txtName.TextChanged -= new EventHandler(txtName_TextChanged_1);
txtName.TextChanged -= new EventHandler(txtName_TextChanged);
txtName.TextChanged += new EventHandler(txtName_TextChanged);
}
}
}
/// <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 (cboType.Text.Trim().Length < 1)
{
MessageBox.Show("请选择器械类别!", "系统提示");
}
else
{
key = true;
}
return key;
}
/// <summary>
/// 输入字典名称时为助记码文本框赋值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtName_TextChanged(object sender, EventArgs e)
{
chkAll_CheckedChanged(null, null);
}
/// <summary>
/// 输入字典名称时为助记码文本框赋值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtName_TextChanged_1(object sender, EventArgs e)
{
txtHCode.Text = PublicMethod.GetFirstLetter(txtName.Text);
}
private void chkAll_CheckedChanged(object sender, EventArgs e)
{
if (chkAll.Checked)
{
list = BAppliance.Select(" name like '%" + txtName.Text + "%' or HCode like '%" + txtName.Text + "%' ", null);
BindDgv(list);
}
else
{
validlist = BAppliance.Select(" IsValid=1 and (name like '%" + txtName.Text + "%' or HCode like '%" + txtName.Text + "%')", null);
BindDgv(validlist);
}
}
}
}