📄 admingoodhome.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 admingoodhome : System.Web.UI.Page
{
DataSet ds3 = new DataSet();
SqlCommand cmd, cmd1,cmd2,cmd3;
SqlConnection cn;
SqlDataReader dr, dr1;
SqlDataAdapter da, da1,da2,da3;
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();
string strsql, strsql1, strsql2,strsql3,strsql4;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.databindlist();
if (Session["adminname"] == null)
{
Response.Redirect("index.aspx");
}
}
}
private void databindlist()
{
string youxiu = "是";
cn = sqldata.createcon();
cn.Open();
strsql2 = "select distinct homeflood,homehao,homecount,homephone,homefen,homesex,homeyn from home where homeyn='"+youxiu+"'" ;
da1 = new SqlDataAdapter (strsql2, cn);
da1.Fill(ds);
this.mydatagrid3.DataSource = ds.Tables[(0)].DefaultView;
this.mydatagrid3.DataBind();
}
protected void mydatagrid3_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.mydatagrid3.CurrentPageIndex = e.NewPageIndex;
this.databindlist();
}
protected void mydatagrid3_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='#d3d3d3'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.IsValid)
{
if (this.DropDownList1.Text == "几栋")
{
string youxiu = "是";
cn = sqldata.createcon();
cn.Open();
strsql1 = "select distinct homeflood,homehao,homecount,homephone,homefen,homesex ,homeyn from home where homeflood='" + this.txtcontent.Text.ToString() + "' and homeyn='" + youxiu + "'";
da1 = new SqlDataAdapter (strsql1, cn);
da1.Fill(ds1);
this.mydatagrid3.DataSource = ds1.Tables[(0)].DefaultView;
this.mydatagrid3.DataBind();
if (this.mydatagrid3.Items.Count == 0)
{
this.Panel1.Visible = false;
this.labmessage.Text = "对不起?要找的" + this.txtcontent.Text.ToString() + "内容还没有找到";
this.HyperLink1.Visible = true;
}
else
{
this.Panel1.Visible = true;
this.HyperLink1.Visible = true;
this.labmessage.Text = "恭喜!要找的" + this.txtcontent.Text.ToString() + "内容找到了"; ;
}
}
else if (this.DropDownList1.Text == "几号")
{
string youxiu = "是";
cn = sqldata.createcon();
cn.Open();
strsql = "select distinct homeflood,homehao,homecount,homephone,homefen,homesex,homeyn from home where homehao='" + this.txtcontent.Text.ToString() + "' and homeyn='" + youxiu + "'";
da = new SqlDataAdapter (strsql, cn);
da.Fill(ds);
this.mydatagrid3.DataSource = ds.Tables[(0)].DefaultView;
this.mydatagrid3.DataBind();
if (this.mydatagrid3.Items.Count == 0)
{
this.Panel1.Visible = false;
this.labmessage.Text = "对不起?要找的" + this.txtcontent.Text.ToString() + "内容还没有找到";
this.HyperLink1.Visible = true;
}
else
{
this.Panel1.Visible = true;
this.HyperLink1.Visible = true;
this.labmessage.Text = "恭喜!要找的" + this.txtcontent.Text.ToString() + "内容找到了"; ;
}
}
else
{
string youxiu = "是";
cn = sqldata.createcon();
cn.Open();
strsql3 = "select distinct homeflood,homehao,homecount,homephone,homefen,homesex ,homeyn from home where homefen='" + this.txtcontent.Text.ToString() + "' and homeyn='" + youxiu + "'";
da3 = new SqlDataAdapter (strsql3, cn);
da3.Fill(ds3);
this.mydatagrid3.DataSource = ds3.Tables[(0)].DefaultView;
this.mydatagrid3.DataBind();
if (this.mydatagrid3.Items.Count == 0)
{
this.Panel1.Visible = false;
this.labmessage.Text = "对不起?要找的" + this.txtcontent.Text.ToString() + "内容还没有找到";
this.HyperLink1.Visible = true;
}
else
{
this.Panel1.Visible = true;
this.HyperLink1.Visible = true;
this.labmessage.Text = "恭喜!要找的" + this.txtcontent.Text.ToString() + "内容找到了"; ;
}
}
}
}
protected void mydatagrid3_CancelCommand(object source, DataGridCommandEventArgs e)
{
this.mydatagrid3.EditItemIndex = -1;
this.databindlist();
}
protected void mydatagrid3_EditCommand(object source, DataGridCommandEventArgs e)
{
this.mydatagrid3.EditItemIndex = e.Item.ItemIndex;
this.databindlist();
}
protected void mydatagrid3_UpdateCommand(object source, DataGridCommandEventArgs e)
{
string homeflood = ((TextBox)(e.Item.Cells[0].Controls[0])).Text.ToString();
string homecount = ((TextBox)(e.Item.Cells[3].Controls[0])).Text.ToString();
string homehao = ((TextBox)(e.Item.Cells[2].Controls[0])).Text.ToString();
string homesex = ((TextBox)(e.Item.Cells[1].Controls[0])).Text.ToString();
string homephone = ((TextBox)(e.Item.Cells[4].Controls[0])).Text.ToString();
string homefen = ((TextBox)(e.Item.Cells[5].Controls[0])).Text.ToString();
cn = sqldata.createcon();
cn.Open();
strsql4 = "update home set home='" + homefen + "' where homesex='" + homesex + "'and homeflood='" + homeflood + "' and homehao='" + homehao + "' and homecount='" + homecount + "' and homephone='" + homephone + "'";
cmd3 = new SqlCommand (strsql4, cn);
cmd3.ExecuteNonQuery();
cn.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -