📄 homeadd.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 ;
public partial class homeadd : System.Web.UI.Page
{
SqlCommand cmd, cmd1;
SqlConnection cn;
SqlDataReader dr, dr1;
SqlDataAdapter da, da1;
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();
string strcon, strsql,strsql1,strsql2;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (Session["adminname"] == null)
{
Response.Redirect("index.aspx");
}
else
{
this.databindlist();
}
}
}
private void databindlist()
{
cn = sqldata.createcon();
cn.Open();
strsql = "select * from homedetail";
da = new SqlDataAdapter (strsql, cn);
da.Fill(ds);
this.mydatagrid.DataSource = ds.Tables[(0)].DefaultView;
this.mydatagrid.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.IsValid)
{
cn = sqldata.createcon();
cn.Open();
strsql2 = "select * from homedetail where home='"+this.homename .Text .ToString ().Trim ()+"' and homesex='"+this.homesex .SelectedItem .Value .ToString ()+"'";
cmd1 = new SqlCommand (strsql2, cn);
dr = cmd1.ExecuteReader();
if (dr.Read())
{
Session["home"] = dr["home"].ToString().Trim ();
Session["homesex"] = dr["homesex"].ToString();
Session["id"] = dr["id"].ToString();
this.Label1.Text = "要添加的寝室楼已经存在了.";
}
else
{
dr.Close();
strsql1 = "insert into homedetail(home,homesex)values('"+this.homename .Text .ToString ().Trim ()+"','"+this.homesex .SelectedItem .Value .ToString ()+"')";
cmd = new SqlCommand (strsql1, cn);
cmd.ExecuteNonQuery();
cn.Close();
this.Label1.Text = "添加成功";
}
}
}
protected void mydatagrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.mydatagrid.CurrentPageIndex = e.NewPageIndex;
this.databindlist();
}
protected void mydatagrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#808080'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -