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.

146 lines
5.3 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 Form312 : Form
{
Form311 form311;
string[] str = new string[4]; //定义范围,只许多不能少
public Form312(Form311 f)
{
InitializeComponent();
form311 = f;
}
private void button2_Click(object sender, EventArgs e)
{
if (button1.Visible == false)
{
Close();
}
else if (textBox1.Text != "" || textBox2.Text != "" || textBox3.Text != "" || textBox4.Text != ""|| textBox5.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 == ""|| textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || textBox8.Text == "")
{
MessageBox.Show("输入不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string sql = "Insert into Book(Id,Name,Author,DOP,Count,Publisher,Category,State) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "')";
//判断是否有书号重复的,重复则禁止添加
string ID = "select * from Book";
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;
textBox5.Text = null;
}
form311.Table(); //实现实时刷新表
}
}
//判断是否有图书编号重复的,重复则禁止添加
}
}
private void button8_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || textBox8.Text == "")
{
MessageBox.Show("输入不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string sq = "update Book set Id='" + textBox1.Text + "', Name='" + textBox2.Text + "', Author='" + textBox3.Text + "', DOP='" + textBox4.Text + "', Count='" + textBox5.Text + "', Publisher='" + textBox6.Text + "', Count='" + textBox7.Text + "', Count='" + textBox8.Text + "' where Id='" + textBox1.Text + "'";
Dao da = new Dao();
da.Execute(sq); //执行更新对应书籍信息的操作
MessageBox.Show("修改书籍成功");
Close();
}
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = null;
}
private void button5_Click(object sender, EventArgs e)
{
textBox2.Text = null;
}
private void button6_Click(object sender, EventArgs e)
{
textBox3.Text = null;
}
private void button7_Click(object sender, EventArgs e)
{
textBox4.Text = null;
}
private void button3_Click(object sender, EventArgs e)
{
textBox5.Text = null;
}
private void label6_Click(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
}
}
}