DAL_Hotel.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. namespace DAL
  7. {
  8. public class DAL_Hotel
  9. {
  10. //操作员登录
  11. public static DataTable OPlogin(string name, string pwd) {
  12. string sql = "select * from OPinfo where Oname='"+name+"' and pwd='"+pwd+"'";
  13. return DBHelper.Query(sql);
  14. }
  15. //用户登录
  16. public static DataTable UserLogin(string name, string pwd) {
  17. string sql = "select * from UserInfo where Uname='"+name+"' and upwd='"+pwd+"'";
  18. return DBHelper.Query(sql);
  19. }
  20. //入住/预定信息查询
  21. public static DataTable LiveMark(string table) {
  22. string idd="";
  23. if (table == "record")
  24. {
  25. idd = "Reid";
  26. }
  27. else {
  28. idd = "yid";
  29. }
  30. string sql = "select * from " + table + " ,guestinfo,Roominfo where " + table + ".gid=guestinfo.gid and roominfo.roomid =" + table + ".roomid order by "+idd+" desc";
  31. return DBHelper.Query(sql);
  32. }
  33. //入住/预定信息查询(分页)
  34. public static DataTable LiveMark(string table,int ye)
  35. {
  36. string idd = "";
  37. if (table == "record")
  38. {
  39. idd = "Reid";
  40. }
  41. else
  42. {
  43. idd = "yid";
  44. }
  45. string sql = "select top 10 * from " + table + " ,guestinfo,Roominfo where " + table + ".gid=guestinfo.gid and roominfo.roomid =" + table + ".roomid and "+idd+" not in (select top " + (ye - 1) * 10 + " "+idd+" from " + table + " order by "+idd+" desc) order by " + idd + " desc";
  46. return DBHelper.Query(sql);
  47. }
  48. //删除入住信息表
  49. public static int DelRecord(int idd) {
  50. string sql = "delete from record where reid="+idd;
  51. return DBHelper.Modify(sql);
  52. }
  53. //查询所有顾客信息
  54. public static DataTable ChaCus() {
  55. string sql = "select * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid";
  56. return DBHelper.Query(sql);
  57. }
  58. //图标方式展示房间信息
  59. public static DataTable imgtable(){
  60. string sql = "select * from RoomInfo,RoomState,FloorInfo,RoomType where RoomState.Stateid=Roominfo.Rsid and RoomInfo.FId=FloorInfo.fid and RoomInfo.RTid=RoomType.Rtid";
  61. return DBHelper.Query(sql);
  62. }
  63. //只查看单独类型的房间
  64. public static DataTable image_TableType(int type)
  65. {
  66. string sql = "select top 36 * from RoomInfo,RoomState,FloorInfo,RoomType where RoomState.Stateid=Roominfo.Rsid and RoomInfo.FId=FloorInfo.fid and RoomInfo.RTid=RoomType.Rtid and roominfo.RTid=" + type;
  67. return DBHelper.Query(sql);
  68. }
  69. //图标方式展示房间信息(分页)
  70. public static DataTable imgtable(int ye)
  71. {
  72. string sql = "select top 36 * from RoomInfo,RoomState,FloorInfo,RoomType where RoomState.Stateid=Roominfo.Rsid and RoomInfo.FId=FloorInfo.fid and RoomInfo.RTid=RoomType.Rtid and roomid not in(select top " + (ye - 1) * 36 + " roomid from roominfo) order by roomid asc";
  73. return DBHelper.Query(sql);
  74. }
  75. //根据顾客编号查询信息
  76. public static DataTable Cha_Gid(string gid,string table) {
  77. string sql = "select * from " + table + " ,guestinfo,Roominfo where " + table + ".gid=guestinfo.gid and roominfo.roomid =" + table + ".roomid and " + table + ".gid like'%" + gid + "%'";
  78. return DBHelper.Query(sql);
  79. }
  80. //根据房间编号查询信息
  81. public static DataTable Cha_Roomid(string roomid,string table)
  82. {
  83. string sql = "select * from " + table + " ,guestinfo,Roominfo where " + table + ".gid=guestinfo.gid and roominfo.roomid =" + table + ".roomid and number like'%" + roomid + "%'";
  84. return DBHelper.Query(sql);
  85. }
  86. //根据顾客姓名查询信息
  87. public static DataTable Cha_Gname(string gname,string table)
  88. {
  89. string sql = "select * from " + table + " ,guestinfo,Roominfo where " + table + ".gid=guestinfo.gid and roominfo.roomid =" + table + ".roomid and gname like '%" + gname + "%'";
  90. return DBHelper.Query(sql);
  91. }
  92. //根据身份证号查询信息
  93. public static DataTable Cha_Idcard(string idcard,string table)
  94. {
  95. string sql = "select * from " + table + " ,guestinfo,Roominfo where " + table + ".gid=guestinfo.gid and roominfo.roomid =" + table + ".roomid and pid like'%" + idcard + "%'";
  96. return DBHelper.Query(sql);
  97. }
  98. //根据手机号查询信息
  99. public static DataTable Cha_Tel(string tel,string table)
  100. {
  101. string sql = "select * from "+table+" ,guestinfo,Roominfo where "+table+".gid=guestinfo.gid and roominfo.roomid ="+table+".roomid and mobile like '%" + tel + "%'";
  102. return DBHelper.Query(sql);
  103. }
  104. //根据入住时间查询信息
  105. public static DataTable Cha_LiveTime(string livetime,string table)
  106. {
  107. string sql = "select * from "+table+" ,guestinfo,Roominfo where "+table+".gid=guestinfo.gid and roominfo.roomid ="+table+".roomid and Convert(varchar,intime,120) like '%"+ livetime + "%'";
  108. return DBHelper.Query(sql);
  109. }
  110. //根据单独id查询房间状态信息
  111. public static DataTable Cha_One(int idd) {
  112. string sql = "select * from RoomInfo,RoomState,FloorInfo,RoomType where RoomState.Stateid=Roominfo.Rsid and RoomInfo.FId=FloorInfo.fid and RoomInfo.RTid=RoomType.Rtid and roomid=" + idd;
  113. return DBHelper.Query(sql);
  114. }
  115. //绑定房间类型
  116. public static DataTable bind_roomtype() {
  117. string sql = "select * from RoomType";
  118. return DBHelper.Query(sql);
  119. }
  120. //根据房间类型绑定未入住的房间编号
  121. public static DataTable bind_roominfo(int typeid)
  122. {
  123. string sql = "select * from roominfo where rtid="+typeid+" and rsid=3";
  124. return DBHelper.Query(sql);
  125. }
  126. //根据顾客编号查询该顾客的个人信息
  127. public static DataTable Cha_Guestinfo(int idd) {
  128. string sql = "select * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and gid =" + idd;
  129. return DBHelper.Query(sql);
  130. }
  131. //入住登记(入住信息表插入数据)
  132. public static int Add_Record(int gid,int roomid,DateTime intime,DateTime outtime,int day, double charge) {
  133. string sql = string.Format("insert into record values({0},{1},'{2}','{3}',default,{4},{5})",gid,roomid,intime,outtime,day,charge);
  134. return DBHelper.Modify(sql);
  135. }
  136. //修改房间状态
  137. public static int Gai_roomstate(int roomid,int roomtype) {
  138. string sql = "update roominfo set rsid="+roomtype+" where roomid ="+roomid;
  139. return DBHelper.Modify(sql);
  140. }
  141. //根据记录编号查询入住信息
  142. public static DataTable Cha_OneRecord(int roomid) {
  143. string sql = "select * from record,guestinfo,roominfo,guesttype,FloorInfo,roomtype where guestinfo.gid=record.gid and roominfo. roomid=record.roomid and record.roomid=" + roomid + " and guestinfo.gtid=guesttype.gtid and FloorInfo.fid=RoomInfo.fid and roomtype.rtid=roominfo.rtid and(rsid=2 or rsid = 1) and facttime='暂未离开'";
  144. return DBHelper.Query(sql);
  145. }
  146. //计算入住的天数
  147. public static DataTable Cha_DayNum(DateTime dt) {
  148. string sql = "select datediff(day,'"+dt+"',getdate()) 'daynum'";
  149. return DBHelper.Query(sql);
  150. }
  151. //查询即将到期的客房
  152. public static DataTable Cha_OutDay() {
  153. string sql = "select * ,(outtime-getdate())'day'from record,roominfo where record.roomid=roominfo.roomid and facttime = '暂未离开' order by day asc";
  154. return DBHelper.Query(sql);
  155. }
  156. //退房时修改入住信息表
  157. public static int Gai_Record(string facttime,int factnum,double charge,int reid){
  158. string sql = string.Format("update record set facttime='{0}',daynum={1},charge={2} where reid ={3}",facttime,factnum,charge,reid);
  159. return DBHelper.Modify(sql);
  160. }
  161. //顾客消费金额更新
  162. public static int Gai_GuestChargeSum(int gid,double charge) {
  163. string sql = "update Guestinfo set chargesum=chargesum+"+charge+" where gid="+gid;
  164. return DBHelper.Modify(sql);
  165. }
  166. //更新交易额统计表
  167. public static int Gai_TradeCount(double money) {
  168. string sql = "insert into ChargeCount values(getdate(),"+money+")";
  169. return DBHelper.Modify(sql);
  170. }
  171. //查询销售额
  172. public static DataTable Cha_Charge(int day) {
  173. string sql = "select sum(charge) from chargecount where (select datediff(day,date,getdate()))<="+day;
  174. return DBHelper.Query(sql);
  175. }
  176. //用户房间续费该表
  177. public static int Gai_AddDay(DateTime intime, DateTime outtime, int addday, int charge, int roomid)
  178. {
  179. string sql =string.Format("update record set intime='{0}',outtime='{1}',daynum=daynum+{2},charge=charge+{3} where roomid={4} and facttime='暂未离开'",intime,outtime,addday,charge,roomid);
  180. return DBHelper.Modify(sql);
  181. }
  182. //换房原因绑定
  183. public static DataTable Cha_TranHome() {
  184. string sql = "select * from Trans";
  185. return DBHelper.Query(sql);
  186. }
  187. //换房维修费用查询
  188. public static DataTable Cha_Transmoney(int idd) {
  189. string sql = "select * from Trans where transid="+idd;
  190. return DBHelper.Query(sql);
  191. }
  192. //绑定顾客等级
  193. public static DataTable bind_GuestTname() {
  194. string sql = "select * from Guesttype";
  195. return DBHelper.Query(sql);
  196. }
  197. //新增顾客信息
  198. public static int Add_GuestInfo(string name,int type,string sex,string mobile, int chargesum,string pid) {
  199. string sql = string.Format("insert into Guestinfo values('{0}',{1},'{2}','{3}',{4},'{5}')",name,type,sex, mobile,chargesum,pid);
  200. return DBHelper.Modify(sql);
  201. }
  202. //修改管理员密码
  203. public static int Gai_OPPwd(string opname, string pwd) {
  204. string sql = "update OPInfo set pwd='"+pwd+"' where oname='"+opname+"'";
  205. return DBHelper.Modify(sql);
  206. }
  207. //根据顾客编号查询顾客信息
  208. public static DataTable Cha_GuestInfoByGid(int idd) {
  209. string sql = "select * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and gid like '%" + idd + "%'";
  210. return DBHelper.Query(sql);
  211. }
  212. //根据顾客编号查询顾客信息(分页)
  213. public static DataTable Cha_GuestInfoByGid(int idd,int ye)
  214. {
  215. string sql = "select top 6 * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and gid like '%" + idd + "%'and gid not in (select top " + (ye - 1) * 6 + " gid from guestinfo where gid like '%" + idd + "%' )";
  216. return DBHelper.Query(sql);
  217. }
  218. //根据顾客身份证号查询顾客信息
  219. public static DataTable Cha_GuestInfoByPid(string pid)
  220. {
  221. string sql = "select * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and pid like '%" + pid + "%'";
  222. return DBHelper.Query(sql);
  223. }
  224. //根据顾客身份证号查询顾客信息(分页)
  225. public static DataTable Cha_GuestInfoByPid(string pid,int ye)
  226. {
  227. string sql = "select top 6 * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and pid like '%" + pid + "%'and gid not in (select top " + (ye - 1) * 6 + " gid from guestinfo where pid like '%" + pid + "%' )";
  228. return DBHelper.Query(sql);
  229. }
  230. //根据顾客手机号查询顾客信息
  231. public static DataTable Cha_GuestInfoByMobile(string mobile)
  232. {
  233. string sql = "select * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and mobile like '%" + mobile + "%'";
  234. return DBHelper.Query(sql);
  235. }
  236. //根据顾客手机号查询顾客信息(分页)
  237. public static DataTable Cha_GuestInfoByMobile(string mobile,int ye)
  238. {
  239. string sql = "select top 6 * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and mobile like '%" + mobile + "%'and gid not in (select top " + (ye - 1) * 6 + " gid from guestinfo where Mobile like '%" + mobile + "%' )";
  240. return DBHelper.Query(sql);
  241. }
  242. //根据顾客姓名查询顾客信息
  243. public static DataTable Cha_GuestInfoByGname(string gname)
  244. {
  245. string sql = "select * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and Gname like '%" + gname + "%'";
  246. return DBHelper.Query(sql);
  247. }
  248. //根据顾客姓名查询顾客信息(分页)
  249. public static DataTable Cha_GuestInfoByGname(string gname,int ye)
  250. {
  251. string sql = "select top 6 * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and Gname like '%" + gname + "%'and gid not in (select top " + (ye - 1) * 6 + " gid from guestinfo where Gname like '%" + gname + "%' )";
  252. return DBHelper.Query(sql);
  253. }
  254. //查出指定年份的销售额
  255. public static DataTable Cha_YearChargeCount(int year) {
  256. string sql = "select month(date),sum(charge) from chargecount where year(date)='"+year+"' group by month(date)";
  257. return DBHelper.Query(sql);
  258. }
  259. //查询指定月份的销售额
  260. public static DataTable Cha_MonthChargeCount(int month,int year) {
  261. string sql = "select month(date),sum(charge) from chargecount where year(date)='"+year+"' and month(date)='"+month+"' group by month(date)";
  262. return DBHelper.Query(sql);
  263. }
  264. //DropDwonList绑定年份
  265. public static DataTable Bind_DropDwonListBindYear() {
  266. string sql = "select year(date) 'year' from chargecount group by year(date) order by year(date) desc";
  267. return DBHelper.Query(sql);
  268. }
  269. //查询最近三年的收益总额
  270. public static DataTable Cha_ThreeChargeCount(int year) {
  271. string sql = "select year(date) 'years',sum(charge)from chargecount group by year(date) having year(date) between " + (year - 2) + " and " +year;
  272. return DBHelper.Query(sql);
  273. }
  274. //客户信息表分页
  275. public static DataTable Cha_CusFenYe(int ye) {
  276. string sql = "select top 6 * from GuestInfo,GuestType where GuestType.GTid=GuestInfo.GTid and Gid not in (select top " + (ye - 1) * 6 + " gid from GuestInfo) order by gid desc";
  277. return DBHelper.Query(sql);
  278. }
  279. //查看楼层信息
  280. public static DataTable Bind_LouCeng() {
  281. string sql = "select * from FloorInfo";
  282. return DBHelper.Query(sql);
  283. }
  284. //新增房间
  285. public static int Add_Room(string name,int fid,string mark,int roomid) {
  286. string sql = string.Format("update roominfo set number='{0}',fid={1},rsid=3,mark='{2}' where roomid={3}",name,fid,mark,roomid);
  287. return DBHelper.Modify(sql);
  288. }
  289. //入住预定(预定信息表插入数据)
  290. public static int Add_Reserve(int gid, int roomid, DateTime intime, DateTime outtime, int day, double charge,double actcharge)
  291. {
  292. string sql = string.Format("insert into Reserve values({0},{1},'{2}','{3}',default,{4},{5},{6})", gid, roomid, intime, outtime, day, charge,actcharge);
  293. return DBHelper.Modify(sql);
  294. }
  295. //根据房间编号查询预约信息
  296. public static DataTable Cha_OneReserve(int roomid)
  297. {
  298. string sql = "select * from reserve,guestinfo,roominfo,guesttype,FloorInfo,roomtype where guestinfo.gid=reserve.gid and roominfo. roomid=reserve.roomid and reserve.roomid= "+roomid+" and guestinfo.gtid=guesttype.gtid and FloorInfo.fid=RoomInfo.fid and roomtype.rtid=roominfo.rtid and(rsid=2 or rsid = 1) and facttime='暂未入住'";
  299. return DBHelper.Query(sql);
  300. }
  301. //取消房间预约
  302. public static int Qu_Reserve(int roomid,string state) {
  303. string sql = "update reserve set facttime='"+state+"' where roomid="+roomid+" and facttime='暂未入住'";
  304. return DBHelper.Modify(sql);
  305. }
  306. //删除预约信息表
  307. public static int DelReserve(int idd)
  308. {
  309. string sql = "delete from reserve where yid=" + idd;
  310. return DBHelper.Modify(sql);
  311. }
  312. //修改顾客信息
  313. public static int ChangeGuestInfo(string name, int GTid, string sex, string mobile, int chargesum, string pid, int gid) {
  314. string sql = string.Format("update GuestInfo set gname='{0}',Gtid={1},Sex='{2}',mobile='{3}',Chargesum='{4}',pid='{5}' where gid={6}",name,GTid,sex,mobile,chargesum,pid,gid);
  315. return DBHelper.Modify(sql);
  316. }
  317. //删除顾客
  318. public static int Del_GuestInfo(int gid) {
  319. string sql = "delete from Guestinfo where gid="+gid;
  320. return DBHelper.Modify(sql);
  321. }
  322. //顾客升级
  323. public static int UpdateGuest(int gid) {
  324. string sql = "update Guestinfo set Gtid=Gtid+1 where gid="+gid;
  325. return DBHelper.Modify(sql);
  326. }
  327. }
  328. }