📄 managescape.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;
using System.Data.SqlClient;
namespace hotel.manage
{
/// <summary>
/// managerscape 的摘要说明。
/// </summary>
public class managerscape : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected hotel.manage.DataSet3 dataSet31;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
void bindData()
{
sqlDataAdapter1.Fill(dataSet31);
DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
bindData();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet31 = new hotel.manage.DataSet3();
((System.ComponentModel.ISupportInitialize)(this.dataSet31)).BeginInit();
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"TWJ-9490D5784F6\";packet size=4096;user id=sa;data source=\".\";pers" +
"ist security info=True;initial catalog=twj;password=sa";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "scape", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("scapeid", "scapeid"),
new System.Data.Common.DataColumnMapping("scapename", "scapename"),
new System.Data.Common.DataColumnMapping("picture", "picture"),
new System.Data.Common.DataColumnMapping("presentation", "presentation"),
new System.Data.Common.DataColumnMapping("price", "price"),
new System.Data.Common.DataColumnMapping("bus", "bus")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM scape WHERE (scapename = @Original_scapename) AND (bus = @Original_bus OR @Original_bus IS NULL AND bus IS NULL) AND (picture = @Original_picture OR @Original_picture IS NULL AND picture IS NULL) AND (price = @Original_price OR @Original_price IS NULL AND price IS NULL) AND (scapeid = @Original_scapeid)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_scapename", System.Data.SqlDbType.VarChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "scapename", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bus", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bus", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_picture", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "picture", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_price", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_scapeid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "scapeid", System.Data.DataRowVersion.Original, null));
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO scape(scapeid, scapename, picture, presentation, price, bus) VALUES (" +
"@scapeid, @scapename, @picture, @presentation, @price, @bus); SELECT scapeid, sc" +
"apename, picture, presentation, price, bus FROM scape WHERE (scapename = @scapen" +
"ame)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@scapeid", System.Data.SqlDbType.Int, 4, "scapeid"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@scapename", System.Data.SqlDbType.VarChar, 100, "scapename"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@picture", System.Data.SqlDbType.VarChar, 50, "picture"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@presentation", System.Data.SqlDbType.VarChar, 2147483647, "presentation"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@price", System.Data.SqlDbType.VarChar, 20, "price"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bus", System.Data.SqlDbType.VarChar, 50, "bus"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT scapeid, scapename, picture, presentation, price, bus FROM scape";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE scape SET scapeid = @scapeid, scapename = @scapename, picture = @picture, presentation = @presentation, price = @price, bus = @bus WHERE (scapename = @Original_scapename) AND (bus = @Original_bus OR @Original_bus IS NULL AND bus IS NULL) AND (picture = @Original_picture OR @Original_picture IS NULL AND picture IS NULL) AND (price = @Original_price OR @Original_price IS NULL AND price IS NULL) AND (scapeid = @Original_scapeid); SELECT scapeid, scapename, picture, presentation, price, bus FROM scape WHERE (scapename = @scapename)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@scapeid", System.Data.SqlDbType.Int, 4, "scapeid"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@scapename", System.Data.SqlDbType.VarChar, 100, "scapename"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@picture", System.Data.SqlDbType.VarChar, 50, "picture"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@presentation", System.Data.SqlDbType.VarChar, 2147483647, "presentation"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@price", System.Data.SqlDbType.VarChar, 20, "price"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bus", System.Data.SqlDbType.VarChar, 50, "bus"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_scapename", System.Data.SqlDbType.VarChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "scapename", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_bus", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "bus", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_picture", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "picture", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_price", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "price", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_scapeid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "scapeid", System.Data.DataRowVersion.Original, null));
//
// dataSet31
//
this.dataSet31.DataSetName = "DataSet3";
this.dataSet31.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet31)).EndInit();
}
#endregion
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
((LinkButton)(e.Item.Cells[6].Controls[0])).Attributes.Add("onclick","return confirm('确认要删除吗?');");
((LinkButton)(e.Item.Cells[7].Controls[0])).Attributes.Add("onclick","return confirm('确认要修改吗?');");
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
this.bindData();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
bindData();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int scapeid=Convert.ToInt32(this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString());
SqlConnection con=DB.createCon();
SqlCommand cmd=new SqlCommand("delete from scape where scapeid='"+scapeid+"'",con);
con.Open();
cmd.ExecuteNonQuery();
this.bindData();
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{
Response.Redirect("addscape.aspx");
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=-1;
bindData();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlConnection con =DB.createCon();
con.Open ();
int scapeid= Convert.ToInt32(this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString());
//非只读绑定列,处于编辑状态
string scapename= ((TextBox)(e.Item.Cells[1].Controls[0])).Text;
string picture = ((TextBox)(e.Item.Cells[2].Controls[0])).Text;
string presentation= ((TextBox)(e.Item.Cells[3].Controls[0])).Text;
string price= ((TextBox)(e.Item.Cells[4].Controls[0])).Text;
string bus= ((TextBox)(e.Item.Cells[5].Controls[0])).Text;
// this.Response.Write(readersex);
string strSql = "update scape set scapename = '"+scapename+"',picture='"+picture+"',presentation='"+presentation+"',price='"+price+"',bus='"+bus+"'where scapeid =" +scapeid;
// string strSql = "update 读者信息表 set readername = '" + readername + "',readsex='"+readersex+"',readerdep='"+readerdep+"',readertype='"+readertype+"'where readerid =" + readerid;
SqlCommand cmd=new SqlCommand (strSql,con);
try
{
cmd.ExecuteNonQuery();
this.Response.Write(" <script language ='javascript'> alert ('更新成功!')</script>");
this.DataGrid1.EditItemIndex=-1; //退出行的编辑模式
}
catch
{
this.Response.Write(" <script language ='javascript'> alert ('更新失败!')</script>");
}
this.DataGrid1.EditItemIndex=-1;
bindData();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -