酒店管理系统-计算机应用专业毕业论文_第1页
酒店管理系统-计算机应用专业毕业论文_第2页
酒店管理系统-计算机应用专业毕业论文_第3页
酒店管理系统-计算机应用专业毕业论文_第4页
酒店管理系统-计算机应用专业毕业论文_第5页
已阅读5页,还剩72页未读 继续免费阅读

下载本文档

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

文档简介

1、精品资料9JWKffwvG#tYM*Jg&6a*CZ7H$dq8KqqfHVZFedswSyXTy#&QA9wkxFyeQ!djs#XuyUP2kNXpRWXmA&UE9aQGn8xp$R#using System.Data;using System.Data.SqlClient;using System.Collections.Generic;using System.Configuration;using System.Linq;using System.Text;usingices;namespace HotelCOM public class HotelClass:ServicedCo

2、mponent /保存数据库的连接字符串windows身份验证 private readonly string connectionString = Data Source=.;Initial Catalog=Hotel;Integrated Security=True; protected SqlConnection ConnObject; protected SqlCommand CmdObject; protected SqlDataAdapter AdapterObject; public HotelClass() ConnObject = new SqlConnection(conn

3、ectionString); /执行Sql语句,如 Update、Delete、Insert语句,成功返回影响行数据 public int ExecuteSql(string sSql) CmdObject = new SqlCommand(sSql, ConnObject); try ConnObject.Open(); int i = CmdObject.ExecuteNonQuery(); return i; catch (Exception ex) throw new Exception(ex.Message); finally CmdObject.Dispose(); ConnObj

4、ect.Close(); /执行存在性查询SQL语句,如果不存在抛出异常 查找的值不存在 存在返回 id public string ExecuteSqlRead(string sSql) SqlDataReader myReader; CmdObject = new SqlCommand(sSql, ConnObject); try (); myReader = CmdObject.ExecuteReader(); if (myReader.Read() return myReader0.ToString(); else throw new Exception(查找的值不存在); catch

5、 (Exception ex) throw new Exception(ex.Message); finally CmdObject.Dispose();(); /执行返回数据集DataSet的语句,失败抛出异常 public DataSet ExecuteSqlDataSet(string sSql) DataSet dsTemp; try ConnObject.Open(); AdapterObject = new SqlDataAdapter(sSql, ConnObject); dsTemp = new DataSet(ds); AdapterObject.Fill(dsTemp);

6、return dsTemp; catch (Exception ex) throw new Exception(ex.Message); finally ConnObject.Close(); /执行返回一个数值的查询SQL语句,如果不存在那么抛出“值不存在异常 /如果存在那么抛出成功返回查询得到的值,出现其他异常值那么直接抛出异常 public string ExecuteSqlValue(string sSql) object oTemp; CmdObject = new SqlCommand(sSql, ConnObject); try ConnObject.Open(); oTemp

7、= CmdObject.ExecuteScalar(); if (object.Equals(oTemp, null) throw new Exception(值不存在); else return oTemp.ToString(); catch (Exception ex) throw new Exception(ex.Message); finally CmdObject.Dispose(); ConnObject.Close(); /执行返回任何类型的查询SQL语句,如果不存在那么抛出“值不存在异常 /如果存在那么抛出成功返回查询得到的值,出现其他异常值那么直接抛出异常 public ob

8、ject ExecuteSqlObject(string sSql) object oTemp; CmdObject = new SqlCommand(sSql, ConnObject); try ConnObject.Open(); oTemp = CmdObject.ExecuteScalar(); if (object.Equals(oTemp, null) throw new Exception(值不存在); else return oTemp; catch (Exception ex) throw new Exception(ex.Message); finally CmdObjec

9、t.Dispose(); ConnObject.Close(); public int ExecuteSqls(string Sqls) int iLen; SqlTransaction oSqlTrans; CmdObject = new SqlCommand(); iLen = Sqls.Length; try ConnObject.Open(); catch (Exception ex) throw new Exception(ex.Message); oSqlTrans = ConnObject.BeginTransaction(); try CmdObject.Connection

10、= ConnObject; CmdObject.Transaction = oSqlTrans; for (int i = 0; i iLen; i+) CmdObject.CommandText = Sqlsi; CmdObject.ExecuteNonQuery(); oSqlTrans.Commit(); return 1; catch (Exception ex) oSqlTrans.Rollback(); throw new Exception(ex.Message); finally CmdObject.Dispose(); ConnObject.Close(); /获取效劳器时间

11、 public DateTime getServerTime() return DateTime.Now; /获取随机数 public static string Number(int length) string result = ; System.Random random = new Random(); for (int i = 0; i length; i+) result += random.Next(10).ToString(); return result; /判断是否为数字 public bool isNumber(string s) int Flag = 0; char st

12、r = s.ToCharArray(); for (int i = 0; i 0) return true; else return false; 1.2用户操作类Userusing System;using System.Data;using System.Data.SqlClient;using System.Collections.Generic;using System.Linq;using System.Text;using System.EnterpriseServices;namespace HotelCOM public class UserClass:HotelClass p

13、rivate string _cUserID=N/A; private string _cName = N/A; private string _cPassword = N/A; private byte _nRolelLevel = 0; private string _cHotelState = N/A; private string _cHotelCity = N/A; private string _tDescription = N/A; public UserClass() /构造函数 public string CUserID get return _cUserID; set _c

14、UserID = value; public string CName get return _cName; set _cName = value; public string CPassword get return _cPassword; set _cPassword = value; public byte NRolelLevel get return _nRolelLevel; set _nRolelLevel = value; public string CHotelState get return _cHotelState; set _cHotelState = value; pu

15、blic string CHotelCity get return _cHotelCity; set _cHotelCity = value; public string TDescription get return _tDescription; set _tDescription = value; /用户登录 public string userLogin(string cUserID, string cPassword) string user = new string4; string LoginSQLstring = select * from Users where cUserID

16、 = + cUserID + and cPassword = + cPassword + ; SqlDataReader myReader; CmdObject = new SqlCommand(LoginSQLstring, ConnObject); try if(ConnObject.State = ConnectionState.Closed) ConnObject.Open(); myReader = CmdObject.ExecuteReader(); if (myReader.Read() user0 = myReader0.ToString(); user1 = myReader

17、3.ToString(); user2 = myReader4.ToString(); user3 = myReader5.ToString(); return user; else throw new Exception(用户或密码错误!); catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); /查看用户信息 /执行返回数据集DataTable的语句,

18、失败抛出异常 public DataTable SelectUser(string uName) DataTable tableTemp; try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); string sSql = ; if (uName.Equals(selectAllbyAdmin) sSql = select * from Users where nRolelLevel = 2; else if (uName.Equals(selectAllbyManager) sSql = select * f

19、rom Users where nRolelLevel = 3; else if (uName.Equals(selectUserIDbyAdmin) sSql = select cUserID from Users where nRolelLevel = 2; else if (uName.Equals(selectUserIDbyManager) sSql = select cUserID from Users where nRolelLevel = 3 and cHotelState = + CHotelState + and cHotelCity = + CHotelCity + ;

20、else if (uName.Equals(OneUser)/查询一条记录 sSql = select * from Users where cUserID = + this.CUserID + ; else sSql = select * from Users where (cUserID like % + uName + % or cName like % + uName + %) and nRolelLevel = 2; AdapterObject = new SqlDataAdapter(sSql, ConnObject); tableTemp = new DataTable(User

21、s); AdapterObject.Fill(tableTemp); return tableTemp; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) ConnObject.Close(); /判断用户是否存在 /执行存在性查询SQL语句,如果不存在抛出异常 查找的值不存在 存在返回 id public bool ValidateUserID(string cUserID) SqlDataReader myReader; str

22、ing sSql = select cUserID from Users where cUserID= + cUserID + ; CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); myReader = CmdObject.ExecuteReader(); if (myReader.Read() return false; else return true; catch (Exception ex) throw n

23、ew Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); /添加用戶信息 public bool AddUsers() string sSql = INSERT INTO Users VALUES ( + CUserID + , + CName + , + CPassword + , + NRolelLevel + , + CHotelState + , + CHotelCity + , + TDescriptio

24、n + ); CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); int i = CmdObject.ExecuteNonQuery(); if (i 0) return true; else return false; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionStat

25、e.Open) CmdObject.Dispose(); ConnObject.Close(); /删除用户信息 public bool DelUsers() string sSql = delete Users where cUserID = + CUserID + ; CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); int i = CmdObject.ExecuteNonQuery(); if (i 0) r

26、eturn true; else return false; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); /修改用户信息 public bool UpdateUsers() string sSql = update Users SET cName = + CName + ,cPassword = + CPassword + ,tDescripti

27、on = + TDescription + where cUserID = + CUserID + ; CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); int i = CmdObject.ExecuteNonQuery(); if (i 0) return true; else return false; catch (Exception ex) throw new Exception(ex.Message);

28、finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); 1.3酒店信息操作类using System;using System.Data;using System.Data.SqlClient;using System.Collections.Generic;using System.Linq;using System.Text;using System.EnterpriseServices;namespace HotelCOM public class Hote

29、lsClass:HotelClass private string _cHotel = N/A; private string _cUserID = N/A; private string _cHotelState = N/A; private string _cHotelCity = N/A; private string _tDescription = N/A; public HotelsClass() public string CHotel get return _cHotel; set _cHotel = value; public string CUserID get return

30、 _cUserID; set _cUserID = value; public string CHotelCity get return _cHotelCity; set _cHotelCity = value; public string CHotelState get return _cHotelState; set _cHotelState = value; public string TDescription get return _tDescription; set _tDescription = value; /验证酒店信息是否存在 public bool ValidateHote

31、l() SqlDataReader myReader = null; string sSql = select cHotel from Hotels where cUserID = + CUserID + and cHotelState = + CHotelState + and cHotelCity = + CHotelCity + ; CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); myReader = Cm

32、dObject.ExecuteReader(); if (myReader.Read() return false; else return true; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); /获取酒店信息 public DataTable getHotelInfo(string RowIndex) DataTable TempTable;

33、 try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); String sSql = ; if(RowIndex.Equals(0) sSql = select top(1) cHotel from Hotels order by cHotel desc; else if (RowIndex.Equals(00) sSql = select cHotel from Hotels where cUserID = + CUserID + ; else if (RowIndex.Equals(023) sSql =

34、select cHotel,cHotelState,cHotelCity from Hotels where cHotel = + CHotel + ; else if (RowIndex.Equals(01) sSql = select cHotel,cUserID from Hotels where cHotelState = + CHotelState + and cHotelCity = + CHotelCity + ; AdapterObject = new SqlDataAdapter(sSql ,ConnObject); TempTable = new DataTable(Hot

35、els); AdapterObject.Fill(TempTable); return TempTable; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) ConnObject.Close(); /添加酒店信息 public bool AddHotelInfo() string sSql = INSERT INTO Hotel.dbo.Hotels VALUES ( + CHotel + , + CUserID + , + CH

36、otelState + , + CHotelCity + , + TDescription + ); CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); int i = CmdObject.ExecuteNonQuery(); if (i 0) return true; else return false; catch (Exception ex) throw new Exception(ex.Message); f

37、inally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); 1.4房间类型操作类using System;using System.Data;usingqlClient;using System.Collections.Generic;using System.Linq;using System.Text;using System.EnterpriseServices;namespace HotelCOM public class RoomtypesClass:Hote

38、lClass private string _nRoomLevel = N/A; private string _cRoomType = N/A; private string _tDescription = N/A; private string _mRoomPrice = N/A; public RoomtypesClass() public string TDescription get return _tDescription; set _tDescription = value; public string CRoomType get return _cRoomType; set _

39、cRoomType = value; public string NRoomLevel get return _nRoomLevel; set _nRoomLevel = value; public string MRoomPrice get return _mRoomPrice; set _mRoomPrice = value; /获取房间等级信息 public DataTable getRoomTypesInfo(string RowIndex) DataTable TempTable; try if (ConnObject.State = ConnectionState.Closed)

40、ConnObject.Open(); String sSql = ; if (RowIndex.Equals(*) sSql = select * from RoomTypes; else if (RowIndex.Equals(*w) sSql = select * from RoomTypes where nRoomLevel = + NRoomLevel + ; else if (RowIndex.Equals(0) sSql = select top(1) nRoomLevel from RoomTypes order by nRoomLevel desc; AdapterObject

41、 = new SqlDataAdapter(sSql, ConnObject); TempTable = new DataTable(RoomTypes); AdapterObject.Fill(TempTable); return TempTable; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) ConnObject.Close(); /修改等级信息 public bool UpdateRoomTypes() string

42、sSql = update RoomTypes SET cRoomType = +CRoomType+, tDescription = + TDescription + , mRoomPrice = + MRoomPrice + where nRoomLevel = + NRoomLevel + ; CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); int i = CmdObject.ExecuteNonQuery

43、(); if (i 0) return true; else return false; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); /添加等级信息 public bool AddRoomTypes() string sSql = INSERT INTO RoomTypes VALUES ( + this.NRoomLevel + , + thi

44、s.CRoomType + , + TDescription + , + this.MRoomPrice + ); CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); int i = CmdObject.ExecuteNonQuery(); if (i 0) return true; else return false; catch (Exception ex) throw new Exception(ex.Mess

45、age); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); 1.5房间管理操作类using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;using System.EnterpriseServices;namespace HotelCOM public clas

