📄 return.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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>
/// Return 的摘要说明。
/// </summary>
public class Return : System.Web.UI.Page
{protected CCUtility Utility;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button bt1;
protected System.Web.UI.WebControls.Button bt2;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
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.Button bt4;
private Access acc=new Access();
private DataSet ds1=new DataSet();
private DataSet ds2=new DataSet();
private DataView MyDV=new DataView();
public void MsgBox( string msg )
{
string strScript = "<script language='Javascript'>alert('" + msg + "');</script>";
Page.RegisterStartupScript("alert", strScript);
}
private void Page_Load(object sender, System.EventArgs e)
{
this.Utility=new CCUtility(this);
Utility.CheckSecurity();
this.Label1.Visible=false;
this.Label2.Visible=false;
this.bt2.Enabled=false;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.bt1.Click += new System.EventHandler(this.bt1_Click);
this.bt2.Click += new System.EventHandler(this.bt2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void bt1_Click(object sender, System.EventArgs e)
{
int singal=0;
double owe=0;
////显示第二个数据窗口.
string sql_1="select StuID, StuName, Profession, MaxBookNum,MaxTerm from DB_Studentinfo"
+" where StuID in (select StuID from DB_LendRecord where BookID='"
+this.TextBox1.Text+"')";
ds1.Clear();
acc.GetDataSet(sql_1,ds1);
if(ds1.Tables[0].Rows.Count==0){this.MsgBox("该书不存在或尚未借出!");return;}
MyDV=ds1.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.DataGrid1.Items[0].Cells[0].Text+"'";
ds2.Clear();
acc.GetDataSet(sql_2,ds2);
MyDV=ds2.Tables[0].DefaultView;
this.DataGrid2.DataSource=MyDV;
DataGrid2.DataBind();
/////更新欠费情况.
int count=ds2.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.DataGrid1.Items[0].Cells[0].Text+"'";
ds2.Clear();
acc.GetDataSet(sql_2,ds2);
MyDV=ds2.Tables[0].DefaultView;
this.DataGrid2.DataSource=MyDV;
DataGrid2.DataBind();
owe=owe+System.Convert.ToDouble(this.DataGrid2.Items[i].Cells[5].Text);
}
else {this.MsgBox("更新失败!");}
}
}
this.bt2.Enabled=true;
this.Label1.Visible=true;
this.Label2.Visible=true;
this.Label1.Text="您欠费共计:"+ owe.ToString()+"元.";
this.Label2.Text="您当前已借数目:"+this.ds2.Tables[0].Rows.Count.ToString()+"本.";
}
private void bt2_Click(object sender, System.EventArgs e)
{
double owe=0;
string str_delete="delete from DB_LendRecord where BookID='"
+this.TextBox1.Text+"'";
string str_Updt = " UPDATE DB_bookinfo SET state = '在馆' WHERE BookID = '" + this.TextBox1.Text+"'" ;
string str_sql2="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.DataGrid1.Items[0].Cells[0].Text+"'";
bool success1=acc.ExecuteSQL(str_delete);
bool success2=acc.ExecuteSQL(str_Updt);
if(success1==true && success2==true)
{
ds2.Clear();
acc.GetDataSet(str_sql2,ds2);
MyDV=ds2.Tables[0].DefaultView;
this.DataGrid2.DataSource=MyDV;
DataGrid2.DataBind();
}
else {this.MsgBox("还书失败!");return;}
this.Label1.Visible=true;
this.Label2.Visible=true;
this.Label1.Text="您欠费共计:"+ owe.ToString()+"元.";
this.Label2.Text="您共计借书:"+ds2.Tables[0].Rows.Count.ToString()+"本.";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -