📄 图书注销.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 图书馆管理系统
{
/// <summary>
/// 图书注销---用SqlCommand进行操作
/// 根据注销的数量 相应的在图书档案中减少图书库存量 同时将图书注销的信息保存了图书注销的数据库中
/// 用运了radiobutton来控制是否注销 与显示但查看注销记录时数据库中是否注销的字段记录
/// </summary>
public partial class 图书注销 : Form
{
public BindingManagerBase Navigator;
public 图书注销()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public void TextReadOnly(bool A)
{
textBox1.ReadOnly = A;
textBox2.ReadOnly = A;
textBox3.ReadOnly = A;
textBox4.ReadOnly = A;
}
//-----------------------------------------------------注销--------------------
private void button1_Click(object sender, EventArgs e)
{
sqlConnection1.Open();
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{
MessageBox.Show("必须填写完整!请重新填写!");
return;
}
else
{
if (radioButton1.Checked == true)
{
DialogResult result = MessageBox.Show("确定要注销吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
//----------------注销后图书数据根据注销数量相应的减少几本------
string str = "select 库存总量 from 图书信息 where 编号='" + textBox2.Text + "'";
SqlCommand mycom = new SqlCommand(str, sqlConnection1);
object num = mycom.ExecuteScalar();
int count = Convert.ToInt32(num) - Int32.Parse(textBox3.Text);
SqlCommand com = new SqlCommand("update 图书信息 set 库存总量=" + count + " where 编号='" + textBox2.Text + "'", sqlConnection1);
int a = com.ExecuteNonQuery();
if (a != 0)
{
SqlCommand sqlcom = new SqlCommand("select * from 图书注销 where 图书编号='" + textBox2.Text + "'", sqlConnection1);
SqlDataReader dr = sqlcom.ExecuteReader();
//--------------控制更改radioButton的状态来更改图书注销数据库的更新和添加工作---------------------------
if (dr.Read())
{
dr.Close();
SqlCommand comInsert = new SqlCommand("update 图书注销 set 确定注销=1 where 确定注销=0 and 图书编号='" + textBox2.Text + "'", sqlConnection1);
int num1 = comInsert.ExecuteNonQuery();
}
else
{
dr.Close();
Navigator.EndCurrentEdit();
SqlCommand comInsert = new SqlCommand("insert into 图书注销(注销编号,图书编号,注销数量,注销时间,确定注销) values(" + textBox1.Text + ",'" + textBox2.Text + "'," + textBox3.Text + ",'" + textBox4.Text + "',1)", sqlConnection1);
int num1 = comInsert.ExecuteNonQuery();
}
MessageBox.Show("操作成功!数据库以相应的更改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
MessageBox.Show("返回数据库操作失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MessageBox.Show("无法注销数据记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (radioButton2.Checked == true)
{
Navigator.EndCurrentEdit();
//sqlDataAdapter1.Update(dataSet11, "图书注销");
MessageBox.Show("操作失败!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
return;
return;
}
TextReadOnly(true);
}
sqlConnection1.Close();
}
private void 图书注销_Load(object sender, EventArgs e)
{
sqlDataAdapter1.Fill(dataSet11, "图书注销");
Navigator = this.BindingContext[dataSet11, "图书注销"];
TextReadOnly(true);
}
private void button4_Click(object sender, EventArgs e)
{
Navigator.CancelCurrentEdit();
TextReadOnly(true);
if (Navigator.Position == 0)
{
Navigator.Position = 0;
}
else
{
Navigator.Position--;
}
show();
}
private void button5_Click(object sender, EventArgs e)
{
Navigator.CancelCurrentEdit();
TextReadOnly(true);
if (Navigator.Position == Navigator.Count - 1)
{
Navigator.Position = Navigator.Count - 1;
}
else
{
Navigator.Position++;
}
show();
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
TextReadOnly(false);
Navigator.AddNew();
}
private void button6_Click(object sender, EventArgs e)
{
Navigator.CancelCurrentEdit();
TextReadOnly(true);
}
//--------------------------------------------将 radioButton与数据库中的确定注销绑定-------------------
public void show()
{
int restual = Convert.ToInt32(dataSet11.Tables["图书注销"].Rows[Navigator.Position]["确定注销"]);
if (restual==1)
{
radioButton1.Checked = true;
radioButton2.Checked = false;
}
else
if (restual==0)
{
radioButton1.Checked = false;
radioButton2.Checked = true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -