📄 facilityspanel.cs
字号:
{
if (cmdChanged) cmd = cmd + " and 电话='" + tb_tel.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 电话='" + tb_tel.Text + "'";
}
}
if (tb_fuzhe.Text != "")
{
if (cmdChanged) cmd = cmd + " and 负责人='" + tb_fuzhe.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 负责人='" + tb_fuzhe.Text + "'";
}
}
if (tb_jiaofutime.Text != "")
{
if (cmdChanged) cmd = cmd + " and 交付日期'" + tb_jiaofutime.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 交付日期'" + tb_jiaofutime.Text + "'";
}
}
if (tb_sheshiM.Text != "")
{
if (cmdChanged) cmd = cmd + " and 设施金额'" + tb_sheshiM.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 设施金额'" + tb_sheshiM.Text + "'";
}
}
if (tb_user.Text != "")
{
if (cmdChanged) cmd = cmd + " and 使用人员名称'" + tb_user.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 用户'" + tb_user.Text + "'";
}
}
if (tb_usetime.Text != "")
{
if (cmdChanged) cmd = cmd + " and 使用时间'" + tb_usetime.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 使用时间'" + tb_usetime.Text + "'";
}
}
if (tb_useNofP.Text != "")
{
if (cmdChanged) cmd = cmd + " and 使用人数'" + tb_useNofP.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 使用人数'" + tb_useNofP.Text + "'";
}
}
if (tb_useM.Text != "")
{
if (cmdChanged) cmd = cmd + " and 使用金额'" + tb_useM.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 使用金额'" + tb_useM.Text + "'";
}
}
if (tb_usestate.Text != "")
{
if (cmdChanged) cmd = cmd + " and 使用状态'" + tb_usestate.Text + "'";
else
{
cmdChanged = true;
cmd = cmd + "where 使用状态'" + tb_usestate.Text + "'";
}
}*/
return cmds+cmd;
}
private String generateUpdateCommand()
{
String cmd = "";
cmd = String.Format("update 设施信息 set 设施编号={0},设施名称='{1}',承建商='{2}',电话={3},负责人='{4}',", Int64.Parse(tb_SSnum.Text), tb_sheshiName.Text, tb_chengjian.Text, Int64.Parse(tb_tel.Text), tb_fuzhe.Text);
cmd = cmd + String.Format("交付日期='{0}',使用人员名称='{1}',使用时间='{2}',使用次数={3},使用状态='{4}',使用金额={5},设施金额={6}", tb_jiaofutime.Text, tb_user.Text, tb_usetime.Text, tb_useNofP.Text, tb_usestate.Text, float.Parse(tb_useM.Text), float.Parse(tb_sheshiM.Text));
cmd = cmd + String.Format(" where 设施编号={0}", Int64.Parse(tb_SSnum.Text));
return cmd;
}
private String generateInsertCommand()
{
String cmd = "insert into 设施信息 values(";
Int64 id = DateTime.Now.ToBinary();
insertDealID = id;
cmd = cmd + String.Format("{0},'','{1}','{2}',{3},'{4}','{5}',", Int64.Parse(tb_SSnum.Text), tb_sheshiName.Text, tb_chengjian.Text, Int64.Parse(tb_tel.Text), tb_fuzhe.Text,tb_jiaofutime.Text);
cmd = cmd + String.Format("'{0}','{1}',{2},'{3}',{4},{5})", tb_user.Text, tb_usetime.Text, Int64.Parse(tb_useNofP.Text), tb_usestate.Text, float.Parse(tb_useM.Text), float.Parse(tb_sheshiM.Text));
return cmd;
}
private String generateDeleteCommand()
{
String cmd = String.Format("Delete from 设施信息 where 设施编号={0}", dataGridView1.Rows[selectedIndex].Cells["设施编号"].Value);
return cmd;
}
private void btFind_sheshi_Click(object sender, EventArgs e)
{
String cmd;
// if (checkInput("Select") == false) return; //用户输入不合法
cmd = generateSelectCommand(); //根据输入情况生成相应的命令
DataTable dataTable = DBManager.ExecuteSelectCommand(cmd);
if (dataTable == null)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (dataTable.Rows.Count == 0)
{//没有搜索到对应信息,显示一个空的DataGridView
MessageBox.Show("没有查找到任何信息");
// dataGridViewCQRS.DataSource = dataTable;
return;
}
else
{//至少找到一条信息,将信息显示到DataGridView,并将第一条信息详细列出
dataGridView1.DataSource = dataTable;
showDetailInfo(0);
}
}
private void btDel_sheshi_Click(object sender, EventArgs e)
{
String cmd = generateDeleteCommand();
int affectRows = DBManager.Execute(cmd);
if (affectRows == -1)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (affectRows == 0)
{
MessageBox.Show("此数据已被其他登陆用户删除");
}
MessageBox.Show(selectedIndex + "");
if (selectedIndex == dataGridView1.Rows.Count - 2)
{
dataGridView1.Rows.Remove(dataGridView1.Rows[selectedIndex]);
selectedIndex--;
if (selectedIndex == -1)
{//若dataGridView1没有数据则重置界面
reset();
dataGridView1.DataSource = DBManager.ExecuteSelectCommand("select 设施编号,设施名称,承建商,电话,负责人,交付日期,使用人员名称,使用时间,使用次数,使用状态,使用金额,设施金额 from 设施信息");
return;
}
}
else dataGridView1.DataSource = DBManager.ExecuteSelectCommand("select 设施编号,设施名称,承建商,电话,负责人,交付日期,使用人员名称,使用时间,使用次数,使用状态,使用金额,设施金额 from 设施信息");
//dataGridView1.Rows.Remove(dataGridView1.Rows[selectedIndex]);
}
private void btAdd_sheshi_Click_1(object sender, EventArgs e)
{
String cmd;
if (checkInput("Insert") == false) return;//用户输入错误
cmd = generateSelectCommand(); //首先查找数据库中有没有相同内容的行
DataTable dataTable = DBManager.ExecuteSelectCommand(cmd);
if (dataTable == null)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (dataTable.Rows.Count > 0)
{
MessageBox.Show("数据库中已存在相同信息");
return;
}
//将信息添加到数据库
cmd = generateInsertCommand(); //根据输入情况生成相应的命令
int affectedRows = DBManager.Execute(cmd);
if (affectedRows == -1)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (affectedRows == 0)
{//
MessageBox.Show("插入失败");
return;
}
else
{//插入成功,
showDetailInfo(selectedIndex);//显示插入前的一行
dataGridView1.DataSource = DBManager.ExecuteSelectCommand("select 设施编号,设施名称,承建商,电话,负责人,交付日期,使用人员名称,使用时间,使用次数,使用状态,使用金额,设施金额 from 设施信息");
MessageBox.Show("插入成功!");
}
}
private void btXiug_sheshi_Click(object sender, EventArgs e)
{
String cmd;
if (checkInput("Modify") == false) return; //用户输入不合法
cmd = generateUpdateCommand(); //根据输入情况生成相应的命令
int affectRows = DBManager.Execute(cmd);
if (affectRows == -1)
{ //数据库出错
MessageBox.Show(DBManager.errorMessage);
return;
}
else if (affectRows == 0)
{//没有搜索到对应信息
MessageBox.Show("设施编号不能修改");
return;
}
else
{
MessageBox.Show("修改成功!");
dataGridView1.DataSource = DBManager.ExecuteSelectCommand("select 设施编号,设施名称,承建商,电话,负责人,交付日期,使用人员名称,使用时间,使用次数,使用状态,使用金额,设施金额 from 设施信息");
//成功修改,更新dataGridView1
}
}
private void tb_tel_TextChanged(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -