278 lines
10 KiB
C#
278 lines
10 KiB
C#
using AIMSBLL;
|
|
using AIMSExtension;
|
|
using AIMSModel;
|
|
using DrawGraph;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AIMS.PublicUI.UI
|
|
{
|
|
public partial class frmChargsTemplateNew : Form
|
|
{
|
|
/// <summary>
|
|
/// 收费类型集合
|
|
/// </summary>
|
|
public List<ChargsTemplate> list;
|
|
/// <summary>
|
|
/// 声明保存数据时的状态
|
|
/// </summary>
|
|
public EditState _state;
|
|
|
|
public string TemplateType;
|
|
public frmChargsTemplateNew()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void frmApplianceUseType_Load(object sender, EventArgs e)
|
|
{
|
|
if (PublicMethod.OperatorNo == "admin" || PublicMethod.RoleName.Contains("创建收费模板"))
|
|
{
|
|
chkAll.Visible = true;
|
|
tsbAdd.Visible = true;
|
|
tsbModify.Visible = true;
|
|
tsbSave.Visible = true;
|
|
toolStripSeparator2.Visible = true;
|
|
toolStripSeparator4.Visible = true;
|
|
panel1.Visible = true;
|
|
dgvApplianceUseType.Columns["IsValid"].Visible = true;
|
|
dgvApplianceUseType.Columns["SelectC"].Visible = true;
|
|
}
|
|
|
|
ControlExtension.EnabledControl(panel1, false);
|
|
txtName.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 = BChargsTemplate.Select(" TemplateType='" + TemplateType + "' and TemplateName like '%" + txtName.Text.Trim() + "%' or HCode like '%" + txtName.Text.Trim() + "%'", new ParameterList(), RecursiveType.None, 0);
|
|
}
|
|
else
|
|
{
|
|
list = BChargsTemplate.Select(" TemplateType='" + TemplateType + "' and IsValid= 1 and ( TemplateName 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 (ChargsTemplate 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.TemplateName;
|
|
this.dgvApplianceUseType.Rows[index].Cells["HCode"].Value = item.HCode;
|
|
this.dgvApplianceUseType.Rows[index].Cells["IsValid"].Value = item.IsValid == 1 ? "有效" : "无效";
|
|
}
|
|
dgvApplianceUseType.ClearSelection();
|
|
}
|
|
/// <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;
|
|
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)
|
|
{
|
|
ChargsTemplate temp = BChargsTemplate.SelectSingle(" TemplateName='" + txtName.Text.Trim() + "'", null);
|
|
if (temp != null && temp.Id > 0)
|
|
{
|
|
MessageBox.Show("该模板已存在,请重新输入!");
|
|
txtName.Focus();
|
|
return;
|
|
}
|
|
}
|
|
ChargsTemplate aut = new ChargsTemplate();
|
|
if (_state == EditState.EDIT) aut = BChargsTemplate.SelectSingle(autid);
|
|
aut.TemplateType = TemplateType;
|
|
aut.TemplateName = txtName.Text.Trim();
|
|
aut.HCode = txtHCode.Text.Trim();
|
|
aut.IsValid = chkIsValid.Checked == true ? 1 : 0;
|
|
aut.OperatorId = PublicMethod.OperatorId;
|
|
aut.OperatorTime = DateTime.Now;
|
|
int num = 0;
|
|
if (_state == EditState.ADD)
|
|
{
|
|
num = BChargsTemplate.Insert(aut);
|
|
}
|
|
else if (_state == EditState.EDIT)
|
|
{
|
|
aut.Id = autid;
|
|
num = BChargsTemplate.Update(aut);
|
|
}
|
|
if (num > 0)
|
|
{
|
|
new frmMessageBox().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);
|
|
dgvApplianceUseType.CurrentRow.Cells["check"].Value = false;
|
|
this.Tag = null;
|
|
frmChargSelect fs = new frmChargSelect(id);
|
|
fs.ShowDialog();
|
|
dgvApplianceUseType.ClearSelection();
|
|
}
|
|
}
|
|
|
|
public List<string> SelTemps;
|
|
private void dgvApplianceUseType_Click(object sender, EventArgs e)
|
|
{
|
|
if (dgvApplianceUseType.CurrentRow == null) return;
|
|
string oName = dgvApplianceUseType.CurrentRow.Cells["oName"].Value.ToString();
|
|
if (SelTemps == null) SelTemps = new List<string>();
|
|
string id = dgvApplianceUseType.CurrentRow.Cells["Id"].Value.ToString();
|
|
if (dgvApplianceUseType.CurrentRow.Cells["check"].EditedFormattedValue.ToString() == "True")
|
|
{
|
|
dgvApplianceUseType.CurrentRow.Cells["check"].Value = false;
|
|
if (SelTemps.Contains(oName)) SelTemps.Remove(oName);
|
|
this.Tag = SelTemps;
|
|
}
|
|
else
|
|
{
|
|
dgvApplianceUseType.CurrentRow.Cells["check"].Value = true;
|
|
if (!SelTemps.Contains(oName)) SelTemps.Add(oName);
|
|
this.Tag = SelTemps;
|
|
|
|
}
|
|
}
|
|
|
|
private void dgvApplianceUseType_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
//this.Close();
|
|
}
|
|
}
|
|
}
|