⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 borrowbookedit.aspx.cs

📁 管理系统源码 很好的用于参考很好对开发毕业设计很有帮助
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
//该源码下载自【编程联盟】ASp.Net下载中心 【 http://aspx.bcbbs.net 】
//该源码下载自【编程联盟】ASp.Net下载中心 【 http://aspx.bcbbs.net 】
//该源码下载自【编程联盟】ASp.Net下载中心 【 http://aspx.bcbbs.net 】

public partial class Pages_BorrowBookEdit : System.Web.UI.Page
{
    //更新标志
    public static string Update_Flag;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //取得参数
            string strCode = Request.QueryString["ID"];
           
            //判断是添加还是编辑
            if (strCode == null || strCode == "")
            {
                //设置标题
                this.Title = "图书借阅管理--添加";

                //设置更新标志
                Update_Flag = "Add";
            }
            else
            {
                //设置标题
                this.Title = "图书借阅管理--编辑";

                //保存参数
                lblID.Text = strCode;

                //设置更新标志
                Update_Flag = "Update";

                //绑定信息
                BindData();
            }
        }
    }
    private void BindData()
    {
        //定义一个连接对象
        SqlConnection conn = new SqlConnection("server=(local);database=school;uid=sa;pwd=");

        //SQL 语句
        string strSql = "select * from BookBorrow where BorrowID='" + lblID.Text + "'";

        //定义一个适配器,从数据库中去数据
        SqlDataAdapter adapter = new SqlDataAdapter(strSql, conn);

        //定义数据集
        DataSet dsBook = new DataSet();

        conn.Open();

        //用适配器填充数据集
        adapter.Fill(dsBook, "Book");

        conn.Close();


        //将信息赋给控件 
        if (dsBook != null)
        {
            txtBookName.Text = dsBook.Tables["Book"].Rows[0]["BookName"].ToString();
            txtBorrowPeople.Text = dsBook.Tables["Book"].Rows[0]["BorrowPeople"].ToString();
            txtQuantity.Text = dsBook.Tables["Book"].Rows[0]["Quantity"].ToString();
            txtBorrowDate.Text = dsBook.Tables["Book"].Rows[0]["BorrowDate"].ToString();
            txtHandlingPeople.Text = dsBook.Tables["Book"].Rows[0]["HandlingPeople"].ToString();
            txtPlanReturnDate.Text = dsBook.Tables["Book"].Rows[0]["PlanReturnDate"].ToString();
            txtRemark.Text = dsBook.Tables["Book"].Rows[0]["Remark"].ToString();
            for (int i = 0; i < ddlUnit.Items.Count; i++)
            {
                if (ddlUnit.Items[i].Text.ToString() == dsBook.Tables["Book"].Rows[0]["Unit"].ToString())
                {
                    ddlUnit.SelectedIndex = i;
                    break;
                }
            }
        }

        dsBook.Dispose();
    }
    protected void btnOK_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection conn = new SqlConnection("server=(local);database=school;uid=sa;pwd=");

        string strSql = "";
        //判断更新标志,Add为添加, update为修改
        if (Update_Flag == "Add")
        {
            //添加语句
            strSql = "INSERT INTO BookBorrow(BookName, BorrowPeople,BorrowDate,Quantity,Unit,PlanReturnDate,HandlingPeople,Remark)VALUES ('"
                +txtBookName.Text.Trim()+"','"+ txtBorrowPeople.Text.Trim()+"','"+txtBorrowDate.Text+"','"+txtQuantity.Text+"','"+ddlUnit.SelectedItem.Text+"','"+txtPlanReturnDate.Text
                +"','"+txtHandlingPeople.Text.Trim()+"','"+txtRemark.Text.Trim()+"')";
        }
        else if (Update_Flag == "Update")
        {
            //修改语句
            strSql = "UPDATE BookBorrow SET BookName='" + txtBookName.Text.Trim() + "', BorrowPeople = '" + txtBorrowPeople.Text.Trim() + "',BorrowDate = '" + txtBorrowDate.Text + "',Quantity = '" + txtQuantity.Text + "',Unit = '" + ddlUnit.SelectedItem.Text + "',PlanReturnDate ='"
                + txtPlanReturnDate.Text + "',HandlingPeople = '" + txtHandlingPeople.Text.Trim() + "',Remark = '" + txtRemark.Text.Trim() + "' WHERE  BorrowID = '" + lblID.Text + "'";
;
        }

        SqlCommand cmd = new SqlCommand(strSql, conn);

        try
        {
            conn.Open();

            cmd.ExecuteNonQuery();

            //关闭子窗体,刷新父窗体
            Response.Write("<script>window.close();window.opener.location='BorrowBook.aspx'; </script>");
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
        finally
        {
            conn.Close();
        }
    }
    protected void btnCancel_Click(object sender, ImageClickEventArgs e)
    {
        //关闭子窗体
        Response.Write("<script>window.close(); </script>");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -