欢迎来到天天文库
浏览记录
ID:18341301
大小:165.00 KB
页数:20页
时间:2018-09-16
《学生管理系统web程序设计代码new》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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.DAL{publicstati
2、cclassCustomerService{///根据提供的登录账号查询用户信息publicstaticCustomerGetCustomerByLoginName(stringname){stringsql=string.Format("select*fromCustomerswhereLoginName='{0}'",name);returnGetCustomerBySQL(sql);}///根据用户ID查询用户信息publicstaticCustomerGetCustomerById(intid){stringsql=string.
3、Format("select*fromCustomerswhereCustomerId={0}",id);returnGetCustomerBySQL(sql);}///私有方法,提供公共方法查询用户信息使用privatestaticCustomerGetCustomerBySQL(stringsql){using(SqlConnectionconn=newSqlConnection(DBHelper.connectString)){Customerc=null;try{conn.Open();SqlCommandcmd=newSqlCo
4、mmand(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;
5、}}}}(2)在DBHelper中usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceHouseManager.DAL{publicstaticclassDBHelper{publicstaticreadonlystringconnectString="server=.;database=HouseDB;uid=sa;pwd=123456";}}(3)在HouseService中usingSystem;usingSystem.Collections.G
6、eneric;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingHouseManager.Models;namespaceHouseManager.DAL{publicstaticclassHouseService{///获取所有发布的房屋信息publicstaticIListGetAllHouse(){Listhouses=newList();using(SqlConnectionconn=newSqlConnec
7、tion(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
8、=Convert.ToDouble(sdr["Price"]);h.Address=sdr["Address"].ToString();//外键对象的处理h.Customer=Customer
此文档下载收益归作者所有