c#注释一段代码!球大神
1个回答
2014-01-22
展开全部
public partial class System_Sys_Member_List : System.Web.UI.Page
{
protected string con = CommonLib.SqlHelper.SqlConnectionString;//获取连接字符串
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CommonLib.SqlHelper.islogin(Page); //检测用户是否已登录
Bind();//如果上面的方法返回true 就会对gridview控件进行绑定
}
}
#region 绑定
private void Bind()
{
string count = "select count(*) from member"; //查询总记录数
AspNetPager1.RecordCount = Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, count, null));//绑定分页控件总记录数
string sql = "select * from member order by m_id desc";
CommonLib.SqlHelper.BindGridView(GridView1, sql, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex - 1);//该方法绑定分页控件和gridview
//如果存在记录,全选按钮可用
if (AspNetPager1.RecordCount > 0)
{
quanxuan.Visible = true;
Button2.Visible = true;
}
else
{
quanxuan.Visible = false;
Button2.Visible = false;
}
}
#endregion
#region 分¤?页°3 //翻页事件
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
Bind();
}
#endregion
#region 重置密码
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string sql = "";
//这个LinkButton按钮控件还是删除 CommandName属性为del,被点击时会进入这个if
if (e.CommandName == "del")
{
sql = "delete from member where m_id=" + e.CommandArgument.ToString();
try
{
//删除的方式就不用解释了吧,返回受影响的行数
int i = CommonLib.SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, null);
if (i > 0)
{
CommonLib.JavaScriptHelper.Alert("删除成功", this.Page);
}
else
{
CommonLib.JavaScriptHelper.Alert("服务器忙删除失败", this.Page);
}
}
catch
{
CommonLib.JavaScriptHelper.Alert("服务器忙删除失败", this.Page);
}
}
if (e.CommandName == "reset")
{
//这个后台的方法就是把密码加密 MD5加密
string n_pwd = CommonLib.EncryptHelper.Encrypt("123456", "MD5");
//然后更新现在的密码
sql = "update member set m_pwd='" + n_pwd + "' where m_id=" + e.CommandArgument.ToString();
try
{
int i = CommonLib.SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, null);
if (i > 0)
{
CommonLib.JavaScriptHelper.Alert("密码成功初始密码为123456", this.Page);
}
else
{
CommonLib.JavaScriptHelper.Alert("服务器忙操作失败", this.Page);
}
}
catch
{
CommonLib.JavaScriptHelper.Alert("服务器忙操作失败", this.Page);
}
}
Bind();
}
#endregion
#region 批量删除
protected void Button2_Click(object sender, EventArgs e)
{
string idlist = "";
//遍历gridview中每一行
foreach (GridViewRow row in GridView1.Rows)
{
//获取每一行的CheckBox控件
CheckBox chkbx = (CheckBox)GridView1.Rows[row.RowIndex].Cells[6].FindControl("chk1");
//获取每一行的 ID ,其实这句话可以写在下面的那个if里面
int id = Convert.ToInt32(GridView1.Rows[row.RowIndex].Cells[0].Text);
//如果checkbox选中了就把ID保存起来
if (chkbx.Checked)
{
//拼接字符串 构造in的参数
idlist += id.ToString() + ",";
}
}
if (idlist.Length > 0)
{
//提取最后一个逗号之前的 字符串. 应该也可以这样写 idlist=idlist.TrimEnd(new char[]{'});
idlist = idlist.Substring(0, idlist.Length - 1);
string sql = "delete from member where m_id in (" + idlist + ")";
try
{
//这个执行删除的方法.不过最好用个事务
int i = CommonLib.SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, null);
if (i > 0)
{
Bind();
CommonLib.JavaScriptHelper.Alert("批量删除成功", this.Page);
}
else
CommonLib.JavaScriptHelper.Alert("服务器忙 删除失败", this.Page);
}
catch
{
CommonLib.JavaScriptHelper.Alert("服务器忙 删除失败", this.Page);
}
this.quanxuan.Value = " 全选 ";
}
else
{
CommonLib.JavaScriptHelper.Alert("选择需要删除的数据", this.Page);
}
}
#endregion
}
{
protected string con = CommonLib.SqlHelper.SqlConnectionString;//获取连接字符串
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CommonLib.SqlHelper.islogin(Page); //检测用户是否已登录
Bind();//如果上面的方法返回true 就会对gridview控件进行绑定
}
}
#region 绑定
private void Bind()
{
string count = "select count(*) from member"; //查询总记录数
AspNetPager1.RecordCount = Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, count, null));//绑定分页控件总记录数
string sql = "select * from member order by m_id desc";
CommonLib.SqlHelper.BindGridView(GridView1, sql, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex - 1);//该方法绑定分页控件和gridview
//如果存在记录,全选按钮可用
if (AspNetPager1.RecordCount > 0)
{
quanxuan.Visible = true;
Button2.Visible = true;
}
else
{
quanxuan.Visible = false;
Button2.Visible = false;
}
}
#endregion
#region 分¤?页°3 //翻页事件
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
Bind();
}
#endregion
#region 重置密码
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string sql = "";
//这个LinkButton按钮控件还是删除 CommandName属性为del,被点击时会进入这个if
if (e.CommandName == "del")
{
sql = "delete from member where m_id=" + e.CommandArgument.ToString();
try
{
//删除的方式就不用解释了吧,返回受影响的行数
int i = CommonLib.SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, null);
if (i > 0)
{
CommonLib.JavaScriptHelper.Alert("删除成功", this.Page);
}
else
{
CommonLib.JavaScriptHelper.Alert("服务器忙删除失败", this.Page);
}
}
catch
{
CommonLib.JavaScriptHelper.Alert("服务器忙删除失败", this.Page);
}
}
if (e.CommandName == "reset")
{
//这个后台的方法就是把密码加密 MD5加密
string n_pwd = CommonLib.EncryptHelper.Encrypt("123456", "MD5");
//然后更新现在的密码
sql = "update member set m_pwd='" + n_pwd + "' where m_id=" + e.CommandArgument.ToString();
try
{
int i = CommonLib.SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, null);
if (i > 0)
{
CommonLib.JavaScriptHelper.Alert("密码成功初始密码为123456", this.Page);
}
else
{
CommonLib.JavaScriptHelper.Alert("服务器忙操作失败", this.Page);
}
}
catch
{
CommonLib.JavaScriptHelper.Alert("服务器忙操作失败", this.Page);
}
}
Bind();
}
#endregion
#region 批量删除
protected void Button2_Click(object sender, EventArgs e)
{
string idlist = "";
//遍历gridview中每一行
foreach (GridViewRow row in GridView1.Rows)
{
//获取每一行的CheckBox控件
CheckBox chkbx = (CheckBox)GridView1.Rows[row.RowIndex].Cells[6].FindControl("chk1");
//获取每一行的 ID ,其实这句话可以写在下面的那个if里面
int id = Convert.ToInt32(GridView1.Rows[row.RowIndex].Cells[0].Text);
//如果checkbox选中了就把ID保存起来
if (chkbx.Checked)
{
//拼接字符串 构造in的参数
idlist += id.ToString() + ",";
}
}
if (idlist.Length > 0)
{
//提取最后一个逗号之前的 字符串. 应该也可以这样写 idlist=idlist.TrimEnd(new char[]{'});
idlist = idlist.Substring(0, idlist.Length - 1);
string sql = "delete from member where m_id in (" + idlist + ")";
try
{
//这个执行删除的方法.不过最好用个事务
int i = CommonLib.SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, null);
if (i > 0)
{
Bind();
CommonLib.JavaScriptHelper.Alert("批量删除成功", this.Page);
}
else
CommonLib.JavaScriptHelper.Alert("服务器忙 删除失败", this.Page);
}
catch
{
CommonLib.JavaScriptHelper.Alert("服务器忙 删除失败", this.Page);
}
this.quanxuan.Value = " 全选 ";
}
else
{
CommonLib.JavaScriptHelper.Alert("选择需要删除的数据", this.Page);
}
}
#endregion
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询