Advertisement
Guest User

hellow cw

a guest
Apr 23rd, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 KB | None | 0 0
  1. namespace RoomBookingSystem
  2. {
  3. public partial class RoomBookingForm : Form
  4. {
  5. public RoomBookingForm()
  6. {
  7. InitializeComponent();
  8. }
  9.  
  10. private void RoomBookingForm_Load(object sender, EventArgs e)
  11. {
  12.  
  13. }
  14.  
  15. private void RoomBookingForm_FormClosing(object sender, FormClosingEventArgs e)
  16. {
  17. Application.Exit();
  18. }
  19.  
  20. private void BookRoomButton_Click(object sender, EventArgs e)
  21. {
  22. string Date = DateToBeBooked.Text;
  23. string Period = PeriodBooked.Text;
  24. string Email = EmailBookingRoom.Text;
  25. string Room = RoomBeingBooked.Text;
  26. string ExtraEquipment = ExtraEquipmentTextBox.Text;
  27. List<string> DatabaseDate = new List<string>();
  28. List<string> DatabasePeriod = new List<string>();
  29.  
  30. //Selects all date records from the bookings table so that they can be compared to eliminate double bookings.
  31. using (SqlConnection CompareDate = new SqlConnection("RoomBookingSystem"))
  32. {
  33. string SelectDate = "SELECT DateBooked FROM Bookings";
  34. using (SqlCommand GetDate = new SqlCommand(SelectDate, CompareDate))
  35. {
  36. using (SqlDataReader DateReader = GetDate.ExecuteReader())
  37. {
  38. while (DateReader.Read())
  39. {
  40. CompareDate.Open();
  41. DatabaseDate.Add(DateReader.GetString(0));
  42. }
  43. }
  44. }
  45. }
  46.  
  47. //Takes the date records from the bookings table in the database and puts them in a list
  48. if (DatabaseDate.Contains(Date))
  49. {
  50. using (SqlConnection ComparePeriod = new SqlConnection("RoomBookingSystem"))
  51. {
  52. string SelectPeriod = "SELECT PeriodBookedFor FROM Bookings";
  53. using (SqlCommand GetPeriod = new SqlCommand(SelectPeriod, ComparePeriod))
  54. {
  55. using (SqlDataReader DateReader = GetPeriod.ExecuteReader())
  56. {
  57. while (DateReader.Read())
  58. {
  59. ComparePeriod.Open();
  60. DatabasePeriod.Add(DateReader.GetString(0));
  61. }
  62. }
  63. }
  64. }
  65.  
  66. //If the list contains the period that the user is booking for on the same date, emails the user telling them the booking was a failure
  67. if (DatabasePeriod.Contains(Period))
  68. {
  69. MailMessage emailFailure = new MailMessage();
  70. SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
  71. emailFailure.From = new MailAddress("RoomBookingSystem@gmail.com");
  72. emailFailure.To.Add(Email);
  73. emailFailure.Subject = "Booking Failure";
  74. emailFailure.Body = "Your recent booking failed due to the room already being booked on the same date and the same time.";
  75.  
  76.  
  77. SmtpServer.Send(emailFailure);
  78. }
  79. else
  80. {
  81. //Because the period booking for was different but on the same date, the booking can go through and so the details are added
  82. using (SqlConnection connection = new SqlConnection("RoomBookingConnection"))
  83. {
  84. string SaveBooking = "INSERT INTO User(DateBooked, PeriodBooked) " + "Values('" + Date + "' , '" + Period + "')";
  85. using (SqlCommand command = new SqlCommand(SaveBooking, connection))
  86. {
  87. connection.Open();
  88. command.ExecuteNonQuery();
  89. }
  90. }
  91.  
  92. //Emails the user telling them that the booking was successful
  93. MailMessage emailSuccess = new MailMessage();
  94. SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
  95. emailSuccess.From = new MailAddress("RoomBookingSystem@gmail.com");
  96. emailSuccess.To.Add(Email);
  97. emailSuccess.Subject = "Booking Success";
  98. emailSuccess.Body = "Your recent booking was successful and has been added to the database.";
  99. SmtpServer.Send(emailSuccess);
  100.  
  101. //Emails the side team for extra equipment
  102. MailMessage emailSideTeam = new MailMessage();
  103. SmtpClient SmtpServer2 = new SmtpClient("smtp.gmail.com");
  104. emailSideTeam.From = new MailAddress("RoomBookingSystem@gmail.com");
  105. emailSideTeam.To.Add("sideteam@gmail.com");
  106. emailSideTeam.Subject = "Extra Equipment";
  107. emailSideTeam.Body = "The user has entered this as what they would like for extra equipment " + ExtraEquipment + " in the room " + Room + " by period " + Period + ", thank you.";
  108. SmtpServer2.Send(emailSideTeam);
  109.  
  110. }
  111. }
  112. else
  113. {
  114. //Adds booking details in to the database
  115. using (SqlConnection connection = new SqlConnection("RoomBookingConnection"))
  116. {
  117. string SaveBooking = "INSERT INTO User(DateBooked, PeriodBooked) " + "Values('" + Date + "' , '" + Period + "')";
  118. using (SqlCommand command = new SqlCommand(SaveBooking, connection))
  119. {
  120. connection.Open();
  121. command.ExecuteNonQuery();
  122. }
  123. }
  124.  
  125. //Emails the user telling them that the booking was successful
  126. MailMessage emailSuccess = new MailMessage();
  127. SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
  128. emailSuccess.From = new MailAddress("RoomBookingSystem@gmail.com");
  129. emailSuccess.To.Add(Email);
  130. emailSuccess.Subject = "Booking Success";
  131. emailSuccess.Body = "Your recent booking was successful and has been added to the database.";
  132. SmtpServer.Send(emailSuccess);
  133.  
  134. //Emails the side team for extra equipment
  135. MailMessage emailSideTeam = new MailMessage();
  136. SmtpClient SmtpServer2 = new SmtpClient("smtp.gmail.com");
  137. emailSideTeam.From = new MailAddress("RoomBookingSystem@gmail.com");
  138. emailSideTeam.To.Add("sideteam@gmail.com");
  139. emailSideTeam.Subject = "Extra Equipment";
  140. emailSideTeam.Body = "The user has entered this as what they would like for extra equipment " + ExtraEquipment + " in the room " + Room + " by period " + Period + ", thank you.";
  141. SmtpServer2.Send(emailSideTeam);
  142. }
  143. }
  144.  
  145. //Adds each line of the text file "Rooms" into the drop down box
  146. private void RoomBeingBooked_SelectedIndexChanged(object sender, EventArgs e)
  147. {
  148. string[] Rooms = File.ReadAllLines("Rooms.txt");
  149. foreach (var line in Rooms)
  150. {
  151. RoomBeingBooked.Items.Add(line);
  152. }
  153.  
  154. }
  155. }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement