学生管理系统web程序设计代码.docx
- 文档编号:24562759
- 上传时间:2023-05-28
- 格式:DOCX
- 页数:30
- 大小:131.48KB
学生管理系统web程序设计代码.docx
《学生管理系统web程序设计代码.docx》由会员分享,可在线阅读,更多相关《学生管理系统web程序设计代码.docx(30页珍藏版)》请在冰豆网上搜索。
学生管理系统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)
{
name);
stringsql=string.Format("select*fromCustomerswhereLoginName='{0}'"returnGetCustomerBySQL(sql);
}
III根据用户ID查询用户信息
publicstaticCustomerGetCustomerById(intid)
{
id);
stringsql=string.Format("select*fromCustomerswhereCustomerId={0}"returnGetCustomerBySQL(sql);
}
III私有方法,提供公共方法查询用户信息使用privatestaticCustomerGetCustomerBySQL(stringsql)
{
using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)){
Customerc=null;
try
{
conn.Open();
SqlCommandcmd=newSqlCommand(sql,conn);SqlDataReadersdr=cmd.ExecuteReader();
c=c.Id=(
c.LoginName
=sdr[
c.Password=
sdr[
}
{
if(sdr.Read())
newCustomer();
int)sdr["CustomerId"];
"LoginName"].ToString();
"Password"].ToString();
catch(Exceptionex)
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
return
}
}
}
}
{
(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
{
///获取所有发布的房屋信息publicstaticIList
{
List
using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)){
try
{
conn.Open();
SqlCommandcmd=newSqlCommand("select*fromHouses",conn);
SqlDataReadersdr=cmd.ExecuteReader();
while(sdr.Read())
newHouse();
int)sdr["HouseId"];
"HouseTypeName"].ToString();
int)sdr["Area"];
h.Price=h.Address=sdr[
Convert.ToDouble(sdr["Price"]);
"Address"].ToString();//外键对象的处理
"CustomerId"]);
h.Customer=CustomerService.GetCustomerById((int)sdr[
houses.Add(h);
}
}
catch(Exceptionex)
{
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
}
returnhouses;
}
///根据房屋信息主键ID删除发布的房屋信息
///
publicstaticintDeleteHouseById(inthouserId)
{
intcount=0;
using(SqlConnectionconn=newSqlConnection(DBHelper.connectString))
{
try
{
houserId);
stringsql=string.Format("deletefromHouseswhereHouseId={0}"conn.Open();
SqlCommandcmd=newSqlCommand(sql,conn);count=cmd.ExecuteNonQuery();
}
catch(Exceptionex)
{
Console.WriteLine(ex.Message);
finally
conn.Close();
}
}
returncount;
}
///增加发布的房屋信息
///
{
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
{
///查询所有发布的房屋信息
publicstaticIList
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;
}
}
}
禾口LoginPage.aspx禾口
四、在表示层中建立一个空网站:
其中包括四个网页窗体:
about.aspx和default.aspx
ReleaseHouseInformationPage.aspx
(1)在LoginPage.aspx中
1登录窗口
登录名
密码
B[
誓1
代码如下:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.Ul.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」sPostBack)
{
//已登录直接跳转到查看页面
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
{
//提示错误信息
"Warnning"
this.ClientScript.RegisterStartupScript(this.GetType(),
"");
}
}
}
(2)在ReleaseHouseInformationPage.aspx中:
房型
面积
丄皇_厅耳1
r平方杷li1
价格
F元厂
地址
U
E嘴错误消息工
-卅息2-1J
代码如下:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.Ul.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=house.TypeName=
newHouse();
this.ddlType.SelectedValue;
house.Area=int.Parse(this.txtArea.Text);
house.Price=double.Parse(this.txtPrice.Text);
}
(3)在default.aspx中:
房屋类型面积价格地址
数据娜定数据绑定数据绑审数据绑定删除
数据绑定数据绑定数据绑定数据绑定删陈
数据绑定数据绑定数据绑定数据绑定删除
数据编定数据绑定数据绑定数据绑定删除数据绑定建据绑定数据塑数据绑定删除6bjcCtDat&So'tarce-odsHousft5
具体就是:
设置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*fromadminwhereUserld='{0}'",name);returnGetAdminBySQL(sql);
}
privatestaticAdminGetAdminBySQL(stringsql)
{
using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)){
Adminc=nuII;
try
{
conn.Open();
SqlCommandcmd=newSqlCommand(sql,conn);
SqlDataReadersdr=cmd.ExecuteReader();
if(sdr.Read())
{
c=newAdmin();
c.Userld=sdr["Userld"].ToString().Trim();
c.UserPwd=sdr["UserPwd"].ToString().Trim();
}
catch(Exceptionex)
{
Console.WriteLine(ex.Message);
}
finally
{conn.Close();
}
returnc;
}
}
}
}
(2)在DBHelper中
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceStudentDAL
{
publicstaticclassDBHelper
{
publicstaticreadonlystringconnectString="Data
Source=PC-201012101127\\SQLEXPRESS;InitialCatalog=StudDB;IntegratedSecurity=True";}
}
(3)在studentDAL.cs中
usingSystem;
usingSystem.Collections.Generic;
usingSy
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 管理 系统 web 程序设计 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)