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.

198 lines
7.1 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sql
{
public partial class Form41 : Form
{
Form4 form4;
string[] str = new string[4]; //定义范围,只许多不能少
public Form41(Form4 f)
{
InitializeComponent();
button7.Visible = false; //隐藏修改按钮
form4 = f;
}
public Form41(string[] a, Form4 f) //6
{
InitializeComponent();
for (int i = 0; i < 4; i++)
{
str[i] = a[i];
}
textBox1.Text = str[0];
textBox2.Text = str[1];
textBox3.Text = str[2];
textBox4.Text = str[3];
button1.Visible = false; //隐藏保存按钮
form4 = f;
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = null;
}
private void button3_Click(object sender, EventArgs e)
{
textBox2.Text = null;
}
private void button5_Click(object sender, EventArgs e)
{
textBox3.Text = null;
}
private void button6_Click(object sender, EventArgs e)
{
textBox4.Text = null;
}
private void button2_Click(object sender, EventArgs e)
{
if (button1.Visible == false)
{
Close();
}
else if (textBox1.Text != "" || textBox2.Text != "" || textBox3.Text != "" || textBox4.Text != "")
{
DialogResult r = MessageBox.Show("退出后当前输入内容不会保存", "提示", MessageBoxButtons.OKCancel);
if (r == DialogResult.OK)
{
Close();
}
}
else
{
Close();
}
}
//添加
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{
MessageBox.Show("输入不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string sql = "Insert into seat values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
//判断是否有工号重复的,重复则禁止添加
string ID = "select * from seat";
int b = 1;
Dao doo = new Dao();
IDataReader drr = doo.read(ID);
while (drr.Read())
{
string a;
a = drr["Id"].ToString();
if (a == textBox1.Text)
{
MessageBox.Show("工号为" + textBox1.Text + "的座位已经存在\n 请重新添加");
b = 0;
break;
}
}
drr.Close();//关闭连接
if (b != 0)
{
DialogResult r = MessageBox.Show(" 是否确认添加", "提示", MessageBoxButtons.OKCancel);
if (r == DialogResult.OK)
{
Dao dao = new Dao();
int i = dao.Execute(sql);
if (i > 0)
{
MessageBox.Show("添加成功");
textBox1.Text = null; //添加后归空,方便再次添加
textBox2.Text = null;
textBox3.Text = null;
textBox4.Text = null;
}
form4.Table(); //实现实时刷新表
}
}
//判断是否有工号重复的,重复则禁止添加
}
}
//修改
private void button7_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{
MessageBox.Show("修改中有空项", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
//判断是否有工号重复的,重复则禁止添加
string ID = "select * from seat";
int b = 1;
Dao doo = new Dao();
IDataReader drr = doo.read(ID);
while (drr.Read())
{
string a;
a = drr["Id"].ToString();
if (a == textBox1.Text)
{
MessageBox.Show("工号为" + textBox1.Text + "的座位已经存在请重新修改");
b = 0;
break;
}
}
drr.Close();//关闭连接
if (b != 0)
{
if (textBox1.Text != str[0])
{
string sql = "update seat set Id='" + textBox1.Text + "'where Id='" + str[0] + "' and Name='" + str[1] + "'";
Dao dao = new Dao();
dao.Execute(sql);
str[0] = textBox1.Text;
}
if (textBox2.Text != str[1])
{
string sql = "update seat set Name='" + textBox2.Text + "' where Id='" + str[0] + "' and Name='" + str[1] + "'";
Dao dao = new Dao();
dao.Execute(sql);
str[1] = textBox2.Text;
}
if (textBox3.Text != str[2])
{
string sql = "update seat set ZC='" + textBox3.Text + "' where Id='" + str[0] + "' and Name='" + str[1] + "'";
Dao dao = new Dao();
dao.Execute(sql);
str[2] = textBox3.Text;
}
if (textBox4.Text != str[3])
{
string sql = "update seat set Password='" + textBox4.Text + "' where Id='" + str[0] + "' and Name='" + str[1] + "'";
Dao dao = new Dao();
dao.Execute(sql);
str[3] = textBox4.Text;
}
DialogResult r = MessageBox.Show(" 是否确认修改", "提示", MessageBoxButtons.OKCancel);
if (r == DialogResult.OK)
{
form4.Table(); //实现实时刷新表
Close();
}
}
//判断是否有工号重复的,重复则禁止添加
}
}
}
}