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

下载本文档

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

文档简介

1、房屋销售管理系统一、HouseMa nagerDAL数据访问层中设计三个类:CustomerService.cs 和 DBhelper.cs 和 houseserver.cs(1) 在 CustomerService.cs 中using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.SqlClient;using HouseManager.Models;namespace HouseManager.DAL public static class Cust

2、omerService/ 根据提供的登录账号查询用户信息public static Customer GetCustomerByLoginName( string name), name);string sql = string .Format( select * from Customers where LoginName=0 return GetCustomerBySQL(sql);III根据用户ID查询用户信息public static Customer GetCustomerById( int id), id);string sql = string .Format( select *

3、 from Customers where CustomerId=0 return GetCustomerBySQL(sql);III 私有方法,提供公共方法查询用户信息使用 private static Customer GetCustomerBySQL( string sql)using ( SqlConnection conn = new SqlConnection (DBHelper.connectString) Customer c =null ;tryconn.Open();SqlCommandcmd = new SqlCommand(sql, conn); SqlDataRead

4、er sdr = cmd.ExecuteReader();c = c.Id = (c.LoginName= sdrc.Password =sdrif (sdr.Read()new Customer();int )sdr CustomerId ;LoginName .ToString();Password .ToString();catch ( Exception ex)Console .WriteLine(ex.Message);finallyconn.Close();return(2) 在 DBHelper 中 using System; using System.Collections.G

5、eneric; using System.Text;namespace HouseManager.DALpublic static class DBHelper public static readonly string connectString = server=.;database=HouseDB;uid=sa;pwd=123456 ;(3) 在 HouseService 中using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.SqlClien

6、t;using HouseManager.Models; namespace HouseManager.DALpublic static class HouseService/ 获取所有发布的房屋信息 public static IList GetAllHouse()List houses = new List ();using ( SqlConnection conn = new SqlConnection (DBHelper.connectString) tryconn.Open();SqlCommandcmd = new SqlCommand( select * from Houses

7、, conn);SqlDataReader sdr = cmd.ExecuteReader();House h =h.Id = (h.TypeName = sdrh.Area = (while (sdr.Read()new House();int )sdr HouseId ;HouseTypeName.ToString();int )sdr Area ;h.Price = h.Address = sdrConvert .ToDouble(sdr Price );Address .ToString(); / 外键对象的处理CustomerId );h.Customer = CustomerSer

8、vice.GetCustomerById(int )sdrhouses.Add(h);catch ( Exception ex)Console .WriteLine(ex.Message);finallyconn.Close();return houses;/ 根据房屋信息主键 ID 删除发布的房屋信息/ 受影响的行数 public static int DeleteHouseById( int houserId)int count = 0;using ( SqlConnection conn = new SqlConnection (DBHelper.connectString)try, h

9、ouserId);string sql = string .Format( delete from Houses where HouseId=0 conn.Open();SqlCommandcmd = new SqlCommand(sql, conn); count = cmd.ExecuteNonQuery();catch ( Exception ex)Console .WriteLine(ex.Message);finallyconn.Close();return count;/ 增加发布的房屋信息/ 受影响的行数 public static int AddHouse(House hous

10、e)string sql = string .Format( insert into dbo.Houses + (HouseTypeName,Area,Price,Address,CustomerId)+ 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 (DBHelper.connectString) try conn.Open();S

11、qlCommandcmd = new SqlCommand(sql, conn); count = cmd.ExecuteNonQuery();catch ( Exception ex)Console .WriteLine(ex.Message); return 0;finally conn.Close(); return 1;二、在 HouseManagerModels 模型层中设计两个类: Customer.cs 和 house.cs(1) 在 Customer.cs 中 using System;using System.Collections.Generic;using System.

12、Text;namespace Serializable public class 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;/ 登录密码 public string Password get return password; set password = v

13、alue ; ( 2)在 house.cs 中using System;using System.Collections.Generic;using System.Text;namespace HouseManager.Models Serializable public class Houseprivate int id;public int Idget return id; set id = value ; private string typeName;/ 房屋类型名称public string TypeNameget return typeName; set typeName = va

14、lue ; private int area;/ 面积 public int Areaget return 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 Cu

15、stomerget return customer; set customer = value ; 三、在 HouseManagerBLL逻辑业务层中设计两个类:HouseManager.cs 和 LoginManager.cs(1) 在 HouseManager.cs 中:using System;using System.Collections.Generic;using System.Text;using HouseManager.Models;using HouseManager.DAL;namespace HouseManager.BLLpublic static class Hou

16、seManager/ 查询所有发布的房屋信息public static IList GetAllHouse() return HouseService.GetAllHouse();/ 删除已发布的房屋信息/ 删除是否成功 public static bool DeleteHouse( int houseId) return HouseService.DeleteHouseById(houseId) != 0;/ 发布房屋信息/ 添加是否成功 public static bool AddHouse(House house) return HouseService.AddHouse(house)

17、!= 0;(2) 在 LoginManager.cs 中using System;using System.Collections.Generic;using System.Text;using HouseManager.Models;using HouseManager.DAL;namespace HouseManager.BLLpublic static class LoginManager/ 用户登录判断/ 是否登录成功 public static bool Login( string name, string password, out Customer customer) custo

18、mer = null ;Customer c = CustomerService.GetCustomerByLoginName(name);if (c = null )return false ;if (c.Password.Equals(password)customer = c;return true ;return false ;禾口 LoginPage.aspx 禾口四、在表示层中建立一个空网站:其中包括四个网页窗体:about.aspx和default.aspxReleaseHouse In formati on Page.aspx(1)在 LoginPage.aspx 中1登录窗口

19、登录名密码B誓1代码如下:using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.Ul.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using HouseManager.Models;using Hou

20、seManager.BLL;public partial class Logi nPage : System.Web.UI.Pageprotected void Page_Load( object sender,EventArgs e)if (! thissPostBack)/已登录直接跳转到查看页面if (Session User != null )this .Response.Redirect(/default.aspx );protected void btnLogin_Click(object sender,EventArgs e)Customer cus =null ;/验证登录信息

21、是否正确if (LoginManager.Login(this .txtLoginName.Text.Trim(),this .txtPassword.Text.Trim(),out cus)/跳转到查看页面SessionUser = cus;this .Response.Redirect(/default.aspx );else/提示错误信息Warn ningthis .ClientScript.RegisterStartupScript(this .GetType(),alert(用户信息不正确!) );(2) 在 ReleaseHouseInformationPage.aspx 中:房型

22、面积丄皇_厅耳1r平方杷li1价格F元厂地址UE嘴错误消息工-卅息2-1J代码如下:using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.Ul.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using

23、HouseManager.Models;using HouseManager.BLL;public partial class ReleaseHouseInformationPage : System.Web.UI.Page protected void Page_Load( object sender, EventArgs e)if (! this .IsPostBack)/ 没有登录的话,跳转到登录页面if (Session User = null )this .Response.Redirect( /LoginPage.aspx ); protected void btnSubmit_C

24、lick( object sender, EventArgs e) / 从界面获取用户输入的信息House house = house.TypeName =new House();this .ddlType.SelectedValue;house.Area = int .Parse( this .txtArea.Text);house.Price = double .Parse( this .txtPrice.Text);house.Address =this .txtAddress.Text;Customer customer = SessionUser as Customer;house.

25、Customer = customer;/ 判断保存信息是否成功if (HouseManager.BLL.HouseManager.AddHouse(house) / 提示成功信息并跳转到查看页面this .ClientScript.RegisterStartupScript(this .GetType(),Alertalert( 房屋信息增加成功!);window.location.href=default.aspx; );else/ 提示错误信息this .ClientScript.RegisterStartupScript(alert( 房屋信息增加失败!this .GetType(),

26、 ); );Alert( 3)在 default.aspx 中:房屋类型面积 价格 地址数据娜定数据绑定数据绑审数据绑定删除数据绑定数据绑定数据绑定数据绑定删陈数据绑定 数据绑定数据绑定数据绑定删除数据编定数据绑定数据绑定数据绑定删除 数据绑定建据绑定数据塑数据绑定删除 6bj cCtDat&Sotarce - odsHousft 5具体就是:设置GridView,设置数据源等操作。(4)在about.aspx 中:自动带的。学生管理系统一、StudentDAL数据访问层中设计三个类:AdminDAL.cs 和 DBHelper.cs 和 studentDAL.cs (1) 在 AdminDA

27、L.cs 中using System;using System.Collect ion s.Ge neric;using System.L inq;using System.Text;using Stude ntModel;using System.Data;using System.Data.SqlClie nt;n amespace Stude ntDALpublic class Adm in DALpublic static Admin GetAdmi nByLogi nN ame(stri ng n ame)string sql = string.Format(select * fro

28、m admin where Userld=0, name); return GetAdmi nBySQL(sql);private static Adm in GetAdminBySQL(string sql)using (SqlC onn ectio n conn = new SqlC onn ectio n(DBHelper.c onn ectStri ng) Admin c = nu II;tryconn. Ope n();SqlComma nd cmd = new SqlComma nd(sql, conn);SqlDataReader sdr = cmd.ExecuteReader(

29、);if (sdr.Read()c = new Admi n();c.Userld = sdrUserld.ToStri ng().Trim();c.UserPwd = sdrUserPwd.ToStri ng().Trim();catch (Exception ex)Console.WriteLine(ex.Message);finally conn.Close();return c;(2) 在 DBHelper 中using System;using System.Collections.Generic;using System.Text;namespace StudentDALpubli

30、c static class DBHelperpublic static readonly string connectString = DataSource=PC-201012101127SQLEXPRESS;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.SqlCli

31、ent;using StudentModel;namespace StudentDALpublic static class studentDALpublic static IList GetAllstudent()List students = new List();using (SqlConnection conn = new SqlConnection(DBHelper.connectString)try conn.Open(); SqlCommand cmd = new SqlCommand(select * from student,conn); SqlDataReader sdr

32、= cmd.ExecuteReader();while (sdr.Read() student s = new student(); s.sno = sdrsno.ToString(); s.sname = sdrsname.ToString(); s.ssex = sdrssex.ToString(); s.snation = sdrsnation.ToString(); s.sclass = sdrsclass.ToString(); s.spass = sdrspass.ToString(); students.Add(s); catch(Exception ex) Console.Wr

33、iteLine(ex.Message); finally conn.Close();return students; public static int AddStudent(student student)string sql = string.Format(insert into student+ (sno,sname,ssex,snation,sclass,spass) + values (0,1,2,3,4,5),student.sno,student.sname,student.ssex,student.snation,student.sclass,student.spass); i

34、nt count = 0;using (SqlConnection conn = new SqlConnection(DBHelper.connectString) try conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); count = cmd.ExecuteNonQuery();catch (Exception ex)Console.WriteLine(ex.Message);return 0;finally conn.Close();return 1;public static int DeleteStudent(strin

35、g studentsno)int count = 0;using (SqlConnection conn = new SqlConnection(DBHelper.connectString)trystring sql =string.Format(delete from student where sno=0,studentsno); conn.Open();SqlCommand cmd = new SqlCommand(sql,conn);count = cmd.ExecuteNonQuery();catch (Exception ex)Console.WriteLine(ex.Messa

36、ge);finally conn.Close();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 StudentModelpublic class Adminprivate string userid;public string UserIdget return useri

37、d; set userid = value; private string userpwd; public string UserPwd get return userpwd; set userpwd = value; ( 2)在 student.cs中using System;using System.Collections.Generic; using System.Linq;using System.Text;using System.Data;namespace StudentModelpublic class studentprivate string S_sno;public st

38、ring snoget return S_sno; set S_sno = value; private string S_sname; 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; private string S_snation;public string snationget return S_snation; set S_snation = value;

39、 private string S_sclass;public string sclassget return S_sclass; set S_sclass = value; private string S_spass;public string spassget return S_spass; set S_spass = value; 三、在 StudentBLL 逻辑业务层中设计两个类: AdminBLL.cs 和 studentBLL.cs (1) 在 AdminBLL.cs 中:using System;using System.Collections.Generic;using S

40、ystem.Linq;using System.Text;using StudentDAL;using StudentModel;namespace StudentBLLpublic class AdminBLLpublic static bool Login(string name, string password, out Admin admin)admin = null;Admin c = AdminDAL.GetAdminByLoginName(name);if (c = null)return false;if (c.UserPwd.Equals(password) admin =

41、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 class studentBLLpublic static IList GetAllStudent()return studentDAL.GetAllstudent();public static

42、 bool AddStudent(student student)return studentDAL.AddStudent(student) != 0;public static bool DeleteStudent(string sno)return studentDAL.DeleteStudent(sno)!= 0;about.aspx 和 AddStudent.aspx 和 Login.aspx 和四、在表示层中建立一个空网站:其中包括五个网页窗体: Default.aspx 和 ShowStudent.aspx(1) 在 AddStudent.aspx 中代码如下:using Syst

43、em;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.Ul.WebControls;using StudentModel;using StudentBLL;public partialclass AddStudent : System.Web.UI. Pageprotected void Page_Load( object sender,EventArgs e)protected void Butt on 1_Click(object sen der,Even tArgs e)stude nt stu =new stude nt();stu.sno =this .TextBox1.Text.ToString().Trim();stu.sname =this .TextBox2.Text.ToString().Trim();stu.ssex =this .

温馨提示

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

评论

0/150

提交评论