您的位置:首页 > 其它

关于三层的一些内容

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: