📄 bookborrowcenter.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.IO;
namespace BookMS
{
public partial class BookBorrowCenter : Form
{
public BookBorrowCenter()
{
InitializeComponent();
}
DataSet ds = new DataSet("BookDs");
DataSet ds1 = new DataSet("ReaderDs");
DataSet ds2 = new DataSet("BorrowDs");
private void UserBookLookCenter_Load(object sender, EventArgs e)
{
//DataTable dt2 = new DataTable("BorrowTab");
//DataColumn dc1 = new DataColumn("读者编号");
//DataColumn dc2 = new DataColumn("读者姓名");
//DataColumn dc3 = new DataColumn("读者性别");
//DataColumn dc4 = new DataColumn("读者状态");
//DataColumn dc5 = new DataColumn("图书编号");
//DataColumn dc6 = new DataColumn("图书名称");
//DataColumn dc7 = new DataColumn("已借阅本数");
//DataColumn dc8 = new DataColumn("借阅日期");
//dt2.Columns.AddRange(new DataColumn[] { dc1, dc2, dc3, dc4, dc5, dc6, dc7, dc8 });
//ds2.Tables.Add(dt2);
if (File.Exists("..\\..\\BookDs.ds"))
{
ds.ReadXml("..\\..\\BookDs.ds");
ds.Tables["BookTab"].PrimaryKey = new DataColumn[] { ds.Tables["BookTab"].Columns["BookID"] };
dataGridView1.DataSource = ds.Tables["BookTab"];
}
if (File.Exists("..\\..\\BorrowDs.ds"))
{
ds2.ReadXml("..\\..\\BorrowDs.ds");
dataGridView2.DataSource = ds2.Tables["BorrowTab"];
}
}
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists("..\\..\\BookDs.ds"))
{
ds.Clear();
ds.ReadXml("..\\..\\BookDs.ds");
ds.Tables["BookTab"].PrimaryKey = new DataColumn[] { ds.Tables["BookTab"].Columns["BookID"] };
dataGridView1.DataSource = ds.Tables["BookTab"];
}
if (File.Exists("..\\..\\BorrowDs.ds"))
{
ds2.Clear();
ds2.ReadXml("..\\..\\BorrowDs.ds");
dataGridView2.DataSource = ds2.Tables["BorrowTab"];
}
}
private void button2_Click(object sender, EventArgs e)
{
DataTable dt1 = new DataTable();
dt1 = ds.Tables["BookTab"].Clone();
foreach (DataRow dr1 in ds.Tables["BookTab"].Select("BookName='" + textBox1.Text + "'"))
{
dt1.Rows.Add(dr1.ItemArray);
}
DataTable dt2 = new DataTable();
dt2 = ds2.Tables["BorrowTab"].Clone();
foreach (DataRow dr2 in ds2.Tables["BorrowTab"].Select("图书名称='" + textBox1.Text + "'"))
{
dt2.Rows.Add(dr2.ItemArray);
}
dataGridView2.DataSource = dt2;
dataGridView1.DataSource = dt1;
}
private void button3_Click_1(object sender, EventArgs e)
{
try
{
ds.Clear();
ds.ReadXml("..\\..\\BookDs.ds");
ds.Tables["BookTab"].PrimaryKey = new DataColumn[] { ds.Tables["BookTab"].Columns["BookID"] };
DataRow dr = ds.Tables["BookTab"].Rows.Find(textBox2.Text.ToString());
textBox3.Text = dr["BookName"].ToString();
textBox4.Text = dr["Author"].ToString();
textBox5.Text = dr["Publishing"].ToString();
textBox6.Text = dr["Publishingtime"].ToString();
if (Convert.ToInt32(dr["BookNum"]) > 0)
{
textBox7.Text = "可借";
}
else if (Convert.ToInt32(dr["BookNum"]) == 0)
{
textBox7.Text = "不可借";
}
}
catch
{
MessageBox.Show("ID不存在");
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
}
}
private void button4_Click_1(object sender, EventArgs e)
{
try
{
ds1.Clear();
ds1.ReadXml("..\\..\\ReaderDs.ds");
ds1.Tables["ReaderTab"].PrimaryKey = new DataColumn[] { ds1.Tables["ReaderTab"].Columns["读者编号"] };
DataRow dr1 = ds1.Tables["ReaderTab"].Rows.Find(textBox8.Text.ToString());
textBox9.Text = dr1["读者姓名"].ToString();
textBox10.Text = dr1["读者性别"].ToString();
textBox11.Text = dr1["读者状态"].ToString();
textBox12.Text = "";
}
catch
{
MessageBox.Show("读者不存在");
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
}
}
private void button5_Click_1(object sender, EventArgs e)
{
if (textBox2.Text != "" && textBox3.Text != "" && textBox8.Text != "" && textBox9.Text != "" && textBox10.Text != "" && textBox11.Text != "")
{
ds.Clear();
ds.ReadXml("..\\..\\BookDs.ds");
ds.Tables["BookTab"].PrimaryKey = new DataColumn[] { ds.Tables["BookTab"].Columns["BookID"] };
DataRow dr = ds.Tables["BookTab"].Rows.Find(textBox2.Text.ToString());
if (Convert.ToInt32(dr["BookNum"]) > 0)
{
ds2.Clear();
ds2.ReadXml("..\\..\\BorrowDs.ds");
DataRow dr2 = ds2.Tables["BorrowTab"].NewRow();
dr2["读者编号"] = textBox8.Text.ToString();
dr2["读者姓名"] = textBox9.Text.ToString();
dr2["读者性别"] = textBox10.Text.ToString();
dr2["读者状态"] = textBox11.Text.ToString();
dr2["图书编号"] = textBox2.Text.ToString();
dr2["图书名称"] = textBox3.Text.ToString();
dr2["已借阅本数"] = "1";
dr2["借阅日期"] = DateTime.Today.ToLongDateString();
ds2.Tables["BorrowTab"].Rows.Add(dr2);
ds2.WriteXml("..\\..\\BorrowDs.ds");
int i = Convert.ToInt32(dr["BookNum"]);
i = i - 1;
dr["BookNum"] = i;
ds.WriteXml("..\\..\\BookDs.ds");
MessageBox.Show("借阅成功!");
}
else
{
MessageBox.Show("此书已经借出!");
}
}
else
{
MessageBox.Show("请填写借阅资料!");
}
}
private void button8_Click(object sender, EventArgs e)
{
this.Close();
}
private void button6_Click_1(object sender, EventArgs e)
{
ds2.Clear();
ds2.ReadXml("..\\..\\BorrowDs.ds");
foreach (DataRow dr2 in ds2.Tables["BorrowTab"].Select("图书编号='" + textBox13.Text.ToString() + "'" + " " + "and 读者编号='" + textBox19.Text.ToString() + "'"))
{
textBox14.Text = dr2["图书名称"].ToString();
textBox20.Text = dr2["读者姓名"].ToString();
textBox21.Text = dr2["读者性别"].ToString();
textBox22.Text = dr2["读者状态"].ToString();
string a = DateTime.Today.ToLongDateString();
string b = Convert.ToDateTime(a).ToBinary().ToString();
string c = Convert.ToDateTime(dr2["借阅日期"]).AddDays(10).ToBinary().ToString();
double d = Convert.ToDouble(b) - Convert.ToDouble(c);
if (d == 0)
{
textBox18.Text="已经到期";
}
else if (d < 0)
{
textBox18.Text="还未到期";
}
else
{
textBox18.Text="已经过期";
}
ds.Clear();
ds.ReadXml("..\\..\\BookDs.ds");
ds.Tables["BookTab"].PrimaryKey = new DataColumn[] { ds.Tables["BookTab"].Columns["BookID"] };
DataRow dr = ds.Tables["BookTab"].Rows.Find(textBox13.Text.ToString());
textBox15.Text = dr["Author"].ToString();
textBox16.Text = dr["Publishing"].ToString();
textBox17.Text = dr["Publishingtime"].ToString();
}
}
private void button7_Click_1(object sender, EventArgs e)
{
ds2.Clear();
ds2.ReadXml("..\\..\\BorrowDs.ds");
foreach (DataRow dr2 in ds2.Tables["BorrowTab"].Select("图书编号='" + textBox13.Text.ToString() + "'" + " " + "and 读者编号='" + textBox19.Text.ToString() + "'"))
{
dr2.Delete();
ds.Clear();
ds.ReadXml("..\\..\\BookDs.ds");
ds.Tables["BookTab"].PrimaryKey = new DataColumn[] { ds.Tables["BookTab"].Columns["BookID"] };
DataRow dr = ds.Tables["BookTab"].Rows.Find(textBox13.Text.ToString());
int i = Convert.ToInt32(dr["BookNum"]);
i = i + 1;
dr["BookNum"] = i;
ds.WriteXml("..\\..\\BookDs.ds");
ds2.WriteXml("..\\..\\BorrowDs.ds");
MessageBox.Show("还书成功!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -