📄 notice.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;
public partial class admin_Default2 : System.Web.UI.Page
{
BaseClass bc = new BaseClass();//定义一个公共类的实例
stringoperator strOper =new stringoperator();
public static string sql = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(Session["UID"]) == "")
{
Response.Redirect("login.aspx");
}
if(!IsPostBack)
{
this.bind();
Button6.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
}
}
protected void bind()
{
string sqlvv = "select * from notice"+sql+" order by noticeDate desc";
// Response.Write(sqlvv);
bc.ExecGridView(GridView1, sqlvv);
}
//分页事件
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.bind();
}
//删除公告
//protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
//{
// string ownerid = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
// //Response.Write(id);
// //Response.End();
// BaseClass bcc = new BaseClass();
// string sqlstr = "delete from notice where ID='" + ownerid + "'";
// if (bcc.ExecSql(sqlstr))
// {
// Response.Write("<script>alert('删除信息成功!');</script>");
// this.bind();
// }
// else
// {
// Response.Write("<script>alert('操作失败!');</script>");
// }
//}
//公告编辑
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
string id = this.GridView1.DataKeys[e.NewEditIndex].Value.ToString();
//Response.Write("<script>window.open('editnotice.aspx?ID=" + id + "','','width=450,height=450')</script>");//弹出新窗口
Response.Redirect("editnotice.aspx?ID=" + id + "");
Response.Write("<script>location='javascript:history.go(-1)'</script>");
}
//数据绑定
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.ToString().Length >30)
{
e.Row.Cells[1].Text = strOper.SubStr(e.Row.Cells[1].Text.ToString(), 20);//如果一串字符大于一定长度就载取部份显示
}
//((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#99ccff';this.Style.color='buttontext';this.Style.cursor='default';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
sql = "";
this.bind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Hashtable htabel = new Hashtable();
if (CheckBox1.Checked)
{
htabel.Add("ID", TextBox1.Text);
// Response.Write(htabel["unitName"].GetType().ToString());
// Response.End();
}
if (CheckBox3.Checked)
{
htabel.Add("title", TextBox3.Text);
}
if (CheckBox4.Checked)
{
htabel.Add("noticePerson", TextBox4.Text);
}
if (CheckBox6.Checked)
{
sql = strOper.GetConditionClause(htabel, true);
}
else
{
sql = strOper.GetConditionClause(htabel, false);
}
if (CheckBox2.Checked)
{
if (htabel.Count>0)
{
sql = sql + " and noticeDate between '" + TextBox2.Text + "' and '" + TextBox5.Text + "'";
}
else
{
sql = " where noticeDate between '" + TextBox2.Text + "' and '" + TextBox5.Text + "'";
}
}
//Response.Write(sql);
// Response.End();
this.bind();
}
//全选
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkSelect = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
chkSelect.Checked = true;
}
}
//
protected void Button4_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkSelect = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
chkSelect.Checked = !chkSelect.Checked;
}
}
//取消
protected void Button5_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkSelect = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
chkSelect.Checked = false;
}
}
//
protected void Button6_Click(object sender, EventArgs e)
{
ArrayList sqltrans = new ArrayList();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkSelect = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
if (chkSelect.Checked)
{
string str = ((Label)GridView1.Rows[i].FindControl("labID")).Text;
string sqlstr = "delete from notice where ID='" + str+"'";
sqltrans.Add(sqlstr);
}
}
//foreach (string item in sqltrans)
//{
// Response.Write(item + "</br>");
//}
//Response.End();
if (bc.ExecSQLTrans(sqltrans))
{
Response.Write("<script>alert('删除信息成功!');</script>");
this.bind();
}
else
{
Response.Write("<script>alert('操作失败!');</script>");
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -