📄 booksubscriptionedit.aspx.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_BookSubscriptionEdit : System.Web.UI.Page
{
//更新标志 指示此页面是添加数据还是编辑数据
public static string Update_Flag;
//页面加载方法
protected void Page_Load(object sender, EventArgs e)
{
//判断页面是否是首次加载
if (!IsPostBack)
{
//取得参数
string strID = Request.QueryString["ID"];
//判断是添加还是编辑
if (strID == null || strID == "")
{
//设置标题
this.Title = "图书征订管理--添加";
//设置更新标志
Update_Flag = "Add";
}
else
{
//设置标题
this.Title = "图书征订管理--编辑";
//保存参数
lblID.Text = strID;
//设置更新标志
Update_Flag = "Update";
//绑定信息
BindData();
}
}
}
//数据绑定方法
private void BindData()
{
//定义一个连接对象
SqlConnection conn = new SqlConnection("server=(local);database=school;uid=sa;pwd=");
//SQL 语句
string strSql = "select * from BookSubscription where ID='" + 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();
txtDeptment.Text = dsBook.Tables["Book"].Rows[0]["SubscriptionDeptment"].ToString();
txtSuperintendent.Text = dsBook.Tables["Book"].Rows[0]["Superintendent"].ToString();
txtContact.Text = dsBook.Tables["Book"].Rows[0]["Contact"].ToString();
txtQuantity.Text = dsBook.Tables["Book"].Rows[0]["Quantity"].ToString();
txtUnit.Text = dsBook.Tables["Book"].Rows[0]["Unit"].ToString();
txtBookType.Text = dsBook.Tables["Book"].Rows[0]["BookType"].ToString();
txtPrice.Text = dsBook.Tables["Book"].Rows[0]["Price"].ToString();
txtCurrencyUnit.Text = dsBook.Tables["Book"].Rows[0]["CurrencyUnit"].ToString();
txtReamrks.Text = dsBook.Tables["Book"].Rows[0]["Remarks"].ToString();
txtHandlingPeople.Text = dsBook.Tables["Book"].Rows[0]["HandlingPeople"].ToString();
txtHandlingPeopleContact.Text = dsBook.Tables["Book"].Rows[0]["HandlingPeopleContact"].ToString();
txtDate.Text = dsBook.Tables["Book"].Rows[0]["DateReceived"].ToString();
}
}
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 BookSubscription(BookName,SubscriptionDeptment,Superintendent,Contact,Quantity,Unit,BookType,Price,CurrencyUnit,Remarks,HandlingPeople,HandlingPeopleContact,DateReceived)";
strSql += "VALUES('" + txtBookName.Text.Trim() + "','" + txtDeptment.Text.Trim() + "','" + txtSuperintendent.Text.Trim() + "','" + txtContact.Text.Trim() + "', '" + txtQuantity.Text.Trim() + "','" + txtUnit.Text.Trim() + "','"
+ txtBookType.Text.Trim() + "','" + txtPrice.Text.Trim() + "','" + txtCurrencyUnit.Text.Trim() + "','" + txtReamrks.Text.Trim() + "','" + txtHandlingPeople.Text.Trim() + "','" + txtHandlingPeopleContact.Text.Trim() + "','" + txtDate.Text.Trim() + "')";
}
else if (Update_Flag == "Update")
{
//修改语句
strSql = "UPDATE BookSubscription SET BookName = '" + txtBookName.Text.Trim() + "',SubscriptionDeptment = '" + txtDeptment.Text.Trim() + "',Superintendent = '" + txtSuperintendent.Text.Trim() + "',Contact = '" + txtContact.Text.Trim() + "',Quantity = '" + txtQuantity.Text.Trim() + "',Unit = '" + txtUnit.Text.Trim() + "',BookType = '" + txtBookType.Text.Trim()
+ "',Price = '" + txtPrice.Text.Trim() + "',CurrencyUnit = '" + txtCurrencyUnit.Text.Trim() + "',Remarks = '" + txtReamrks.Text.Trim() + "',HandlingPeople = '"+txtHandlingPeople.Text.Trim()+"',HandlingPeopleContact = '" + txtHandlingPeopleContact.Text.Trim() + "',DateReceived = '" + txtDate.Text.Trim() + "' WHERE ID = " + lblID.Text;
}
SqlCommand cmd = new SqlCommand(strSql, conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
//关闭子窗体,刷新父窗体
Response.Write("<script>window.close();window.opener.location='BookSubscription.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 + -