protected void Button4_Click(object sender, EventArgs e) { DataTable dt = getGridviewTable(); DataManage dm = new DataManage(); //string insql = "insert into [Library].[library].[Book] ([Bname], [Btype],[Bwriter],[Bpublish],[Bamount],[Bprice]) VALUES('{0}','{1}','{2}','{3}',{4},{5})"; int dtcount = dt.Rows.Count; for (int i = 0; i < dtcount; i++) { string selectsql = "select * from [Library].[library].[Book] where [Bname] like '" + dt.Rows[i][0] + "' and [Bwriter] like '" + dt.Rows[i][2] + "'"; int amount; DataTable table = dm.ReadTable(selectsql); if (table.Rows.Count > 0) { amount = Convert.ToInt32(dt.Rows[i][4]) + (int)table.Rows[0][5]; string updatesql = "update [Library].[library].[Book] set [Bamount] =" + amount + "where [Bname] like '" + dt.Rows[i][0] + "' and [Bwriter] like '" + dt.Rows[i][2] + "'"; dm.ExecuteSql(updatesql); } else { //insql = string.Format(insql, dt.Rows[i][0], dt.Rows[i][1], dt.Rows[i][2], dt.Rows[i][3], dt.Rows[i][4], dt.Rows[i][5]); string insql = "insert into [Library].[library].[Book] ([Bname], [Btype],[Bwriter],[Bpublish],[Bamount],[Bprice]) VALUES('" + dt.Rows[i][0] + "','" + dt.Rows[i][1] + "','" + dt.Rows[i][2] + "','" + dt.Rows[i][3] + "'," + dt.Rows[i][4] + "," + dt.Rows[i][5] + ")"; dm.ExecuteSql(insql); } } Response.Write("<script>alert('导入成功!')</script>"); }
protected void Button2_Click(object sender, EventArgs e) { int amount = Convert.ToInt32(this.TextBox2.Text); int tagindex = -1; foreach (GridViewRow GR in this.GridView1.Rows) { CheckBox CB = (CheckBox)GR.FindControl("CheckBox1"); if (CB.Checked) { tagindex = GR.RowIndex; } } int bookamount = Convert.ToInt32(this.GridView1.Rows[tagindex].Cells[5].Text); int decrease = bookamount - amount; DataManage dm = new DataManage(); if (decrease > 0) { string sql = "update [Library].[library].[Book] set [Bamount] =" + decrease + "where [Bname] like '" + this.GridView1.Rows[tagindex].Cells[1].Text + "' and [Btype] like '" + this.GridView1.Rows[tagindex].Cells[2].Text + "' and [Bwriter] like '" + this.GridView1.Rows[tagindex].Cells[3].Text + "' and [Bpublish] like '" + this.GridView1.Rows[tagindex].Cells[4].Text + "'"; dm.ExecuteSql(sql); } else { string sql = "delete from [Library].[library].[Book] where [Bname] like '" + this.GridView1.Rows[tagindex].Cells[1].Text + "' and [Btype] like '" + this.GridView1.Rows[tagindex].Cells[2].Text + "' and [Bwriter] like '" + this.GridView1.Rows[tagindex].Cells[3].Text + "' and [Bpublish] like '" + this.GridView1.Rows[tagindex].Cells[4].Text + "'"; dm.ExecuteSql(sql); } Response.Write("<script>alert('出库成功!')</script>"); databind(); }
private void hotdata(int bookid, string bookname) //hot表插数据 { int id = bookid; string name = bookname; string sql_book_search = "select * from [Library].[library].[Book] where [Bid] like " + id; DataManage dm = new DataManage(); DataTable dt = dm.ReadTable(sql_book_search); string Hbname = dt.Rows[0][1].ToString(); string Hbwriter = dt.Rows[0][3].ToString(); string Hbpublisher = dt.Rows[0][4].ToString(); string Hbtype = dt.Rows[0][2].ToString(); string sql_hot_search = "select * from [Library].[library].[Hot] where [Hbname] like '" + name + "'"; string sql_hot_insert = "insert into [Library].[library].[Hot] ([Hbname],[Hbwriter],[Hbpublisher],[Hbtype],[Hot]) values ('" + Hbname + "','" + Hbwriter + "','" + Hbpublisher + "','" + Hbtype + "',1)"; string sql_hot_update = string.Empty; DataTable dt_2 = dm.ReadTable(sql_hot_search); if (dt_2.Rows.Count > 0) { int count = Convert.ToInt32(dt_2.Rows[0][5].ToString()) + 1; sql_hot_update = "update [Library].[library].[Hot] set [Hot] = " + count + " where [Hbname] like '" + name + "'"; dm.ExecuteSql(sql_hot_update); } else { dm.ExecuteSql(sql_hot_insert); } }
protected void Button3_Click(object sender, EventArgs e) { string sql = "delete from [Library].[library].[Reader] where [Rid] = " + Label1.Text; DataManage dm = new DataManage(); if (this.TextBox1.ReadOnly == true) { dm.ExecuteSql(sql); Response.Write("<script>删除成功!</script>"); } }
protected void Button2_Click(object sender, EventArgs e) { string rname = this.Label2.Text; //读者姓名 string rnum = this.Label3.Text; //读者学/工号 string rtype = this.Label4.Text; //读者类型 int bnum = Convert.ToInt32(this.Label5.Text); //可借数量 string bname = this.TextBox2.Text; //图书名称 string bid = this.TextBox3.Text; //图书序号 string date = DateTime.Now.ToShortDateString().ToString(); //借书日期 string deadline = date; //应还日期 switch (rtype) //改应还日期 { case "本科生": deadline = DateTime.Now.AddDays(60).ToShortDateString().ToString(); break; case "研究生": deadline = DateTime.Now.AddDays(90).ToShortDateString().ToString(); break; case "博士生": deadline = DateTime.Now.AddDays(100).ToShortDateString().ToString(); break; case "教职工": deadline = DateTime.Now.AddDays(100).ToShortDateString().ToString(); break; } DataManage dm = new DataManage(); string sql_1 = "select count(*) from [Library].[library].[Borrow] where [BorrowRnum] like '" + rnum + "' and [Bookstate] like 'Unreturn'"; DataTable dt = dm.ReadTable(sql_1); if (Convert.ToInt32(dt.Rows[0][0]) > bnum) //判断书借到限额 { Response.Write("<script>alert('借书达到限额!')</script>"); } else { string sql = "insert into [Library].[library].[Borrow] ([BorrowRname],[BorrowRnum],[BorrowBname],[BorrowBid],[Bookstate],[BorrowDate],[BorrowDeadline]) values ('" + rname + "','" + rnum + "','" + bname + "','" + bid + "','Unreturn','" + date + "','" + deadline + "')"; dm.ExecuteSql(sql); gridBind(); int bookid = Convert.ToInt32(bid); hotdata(bookid, bname); this.TextBox2.Text = null; this.TextBox3.Text = null; Response.Write("<script>alert('借阅成功!')</script>"); } }
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Cancel") { string reader = this.Label2.Text; int index = Convert.ToInt32(e.CommandArgument); string book = this.GridView2.Rows[index].Cells[0].Text.ToString(); string sql_order_delete = "delete from [Library].[library].[Order] where [OrderRname] like '" + reader + "' and [OrderBname] like '" + book + "'"; DataManage dm = new DataManage(); dm.ExecuteSql(sql_order_delete); Response.Write("<script>alert('取消成功!')</script>"); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "return") { int index = Convert.ToInt32(e.CommandArgument); string borrowid = this.GridView1.Rows[index].Cells[0].Text.ToString(); string sql = "update [Library].[library].[Borrow] set [Bookstate] ='return' where [Borrowid] = " + borrowid; DataManage dm = new DataManage(); dm.ExecuteSql(sql); Response.Write("<script>alert('还书成功!')</script>"); gridBind(); } }
private void dataoperator() { DataManage dm = new DataManage(); string rname = this.TextBox3.Text; string rnum = this.TextBox4.Text; string bid = this.TextBox5.Text; string bname = this.TextBox6.Text; string sql = "insert into [Library].[library].[Order] ([OrderRname], [OrderRnum],[OrderBname],[OrderBid]) VALUES ('" + rname + "','" + rnum + "','" + bname + "'," + bid + ")"; if (Page.IsValid == true) { dm.ExecuteSql(sql); Response.Write("<script>预约成功!</script>"); Response.Redirect("Success.aspx", true); } }
protected void Button1_Click(object sender, EventArgs e) { DataManage dm = new DataManage(); string name = TextBox3.Text; string num = TextBox4.Text; string pwd = TextBox5.Text; string sql = "insert into [Library].[library].[Admin] ([Adminname], [Adminnum],[Adminpwd]) VALUES ('" + name + "','" + num + "','" + pwd + "')"; if (Page.IsValid == true) { dm.ExecuteSql(sql); Session["AdminName"] = name; Response.Write("<script>注册成功!</script>"); Response.Redirect("./AdminPage.aspx", true); } }
protected void Button1_Click(object sender, EventArgs e) { string name = this.TextBox3.Text; string num = this.TextBox4.Text; string pwd = this.TextBox5.Text; string type = this.DropDownList1.SelectedItem.Text; int index = this.DropDownList1.SelectedIndex; int allocation = -1; switch (index) { case 0: allocation = 6; break; case 1: allocation = 9; break; case 2: allocation = 12; break; case 3: allocation = 12; break; } string sql_1 = "insert into [Library].[library].[Reader] ([Rname], [Rnumber],[Rtype],[Rallocation],[Rpwd]) VALUES ('" + name + "','" + num + "','" + type + "'," + allocation + ",'" + pwd + "')"; string sql_2 = "select * from [Library].[library].[Reader] where [Rname] like '" + name + "' and [Rnumber] like '" + num + "'"; DataManage dm = new DataManage(); if (Page.IsValid == true) { DataTable dt = dm.ReadTable(sql_2); if (dt.Rows.Count > 0) { Response.Write("<script>alert('该用户已存在!')</script>"); } else { dm.ExecuteSql(sql_1); Session["UserName"] = name; Session["UserNumber"] = num; Response.Write("<script>alert('注册成功!')</script>"); string url = "UserPage.aspx?name=" + Session["UserName"].ToString() + "&id=" + Session["UserNumber"].ToString(); Response.Redirect(url, true); } } }
protected void Button1_Click(object sender, EventArgs e) { string name = this.TextBox3.Text; string writer = this.TextBox4.Text; string publish = this.TextBox5.Text; string date = DateTime.Now.ToShortDateString().ToString(); DataManage dm = new DataManage(); string sql = "insert into [Library].[library].[Apply] ([ApplyBname], [ApplyBwriter],[ApplyBpublish],[ApplyDate]) VALUES ('" + name + "','" + writer + "','" + publish + "','" + date + "')"; if (Page.IsValid == true) { dm.ExecuteSql(sql); Response.Write("<script>alert('申请成功!')</script>"); Response.Redirect("Success.aspx", true); } }
protected void Button2_Click(object sender, EventArgs e) { string name = this.TextBox1.Text; string num = this.TextBox2.Text; string pwd = this.TextBox3.Text; string sql = "update [Library].[library].[Admin] set [Adminname]='" + name + "', [Adminnum]='" + num + "', [Adminpwd]='" + pwd + "' where [Adminid] = " + Label1.Text; DataManage dm = new DataManage(); if (this.TextBox1.ReadOnly == false) { dm.ExecuteSql(sql); this.TextBox1.ReadOnly = true; this.TextBox2.ReadOnly = true; this.TextBox3.ReadOnly = true; Response.Write("<script>alert('修改成功!')</script>"); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) //续借 { if (e.CommandName == "Reborrow") { string rid = this.Label3.Text; int index = Convert.ToInt32(e.CommandArgument); string bid = this.GridView1.Rows[index].Cells[0].Text.ToString(); DateTime old_deadline = Convert.ToDateTime(this.GridView1.Rows[index].Cells[3].Text.ToString()); string new_deadline = old_deadline.AddDays(30).ToShortDateString().ToString(); string sql_borrow_adddays = "update [Library].[library].[Borrow] set [BorrowDeadline] = '" + new_deadline + "' where [BorrowRnum] like '" + rid + "' and [BorrowBid] like '" + bid + "'"; DataManage dm = new DataManage(); dm.ExecuteSql(sql_borrow_adddays); gridBind(); Response.Write("<script>alert('续借成功!')</script>"); } }
protected void Button2_Click(object sender, EventArgs e) { string name = this.TextBox1.Text; string type = this.DropDownList1.SelectedItem.Text; string writer = this.TextBox2.Text; string publish = this.TextBox3.Text; string price = this.TextBox4.Text; string sql = "update [Library].[library].[Book] set [Bname]='" + name + "', [Btype]='" + type + "', [Bwriter]='" + writer + "', [Bpublish]='" + publish + "', [Bprice]='" + price + "' where [Bid] = " + Label1.Text; DataManage dm = new DataManage(); if (this.TextBox1.ReadOnly == false) { dm.ExecuteSql(sql); this.TextBox1.ReadOnly = true; this.TextBox2.ReadOnly = true; this.TextBox3.ReadOnly = true; this.TextBox4.ReadOnly = true; this.DropDownList1.Enabled = false; Response.Write("<script>alert('修改成功!')</script>"); } }
protected void Button2_Click(object sender, EventArgs e) { string name = this.TextBox1.Text; string num = this.TextBox2.Text; string pwd = this.TextBox3.Text; string type = this.DropDownList1.SelectedItem.Text; int allocation = Convert.ToInt32(this.Label2.Text); int typeindex = (int)this.DropDownList1.SelectedIndex; switch (typeindex) { case 0: allocation = 6; break; case 1: allocation = 9; break; case 2: allocation = 12; break; case 3: allocation = 12; break; } string sql = "update [Library].[library].[Reader] set [Rname]='" + name + "', [Rnumber]='" + num + "', [Rtype]='" + type + "', [Rallocation]=" + allocation + ", [Rpwd]='" + pwd + "' where [Rid] = " + Label1.Text; DataManage dm = new DataManage(); if (this.TextBox1.ReadOnly == false) { dm.ExecuteSql(sql); this.TextBox1.ReadOnly = true; this.TextBox2.ReadOnly = true; this.TextBox3.ReadOnly = true; this.DropDownList1.Enabled = false; this.Label2.Text = allocation.ToString(); Response.Write("<script>修改成功!</script>"); } }