Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Services;
  10.  
  11. [WebService(Namespace = "http://LaundryBookingWebService.org/")]
  12. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  13. [System.Web.Script.Services.ScriptService]
  14.  
  15.  
  16.  
  17. public class LaundryBookingWebService : System.Web.Services.WebService
  18. {
  19. public LaundryBookingWebService()
  20. {
  21. }
  22. private SqlConnection connection = new SqlConnection("Data Source=LAPTOP-5EDFEDTV\\WACKU;Initial Catalog=LaundryBookingApp;Integrated Security=True");
  23.  
  24. //--------GET Residents FROM SQL-DATABASE------------
  25.  
  26. [WebMethod(Description = "Returns Residents", EnableSession = true)]
  27. public DataSet GetResidents()
  28. {
  29. try
  30. {
  31. connection.Open();
  32. SqlDataAdapter adapter = new SqlDataAdapter("select * from Residents", connection);
  33. DataSet ResidentDS = new DataSet();
  34. adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  35. adapter.Fill(ResidentDS, "Residents");
  36.  
  37. connection.Close();
  38. return ResidentDS;
  39. }
  40. catch (Exception e)
  41. {
  42. return null;
  43. }
  44. }
  45. //--------GET Bookings FROM SQL-DATABASE------------
  46.  
  47. [WebMethod(Description = "Returns Bookings", EnableSession = true)]
  48. public DataSet GetBookings()
  49. {
  50. try
  51. {
  52. connection.Open();
  53. SqlDataAdapter adapter = new SqlDataAdapter("select * from Bookings", connection);
  54. DataSet BookingDS = new DataSet();
  55. adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  56. adapter.Fill(BookingDS, "Residents");
  57.  
  58. connection.Close();
  59. return BookingDS;
  60. }
  61. catch (Exception e)
  62. {
  63. return null;
  64. }
  65. }
  66. //--------GET LaundryRooms FROM SQL-DATABASE------------
  67.  
  68. [WebMethod(Description = "Returns LaundryRooms", EnableSession = true)]
  69. public DataSet GetLaundryRooms()
  70. {
  71. try
  72. {
  73. connection.Open();
  74. SqlDataAdapter adapter = new SqlDataAdapter("select * from LaundryRooms", connection);
  75. DataSet LaundryRoomDS = new DataSet();
  76. adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  77. adapter.Fill(LaundryRoomDS, "LaundryRooms");
  78.  
  79. connection.Close();
  80. return LaundryRoomDS;
  81. }
  82. catch (Exception e)
  83. {
  84. return null;
  85. }
  86. }
  87.  
  88. [WebMethod(Description = "Get file content", EnableSession = true)]
  89. public string ReadFile(string FileName)
  90. {
  91. try
  92. {
  93. string strdocPath;
  94. strdocPath = @"C:\Users\Jacob\Desktop\" + FileName;
  95. strdocPath += ".txt";
  96. string content = File.ReadAllText(strdocPath);
  97. return content;
  98. }
  99. catch (Exception e)
  100. {
  101. return e.ToString();
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement