学生管理系统web程序设计代码_第1页
学生管理系统web程序设计代码_第2页
学生管理系统web程序设计代码_第3页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、房屋销售管理系统一、HouseManagerDAL数据访问层中设计三个类:CustomerService.cs和DBhelper.cs和houseserver.cs(1)在CustomerService.cs中usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingHouseManager.Models;namespaceHouseManager.DALpublic/staticclassCustomerService根据提供的登录

2、账号查询用户信息publicstaticCustomerGetCustomerByLoginName(stringname)stringsql=string.Format("select*fromCustomerswhereLoginName='0'"returnGetCustomerBySQL(sql);/根据用户ID查询用户信息publicstaticCustomerGetCustomerById(intid)stringsql=string.Format("select*fromCustomerswhereCustomerId=0"

3、returnGetCustomerBySQL(sql);/私有方法,提供公共方法查询用户信息使用privatestaticCustomerGetCustomerBySQL(stringsql)using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)Customerc=null;,name);,id);tryconn.Open();SqlCommandcmd=newSqlCommand(sql,conn);SqlDataReadersdr=cmd.ExecuteReader();if(sdr.Read()c=c.Id=(c.

4、LoginName=sdrc.Password=sdrnewCustomer();int)sdr"CustomerId""LoginName".ToString();"Password".ToString();catch(Exceptionex)Console.WriteLine(ex.Message);finally(conn.Close();returnc;在DBHelper中usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceHouseMan

5、ager.DAL(publicstaticclassDBHelper(publicstaticreadonlystringconnectString="server=.;database=HouseDB;uid=sa;pwd=123456”;在HouseService中usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingHouseManager.Models;namespaceHouseManager.DAL(publ

6、icstaticclassHouseService(/获取所有发布的房屋信息publicstaticIList<House>GetAllHouse()(List<House>houses=newList<House>();using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)(try(conn.Open();SqlCommandcmd=newSqlComman(d"select*fromHouses",conn);SqlDataReadersdr=cmd.Execu

7、teReader();Househ=h.Id=(h.TypeName=sdrh.Area=(while(sdr.Read()newHouse();int)sdr"HouseId""HouseTypeName'.ToString();int)sdr"Area"h.Price=Convert.ToDouble(sdr"Price");h.Address=sdr"Address".ToString();外键对象的处理h.Customer=CustomerService.GetCustomerById(i

8、nt)sdr"CustomerId");houses.Add(h);catch(Exceptionex)Console.WriteLine(ex.Message);finallyconn.Close();returnhouses;/根据房屋信息主键ID删除发布的房屋信息/<returns>受影响的行数/returnspublicstaticintDeleteHouseById(inthouserId)intcount=0;using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)trystri

9、ngsql=string.Format("deletefromHouseswhereHouseId=0",houserld);conn.Open();SqlCommandcmd=newSqlCommandsql,conn);count=cmd.ExecuteNonQuery();catch(Exceptionex)Console.WriteLine(ex.Message);finallyconn.Close();returncount;/增加发布的房屋信息/<returns>受影响的行数</returns>publicstaticintAddHous

10、e(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

11、.connectString)tryconn.Open();SqlCommandcmd=newSqlCommand(sql,conn);count=cmd.ExecuteNonQuery();catch(Exceptionex)Console.WriteLine(ex.Message);return0;finallyconn.Close();return1;二、在HouseManagerModels模型层中设计两个类:Customer.cs和house.cs(1)在Customer.cs中usingSystem;usingSystem.Collections.Generic;usingSyst

12、em.Text;namespace(SerializablepublicclassCustomer(privateintid;publicintId(get(returnid;set(id=value;privatestringloginName;/登录账号publicstringLoginName(get(returnloginName;set(loginName=value;privatestringpassword;/登录密码publicstringPassword(get(returnpassword;set(password=value;(2)在house.cs中usingSyste

13、m;usingSystem.Collections.Generic;usingSystem.Text;namespaceHouseManager.Models(SerializablepublicclassHouse(privateintid;publicintId(get(returnid;set(id=value;privatestringtypeName;/房屋类型名称publicstringTypeName(get(returntypeName;set(typeName=value;privateintarea;/面积publicintArea(get(returnarea;set(a

14、rea=value;privatedoubleprice;/价格publicdoublePrice(get(returnprice;set(price=value;privatestringaddress;/地址publicstringAddress(get(returnaddress;set(address=value;privateCustomercustomer;/发布人publicCustomerCustomer(get(returncustomer;set(customer=value;(1) 三、在HouseManagerBL逻辑业务层中设计两个类:HouseManager.cs和

15、LoginManager.cs在HouseManager.cs中:usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingHouseManager.Models;usingHouseManager.DAL;namespaceHouseManager.BLL(publicstaticclassHouseManager(/查询所有发布的房屋信息publicstaticIList<House>GetAllHouse()(returnHouseService.GetAllHouse();/删除已发布的房屋信息/&l

16、t;returns>删除是否成功</returns>publicstaticboolDeleteHouse(inthouseId)(returnHouseService.DeleteHouseById(houseId)!=0;/发布房屋信息/<returns>添加是否成功</returns>publicstaticboolAddHouse(Househouse)(returnHouseService.AddHouse(house)!=0;在LoginManager.cs中usingSystem;usingSystem.Collections.Gener

17、ic;usingSystem.Text;usingHouseManager.Models;usingHouseManager.DAL;namespaceHouseManager.BLL(publicstaticclassLoginManager(/用户登录判断/returns是否登录成功/returnspublicstaticboolLogin(stringname,stringpassword,outCustomercustomer)(customer=null;Customerc=CustomerService.GetCustomerByLoginName(name);if(c=null)

18、(returnfalse;if(c.Password.Equals(password)customer=c;returntrue;returnfalse;(1) 和LoginPage.aspx和四、在表示层中建立一个空网站:其中包括四个网页窗体:about.aspx和default.aspxReleaseHouseInformationPage.aspx在LoginPage.aspx中1登家窗口登录名密码B嗟录代码如下:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSyst

19、em.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(!

20、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&q

21、uot;User"=cus;this.Response.Redirect("/default.aspx");else(Warnning/提不'错误信息this.ClientScript.RegisterStartupScript(this.GetType(),"<script>alert('用户信息不正确!)</script>");(2) 在ReleaseHouseInformationPage.aspx中:房型史堂一厅,面积B平方米幻LI1价格ibfer已1地址Un1E.错误消息瓦错误消息2.代码如下:

22、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;publicparti

23、alclassReleaseHouseInformationPage: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

24、=newHouse();house.TypeName=house.Area=house.Price=house.Address=this.ddlType.SelectedValue;int.Parse(this.txtArea.Text);double.Parse(this.txtPrice.Text);this.txtAddress.Text;Customercustomer=Session"User"asCustomer;house.Customer=customer;/判断保存信息是否成功if(HouseManager.BLL.HouseManager.AddHous

25、e(house)(/提示成功信息并跳转到查看页面"Alert"this.ClientScript.RegisterStartupScript(this.GetType(),"<script>alert('房屋信息增加成功!);window.location.href='default.aspx'</script>");else(/提不'错误信息"Alert"this.ClientScript.RegisterStartupScript(this.GetType(),"&

26、lt;script>alert('房屋信息增加失败!);</script>");(3) 在default.aspx中:房屋类型面积价格地址数据绑定数据绑定数据绑定数据绑定删除数据绑定数据绑定数据绑定数据绑定删除数据绑定数据绑定数据绑定数据绑定删除数据绑定数据绑定数据绑定数据绑定删除数据绑定选据绑定数据墅数据绑定删除6bjcCtDat&So'tarce-odsHousft5具体就是:设置GridView,设置数据源等操作。(4) 在about.aspx中:自动带的。学生管理系统一、StudentDAL数据访问层中设计三个类:AdminDAL.c

27、s和DBHelper.cs和studentDAL.cs(1)在AdminDAL.cs中usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingStudentModel;usingSystem.Data;usingSystem.Data.SqlClient;namespaceStudentDALpublicclassAdminDALpublicstaticAdminGetAdminByLoginName(stringname)stringsql=string.Format("s

28、elect*fromadminwhereUserId='0'",name);returnGetAdminBySQL(sql);privatestaticAdminGetAdminBySQL(stringsql)using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)Adminc=null;tryconn.Open();SqlCommandcmd=newSqlCommand(sql,conn);SqlDataReadersdr=cmd.ExecuteReader();if(sdr.Read()c=n

29、ewAdmin();c.UserId=sdr"UserId".ToString().Trim();c.UserPwd=sdr"UserPwd".ToString().Trim();catch(Exceptionex)(Console.WriteLine(ex.Message);finally(conn.Close();returnc;在DBHelper中usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceStudentDAL(publicstaticclassDBHe

30、lper(publicstaticreadonlystringconnectString="DataSource=PC-201012101127SQLEXPRESS;InitialCatalog=StudDB;IntegratedSecurity=True”;在studentDAL.cs中usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingStudentModel;namespaceS

31、tudentDAL(publicstaticclassstudentDAL(publicstaticIList<student>GetAllstudent()(List<student>students=newList<student>();using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)(try(conn.Open();SqlCommandcmd=newSqlCommand("select*fromstudent",conn);SqlDataReadersd

32、r=cmd.ExecuteReader();while(sdr.Read()(students=newstudent();s.sno=sdr"sno".ToString();s.sname=sdr"sname".ToString();s.ssex=sdr"ssex".ToString();s.snation=sdr"snation".ToString();s.sclass=sdr"sclass".ToString();s.spass=sdr"spass".ToString()

33、;students.Add(s);catch(Exceptionex)(Console.WriteLine(ex.Message);finally(conn.Close();returnstudents;publicstaticintAddStudent(studentstudent)(stringsql=string.Format("insertintostudent"+"(sno,sname,ssex,snation,sclass,spass)”+"values('0','1','2','3&#

34、39;,'4','5')”,student.sno,student.sname,student.ssex,student.snation,student.sclass,student.spass);intcount=0;using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)tryconn.Open();SqlCommandcmd=newSqlCommand(sql,conn);count=cmd.ExecuteNonQuery();catch(Exceptionex)(Console.Wr

35、iteLine(ex.Message);return0;finally(conn.Close();return1;publicstaticintDeleteStudent(stringstudentsno)(intcount=0;using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)(try(stringsql=string.Format("deletefromstudentwheresno='0'",studentsno);conn.Open();SqlCommandcmd=newS

36、qlCommand(sql,conn);count=cmd.ExecuteNonQuery();catch(Exceptionex)Console.WriteLine(ex.Message);finallyconn.Close();returncount;二、在StudentModel模型层中设计两个类:Admin.cs和student.cs(1)在Admin.cs中usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data;namespaceStudentMode

37、l(publicclassAdmin(privatestringuserid;publicstringUserId(get(returnuserid;set(userid=value;privatestringuserpwd;publicstringUserPwd(get(returnuserpwd;set(userpwd=value;(2)在student.cs中usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data;namespaceStudentModel

38、(publicclassstudent(privatestringS_sno;publicstringsno(get(returnS_sno;set(S_sno=value;privatestringS_sname;publicstringsname(get(returnS_sname;set(S_sname=value;privatestringS_ssex;publicstringssexget(returnS_ssex;set(S_ssex=value;privatestringS_snation;publicstringsnation(get(returnS_snation;set(S

39、_snation=value;privatestringS_sclass;publicstringsclass(get(returnS_sclass;set(S_sclass=value;privatestringS_spass;publicstringspass(get(returnS_spass;set(S_spass=value;(1) 三、在StudentBLL逻辑业务层中设计两个类:AdminBLL.cs和studentBLL.cs在AdminBLL.cs中:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;us

40、ingSystem.Text;usingStudentDAL;usingStudentModel;namespaceStudentBLL(publicclassAdminBLL(publicstaticboolLogin(stringname,stringpassword,outAdminadmin)(admin=null;Adminc=AdminDAL.GetAdminByLoginName(name);if(c=null)(returnfalse;if(c.UserPwd.Equals(password)(admin=c;returntrue;returnfalse;在studentBLL

41、.cs中usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingStudentDAL;usingStudentModel;namespaceStudentBLL(publicstaticclassstudentBLL(publicstaticIList<student>GetAllStudent()(returnstudentDAL.GetAllstudent();publicstaticboolAddStudent(studentstudent)(returnstuden

42、tDAL.AddStudent(student)!=0;publicstaticboolDeleteStudent(stringsno)(returnstudentDAL.DeleteStudent(sno)!=0;about.aspx和AddStudent.aspx和Login.aspx和四、在表示层中建立一个空网站:其中包括五个网页窗体:Default.aspx和ShowStudent.aspx在AddStudent.aspx中学号匕I姓凯性别;I阳f蓿备I代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;u

43、singSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingStudentModel;usingStudentBLL;publicpartialclassAddStudent:System.Web.UI.PageprotectedvoidPage_Load(objectsender,EventArgse)protectedvoidButton1_Click(objectsender,EventArgse)studentstu=newstudent();stu.sno=this.TextBox1.Text.ToString().Trim();stu.sname=this.TextBox2.Text.ToString().Trim();stu.ssex=this.TextBox3.Text.ToString().Trim();stu.sclass=this.TextBox4.Text.ToString().Trim();stu.snation=this.TextBox5.Text.ToString()

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论