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

下载本文档

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

文档简介

1、房屋销售管理系统一、housemanagerdal数据访问层屮设计三个类:customerservice cs 彳h dbhelper cs 彳h houseserver cs在 customerservice. cs 中using system;using system. collections. generic;using systcm. text;using system. data;using system.data. sqlclient;using ilousemanager. models;namespace housemanager. dalpublic static class

2、 customerservice/根据提供的登录账号查询用户信息public static customer getcustomerbyloginname(string name)string sql = string. format ("'select * from customers where loginname=,name); rcturn getcustomerbysql(sql);/根据用户id查询用户信息public static customer getcustomerbyld(int id)str ing sql = str ing format ('

3、;'select * from customers where customer i d=0id); return getcustomerbysql(sql);/私有方法,提供公共方法查询用户信息使用private static customer getcustomerbysql(string sql)using (sqlcormection conn = new sqlconnection(dbhelper connectstring)customer c 二 null;tryconn. open ();sqlcommand cmd 二 new sqlcommand(sql, con

4、n); sqldatareader sdr 二 cmd. executereadero;if (sdr. reado)c = new customer ();c. td = (int) sdrz,customertd,z;c- log inname 二 sdr ,zloginname,z. tostringo ;c. password = sdr/zpasswordz,. tostringo ;catch (except!on ex)conso1e.wri teline(ex message);finallyconn. closeo ;return c;(2) 在dbhelper中using

5、system;using system.collections- generic;using system. text;namespace housemanagcr. dalpublic static class dbhelperpublic static readonly string connectstring ="server二.;database=housedb;u id=sa;pwd=123456;(3) 在houseservi ce屮using system;using systcm. collections. generic;using system. text;usi

6、ng system. data;using system. data. sqlclient;using housemanager. models;namespace housemanager. dalpublic static class houseservice/获取所有发布的房屋信息pub 1i c static ilist<house> getali house ()li st<house> houses = new li st<house> ();using (sqlconnection conn 二 new sqlconnection(dbhelp

7、er. connectstring)tryconn. open ();sqlcoinmand cmd = new sqlcommand("select * from houses", conn);sqldatarcader sdr = cmd.executereadcr();whi le (sdr. read ()house h = new house();h. id = (int) sdr,houseid/,;h. typename = sdr/,housetypename,/. tostring();h. area = (int) sdr ,zareaz,;h.pric

8、e = convert. todouble (sdr"price");h. address = sdr ,address,j. tostring();/夕卜键对象的处理h. customer = customerservice. getcustomerbyld (int) sdwcustomerlcr); houses.add(h);catch (exception ex)gonso 1e. wri telinc (ex. message);finallyconn. closeo ;return houses;/根据房屋信息主键id删除发布的房屋信息/returns受影响的

9、行数/returnspublic static int deletehousebyld(int houserld)int count 二 0;using (sqlconnection conn = new sqlconnection(dbhelper. connectstring)trystring sql = string. format("delete from houses where ilouseld二0", houserld); conn. open();sqlconuna nd cmd = new sq 1 comma nd (sql, conn);count

10、二 cmd. executenonquery();catch (exception ex)gonso 1e. wri telinc (ex. message);finallyconn. closeo ;return count;/增加发布的房屋信息/ <returns>受影响的行数</returns>public static int addllouse(house house)string sql = string. format ("'insert into dbo houses'7+ " (housetypenamo, area

11、, price, address, customerld)"+ values (' 0', 1, 2, ' 3' , 4) ,house typename, house.area, house. price, house. address, house customer. id);int count = 0;using (sqlconnection conn = new sqlconnection(dbhelpercormectslring) tryconn. opcn ();sqlcommand emd = new sqlcommand(sql, c

12、onn);count = cmd. executenonquery();catch (exception ex)console. writeline(ex. message);return 0;finallyconn. close ();return 1;二、在housemanagermodel s模型层屮设计两个类:customer, cs和house.cs(1)在customer, cs屮using system;using system. collections. generic;using system. text;namespaceserializable public class

13、customerprivate int id;public int idget return id; set id = value; private string loginname;/登录账号public string loginnameget return loginname; set loginname = value; private string password;/登录密码pub 1ic string passwordget return password; set password = value; (2)在house, cs中 using system;using system

14、. collections. generic;using system. text;namespace housemanager. modelsserializablepublic class houseprivate int id;public int tdget return id; set id = value; private string typename;/房屋类型名称pub 1ic string typcnamcget return typename; set typename = value; private int area;/面积public int areaget ret

15、urn area; set area = value; private double price;/价格public double priceget return price; set price = value; private string address;/地址public string addressget return address; set address = value; private customer customer;/发布人public customer customerget roturn customer; set customer = value; 三、在 hou

16、semanagerbll 逻辑业务层屮设计两个类:houscmanagcr. cs 和 log inmanager, cs(1) 在housemanager. cs中:using system;using system.collections- generic;using system. text;using houscmanagor.models;using housemanager. dal;namespace housemanager. bllpublic static class housemanager/查询所有发布的房屋信息public static llist<house&

17、gt; getallhouseoreturn houseservice.getallhouse();/删除已发布的房屋信息/ <returns>删除是否成功</returns>public static bool deletehousednt houseld)return houseservice. deletellousebyld(housetd) != 0; /发布房屋信息/ <returns>添加是否成功/returnspublic static bool addhouse(house house)return houseservice.addhous

18、e(house) != 0;(2) 在logi nmanager. cs中using system;using system. collections. generic;using systcm. text;using housemanager.models;using housemanager. dal;namespace housemanager> bllpublic static class loginmanager/用户登录判断/ <returns>是否登录成功</returns>public static bool login(string name,

19、string password, out customer customer) customer = null;customer c = customerservice. getcustomerbyloginname (name);if (c = null)return false;i f (c. password. equals(password)customer = c;return true;return false;四、在表示层中建立一个空网站:其中包括四个网页窗体:about, aspx和default, aspx和loginpage. aspx和releasellouselnfor

20、mationpage. aspx在loginpage. aspx中登录窗口1登录名en密码e片1壁录代码如下:using system;using system. data;using system. configuration;using systcm. collections;using system. web;using system. web. securi ty;using system. web. ut;using system. web. ul. webcontrols;using systcm. web ui webcontrols wobparts;using system.

21、 web. ui htmlcontrols;using housemanager.models;using housemanagerbll;public partial class loginpage : systemweb. ui. pageprotected void page load(object sender, eventargs e)if (!this. ispostback)/已登录直接跳转到查看页面if (session"user" != null)this. response. redirect("“/default, aspx");p

22、rotected void btnloginclick(object sender, eventargs e)customer cus = null;验证登录信息是否正确i f (lo gin manager. log in( this. txtloginname. text. trim(), this. txtpassword. text. trim(), out cus)/跳转到查看页面session"user" = cus; this. response. redirect (小/default. aspxz,);else/提示错误信息,/warnning,this.

23、 clientscript. registerstartupscript (this. gettypeo, /z<script>alert ('用户信息不正确! ')/script");(2) itreleasellouselnformationpage. aspx中:代码如下:using system;using system. data;using system. configuration;using system. collections;using system web;using system. websecurity;using system

24、.web. ut;using system. web. ui. webcontrols;using system. web. ul. webcontrols. webparts;using systcm. web ui htinlcontrols;using housemanager.models;using housemanagerbi丄;protected void page load(object sender, eventatgs e)if (!this.tspostback)/没有登录的话,跳转到登录页面if (session"user" = null)this.

25、 response. redirect (''"/loginpage. aspx,z);protected void btnsubmi t_click(object sender, eventargs e)/从界而获取用户输入的信息house house = new house ();house. typename = this.ddltype.selectedvalue;house. area = int. parse(this. txtarea. text);house.price = double. parse(thistxtprice. text);house

26、.address = this.txtaddress. text;customer customer = session"user" as customer;house. customer = customer;判断保存信息是否成功i f (houseman鸥er. bll. iiousemanager. addhouse (house)/提示成功信息并跳转到査看页面"alert","alert",this. clientscript. registerstartupscript (this. gettype(),/z<scri

27、pt>alert ('房屋信息增加成功!');window, location, href二'default. aspx,;/script");else/提示错误信息this. clientscript. registerstartupscript (this. gettypeo, z,<script>alert(,房屋信息增加失败!);/script");(3) 在default, aspx中:价格 地址房屋类型面积数据绑定数据绑定数据绑定数据绑定删除 数据绑定数据绑定数据绑定数据绑定删除 数据绑定数据绑定数据绑定数据绑定删除 数

28、据绑定数据绑定数据绑定数据绑定删除 数据绑定数据绑定数据绑定数据绑定删隆 ibj ectdatasource 一 odshouses具体就是:设置gridview,设置数据源等操作。(4) 在about, aspx中:自动带的。 学生管理系统一、studcntdal数据访问层中设计三个类:admindal. cs 和 dbhelper. cs 和 studentdal. cs (1)在 admindal. cs 中using system;using system. collections- generic;using system. linq;using system text;using

29、studenthodel;using system. data;using system. data. sqlclient;namespace studentdalpublic class admindalpublic static admin getadminbyloginname(string name)string sql = string. format (select * from admin where userid0',namc); return getadminbysql(sql);private static admin getadminbysql(string sq

30、l)using (sqlconnection corm 二 new sqlconnoct ion(dbholporconnoctstring)admin c = nul1;tryconn. opcn ();sqlcommand cmd = new sqlcommand(sql, conn);sqldatareader sdr = cmd.executereader();if (sdr. reado)c = now adm in ();c.userid = sdr"userid". tostring(). trim();c. userpwd = sdr/,userpwd,j.

31、 tostring(). trim();console. wri teline (ex. message); finallyconn. closeo ;return c;(2)在dbhelper中using system;using system.collections generic;using system. text;namespace studentdalpublic static class dbhelperpublic static readonly string connectstring = "datasource=pc-201012101127sqlexpress;

32、initial catalog二studdb;integrated security二true" (3)在studentdal. cs中using system;using system-collections- generic;using system. linq;using system. text;using system .data;using system.data. sqlclient;using studentmodel;namespace studentdalpublic static class studentdalpublic static tlist<st

33、udentgetal1 student()list<studcnt> students = new list<student();using (sqlconnection conn = new sqlconnection(dbhelperconnectstring)tryconn open ();sqlcommand cmd = new sqlcommand(select * from student"7, conn); sqldatareader sdr = cmdexecutereader ();while (sdr. read()student s = new

34、 student ();s. sno = sdrsno tostring();s. sname 二 sdr"snaine tostring();s. ssex = sdr ssex tostringo ;s. snation = sdr/zsnation tostringo ;s. sclass = sdr /zsclass/z tostring();s. spass = sdr,zspassz,. tostringo ; students-add(s);catch(exception ex)console.writeline (ex. message);finallyconn. c

35、loseo ;return students;public static int addstudent (student student)string sql = stringformat("insert into student"+ " (sno, sname, ssex, snation, sclass, spass)"+ " values (' 0',' 1',' 2',' 3',' 4',''),student. sno, student.

36、sname, student. ssex, student. snation, student, sclass, student. spass); int count = 0;using (sqlconnection conn = new sqlcormection(dbhelperconncctstring)tryconn. 0pen();sql comma nd cmd = new sql comma nd (sql, corm);count = cmdexecutenonquery ();console writeline (ex. message);return 0;finallyco

37、nn. close ();return 1;public static int deletestudent (string studentsno)int count 二 0;using (sqlconnection conn = new sqlconnection(dbhelper.connectstring)trystring sql =string. format (''delete from student where sno二'0' studentsno); conn 0pen();sqlcommand cmd = new sqlcommand(sql,

38、 conn);count = cmdexecutenonquery();catch (except!on ex)console.writeline(ex message);finallyconn. closeo ;return count;二、在studentmodel模型层中设计两个类: admin.cs和student cs(1)在admin, cs中using system;using system collections. generic;using system. linq;using system. text;using system. data;namespace student

39、uodcl public class adminprivate string userid; public string userid get return userid; set userid 二 value; private string usorpwd; public string userpwd get return userpwd; set userpwd = value;) (2)在student, cs 中using system;using system collections. generic;using system. linq;using system. text;usi

40、ng system. data;namespace studentuodclpublic class studentprivate string s_sno;public string snoget return s_sno; set s_sno 二 value; private string s_snainc; public string sname get return s_sname; set s_sname = value;) private string s ssex; public string ssexget return s_ssex; set s ssex = value;

41、private string s_snation; public string snation get return s snation; set s_snation 二 value; private string s_sclass; public string sclassgetset return s_sclass; s_sclass 二 value; privatestring s_spass;public string spassget return s_spass; set s_spass = value;)三、在studentbll逻辑业务层中设计两个类:adminbll. cs和

42、studentbll. cs(1) 在adminbll. cs中: using system;using system. collections. generic;using system. linq;using system. text;using studentdal;using stuclcntmodcl;namespace studentbllpublic class adminbllpub 1ic static bool login(string name, string password, out admin admin) admin 二 nul1;admin c = admind

43、al. getadminbyloginname(name);if (c = null)return false;if (c. userpwd equals(password)admin 二 c; return true;return false;(2) 在studentbll. cs中using system;using system collections generic;using system. linq;using system. text;using studentdal;using studentmodel;namespace studentbllpublic static cla

44、ss studentbllpub i i c static ilist<studcnt> getalistudent ()return studentdal. getal1 student();public static bool addstudent(student student) return studentdaladdstudent(student) != 0;public static bool deletestudent(string sno) return studentdaldoletestudent(sno)!= 0;四、在表示层中建立一个空网站:其中包括五个网页

45、窗体:about, aspx和addstudent. aspx和login, aspx和default aspx和showstudcnt aspx在addstudent. aspx中学号: 姓名: 性别: 翻:宿舍:i代码如下:using system;using system.collections. generic;using system. linq;using system. web;using system. webui;using system. web ui. webcontrols;using studentmodel;using studentbll;pub 1ic part

46、ial class addstudenl : systemweb. uipageprotected voi d page_load(object sender, eventargs e)protected void buttonl_c1ick(object sender, eventargs e)student stu = new student ();stu. sno 二 this. textbox 1. text. tostring(). trimo ;stu. sname = this. textbox2. text. tostringo. trimo ;stu. ssex = this. textbox3. text. tostringo. trimo ;stu. sclass = this. textbox4. text. tostring(). trimo ;stu. snation二 this. textbox5.

温馨提示

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

评论

0/150

提交评论