版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、房屋销售管理系统一、HouseManagerDAL数据访问层中设计三个类: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.DALpublic static class CustomerServi
2、ce / 根据提供的登录账号查询用户信息 public static Customer GetCustomerByLoginName(string name) string sql = string.Format(select * from Customers where LoginName=0, name); return GetCustomerBySQL(sql); / 根据用户ID查询用户信息 public static Customer GetCustomerById(int id) string sql = string.Format(select * from Customers
3、where CustomerId=0, id); return GetCustomerBySQL(sql); / 私有方法,提供公共方法查询用户信息使用 private static Customer GetCustomerBySQL(string sql) using (SqlConnection conn = new SqlConnection(DBHelper.connectString) Customer c = null; try conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader sdr =
4、cmd.ExecuteReader(); if (sdr.Read() c = new Customer(); c.Id = (int)sdrCustomerId; c.LoginName = sdrLoginName.ToString(); c.Password = sdrPassword.ToString(); catch (Exception ex) Console.WriteLine(ex.Message); finally conn.Close(); return c; (2)在DBHelper中using System;using System.Collections.Generi
5、c;using System.Text;namespace HouseManager.DAL public 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.SqlClient;using
6、HouseManager.Models;namespace HouseManager.DAL public static class HouseService / 获取所有发布的房屋信息 public static IList GetAllHouse() List houses = new List(); using (SqlConnection conn = new SqlConnection(DBHelper.connectString) try conn.Open();SqlCommand cmd = new SqlCommand(select * from Houses, conn);
7、 SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read() House h = new House(); h.Id = (int)sdrHouseId; h.TypeName = sdrHouseTypeName.ToString(); h.Area = (int)sdrArea; h.Price = Convert.ToDouble(sdrPrice); h.Address = sdrAddress.ToString();/外键对象的处理 h.Customer = CustomerService.GetCustomerById(in
8、t)sdrCustomerId); houses.Add(h); catch (Exception ex) Console.WriteLine(ex.Message); finally conn.Close(); return houses; / 根据房屋信息主键ID删除发布的房屋信息 / 受影响的行数 public static int DeleteHouseById(int houserId) int count = 0;using (SqlConnection conn = new SqlConnection(DBHelper.connectString) try string sql
9、= string.Format(delete from Houses where HouseId=0, houserId); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); count = cmd.ExecuteNonQuery(); catch (Exception ex) Console.WriteLine(ex.Message); finally conn.Close(); return count; / 增加发布的房屋信息 / 受影响的行数 public static int AddHouse(House house)
10、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(); Sql
11、Command cmd = 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.Text;nam
12、espace Serializable public class Customer private int id; public int Id get return id; set id = value; private string loginName; / 登录账号 public string LoginName get return loginName; set loginName = value; private string password; / 登录密码 public string Password get return password; set password = valu
13、e; (2)在house.cs中using System;using System.Collections.Generic;using System.Text;namespace HouseManager.Models Serializable public class House private int id; public int Id get return id; set id = value; private string typeName; / 房屋类型名称 public string TypeName get return typeName; set typeName = valu
14、e; private int area; / 面积 public int Area get return area; set area = value; private double price; / 价格 public double Price get return price; set price = value; private string address; / 地址 public string Address get return address; set address = value; private Customer customer; / 发布人 public Custome
15、r Customer get 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.BLL public static class Hous
16、eManager / 查询所有发布的房屋信息 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(hou
17、se) != 0; (2)在LoginManager.cs中using System;using System.Collections.Generic;using System.Text;using HouseManager.Models;using HouseManager.DAL;namespace HouseManager.BLL public static class LoginManager / 用户登录判断 / 是否登录成功 public static bool Login(string name, string password, out Customer customer) c
18、ustomer = null; Customer c = CustomerService.GetCustomerByLoginName(name); if (c = null) return false; if (c.Password.Equals(password) customer = c; return true; return false; 四、在表示层中建立一个空网站:其中包括四个网页窗体:about.aspx和default.aspx和LoginPage.aspx和ReleaseHouseInformationPage.aspx(1)在LoginPage.aspx中代码如下:usi
19、ng System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using HouseManager.Models;using HouseManager.BLL;pu
20、blic partial class LoginPage : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (!this.IsPostBack) /已登录直接跳转到查看页面 if (SessionUser != null) this.Response.Redirect(/default.aspx); protected void btnLogin_Click(object sender, EventArgs e) Customer cus = null; /验证登录信息是否正确 if (Lo
21、ginManager.Login(this.txtLoginName.Text.Trim(), this.txtPassword.Text.Trim(), out cus) /跳转到查看页面 SessionUser = cus; this.Response.Redirect(/default.aspx); else /提示错误信息 this.ClientScript.RegisterStartupScript(this.GetType(), Warnning, alert(用户信息不正确!); (2)在ReleaseHouseInformationPage.aspx中:代码如下:using S
22、ystem;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using HouseManager.Models;using HouseManager.BLL;public
23、 partial class ReleaseHouseInformationPage : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (!this.IsPostBack) /没有登录的话,跳转到登录页面 if (SessionUser = null) this.Response.Redirect(/LoginPage.aspx); protected void btnSubmit_Click(object sender, EventArgs e) /从界面获取用户输入的信息 House h
24、ouse = new House(); house.TypeName = 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.Customer = customer; /判断保存信息是否成功 if (HouseManager.BLL.H
25、ouseManager.AddHouse(house) /提示成功信息并跳转到查看页面 this.ClientScript.RegisterStartupScript(this.GetType(), Alert, alert(房屋信息增加成功!);window.location.href=default.aspx;); else /提示错误信息 this.ClientScript.RegisterStartupScript(this.GetType(), Alert, alert(房屋信息增加失败!);); (3)在default.aspx中:具体就是:设置GridView,设置数据源等操作。
26、(4)在about.aspx中:自动带的。学生管理系统一、StudentDAL数据访问层中设计三个类:AdminDAL.cs和DBHelper.cs和studentDAL.cs (1)在AdminDAL.cs中using System;using System.Collections.Generic;using System.Linq;using System.Text;using StudentModel;using System.Data;using System.Data.SqlClient;namespace StudentDAL public class AdminDAL publi
27、c static Admin GetAdminByLoginName(string name) string sql = string.Format(select * from admin where UserId=0, name); return GetAdminBySQL(sql); private static Admin GetAdminBySQL(string sql) using (SqlConnection conn = new SqlConnection(DBHelper.connectString) Admin c = null; try conn.Open(); SqlCo
28、mmand cmd = new SqlCommand(sql, conn); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read() c = new Admin(); c.UserId = sdrUserId.ToString().Trim(); c.UserPwd = sdrUserPwd.ToString().Trim(); catch (Exception ex) Console.WriteLine(ex.Message); finally conn.Close(); return c; (2)在DBHelper中using Sys
29、tem;using System.Collections.Generic;using System.Text;namespace StudentDAL public static class DBHelper public static readonly string connectString = Data Source=PC-201012101127SQLEXPRESS;Initial Catalog=StudDB;Integrated Security=True; (3)在studentDAL.cs中using System;using System.Collections.Generi
30、c;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;using StudentModel;namespace StudentDAL public static class studentDAL public static IList GetAllstudent() List students = new List(); using (SqlConnection conn = new SqlConnection(DBHelper.connectString) try conn.Op
31、en(); SqlCommand cmd = new SqlCommand(select * from student,conn); SqlDataReader sdr = 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.ToSt
32、ring(); s.spass = sdrspass.ToString(); students.Add(s); catch(Exception ex) Console.WriteLine(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
33、), student.sno,student.sname,student.ssex,student.snation,student.sclass,student.spass); int 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.Write
34、Line(ex.Message); return 0; finally conn.Close(); return 1; public static int DeleteStudent(string studentsno) int count = 0; using (SqlConnection conn = new SqlConnection(DBHelper.connectString) try string sql =string.Format(delete from student where sno=0,studentsno); conn.Open(); SqlCommand cmd =
35、 new SqlCommand(sql,conn); count = cmd.ExecuteNonQuery(); catch (Exception ex) Console.WriteLine(ex.Message); 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.Da
36、ta;namespace StudentModel public class Admin private string userid; public string UserId get return userid; 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.Da
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年厦门兴才职业技术学院单招职业倾向性考试题库及参考答案详解一套
- 2026年内蒙古民族幼儿师范高等专科学校单招职业倾向性测试题库及答案详解(基础+提升)
- 2026年厦门兴才职业技术学院单招职业适应性考试题库带答案详解(黄金题型)
- 2026年南阳科技职业学院单招职业适应性考试题库附答案详解(能力提升)
- 2026年内蒙古北方职业技术学院单招综合素质考试题库带答案详解(完整版)
- 2026年信阳学院单招职业适应性测试题库附参考答案详解(研优卷)
- 2026年六安职业技术学院单招综合素质考试题库含答案详解(精练)
- 2026年南宁职业技术学院单招职业技能测试题库带答案详解(预热题)
- 2026年南昌交通学院单招职业技能考试题库含答案详解(突破训练)
- 2026年内蒙古化工职业学院单招职业适应性考试题库附答案详解(b卷)
- 水务公司2026年节后复工安全生产培训
- (2025年)泰兴市事业单位招聘财务会计知识试题及答案
- 2026内蒙古地质矿产集团有限公司社会招聘65人备考题库带答案详解(b卷)
- 《力与大地:重力、摩擦力的科学透视与地理联结》-初中科学(八年级)单元复习课教学设计
- 2025年宁波职业技术学院单招职业技能考试题库附答案解析
- 工程地质工程施工钻探工春节后复工安全考核试卷含答案
- 2025年曼迪匹艾笔试真题及答案
- 江苏省13市2026届高一上数学期末经典试题含解析
- 2026年山东单招职业适应性测试时政经典题集含答案
- 2026年内蒙古单招新能源汽车技术专业技能故障诊断经典题集含答案
- 2025锅炉使用单位锅炉使用安全风险日管控、周排查、月调度管理制度
评论
0/150
提交评论