




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
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 /保存數(shù)據(jù)庫的連接字符串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); /執(zhí)行Sql語句,如 Update、Delete、Insert語句,成功返回影響行數(shù)據(jù) 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(); /執(zhí)行存在性查詢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();(); /執(zhí)行返回數(shù)據(jù)集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(); /執(zhí)行返回一個數(shù)值的查詢SQL語句,如果不存在那么拋出“值不存在異常 /如果存在那么拋出成功返回查詢得到的值,出現(xiàn)其他異常值那么直接拋出異常 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(); /執(zhí)行返回任何類型的查詢SQL語句,如果不存在那么拋出“值不存在異常 /如果存在那么拋出成功返回查詢得到的值,出現(xiàn)其他異常值那么直接拋出異常 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; /獲取隨機(jī)數(shù) 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; /判斷是否為數(shù)字 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() /構(gòu)造函數(shù) 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(); /查看用戶信息 /執(zhí)行返回數(shù)據(jù)集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(); /判斷用戶是否存在 /執(zhí)行存在性查詢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(); /獲取某種類型房間的數(shù)量 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 未來城市治理中的公共政策試題及答案
- 新手備考西方政治考試的建議試題及答案
- 機(jī)電工程分析工具試題及答案
- 機(jī)電工程英語學(xué)習(xí)的必要性及試題與答案
- 西方國家的民主監(jiān)督機(jī)制試題及答案
- 政治理念與西方教育體制的試題及答案
- 軟件測試中的用戶需求分析試題及答案
- 計算機(jī)三級軟件測試中的團(tuán)隊協(xié)作試題及答案
- 公共政策改革中的政治因素分析試題及答案
- 機(jī)電工程科學(xué)研究方法試題及答案
- 建設(shè)工程法規(guī)考試題真題及答案
- 中國鹽業(yè)集團(tuán)有限公司所屬企業(yè)招聘筆試題庫2025
- 2024年江蘇省泰興市事業(yè)單位公開招聘教師崗考試題帶答案分析
- Q-GDW 10393.1-2024 變電站設(shè)計規(guī)范-第1部分:35kV變電站
- (人教2024版)英語七下期末全冊分單元總復(fù)習(xí)課件(新教材)
- 2025年市場營銷專業(yè)人才考核試題及答案
- 防范惡劣天氣安全教育
- 第七章郵輪游客投訴心理及處理技巧46課件
- 深圳市住房公積金管理中心員額人員招聘真題2024
- 梅州市大埔縣客家圍屋小學(xué)-攜數(shù)同行靜待花開-二年級下冊數(shù)學(xué)家長會【課件】
- 耳鼻喉護(hù)理學(xué)試題及答案
評論
0/150
提交評論