关于三层的一些内容
2011-10-09 09:09
323 查看
Model 层
ModelUser.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Model
{
public class ModelUser
{
public class UserDetails
{
public int id;
public string departname;
public string departcode;
public string parentdepartcode;
public string username;
public string userpwd;
public string dtype;
public string showorder;
public string iflock;
}
}
}
BLL 层
BLLUser.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using DAL;
using Model;
namespace BLL
{
public class BLLUser
{
Db newdb = new Db();
public string ReturnLoginUserID()
{
string sUID = "0";
object oo = HttpContext.Current.Request.Cookies["JobUserCookies"];
if (oo != null)
{
sUID = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["JobUserCookies"].Values["UserID"].ToString());
object pp = HttpContext.Current.Session["UserID"];
if (pp == null)
{
HttpContext.Current.Session["UserID"] = sUID;
}
}
else
{
object pp = System.Web.HttpContext.Current.Session["UserID"];
if (pp != null)
{
sUID = pp.ToString();
System.Web.HttpCookie myHttpCookie = new System.Web.HttpCookie("JobUserCookies");
myHttpCookie.Values.Add("UserID", HttpUtility.UrlEncode(sUID));
System.Web.HttpContext.Current.Response.AppendCookie(myHttpCookie);
}
}
return sUID;
}
public ModelUser.UserDetails GetUserDetails()
{
string UserID = ReturnLoginUserID();
ModelUser.UserDetails UserDetails = new ModelUser.UserDetails();
string sql = "select id,departname,departcode,parentdepartcode,username,userpwd,dtype,showorder,iflock from depart where id = '" + UserID + "'";
SqlDataReader dr = newdb.CommonExecuteReader(sql);
dr.Read();
if (dr.HasRows)
{
UserDetails.id = int.Parse(dr[0].ToString());
UserDetails.departname = dr[1].ToString();
UserDetails.departcode = dr[2].ToString();
UserDetails.iflock = dr[3].ToString();
UserDetails.username = dr[4].ToString();
UserDetails.userpwd = dr[5].ToString();
UserDetails.dtype = dr[6].ToString();
UserDetails.showorder = dr[7].ToString();
UserDetails.iflock = dr[8].ToString();
}
dr.Close();
return UserDetails;
}
}
}
WebUI 层中 Read.aspx.CS 中读取
using BLL;
this.Label1.Text = new BLLUser().GetUserDetails().departname;
ModelUser.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Model
{
public class ModelUser
{
public class UserDetails
{
public int id;
public string departname;
public string departcode;
public string parentdepartcode;
public string username;
public string userpwd;
public string dtype;
public string showorder;
public string iflock;
}
}
}
BLL 层
BLLUser.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using DAL;
using Model;
namespace BLL
{
public class BLLUser
{
Db newdb = new Db();
public string ReturnLoginUserID()
{
string sUID = "0";
object oo = HttpContext.Current.Request.Cookies["JobUserCookies"];
if (oo != null)
{
sUID = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["JobUserCookies"].Values["UserID"].ToString());
object pp = HttpContext.Current.Session["UserID"];
if (pp == null)
{
HttpContext.Current.Session["UserID"] = sUID;
}
}
else
{
object pp = System.Web.HttpContext.Current.Session["UserID"];
if (pp != null)
{
sUID = pp.ToString();
System.Web.HttpCookie myHttpCookie = new System.Web.HttpCookie("JobUserCookies");
myHttpCookie.Values.Add("UserID", HttpUtility.UrlEncode(sUID));
System.Web.HttpContext.Current.Response.AppendCookie(myHttpCookie);
}
}
return sUID;
}
public ModelUser.UserDetails GetUserDetails()
{
string UserID = ReturnLoginUserID();
ModelUser.UserDetails UserDetails = new ModelUser.UserDetails();
string sql = "select id,departname,departcode,parentdepartcode,username,userpwd,dtype,showorder,iflock from depart where id = '" + UserID + "'";
SqlDataReader dr = newdb.CommonExecuteReader(sql);
dr.Read();
if (dr.HasRows)
{
UserDetails.id = int.Parse(dr[0].ToString());
UserDetails.departname = dr[1].ToString();
UserDetails.departcode = dr[2].ToString();
UserDetails.iflock = dr[3].ToString();
UserDetails.username = dr[4].ToString();
UserDetails.userpwd = dr[5].ToString();
UserDetails.dtype = dr[6].ToString();
UserDetails.showorder = dr[7].ToString();
UserDetails.iflock = dr[8].ToString();
}
dr.Close();
return UserDetails;
}
}
}
WebUI 层中 Read.aspx.CS 中读取
using BLL;
this.Label1.Text = new BLLUser().GetUserDetails().departname;
相关文章推荐
- C++中关于文本内容的实用操作集合(新)(添加一些关于文件流的介绍)
- 关于MyBatis一些小错误,元素内容必须由格式正确的字符数据或标记组成.
- 关于Eclipse3.3中内容助手不是Alt+/的问题解答,以及它的一些其他新特性
- 现阶段现阶段关于产品经理、项目经理、需求分析师的工作内容和职责、行业标准化规范、产品生命周期和项目生命周期的一些认知
- 关于推荐的一个算法工程师访谈,有一些内容值得看看
- html复习笔记---------关于内容的一些小基础
- 关于token的一些内容
- 关于之前自己总结的一些内容
- 关于MyBatis一些小错误,元素内容必须由格式正确的字符数据或标记组成.
- 关于CMS(内容管理系统)系统的一些构思
- 关于函数指针的一些理解与其他相关内容的联想
- 关于CSS的一些基础内容
- 黑马韩前成java基础之关于学习java的一些建议、内容
- 关于从网上复制一些网页内容的时候,会提示需要注册才能复制的解决方法
- 摘录的一些Bjarne Stroustrup关于C++的谈话内容
- 关于javascript的一些内容
- 关于oracle rowid的一些内容
- 关于PHP采集网站内容的一些思路--遇到的问题
- 关于linux USB WIFI 的一些内容
- Vue------第五天(关于组件的一些基础了解,包括组件的注册、Prop、自定义事件、使用插槽分发内容等)