📄 adminyg.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;
using BLL;
public partial class AdminYG : System.Web.UI.Page
{
SQLHelper sqlHelper = new SQLHelper();
//SqlDataReader dr;
DataSet ds = new DataSet();
string sqlCounts = "select RowCounts=Count(*) from YuGongInfo where XingMing!=''";
string sql = "select YGId,XingMing,XingBie,CSNianYue from YuGongInfo where XingMing!=''";
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack){
if (!(Session["UserName"] != null && Session["UserRole"] == "Admin"))
{
Response.Redirect("../Default.aspx");
}
pager.RecordCount = GetRowCounts(sqlCounts);
BindYGData(sql);
}
}
protected void dgYG_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton btDelete = (LinkButton)e.Item.Cells[5].Controls[0];
btDelete.Attributes.Add("onclick", "javascript:return confirm('你确定要删除吗?');");
e.Item.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='E8F4FF'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
protected void GetSearchString()
{
if(tbXingMing .Text .Trim ()!=""){
sql = sql + " and XingMing='" + tbXingMing.Text.Trim()+"'";
sqlCounts = sqlCounts + " and XingMing='" + tbXingMing.Text.Trim()+"'";
}
}
protected int GetRowCounts(string sqlCounts)
{
int RowCounts = 0;
if (ds.Tables["RowCounts"] != null)
{
ds.Tables.Remove("RowCounts");
}
sqlHelper.RunSQL(sqlCounts, ref ds, "RowCounts");
RowCounts = Convert.ToInt32(ds.Tables["RowCounts"].Rows[0]["RowCounts"].ToString());
return RowCounts;
}
protected void BindYGData(string sql)
{
SqlCommand cmd = new SqlCommand();
sqlHelper.Open();
cmd.Connection = sqlHelper.myConnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
SqlDataAdapter sa = new SqlDataAdapter(cmd);
if (ds.Tables["YGData"] != null)
{
ds.Tables.Clear();
}
sa.Fill(ds, pager.PageSize * (pager.CurrentPageIndex - 1), pager.PageSize, "YGData");
dgYG.DataSource = ds.Tables["YGData"];
dgYG.DataBind();
AddCustomText();
}
public void AddCustomText()
{
pager.CustomInfoText = "员工总数:<font color=\"Green\"><b>" + pager.RecordCount.ToString() + "</b></font>";
pager.CustomInfoText += " 总页数:<font color=\"Green\"><b>" + pager.PageCount.ToString() + "</b></font>";
pager.CustomInfoText += " 当前页:<font color=\"red\"><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";
}
protected void ibtSearch_Click(object sender, ImageClickEventArgs e)
{
GetSearchString();
pager.RecordCount = GetRowCounts(sqlCounts);
BindYGData(sql);
}
protected void pager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
pager.CurrentPageIndex = e.NewPageIndex;
GetSearchString();
pager.RecordCount = GetRowCounts(sqlCounts);
BindYGData(sql);
}
protected void dgYG_DeleteCommand(object source, DataGridCommandEventArgs e)
{
Ed.DeleteYGEd(dgYG.DataKeys[e.Item.ItemIndex].ToString ());
XiangMu.DeleteYGXM(dgYG.DataKeys[e.Item.ItemIndex].ToString ());
YuanGong YG = new YuanGong();
YG.YGId = Convert.ToInt32(dgYG.DataKeys[e.Item.ItemIndex]);
YG.DeleteRelf();
GetSearchString();
pager.RecordCount = GetRowCounts(sqlCounts);
BindYGData(sql);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -