📄 huanshchuli.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 tsh
{
public partial class huanshchuli : Form
{
public huanshchuli()
{
InitializeComponent();
}
DB.ClsSQL sql = new DB.ClsSQL(".", "mylw", "sa", "", 3);
private int yjss = 0;
private int kjss = 0;
private int kjts = 0;
private DataSet ds, ds1, ds2;
private void huanshchuli_Load(object sender, EventArgs e)
{
label1.Visible = false;
}
private void textBbianhao_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
e.Handled = true;
if (e.KeyChar == 13)
{
//string s1 = "select * from reader where duzhebianhao='" + textBbianhao.Text + "'";
//ds = sql.DBToDS(s1, "reader");
//int n = ds.Tables["reader"].Rows.Count;
//if (n == 0)
//{
// MessageBox.Show("无此读者编号!!!", "信息提示");
// textBbianhao.Text = "";
// textBbianhao.Focus();
//}
string s1 = "select * from reader where duzhebianhao='" + textBbianhao.Text + "'";
ds = sql.DBToDS(s1, "reader");
int n = ds.Tables["reader"].Rows.Count;
if (n == 0)
{
MessageBox.Show("无此读者编号!!!", "信息提示");
textBbianhao.Text = "";
textBbianhao.Focus();
}
else
{
textBxingming.Text = ds.Tables["reader"].Rows[0]["duzhexingming"].ToString();
textBleibie.Text = ds.Tables["reader"].Rows[0]["duzheleibie"].ToString();
textBzhuangtai.Text = ds.Tables["reader"].Rows[0]["shuzhengzhuangtai"].ToString();
textBxingbie.Text = ds.Tables["reader"].Rows[0]["xingbie"].ToString();
string s2 = "select * from borrow where duzhebianhao='" + textBbianhao.Text.Trim() + "'";
ds1 = sql.DBToDS(s2, "borrow");
yjss = ds1.Tables["borrow"].Rows.Count;
textByjshushu.Text = yjss.ToString();
if (yjss == 0)
{
MessageBox.Show("该读者未借任何书籍!!!", "信息提示");
buttxiayi_Click(null, null);
}
else
{
dataGVi1.DataSource = ds1.Tables["borrow"];
textBbianhao.Enabled = false;
label1.Visible = true;
butthuanhui.Enabled = true;
butthuanhui.Focus();
string s3 = "select * from readerc where duzheleibie='" + textBleibie.Text + "'";
ds2 = sql.DBToDS(s3, "readerc");
kjss = int.Parse(ds2.Tables["readerc"].Rows[0][1].ToString());
kjts = int.Parse(ds2.Tables["readerc"].Rows[0][2].ToString());
if (yjss >= kjss)
{
MessageBox.Show("该读者书已借满,请速归还部分书籍!!!", "信息提示");
}
int cqss = 0;
DateTime d1 = DateTime.Now;
for (int i = 0; i < yjss; i++)
{
DateTime d2 = (DateTime)ds1.Tables["borrow"].Rows[i]["jieshuriqu"];
string g = ds1.Tables["borrow"].Rows[i]["duzhebianhao"].ToString();
string g1 = ds1.Tables["borrow"].Rows[i]["tushubianhao"].ToString();
System.TimeSpan t = d1 - d2;
int jsts = (int)t.TotalDays;
int cqts = jsts - kjts;
if (cqts > 0)
{
ds1.Tables["borrow"].Rows[i]["chaoqutianshu"] = cqts;
string gx = "update borrow set chaoqutianshu=" + cqts + " where duzhebianhao='" + g + "' and tushubianhao='" + g1 + "'";
sql.SQLCommand(gx);
cqss++;
}
else
ds1.Tables["borrow"].Rows[i]["chaoqutianshu"] = 0;
}
if (cqss > 0)
{
MessageBox.Show("该读者有" + cqss.ToString() + "本书超期,请归还在借!!!", "提示");
}
}
}
}
}
private void buttxiayi_Click(object sender, EventArgs e)
{
textBbianhao.Text = "";
textBbianhao.Enabled = true;
textBbianhao.Focus();
textBleibie.Text = "";
textBxingming.Text = "";
textByjshushu.Text = "";
textBzhuangtai.Text = "";
textBxingbie.Text = "";
ds1.Clear();
}
private void butthuanhui_Click(object sender, EventArgs e)
{
string bkmane = dataGVi1.CurrentRow.Cells[2].Value.ToString();
DialogResult result = MessageBox.Show("真的要归还”" + bkmane + "“这本书吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
string tshb = dataGVi1.CurrentRow.Cells[1].Value.ToString();
string s4 = "delete from borrow where duzhebianhao='" + textBbianhao.Text.Trim() +"'and tushubianhao='" + tshb.Trim() + "'";
sql.SQLCommand(s4);
string s5 = "update book set zaikushu=zaikushu+1 where tushubianhao='" + tshb + "'";
sql.SQLCommand(s5);
ds1.Clear();
string s6 = "select * from borrow where duzhebianhao='" + textBbianhao.Text.Trim() + "'";
ds1 = sql.DBToDS(s6, "borrow");
yjss = ds1.Tables["borrow"].Rows.Count;
//--yjss;
textByjshushu.Text = yjss.ToString();
dataGVi1.DataSource = ds1.Tables["borrow"];
if (yjss == 0)
{
label1.Visible = false;
MessageBox.Show("该读者所借书籍已还完!!!", "信息提示");
butthuanhui.Enabled = false;
buttxiayi_Click(null, null);
}
// MessageBox.Show("归还”" + bkmane + "“这本书成功!!!", "信息提示");
DateTime d1 = DateTime.Now;
for (int i=0; i < yjss; i++)
{
DateTime d2 = (DateTime)ds1.Tables["borrow"].Rows[i]["jieshuriqu"];
string g = ds1.Tables["borrow"].Rows[i]["duzhebianhao"].ToString();
string g1 = ds1.Tables["borrow"].Rows[i]["tushubianhao"].ToString();
System.TimeSpan t = d1 - d2;
int jsts = (int)t.TotalDays;
int cqts = jsts - kjts;
if (cqts > 0)
{
ds1.Tables["borrow"].Rows[i]["chaoqutianshu"] = cqts;
string gx = "update borrow set chaoqutianshu=" + cqts + " where duzhebianhao='" + g + "' and tushubianhao='" + g1 + "'";
sql.SQLCommand(gx);
}
else
ds1.Tables["borrow"].Rows[i]["chaoqutianshu"] = 0;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -