web程序设计代码 学生管理系统.docx

上传人:b****7 文档编号:23776024 上传时间:2023-05-20 格式:DOCX 页数:33 大小:50.39KB
下载 相关 举报
web程序设计代码 学生管理系统.docx_第1页
第1页 / 共33页
web程序设计代码 学生管理系统.docx_第2页
第2页 / 共33页
web程序设计代码 学生管理系统.docx_第3页
第3页 / 共33页
web程序设计代码 学生管理系统.docx_第4页
第4页 / 共33页
web程序设计代码 学生管理系统.docx_第5页
第5页 / 共33页
点击查看更多>>
下载资源
资源描述

web程序设计代码 学生管理系统.docx

《web程序设计代码 学生管理系统.docx》由会员分享,可在线阅读,更多相关《web程序设计代码 学生管理系统.docx(33页珍藏版)》请在冰豆网上搜索。

web程序设计代码 学生管理系统.docx

web程序设计代码学生管理系统

房屋销售管理系统

一、HouseManagerDAL数据访问层中设计三个类:

CustomerService.cs和DBhelper.cs和houseserver.cs

(1)在CustomerService.cs中

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingSystem.Data;

usingSystem.Data.SqlClient;

usingHouseManager.Models;

namespaceHouseManager.DAL

{publicstaticclassCustomerService

{///根据提供的登录账号查询用户信息

publicstaticCustomerGetCustomerByLoginName(stringname)

{

stringsql=string.Format("select*fromCustomerswhereLoginName='{0}'",name);

returnGetCustomerBySQL(sql);

}

///根据用户ID查询用户信息

publicstaticCustomerGetCustomerById(intid)

{

stringsql=string.Format("select*fromCustomerswhereCustomerId={0}",id);

returnGetCustomerBySQL(sql);

}

///私有方法,提供公共方法查询用户信息使用

privatestaticCustomerGetCustomerBySQL(stringsql)

{

using(SqlConnectionconn=newSqlConnection(DBHelper.connectString))

{

Customerc=null;

try

{

conn.Open();

SqlCommandcmd=newSqlCommand(sql,conn);

SqlDataReadersdr=cmd.ExecuteReader();

if(sdr.Read())

{

c=newCustomer();

c.Id=(int)sdr["CustomerId"];

c.LoginName=sdr["LoginName"].ToString();

c.Password=sdr["Password"].ToString();

}

}

catch(Exceptionex)

{

Console.WriteLine(ex.Message);

}

finally

{

conn.Close();

}

returnc;

}

}

}

}

(2)在DBHelper中

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

namespaceHouseManager.DAL

{

publicstaticclassDBHelper

{

publicstaticreadonlystringconnectString="server=.;database=HouseDB;uid=sa;pwd=123456";

}

}

(3)在HouseService中

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingSystem.Data;

usingSystem.Data.SqlClient;

usingHouseManager.Models;

namespaceHouseManager.DAL

{

publicstaticclassHouseService

{

///获取所有发布的房屋信息

publicstaticIListGetAllHouse()

{

Listhouses=newList();

using(SqlConnectionconn=newSqlConnection(DBHelper.connectString))

{

try

{

conn.Open();

SqlCommandcmd=newSqlCommand("select*fromHouses",conn);

SqlDataReadersdr=cmd.ExecuteReader();

while(sdr.Read())

{

Househ=newHouse();

h.Id=(int)sdr["HouseId"];

h.TypeName=sdr["HouseTypeName"].ToString();

h.Area=(int)sdr["Area"];

h.Price=Convert.ToDouble(sdr["Price"]);

h.Address=sdr["Address"].ToString();//外键对象的处理

h.Customer=CustomerService.GetCustomerById((int)sdr["CustomerId"]);

houses.Add(h);

}

}

catch(Exceptionex)

{

Console.WriteLine(ex.Message);

}

finally

{

conn.Close();

}

}

returnhouses;

}

///根据房屋信息主键ID删除发布的房屋信息

///受影响的行数

publicstaticintDeleteHouseById(inthouserId)

{

intcount=0;

using(SqlConnectionconn=newSqlConnection(DBHelper.connectString))

{

try

{

stringsql=string.Format("deletefromHouseswhereHouseId={0}",houserId);

conn.Open();

SqlCommandcmd=newSqlCommand(sql,conn);

count=cmd.ExecuteNonQuery();

}

catch(Exceptionex)

{

Console.WriteLine(ex.Message);

}

finally

{

conn.Close();

}

}

returncount;

}

///增加发布的房屋信息

///受影响的行数

publicstaticintAddHouse(Househouse)

{

stringsql=string.Format("insertintodbo.Houses"+"(HouseTypeName,Area,Price,Address,CustomerId)"

+"values('{0}',{1},{2},'{3}',{4})",

house.TypeName,house.Area,

house.Price,house.Address,

house.Customer.Id);

intcount=0;

using(SqlConnectionconn=newSqlConnection(DBHelper.connectString))

{

try

{

conn.Open();

SqlCommandcmd=newSqlCommand(sql,conn);

count=cmd.ExecuteNonQuery();

}

catch(Exceptionex)

{

Console.WriteLine(ex.Message);

return0;

}

finally

{

conn.Close();

}

}

return1;

}

}

}

二、在HouseManagerModels模型层中设计两个类:

Customer.cs和house.cs

(1)在Customer.cs中

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

namespace

{

[Serializable]

publicclassCustomer

{

privateintid;

publicintId

{

get{returnid;}

set{id=value;}

}

privatestringloginName;

///登录账号

publicstringLoginName

{

get{returnloginName;}

set{loginName=value;}

}

privatestringpassword;

///登录密码

publicstringPassword

{

get{returnpassword;}

set{password=value;}

}

}

}

(2)在house.cs中

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

namespaceHouseManager.Models

{

[Serializable]

publicclassHouse

{

privateintid;

publicintId

{

get{returnid;}

set{id=value;}

}

privatestringtypeName;

///房屋类型名称

publicstringTypeName

{

get{returntypeName;}

set{typeName=value;}

}

privateintarea;

///面积

publicintArea

{

get{returnarea;}

set{area=value;}

}

privatedoubleprice;

///价格

publicdoublePrice

{

get{returnprice;}

set{price=value;}

}

privatestringaddress;

///地址

publicstringAddress

{

get{returnaddress;}

set{address=value;}

}

privateCustomercustomer;

///发布人

publicCustomerCustomer

{

get{returncustomer;}

set{customer=value;}

}

}

}

三、在HouseManagerBLL逻辑业务层中设计两个类:

HouseManager.cs和LoginManager.cs

(1)在HouseManager.cs中:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingHouseManager.Models;

usingHouseManager.DAL;

namespaceHouseManager.BLL

{

publicstaticclassHouseManager

{

///查询所有发布的房屋信息

publicstaticIListGetAllHouse()

{

returnHouseService.GetAllHouse();

}

///删除已发布的房屋信息

///删除是否成功

publicstaticboolDeleteHouse(inthouseId)

{

returnHouseService.DeleteHouseById(houseId)!

=0;

}

///发布房屋信息

///添加是否成功

publicstaticboolAddHouse(Househouse)

{

returnHouseService.AddHouse(house)!

=0;

}

}

}

(2)在LoginManager.cs中

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingHouseManager.Models;

usingHouseManager.DAL;

namespaceHouseManager.BLL

{

publicstaticclassLoginManager

{

///用户登录判断

///是否登录成功

publicstaticboolLogin(stringname,stringpassword,outCustomercustomer)

{

customer=null;

Customerc=CustomerService.GetCustomerByLoginName(name);

if(c==null)

{

returnfalse;

}

if(c.Password.Equals(password))

{

customer=c;

returntrue;

}

returnfalse;

}

}

}

四、在表示层中建立一个空网站:

其中包括四个网页窗体:

about.aspx和default.aspx和LoginPage.aspx和ReleaseHouseInformationPage.aspx

(1)在LoginPage.aspx中

代码如下:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Collections;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

usingHouseManager.Models;

usingHouseManager.BLL;

publicpartialclassLoginPage:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

if(!

this.IsPostBack)

{

//已登录直接跳转到查看页面

if(Session["User"]!

=null)

{

this.Response.Redirect("~/default.aspx");

}

}

}

protectedvoidbtnLogin_Click(objectsender,EventArgse)

{

Customercus=null;

//验证登录信息是否正确

if(LoginManager.Login(this.txtLoginName.Text.Trim(),

this.txtPassword.Text.Trim(),

outcus))

{

//跳转到查看页面

Session["User"]=cus;

this.Response.Redirect("~/default.aspx");

}

else

{

//提示错误信息

this.ClientScript.RegisterStartupScript(this.GetType(),"Warnning",

"");

}

}

}

(2)在ReleaseHouseInformationPage.aspx中:

代码如下:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Collections;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

usingHouseManager.Models;

usingHouseManager.BLL;

publicpartialclassReleaseHouseInformationPage:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

if(!

this.IsPostBack)

{

//没有登录的话,跳转到登录页面

if(Session["User"]==null)

{

this.Response.Redirect("~/LoginPage.aspx");

}

}

}

protectedvoidbtnSubmit_Click(objectsender,EventArgse)

{

//从界面获取用户输入的信息

Househouse=newHouse();

house.TypeName=this.ddlType.SelectedValue;

house.Area=int.Parse(this.txtArea.Text);

house.Price=double.Parse(this.txtPrice.Text);

house.Address=this.txtAddress.Text;

Customercustomer=Session["User"]asCustomer;

house.Customer=customer;

//判断保存信息是否成功

if(HouseManager.BLL.HouseManager.AddHouse(house))

{

//提示成功信息并跳转到查看页面

this.ClientScript.RegisterStartupScript(this.GetType(),"Alert",

"");

}

else

{

//提示错误信息

this.ClientScript.RegisterStartupScript(this.GetType(),"Alert",

"");

}

}

}

(3)在default.aspx中:

具体就是:

设置GridView,设置数据源等操作。

(4)在about.aspx中:

自动带的。

 

学生管理系统

一、StudentDAL数据访问层中设计三个类:

AdminDAL.cs和DBHelper.cs和studentDAL.cs

(1)在AdminDAL.cs中

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingStudentModel;

usingSystem.Data;

usingSystem.Data.SqlClient;

namespaceStudentDAL

{

publicclassAdminDAL

{

publicstaticAdminGetAdminByLoginName(stringname)

{

stringsql=string.Format("select*fromadminwhereUserId='{0}'",name);

returnGetAdminBySQL(sql);

}

privatestaticAdminGetAdminBySQL(stringsql)

{

using(SqlConnectionconn=newSqlConnection(DBHelper.connectString))

{

Adminc=null;

try

{

conn.Open();

SqlCommandcmd=newSqlCommand(sql,conn);

SqlDataReadersdr=cmd.ExecuteReader();

if(sdr.Read())

{

c=newAdmin();

c.UserId=sdr["UserId"].ToString().Trim();

c.UserPwd=sdr["UserPwd"].ToString().Trim();

}

}

catch(Exceptionex)

{

Console.WriteLine(ex.Me

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 商业计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1