📄 roomthings.aspx.cs
字号:
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Desk", System.Data.SqlDbType.SmallInt, 2, "Room_Desk"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Light", System.Data.SqlDbType.SmallInt, 2, "Room_Light"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Bed", System.Data.SqlDbType.SmallInt, 2, "Room_Bed"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Seat", System.Data.SqlDbType.SmallInt, 2, "Room_Seat"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Closet", System.Data.SqlDbType.SmallInt, 2, "Room_Closet"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_WaterBill", System.Data.SqlDbType.Money, 8, "Room_WaterBill"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_ElectricalBill", System.Data.SqlDbType.Money, 8, "Room_ElectricalBill"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT Room_ID, Floor_ID, Room_NO, Room_Sta, Room_Phone, Room_Desk, Room_Light, R" +
"oom_Bed, Room_Seat, Room_Closet, Room_WaterBill, Room_ElectricalBill FROM Room";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE Room SET Room_ID = @Room_ID, Floor_ID = @Floor_ID, Room_NO = @Room_NO, Room_Sta = @Room_Sta, Room_Phone = @Room_Phone, Room_Desk = @Room_Desk, Room_Light = @Room_Light, Room_Bed = @Room_Bed, Room_Seat = @Room_Seat, Room_Closet = @Room_Closet, Room_WaterBill = @Room_WaterBill, Room_ElectricalBill = @Room_ElectricalBill WHERE (Room_ID = @Original_Room_ID) AND (Floor_ID = @Original_Floor_ID) AND (Room_Bed = @Original_Room_Bed) AND (Room_Closet = @Original_Room_Closet) AND (Room_Desk = @Original_Room_Desk) AND (Room_ElectricalBill = @Original_Room_ElectricalBill OR @Original_Room_ElectricalBill IS NULL AND Room_ElectricalBill IS NULL) AND (Room_Light = @Original_Room_Light) AND (Room_NO = @Original_Room_NO) AND (Room_Phone = @Original_Room_Phone OR @Original_Room_Phone IS NULL AND Room_Phone IS NULL) AND (Room_Seat = @Original_Room_Seat) AND (Room_Sta = @Original_Room_Sta) AND (Room_WaterBill = @Original_Room_WaterBill OR @Original_Room_WaterBill IS NULL AND Room_WaterBill IS NULL); SELECT Room_ID, Floor_ID, Room_NO, Room_Sta, Room_Phone, Room_Desk, Room_Light, Room_Bed, Room_Seat, Room_Closet, Room_WaterBill, Room_ElectricalBill FROM Room WHERE (Room_ID = @Room_ID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_ID", System.Data.SqlDbType.BigInt, 8, "Room_ID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Floor_ID", System.Data.SqlDbType.SmallInt, 2, "Floor_ID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_NO", System.Data.SqlDbType.Int, 4, "Room_NO"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Sta", System.Data.SqlDbType.TinyInt, 1, "Room_Sta"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Phone", System.Data.SqlDbType.BigInt, 8, "Room_Phone"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Desk", System.Data.SqlDbType.SmallInt, 2, "Room_Desk"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Light", System.Data.SqlDbType.SmallInt, 2, "Room_Light"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Bed", System.Data.SqlDbType.SmallInt, 2, "Room_Bed"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Seat", System.Data.SqlDbType.SmallInt, 2, "Room_Seat"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_Closet", System.Data.SqlDbType.SmallInt, 2, "Room_Closet"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_WaterBill", System.Data.SqlDbType.Money, 8, "Room_WaterBill"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_ElectricalBill", System.Data.SqlDbType.Money, 8, "Room_ElectricalBill"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_ID", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_ID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Floor_ID", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Floor_ID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_Bed", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_Bed", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_Closet", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_Closet", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_Desk", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_Desk", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_ElectricalBill", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_ElectricalBill", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_Light", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_Light", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_NO", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_NO", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_Phone", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_Phone", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_Seat", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_Seat", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_Sta", System.Data.SqlDbType.TinyInt, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_Sta", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_WaterBill", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_WaterBill", System.Data.DataRowVersion.Original, null));
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=e.Item.ItemIndex;
if(this.TextBox1.Text!="")
Grid_Bind();
else if(this.TextBox1.Text=="")
Data_Bind();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
myConn=ConfigurationSettings.AppSettings["mySql"];
string cmdstr="update Room set Room_Desk='"+((TextBox)e.Item.Cells[3].Controls[0]).Text+"', Room_Seat='"+((TextBox)e.Item.Cells[4].Controls[0]).Text+"', Room_Closet='"+((TextBox)e.Item.Cells[5].Controls[0]).Text+"',Room_Light='"+((TextBox)e.Item.Cells[6].Controls[0]).Text+"',Room_Bed='"+((TextBox)e.Item.Cells[7].Controls[0]).Text+"' where Room_ID='"+e.Item.Cells[0].Text+"'";
conn=new System.Data.SqlClient.SqlConnection(myConn);
conn.Open();
cmd=new System.Data.SqlClient.SqlCommand(cmdstr,conn);
cmd.ExecuteNonQuery();
conn.Close();
this.DataGrid1.EditItemIndex=-1;
if(this.TextBox1.Text!="")
Grid_Bind();
else if(this.TextBox1.Text=="")
Data_Bind();
}
catch(Exception ex)
{
Response.Write("<script>alert('"+ex.Message+"输入数据格式错误!')</script>");
}
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=-1;
if(this.TextBox1.Text!="")
Grid_Bind();
else if(this.TextBox1.Text=="")
Data_Bind();
}
private void Search1_Click(object sender, System.EventArgs e)
{
this.DataGrid1.CurrentPageIndex=0;
string s;
s=this.DropDownList1.SelectedValue.ToString()+"="+"'"+this.TextBox1.Text+"'";
this.myConn=ConfigurationSettings.AppSettings["mySql"];
this.conn=new System.Data.SqlClient.SqlConnection(myConn);
try
{
if(this.TextBox1.Text!="")
{
cmdText="select * from Room where ";
cmdText=cmdText+s;
this.sqlConnection1=new System.Data.SqlClient.SqlConnection(myConn);
this.sqlConnection1.Open();
this.sqlDataAdapter1=new System.Data.SqlClient.SqlDataAdapter(cmdText,this.sqlConnection1);
this.dataSet11=new DataSet1();
this.sqlDataAdapter1.Fill(this.dataSet11,"Room");
this.DataGrid1.DataSource=this.dataSet11;
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
//this.Label2.Text=this.DropDownList1.SelectedItem.Text+"为"+this.TextBox1.Text+"的寝室共有"+Convert.ToString(i)+"间";
}
else
{
Response.Write("<script>alert('请输入查询条件!')</script>");
Data_Bind();
}
}
catch(Exception ex)
{
Response.Write("<script>alert('"+ex.Message+"查询条件格式错误!')</script>");
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
if(this.TextBox1.Text!="")
Grid_Bind();
else if(this.TextBox1.Text=="")
Data_Bind();
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
((TextBox)e.Item.Cells[3].Controls[0]).Width = Unit.Pixel(40);
((TextBox)e.Item.Cells[4].Controls[0]).Width = Unit.Pixel(40);
((TextBox)e.Item.Cells[5].Controls[0]).Width = Unit.Pixel(40);
((TextBox)e.Item.Cells[6].Controls[0]).Width = Unit.Pixel(40);
((TextBox)e.Item.Cells[7].Controls[0]).Width = Unit.Pixel(40);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -