You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
8.8 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DBFactory;
using Microsoft.VisualBasic;
namespace SystemConfig
{
public partial class FrmDeviceCommand : Form
{
DBOperator dbo = CStaticClass.dbo;
bool IfUpdate = false;
private static FrmDeviceCommand _formInstance;
public static FrmDeviceCommand FormInstance
{
get
{
if (_formInstance == null)
{
_formInstance = new FrmDeviceCommand();
}
return FrmDeviceCommand._formInstance;
}
set { FrmDeviceCommand._formInstance = value; }
}
public FrmDeviceCommand()
{
InitializeComponent();
_formInstance = this;
}
private void btSave_Click(object sender, EventArgs e)
{
if (MessageBox.Show("��ȷ��Ҫ�����豸���͵�������Ϣ����", "������ʾ��", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
string sql = "";
string strsql;
if (Information.IsNumeric(this.cbDeviceKindIndex.Text) == false)
{
MessageBox.Show("�豸��������ֻ�����������ͣ�", "��������ʾ��", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (Information.IsNumeric(this.tbDeviceCommandIndex.Text) == false)
{
MessageBox.Show("�豸��������ֻ�����������ͣ�", "��������ʾ��", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (this.tbDeviceCommandName.Text.Trim().Length == 0)
{
MessageBox.Show("�豸�������Ʋ������ǿ�ֵ��", "��������ʾ��", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
DataSet ds;
strsql = "SELECT F_DeviceKindIndex, F_DeviceCommandIndex, F_DeviceCommandName FROM T_Base_Device_Command WHERE F_DeviceKindIndex = " +Convert.ToInt32( this.cbDeviceKindIndex.Text.Trim()) + " and F_DeviceCommandIndex= "+Convert.ToInt32( this.tbDeviceCommandIndex.Text.Trim()) ;
if (dbo.Exists(strsql) == false)
{
IfUpdate = false;
}
if (IfUpdate == true)
{
sql = "update T_Base_Device_Command set F_DeviceCommandName= '" + this.tbDeviceCommandName.Text + "' where F_DeviceKindIndex= " +Convert.ToInt32( this.cbDeviceKindIndex.Text.Trim()) + " and F_DeviceCommandIndex=" +Convert.ToInt32( this.tbDeviceCommandIndex.Text.Trim()) ;
ds = dbo.ExceSQL(sql);
MessageBox.Show("�豸������Ϣ�޸ijɹ���", "������ʾ��", MessageBoxButtons.OK, MessageBoxIcon.Information);
IfUpdate = false;
}
else
{
strsql = "SELECT F_DeviceKindIndex, F_DeviceCommandIndex, F_DeviceCommandName FROM T_Base_Device_Command WHERE F_DeviceKindIndex = " +Convert.ToInt32( this.cbDeviceKindIndex.Text.Trim()) + " and F_DeviceCommandIndex=" +Convert.ToInt32( this.tbDeviceCommandIndex.Text.Trim()) + "";
if (dbo.Exists(strsql) == true)
{
MessageBox.Show("�豸�����������������������������ظ���ֵ��", "��������ʾ��", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
sql = "INSERT INTO T_Base_Device_Command (F_DeviceKindIndex, F_DeviceCommandIndex,F_DeviceCommandName)VALUES (" + Convert.ToInt32(this.cbDeviceKindIndex.Text) + "," + Convert.ToInt32(this.tbDeviceCommandIndex.Text) + ",'" + this.tbDeviceCommandName.Text + "')";
ds = dbo.ExceSQL(sql);
MessageBox.Show("�豸������Ϣ¼���ɹ���", "������ʾ��", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
ds.Clear();
strsql = "SELECT F_DeviceKindIndex AS �豸��������,F_DeviceCommandIndex AS �豸��������,F_DeviceCommandName AS " +
" �豸�������� FROM T_Base_Device_Command where " +
" F_DeviceCommandIndex= " + Convert.ToInt32(this.tbDeviceCommandIndex.Text) + " and F_DeviceKindIndex = " +Convert.ToInt32( this.cbDeviceKindIndex.Text) + "";
ds = dbo.ExceSQL(strsql);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
private void btQuery_Click(object sender, EventArgs e)
{
//�豸��������
//�豸��������
try
{
string df, sql;
if (this.tbContent.Text.Trim() == "") return;
if (this.cbField.Text == "�豸��������")
{
df = "F_DeviceKindIndex";
}
else
{
df = "F_DeviceCommandIndex";
}
sql = "SELECT F_DeviceKindIndex AS �豸��������,F_DeviceCommandIndex AS �豸��������,F_DeviceCommandName AS " +
" �豸�������� FROM T_Base_Device_Command where " +
df + "= " + Convert.ToInt32(this.tbContent.Text);
DataSet ds = dbo.ExceSQL(sql);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
throw ex;
}
}
private void btNullQuery_Click(object sender, EventArgs e)
{
cbField.Text = "";
tbContent.Text = "";
}
private void btNull_Click(object sender, EventArgs e)
{
this.cbDeviceKindIndex.Text = "";
this.textBox3.Text = "";
this.tbDeviceCommandIndex.Text = "";
this.tbDeviceCommandName.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
IfUpdate = false;
}
private void FrmDeviceCommand_Load(object sender, EventArgs e)
{
DataSet ds = dbo.ExceSQL("SELECT F_DeviceKindIndex, F_DeviceKindName FROM T_Base_Device_Kind");
DataView dv = ds.Tables[0].DefaultView;
if (dv.Count > 0)
{
this.cbDeviceKindIndex.ValueMember = "F_DeviceKindIndex";
this.cbDeviceKindIndex.DisplayMember = "F_DeviceKindIndex";
this.cbDeviceKindIndex.DataSource = dv;
}
}
private void cbDeviceKindIndex_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = dbo.ExceSQL("SELECT F_DeviceKindIndex, F_DeviceKindName FROM T_Base_Device_Kind Where F_DeviceKindIndex='" + cbDeviceKindIndex.Text.Trim()+"'");
DataView dv = ds.Tables[0].DefaultView;
if (dv.Count > 0)
{
textBox3.Text = dv[0]["F_DeviceKindName"].ToString();
}
}
private void tsmEdit_Click(object sender, EventArgs e)
{
if (dataGridView1.RowCount <= 0)
{
return;
}
this.tabControl1.SelectTab("tabPage1");
this.cbDeviceKindIndex.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString() + "";
cbDeviceKindIndex_SelectedIndexChanged(sender, e);
this.tbDeviceCommandIndex.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString() + "";
this.tbDeviceCommandName.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString() + "";
IfUpdate = true;
}
private void tsmDel_Click(object sender, EventArgs e)
{
if (dataGridView1.RowCount <= 0)
{
return;
}
if (MessageBox.Show("��ȷ��Ҫɾ��ѡ���еġ��豸����������" + this.dataGridView1.CurrentRow.Cells[0].Value.ToString() + "�������豸��������:" + this.dataGridView1.CurrentRow.Cells[1].Value.ToString() + "��Ϣ����", "������ʾ��", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
dbo.ExceSQL("delete from T_Base_Device_Kind where F_DeviceKindIndex =" + Convert.ToInt32(this.dataGridView1.CurrentRow.Cells[0].Value) + " and F_DeviceCommandIndex="+ Convert.ToInt32(this.dataGridView1.CurrentRow.Cells[1].Value));
button2_Click(sender, e);
}
private void button2_Click(object sender, EventArgs e)
{
string sql = "SELECT F_DeviceKindIndex AS �豸��������,F_DeviceCommandIndex AS �豸��������,F_DeviceCommandName AS " +
" �豸�������� FROM T_Base_Device_Command";
DataSet ds = dbo.ExceSQL(sql);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
}
}