46、s RoomCodesClass:HotelClass private string _cHotel = N/A; private string _nRoomCode = N/A; private byte _nRoomLevel = 0; private string _roomCodes; private int mysum = 0; private string _cRoomType = N/A; private string _tDescription = N/A; private string _mRoomPrice = N/A; public RoomCodesClass() pu

47、blic string MRoomPrice get return _mRoomPrice; set _mRoomPrice = value; public string TDescription get return _tDescription; set _tDescription = value; public string CRoomType get return _cRoomType; set _cRoomType = value; public string CHotel get return _cHotel; set _cHotel = value; public string N

48、RoomCode get return _nRoomCode; set _nRoomCode = value; public byte NRoomLevel get return _nRoomLevel; set _nRoomLevel = value; public string RoomCodes get return _roomCodes; set _roomCodes = value; public int Mysum get return mysum; set mysum = value; /添加房间信息 public bool AddRoomInfo(string n) strin

49、g sqls = ; try int x = 0; if (n.Equals(n) if (RoomCodes != null) for (int i = 0; i 0) return true; else return false; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); /验证房间信息是否存在 public bool ValidateRo

50、om() SqlDataReader myReader = null; string sSql = select top(1) nRoomCode from RoomCodes where cHotel = + CHotel + ; CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = ConnectionState.Closed) ConnObject.Open(); myReader = CmdObject.ExecuteReader(); if (myReader.Read() return fa

51、lse; else return true; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); /获取房间信息 public DataTable getRoomInfo(string RowIndex) DataTable TempTable; try if (ConnObject.State = ConnectionState.Closed) Con

52、nObject.Open(); String sSql = ; if (RowIndex.Equals(*w) sSql = select nRoomLevel,cRoomType,TypetDescription,mRoomPrice from RoomInfo where nRoomCode = + NRoomCode + ; else if (RowIndex.Equals(1w) sSql = select nRoomCode from RoomCodes where nRoomCode = + NRoomCode + ; else if (RowIndex.Equals(t0w) s

53、Sql = select top(1) nRoomCode from RoomCodes where cHotel = + CHotel + and nRoomLevel= + NRoomLevel + order by nRoomCode desc; else if (RowIndex.Equals(1ww) sSql = select nRoomCode from RoomCodes where cHotel = + CHotel + and nRoomLevel= + NRoomLevel + ; AdapterObject = new SqlDataAdapter(sSql, Conn

54、Object); TempTable = new DataTable(RoomCodes); AdapterObject.Fill(TempTable); return TempTable; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) ose(); /获取某种类型房间的数量 public int getTypeCount(int x) SqlDataReader myReader; string sSql = select C

55、OUNT(nRoomCode) from dbo.RoomCodes where cHotel = + CHotel + and nRoomLevel= + x + ; CmdObject = new SqlCommand(sSql, ConnObject); try ConnObject.Open(); myReader = CmdObject.ExecuteReader(); if (myReader.Read() return Convert.ToInt16(myReader0); else return 0; catch (Exception ex) throw new Excepti

56、on(ex.Message); finally CmdObject.Dispose(); ConnObject.Close(); /删除房间信息 public bool DelRoomCode(string n) string sSql = ; if (n.Equals(1w) sSql = delete RoomCodes where cHotel = + CHotel + and nRoomCode = + NRoomCode + ; CmdObject = new SqlCommand(sSql, ConnObject); try if (ConnObject.State = Conne

57、ctionState.Closed) ConnObject.Open(); int i = CmdObject.ExecuteNonQuery(); if (i 0) return true; else return false; catch (Exception ex) throw new Exception(ex.Message); finally if (ConnObject.State = ConnectionState.Open) CmdObject.Dispose(); ConnObject.Close(); 1.6酒店会员操作类using System;using System.

58、Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;using System.EnterpriseServices;namespace HotelCOM public class AssociatorsClass : HotelClass private string _cAssociator = N/A; private string _cID = N/A; private string _cName = N/A; private strin

59、g _cPassword = N/A; private string _dJoinTime = N/A; private string _nCardLevel = N/A; private string _nMarks = N/A; private string _nBalance = N/A; public string CAssociator get return _cAssociator; set _cAssociator = value; public string CID get return _cID; set _cID = value; public string CName g

60、et return _cName; set _cName = value; public string CPassword get return _cPassword; set _cPassword = value; public string DJoinTime get return _dJoinTime; set _dJoinTime = value; public string NCardLevel get return _nCardLevel; set _nCardLevel = value; public string NMarks get return _nMarks; set _

温馨提示

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

评论

0/150

提交评论