260 lines
9.7 KiB
C#
260 lines
9.7 KiB
C#
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 frmApplianceUseType : Form
|
|
{
|
|
/// <summary>
|
|
/// 器械类型集合
|
|
/// </summary>
|
|
public List<ApplianceUseType> list;
|
|
/// <summary>
|
|
/// 声明保存数据时的状态
|
|
/// </summary>
|
|
public EditState _state;
|
|
public frmApplianceUseType()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void frmApplianceUseType_Load(object sender, EventArgs e)
|
|
{
|
|
ControlExtension.EnabledControl(panel1, false);
|
|
txtName.Enabled = true;
|
|
chkAll.Enabled = true;
|
|
BindDgv();
|
|
txtName.TextChanged += new EventHandler(txtName_TextChanged);
|
|
}
|
|
/// <summary>
|
|
/// 为DataGridView绑定数据
|
|
/// </summary>
|
|
private void BindDgv()
|
|
{
|
|
string IsValid = chkAll.Checked == false ? "0" : "1";
|
|
if (IsValid == "1")
|
|
{
|
|
list = BApplianceUseType.Select(" name like '%" + txtName.Text.Trim() + "%' or HCode like '%" + txtName.Text.Trim() + "%'", new ParameterList(), RecursiveType.None, 0);
|
|
}
|
|
else
|
|
{
|
|
list = BApplianceUseType.Select(" IsValid= 1 and ( name like '%" + txtName.Text.Trim() + "%' or HCode like '%" + txtName.Text.Trim() + "%' )", new ParameterList(), RecursiveType.None, 0);
|
|
}
|
|
|
|
dgvApplianceUseType.AutoGenerateColumns = false;
|
|
dgvApplianceUseType.Rows.Clear();
|
|
int num = 1;
|
|
foreach (ApplianceUseType item in list)
|
|
{
|
|
|
|
int index = this.dgvApplianceUseType.Rows.Add();
|
|
this.dgvApplianceUseType.Rows[index].Cells["Id"].Value = item.Id;
|
|
this.dgvApplianceUseType.Rows[index].Cells["Index"].Value = num;
|
|
num++;
|
|
this.dgvApplianceUseType.Rows[index].Cells["oName"].Value = item.Name;
|
|
this.dgvApplianceUseType.Rows[index].Cells["HCode"].Value = item.HCode;
|
|
this.dgvApplianceUseType.Rows[index].Cells["IsValid"].Value = item.IsValid == 1 ? "有效" : "无效";
|
|
if (item.TheApplianceId != "")
|
|
{
|
|
string[] n = item.TheApplianceId.Split(',');
|
|
int a = n.Length;
|
|
this.dgvApplianceUseType.Rows[index].Cells["AppType"].Value = a; ;
|
|
}
|
|
else
|
|
{
|
|
this.dgvApplianceUseType.Rows[index].Cells["AppType"].Value = "0";
|
|
}
|
|
try
|
|
{
|
|
|
|
int number = 0;
|
|
if (item.ApplianceNumber != null && item.ApplianceNumber != "")
|
|
{
|
|
string[] numbes = item.ApplianceNumber.Split(',');
|
|
for (int i = 0; i < numbes.Length; i++)
|
|
number += int.Parse(numbes[i]);
|
|
}
|
|
this.dgvApplianceUseType.Rows[index].Cells["HNumber"].Value = number;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
/// <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.EnabledControl(panel1, true);
|
|
ControlExtension.ClearControl(panel1);
|
|
chkIsValid.Checked = true;
|
|
}
|
|
int autid;
|
|
/// <summary>
|
|
/// 修改事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void tsbModify_Click(object sender, EventArgs e)
|
|
{
|
|
//设置状态为修改
|
|
_state = EditState.EDIT;
|
|
if (!(dgvApplianceUseType.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.EnabledControl(panel1, true);
|
|
autid = Convert.ToInt32(dgvApplianceUseType.SelectedRows[0].Cells["Id"].Value);
|
|
txtName.Text = dgvApplianceUseType.SelectedRows[0].Cells["oName"].Value.ToString();
|
|
txtHCode.Text = dgvApplianceUseType.SelectedRows[0].Cells["HCode"].Value.ToString();
|
|
chkIsValid.Checked = dgvApplianceUseType.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);
|
|
BindDgv();
|
|
}
|
|
/// <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 && dgvApplianceUseType.Rows.Count > 0 && ControlExtension.ValidDataGridViewExistsItemName(dgvApplianceUseType, "oName", txtName.Text.Trim()))
|
|
{
|
|
MessageBox.Show("该级别名称已存在,请重新输入!");
|
|
txtName.Focus();
|
|
return;
|
|
}
|
|
ApplianceUseType aut = new ApplianceUseType();
|
|
if (_state == EditState.EDIT) aut = BApplianceUseType.SelectSingle(autid);
|
|
aut.Name = txtName.Text.Trim();
|
|
aut.HCode = txtHCode.Text.Trim();
|
|
aut.IsValid = chkIsValid.Checked == true ? 1 : 0;
|
|
if (aut.TheApplianceId == null) aut.TheApplianceId = "";
|
|
aut.OperatorId = PublicMethod.OperatorId;
|
|
aut.OperatorTime = DateTime.Now;
|
|
int num = 0;
|
|
if (_state == EditState.ADD)
|
|
{
|
|
num = BApplianceUseType.Insert(aut);
|
|
}
|
|
else if (_state == EditState.EDIT)
|
|
{
|
|
aut.Id = autid;// Convert.ToInt32(dgvApplianceUseType.SelectedRows[0].Cells["Id"].Value);
|
|
num = BApplianceUseType.Update(aut);
|
|
}
|
|
if (num > 0)
|
|
{
|
|
MessageBox.Show("保存成功!");
|
|
tsbCancel_Click(null, null);
|
|
}
|
|
}
|
|
/// <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
|
|
{
|
|
key = true;
|
|
}
|
|
return key;
|
|
}
|
|
/// <summary>
|
|
/// 输入字典名称时为助记码文本框赋值
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void txtName_TextChanged(object sender, EventArgs e)
|
|
{
|
|
BindDgv();
|
|
}
|
|
/// <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);
|
|
}
|
|
/// <summary>
|
|
/// 判断DataGridView是否显示全部记录
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void chkAll_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
BindDgv();
|
|
}
|
|
|
|
private void dgvApplianceUseType_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (dgvApplianceUseType.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex > -1)
|
|
{
|
|
int id = Convert.ToInt32(dgvApplianceUseType.CurrentRow.Cells["Id"].Value);
|
|
frmApplianceSelect fs = new frmApplianceSelect();
|
|
fs._applianceUsetypeId = id;
|
|
fs.ShowDialog();
|
|
}
|
|
}
|
|
}
|
|
}
|