📄 borrow.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/// <summary>
/// Borrow 的摘要说明。
/// </summary>
public class Borrow : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button bt1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button bt2;
protected System.Web.UI.WebControls.DataGrid DataGrid2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private Access acc=new Access();
private DataSet ds=new DataSet();
private DataView MyDV=new DataView();
private DataSet ds2=new DataSet();
MyDateControl MyDate=new MyDateControl();
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Button bt3;
protected System.Web.UI.WebControls.Button bt4;
protected CCUtility Utility;
private void Page_Load(object sender, System.EventArgs e)
{
this.Utility=new CCUtility(this);
Utility.CheckSecurity();this.init_2();}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.bt1.Click += new System.EventHandler(this.bt1_Click);
this.bt2.Click += new System.EventHandler(this.bt2_Click);
this.bt3.Click += new System.EventHandler(this.bt3_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void MsgBox( string msg )
{
string strScript = "<script language='Javascript'>alert('" + msg + "');</script>";
Page.RegisterStartupScript("alert", strScript);
}
private void bt1_Click(object sender, System.EventArgs e)
{
double owe=0;
int singal=0;
string sql_1="select * from DB_studentinfo where StuID='"+this.TextBox1.Text+"'";
acc.GetDataSet(sql_1,ds);
if(ds.Tables[0].Rows.Count==0){this.init_2();this.MsgBox("该生不存在!");return;}
MyDV=ds.Tables[0].DefaultView;
this.DataGrid1.DataSource=MyDV;
DataGrid1.DataBind();
string sql_2="select DB_bookinfo.BookID ,DB_bookinfo.BookName ,DB_bookinfo.Type ,DB_bookinfo.Writer ,L.LendDate ,L.OweCharge from (DB_bookinfo inner join DB_LendRecord as L on L.BookID=DB_bookinfo.BookID)"
+" where L.StuID='"+this.TextBox1.Text+"'";
ds.Clear();
acc.GetDataSet(sql_2,ds);
MyDV=ds.Tables[0].DefaultView;
this.DataGrid2.DataSource=MyDV;
DataGrid2.DataBind();
int count=ds.Tables[0].Rows.Count;
System.DateTime today = System.DateTime.Now;
System.DateTime[] maxdate=new DateTime[count];
for(int i=0;i < count;i++)
{
maxdate[i]=System.Convert.ToDateTime(this.DataGrid2.Items[i].Cells[4].Text).AddDays(System.Convert.ToInt16(this.DataGrid1.Items[0].Cells[4].Text));
if(DateTime.Compare(today,maxdate[i])>0)
{
CCUtility Utility=new CCUtility(this);
singal++;
string strUpdt = " UPDATE DB_LendRecord SET OweCharge = '"
+System.Convert.ToString(Utility.Compare(today,System.Convert.ToDateTime(this.DataGrid2.Items[i].Cells[4].Text)) * 0.05) + "'"
+" WHERE BookID = '" + this.DataGrid2.Items[i].Cells[0].Text+"'";
bool success=acc.ExecuteSQL(strUpdt);
if(success==true)
{
sql_2="select DB_bookinfo.BookID ,DB_bookinfo.BookName ,DB_bookinfo.Type ,DB_bookinfo.Writer ,L.LendDate ,L.OweCharge from (DB_bookinfo inner join DB_LendRecord as L on L.BookID=DB_bookinfo.BookID)"
+" where L.StuID='"+this.TextBox1.Text+"'";
ds.Clear();
acc.GetDataSet(sql_2,ds);
MyDV=ds.Tables[0].DefaultView;
this.DataGrid2.DataSource=MyDV;
DataGrid2.DataBind();
owe=owe+System.Convert.ToDouble(this.DataGrid2.Items[i].Cells[5].Text);
}
else {this.MsgBox("更新失败!");}
}
}
if(singal!=0)
{
this.Label1.Visible=true;
this.Label2.Visible=true;
this.Label1.Text="您欠费共计:"+ owe.ToString()+"元.";
this.Label2.Text="您当前已借数目:"+this.ds.Tables[0].Rows.Count.ToString()+"本.";
this.MsgBox("您有逾期的书还未归还!");return;
}
this.Label1.Text="您当前已借数目:"+this.ds.Tables[0].Rows.Count.ToString()+"本.";
int allownum=System.Convert.ToInt16(this.DataGrid1.Items[0].Cells[3].Text) - System.Convert.ToInt16(this.ds.Tables[0].Rows.Count);
if(allownum <= 0)
{
this.Label2.Text="您当前已借数目:"+this.ds.Tables[0].Rows.Count.ToString()+"本.";
this.MsgBox("该生图书已借满,不可再借!");
return;
}
this.Label1.Visible=true;
this.Label2.Visible=true;
this.Label1.Text="您当前已借数目:"+this.ds.Tables[0].Rows.Count.ToString()+"本.";
this.Label2.Text="尚可借书数目:"+allownum.ToString()+"本.";
ds.Clear();
acc.GetDataSet(sql_2,ds);
MyDV=ds.Tables[0].DefaultView;
this.DataGrid2.DataSource=MyDV;
DataGrid2.DataBind();
this.init_1();
}
private void Button1_Click(object sender, System.EventArgs e)
{
}
private void bt4_Click(object sender, System.EventArgs e)
{
CCUtility Utility=new CCUtility(this);
System.DateTime today = System.DateTime.Now;
System.DateTime date=System.Convert.ToDateTime(this.DataGrid2.Items[1].Cells[4].Text);
date=System.Convert.ToDateTime("2005-11-19");
int temp=Utility.Compare(today,date);
//temp=System.DateTime.Compare(today,today);
double dd=temp*0.05;
this.MsgBox(temp.ToString());
}
private void bt2_Click(object sender, System.EventArgs e)
{
if(this.TextBox2.Text==""){this.MsgBox("请输入图书编号!");this.init_1();return;}
string strcheck="select * from DB_bookinfo where BookID='"+this.TextBox2.Text+"'";
SqlDataReader dr=acc.GetReader(strcheck);
acc.GetDataSet(strcheck,ds2);
if(ds2.Tables[0].Rows.Count==0){this.init_1();ds2.Clear();this.MsgBox("该书不存在或未注册!");return;}
dr.Read();
if(dr.GetValue(10).ToString().Trim()=="出馆"){this.MsgBox("该书已借出!");this.init_1();return;}
string strInsert="insert into DB_LendRecord(StuID,BookID,LendDate,OweCharge)VALUES( '"
+this.TextBox1.Text+"','"
+this.TextBox2.Text+"','"
+this.TextBox4.Text+"',0)";
try
{
bool success1=acc.ExecuteSQL(strInsert);
if(success1==true)
{
string strUpdt = " UPDATE DB_bookinfo SET state = '出馆' WHERE BookID = '" + this.TextBox2.Text+"'" ;
bool success2=acc.ExecuteSQL(strUpdt);
string str_show="select DB_bookinfo.BookID ,DB_bookinfo.BookName ,DB_bookinfo.Type ,DB_bookinfo.Writer ,L.LendDate ,L.OweCharge from (DB_bookinfo inner join DB_LendRecord as L on L.BookID=DB_bookinfo.BookID)"
+" where L.StuID='"+this.TextBox1.Text+"'";
ds2.Clear();
acc.GetDataSet(str_show,ds);
MyDV=ds.Tables[0].DefaultView;
this.DataGrid2.DataSource=MyDV;
DataGrid2.DataBind();
this.Label1.Visible=true;
this.Label2.Visible=true;
this.Label1.Text="您当前已借数目:"+this.ds.Tables[0].Rows.Count.ToString()+"本.";
int allownum=System.Convert.ToInt16(this.DataGrid1.Items[0].Cells[3].Text) - System.Convert.ToInt16(this.ds.Tables[0].Rows.Count);
this.Label2.Text="尚可借书数目:"+allownum.ToString()+"本.";
if(allownum <= 0){this.MsgBox("该生图书已借满,不可再借!");this.init_1();return;}
}
else
{this.MsgBox("录入失败!");}
}
catch(Exception ed){this.MsgBox(ed.ToString());}
this.init_1();
}
private void init_1()
{
this.Label1.Visible=true;
this.Label2.Visible=true;
this.TextBox1.Enabled=false;
this.TextBox1.BackColor=Color.Gray;
this.TextBox2.Enabled=true;
this.TextBox2.BackColor=Color.White;
this.TextBox4.Enabled=true;
this.TextBox4.BackColor=Color.White;
this.bt2.Enabled=true;
this.bt1.Enabled=false;
this.bt3.Enabled=true;
Page.RegisterClientScriptBlock(this.ClientID+"SaSBYaDateTimePicker",MyDate.ConstructScripts());
this.TextBox4.Attributes.Add("onfocus","setday("+this.TextBox4.ClientID+")");
this.TextBox4.Text=System.DateTime.Now.ToString();
}
private void init_2()
{
this.TextBox1.Enabled=true;
this.TextBox1.BackColor=Color.White;
this.TextBox2.Enabled=false;
this.TextBox2.BackColor=Color.Gray;
this.TextBox4.Enabled=false;
this.TextBox4.BackColor=Color.Gray;
this.bt2.Enabled=false;
this.bt1.Enabled=true;
this.bt3.Enabled=false;
this.Label1.Visible=false;
this.Label2.Visible=false;
}
private void bt3_Click(object sender, System.EventArgs e)
{this.init_2();}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -