本帖最后由 wang346351 于 2013-4-16 11:12 编辑
试着自己开始写一个项目,写登录这个界面,之前写登录是在控制台应用程序中和单独的一个Web页面中写,三层的登录之间应该是通过参数的方式传值的把,我写了一个,想问下还有没有其他的方式方法?是不是可以通过Model实体层方式传值,怎么写?
我写的这个不能使用Session把账号存起来让另一个页面使用,所以想请教其他的方法。
代码如下:
DAL层
public class CompanyService
{
/// <summary>
/// 管理员登录
/// </summary>
/// <param name="AgentCode"></param>
/// <param name="AgentPWD"></param>
/// <param name="Result"></param>
/// <returns></returns>
public void AdminLogin(string AdminCode, string AdminPWD, out bool Result)
{
bool result;
string sql = "select * from Company where Name=@Name and Password=@Password";
using (SqlConnection conn = new SqlConnection(@"Data Source=wang-pc;Initial Catalog=PhoneRechargeSys;User ID=sa Password=123 "))
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add(new SqlParameter("@Name", AdminCode));
cmd.Parameters.Add(new SqlParameter("@Password", AdminPWD));
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
result = true;
}
else
{
result = false;
}
Result = result;
//return Result;
}
}
}
BLL层
public class CompanyManager
{
/// <summary>
/// 管理员登录
/// </summary>
/// <param name="AgentCode"></param>
/// <param name="AgentPWD"></param>
/// <param name="Result"></param>
/// <returns></returns>
public bool AdminLogin(string AdminCode, string AdminPWD, out bool Result)
{
RechargeSys.DAL.CompanyService DALAdminService = new DAL.CompanyService();
DALAdminService.AdminLogin(AdminCode, AdminPWD, out Result);
return Result;
}
}
Model层
public class Company
{
#region 属性
/// <summary>
/// 公司ID
/// </summary>
public int ID { get; set; }
/// <summary>
/// 公司名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 帐号余额
/// </summary>
public double Money { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 添加日期
/// </summary>
public DateTime RegDate { get; set; }
/// <summary>
/// 帐号
/// </summary>
public string Account { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 接口帐号
/// </summary>
public string AppAccount { get; set; }
/// <summary>
/// 接口KEY
/// </summary>
public string AppKey { get; set; }
/// <summary>
/// 接口ID
/// </summary>
public string AppPartner { get; set; }
/// <summary>
/// 公司自留利润,以元为单位
/// </summary>
public double CompanyProfi { get; set; }
#endregion
}
Web界面
/// <summary>
/// 管理员登录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnLogin_Click(object sender, EventArgs e)
{
bool Result;
bool isSuccess;
string AdminCode = this.txtAdminCode.Text.Trim();
string AdminPwd = this.txtPWD.Text.Trim();
RechargeSys.BLL.CompanyManager AdminManager = new CompanyManager();
isSuccess = AdminManager.AdminLogin(AdminCode, AdminPwd, out Result);
if (isSuccess==true)
{
//Response.Redirect("AdminIndex.aspx");
this.lbMsg.Text = "登录成功!";
}
else
{
this.lbMsg.Text = "帐号/密码错误!";
}
}
|