跪求C#大神注释一段代码!!!
publicpartialclassmember_pro_add:System.Web.UI.Page{#region初?始º?化¡¥pro...
publicpartialclassmember_pro_add : System.Web.UI.Page
{
#region 初?始º?化¡¥
protectedstring con = CommonLib.SqlHelper.SqlConnectionString;
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["buy"] == null)
{
Response.Redirect("login.aspx");
return;
}
if (Request["id"] != null)
{
try
{int id = Convert.ToInt32(Request.QueryString["id"]);
Bind();
}
catch
{
CommonLib.JavaScriptHelper.AlertAndRedirect("数据不存在或已删除", "member_pro_list.aspx");
}}}}
#endregion
#region绑定
privatevoid Bind()
#region会员编号
string mname = HttpUtility.UrlDecode(Request.Cookies["buy"]["user"]);
string con = CommonLib.SqlHelper.SqlConnectionString;
string sql = "select m_id from member where m_name='" + mname + "'";
string mid = CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql, null).ToString();
#endregion
sql = "select * from product where pro_id=" + Request.QueryString["id"]
+ " and m_id=" + mid;
SqlDataReader dr = CommonLib.SqlHelper.ExecuteReader(con, CommandType.Text, sql, null);
if (dr.Read())
{
title.Text = dr["pro_title"].ToString();
name.Text = dr["pro_name"].ToString();
hidclsid.Value = dr["pro_cls_id"].ToString();
edit.Value = dr["pro_img"].ToString();
pri.Text = dr["pro_pri"].ToString();
num.Text = dr["pro_num"].ToString();
tel.Text = dr["pro_tel"].ToString();
qq.Text = dr["pro_qq"].ToString();
add.Text = dr["pro_add"].ToString();
intro.Text = dr["pro_intro"].ToString();
dr.Close(); dr.Dispose();
}else{ 展开
{
#region 初?始º?化¡¥
protectedstring con = CommonLib.SqlHelper.SqlConnectionString;
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["buy"] == null)
{
Response.Redirect("login.aspx");
return;
}
if (Request["id"] != null)
{
try
{int id = Convert.ToInt32(Request.QueryString["id"]);
Bind();
}
catch
{
CommonLib.JavaScriptHelper.AlertAndRedirect("数据不存在或已删除", "member_pro_list.aspx");
}}}}
#endregion
#region绑定
privatevoid Bind()
#region会员编号
string mname = HttpUtility.UrlDecode(Request.Cookies["buy"]["user"]);
string con = CommonLib.SqlHelper.SqlConnectionString;
string sql = "select m_id from member where m_name='" + mname + "'";
string mid = CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql, null).ToString();
#endregion
sql = "select * from product where pro_id=" + Request.QueryString["id"]
+ " and m_id=" + mid;
SqlDataReader dr = CommonLib.SqlHelper.ExecuteReader(con, CommandType.Text, sql, null);
if (dr.Read())
{
title.Text = dr["pro_title"].ToString();
name.Text = dr["pro_name"].ToString();
hidclsid.Value = dr["pro_cls_id"].ToString();
edit.Value = dr["pro_img"].ToString();
pri.Text = dr["pro_pri"].ToString();
num.Text = dr["pro_num"].ToString();
tel.Text = dr["pro_tel"].ToString();
qq.Text = dr["pro_qq"].ToString();
add.Text = dr["pro_add"].ToString();
intro.Text = dr["pro_intro"].ToString();
dr.Close(); dr.Dispose();
}else{ 展开
2个回答
展开全部
publicpartialclassmember_pro_add : System.Web.UI.Page
{
#region 初?始º?化¡¥
protected string con = CommonLib.SqlHelper.SqlConnectionString; //定义数据库连接字符串变量,赋值
protect edvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //判断是否是页面回传,本处是为了if内语句只在本页面重新打开时执行,而页面回传提交时不执行
{
if (Request.Cookies["buy"] == null) //判断cookies是否有值,从而判断会员是否登录
{
Response.Redirect("login.aspx");//cookies为空,则未登录,跳转到登录页
return; //方法返回,让后面的语句不执行
}
//以下语句则是在会员已经登录的前提下执行的
if (Request["id"] != null) //判断页面post或者get方式传递过来的参数id是否有值
{
try //try语句用于预防程序
{int id = Convert.ToInt32(Request.QueryString["id"]);//从get方式传递过来的参数id取值,也就是url中的id参数的值
Bind();//执行方法
}
catch
{
CommonLib.JavaScriptHelper.AlertAndRedirect("数据不存在或已删除", "member_pro_list.aspx"); //这里是在try中语句执行出错是执行的.本语句是弹出提示问题并跳转页面
}}}}
#endregion
#region绑定
privatevoid Bind()
#region会员编号
string mname = HttpUtility.UrlDecode(Request.Cookies["buy"]["user"]); //从cookies中取值并赋值,这里做了url转码
string con = CommonLib.SqlHelper.SqlConnectionString; //定义数据库连接字符串变量,赋值
string sql = "select m_id from member where m_name='" + mname + "'"; //定义sql语句
string mid = CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql, null).ToString(); //执行sql语句,并返回值赋值给mid ,ExecuteScalar方法是返回查询结果的第一条记录的第一列的值。
#endregion
sql = "select * from product where pro_id=" + Request.QueryString["id"]
+ " and m_id=" + mid;//给sql赋值一条新的sql语句
SqlDataReader dr = CommonLib.SqlHelper.ExecuteReader(con, CommandType.Text, sql, null); //执行sql语句并返回查询记录集,赋值给SqlDataReader 类型变量dr
if (dr.Read()) //判断dr记录集中是否有记录存在
{
//有的话执行以下语句,一下语句均是将记录集中的值赋值到页面控件中,从而显示在页面上
title.Text = dr["pro_title"].ToString();
name.Text = dr["pro_name"].ToString();
hidclsid.Value = dr["pro_cls_id"].ToString();
edit.Value = dr["pro_img"].ToString();
pri.Text = dr["pro_pri"].ToString();
num.Text = dr["pro_num"].ToString();
tel.Text = dr["pro_tel"].ToString();
qq.Text = dr["pro_qq"].ToString();
add.Text = dr["pro_add"].ToString();
intro.Text = dr["pro_intro"].ToString();
dr.Close(); //关闭记录集对象
dr.Dispose(); //注销dr对象
}else{
{
#region 初?始º?化¡¥
protected string con = CommonLib.SqlHelper.SqlConnectionString; //定义数据库连接字符串变量,赋值
protect edvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //判断是否是页面回传,本处是为了if内语句只在本页面重新打开时执行,而页面回传提交时不执行
{
if (Request.Cookies["buy"] == null) //判断cookies是否有值,从而判断会员是否登录
{
Response.Redirect("login.aspx");//cookies为空,则未登录,跳转到登录页
return; //方法返回,让后面的语句不执行
}
//以下语句则是在会员已经登录的前提下执行的
if (Request["id"] != null) //判断页面post或者get方式传递过来的参数id是否有值
{
try //try语句用于预防程序
{int id = Convert.ToInt32(Request.QueryString["id"]);//从get方式传递过来的参数id取值,也就是url中的id参数的值
Bind();//执行方法
}
catch
{
CommonLib.JavaScriptHelper.AlertAndRedirect("数据不存在或已删除", "member_pro_list.aspx"); //这里是在try中语句执行出错是执行的.本语句是弹出提示问题并跳转页面
}}}}
#endregion
#region绑定
privatevoid Bind()
#region会员编号
string mname = HttpUtility.UrlDecode(Request.Cookies["buy"]["user"]); //从cookies中取值并赋值,这里做了url转码
string con = CommonLib.SqlHelper.SqlConnectionString; //定义数据库连接字符串变量,赋值
string sql = "select m_id from member where m_name='" + mname + "'"; //定义sql语句
string mid = CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql, null).ToString(); //执行sql语句,并返回值赋值给mid ,ExecuteScalar方法是返回查询结果的第一条记录的第一列的值。
#endregion
sql = "select * from product where pro_id=" + Request.QueryString["id"]
+ " and m_id=" + mid;//给sql赋值一条新的sql语句
SqlDataReader dr = CommonLib.SqlHelper.ExecuteReader(con, CommandType.Text, sql, null); //执行sql语句并返回查询记录集,赋值给SqlDataReader 类型变量dr
if (dr.Read()) //判断dr记录集中是否有记录存在
{
//有的话执行以下语句,一下语句均是将记录集中的值赋值到页面控件中,从而显示在页面上
title.Text = dr["pro_title"].ToString();
name.Text = dr["pro_name"].ToString();
hidclsid.Value = dr["pro_cls_id"].ToString();
edit.Value = dr["pro_img"].ToString();
pri.Text = dr["pro_pri"].ToString();
num.Text = dr["pro_num"].ToString();
tel.Text = dr["pro_tel"].ToString();
qq.Text = dr["pro_qq"].ToString();
add.Text = dr["pro_add"].ToString();
intro.Text = dr["pro_intro"].ToString();
dr.Close(); //关闭记录集对象
dr.Dispose(); //注销dr对象
}else{
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询