📄 jieshuchuli.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 jieshuchuli : Form
{
public jieshuchuli()
{
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,ds3;
private void label2_Click(object sender, EventArgs e)
{
}
private void butttuichu_Click(object sender, EventArgs e)
{
this.Close();
}
//private void textBjiage_KeyPress(object sender, KeyPressEventArgs e)
//{
// if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
// {
// if (e.KeyChar == '.')
// {
// if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
// e.Handled = true;
// }
// else
// e.Handled = true;
// }
// else
// {
// if (e.KeyChar <= 31)
// {
// e.Handled = false;
// }
// else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
// {
// if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 2)
// e.Handled = true;
// }
// }
//}
//private void textBchubanshe_KeyPress(object sender, KeyPressEventArgs e)
//{
// if ((e.KeyChar >= '0') && (e.KeyChar <= '9') || e.KeyChar == '.')
// {
// e.Handled = true;
// }
//}
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();
}
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();
dataGVi1.DataSource = ds1.Tables["borrow"];
//String s0 = "select * from borrow where duzhebianhao='" + textBbianhao.Text + "'";
//sql.DBToDG(s0, dataGVi1, "borrow");
if (textBzhuangtai.Text .Trim()!= "可用")
{
MessageBox.Show("该读者的书证不可用,谢绝借书!!!", "提示");
// buttxiayi_Click(null, null);
}
else
{
string s3 = "select * from readerc where duzheleibie='" + textBleibie.Text + "'";
//MessageBox.Show("4563");
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("该读者书已借满,不能再借!!", "信息提示");
buttxiayi_Click(null, null);
}
else
{
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;
//更新数据源中borrow表的chaoqutianshu字段
string gx = "update borrow set chaoqutianshu=" + cqts + " where duzhebianhao='" + g + "' and tushubianhao='" + g1 + "'";
sql.SQLCommand(gx);
//sqldar.Update(ds1, "borrow");
cqss++;
}
else
ds1.Tables["borrow"].Rows[i]["chaoqutianshu"] = 0;
}
if (cqss > 0)
{
MessageBox.Show("该读者有" + cqss.ToString() + "本书超期,请归还在借!!!", "提示");
buttxiayi_Click(null, null);
}
else
{
textBbianhao.Enabled = false;
textBtshbianhao.Enabled = true;
textBtshbianhao.Focus();
}
}
}
}
}
}
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();
textBtshbianhao.Text = "";
textBzuozhe.Text = "";
textBchubanshe.Text = "";
textBjiage.Text = "";
textBtshumingcheng.Text = "";
textBtshbianhao.Enabled = false;
buttjiechu.Enabled=false;
buttquxiao.Enabled=false;
}
private void textBtshbianhao_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
string bookNo = textBtshbianhao.Text;
bool Query = false;
for (int i = 0; i < bookNo.Length; i++)
{
if (bookNo[i] == '?'||bookNo[i] == '?')
{
Query = true;
break;
}
}
if (Query == true)
{
tushuxinxichaxun Ftuxun = new tushuxinxichaxun();
DialogResult result = Ftuxun.ShowDialog();
if (result == DialogResult.OK)
{
textBtshbianhao.Text = Ftuxun.BookNo;
bookNo = textBtshbianhao.Text;
}
}
string s4 = "select * from borrow where tushubianhao='" + bookNo + "' and duzhebianhao='" + textBbianhao.Text + "'";
if (sql.DBToDS(s4, "borrow").Tables["borrow"].Rows.Count != 0)
{
MessageBox.Show("读者" + textBbianhao.Text + "已借了编号为" + textBtshbianhao.Text + "的这本书,不能再借!!", "信息提示");
textBtshbianhao.Text = "";
textBtshbianhao.Focus();
}
else
{
string s5 = "select * from book where tushubianhao='" + bookNo + "'";
ds3 = sql.DBToDS(s5, "book");
if (ds3.Tables["book"].Rows.Count == 0)
{
MessageBox.Show("无此图书编号!!!", "信息提示");
textBtshbianhao.Text = "";
textBtshbianhao.Focus();
}
else
{
if (ds3.Tables["book"].Rows[0]["zaikushu"].ToString() == "0")
{
MessageBox.Show("此书已借完!!", "书讯提示");
textBtshbianhao.Text = "";
textBtshbianhao.Focus();
//ds1.Clear();
//string s2 = "select * from borrow where duzhebianhao='" + textBbianhao + "'";
//sql.DBToDS(s2, "borrow");
}
else
{
textBtshumingcheng.Text = ds3.Tables["book"].Rows[0]["shuming"].ToString();
textBzuozhe.Text = ds3.Tables["book"].Rows[0]["zuozhe"].ToString();
textBchubanshe.Text = ds3.Tables["book"].Rows[0]["chubanshe"].ToString();
textBjiage.Text = ds3.Tables["book"].Rows[0]["jiage"].ToString();
buttjiechu.Enabled = true;
buttquxiao.Enabled = true;
buttjiechu.Focus();
}
}
}
}
}
private void buttquxiao_Click(object sender, EventArgs e)
{
textBtshbianhao.Text = "";
textBtshbianhao.Focus();
textBzuozhe.Text = "";
textBchubanshe.Text = "";
textBjiage.Text = "";
textBtshumingcheng.Text = "";
}
private void buttjiechu_Click(object sender, EventArgs e)
{
if (yjss >= kjss)
{
MessageBox.Show("该读者书已借满,不能再借!!", "信息提示");
buttxiayi_Click(null, null);
}
else
{
DateTime t1 = DateTime.Now;
string s = "insert into borrow (duzhebianhao,tushubianhao,shuming,zuozhe,chubanshe,jiage,jieshuriqu,chaoqutianshu) values ('" + textBbianhao.Text.Trim() + "','" + textBtshbianhao.Text.Trim() + "','" + textBtshumingcheng.Text.Trim() + "','" + textBzuozhe.Text.Trim() + "','" + textBchubanshe.Text.Trim() + "','" + textBjiage.Text.Trim() +"','" + t1 + "',0)";
if (sql.SQLCommand(s) > 0)
{
MessageBox.Show("读者" + textBbianhao.Text + "现在借出编号为" + textBtshbianhao.Text + "的这本书!!", "信息提示");
string s1 = "update book set zaikushu=zaikushu-1 where tushubianhao='" + textBtshbianhao.Text + "'";
sql.SQLCommand(s1);
ds1.Clear();
string s2 = "select * from borrow where duzhebianhao='" + textBbianhao.Text + "'";
//sql.DBToDG(s2, dataGVi1, "borrow");
//必须用下面数据集填充表格的方法
ds1 = sql.DBToDS(s2, "borrow");
dataGVi1.DataSource = ds1.Tables["borrow"];
buttjiechu.Enabled = false;
buttquxiao.Enabled = false;
textBtshbianhao.Text = "";
textBtshbianhao.Focus();
textBzuozhe.Text = "";
textBchubanshe.Text = "";
textBjiage.Text = "";
textBtshumingcheng.Text = "";
yjss++;
textByjshushu.Text = yjss.ToString();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -