Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

303 wiersze
10KB

  1. <%
  2. '=======================================================================================================================
  3. ' Contacts Model
  4. '=======================================================================================================================
  5. Class ContactsModel_Class
  6. Public Validator
  7. Public Class_Get_Properties
  8. Public ID '90
  9. Public JURISCODE '106
  10. Public TownshipName '106
  11. Public CONTACT_NAME '106
  12. Public TownshipNum '106
  13. Public BUSINESS_ADDRESS '106
  14. Public TITLE '106
  15. Public BUSINESS_ADDRESS2 '106
  16. Public BUSINESS_ADDRESS3 '106
  17. Public MAILING_ADDRESS '106
  18. Public MAILING_ADDRESS2 '106
  19. Public MAILING_ADDRESS3 '106
  20. Public RESIDENTIAL_ADDRESS '106
  21. Public RESIDENTIAL_ADDRESS2 '106
  22. Public PHONENUM1 '106
  23. Public RESIDENTIAL_ADDRESS3 '106
  24. Public FAXNUM '122
  25. Public PHONENUM2 '106
  26. Public EMAIL '106
  27. Private Sub Class_Initialize
  28. 'ValidateExitsts Me, "",""
  29. Class_Get_Properties = Array("ID, JURISCODE, TownshipName, CONTACT_NAME, TownshipNum, BUSINESS_ADDRESS, TITLE, BUSINESS_ADDRESS2, BUSINESS_ADDRESS3, MAILING_ADDRESS, MAILING_ADDRESS2, MAILING_ADDRESS3, RESIDENTIAL_ADDRESS, RESIDENTIAL_ADDRESS2, PHONENUM1, RESIDENTIAL_ADDRESS3, FAXNUM, PHONENUM2, EMAIL")
  30. End Sub
  31. End CLass
  32. '=======================================================================================================================
  33. ' Contacts Repository
  34. '=======================================================================================================================
  35. Class ContactsRepository_Class
  36. Public Function FindByID(ID)
  37. dim sql : sql = "Select [ID], [JURISCODE], [TownshipName], [CONTACT_NAME], [TownshipNum], [BUSINESS_ADDRESS], [TITLE], [BUSINESS_ADDRESS2], [BUSINESS_ADDRESS3], [MAILING_ADDRESS], [MAILING_ADDRESS2], [MAILING_ADDRESS3], [RESIDENTIAL_ADDRESS], [RESIDENTIAL_ADDRESS2], [PHONENUM1], [RESIDENTIAL_ADDRESS3], [FAXNUM], [PHONENUM2], [EMAIL] FROM [Contacts] WHERE ID = ?"
  38. dim rs : set rs = DAL.Query(sql,ID)
  39. If rs.EOF then
  40. Err.Raise 1, "ContactsRepository_Class", ContactsNotFoundException("ID", ID)
  41. Else
  42. set FindByID = Automapper.AutoMap(rs,"ContactsModel_Class")
  43. End If
  44. End Function
  45. Public Function GetAll(orderBy)
  46. set GetAll = Find(empty,orderBy)
  47. End Function
  48. Public Function Find(where_kvarray, order_string_or_array)
  49. dim sql : sql = "Select [ID], [JURISCODE], [TownshipName], [CONTACT_NAME], [TownshipNum], [BUSINESS_ADDRESS], [TITLE], [BUSINESS_ADDRESS2], [BUSINESS_ADDRESS3], [MAILING_ADDRESS], [MAILING_ADDRESS2], [MAILING_ADDRESS3], [RESIDENTIAL_ADDRESS], [RESIDENTIAL_ADDRESS2], [PHONENUM1], [RESIDENTIAL_ADDRESS3], [FAXNUM], [PHONENUM2], [EMAIL] FROM [Contacts]"
  50. If Not IsEmpty(where_kvarray) then
  51. sql = sql & " WHERE "
  52. dim where_keys, where_values
  53. KVUnzip where_kvarray, where_keys, where_values
  54. dim i
  55. For i = 0 to UBound(where_keys)
  56. If i > 0 then sql = sql & " AND "
  57. sql = sql & " " & where_keys(i) & " "
  58. Next
  59. End If
  60. If Not IsEmpty(order_string_or_array) then
  61. sql = sql & "ORDER BY "
  62. If IsArray(order_string_or_array) then
  63. dim order_array : order_array = order_string_or_array
  64. For i = 0 to UBound(order_array)
  65. If i > 0 then sql = sql & ", "
  66. sql = sql & " " & order_array(i)
  67. Next
  68. Else
  69. sql = sql & order_string_or_array & " "
  70. End If
  71. End If
  72. dim rs : set rs = DAL.Query(sql, where_values)
  73. set Find = ContactsList(rs)
  74. Destroy rs
  75. End Function
  76. Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  77. dim sql : sql = "Select [ID], [JURISCODE], [TownshipName], [CONTACT_NAME], [TownshipNum], [BUSINESS_ADDRESS], [TITLE], [BUSINESS_ADDRESS2], [BUSINESS_ADDRESS3], [MAILING_ADDRESS], [MAILING_ADDRESS2], [MAILING_ADDRESS3], [RESIDENTIAL_ADDRESS], [RESIDENTIAL_ADDRESS2], [PHONENUM1], [RESIDENTIAL_ADDRESS3], [FAXNUM], [PHONENUM2], [EMAIL] FROM [Contacts]"
  78. If Not IsEmpty(where_kvarray) then
  79. sql = sql & " WHERE "
  80. dim where_keys, where_values
  81. KVUnzip where_kvarray, where_keys, where_values
  82. dim i
  83. For i = 0 to UBound(where_keys)
  84. If i > 0 then sql = sql & " AND "
  85. sql = sql & " " & where_keys(i) & " "
  86. Next
  87. End If
  88. If Not IsEmpty(order_string_or_array) then
  89. sql = sql & "ORDER BY "
  90. If IsArray(order_string_or_array) then
  91. dim order_array : order_array = order_string_or_array
  92. For i = 0 to UBound(order_array)
  93. If i > 0 then sql = sql & ", "
  94. sql = sql & " " & order_array(i)
  95. Next
  96. Else
  97. sql = sql & order_string_or_array & " "
  98. End If
  99. End If
  100. dim list : set list = new LinkedList_Class
  101. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  102. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  103. rs.PageSize = per_page
  104. rs.AbsolutePage = page_num
  105. page_count = rs.PageCount
  106. record_count = rs.RecordCount
  107. End If
  108. set FindPaged = PagedContactsList(rs, per_page)
  109. Destroy rs
  110. End Function
  111. Public Function SearchTablePaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  112. dim sql : sql = "Select [ID], [JURISCODE], [TownshipName], [CONTACT_NAME], [TownshipNum], [BUSINESS_ADDRESS], [TITLE], [BUSINESS_ADDRESS2], [BUSINESS_ADDRESS3], [MAILING_ADDRESS], [MAILING_ADDRESS2], [MAILING_ADDRESS3], [RESIDENTIAL_ADDRESS], [RESIDENTIAL_ADDRESS2], [PHONENUM1], [RESIDENTIAL_ADDRESS3], [FAXNUM], [PHONENUM2], [EMAIL] FROM [Contacts]"
  113. If Not IsEmpty(where_kvarray) then
  114. sql = sql & " WHERE "
  115. dim where_keys, where_values
  116. KVUnzip where_kvarray, where_keys, where_values
  117. dim i
  118. For i = 0 to UBound(where_keys)
  119. If i > 0 then sql = sql & " OR"
  120. sql = sql & " " & where_keys(i) & " LIKE ?"
  121. Next
  122. End If
  123. If Not IsEmpty(order_string_or_array) then
  124. sql = sql & " ORDER BY "
  125. If IsArray(order_string_or_array) then
  126. dim order_array : order_array = order_string_or_array
  127. For i = 0 to UBound(order_array)
  128. If i > 0 then sql = sql & ", "
  129. sql = sql & " " & order_array(i)
  130. Next
  131. Else
  132. sql = sql & order_string_or_array & " "
  133. End If
  134. End If
  135. dim list : set list = new LinkedList_Class
  136. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  137. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  138. rs.PageSize = per_page
  139. rs.AbsolutePage = page_num
  140. page_count = rs.PageCount
  141. record_count = rs.RecordCount
  142. End If
  143. set SearchTablePaged = PagedContactsList(rs, per_page)
  144. Destroy rs
  145. End Function
  146. Private Function PagedContactsList(rs, per_page)
  147. dim list : set list = new LinkedList_Class
  148. dim x : x =0
  149. Do While x < per_page and Not rs.EOF
  150. list.Push Automapper.AutoMap(rs, new ContactsModel_Class)
  151. x = x +1
  152. rs.MoveNext
  153. Loop
  154. set PagedContactsList = list
  155. End Function
  156. Private Function ContactsNotFoundException(ByVal field_name, ByVal field_val)
  157. ContactsNotFoundException = "Contacts was not found with " & field_name & " of '" & field_val & "'."
  158. End Function
  159. Private Function ContactsList(rs)
  160. dim list : set list = new LinkedList_Class
  161. dim model
  162. Do until rs.EOF
  163. set model = new ContactsModel_Class
  164. list.Push Automapper.AutoMap(rs, model)
  165. rs.MoveNext
  166. Loop
  167. set ContactsList = list
  168. End Function
  169. Public Sub AddNew(ByRef model)
  170. dim sql : sql = "INSERT INTO [Contacts] (" &_
  171. "[JURISCODE]," &_
  172. "[TownshipName]," &_
  173. "[CONTACT_NAME]," &_
  174. "[TownshipNum]," &_
  175. "[BUSINESS_ADDRESS]," &_
  176. "[TITLE]," &_
  177. "[BUSINESS_ADDRESS2]," &_
  178. "[BUSINESS_ADDRESS3]," &_
  179. "[MAILING_ADDRESS]," &_
  180. "[MAILING_ADDRESS2]," &_
  181. "[MAILING_ADDRESS3]," &_
  182. "[RESIDENTIAL_ADDRESS]," &_
  183. "[RESIDENTIAL_ADDRESS2]," &_
  184. "[PHONENUM1]," &_
  185. "[RESIDENTIAL_ADDRESS3]," &_
  186. "[FAXNUM]," &_
  187. "[PHONENUM2]," &_
  188. "[EMAIL])" &_
  189. "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
  190. DAL.Execute sql, Array(model.JURISCODE, _
  191. model.TownshipName, _
  192. model.CONTACT_NAME, _
  193. model.TownshipNum, _
  194. model.BUSINESS_ADDRESS, _
  195. model.TITLE, _
  196. model.BUSINESS_ADDRESS2, _
  197. model.BUSINESS_ADDRESS3, _
  198. model.MAILING_ADDRESS, _
  199. model.MAILING_ADDRESS2, _
  200. model.MAILING_ADDRESS3, _
  201. model.RESIDENTIAL_ADDRESS, _
  202. model.RESIDENTIAL_ADDRESS2, _
  203. model.PHONENUM1, _
  204. model.RESIDENTIAL_ADDRESS3, _
  205. model.FAXNUM, _
  206. model.PHONENUM2, _
  207. model.EMAIL)
  208. sql = "SELECT TOP 1 ID FROM [Contacts] ORDER BY ID DESC"
  209. dim rs : set rs = DAL.Query(sql, empty)
  210. model.ID = rs("ID")
  211. Destroy rs
  212. End Sub
  213. Public Sub Update(model)
  214. dim sql : sql = "UPDATE [Contacts] SET [JURISCODE] = ?," &_
  215. "[TownshipName] = ?," &_
  216. "[CONTACT_NAME] = ?," &_
  217. "[TownshipNum] = ?," &_
  218. "[BUSINESS_ADDRESS] = ?," &_
  219. "[TITLE] = ?," &_
  220. "[BUSINESS_ADDRESS2] = ?," &_
  221. "[BUSINESS_ADDRESS3] = ?," &_
  222. "[MAILING_ADDRESS] = ?," &_
  223. "[MAILING_ADDRESS2] = ?," &_
  224. "[MAILING_ADDRESS3] = ?," &_
  225. "[RESIDENTIAL_ADDRESS] = ?," &_
  226. "[RESIDENTIAL_ADDRESS2] = ?," &_
  227. "[PHONENUM1] = ?," &_
  228. "[RESIDENTIAL_ADDRESS3] = ?," &_
  229. "[FAXNUM] = ?," &_
  230. "[PHONENUM2] = ?," &_
  231. "[EMAIL] = ?" &_
  232. " WHERE [ID] = ?"
  233. DAL.Execute sql, Array(model.JURISCODE, _
  234. model.TownshipName, _
  235. model.CONTACT_NAME, _
  236. model.TownshipNum, _
  237. model.BUSINESS_ADDRESS, _
  238. model.TITLE, _
  239. model.BUSINESS_ADDRESS2, _
  240. model.BUSINESS_ADDRESS3, _
  241. model.MAILING_ADDRESS, _
  242. model.MAILING_ADDRESS2, _
  243. model.MAILING_ADDRESS3, _
  244. model.RESIDENTIAL_ADDRESS, _
  245. model.RESIDENTIAL_ADDRESS2, _
  246. model.PHONENUM1, _
  247. model.RESIDENTIAL_ADDRESS3, _
  248. model.FAXNUM, _
  249. model.PHONENUM2, _
  250. model.EMAIL, _
  251. model.ID)
  252. End Sub
  253. Public Sub Delete(id)
  254. dim sql : sql = "DELETE FROM [Contacts] WHERE [ID] = ?"
  255. DAL.Execute sql, id
  256. End Sub
  257. End Class
  258. dim ContactsRepository__Singleton
  259. Function ContactsRepository()
  260. If IsEmpty(ContactsRepository__Singleton) then
  261. set ContactsRepository__Singleton = new ContactsRepository_Class
  262. End If
  263. set ContactsRepository = ContactsRepository__Singleton
  264. End Function
  265. %>

Powered by TurnKey Linux.