Advertisement
Guest User

Reserfy App - Reservation System SourceCode

a guest
Oct 25th, 2017
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 155.30 KB | None | 0 0
  1. Public Class About
  2.  
  3. End Class
  4. Public Class accounts
  5.  
  6. End Class
  7. Public Class Account
  8. Private Sub b_UpdateProfile_Click(sender As Object, e As RoutedEventArgs) Handles b_UpdateProfile.Click
  9.  
  10. End Sub
  11. End Class
  12. Class Application
  13.  
  14. ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
  15. ' can be handled in this file.
  16.  
  17. End Class
  18. Imports System.Data
  19. Imports System.Data.SQLite
  20. Imports System.Windows.Forms
  21. Imports MySql.Data.MySqlClient
  22.  
  23. Public Class Breifcase
  24.  
  25. Private Sub onLoad() Handles Me.Loaded
  26. daemon()
  27. End Sub
  28.  
  29. Private Async Sub daemon()
  30. onloadDataGrid()
  31. Await Delay(2)
  32. daemon()
  33. End Sub
  34.  
  35. 'dataGrid
  36. Private Sub onloadDataGrid()
  37. dgv.Children.Clear()
  38. Dim Connector As New SQLConnector
  39. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  40. Dim sqli As MySqlConnection = Connector.ConnectDB(True)
  41. Try
  42. Dim cmd1 As New MySqlCommand("Select (Select type from student_user Union all select type from employee_user ),reservation.reservation_name, reservation.id_number, reservation.room_id, reservation.start_time, reservation.end_time, users.first_name, users.mid_name, users.last_name, room.room_type_id, room_type.description From (((reservation inner join users on reservation.id_number = users.id_number) inner join room on room.room_id = reservation.room_id) inner join room_type on room_type.room_type_id = room.room_type_id) ", sqli)
  43. Dim id As MySqlDataReader = cmd1.ExecuteReader()
  44. While id.Read()
  45. Dim dg As New gridData
  46. dg.eventname.Content = id("reservation_name").ToString
  47. dg.room.Content = id("description").ToString
  48. dg.username.Content = id("first_name").ToString & " " & id("mid_name") & " " & id("last_name")
  49. dg.usertype.Content = id("(Select type from student_user Union all select type from employee_user )").ToString
  50. dg.date.Content = CDate(id("start_time")).ToShortDateString
  51. dg.startime.Content = id("start_time")
  52. dg.endtime.Content = id("end_time")
  53. dgv.Children.Add(dg)
  54. End While
  55. id.Close()
  56. cmd1 = Nothing
  57. Catch ex As Exception
  58. MainWindow.Instance.MainSnackBar("Opps, Something went wrong. Try again", 3)
  59. ex = Nothing
  60. Finally
  61. sqli.Close()
  62. sqli.Dispose()
  63. sqli = Nothing
  64. End Try
  65. Else
  66. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  67. Try
  68. Dim cmd1 As New SQLiteCommand("Select (Select type from student_user Union all select type from employee_user ),reservation.reservation_name, reservation.id_number, reservation.room_id, reservation.start_time, reservation.end_time, users.first_name, users.mid_name, users.last_name, room.room_type_id, room_type.description From (((reservation inner join users on reservation.id_number = users.id_number) inner join room on room.room_id = reservation.room_id) inner join room_type on room_type.room_type_id = room.room_type_id) ", sqli)
  69. Dim id As SQLiteDataReader = cmd1.ExecuteReader()
  70. Dim dgy As New gridData
  71. dgy.eventname.Content = "Event Name"
  72. dgy.room.Content = "Room Name"
  73. dgy.username.Content = "Name of User"
  74. dgy.usertype.Content = "Type of User"
  75. dgy.date.Content = "Reservation Date"
  76. dgy.startime.Content = "Start Time"
  77. dgy.endtime.Content = "End Time"
  78. dgv.Children.Add(dgy)
  79. While id.Read()
  80. Dim dg As New gridData
  81. dg.eventname.Content = id("reservation_name").ToString
  82. dg.room.Content = id("description").ToString
  83. dg.username.Content = id("first_name").ToString & " " & id("mid_name") & " " & id("last_name")
  84. dg.usertype.Content = id("(Select type from student_user Union all select type from employee_user )").ToString
  85. dg.date.Content = CDate(id("start_time")).ToShortDateString
  86. dg.startime.Content = id("start_time")
  87. dg.endtime.Content = id("end_time")
  88. dgv.Children.Add(dg)
  89. End While
  90. id.Close()
  91. cmd1 = Nothing
  92. Catch ex As Exception
  93. MainWindow.Instance.MainSnackBar("Opps, Something went wrong. Try again", 3)
  94. ex = Nothing
  95. Finally
  96. sqli.Close()
  97. sqli.Dispose()
  98. sqli = Nothing
  99. End Try
  100. End If
  101. End Sub
  102.  
  103.  
  104.  
  105.  
  106. End Class
  107. Imports System.Data.SQLite
  108. Imports MySql.Data.MySqlClient
  109.  
  110. Namespace cldr
  111.  
  112. Partial Public Class Calendar
  113. Private _myReservationsList As New List(Of Reservation)
  114.  
  115. Public n As New NewAppointmentEventArgs()
  116.  
  117. #Region "Data Validation"
  118. Partial Public Class Calendar
  119. Inherits UserControl
  120.  
  121. End Class
  122.  
  123. Private _errors As Integer = 0
  124. Private _reservationData As New ReservationData()
  125. Private _userData As New UserInfo()
  126. Private _userTypeData As New UserType()
  127.  
  128. Public Sub New()
  129. InitializeComponent()
  130. reservation_context.DataContext = _reservationData
  131. userinfo_context.DataContext = _userData
  132. 'User Type
  133. usertype_context.DataContext = _userTypeData
  134. position.DataContext = _userTypeData
  135. rank.DataContext = _userTypeData
  136. college.DataContext = _userTypeData
  137. track.DataContext = _userTypeData
  138. grade.DataContext = _userTypeData
  139. End Sub
  140.  
  141. Private Sub Confirm_CanExecute(sender As Object, e As CanExecuteRoutedEventArgs)
  142. e.CanExecute = _errors = 0
  143. e.Handled = True
  144. End Sub
  145.  
  146. Private Sub Confirm_Executed(sender As Object, e As ExecutedRoutedEventArgs)
  147. _reservationData = New ReservationData()
  148. _userData = New UserInfo()
  149. _userTypeData = New UserType()
  150.  
  151. reservation_context.DataContext = _reservationData
  152. userinfo_context.DataContext = _userData
  153. 'User Type
  154. usertype_context.DataContext = _userTypeData
  155. position.DataContext = _userTypeData
  156. rank.DataContext = _userTypeData
  157. college.DataContext = _userTypeData
  158. track.DataContext = _userTypeData
  159. grade.DataContext = _userTypeData
  160. e.Handled = True
  161. End Sub
  162.  
  163. Private Sub Validation_Error(sender As Object, e As ValidationErrorEventArgs)
  164. If e.Action = ValidationErrorEventAction.Added Then
  165. _errors += 1
  166. Else
  167. _errors -= 1
  168. End If
  169. End Sub
  170.  
  171.  
  172. #End Region
  173.  
  174. Public Sub onLoad() Handles Me.Loaded
  175. onLoadReservation()
  176. End Sub
  177.  
  178. Private Sub b_save_Click(sender As Object, e As RoutedEventArgs)
  179. 'Todo validation
  180. saveUserInfo()
  181. saveReservation()
  182. End Sub
  183.  
  184.  
  185. Private Sub DayBoxClicked_event(ByVal e As NewAppointmentEventArgs) Handles Reservation_Calendar.DayBoxClicked
  186. Add_Reservation.IsOpen = True
  187. Add_Reservation.Tag = e.TagID
  188. retrieveData()
  189. roomListRefresh()
  190. dp_date.IsEnabled = False
  191. dp_date.Text = CDate(e.StartDate)
  192. l_date.Content = Microsoft.VisualBasic.MonthName(CDate(e.StartDate).Month) & " " & CDate(e.StartDate).Day & ", " & CDate(e.StartDate).Year
  193. n = e
  194. End Sub
  195.  
  196. Private Sub roomListRefresh()
  197. cb_room_name.Items.Clear()
  198. Dim Connector As New SQLConnector()
  199. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  200. Try
  201. Dim sqli As MySqlConnection = Connector.ConnectDB(True)
  202. Dim rmd As New MySqlCommand("SELECT * From room", sqli)
  203. Dim dr As MySqlDataReader = rmd.ExecuteReader()
  204. While dr.Read()
  205. Dim rmd1 As New MySqlCommand("SELECT * From room_type Where room_type_id =" & dr("room_type_id").ToString, sqli)
  206. Dim dr1 As MySqlDataReader = rmd1.ExecuteReader()
  207. While dr1.Read
  208. cb_room_name.Items.Add(dr1("description").ToString)
  209. End While
  210. End While
  211. Catch ex As MySQLException
  212. MainWindow.Instance.MainSnackBar("Refresh Failed", 3)
  213. Catch ex As Exception
  214. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  215. End Try
  216. Else
  217. Try
  218. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  219. Dim rmd As New SQLiteCommand("SELECT * From room", sqli)
  220. Dim dr As SQLiteDataReader = rmd.ExecuteReader()
  221. While dr.Read()
  222. Dim rmd1 As New SQLiteCommand("SELECT * From room_type Where room_type_id =" & dr("room_type_id").ToString, sqli)
  223. Dim dr1 As SQLiteDataReader = rmd1.ExecuteReader()
  224. While dr1.Read
  225. cb_room_name.Items.Add(dr1("description").ToString)
  226. End While
  227. End While
  228. Catch ex As SQLiteException
  229. MainWindow.Instance.MainSnackBar("Refresh Failed", 3)
  230. Catch ex As Exception
  231. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  232. End Try
  233. End If
  234. End Sub
  235.  
  236. Private Sub AppointmentDblClicked(ByVal Appointment_Id As Integer) Handles Reservation_Calendar.ReservationClickedEvent
  237. MessageBox.Show("You Clicked a reservation ID = " & Appointment_Id, "Calendar Event", MessageBoxButton.OK)
  238. End Sub
  239.  
  240. Private Sub AddReservation(ByVal e As NewAppointmentEventArgs)
  241. Dim apt As New Reservation()
  242. apt.ReservationID = e.TagID
  243. apt.StartTime = CDate(e.StartDate)
  244. apt.EndTime = apt.StartTime
  245. apt.Subject = tb_ev_name.Text & " on " & tp_start_time.Text & "-" & tp_end_time.Text
  246. _myReservationsList.Add(apt)
  247.  
  248. Call SetReservations()
  249. End Sub
  250.  
  251. Private Sub onLoadReservation()
  252. _myReservationsList.Clear()
  253. Dim Connector As New SQLConnector()
  254. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  255. Try
  256. Dim sqli As MySqlConnection = Connector.ConnectDB(True)
  257. Dim rmd As New MySqlCommand("Select reservation.reservation_name, reservation.start_time, reservation.end_time, reservation.reservation_id from reservation", sqli)
  258. Dim d As MySqlDataReader = rmd.ExecuteReader()
  259. While d.Read()
  260. Dim apt As New Reservation()
  261. apt.ReservationID = d("reservation_id").ToString
  262. apt.StartTime = CDate(d("start_time"))
  263. apt.EndTime = apt.StartTime
  264. apt.Subject = d("reservation_name") & " on " & CDate(d("start_time")).ToString("hh:MM tt") & "-" & CDate(d("end_time")).ToString("hh:MM tt")
  265. _myReservationsList.Add(apt)
  266.  
  267. Call SetReservations()
  268. End While
  269. Catch ex As MySQLException
  270. MainWindow.Instance.MainSnackBar("Reservation Info Failed", 3)
  271. Catch ex As Exception
  272. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  273. End Try
  274. Else
  275. Try
  276. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  277. Dim rmd As New SQLiteCommand("Select reservation.reservation_name, reservation.start_time, reservation.end_time, reservation.reservation_id from reservation", sqli)
  278. Dim d As SQLiteDataReader = rmd.ExecuteReader()
  279. While d.Read()
  280. Dim apt As New Reservation()
  281. apt.ReservationID = d("reservation_id").ToString
  282. apt.StartTime = CDate(d("start_time"))
  283. apt.EndTime = apt.StartTime
  284. apt.Subject = d("reservation_name") & " on " & CDate(d("start_time")).ToString("hh:MM tt") & "-" & CDate(d("end_time")).ToString("hh:MM tt")
  285. _myReservationsList.Add(apt)
  286.  
  287. Call SetReservations()
  288. End While
  289. Catch ex As SQLiteException
  290. MainWindow.Instance.MainSnackBar("Reservation Info Failed", 3)
  291. Catch ex As Exception
  292. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  293. End Try
  294. End If
  295. End Sub
  296.  
  297. Private Sub DisplayMonthChanged(ByVal e As MonthChangedEventArgs) Handles Reservation_Calendar.DisplayMonthChanged
  298. onLoadReservation()
  299. Call SetReservations()
  300. End Sub
  301.  
  302. Public Sub SetReservations()
  303. '-- Use whatever function you want to load the MonthReservations list, I happen to have a list filled by linq that has
  304. ' many (possibly the past several years) of them loaded, so i filter to only pass the ones showing up in the displayed
  305. ' month. Note that the "setter" for MonthReservations also triggers a redraw of the display.
  306. Me.Reservation_Calendar.MonthAppointments = _myReservationsList.FindAll(
  307. New System.Predicate(Of Reservation)(
  308. Function(apt As Reservation) _
  309. apt.StartTime IsNot Nothing AndAlso
  310. CDate(apt.StartTime).Month = Me.Reservation_Calendar.DisplayStartDate.Month AndAlso
  311. CDate(apt.StartTime).Year = Me.Reservation_Calendar.DisplayStartDate.Year))
  312. End Sub
  313.  
  314.  
  315. Private Sub b_cancel_Click(sender As Object, e As RoutedEventArgs)
  316. Add_Reservation.IsOpen = False
  317. clearInputs()
  318. MainWindow.Instance.MainSnackBar("Action Canceled", 3)
  319. End Sub
  320.  
  321. Private Sub saveReservation()
  322. Dim Connector As New SQLConnector()
  323. Dim id As String
  324. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  325.  
  326. Else
  327. Try
  328. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  329. Dim rmd As New SQLiteCommand("SELECT max(reservation_id) FROM reservation", sqli)
  330. Dim d As SQLiteDataReader = rmd.ExecuteReader()
  331. While d.Read()
  332. id = CInt(If(IsDBNull(d(0)), n.TagID & 1, n.TagID & CInt(d(0).ToString.Last.ToString) + 1))
  333. End While
  334. Dim rdr As New SQLiteCommand("SELECT room_type_id From room_type Where description = '" & cb_room_name.SelectedValue & "'", sqli)
  335. Dim dr As SQLiteDataReader = rdr.ExecuteReader()
  336. While dr.Read()
  337. Dim cmd As New SQLiteCommand("INSERT INTO reservation(reservation_id, reservation_name, staff_id, room_id, id_number, start_time, end_time) values ('" & id & "','" & tb_ev_name.Text & "','" & config.io.getSession("id") & "','" & dr("room_type_id") & "','" & cb_id_number.Text & "','" & CDate(n.StartDate).ToString("MM/dd/yyyy") & " " & tp_start_time.Text & "','" & CDate(n.EndDate).ToString("MM/dd/yyyy") & " " & tp_end_time.Text & "')", sqli)
  338. cmd.ExecuteNonQuery()
  339. Add_Reservation.IsOpen = False
  340. MainWindow.Instance.MainSnackBar("Reservation Reserved", 3)
  341. AddReservation(n)
  342. clearInputs()
  343. End While
  344. Catch ex As SQLiteException
  345. MainWindow.Instance.MainSnackBar("Reservation Info Failed", 3)
  346. Catch ex As Exception
  347. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  348. End Try
  349. End If
  350. End Sub
  351.  
  352. Private Sub saveUserInfo()
  353. Dim Connector As New SQLConnector()
  354. Dim type As String = cb_user_type.SelectedValue
  355. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  356.  
  357. Else
  358. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  359. Dim depid As Integer
  360. Try
  361. Dim dep1 As New SQLiteCommand("Select * From Department Where description like '" & tb_department.Text & "'", sqli)
  362. Dim r3 As SQLiteDataReader = dep1.ExecuteReader()
  363. If r3.Read() Then
  364. While r3.Read()
  365. depid = r3("dep_id")
  366. End While
  367. Else
  368. Dim dep As New SQLiteCommand("Select max(dep_id) From Department", sqli)
  369. Dim r2 As SQLiteDataReader = dep.ExecuteReader()
  370. While r2.Read
  371. depid = CInt(If(IsDBNull(r2(0)), 0, r2(0)))
  372. End While
  373. depid += 1
  374. Dim cmd As New SQLiteCommand("INSERT INTO Department(Dep_ID , Description) Values('" & depid & "','" & tb_department.Text & "')", sqli)
  375. cmd.ExecuteNonQuery()
  376. r2.Close()
  377. dep.Dispose()
  378. End If
  379. Dim cmd1 As New SQLiteCommand("INSERT INTO Users(id_number, First_name, Mid_name, Last_name, Dep_ID) Values('" & cb_id_number.Text & "','" & tb_fname.Text & "','" & tb_mname.Text & "','" & tb_lname.Text & "','" & depid & "')", sqli)
  380. cmd1.ExecuteNonQuery()
  381. If rb_student.IsChecked Then
  382. Dim cmd2 As New SQLiteCommand("INSERT INTO Student_User(S_ID_Number, type) Values ('" & cb_id_number.Text & "', '" & type & "')", sqli)
  383. cmd2.ExecuteNonQuery()
  384. Else
  385. Dim cmd2 As New SQLiteCommand("INSERT INTO Employee_User(E_ID_Number, type) Values ('" & cb_id_number.Text & "', '" & type & "')", sqli)
  386. cmd2.ExecuteNonQuery()
  387. End If
  388. Dim cmdType As New SQLiteCommand()
  389. If type Like "NTEA" Then
  390. cmdType.CommandText = "INSERT INTO NTEA_Employee_User(N_E_ID_Number, Position) Values (" & cb_id_number.Text & ", '" & tb_pname.Text & "')"
  391. cmdType.Connection = sqli
  392. cmdType.ExecuteNonQuery()
  393. cmdType.Dispose()
  394. ElseIf type Like "Faculty"
  395. cmdType.CommandText = "INSERT INTO Faculty_Employee_User(F_E_ID_Number, Rank) Values (" & cb_id_number.Text & ",'" & tb_rank.Text & "')"
  396. cmdType.Connection = sqli
  397. cmdType.ExecuteNonQuery()
  398. cmdType.Dispose()
  399. ElseIf type Like "College"
  400. cmdType.CommandText = "INSERT INTO college_student(c_id_number, Course, Year) Values (" & cb_id_number.Text & ", '" & tb_cname.Text & "','" & cb_college_level.Text & "')"
  401. cmdType.Connection = sqli
  402. cmdType.ExecuteNonQuery()
  403. cmdType.Dispose()
  404. ElseIf type Like "Senior High School"
  405. cmdType.CommandText = "INSERT INTO High_School_Student(HS_ID_Number, Grade) Values (" & cb_id_number.Text & ",'" & cb_high_level.Text & "')"
  406. cmdType.Connection = sqli
  407. cmdType.ExecuteNonQuery()
  408. cmdType.Dispose()
  409. ElseIf type Like "High School"
  410. cmdType.CommandText = "INSERT INTO Senior_High_School_Student(S_HS_ID_Number, Track) Values (" & cb_id_number.Text & ", '" & tb_track.Text & "')"
  411. cmdType.Connection = sqli
  412. cmdType.ExecuteNonQuery()
  413. cmdType.Dispose()
  414. End If
  415. cmdType = Nothing
  416. cmd1 = Nothing
  417. Catch ex As Exception
  418. MainWindow.Instance.MainSnackBar("Opps, Something went wrong. Try again", 3)
  419. ex = Nothing
  420. Finally
  421. sqli.Close()
  422. sqli.Dispose()
  423. sqli = Nothing
  424. End Try
  425. End If
  426. End Sub
  427.  
  428. Private Sub retrieveData()
  429. Dim Connector As New SQLConnector
  430. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  431.  
  432. Else
  433. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  434. Try
  435. Dim cmd1 As New SQLiteCommand("SELECT s_id_number FROM Student_User Union all SELECT e_id_number FROM Employee_User", sqli)
  436. Dim id As SQLiteDataReader = cmd1.ExecuteReader()
  437. While id.Read
  438. cb_id_number.Items.Add(id("s_id_number").ToString)
  439. End While
  440. id.Close()
  441. cmd1 = Nothing
  442. Dim cmd2 As New SQLiteCommand("Select * From Department", sqli)
  443. Dim r2 As SQLiteDataReader = cmd2.ExecuteReader
  444. While r2.Read
  445. tb_department.Items.Add(r2("description"))
  446. End While
  447. r2.Close()
  448. cmd2 = Nothing
  449. Catch ex As Exception
  450. MainWindow.Instance.MainSnackBar("Opps, Something went wrong. Try again", 3)
  451. ex = Nothing
  452. Finally
  453. sqli.Close()
  454. sqli.Dispose()
  455. sqli = Nothing
  456. End Try
  457. End If
  458. End Sub
  459.  
  460. Private Sub onSelected(sender As Object, e As RoutedEventArgs) Handles cb_id_number.SelectionChanged
  461. Dim u As New UserInfo
  462. Dim t As New UserType
  463. If cb_id_number.Items.Contains(cb_id_number.SelectedValue) Then
  464. Dim id As Integer = cb_id_number.SelectedValue
  465. Dim Connector As New SQLConnector
  466. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  467.  
  468. Else
  469. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  470. Dim dep_id As Integer
  471. Try
  472. Dim cmd1 As New SQLiteCommand("Select * From users where id_number = " & id, sqli)
  473. Dim r1 As SQLiteDataReader = cmd1.ExecuteReader()
  474. While r1.Read
  475. u.FName = r1("first_name").ToString
  476. u.MName = r1("mid_name").ToString
  477. u.LName = r1("last_name").ToString
  478. dep_id = CInt(r1("dep_id").ToString)
  479. End While
  480. r1.Close()
  481. cmd1 = Nothing
  482. Dim cmd2 As New SQLiteCommand("Select description From Department where dep_id = " & dep_id, sqli)
  483. Dim r2 As SQLiteDataReader = cmd2.ExecuteReader()
  484. While r2.Read
  485. u.DepName = r2(0).ToString
  486. End While
  487. r2.Close()
  488. cmd2 = Nothing
  489. Dim cmd3 As New SQLiteCommand("select type from student_user where s_id_number = " & id & " union all select type from employee_user where e_id_number = " & id, sqli)
  490. Dim r3 As SQLiteDataReader = cmd3.ExecuteReader()
  491. While r3.Read
  492. t.UserType = r3(0).ToString
  493. End While
  494. r3.Close()
  495. cmd3 = Nothing
  496. Dim cmdType As New SQLiteCommand()
  497. If t.UserType Like "NTEA" Then
  498. cmdType.CommandText = "select position from ntea_employee_user where n_e_id_number =" & id
  499. cmdType.Connection = sqli
  500. Dim r As SQLiteDataReader = cmdType.ExecuteReader()
  501. While r.Read
  502. t.PName = r("position").ToString
  503. End While
  504. r.Close()
  505. cmdType.Dispose()
  506. ElseIf t.UserType Like "Faculty"
  507. cmdType.CommandText = "select rank from faculty_employee_user where f_e_id_number =" & id
  508. cmdType.Connection = sqli
  509. Dim r As SQLiteDataReader = cmdType.ExecuteReader()
  510. While r.Read
  511. t.Rank = r("rank").ToString
  512. End While
  513. r.Close()
  514. cmdType.Dispose()
  515. ElseIf t.UserType Like "College"
  516. cmdType.CommandText = "select course, year from college_student where c_id_number =" & id
  517. cmdType.Connection = sqli
  518. Dim r As SQLiteDataReader = cmdType.ExecuteReader()
  519. While r.Read
  520. t.CName = r("course").ToString
  521. t.CollegeLevel = r("year").ToString
  522. End While
  523. r.Close()
  524. cmdType.Dispose()
  525. ElseIf t.UserType Like "Senior High School"
  526. cmdType.CommandText = "select track from senior_high_school_student where s_hs_id_number =" & id
  527. cmdType.Connection = sqli
  528. Dim r As SQLiteDataReader = cmdType.ExecuteReader()
  529. While r.Read
  530. t.Track = r("track").ToString
  531. End While
  532. r.Close()
  533. cmdType.Dispose()
  534. ElseIf t.UserType Like "High School"
  535. cmdType.CommandText = "select grade from high_school_student where hs_id_number =" & id
  536. cmdType.Connection = sqli
  537. Dim r As SQLiteDataReader = cmdType.ExecuteReader()
  538. While r.Read
  539. t.HighLevel = r("grade").ToString
  540. End While
  541. r.Close()
  542. cmdType.Dispose()
  543. End If
  544. Catch ex As Exception
  545. 'Logs
  546. ex = Nothing
  547. Finally
  548. sqli.Close()
  549. sqli.Dispose()
  550. sqli = Nothing
  551. End Try
  552. End If
  553. deployUserInfo(u, t)
  554. Else
  555. clearUserInfo()
  556. End If
  557. End Sub
  558.  
  559. Public Sub clearUserInfo()
  560. 'Clear User Information
  561. tb_fname.Clear()
  562. tb_mname.Clear()
  563. tb_lname.Clear()
  564. tb_department.Text = Nothing
  565. 'Clear User Type
  566. rb_student.IsChecked = True
  567. tb_pname.Clear()
  568. tb_rank.Clear()
  569. tb_cname.Clear()
  570. tb_track.Clear()
  571. cb_user_type.Text = Nothing
  572. cb_college_level.Text = Nothing
  573. cb_high_level.Text = Nothing
  574. End Sub
  575. 'Auto Fill User Information
  576. Public Sub deployUserInfo(u As UserInfo, t As UserType)
  577. 'User Information
  578. tb_fname.Text = u.FName
  579. tb_mname.Text = u.MName
  580. tb_lname.Text = u.LName
  581. tb_department.SelectedValue = u.DepName
  582. 'User Type Information
  583. If t.UserType Like "NTEA" Then
  584. rb_employee.IsChecked = True
  585. cb_user_type.SelectedValue = t.UserType
  586. tb_pname.Text = t.PName
  587. ElseIf t.UserType Like "Faculty"
  588. rb_employee.IsChecked = True
  589. cb_user_type.SelectedValue = t.UserType
  590. tb_rank.Text = t.Rank
  591. ElseIf t.UserType Like "College"
  592. rb_student.IsChecked = True
  593. cb_user_type.SelectedValue = t.UserType
  594. tb_cname.Text = t.CName
  595. cb_college_level.Text = t.CollegeLevel
  596. ElseIf t.UserType Like "Senior High School"
  597. rb_student.IsChecked = True
  598. cb_user_type.SelectedValue = t.UserType
  599. tb_track.Text = t.Track
  600. ElseIf t.UserType Like "High School"
  601. rb_student.IsChecked = True
  602. cb_user_type.SelectedValue = t.UserType
  603. cb_high_level.Text = t.HighLevel
  604. End If
  605. user_typeChange()
  606. End Sub
  607.  
  608. Private Async Sub rb_student_Click(sender As Object, e As RoutedEventArgs)
  609. Await Tasker.Delay(1)
  610. cb_user_type.Items.Clear()
  611. cb_user_type.Items.Add("College")
  612. cb_user_type.Items.Add("Senior High School")
  613. cb_user_type.Items.Add("High School")
  614. End Sub
  615.  
  616. Private Sub rb_employee_Click(sender As Object, e As RoutedEventArgs)
  617. cb_user_type.Items.Clear()
  618. cb_user_type.Items.Add("NTEA")
  619. cb_user_type.Items.Add("Faculty")
  620. End Sub
  621.  
  622. Public Sub clearInputs()
  623. tb_ev_name.Clear()
  624. cb_room_name.Text = Nothing
  625. chb_whole_day.IsChecked = False
  626. tp_start_time.Text = Nothing
  627. tp_end_time.Text = Nothing
  628. cb_id_number.Text = Nothing
  629. tb_fname.Clear()
  630. tb_mname.Clear()
  631. tb_lname.Clear()
  632. rb_employee.IsChecked = False
  633. rb_student.IsChecked = True
  634. cb_user_type.Text = Nothing
  635. tb_pname.Text = Nothing
  636. tb_rank.Text = Nothing
  637. tb_cname.Text = Nothing
  638. cb_college_level.Text = Nothing
  639. tb_track.Text = Nothing
  640. cb_high_level.Text = Nothing
  641. tb_department.Text = Nothing
  642. 'Removing Error Validation
  643. Validation.ClearInvalid(DirectCast(tb_ev_name, TextBox).GetBindingExpression(TextBox.TextProperty))
  644. Validation.ClearInvalid(DirectCast(tb_fname, TextBox).GetBindingExpression(TextBox.TextProperty))
  645. Validation.ClearInvalid(DirectCast(tb_mname, TextBox).GetBindingExpression(TextBox.TextProperty))
  646. Validation.ClearInvalid(DirectCast(tb_lname, TextBox).GetBindingExpression(TextBox.TextProperty))
  647. Validation.ClearInvalid(DirectCast(tb_pname, TextBox).GetBindingExpression(TextBox.TextProperty))
  648. Validation.ClearInvalid(DirectCast(tb_rank, TextBox).GetBindingExpression(TextBox.TextProperty))
  649. Validation.ClearInvalid(DirectCast(tb_cname, TextBox).GetBindingExpression(TextBox.TextProperty))
  650. Validation.ClearInvalid(DirectCast(tb_track, TextBox).GetBindingExpression(TextBox.TextProperty))
  651. Validation.ClearInvalid(DirectCast(cb_id_number, ComboBox).GetBindingExpression(ComboBox.TextProperty))
  652. Validation.ClearInvalid(DirectCast(cb_user_type, ComboBox).GetBindingExpression(ComboBox.TextProperty))
  653. Validation.ClearInvalid(DirectCast(cb_college_level, ComboBox).GetBindingExpression(ComboBox.TextProperty))
  654. Validation.ClearInvalid(DirectCast(cb_high_level, ComboBox).GetBindingExpression(ComboBox.TextProperty))
  655. Validation.ClearInvalid(DirectCast(tb_department, ComboBox).GetBindingExpression(ComboBox.TextProperty))
  656. Validation.ClearInvalid(DirectCast(cb_room_name, ComboBox).GetBindingExpression(ComboBox.TextProperty))
  657. Validation.ClearInvalid(DirectCast(tp_start_time, MaterialDesignThemes.Wpf.TimePicker).GetBindingExpression(MaterialDesignThemes.Wpf.TimePicker.TextProperty))
  658. Validation.ClearInvalid(DirectCast(tp_end_time, MaterialDesignThemes.Wpf.TimePicker).GetBindingExpression(MaterialDesignThemes.Wpf.TimePicker.TextProperty))
  659. End Sub
  660.  
  661. Private Sub chb_whole_day_Checked(sender As Object, e As RoutedEventArgs)
  662. If chb_whole_day.IsChecked Then
  663. tp_start_time.IsEnabled = False
  664. tp_start_time.ToolTip = "Whole Day Event"
  665. tp_start_time.Text = "12:00 AM"
  666. tp_end_time.Text = ""
  667. tp_end_time.IsEnabled = False
  668. tp_end_time.ToolTip = "Whole Day Event"
  669. tp_end_time.Text = "12:00 PM"
  670. Else
  671. tp_start_time.IsEnabled = True
  672. tp_start_time.ToolTip = "Select start time"
  673. tp_end_time.IsEnabled = True
  674. tp_end_time.ToolTip = "Select end time"
  675. End If
  676. End Sub
  677.  
  678. Private Sub b_reset_Click(sender As Object, e As RoutedEventArgs)
  679. clearInputs()
  680. MainWindow.Instance.MainSnackBar("Values Cleared", 3)
  681. End Sub
  682.  
  683. Private Sub cb_user_type_Selected(sender As Object, e As RoutedEventArgs) Handles cb_user_type.SelectionChanged
  684. user_typeChange()
  685. End Sub
  686.  
  687. Private Sub user_typeChange()
  688. Select Case cb_user_type.SelectedValue
  689. Case "NTEA"
  690. user_type.SelectedIndex = 0
  691. Case "Faculty"
  692. user_type.SelectedIndex = 1
  693. Case "College"
  694. user_type.SelectedIndex = 2
  695. Case "Senior High School"
  696. user_type.SelectedIndex = 3
  697. Case "High School"
  698. user_type.SelectedIndex = 4
  699. Case Else
  700. user_type.SelectedIndex = 5
  701. End Select
  702. End Sub
  703.  
  704. End Class
  705.  
  706. End NamespacePublic Class card
  707.  
  708. End Class
  709. Imports System.IO
  710. Imports System.Reflection
  711. Imports System.Text.RegularExpressions
  712. Imports AMS.Profile
  713. Imports MySql.Data.MySqlClient
  714.  
  715. Public Class config
  716.  
  717. Public Shared m_instance As config
  718. Public conf As Registry = New Registry()
  719. Public hash As New Cypher("R$4@zD*<uT)+?!0,\%1dT")
  720. Private theme As New App.Settings.Theme
  721.  
  722. #Region "Instantion of Class"
  723. Public Shared ReadOnly Property [io]() As config
  724. Get
  725. Return m_instance
  726. End Get
  727. End Property
  728. Public Sub Config_onLoad() Handles Me.Loaded
  729. m_instance = Me
  730. End Sub
  731. #End Region
  732. #Region "Installation Configuration"
  733. Public Sub setAdmin(id As Integer, username As String, password As String, email As String)
  734. conf.SetValue("Account", "type", "0")
  735. conf.SetValue("Account", "user_id", hash.EncryptData(id))
  736. conf.SetValue("Account", "email", hash.EncryptData(email))
  737. conf.SetValue("Account", "username", hash.EncryptData(username))
  738. conf.SetValue("Account", "password", hash.EncryptData(password))
  739. id = Nothing
  740. username = Nothing
  741. password = Nothing
  742. email = Nothing
  743. End Sub
  744.  
  745. Public Function getAdmin()
  746. Return conf.GetValue("Account", "type") & "," & hash.DecryptData(conf.GetValue("Account", "user_id")) & "," & hash.DecryptData(conf.GetValue("Account", "email")) & "," & hash.DecryptData(conf.GetValue("Account", "username")) & "," & hash.DecryptData(conf.GetValue("Account", "password"))
  747. End Function
  748.  
  749. Public Function getRegistryStatus() As Boolean
  750. If conf.GetSectionNames.Length = 5 Then
  751. Return True
  752. Else
  753. Return False
  754. End If
  755. End Function
  756.  
  757. Public Sub setDefaults()
  758. conf.RemoveSection("Establishment")
  759. conf.RemoveSection("Theme")
  760. conf.RemoveSection("Database")
  761. conf.RemoveSection("Account")
  762. conf.RemoveSection("Misc Configuration")
  763. setStablishment("Reserfy", "Malaybalay City", "reserfy@survs-systems.ml")
  764. theme.Mode(False)
  765. theme.Color("Blue")
  766. setDBLocation(String.Empty)
  767. setMiscEnable()
  768. setmysqlStatus(False)
  769. Session(False)
  770. Settings.Instance.ts_advance_modes(True)
  771. End Sub
  772. #End Region
  773. #Region "General Establishment Settings"
  774. Public Sub setStablishment(name As String, address As String, contact As String)
  775. conf.SetValue("Establisment", "name", name)
  776. conf.SetValue("Establisment", "address", address)
  777. conf.SetValue("Establisment", "contact", contact)
  778. MainWindow.Instance.l_sys_name.Content = name
  779. name = Nothing
  780. address = Nothing
  781. contact = Nothing
  782. End Sub
  783.  
  784. Public Function getStablishment()
  785. Return If(conf.GetValue("Establisment", "name") Is Nothing, "Establishment Name", conf.GetValue("Establisment", "name")) & "," & If(conf.GetValue("Establisment", "address") Is Nothing, "Address", conf.GetValue("Establisment", "address")) & "," & If(conf.GetValue("Establisment", "contact") Is Nothing, "Contact", conf.GetValue("Establisment", "contact"))
  786. End Function
  787. #End Region
  788. #Region "Database Related Configuration"
  789. Public Sub setDBLocation(location As String)
  790. If Not System.IO.Directory.Exists(System.Windows.Forms.Application.UserAppDataPath & "\Reserfy Local Database\") Then
  791. System.IO.Directory.CreateDirectory(System.Windows.Forms.Application.UserAppDataPath & "\Reserfy Local Database\")
  792. End If
  793. conf.SetValue("Database", "Type", "personal")
  794. conf.SetValue("Database", "location", If(location = "", System.Windows.Forms.Application.UserAppDataPath & "\Reserfy Local Database\", location))
  795. location = Nothing
  796. End Sub
  797.  
  798. Public Function getDBLocation() As String
  799. Return If(conf.GetValue("Database", "location") = "", System.Windows.Forms.Application.UserAppDataPath & "\Reserfy Local Database\", conf.GetValue("Database", "location"))
  800. End Function
  801.  
  802. Public Sub setDBShared(servername As String, port As String, username As String, password As String, dbname As String)
  803. conf.SetValue("Database", "Type", "shared")
  804. conf.SetValue("Database", "servername", servername)
  805. conf.SetValue("Database", "port", If(port = String.Empty, 3306, port))
  806. conf.SetValue("Database", "dbname", getDBName())
  807. conf.SetValue("Database", "username", hash.EncryptData(username))
  808. conf.SetValue("Database", "password", hash.EncryptData(password))
  809. servername = Nothing
  810. port = Nothing
  811. username = Nothing
  812. password = Nothing
  813. dbname = Nothing
  814. End Sub
  815. Public Function getDBShared()
  816. Return conf.GetValue("Database", "servername") & "," & conf.GetValue("Database", "port") & "," & hash.DecryptData(conf.GetValue("Database", "username")) & "," & hash.DecryptData(conf.GetValue("Database", "password")) & "," & conf.GetValue("Database", "dbname")
  817. End Function
  818.  
  819. Public Function getDBType() As String
  820. Return If(conf.GetValue("Database", "Type") = "", "personal", conf.GetValue("Database", "Type"))
  821. End Function
  822.  
  823. Public Function getDBName() As String
  824. If daemon.setter.SettingsSQL.Ping Then
  825. Return daemon.setter.SettingsSQL.Database
  826. Else
  827. Return conf.GetValue("Database", "dbname")
  828. End If
  829. End Function
  830.  
  831. Public Function getInitDB() As String
  832. Return "reserfy_data_v"
  833. End Function
  834.  
  835. Public Function setDBCreate(ext As Integer) As String
  836. Return "CREATE DATABASE IF NOT EXISTS `reserfy_data_v" & ext & "` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
  837. USE `reserfy_data_v" & ext & "`"
  838. End Function
  839.  
  840. Public Function getDBTablesCommand() As String
  841. Return "
  842. --
  843.  
  844. -- --------------------------------------------------------
  845.  
  846. --
  847. -- Table structure for table `college_student`
  848. --
  849.  
  850. CREATE TABLE `college_student` (
  851. `c_id_number` int(11) NOT NULL,
  852. `course` varchar(60) NOT NULL,
  853. `year` int(5) NOT NULL
  854. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  855.  
  856. -- --------------------------------------------------------
  857.  
  858. --
  859. -- Table structure for table `contact`
  860. --
  861.  
  862. CREATE TABLE `contact` (
  863. `contact_id` int(11) NOT NULL,
  864. `email_add` varchar(30) NOT NULL,
  865. `mobile` varchar(30) NOT NULL
  866. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  867.  
  868. -- --------------------------------------------------------
  869.  
  870. --
  871. -- Table structure for table `credentials`
  872. --
  873.  
  874. CREATE TABLE `credentials` (
  875. `cred_id` int(11) NOT NULL,
  876. `username` varchar(30) NOT NULL,
  877. `password` varchar(100) NOT NULL,
  878. `privilege` int(11) NOT NULL
  879. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  880.  
  881. -- --------------------------------------------------------
  882.  
  883. --
  884. -- Table structure for table `department`
  885. --
  886.  
  887. CREATE TABLE `department` (
  888. `dep_id` int(11) NOT NULL,
  889. `description` varchar(60) NOT NULL
  890. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  891.  
  892. -- --------------------------------------------------------
  893.  
  894. --
  895. -- Table structure for table `employee_user`
  896. --
  897.  
  898. CREATE TABLE `employee_user` (
  899. `e_id_number` int(11) NOT NULL,
  900. `type` varchar(30) NOT NULL
  901. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  902.  
  903. -- --------------------------------------------------------
  904.  
  905. --
  906. -- Table structure for table `faculty_employee_user`
  907. --
  908.  
  909. CREATE TABLE `faculty_employee_user` (
  910. `f_e_id_number` int(11) NOT NULL,
  911. `rank` int(11) NOT NULL
  912. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  913.  
  914. -- --------------------------------------------------------
  915.  
  916. --
  917. -- Table structure for table `high_school_student`
  918. --
  919.  
  920. CREATE TABLE `high_school_student` (
  921. `hs_id_number` int(11) NOT NULL,
  922. `grade` varchar(30) NOT NULL
  923. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  924.  
  925. -- --------------------------------------------------------
  926.  
  927. --
  928. -- Table structure for table `ntea_employee_user`
  929. --
  930.  
  931. CREATE TABLE `ntea_employee_user` (
  932. `n_e_id_number` int(11) NOT NULL,
  933. `position` int(11) NOT NULL
  934. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  935.  
  936. -- --------------------------------------------------------
  937.  
  938. --
  939. -- Table structure for table `reservation`
  940. --
  941.  
  942. CREATE TABLE `reservation` (
  943. `reservation_id` int(11) NOT NULL,
  944. `reservation_name` varchar(100) NOT NULL,
  945. `staff_id` int(11) NOT NULL,
  946. `room_id` int(11) NOT NULL,
  947. `id_number` int(11) NOT NULL,
  948. `start_time` varchar(30) NOT NULL,
  949. `end_time` varchar(30) NOT NULL
  950. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  951.  
  952. -- --------------------------------------------------------
  953.  
  954. --
  955. -- Table structure for table `room`
  956. --
  957.  
  958. CREATE TABLE `room` (
  959. `room_id` int(11) NOT NULL,
  960. `floor_level` int(11) NOT NULL,
  961. `room_type_id` int(11) NOT NULL
  962. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  963.  
  964. -- --------------------------------------------------------
  965.  
  966. --
  967. -- Table structure for table `room_type`
  968. --
  969.  
  970. CREATE TABLE `room_type` (
  971. `room_type_id` int(11) NOT NULL,
  972. `description` varchar(60) NOT NULL
  973. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  974.  
  975. -- --------------------------------------------------------
  976.  
  977. --
  978. -- Table structure for table `senior_high_school_student`
  979. --
  980.  
  981. CREATE TABLE `senior_high_school_student` (
  982. `s_hs_id_number` int(11) NOT NULL,
  983. `track` varchar(30) NOT NULL
  984. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  985.  
  986. -- --------------------------------------------------------
  987.  
  988. --
  989. -- Table structure for table `staff`
  990. --
  991.  
  992. CREATE TABLE `staff` (
  993. `staff_id` int(11) NOT NULL,
  994. `name_id` int(11) NOT NULL,
  995. `birth_date` date NOT NULL,
  996. `photo` BLOB NOT NULL,
  997. `contact_id` int(11) NOT NULL,
  998. `cred_id` int(11) NOT NULL
  999. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1000.  
  1001. -- --------------------------------------------------------
  1002.  
  1003. --
  1004. -- Table structure for table `staff_name`
  1005. --
  1006.  
  1007. CREATE TABLE `staff_name` (
  1008. `name_staff_id` int(11) NOT NULL,
  1009. `first_name` varchar(60) NOT NULL,
  1010. `mid_name` varchar(60) NOT NULL,
  1011. `last_name` varchar(60) NOT NULL
  1012. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1013.  
  1014. -- --------------------------------------------------------
  1015.  
  1016. --
  1017. -- Table structure for table `student_user`
  1018. --
  1019.  
  1020. CREATE TABLE `student_user` (
  1021. `s_id_number` int(11) NOT NULL,
  1022. `type` varchar(30) NOT NULL
  1023. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1024.  
  1025. -- --------------------------------------------------------
  1026.  
  1027. --
  1028. -- Table structure for table `users`
  1029. --
  1030.  
  1031. CREATE TABLE `users` (
  1032. `id_number` int(11) NOT NULL,
  1033. `first_name` varchar(30) NOT NULL,
  1034. `mid_name` varchar(30) NOT NULL,
  1035. `last_name` varchar(30) NOT NULL,
  1036. `dep_id` int(11) NOT NULL
  1037. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1038.  
  1039. --
  1040. -- Indexes for dumped tables
  1041. --
  1042.  
  1043. --
  1044. -- Indexes for table `college_student`
  1045. --
  1046. ALTER TABLE `college_student`
  1047. ADD PRIMARY KEY (`c_id_number`);
  1048.  
  1049. --
  1050. -- Indexes for table `contact`
  1051. --
  1052. ALTER TABLE `contact`
  1053. ADD PRIMARY KEY (`contact_id`);
  1054.  
  1055. --
  1056. -- Indexes for table `credentials`
  1057. --
  1058. ALTER TABLE `credentials`
  1059. ADD PRIMARY KEY (`cred_id`);
  1060.  
  1061. --
  1062. -- Indexes for table `department`
  1063. --
  1064. ALTER TABLE `department`
  1065. ADD PRIMARY KEY (`dep_id`);
  1066.  
  1067. --
  1068. -- Indexes for table `employee_user`
  1069. --
  1070. ALTER TABLE `employee_user`
  1071. ADD PRIMARY KEY (`e_id_number`);
  1072.  
  1073. --
  1074. -- Indexes for table `faculty_employee_user`
  1075. --
  1076. ALTER TABLE `faculty_employee_user`
  1077. ADD PRIMARY KEY (`f_e_id_number`);
  1078.  
  1079. --
  1080. -- Indexes for table `high_school_student`
  1081. --
  1082. ALTER TABLE `high_school_student`
  1083. ADD PRIMARY KEY (`hs_id_number`);
  1084.  
  1085. --
  1086. -- Indexes for table `ntea_employee_user`
  1087. --
  1088. ALTER TABLE `ntea_employee_user`
  1089. ADD PRIMARY KEY (`n_e_id_number`);
  1090.  
  1091. --
  1092. -- Indexes for table `reservation`
  1093. --
  1094. ALTER TABLE `reservation`
  1095. ADD PRIMARY KEY (`reservation_id`),
  1096. ADD KEY `id_number` (`id_number`),
  1097. ADD KEY `room_id` (`room_id`),
  1098. ADD KEY `staff_id` (`staff_id`);
  1099.  
  1100. --
  1101. -- Indexes for table `room`
  1102. --
  1103. ALTER TABLE `room`
  1104. ADD PRIMARY KEY (`room_id`),
  1105. ADD KEY `room_type_id` (`room_type_id`);
  1106.  
  1107. --
  1108. -- Indexes for table `room_type`
  1109. --
  1110. ALTER TABLE `room_type`
  1111. ADD PRIMARY KEY (`room_type_id`);
  1112.  
  1113. --
  1114. -- Indexes for table `senior_high_school_student`
  1115. --
  1116. ALTER TABLE `senior_high_school_student`
  1117. ADD PRIMARY KEY (`s_hs_id_number`);
  1118.  
  1119. --
  1120. -- Indexes for table `staff`
  1121. --
  1122. ALTER TABLE `staff`
  1123. ADD PRIMARY KEY (`staff_id`),
  1124. ADD KEY `name_id` (`name_id`),
  1125. ADD KEY `contact_id` (`contact_id`),
  1126. ADD KEY `cred_id` (`cred_id`);
  1127.  
  1128. --
  1129. -- Indexes for table `staff_name`
  1130. --
  1131. ALTER TABLE `staff_name`
  1132. ADD PRIMARY KEY (`name_staff_id`);
  1133.  
  1134. --
  1135. -- Indexes for table `student_user`
  1136. --
  1137. ALTER TABLE `student_user`
  1138. ADD PRIMARY KEY (`s_id_number`);
  1139.  
  1140. --
  1141. -- Indexes for table `users`
  1142. --
  1143. ALTER TABLE `users`
  1144. ADD PRIMARY KEY (`id_number`),
  1145. ADD KEY `dep_id` (`dep_id`);
  1146.  
  1147. --
  1148. -- AUTO_INCREMENT for dumped tables
  1149. --
  1150.  
  1151. --
  1152. -- AUTO_INCREMENT for table `reservation`
  1153. --
  1154. ALTER TABLE `reservation`
  1155. MODIFY `reservation_id` int(11) NOT NULL AUTO_INCREMENT;
  1156. --
  1157. -- Constraints for dumped tables
  1158. --
  1159.  
  1160. --
  1161. -- Constraints for table `college_student`
  1162. --
  1163. ALTER TABLE `college_student`
  1164. ADD CONSTRAINT `college_student_ibfk_1` FOREIGN KEY (`c_id_number`) REFERENCES `student_user` (`s_id_number`);
  1165.  
  1166. --
  1167. -- Constraints for table `employee_user`
  1168. --
  1169. ALTER TABLE `employee_user`
  1170. ADD CONSTRAINT `employee_user_ibfk_1` FOREIGN KEY (`e_id_number`) REFERENCES `users` (`id_number`);
  1171.  
  1172. --
  1173. -- Constraints for table `faculty_employee_user`
  1174. --
  1175. ALTER TABLE `faculty_employee_user`
  1176. ADD CONSTRAINT `faculty_employee_user_ibfk_1` FOREIGN KEY (`f_e_id_number`) REFERENCES `employee_user` (`e_id_number`);
  1177.  
  1178. --
  1179. -- Constraints for table `high_school_student`
  1180. --
  1181. ALTER TABLE `high_school_student`
  1182. ADD CONSTRAINT `high_school_student_ibfk_1` FOREIGN KEY (`hs_id_number`) REFERENCES `student_user` (`s_id_number`);
  1183.  
  1184. --
  1185. -- Constraints for table `ntea_employee_user`
  1186. --
  1187. ALTER TABLE `ntea_employee_user`
  1188. ADD CONSTRAINT `ntea_employee_user_ibfk_1` FOREIGN KEY (`n_e_id_number`) REFERENCES `employee_user` (`e_id_number`);
  1189.  
  1190. --
  1191. -- Constraints for table `reservation`
  1192. --
  1193. ALTER TABLE `reservation`
  1194. ADD CONSTRAINT `reservation_ibfk_1` FOREIGN KEY (`id_number`) REFERENCES `users` (`id_number`),
  1195. ADD CONSTRAINT `reservation_ibfk_2` FOREIGN KEY (`room_id`) REFERENCES `room` (`room_id`),
  1196. ADD CONSTRAINT `reservation_ibfk_3` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`);
  1197.  
  1198. --
  1199. -- Constraints for table `room`
  1200. --
  1201. ALTER TABLE `room`
  1202. ADD CONSTRAINT `room_ibfk_1` FOREIGN KEY (`room_type_id`) REFERENCES `room_type` (`room_type_id`);
  1203.  
  1204. --
  1205. -- Constraints for table `senior_high_school_student`
  1206. --
  1207. ALTER TABLE `senior_high_school_student`
  1208. ADD CONSTRAINT `senior_high_school_student_ibfk_1` FOREIGN KEY (`s_hs_id_number`) REFERENCES `student_user` (`s_id_number`);
  1209.  
  1210. --
  1211. -- Constraints for table `staff`
  1212. --
  1213. ALTER TABLE `staff`
  1214. ADD CONSTRAINT `staff_ibfk_1` FOREIGN KEY (`name_id`) REFERENCES `staff_name` (`name_staff_id`),
  1215. ADD CONSTRAINT `staff_ibfk_2` FOREIGN KEY (`contact_id`) REFERENCES `contact` (`contact_id`),
  1216. ADD CONSTRAINT `staff_ibfk_3` FOREIGN KEY (`cred_id`) REFERENCES `credentials` (`cred_id`);
  1217.  
  1218. --
  1219. -- Constraints for table `student_user`
  1220. --
  1221. ALTER TABLE `student_user`
  1222. ADD CONSTRAINT `student_user_ibfk_1` FOREIGN KEY (`s_id_number`) REFERENCES `users` (`id_number`);
  1223.  
  1224. --
  1225. -- Constraints for table `users`
  1226. --
  1227. ALTER TABLE `users`
  1228. ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`dep_id`) REFERENCES `department` (`dep_id`);
  1229. COMMIT;
  1230.  
  1231. "
  1232. End Function
  1233.  
  1234. Public Function getDBSQLITablesCommand()
  1235. Return "--
  1236. -- File generated with SQLiteStudio v3.1.1 on Tue Oct 10 17:49:33 2017
  1237. --
  1238. -- Text encoding used: System
  1239. --
  1240. PRAGMA foreign_keys = off;
  1241. BEGIN TRANSACTION;
  1242.  
  1243. -- Table: college_student
  1244. DROP TABLE IF EXISTS college_student;
  1245. CREATE TABLE college_student (c_id_number int (11) NOT NULL PRIMARY KEY, course varchar (60) NOT NULL, year int (5) NOT NULL);
  1246.  
  1247. -- Table: contact
  1248. DROP TABLE IF EXISTS contact;
  1249. CREATE TABLE contact (contact_id int (11) NOT NULL PRIMARY KEY, email_add varchar (30) NOT NULL, mobile varchar (30));
  1250.  
  1251. -- Table: credentials
  1252. DROP TABLE IF EXISTS credentials;
  1253. CREATE TABLE credentials (cred_id int (11) NOT NULL PRIMARY KEY, username varchar (30) NOT NULL, password varchar (100) NOT NULL, privilege int (11) NOT NULL);
  1254.  
  1255. -- Table: department
  1256. DROP TABLE IF EXISTS department;
  1257. CREATE TABLE department (dep_id int (11) NOT NULL PRIMARY KEY, description varchar (60));
  1258.  
  1259. -- Table: employee_user
  1260. DROP TABLE IF EXISTS employee_user;
  1261. CREATE TABLE employee_user (e_id_number int (11) NOT NULL PRIMARY KEY, type varchar (60));
  1262.  
  1263. -- Table: faculty_employee_user
  1264. DROP TABLE IF EXISTS faculty_employee_user;
  1265. CREATE TABLE faculty_employee_user (f_e_id_number int (11) NOT NULL PRIMARY KEY, rank int (11));
  1266.  
  1267. -- Table: high_school_student
  1268. DROP TABLE IF EXISTS high_school_student;
  1269. CREATE TABLE high_school_student (hs_id_number int (11) NOT NULL PRIMARY KEY, grade varchar (30));
  1270.  
  1271. -- Table: ntea_employee_user
  1272. DROP TABLE IF EXISTS ntea_employee_user;
  1273. CREATE TABLE ntea_employee_user (n_e_id_number int (11) NOT NULL PRIMARY KEY, position int (11));
  1274.  
  1275. -- Table: reservation
  1276. DROP TABLE IF EXISTS reservation;
  1277. CREATE TABLE reservation (reservation_id int (11) NOT NULL PRIMARY KEY,`reservation_name` varchar(100) NOT NULL, staff_id int (11) NOT NULL REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE RESTRICT MATCH SIMPLE, room_id int (11) NOT NULL REFERENCES room (room_id) ON DELETE RESTRICT ON UPDATE RESTRICT MATCH SIMPLE, id_number int (11) NOT NULL REFERENCES users (id_number) ON DELETE RESTRICT ON UPDATE RESTRICT MATCH SIMPLE,start_time varchar(30) NOT NULL,
  1278. end_time varchar(30) NOT NULL);
  1279.  
  1280. -- Table: room
  1281. DROP TABLE IF EXISTS room;
  1282. CREATE TABLE room (room_id int (11) NOT NULL PRIMARY KEY, floor_level int (11), room_type_id int (11) NOT NULL REFERENCES room_type (room_type_id) ON DELETE NO ACTION ON UPDATE NO ACTION MATCH SIMPLE);
  1283.  
  1284. -- Table: room_type
  1285. DROP TABLE IF EXISTS room_type;
  1286. CREATE TABLE room_type (room_type_id int (11) NOT NULL PRIMARY KEY, description varchar (60));
  1287.  
  1288. -- Table: senior_high_school_student
  1289. DROP TABLE IF EXISTS senior_high_school_student;
  1290. CREATE TABLE senior_high_school_student (s_hs_id_number int (11) NOT NULL PRIMARY KEY, track varchar (30));
  1291.  
  1292. -- Table: staff
  1293. DROP TABLE IF EXISTS staff;
  1294. CREATE TABLE staff (staff_id int (11) NOT NULL PRIMARY KEY, name_id int (11) NOT NULL REFERENCES staff_name (name_staff_id) ON DELETE RESTRICT ON UPDATE RESTRICT MATCH SIMPLE, birth_date date, contact_id int (11) NOT NULL REFERENCES contact (contact_id) ON DELETE RESTRICT ON UPDATE RESTRICT MATCH SIMPLE, cred_id int (11) NOT NULL REFERENCES credentials (cred_id) ON DELETE RESTRICT ON UPDATE RESTRICT MATCH SIMPLE, photo BLOB);
  1295.  
  1296.  
  1297. -- Table: staff_name
  1298. DROP TABLE IF EXISTS staff_name;
  1299. CREATE TABLE staff_name (name_staff_id int (11) NOT NULL PRIMARY KEY, first_name varchar (60), mid_name varchar (60), last_name varchar (60));
  1300.  
  1301. -- Table: student_user
  1302. DROP TABLE IF EXISTS student_user;
  1303. CREATE TABLE student_user (s_id_number int (11) NOT NULL PRIMARY KEY,type varchar (60));
  1304.  
  1305. -- Table: users
  1306. DROP TABLE IF EXISTS users;
  1307. CREATE TABLE users (id_number int (11) NOT NULL PRIMARY KEY, first_name varchar (30), mid_name varchar (30), last_name varchar (30), dep_id int (11) NOT NULL REFERENCES department (dep_id) ON DELETE RESTRICT ON UPDATE RESTRICT MATCH SIMPLE);
  1308.  
  1309. COMMIT TRANSACTION;
  1310. PRAGMA foreign_keys = on;
  1311. "
  1312. End Function
  1313.  
  1314. #End Region
  1315. #Region "Authentication Related Functions"
  1316. Public Sub Session(b As Boolean)
  1317. conf.SetValue("Misc Configuration", "Session", hash.EncryptData(b))
  1318. End Sub
  1319. Public Sub setSession(id As Integer, username As String, name As String, email As String, phone As String, privilege As Integer, photo As Object)
  1320. If (CBool(hash.DecryptData(conf.GetValue("Misc Configuration", "Session")))) Then
  1321. conf.SetValue("Misc Configuration", "SessionString", hash.EncryptData(id & ";" & username & ";" & email & ";" & privilege & ";" & name & ";" & phone & photo))
  1322. End If
  1323. End Sub
  1324.  
  1325. Public Function getSession(session As String)
  1326. Try
  1327. If (CBool(hash.DecryptData(conf.GetValue("Misc Configuration", "Session")))) Then
  1328. Dim s() As String = Split(hash.DecryptData(conf.GetValue("Misc Configuration", "SessionString")), ";")
  1329. Select Case session
  1330. Case "id"
  1331. Return s(0)
  1332. Case "username"
  1333. Return s(1)
  1334. Case "email"
  1335. Return s(2)
  1336. Case "privilege"
  1337. Return s(3)
  1338. Case "name"
  1339. Return s(4)
  1340. Case "phone"
  1341. Return s(5)
  1342. Case "photo"
  1343. Return s(6)
  1344. Case Else
  1345. Return String.Empty
  1346. End Select
  1347. Else
  1348. Return String.Empty
  1349. End If
  1350. Catch ex As Exception
  1351. Return String.Empty
  1352. 'Logs
  1353. End Try
  1354. End Function
  1355.  
  1356. Public Sub deployAccount()
  1357. Try
  1358. Dim name As String = If(getSession("name") = " ", "Not Available", getSession("name"))
  1359. Dim type As String = If(getSession("privilege") = String.Empty, getAccountType(1), getAccountType(CInt(getSession("privilege"))))
  1360. Dim email As String = If(getSession("email") = String.Empty, "Not Available", getSession("email"))
  1361. Dim phone As String = If(getSession("phone") = String.Empty, "Not Available", getSession("phone"))
  1362. Dim username As String = If(getSession("username") = String.Empty, "Not Available", getSession("username"))
  1363. Dim id As String = If(getSession("id") = String.Empty, "Not Available", getSession("id"))
  1364. 'MainWindow UI Text
  1365. MainWindow.Instance.l_account_name.Content = name
  1366. MainWindow.Instance.l_account_type.Content = type
  1367. MainWindow.Instance.l_account_email.Content = email
  1368. MainWindow.Instance.acc_name.Content = username
  1369. MainWindow.Instance.acc_name.ToolTip = If(getSession("name") = " ", "Try to add Preference", getSession("name"))
  1370. 'Settings UI Text
  1371. Settings.Instance.l_account_name_if.Content = name
  1372. Settings.Instance.l_account_name_b_if.Content = name
  1373. Settings.Instance.l_account_name.Content = name
  1374. Settings.Instance.l_account_phone_if.Content = phone
  1375. Settings.Instance.l_account_privilage_if.Content = type
  1376. Settings.Instance.l_account_type.Content = type
  1377. Settings.Instance.l_account_type_if.Content = type
  1378. Settings.Instance.l_account_username_if.Content = username
  1379. Settings.Instance.l_account_id_if.Content = id
  1380. Settings.Instance.l_account_email_if.Content = email
  1381. Catch ex As Exception
  1382. MsgBox("Opps, Something went wrong", "Account Deployment")
  1383. End Try
  1384.  
  1385. End Sub
  1386.  
  1387. Public Sub deployClean()
  1388. MainWindow.Instance.l_account_name.Content = String.Empty
  1389. MainWindow.Instance.l_account_type.Content = String.Empty
  1390. MainWindow.Instance.l_account_email.Content = String.Empty
  1391. MainWindow.Instance.acc_name.Content = String.Empty
  1392. MainWindow.Instance.acc_name.ToolTip = String.Empty
  1393. MainWindow.Instance.tb_login_username.Text = String.Empty
  1394. MainWindow.Instance.pb_password.Password = String.Empty
  1395. Settings.Instance.l_account_name_b_if.Content = String.Empty
  1396. Settings.Instance.l_account_name.Content = String.Empty
  1397. Settings.Instance.l_account_phone_if.Content = String.Empty
  1398. Settings.Instance.l_account_privilage_if.Content = String.Empty
  1399. Settings.Instance.l_account_type.Content = String.Empty
  1400. Settings.Instance.l_account_type_if.Content = String.Empty
  1401. Settings.Instance.l_account_username_if.Content = String.Empty
  1402. Settings.Instance.l_account_id_if.Content = String.Empty
  1403. Settings.Instance.l_account_email_if.Content = String.Empty
  1404. conf.RemoveEntry("Misc Configuration", "SessionString")
  1405. Settings.Instance.b_Add_Accounts.Visibility = Visibility.Collapsed
  1406. Settings.Instance.gb_accounts.Visibility = Visibility.Collapsed
  1407. End Sub
  1408.  
  1409. Public Function getAccountType(p As Integer) As String
  1410. Select Case p
  1411. Case 0
  1412. Settings.Instance.b_Add_Accounts.Visibility = Visibility.Visible
  1413. Settings.Instance.gb_accounts.Visibility = Visibility.Visible
  1414. Return "Administrator"
  1415. Case 1
  1416. Settings.Instance.gb_accounts.Visibility = Visibility.Collapsed
  1417. Return "Staff"
  1418. Case 3
  1419. Return "Developer"
  1420. Case Else
  1421. Return "Visitor"
  1422. End Select
  1423. p = Nothing
  1424. End Function
  1425. #End Region
  1426. #Region "Misc Related"
  1427. Public Sub setMiscEnable()
  1428. conf.SetValue("Misc Configuration", "status", True)
  1429. conf.SetValue("Misc Configuration", "defualt_background", MainWindow.Instance.lockscreen.Background)
  1430. End Sub
  1431.  
  1432. Public Sub setmysqlStatus(status As Boolean)
  1433. conf.SetValue("Misc Configuration", "mysql_status", status)
  1434. End Sub
  1435.  
  1436. Public Function getmysqlStatus() As Boolean
  1437. Return conf.GetValue("Misc Configuration", "mysql_status")
  1438. End Function
  1439.  
  1440.  
  1441. Public Function filter(str As String) As String
  1442. Return Regex.Replace(str, "[^a-zA-Z ]", "")
  1443. End Function
  1444. Public Function filterNum(str As String) As String
  1445. Return Regex.Replace(str, "[^0-9 ]", "")
  1446. End Function
  1447.  
  1448. Public Function Byte2Image(ByVal byteArr() As Byte) As System.Drawing.Image
  1449.  
  1450. Using ImageStream As New MemoryStream(byteArr)
  1451. Dim newImage As System.Drawing.Image
  1452. Try
  1453. If byteArr.GetUpperBound(0) > 0 Then
  1454. newImage = System.Drawing.Image.FromStream(ImageStream)
  1455. Else
  1456. newImage = Nothing
  1457. End If
  1458. Catch ex As Exception
  1459. newImage = Nothing
  1460. End Try
  1461. Return newImage
  1462. End Using
  1463.  
  1464. End Function
  1465. Public Function getVersion() As String
  1466. Return "v"
  1467. End Function
  1468. #End Region
  1469.  
  1470. End Class
  1471.  
  1472.  
  1473. Imports System.ComponentModel
  1474. Imports System.Data.SQLite
  1475. Imports MySql.Data.MySqlClient
  1476.  
  1477. Public Class daemon
  1478.  
  1479. Public Shared m_instance As daemon
  1480. Public connectivity As BackgroundWorker = New BackgroundWorker
  1481. Public tablesInstaller As BackgroundWorker = New BackgroundWorker
  1482. Public SettingsSQL As New MySqlConnection
  1483.  
  1484. Dim incPub As Integer
  1485. Dim connector As New SQLConnector()
  1486. Dim create As String
  1487. Dim command As String
  1488. Dim com() As String
  1489. Dim sql As MySqlConnection
  1490.  
  1491.  
  1492.  
  1493. Public Shared ReadOnly Property setter() As daemon
  1494. Get
  1495. Return m_instance
  1496. End Get
  1497. End Property
  1498. Public Sub daemon_onLoad() Handles Me.Loaded
  1499. m_instance = Me
  1500. End Sub
  1501.  
  1502. Public Sub New()
  1503. InitializeComponent()
  1504. connectivity.WorkerReportsProgress = True
  1505. connectivity.WorkerSupportsCancellation = True
  1506. tablesInstaller.WorkerReportsProgress = True
  1507. tablesInstaller.WorkerSupportsCancellation = True
  1508. AddHandler connectivity.DoWork, AddressOf dsc_DoQuery
  1509. AddHandler connectivity.RunWorkerCompleted, AddressOf dsc_RunQueryCompleted
  1510. AddHandler tablesInstaller.DoWork, AddressOf tables_DoQuery
  1511. AddHandler tablesInstaller.RunWorkerCompleted, AddressOf tables_RunQueryCompleted
  1512. End Sub
  1513. Public Sub connecting()
  1514. MainWindow.Instance.sql_status.Content = "Connecting..."
  1515. MainWindow.Instance.db_type_status.ToolTip = "Connecting to Network"
  1516. MainWindow.Instance.MainSnackBar("Connecting..", 3)
  1517. MainWindow.Instance.FlyoutSnackBar("Connecting..", 3)
  1518. End Sub
  1519. Public Sub connected()
  1520. MainWindow.Instance.sql_status.Content = "Network Connected"
  1521. MainWindow.Instance.db_type_status.ToolTip = "Currently Connected to Network"
  1522. MainWindow.Instance.MainSnackBar("Connected", 3)
  1523. MainWindow.Instance.FlyoutSnackBar("Connected", 3)
  1524. If config.io.getmysqlStatus() Then
  1525. SettingsSQL.ChangeDatabase(config.io.conf.GetValue("Database", "dbname"))
  1526. Settings.Instance.l_database.Content = SettingsSQL.Database
  1527. Settings.Instance.gb_dm_mysql.Visibility = Visibility.Visible
  1528. Else
  1529. database_installation()
  1530. End If
  1531. End Sub
  1532. Public Sub disconnected()
  1533. MainWindow.Instance.sql_status.Content = "Disconnected"
  1534. MainWindow.Instance.db_type_status.ToolTip = "Unable to connect to specified network"
  1535. MainWindow.Instance.MainSnackBar("Disconnected", 3)
  1536. MainWindow.Instance.FlyoutSnackBar("Disconnected", 3)
  1537. End Sub
  1538. Public Sub retry_disconnected()
  1539. MainWindow.Instance.sql_status.Content = "Disconnected"
  1540. MainWindow.Instance.db_type_status.ToolTip = "Click to Reconnect"
  1541. MainWindow.Instance.MainSnackBar("Disconnected", 3)
  1542. MainWindow.Instance.FlyoutSnackBar("Disconnected", 3)
  1543. End Sub
  1544. Public Sub retry_connecting()
  1545. MainWindow.Instance.sql_status.Content = "Connecting..."
  1546. MainWindow.Instance.db_type_status.ToolTip = "Retrying to connect"
  1547. MainWindow.Instance.MainSnackBar("
  1548. Connecting", 3)
  1549. MainWindow.Instance.FlyoutSnackBar("Connecting..", 3)
  1550. End Sub
  1551.  
  1552. 'Background Worker for SQL Connection State
  1553. Public Sub dsc_DoQuery(ByVal sender As Object, ByVal e As DoWorkEventArgs)
  1554. Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
  1555. While SettingsSQL.Ping
  1556. If connectivity.CancellationPending = True Then
  1557. e.Cancel = True
  1558. Exit While
  1559. Else
  1560. System.Threading.Thread.Sleep(3000)
  1561. database_c_update()
  1562. End If
  1563. End While
  1564. End Sub
  1565. Public Sub dsc_RunQueryCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
  1566. If (SettingsSQL.State = Data.ConnectionState.Closed) Then
  1567. If connectivity.IsBusy = True Then
  1568. connectivity.CancelAsync()
  1569. database_c_update()
  1570. End If
  1571. End If
  1572. database_c_update()
  1573. MainWindow.Instance.MainSnackBar("Connection Interupted", 4)
  1574. End Sub
  1575.  
  1576. 'Background Installation DB Tables
  1577. Public Sub tables_DoQuery(ByVal sender As Object, ByVal e As DoWorkEventArgs)
  1578. Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
  1579. Try
  1580. Dim cmdDB As New MySqlCommand(create, sql)
  1581. cmdDB.ExecuteNonQuery()
  1582. Dim cmdTables As New MySqlCommand()
  1583. For index = 0 To com.Length
  1584. If connectivity.CancellationPending = True Then
  1585. e.Cancel = True
  1586. Exit For
  1587. Else
  1588. Try
  1589. cmdTables.Connection = sql
  1590. cmdTables.CommandText = com(index)
  1591. cmdTables.ExecuteNonQuery()
  1592. Settings.Instance.l_deamon_status.Content = "Creating Tables " & index & " of " & com.Length & "tables"
  1593. Catch ex As Exception
  1594. 'TODO Logs
  1595. Finalize()
  1596. End Try
  1597. System.Threading.Thread.Sleep(500)
  1598. End If
  1599. Next
  1600. sql.Close()
  1601. Catch ex As MySqlException
  1602. 'Todo Installation Logs
  1603. Catch exc As Exception
  1604. 'Todo Installation Logs
  1605. End Try
  1606. End Sub
  1607. Public Sub tables_RunQueryCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
  1608. MainWindow.Instance.MainSnackBar("Tables Created", 2)
  1609. config.io.conf.SetValue("Misc Configuration", "mysql_status", True)
  1610. config.io.setDBShared(Settings.Instance.tb_p_db_server.Text, Settings.Instance.tb_p_db_server_port.Text, Settings.Instance.tb_p_db_server_username.Text, Settings.Instance.tb_p_db_server_password.Password, config.io.conf.GetValue("Database", "dbname"))
  1611. Settings.Instance.database_tc_status(4)
  1612. daemon.setter.SettingsSQL = connector.ConnectDB(config.io.getmysqlStatus())
  1613. daemon.setter.connectivity.RunWorkerAsync()
  1614. daemon.setter.database_c_update()
  1615. MainWindow.Instance.FlyoutSnackBar("Saved", 3)
  1616. Settings.Instance.l_deamon_status.Content = "Exporting Credentials"
  1617. Settings.Instance.l_deamon_status.Content = "Connecting..."
  1618. exportAdmin()
  1619. MainWindow.Instance.FlyoutSnackBar("Credential Syncronized", 3)
  1620. End Sub
  1621.  
  1622.  
  1623.  
  1624. Public Sub database_c_update()
  1625. Try
  1626. If (SettingsSQL.State) Then
  1627. Settings.Instance.l_version.Content = SettingsSQL.ServerVersion
  1628. Settings.Instance.l_host.Content = Settings.Instance.tb_p_db_server.Text
  1629. Settings.Instance.l_port.Content = Settings.Instance.tb_p_db_server_port.Text
  1630. connected()
  1631. Else
  1632. Settings.Instance.l_database.Content = ""
  1633. Settings.Instance.gb_dm_mysql.Visibility = Visibility.Collapsed
  1634. Settings.Instance.database_tc_status(2)
  1635. retry_disconnected()
  1636. End If
  1637. Catch ex As System.InvalidOperationException
  1638. Finalize()
  1639. Catch etcEx As Exception
  1640. Finalize()
  1641. End Try
  1642. End Sub
  1643.  
  1644. Public Sub database_installation()
  1645. Try
  1646. config.io.conf.SetValue("Database", "dbname", config.io.getInitDB() & 0)
  1647. Dim setconf() As String = Split(config.io.getDBShared(), ",")
  1648. Dim reg_dbname As String = If(Not setconf(4) = "", setconf(4), config.io.getInitDB() & 0)
  1649. Dim db_version() As String = Split(reg_dbname, "v")
  1650. If (isDBExist(reg_dbname)) Then
  1651. If MessageBox.Show("Another database exist " & Environment.NewLine & "Create new database? Yes or No to use the existing. ", "Old Database Exists", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
  1652. Dim temp As Integer = 0
  1653. While Not config.io.getmysqlStatus
  1654. If isDBExist(config.io.getInitDB() & temp) Then
  1655. temp = temp + 1
  1656. Else
  1657. database_creation(temp)
  1658. config.io.conf.SetValue("Database", "dbname", config.io.getInitDB() & temp)
  1659. Settings.Instance.l_deamon_status.Content = "Database Created"
  1660. Exit While
  1661. End If
  1662. End While
  1663. Else
  1664. config.io.conf.SetValue("Database", "dbname", config.io.getInitDB() & CInt(db_version(1)))
  1665. exportAdmin()
  1666. End If
  1667. Else
  1668. config.io.conf.SetValue("Database", "dbname", config.io.getInitDB() & CInt(db_version(1)))
  1669. database_creation(CInt(db_version(1)))
  1670. exportAdmin()
  1671. End If
  1672. Catch ex As Exception
  1673. 'todo installation logs
  1674. End Try
  1675. End Sub
  1676.  
  1677. Public Function isDBExist(dbname As String) As Boolean
  1678. Try
  1679. Dim sql As MySqlConnection = connector.ConnectDB(False)
  1680. Dim isCreated As New MySqlCommand("SHOW DATABASES LIKE '" & dbname & "';", sql)
  1681. Dim sqlReader As MySqlDataReader = isCreated.ExecuteReader()
  1682. Return sqlReader.Read()
  1683. sql.Close()
  1684. Catch ex As MySqlException
  1685. Return False
  1686. End Try
  1687. End Function
  1688.  
  1689. Public Sub database_creation(inc As Integer)
  1690. If Not (tablesInstaller.IsBusy) Then
  1691. create = config.io.setDBCreate(inc)
  1692. command = config.io.getDBTablesCommand()
  1693. com = Split(command, ";")
  1694. sql = connector.ConnectDB(config.io.getmysqlStatus())
  1695. tablesInstaller.RunWorkerAsync()
  1696. End If
  1697. End Sub
  1698.  
  1699. Private Sub exportAdmin()
  1700. Dim sql As New MySqlConnection()
  1701. sql = connector.ConnectDB(True)
  1702. Dim export As New MySqlCommand("INSERT INTO staff_name (name_staff_id) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ");
  1703. INSERT INTO contact(contact_id, email_add) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ", '" & config.io.hash.DecryptData((config.io.conf.GetValue("Account", "email"))) & "');
  1704. INSERT INTO credentials(cred_id, username, password, privilege) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ", '" & config.io.hash.DecryptData((config.io.conf.GetValue("Account", "username"))) & "', '" & config.io.conf.GetValue("Account", "password") & "', " & config.io.conf.GetValue("Account", "type") & ");
  1705. INSERT INTO staff(staff_id, name_id, cred_id,contact_id) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & "," & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & "," & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & "," & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ")", sql)
  1706. sql.Close()
  1707. End Sub
  1708.  
  1709. Public Sub connectSQLite()
  1710. Try
  1711. Dim dbConnection As SQLiteConnection = connector.ConnectDBSQLI()
  1712. Dim cmd As New SQLiteCommand(config.io.getDBSQLITablesCommand, dbConnection)
  1713. cmd.ExecuteNonQuery()
  1714. dbConnection.Close()
  1715. config.io.conf.SetValue("Misc Configuration", "sqli_status", True)
  1716. Catch ex As Exception
  1717. MsgBox(ex.ToString)
  1718. End Try
  1719. End Sub
  1720. Public Sub exportAdminSQLi()
  1721. Dim sqli As New SQLiteConnection()
  1722. sqli = connector.ConnectDBSQLI()
  1723. Dim export As New SQLiteCommand("INSERT INTO contact (contact_id, email_add) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ", '" & config.io.hash.DecryptData((config.io.conf.GetValue("Account", "email"))) & "');
  1724. INSERT INTO credentials (cred_id, username, password, privilege) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ", '" & config.io.hash.DecryptData((config.io.conf.GetValue("Account", "username"))) & "', '" & config.io.conf.GetValue("Account", "password") & "', " & config.io.conf.GetValue("Account", "type") & ");
  1725. INSERT INTO staff_name (name_staff_id) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ");
  1726. INSERT INTO staff (staff_id, name_id, contact_id, cred_id) VALUES (" & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ", " & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & "," & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ", " & config.io.hash.DecryptData(config.io.conf.GetValue("Account", "user_id")) & ");", sqli)
  1727. export.ExecuteNonQuery()
  1728. sqli.Close()
  1729. End Sub
  1730.  
  1731. Private Sub logger(err As Object)
  1732. If Not System.IO.Directory.Exists(System.Windows.Forms.Application.UserAppDataPath & "\Reserfy Local Database\") Then
  1733. System.IO.Directory.CreateDirectory(System.Windows.Forms.Application.UserAppDataPath & "\Logs\")
  1734. End If
  1735. End Sub
  1736.  
  1737. End Class
  1738. Imports System.Data.SQLite
  1739.  
  1740. Public Class DashBoard
  1741. Private Sub DashBoard_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
  1742. availableRoomRefresh()
  1743. End Sub
  1744.  
  1745. Private Sub Add_Room(sender As Object, e As RoutedEventArgs)
  1746. Add_Rooms.IsOpen = True
  1747. End Sub
  1748.  
  1749. Private Sub Refresh_Rooms(sender As Object, e As RoutedEventArgs)
  1750. availableRoomRefresh()
  1751. End Sub
  1752.  
  1753. Private Sub Delete_Room(sender As Object, e As RoutedEventArgs)
  1754. Delete_Rooms.IsOpen = True
  1755. updateDelList()
  1756. End Sub
  1757.  
  1758. Private Sub b_reset_Click(sender As Object, e As RoutedEventArgs)
  1759. clear()
  1760. MainWindow.Instance.MainSnackBar("Fields Reseted", 3)
  1761. End Sub
  1762.  
  1763. Private Sub b_save_Click(sender As Object, e As RoutedEventArgs)
  1764. Try
  1765. If String.IsNullOrEmpty(tb_room_name.Text) Then
  1766. MainWindow.Instance.MainSnackBar("Floor Field Rquired", 3)
  1767. End If
  1768. If String.IsNullOrEmpty(nud_floor.Value) Then
  1769. MainWindow.Instance.MainSnackBar("Room Field Rquired", 3)
  1770. End If
  1771. If Not (String.IsNullOrEmpty(tb_room_name.Text) Or String.IsNullOrEmpty(nud_floor.Value)) Then
  1772. Add_Rooms.IsOpen = False
  1773. AddRoom()
  1774. availableRoomRefresh()
  1775. End If
  1776. Catch ex As Exception
  1777. MainWindow.Instance.MainSnackBar("Failed to Add", 3)
  1778. End Try
  1779. End Sub
  1780.  
  1781. Private Sub b_cancel_Click(sender As Object, e As RoutedEventArgs)
  1782. Add_Rooms.IsOpen = False
  1783. clear()
  1784. MainWindow.Instance.MainSnackBar("Action Canceled", 3)
  1785. End Sub
  1786.  
  1787. Private Sub clear()
  1788. nud_floor.Value = Nothing
  1789. tb_room_name.Clear()
  1790. End Sub
  1791.  
  1792. Private Sub AddRoom()
  1793. Dim Connector As New SQLConnector()
  1794. Dim id As Integer
  1795. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  1796.  
  1797. Else
  1798. Try
  1799. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  1800. Dim rmd As New SQLiteCommand("SELECT max(room_type_id) FROM room_type", sqli)
  1801. Dim dr As SQLiteDataReader = rmd.ExecuteReader()
  1802. While dr.Read
  1803. id = CInt(If(IsDBNull(dr(0)), 0, dr(0)))
  1804. End While
  1805. Dim cmd As New SQLiteCommand("INSERT INTO room_type(room_type_id, description) values ('" & id + 1 & "','" & tb_room_name.Text & "')", sqli)
  1806. Dim cmd2 As New SQLiteCommand("INSERT INTO room(room_id, floor_level, room_type_id) values ('" & id + 1 & "', '" & nud_floor.Value & "', '" & id + 1 & "')", sqli)
  1807. cmd.ExecuteNonQuery()
  1808. cmd2.ExecuteNonQuery()
  1809. clear()
  1810. MainWindow.Instance.MainSnackBar("Room Added", 3)
  1811. Catch ex As SQLiteException
  1812. MainWindow.Instance.MainSnackBar("Adding Failed", 3)
  1813. Catch ex As Exception
  1814. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  1815. End Try
  1816. End If
  1817. End Sub
  1818.  
  1819. Private Sub availableRoomRefresh()
  1820. available_rooms.Children.Clear()
  1821. Dim Connector As New SQLConnector()
  1822. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  1823.  
  1824. Else
  1825. Try
  1826. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  1827. Dim rmd As New SQLiteCommand("SELECT * From room", sqli)
  1828. Dim dr As SQLiteDataReader = rmd.ExecuteReader()
  1829. While dr.Read()
  1830. Dim room As New card()
  1831. Dim rmd1 As New SQLiteCommand("SELECT * From room_type Where room_type_id =" & dr("room_type_id").ToString, sqli)
  1832. Dim dr1 As SQLiteDataReader = rmd1.ExecuteReader()
  1833. While dr1.Read
  1834. room.l_room_name.Content = dr1("description").ToString
  1835. End While
  1836. room.status.Tag = dr("room_id").ToString & ":" & dr("floor_level").ToString & ":" & dr("room_type_id").ToString
  1837. AddHandler room.status.Click, AddressOf Room_Status_Clicked
  1838. available_rooms.Children.Add(room)
  1839. End While
  1840. Catch ex As SQLiteException
  1841. MainWindow.Instance.MainSnackBar("Refresh Failed", 3)
  1842. Catch ex As Exception
  1843. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  1844. End Try
  1845. End If
  1846. End Sub
  1847.  
  1848.  
  1849. Private Sub updateDelList()
  1850. cb_del.Items.Clear()
  1851. Dim Connector As New SQLConnector()
  1852. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  1853.  
  1854. Else
  1855. Try
  1856. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  1857. Dim rmd As New SQLiteCommand("SELECT * From room", sqli)
  1858. Dim dr As SQLiteDataReader = rmd.ExecuteReader()
  1859. While dr.Read()
  1860. Dim rmd1 As New SQLiteCommand("SELECT * From room_type Where room_type_id =" & dr("room_type_id").ToString, sqli)
  1861. Dim dr1 As SQLiteDataReader = rmd1.ExecuteReader()
  1862. While dr1.Read
  1863. cb_del.Items.Add(dr1("description").ToString)
  1864. End While
  1865. End While
  1866. Catch ex As SQLiteException
  1867. MainWindow.Instance.MainSnackBar("Refresh Failed", 3)
  1868. Catch ex As Exception
  1869. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  1870. End Try
  1871. End If
  1872. End Sub
  1873. Private Sub Room_Status_Clicked(ByVal sender As Object, ByVal e As RoutedEventArgs)
  1874. If e.Source.GetType Is GetType(Button) Then
  1875. MsgBox(sender.Tag)
  1876. End If
  1877. End Sub
  1878.  
  1879. Private Sub b_d_cancel_Click(sender As Object, e As RoutedEventArgs)
  1880. Delete_Rooms.IsOpen = False
  1881. cb_del.Text = Nothing
  1882. End Sub
  1883.  
  1884. Private Sub b_d_Delete_Click(sender As Object, e As RoutedEventArgs)
  1885. Dim Connector As New SQLConnector()
  1886. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  1887.  
  1888. Else
  1889. Try
  1890. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  1891. Dim rdr As New SQLiteCommand("SELECT room_type_id From room_type Where description = '" & cb_del.SelectedValue & "'", sqli)
  1892. Dim dr As SQLiteDataReader = rdr.ExecuteReader()
  1893. While dr.Read()
  1894. Dim cmd As New SQLiteCommand("DELETE FROM `room` WHERE `room_type_id` = " & dr("room_type_id"), sqli)
  1895. cmd.ExecuteNonQuery()
  1896. Dim cmd2 As New SQLiteCommand("DELETE FROM `room_type` WHERE `room_type_id` = " & dr("room_type_id"), sqli)
  1897. cmd2.ExecuteNonQuery()
  1898. availableRoomRefresh()
  1899. Delete_Rooms.IsOpen = False
  1900. MainWindow.Instance.MainSnackBar("Room Removed", 3)
  1901. End While
  1902.  
  1903. Catch ex As SQLiteException
  1904. MainWindow.Instance.MainSnackBar("Failed Remove", 3)
  1905. Catch ex As Exception
  1906. MainWindow.Instance.MainSnackBar("Something Went Wrong", 3)
  1907. End Try
  1908. End If
  1909. End Sub
  1910. End Class
  1911. Imports MySql.Data.MySqlClient
  1912. Imports AMS.Profile
  1913. Imports Reserfy_App.SettingsHelper
  1914.  
  1915. Public Class Database
  1916.  
  1917. Private XMLConfig As New ConfigurationHelper()
  1918. Private settingsXML As Xml = XMLConfig.SettingsConfigXML()
  1919. Private settingsRegistry As Registry = XMLConfig.SettingsConfigRegistry()
  1920. Private settingsHash As Cypher = XMLConfig.SettingsHashWrapper()
  1921. Private mainConnection As MySqlConnection
  1922.  
  1923. Private Sub rb_personal_Checked(sender As Object, e As RoutedEventArgs) Handles rb_personal.Checked
  1924. tc_db_status(1)
  1925. End Sub
  1926.  
  1927. Private Sub b_p_browse_Click(sender As Object, e As RoutedEventArgs) Handles b_p_browse.Click
  1928. Dim location As New System.Windows.Forms.FolderBrowserDialog()
  1929. Dim result As System.Windows.Forms.DialogResult = location.ShowDialog()
  1930. If result Then
  1931. tb_p_db_location.Text = location.SelectedPath
  1932. End If
  1933. End Sub
  1934.  
  1935. Private Function rb_personal_verififcation()
  1936. If Not (tb_p_db_location.Text Like "") Then
  1937. Return True
  1938. Else
  1939. Return False
  1940. End If
  1941. End Function
  1942.  
  1943. Private Sub rb_shared_Checked(sender As Object, e As RoutedEventArgs) Handles rb_shared.Checked
  1944. tc_db_status(2)
  1945. End Sub
  1946.  
  1947. Private Sub tc_db_status(index As Integer)
  1948. tc_db_connections.SelectedIndex = index
  1949. End Sub
  1950.  
  1951. Public Function db_c_update()
  1952. If (mainConnection.State) Then
  1953. l_version.Content = mainConnection.ServerVersion
  1954. l_database.Content = mainConnection.Database
  1955. l_host.Content = tb_p_db_server.Text
  1956. l_port.Content = tb_p_db_server_port.Text
  1957. Else
  1958. l_version.Content = "Can't get Server Version"
  1959. l_database.Content = "Database Unknown"
  1960. l_host.Content = tb_p_db_server.Text
  1961. l_port.Content = tb_p_db_server_port.Text
  1962. End If
  1963. Return mainConnection.State
  1964. End Function
  1965.  
  1966.  
  1967. Private Async Sub b_db_connection_save_Click(sender As Object, e As RoutedEventArgs) Handles b_db_connection_save.Click
  1968. Dim connector As New SQLConnector()
  1969. If (rb_personal.IsChecked = True) Then
  1970. If rb_personal_verififcation() Then
  1971. personal_save_config()
  1972. Else
  1973. 'TODO Prompt Empty DB Location Error
  1974. End If
  1975. ElseIf (rb_shared.IsChecked = True)
  1976. tc_db_status(3)
  1977. Dim status = Await connector.shared_try_config(tb_p_db_server.Text, tb_p_db_server_port.Text, tb_p_db_server_username.Text, tb_p_db_server_password.Password)
  1978. If (status) Then
  1979. rb_personal.IsEnabled = False
  1980. b_db_connection_save.IsEnabled = False
  1981. tc_db_status(4)
  1982. shared_save_config()
  1983. connector.ConnectDB()
  1984. Else
  1985. tc_db_status(2)
  1986. End If
  1987. settingsRegistry.SetValue("db_shared", "status", status)
  1988. db_c_update()
  1989. End If
  1990. End Sub
  1991.  
  1992.  
  1993. Private Sub b_db_management_import_Click(sender As Object, e As RoutedEventArgs) Handles b_db_management_import.Click
  1994.  
  1995. End Sub
  1996.  
  1997. Private Sub b_db_management_export_Click(sender As Object, e As RoutedEventArgs) Handles b_db_management_export.Click
  1998.  
  1999. End Sub
  2000.  
  2001. Private Sub b_db_management_delete_Click(sender As Object, e As RoutedEventArgs) Handles b_db_management_delete.Click
  2002.  
  2003. End Sub
  2004.  
  2005.  
  2006. Private Sub personal_save_config()
  2007. settingsXML.Buffer()
  2008. settingsXML.SetValue("db", "status", "personal")
  2009. settingsXML.RemoveSection("db_shared")
  2010. settingsRegistry.RemoveSection("db_shared")
  2011. settingsXML.SetValue("db_personal", "location", tb_p_db_location.Text)
  2012. End Sub
  2013.  
  2014.  
  2015.  
  2016. Private Sub shared_save_config()
  2017. settingsXML.Buffer()
  2018. settingsXML.SetValue("db", "status", "shared")
  2019. settingsXML.RemoveSection("db_personal")
  2020. settingsXML.SetValue("db_shared", "servername", tb_p_db_server.Text)
  2021. settingsXML.SetValue("db_shared", "port", If(tb_p_db_server_port.Text Like "", 3306, tb_p_db_server_port.Text))
  2022. 'For Security Reasons Database Username And Password Are Not Save same as other configurations
  2023. settingsRegistry.SetValue("db_shared", "username", settingsHash.EncryptData(tb_p_db_server_username.Text))
  2024. settingsRegistry.SetValue("db_shared", "password", settingsHash.EncryptData(tb_p_db_server_password.Password))
  2025. End Sub
  2026.  
  2027.  
  2028. End Class
  2029. Public Class DayBox
  2030.  
  2031. Private _myReservationsList As New List(Of Reservation)
  2032. Public Sub SetReservations()
  2033. '-- Use whatever function you want to load the MonthReservations list, I happen to have a list filled by linq that has
  2034. ' many (possibly the past several years) of them loaded, so i filter to only pass the ones showing up in the displayed
  2035. ' month. Note that the "setter" for MonthReservations also triggers a redraw of the display.
  2036. Dim SetReservation As New cldr.Calendar
  2037. SetReservation.Reservation_Calendar.MonthAppointments = _myReservationsList.FindAll(
  2038. New System.Predicate(Of Reservation)(
  2039. Function(apt As Reservation) _
  2040. apt.StartTime IsNot Nothing AndAlso
  2041. CDate(apt.StartTime).Month = SetReservation.Reservation_Calendar.DisplayStartDate.Month AndAlso
  2042. CDate(apt.StartTime).Year = SetReservation.Reservation_Calendar.DisplayStartDate.Year))
  2043. End Sub
  2044.  
  2045. End Class
  2046. Public Class EventBadge
  2047.  
  2048. End Class
  2049. 
  2050.  
  2051.  
  2052. Public Class gridData
  2053.  
  2054. End Class
  2055. Public Class Home
  2056. Public Shared m_instance As Home
  2057. Public Shared ReadOnly Property Instance() As Home
  2058. Get
  2059. Return m_instance
  2060. End Get
  2061. End Property
  2062. Public Sub Config_onLoad() Handles Me.Loaded
  2063. m_instance = Me
  2064. End Sub
  2065. Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
  2066. MainActivity.Instance.HamburgerTab(2)
  2067. End Sub
  2068.  
  2069. Private Sub button_Copy_Click(sender As Object, e As RoutedEventArgs) Handles button_Copy.Click
  2070. MainActivity.Instance.HamburgerTab(1)
  2071. End Sub
  2072.  
  2073. Private Sub button_Copy1_Click(sender As Object, e As RoutedEventArgs) Handles button_Copy1.Click
  2074. MainActivity.Instance.HamburgerTab(3)
  2075. End Sub
  2076.  
  2077. Private Sub button_Copy2_Click(sender As Object, e As RoutedEventArgs) Handles button_Copy2.Click
  2078. MainWindow.Instance.FlyoutSettings.IsOpen = True
  2079. End Sub
  2080. End Class
  2081. Imports System.Threading
  2082. Imports MahApps.Metro.Controls
  2083. Imports MahApps.Metro.Controls.Dialogs
  2084. Public Class MainActivity
  2085. Public Shared m_instance As MainActivity
  2086.  
  2087. Private Sub uc_onload() Handles Me.Loaded
  2088. m_instance = Me
  2089. l_en_title.Content = config.io.conf.GetValue("Establisment", "name")
  2090. time_date()
  2091. End Sub
  2092. Public Shared ReadOnly Property Instance() As MainActivity
  2093. Get
  2094. Return m_instance
  2095. End Get
  2096. End Property
  2097. Private Sub AppMenu(sender As Object, e As ItemClickEventArgs)
  2098. HamburgerTab(HamburgerMenuControl.SelectedIndex)
  2099. If Me.HamburgerMenuControl.IsPaneOpen Then
  2100. Me.HamburgerMenuControl.IsPaneOpen = False
  2101. End If
  2102. End Sub
  2103.  
  2104. Public Sub HamburgerTab(index As Integer)
  2105. HamburgerTabControl.SelectedIndex = index
  2106. End Sub
  2107.  
  2108. Private Async Sub time_date()
  2109. Await Task.Delay(250)
  2110. l_date_time.Content = DateTime.Now.ToString("MMMM dd, yyyy h:mm:ss tt")
  2111. time_date()
  2112. End Sub
  2113.  
  2114. Private Sub AppOptions(sender As Object, e As ItemClickEventArgs)
  2115. Dim index As Integer = HamburgerMenuControl.SelectedOptionsIndex
  2116. If (index = 0) Then
  2117. If (MessageBox.Show("Logout?", "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes) Then
  2118. config.io.Session(False)
  2119. config.io.deployClean()
  2120. MainWindow.Instance.Auth_Window()
  2121. MainWindow.Instance.RemoveMainActivity()
  2122. Settings.Instance.loginBackground(config.io.conf.GetValue("Misc Configuration", "loginBackground"), False)
  2123. Else
  2124.  
  2125. End If
  2126. ElseIf (index = 1) Then
  2127. MainWindow.Instance.FlyoutSettings.IsOpen = True
  2128. End If
  2129. End Sub
  2130. End Class
  2131. Imports System.ComponentModel
  2132. Imports MySql.Data.MySqlClient
  2133. Imports System.Data.SQLite
  2134. Imports System.Threading
  2135.  
  2136. Public Class MainWindow
  2137.  
  2138. Private Shared m_instance As MainWindow
  2139. 'Authentication retry counts
  2140. Dim authCount As Integer = Nothing
  2141. Public Shared ReadOnly Property Instance() As MainWindow
  2142. Get
  2143. Return m_instance
  2144. End Get
  2145. End Property
  2146.  
  2147.  
  2148. 'Flyout Hyperlink Code
  2149. Private Sub Hyperlink_Account(sender As Object, e As RoutedEventArgs)
  2150. FlyoutSettings.IsOpen = True
  2151. FlyoutAccount.IsOpen = False
  2152. Settings.Instance.settingsMainTab.SelectedIndex = 1
  2153. End Sub
  2154. Private Sub auth_forgot_account(sender As Object, e As RoutedEventArgs)
  2155. tb_login_username.Clear()
  2156. pb_password.Clear()
  2157. tc_authentication.SelectedIndex = 1
  2158. End Sub
  2159. 'Tab Control Main App
  2160. Private Sub mw_tab_control(sender As Object, e As RoutedEventArgs) Handles AppMode.SelectionChanged
  2161. If AppMode.SelectedIndex = 3 Then
  2162. If Settings.Instance.rb_shared.IsChecked = True Then
  2163. db_type_status.Visibility = Visibility.Visible
  2164. Else
  2165. db_type_status.Visibility = Visibility.Collapsed
  2166. End If
  2167. RigthStatusBar.Visibility = Visibility.Visible
  2168. Else
  2169. RigthStatusBar.Visibility = Visibility.Collapsed
  2170. End If
  2171. End Sub
  2172. 'Windows Controls Code
  2173. Private Sub settingsFlyout(sender As Object, e As RoutedEventArgs) Handles FlyoutSettings.ClosingFinished
  2174. Settings.Instance.loginBackground(config.io.conf.GetValue("Misc Configuration", "loginBackground"), True)
  2175. Settings.Instance.i_image.Source = Nothing
  2176. Settings.Instance.image_profile_account.Source = Nothing
  2177. Dim t As New Thread(New ThreadStart(Sub()
  2178. Thread.Sleep(500)
  2179. GC.Collect()
  2180.  
  2181. End Sub))
  2182. t.Start()
  2183. End Sub
  2184.  
  2185. Private Sub settingsFlyoutOpen(sender As Object, e As RoutedEventArgs) Handles FlyoutSettings.IsOpenChanged
  2186. If FlyoutSettings.IsOpen Then
  2187. Settings.Instance.loginBackground(config.io.conf.GetValue("Misc Configuration", "loginBackground"), True)
  2188. MainWindow.Instance.lockscreen.Background = Nothing
  2189. Dim t As New Thread(New ThreadStart(Sub()
  2190. Thread.Sleep(500)
  2191. GC.Collect()
  2192.  
  2193. End Sub))
  2194. t.Start()
  2195. End If
  2196. End Sub
  2197.  
  2198. 'App Configuration Code
  2199. Private Function app_configure_verify()
  2200. 'Return Boolean Validation
  2201. Dim isValid As Boolean = True
  2202. 'User input initializations
  2203. Dim id1 As String = tb_new_id.Text
  2204. Dim p1 As String = pb_new_password.Password
  2205. Dim p2 As String = pb_set_password_retype.Password
  2206. Dim u1 As String = tb_new_username.Text
  2207. Dim e1 As String = tb_recovery_email.Text
  2208. 'User error handling initialization
  2209. If (id1 Like "") Then
  2210. id_error.Content = "ID Number must not be empty"
  2211. isValid = False
  2212. Else
  2213. Try
  2214. id1 = CInt(id1)
  2215. id_error.Content = ""
  2216. Catch ex As Exception
  2217. id_error.Content = "ID Number must be a number"
  2218. isValid = False
  2219. End Try
  2220. End If
  2221. If (u1 Like "") Then
  2222. username_error.Content = "Username must not be empty"
  2223. isValid = False
  2224. ElseIf (u1.Length > 20)
  2225. username_error.Content = "Username must 20 characters or less"
  2226. isValid = False
  2227. Else
  2228. username_error.Content = ""
  2229. End If
  2230. If (p1 Like "") Then
  2231. password_error.Content = "Password must not be empty"
  2232. isValid = False
  2233. ElseIf (p1.Length < 8)
  2234. password_error.Content = "Password must 8 characters or greater"
  2235. isValid = False
  2236. Else
  2237. password_error.Content = ""
  2238. End If
  2239. If Not (p1 Like p2) Then
  2240. retype_password_error.Content = "Password did not match"
  2241. isValid = False
  2242. Else
  2243. retype_password_error.Content = ""
  2244. End If
  2245. If (e1 Like "") Then
  2246. email_error.Content = "Recovery Email must not be empty"
  2247. isValid = False
  2248. Else
  2249. Try
  2250. Dim eAT() As String = Split(e1, "@")
  2251. Dim eDot() As String = Split(eAT(1), ".")
  2252. If (eAT(0) Like "" Or eDot(0) Like "" Or eDot(1) Like "") Then
  2253. email_error.Content = "Recovery Email is Invalid"
  2254. isValid = False
  2255. Else
  2256. email_error.Content = ""
  2257. End If
  2258. Catch ex As IndexOutOfRangeException
  2259. email_error.Content = "Recovery Email is Invalid"
  2260. isValid = False
  2261. End Try
  2262. End If
  2263. id1 = Nothing
  2264. p1 = Nothing
  2265. p2 = Nothing
  2266. u1 = Nothing
  2267. e1 = Nothing
  2268. Return isValid
  2269. End Function
  2270. Private Async Sub app_configure_data_save()
  2271. If (app_configure_verify()) Then
  2272. config.io.setDefaults()
  2273. config.io.setAdmin(tb_new_id.Text, tb_new_username.Text, pb_new_password.Password, tb_recovery_email.Text)
  2274. MainSnackBar("Preparing Login...", 2)
  2275. daemon.setter.connectSQLite()
  2276. daemon.setter.exportAdminSQLi()
  2277. Await Tasker.Delay(2)
  2278. Auth_Window()
  2279. End If
  2280. End Sub
  2281. Private Sub b_get_started_Click(sender As Object, e As RoutedEventArgs)
  2282. AppMode.SelectedIndex = 2
  2283. End Sub
  2284. 'Authentication Window
  2285. Private Sub b_login_Click(sender As Object, e As RoutedEventArgs)
  2286. If Not (tb_login_username.Text = String.Empty Or pb_password.Password = String.Empty) Then
  2287. Dim isLogin As Boolean = False
  2288. Dim staff_id As Integer = 0
  2289. Dim connector As New SQLConnector()
  2290. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  2291. Dim sql As MySqlConnection = connector.ConnectDB(True)
  2292. Try
  2293. Dim cmd As New MySqlCommand("SELECT * FROM `credentials` WHERE `username` LIKE '" & config.io.filter(tb_login_username.Text) & "' AND `password` LIKE '" & config.io.hash.EncryptData(pb_password.Password) & "';", sql)
  2294. Dim sqlReader As MySqlDataReader = cmd.ExecuteReader()
  2295. isLogin = sqlReader.Read()
  2296. staff_id = sqlReader("staff_id").ToString
  2297. sqlReader.Close()
  2298. cmd.Dispose()
  2299. sqlReader = Nothing
  2300. cmd = Nothing
  2301. Catch ex As Exception
  2302. MainSnackBar("Opps, Something went wrong. Try again", 3)
  2303. ex = Nothing
  2304. Finally
  2305. connector = Nothing
  2306. sql.Close()
  2307. sql.Dispose()
  2308. sql = Nothing
  2309. End Try
  2310. Else
  2311. Dim sqli As SQLiteConnection = connector.ConnectDBSQLI()
  2312. Try
  2313. Dim cmd As New SQLiteCommand("select * from credentials where username like '" & config.io.filter(tb_login_username.Text) & "' and password like '" & config.io.hash.EncryptData(pb_password.Password) & "';", sqli)
  2314. Dim sqliReader As SQLiteDataReader = cmd.ExecuteReader()
  2315. isLogin = sqliReader.Read()
  2316. staff_id = sqliReader("cred_id").ToString
  2317. cmd.Dispose()
  2318. cmd = Nothing
  2319. sqliReader.Close()
  2320. sqliReader = Nothing
  2321. Catch ex As Exception
  2322. MainSnackBar("Opps, Something went wrong. Try again", 3)
  2323. ex = Nothing
  2324. Finally
  2325. sqli.Close()
  2326. sqli.Dispose()
  2327. sqli = Nothing
  2328. End Try
  2329. End If
  2330. If isLogin Then
  2331. If (config.io.getDBType() = "personal") Then
  2332. Dim sqli As SQLiteConnection = connector.ConnectDBSQLI()
  2333. Try
  2334. Dim cmd As New SQLiteCommand("SELECT staff.staff_id,staff.photo, staff_name.first_name, staff_name.last_name, contact.email_add, contact.mobile, credentials.username, credentials.privilege FROM (((staff INNER JOIN contact ON staff.staff_id = contact.contact_id) INNER JOIN credentials ON staff.staff_id = credentials.cred_id) INNER JOIN staff_name ON staff_id = staff_name.name_staff_id) WHERE staff.staff_id = " & staff_id & " ", sqli)
  2335. Dim sqliREader As SQLiteDataReader = cmd.ExecuteReader()
  2336. If (sqliREader.Read()) Then
  2337. AddMainActivity()
  2338. onSession()
  2339. config.io.Session(True)
  2340. config.io.setSession(CInt(sqliREader("staff_id")), sqliREader("username").ToString, sqliREader("first_name").ToString & " " & sqliREader("last_name").ToString, sqliREader("email_add").ToString, sqliREader("mobile").ToString, CInt(sqliREader("privilege")), sqliREader("photo"))
  2341. config.io.deployAccount()
  2342. End If
  2343. cmd.Dispose()
  2344. cmd = Nothing
  2345. sqliREader.Close()
  2346. sqliREader = Nothing
  2347. Catch ex As SQLiteException
  2348. MainSnackBar("Opps, Something went wrong. ", 3)
  2349. ex = Nothing
  2350. Catch ex As Exception
  2351. MainSnackBar("Opps, Something went wrong. ", 3)
  2352. ex = Nothing
  2353. Finally
  2354. sqli.Close()
  2355. sqli.Dispose()
  2356. sqli = Nothing
  2357. End Try
  2358. isLogin = Nothing
  2359. Else
  2360. Dim sql As MySqlConnection = connector.ConnectDB(True)
  2361. Try
  2362. Dim cmd As New MySqlCommand("SELECT staff.staff_id,staff.photo, staff_name.first_name, staff_name.last_name, contact.email_add, contact.mobile, credentials.username, credentials.privilege FROM (((staff INNER JOIN contact ON staff.staff_id = contact.contact_id) INNER JOIN credentials ON staff.staff_id = credentials.cred_id) INNER JOIN staff_name ON staff_id = staff_name.name_staff_id) WHERE staff.staff_id = " & staff_id & " ", sql)
  2363. Dim sqlReader As MySqlDataReader = cmd.ExecuteReader()
  2364. If (sqlReader.Read()) Then
  2365. AddMainActivity()
  2366. onSession()
  2367. config.io.Session(True)
  2368. config.io.setSession(CInt(sqlReader("staff_id")), sqlReader("username").ToString, sqlReader("first_name").ToString & " " & sqlReader("last_name").ToString, sqlReader("email_add").ToString, sqlReader("mobile").ToString, CInt(sqlReader("privilege")), sqlReader("photo"))
  2369. config.io.deployAccount()
  2370. End If
  2371. cmd.Dispose()
  2372. cmd = Nothing
  2373. sqlReader.Close()
  2374. sqlReader = Nothing
  2375. Catch ex As MySqlException
  2376. MainSnackBar("Opps, Something went wrong. ", 3)
  2377. ex = Nothing
  2378. Catch ex As Exception
  2379. MainSnackBar("Opps, Something went wrong. ", 3)
  2380. ex = Nothing
  2381. Finally
  2382. sql.Close()
  2383. sql.Dispose()
  2384. sql = Nothing
  2385. End Try
  2386. End If
  2387. cw_auth.IsOpen = False
  2388. AppMode.SelectedIndex = 3
  2389. authCount = 0
  2390. Else
  2391. authCount = authCount + 1
  2392. If (authCount >= 3) Then
  2393. tc_authentication.SelectedIndex = 1
  2394. authCount = 0
  2395. Else
  2396. tb_login_username.Clear()
  2397. pb_password.Clear()
  2398. MainSnackBar("Wrong Credentials, Try again", 3)
  2399. End If
  2400. End If
  2401. Else
  2402. MainSnackBar("Login Failed", 3)
  2403. End If
  2404. sender = Nothing
  2405. e = Nothing
  2406. End Sub
  2407.  
  2408. Private Sub b_exit_Click(sender As Object, e As RoutedEventArgs)
  2409. Me.Close()
  2410. sender = Nothing
  2411. e = Nothing
  2412. End Sub
  2413.  
  2414. Private Sub b_rec_yes_Click(sender As Object, e As RoutedEventArgs)
  2415. tc_authentication.SelectedIndex = 2
  2416. sender = Nothing
  2417. e = Nothing
  2418. End Sub
  2419.  
  2420. Private Sub b_search_confirm_Click(sender As Object, e As RoutedEventArgs)
  2421. 'todo sent reset link
  2422. sender = Nothing
  2423. e = Nothing
  2424. End Sub
  2425.  
  2426. Private Sub auth_recovery_cancel(sender As Object, e As RoutedEventArgs) Handles b_search_cancel.Click, b_sent_cancel.Click, b_retry_cancel.Click, b_rec_no.Click
  2427. tc_authentication.SelectedIndex = 0
  2428. 'todo clean all recovery data's
  2429. sender = Nothing
  2430. e = Nothing
  2431. End Sub
  2432.  
  2433. Private Sub b_retry_send_Click(sender As Object, e As RoutedEventArgs)
  2434. 'todo retry sending
  2435. sender = Nothing
  2436. e = Nothing
  2437. End Sub
  2438.  
  2439. Private Sub b_new_save_Click(sender As Object, e As RoutedEventArgs)
  2440. 'todo save new password
  2441. sender = Nothing
  2442. e = Nothing
  2443. End Sub
  2444.  
  2445. 'Authentication Dialog
  2446. Public Sub Auth_Window()
  2447. cw_auth.IsOpen = True
  2448. tc_authentication.SelectedIndex = 0
  2449. AppMode.SelectedIndex = 4
  2450. End Sub
  2451. 'SnackBar MessageBox
  2452. Public Async Sub MainSnackBar(message As String, timeout As Integer)
  2453. MainWindow.Instance.s_main.Visibility = Visibility.Visible
  2454. MainWindow.Instance.s_main.IsActive = True
  2455. MainWindow.Instance.s_name_msg.Content = message
  2456. Await Tasker.Delay(timeout)
  2457. MainWindow.Instance.s_main.IsActive = False
  2458. MainWindow.Instance.s_name_msg.Content = Nothing
  2459. MainWindow.Instance.s_main.Visibility = Visibility.Collapsed
  2460. message = Nothing
  2461. timeout = Nothing
  2462. End Sub
  2463. Public Async Sub FlyoutSnackBar(message As String, timeout As Integer)
  2464. MainWindow.Instance.fs_main.Visibility = Visibility.Visible
  2465. MainWindow.Instance.fs_main.IsActive = True
  2466. MainWindow.Instance.fs_name_msg.Content = message
  2467. Await Tasker.Delay(timeout)
  2468. MainWindow.Instance.fs_main.IsActive = False
  2469. MainWindow.Instance.fs_name_msg.Content = Nothing
  2470. MainWindow.Instance.fs_main.Visibility = Visibility.Collapsed
  2471. message = Nothing
  2472. timeout = Nothing
  2473. End Sub
  2474. 'Blast Off Main Objects
  2475. Public Async Sub onLoad() Handles Me.Loaded
  2476. Dim opt As New Optimizer.App
  2477. m_instance = Me
  2478. opt.cleanProcess()
  2479. Await Delay(5)
  2480. If config.io.getRegistryStatus() Then
  2481. Auth_Window()
  2482. Else
  2483. AppMode.SelectedIndex = 1
  2484. config.io.conf.SetValue("Misc Configuration", "sqli_status", False)
  2485. End If
  2486. opt = Nothing
  2487. End Sub
  2488.  
  2489. Private Sub onSession()
  2490. MainWindow.Instance.lockscreen.Background = Nothing
  2491. Dim t As New Thread(New ThreadStart(Sub()
  2492. Thread.Sleep(500)
  2493. GC.Collect()
  2494.  
  2495. End Sub))
  2496. t.Start()
  2497. UpdateLayout()
  2498. End Sub
  2499. 'On App Close Handler
  2500. Private Sub MainWindow_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
  2501. If MessageBox.Show("Are you sure do you want to quit the App?", "Quit Reserfy", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
  2502. config.io.deployClean()
  2503. End
  2504. Else
  2505. e.Cancel = True
  2506. End If
  2507. sender = Nothing
  2508. e = Nothing
  2509. End Sub
  2510.  
  2511. Private Sub db_type_status_Click(sender As Object, e As RoutedEventArgs)
  2512. If Not daemon.setter.SettingsSQL.Ping And Settings.Instance.rb_shared.IsChecked = True Then
  2513. Settings.Instance.reconnect()
  2514. End If
  2515. sender = Nothing
  2516. e = Nothing
  2517. End Sub
  2518.  
  2519. Private Sub acc_name_Click(sender As Object, e As RoutedEventArgs)
  2520. FlyoutAccount.IsOpen = True
  2521. sender = Nothing
  2522. e = Nothing
  2523. End Sub
  2524.  
  2525. Private Sub b_start_save_Click(sender As Object, e As RoutedEventArgs)
  2526. app_configure_data_save()
  2527. sender = Nothing
  2528. e = Nothing
  2529. End Sub
  2530.  
  2531. Public Sub AddMainActivity()
  2532. Dim ma As New MainActivity()
  2533. MainActivityHolder.Children.Clear()
  2534. MainActivityHolder.Children.Add(ma)
  2535. End Sub
  2536.  
  2537.  
  2538. Public Sub RemoveMainActivity()
  2539. Dim ma As New MainActivity()
  2540. MainActivityHolder.Children.Clear()
  2541. Finalize()
  2542. End Sub
  2543. End Class
  2544.  
  2545.  
  2546. Imports System.Globalization
  2547.  
  2548. Class MonthView
  2549.  
  2550. Friend _DisplayStartDate As Date = Date.Now.AddDays(-1 * (Date.Now.Day - 1))
  2551. Private _DisplayMonth As Integer = _DisplayStartDate.Month
  2552. Private _DisplayYear As Integer = _DisplayStartDate.Year
  2553. Private _cultureInfo As New CultureInfo(CultureInfo.CurrentUICulture.LCID)
  2554. Private sysCal As Globalization.Calendar = _cultureInfo.Calendar()
  2555. Private _monthAppointments As List(Of Reservation)
  2556.  
  2557. Public Event DisplayMonthChanged(ByVal e As MonthChangedEventArgs)
  2558. Public Event DayBoxClicked(ByVal e As NewAppointmentEventArgs)
  2559. Public Event ReservationClickedEvent(ByVal Appointment_Id As Integer)
  2560.  
  2561. Public Property DisplayStartDate() As Date
  2562. Get
  2563. Return _DisplayStartDate
  2564. End Get
  2565. Set(ByVal value As Date)
  2566. _DisplayStartDate = value
  2567. _DisplayMonth = _DisplayStartDate.Month
  2568. _DisplayYear = _DisplayStartDate.Year
  2569. End Set
  2570. End Property
  2571.  
  2572. Friend Property MonthAppointments() As List(Of Reservation)
  2573. Get
  2574. Return _monthAppointments
  2575. End Get
  2576. Set(ByVal value As List(Of Reservation))
  2577. _monthAppointments = value
  2578. Call BuildCalendarUI()
  2579. End Set
  2580. End Property
  2581.  
  2582. Private Sub MonthView_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles MyBase.Loaded
  2583. If _monthAppointments Is Nothing Then Call BuildCalendarUI()
  2584. End Sub
  2585.  
  2586. Private Sub BuildCalendarUI()
  2587. Dim iDaysInMonth As Integer = sysCal.GetDaysInMonth(_DisplayStartDate.Year, _DisplayStartDate.Month)
  2588. Dim iOffsetDays As Integer = CInt(System.Enum.ToObject(GetType(System.DayOfWeek), _DisplayStartDate.DayOfWeek))
  2589. Dim iWeekCount As Integer = 0
  2590. Dim weekRowCtrl As New WeekBox()
  2591.  
  2592. MonthViewGrid.Children.Clear()
  2593. Call AddRowsToMonthGrid(iDaysInMonth, iOffsetDays)
  2594. MonthLabel.Content = Microsoft.VisualBasic.MonthName(_DisplayMonth)
  2595. YearLabel.Content = _DisplayYear
  2596.  
  2597. For i As Integer = 1 To iDaysInMonth
  2598. If (i <> 1) AndAlso System.Math.IEEERemainder((i + iOffsetDays - 1), 7) = 0 Then
  2599. '-- add existing weekrowcontrol to the monthgrid
  2600. Grid.SetRow(weekRowCtrl, iWeekCount)
  2601. MonthViewGrid.Children.Add(weekRowCtrl)
  2602. '-- make a new weekrowcontrol
  2603. weekRowCtrl = New WeekBox()
  2604. iWeekCount += 1
  2605. End If
  2606.  
  2607. Dim dayBox As New DayBox()
  2608. dayBox.DayNumberLabel.Content = i.ToString
  2609. dayBox.Tag = i.ToString
  2610. dayBox.Uid = i.ToString & _DisplayMonth.ToString & _DisplayYear.ToString
  2611. dayBox.Add_Reservation.Tag = i.ToString
  2612. dayBox.Add_Reservation.Uid = i.ToString & _DisplayMonth.ToString & _DisplayYear.ToString
  2613. AddHandler dayBox.Add_Reservation.Click, AddressOf DayBox_Clicked
  2614.  
  2615.  
  2616. If (New Date(_DisplayYear, _DisplayMonth, i)) = Date.Today Then
  2617. dayBox.DayAppointmentsStack.Background = CType(dayBox.TryFindResource("AccentColorBrush3"), Brush)
  2618. End If
  2619.  
  2620. If _monthAppointments IsNot Nothing Then
  2621.  
  2622. If (New Date(_DisplayYear, _DisplayMonth, i)) = Date.Today Then
  2623. dayBox.DayAppointmentsStack.Background = CType(dayBox.TryFindResource("AccentColorBrush3"), Brush)
  2624. End If
  2625. Dim iday As Integer = i
  2626. Dim aptInDay As List(Of Reservation) =
  2627. _monthAppointments.FindAll(New System.Predicate(Of Reservation)(
  2628. Function(apt As Reservation) CDate(apt.StartTime).Day = iday))
  2629. For Each a As Reservation In aptInDay
  2630. Dim apt As New EventBadge()
  2631. apt.EventName.Text = a.Subject
  2632. apt.Tag = a.ReservationID
  2633. AddHandler apt.MouseDown, AddressOf ReservationClicked
  2634. dayBox.DayAppointmentsStack.Children.Add(apt)
  2635. Next
  2636.  
  2637. End If
  2638.  
  2639. Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays)
  2640. weekRowCtrl.WeekRowGrid.Children.Add(dayBox)
  2641. Next
  2642. Grid.SetRow(weekRowCtrl, iWeekCount)
  2643. MonthViewGrid.Children.Add(weekRowCtrl)
  2644. End Sub
  2645.  
  2646. Private Sub AddRowsToMonthGrid(ByVal DaysInMonth As Integer, ByVal OffSetDays As Integer)
  2647. MonthViewGrid.RowDefinitions.Clear()
  2648. Dim rowHeight As New System.Windows.GridLength(60, System.Windows.GridUnitType.Star)
  2649.  
  2650. Dim EndOffSetDays As Integer = 7 -
  2651. (CInt(System.Enum.ToObject(GetType(System.DayOfWeek), _DisplayStartDate.AddDays(DaysInMonth - 1).DayOfWeek)) + 1)
  2652. For i As Integer = 1 To CInt((DaysInMonth + OffSetDays + EndOffSetDays) / 7)
  2653. Dim rowDef = New RowDefinition()
  2654. rowDef.Height = rowHeight
  2655. MonthViewGrid.RowDefinitions.Add(rowDef)
  2656. Next
  2657. End Sub
  2658.  
  2659. Private Sub UpdateMonth(ByVal MonthsToAdd As Integer)
  2660. Dim ev As New MonthChangedEventArgs()
  2661. ev.OldDisplayStartDate = _DisplayStartDate
  2662. Me.DisplayStartDate = _DisplayStartDate.AddMonths(MonthsToAdd)
  2663. ev.NewDisplayStartDate = _DisplayStartDate
  2664. RaiseEvent DisplayMonthChanged(ev)
  2665. End Sub
  2666.  
  2667. #Region " UI Event Handlers "
  2668.  
  2669. Private Sub ReservationClicked(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
  2670. If e.Source.GetType Is GetType(EventBadge) Then
  2671. If CType(e.Source, EventBadge).Tag IsNot Nothing Then
  2672. RaiseEvent ReservationClickedEvent(CInt(CType(e.Source, EventBadge).Tag))
  2673. End If
  2674. e.Handled = True
  2675. End If
  2676. End Sub
  2677.  
  2678.  
  2679. Private Sub DayBox_Clicked(ByVal sender As Object, ByVal e As RoutedEventArgs)
  2680. If e.Source.GetType Is GetType(Button) AndAlso
  2681. Utilities.FindVisualAncestor(GetType(EventBadge), e.OriginalSource) Is Nothing Then
  2682.  
  2683. Dim ev As New NewAppointmentEventArgs()
  2684. If CType(e.Source, Button).Tag IsNot Nothing Then
  2685. ev.StartDate = New Date(_DisplayYear, _DisplayMonth, CInt(CType(e.Source, Button).Tag), 10, 0, 0)
  2686. ev.EndDate = CDate(ev.StartDate).AddHours(2)
  2687. ev.TagID = CInt(CType(e.Source, Button).Uid)
  2688. End If
  2689. RaiseEvent DayBoxClicked(ev)
  2690. e.Handled = True
  2691. End If
  2692. End Sub
  2693.  
  2694. Private Sub MonthGoPrev_Click(sender As Object, e As RoutedEventArgs)
  2695. UpdateMonth(-1)
  2696. End Sub
  2697.  
  2698. Private Sub MonthGoNext_Click(sender As Object, e As RoutedEventArgs)
  2699. UpdateMonth(1)
  2700. End Sub
  2701.  
  2702. #End Region
  2703. End Class
  2704.  
  2705.  
  2706. Public Structure MonthChangedEventArgs
  2707. Public OldDisplayStartDate As Date
  2708. Public NewDisplayStartDate As Date
  2709. End Structure
  2710.  
  2711. Public Structure NewAppointmentEventArgs
  2712. Public StartDate As Date?
  2713. Public EndDate As Date?
  2714. Public CandidateId As Integer?
  2715. Public RequirementId As Integer?
  2716. Public TagID As String
  2717. Public EventName As String
  2718. End Structure
  2719.  
  2720. Class Utilities
  2721. Public Shared Function FindVisualAncestor(
  2722. ByVal ancestorType As System.Type,
  2723. ByVal visual As Media.Visual) As FrameworkElement
  2724.  
  2725. While (visual IsNot Nothing AndAlso Not ancestorType.IsInstanceOfType(visual))
  2726. visual = DirectCast(Media.VisualTreeHelper.GetParent(visual), Media.Visual)
  2727. End While
  2728. Return CType(visual, FrameworkElement)
  2729. End Function
  2730. End ClassImports System.Data.SQLite
  2731. Imports System.IO
  2732. Imports System.Threading
  2733. Imports MySql.Data.MySqlClient
  2734.  
  2735. Public Class Settings
  2736. Public Shared m_instance As Settings
  2737. Private theme As New App.Settings.Theme
  2738. Private est As New App.Settings.Establishment
  2739. Private db As New App.Settings.Database
  2740. Dim connector As New SQLConnector()
  2741.  
  2742. Private Sub uc_onload() Handles Me.Loaded
  2743. 'Extract Data Registry
  2744. Dim en() As String = Split(est.Name, ",")
  2745. Dim setconf() As String = Split(config.io.getDBShared(), ",")
  2746. general_theme_color_cb(theme.Color, False)
  2747. ts_theme.IsChecked = theme.Mode
  2748. tb_en.Text = en(0)
  2749. tb_ad.Text = en(1)
  2750. tb_ec.Text = en(2)
  2751. 'Login UI
  2752. loginTitle(config.io.conf.GetValue("Misc Configuration", "loginTitle"))
  2753. loginNotification(config.io.conf.GetValue("Misc Configuration", "loginNotify"))
  2754. loginBackground(config.io.conf.GetValue("Misc Configuration", "loginBackground"), False)
  2755. ts_advance_modes(If(config.io.conf.GetValue("Misc Configuration", "LocalAdvanceMode") = String.Empty, True, config.io.conf.GetValue("Misc Configuration", "LocalAdvanceMode")))
  2756. 'Stablishment UI
  2757. config.io.setStablishment(tb_en.Text, tb_ad.Text, tb_ec.Text)
  2758. 'Database UI Connection
  2759. If (config.io.getDBType() Like "personal") Then
  2760. rb_personal.IsChecked = True
  2761. rb_shared.IsChecked = False
  2762. tb_p_db_location.Text = config.io.getDBLocation()
  2763. Else
  2764. rb_shared.IsChecked = True
  2765. rb_personal.IsChecked = False
  2766. tb_p_db_server.Text = setconf(0)
  2767. tb_p_db_server_port.Text = setconf(1)
  2768. tb_p_db_server_username.Text = setconf(2)
  2769. tb_p_db_server_password.Password = setconf(3)
  2770. End If
  2771. 'Version UI
  2772. v_app_version.Content = config.io.getVersion()
  2773. MainWindow.Instance.v_app.Content = config.io.getVersion()
  2774. MainWindow.Instance.tcc_settings.Content = settings_TabNames(settingsMainTab.SelectedIndex)
  2775. setconf = Nothing
  2776. en = Nothing
  2777. updateAccounts()
  2778. End Sub
  2779. Public Shared ReadOnly Property Instance() As Settings
  2780. Get
  2781. Return m_instance
  2782. End Get
  2783. End Property
  2784. Public Sub Config_onLoad() Handles Me.Loaded
  2785. m_instance = Me
  2786. End Sub
  2787. 'General Theme
  2788. Private Sub general_theme_mode_onchange(sender As Object, e As RoutedEventArgs)
  2789. If (ts_theme.IsChecked) Then
  2790. theme.Mode(True)
  2791. MainWindow.Instance.FlyoutSnackBar("Dark Theme Applied", 3)
  2792. Else
  2793. theme.Mode(False)
  2794. MainWindow.Instance.FlyoutSnackBar("Light Theme Applied", 3)
  2795. End If
  2796. sender = Nothing
  2797. e = Nothing
  2798. End Sub
  2799. Private Sub general_theme_color_cb(cb_color As String, bool As Boolean)
  2800. If Not cb_blue.Tag.ToString = cb_color Then
  2801. cb_blue.IsChecked = bool
  2802. Else
  2803. cb_blue.IsChecked = Not bool
  2804. End If
  2805. If Not cb_cyan.Tag.ToString = cb_color Then
  2806. cb_cyan.IsChecked = bool
  2807. Else
  2808. cb_cyan.IsChecked = Not bool
  2809. End If
  2810. If Not cb_green.Tag.ToString = cb_color Then
  2811. cb_green.IsChecked = bool
  2812. Else
  2813. cb_green.IsChecked = Not bool
  2814. End If
  2815. If Not cb_indigo.Tag.ToString = cb_color Then
  2816. cb_indigo.IsChecked = bool
  2817. Else
  2818. cb_indigo.IsChecked = Not bool
  2819. End If
  2820. If Not cb_lightblue.Tag.ToString = cb_color Then
  2821. cb_lightblue.IsChecked = bool
  2822. Else
  2823. cb_lightblue.IsChecked = Not bool
  2824. End If
  2825. If Not cb_pink.Tag.ToString = cb_color Then
  2826. cb_pink.IsChecked = bool
  2827. Else
  2828. cb_pink.IsChecked = Not bool
  2829. End If
  2830. If Not cb_red.Tag.ToString = cb_color Then
  2831. cb_red.IsChecked = bool
  2832. Else
  2833. cb_red.IsChecked = Not bool
  2834. End If
  2835. If Not cb_teal.Tag.ToString = cb_color Then
  2836. cb_teal.IsChecked = bool
  2837. Else
  2838. cb_teal.IsChecked = Not bool
  2839. End If
  2840. MainWindow.Instance.FlyoutSnackBar("Color Theme Applied", 3)
  2841. cb_color = Nothing
  2842. bool = Nothing
  2843. End Sub
  2844. Private Sub general_theme_color_cb_handler(sender As Object, e As RoutedEventArgs)
  2845. Dim cb As CheckBox = DirectCast(sender, CheckBox)
  2846. Dim color As String = cb.Tag.ToString
  2847. If cb.IsChecked Then
  2848. general_theme_color_cb(color, False)
  2849. Else
  2850. color = "blue"
  2851. End If
  2852. theme.Color(color)
  2853. cb = Nothing
  2854. color = Nothing
  2855. sender = Nothing
  2856. e = Nothing
  2857. End Sub
  2858. 'General Theme End
  2859. 'General Reservation Name
  2860. Private Sub b_en_Click(sender As Object, e As RoutedEventArgs)
  2861. config.io.setStablishment(tb_en.Text, tb_ad.Text, tb_ec.Text)
  2862. MainWindow.Instance.FlyoutSnackBar("Applied", 3)
  2863. sender = Nothing
  2864. e = Nothing
  2865. End Sub
  2866. 'General Reservation Name End
  2867. 'Database
  2868. Private Sub database_rb_personal_Checked(sender As Object, e As RoutedEventArgs)
  2869. database_tc_status(1)
  2870. tb_p_db_location.Text = config.io.getDBLocation()
  2871. sender = Nothing
  2872. e = Nothing
  2873. End Sub
  2874. Private Sub database_rb_shared_Checked(sender As Object, e As RoutedEventArgs) Handles rb_shared.Checked
  2875. database_tc_status(2)
  2876. sender = Nothing
  2877. e = Nothing
  2878. End Sub
  2879. Public Sub database_tc_status(index As Integer)
  2880. If index = 1 Then
  2881. rb_personal.IsChecked = True
  2882. rb_shared.IsChecked = False
  2883. MainWindow.Instance.db_type_status.Visibility = Visibility.Collapsed
  2884. ElseIf index = 2
  2885. rb_personal.IsChecked = False
  2886. rb_shared.IsChecked = True
  2887. rb_personal.IsEnabled = True
  2888. b_db_connection_save.IsEnabled = True
  2889. MainWindow.Instance.db_type_status.Visibility = Visibility.Visible
  2890. ElseIf index = 3
  2891. rb_personal.IsEnabled = False
  2892. rb_personal.IsChecked = False
  2893. rb_shared.IsChecked = True
  2894. b_db_connection_save.IsEnabled = False
  2895. ElseIf (index = 4) Then
  2896. rb_personal.IsEnabled = False
  2897. rb_shared.IsChecked = True
  2898. b_db_connection_save.IsEnabled = False
  2899. End If
  2900. tc_db_connections.SelectedIndex = index
  2901. index = Nothing
  2902. End Sub
  2903. Private Async Sub b_db_connection_save_Click(sender As Object, e As RoutedEventArgs)
  2904. If rb_personal.IsChecked Then
  2905. Try
  2906. If database_rb_personal_verififcation() Then
  2907. If (config.io.conf.GetValue("Misc Configuration", "sqli_status") = True) Then
  2908. If Not (tb_p_db_location.Text = config.io.conf.GetValue("Database", "location")) Then
  2909. config.io.setDBLocation(tb_p_db_location.Text)
  2910. daemon.setter.connectSQLite()
  2911. daemon.setter.exportAdminSQLi()
  2912. End If
  2913. Else
  2914. daemon.setter.connectSQLite()
  2915. daemon.setter.exportAdminSQLi()
  2916. End If
  2917. MainWindow.Instance.FlyoutSnackBar("Saved", 3)
  2918. Else
  2919. MainWindow.Instance.FlyoutSnackBar("Opps, Location is empty", 3)
  2920. End If
  2921. Catch ex As System.UnauthorizedAccessException
  2922. MainWindow.Instance.FlyoutSnackBar("Try saving on other location", 3)
  2923. MsgBox(ex.ToString)
  2924. End Try
  2925. ElseIf rb_shared.IsChecked
  2926. Try
  2927. If (Await SharedConnect()) Then
  2928. config.io.setDBShared(tb_p_db_server.Text, tb_p_db_server_port.Text, tb_p_db_server_username.Text, tb_p_db_server_password.Password, config.io.conf.GetValue("Database", "dbname"))
  2929. If config.io.conf.GetValue("Misc Configuration", "mysql_status") = True Then
  2930. database_tc_status(4)
  2931. daemon.setter.SettingsSQL = connector.ConnectDB(True)
  2932. daemon.setter.connectivity.RunWorkerAsync()
  2933. daemon.setter.database_c_update()
  2934. MainWindow.Instance.FlyoutSnackBar("Saved", 3)
  2935. Else
  2936. daemon.setter.database_installation()
  2937. End If
  2938. Else
  2939. database_tc_status(2)
  2940. MainWindow.Instance.FlyoutSnackBar("Failed to Save ", 3)
  2941. End If
  2942. Catch ex As Exception
  2943. database_tc_status(2)
  2944. MainWindow.Instance.FlyoutSnackBar("Failed to Save ", 3)
  2945. End Try
  2946. End If
  2947. sender = Nothing
  2948. e = Nothing
  2949. End Sub
  2950.  
  2951. Public Async Sub reconnect()
  2952. Try
  2953. If (Await SharedConnect()) Then
  2954. database_tc_status(4)
  2955. daemon.setter.SettingsSQL = connector.ConnectDB(True)
  2956. daemon.setter.connectivity.RunWorkerAsync()
  2957. daemon.setter.database_c_update()
  2958. MainWindow.Instance.FlyoutSnackBar("Connected", 3)
  2959. Else
  2960. database_tc_status(2)
  2961. MainWindow.Instance.FlyoutSnackBar("Try Again", 3)
  2962. End If
  2963. Catch ex As Exception
  2964. database_tc_status(2)
  2965. MainWindow.Instance.FlyoutSnackBar("Try Again", 3)
  2966. ex = Nothing
  2967. End Try
  2968. End Sub
  2969. 'Database Personal
  2970. Private Sub database_b_browse_Click(sender As Object, e As RoutedEventArgs)
  2971. Dim location As New System.Windows.Forms.FolderBrowserDialog()
  2972. Dim result As System.Windows.Forms.DialogResult = location.ShowDialog()
  2973. If result Then
  2974. tb_p_db_location.Text = location.SelectedPath
  2975. End If
  2976. location = Nothing
  2977. result = Nothing
  2978. sender = Nothing
  2979. e = Nothing
  2980. End Sub
  2981. Private Function database_rb_personal_verififcation()
  2982. If Not (tb_p_db_location.Text Like "") Then
  2983. Return My.Computer.FileSystem.DirectoryExists(tb_p_db_location.Text)
  2984. Else
  2985. Return False
  2986. End If
  2987. End Function
  2988. 'Database Personal End
  2989. 'Database Shared
  2990. Public Async Function SharedConnect() As Task(Of Boolean)
  2991. database_tc_status(3)
  2992. Return Await connector.ConnectTry(tb_p_db_server.Text, tb_p_db_server_port.Text, tb_p_db_server_username.Text, tb_p_db_server_password.Password)
  2993. End Function
  2994.  
  2995.  
  2996. Private Sub settingsMainTab_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
  2997. If Me.IsLoaded Then
  2998. MainWindow.Instance.tcc_settings.Content = settings_TabNames(settingsMainTab.SelectedIndex)
  2999. End If
  3000. sender = Nothing
  3001. e = Nothing
  3002. End Sub
  3003.  
  3004. Public Function settings_TabNames(index As Integer) As String
  3005. If (index = 0) Then
  3006. Return ti_general.Header
  3007. ElseIf (index = 1)
  3008. Return ti_account.Header
  3009. ElseIf (index = 2)
  3010. Return ti_database.Header
  3011. ElseIf (index = 3)
  3012. Return ti_about.Header
  3013. Else
  3014. Return ti_general.Header
  3015. End If
  3016. index = Nothing
  3017. End Function
  3018. 'Database Shared End
  3019.  
  3020. Private Sub b_account_edit_Click(sender As Object, e As RoutedEventArgs)
  3021. If (config.io.getDBType() = "personal") Then
  3022. Dim sqli As SQLiteConnection = connector.ConnectDBSQLI()
  3023. Try
  3024. Dim cmd As New SQLiteCommand("SELECT staff_name.first_name, staff_name.last_name, staff_name.mid_name, contact.email_add, contact.mobile, credentials.password FROM ((staff_name INNER JOIN contact ON staff_name.name_staff_id = contact.contact_id) INNER JOIN credentials ON staff_name.name_staff_id = credentials.cred_id) WHERE staff_name.name_staff_id =" & config.io.getSession("id") & " ", sqli)
  3025. Dim sqliREader As SQLiteDataReader = cmd.ExecuteReader()
  3026. If (sqliREader.Read()) Then
  3027. AccountEdit(sqliREader("first_name").ToString, sqliREader("mid_name").ToString, sqliREader("last_name").ToString, sqliREader("mobile").ToString)
  3028. End If
  3029. cmd.Dispose()
  3030. cmd = Nothing
  3031. sqliREader.Close()
  3032. sqliREader = Nothing
  3033. Catch ex As SQLiteException
  3034. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3035. ex = Nothing
  3036. Catch ex As Exception
  3037. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3038. ex = Nothing
  3039. Finally
  3040. sqli.Close()
  3041. sqli.Dispose()
  3042. sqli = Nothing
  3043. End Try
  3044. Else
  3045. Dim sql As MySqlConnection = connector.ConnectDB(True)
  3046. Try
  3047. Dim cmd As New MySqlCommand("SELECT staff_name.first_name, staff_name.last_name, staff_name.mid_name, contact.email_add, contact.mobile, credentials.password FROM ((staff_name INNER JOIN contact ON staff_name.name_staff_id = contact.contact_id) INNER JOIN credentials ON staff_name.name_staff_id = credentials.cred_id) WHERE staff_name.name_staff_id = " & config.io.getSession("id") & " ", sql)
  3048. Dim sqlReader As MySqlDataReader = cmd.ExecuteReader()
  3049. If (sqlReader.Read()) Then
  3050. AccountEdit(sqlReader("first_name").ToString, sqlReader("mid_name").ToString, sqlReader("last_name").ToString, sqlReader("mobile").ToString)
  3051. End If
  3052. cmd.Dispose()
  3053. cmd = Nothing
  3054. sqlReader.Close()
  3055. sqlReader.Dispose()
  3056. sqlReader = Nothing
  3057. Catch ex As MySqlException
  3058. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3059. ex = Nothing
  3060. Catch ex As Exception
  3061. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3062. ex = Nothing
  3063. Finally
  3064. sql.Close()
  3065. sql.Dispose()
  3066. sql = Nothing
  3067. End Try
  3068. End If
  3069. tc_account_manage.SelectedIndex = 1
  3070. Finalize()
  3071. End Sub
  3072.  
  3073. Private Sub b_am_p_apply_Click(sender As Object, e As RoutedEventArgs)
  3074. If Not (tb_am_old_pass.Password = String.Empty Or tb_am_new_pass.Password = String.Empty) Then
  3075. If (config.io.getDBType = "personal") Then
  3076. Dim sqli As SQLiteConnection = connector.ConnectDBSQLI()
  3077. Try
  3078. Dim cmd As New SQLiteCommand("Select password From credentials where cred_id =" & config.io.getSession("id"), sqli)
  3079. Dim sqliReader As SQLiteDataReader = cmd.ExecuteReader()
  3080. If (sqliReader.Read) Then
  3081. If (config.io.hash.EncryptData(tb_am_old_pass.Password) = sqliReader("password").ToString) Then
  3082. If (tb_am_old_pass.Password = String.Empty) Then
  3083. MainWindow.Instance.FlyoutSnackBar("New Password must be empty", 3)
  3084. ElseIf tb_am_old_pass.Password.Length < 8
  3085. MainWindow.Instance.FlyoutSnackBar("New Password must atleast 8 characters", 3)
  3086. Else
  3087. sqliReader.Close()
  3088. cmd.CommandText = "Update credentials set password='" & config.io.hash.EncryptData(tb_am_new_pass.Password) & "' where cred_id=" & config.io.getSession("id")
  3089. cmd.Connection = sqli
  3090. cmd.ExecuteNonQuery()
  3091. accountUIUpdate()
  3092. tc_account_manage.SelectedIndex = 0
  3093. MainWindow.Instance.FlyoutSnackBar("Applied", 3)
  3094. End If
  3095.  
  3096. Else
  3097. MainWindow.Instance.FlyoutSnackBar("Wrong Password, Try Again", 3)
  3098. End If
  3099. End If
  3100. cmd.Dispose()
  3101. cmd = Nothing
  3102. sqliReader.Close()
  3103. sqliReader = Nothing
  3104. Catch ex As SQLiteException
  3105. MsgBox(ex.ToString)
  3106. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again ", 3)
  3107. ex = Nothing
  3108. Catch ex As Exception
  3109. MsgBox(ex.ToString)
  3110. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again", 3)
  3111. ex = Nothing
  3112. Finally
  3113. sqli.Close()
  3114. sqli.Dispose()
  3115. sqli = Nothing
  3116. End Try
  3117. Else
  3118. Dim sql As MySqlConnection = connector.ConnectDB(True)
  3119. Try
  3120. Dim cmd As New MySqlCommand("select password from credentials where cred_id =" & config.io.getSession("id"), sql)
  3121. Dim sqlReader As MySqlDataReader = cmd.ExecuteReader()
  3122. If (sqlReader.Read) Then
  3123. If (config.io.hash.EncryptData(tb_am_old_pass.Password) = sqlReader("password").ToString) Then
  3124. If (tb_am_old_pass.Password = String.Empty) Then
  3125. MainWindow.Instance.FlyoutSnackBar("New Password must be empty", 3)
  3126. ElseIf tb_am_old_pass.Password.Length < 8
  3127. MainWindow.Instance.FlyoutSnackBar("New Password must atleast 8 characters", 3)
  3128. Else
  3129. sqlReader.Close()
  3130. cmd.CommandText = "Update credentials set password='" & config.io.hash.EncryptData(tb_am_new_pass.Password) & "' where cred_id=" & config.io.getSession("id")
  3131. cmd.Connection = sql
  3132. cmd.ExecuteNonQuery()
  3133. accountUIUpdate()
  3134. tc_account_manage.SelectedIndex = 0
  3135. MainWindow.Instance.FlyoutSnackBar("Applied", 3)
  3136. End If
  3137. Else
  3138. MainWindow.Instance.FlyoutSnackBar("Wrong Password, Try Again", 3)
  3139. End If
  3140. End If
  3141. MainWindow.Instance.FlyoutSnackBar("Applied", 3)
  3142. cmd.Dispose()
  3143. cmd = Nothing
  3144. sqlReader.Close()
  3145. sqlReader.Dispose()
  3146. sqlReader = Nothing
  3147. Catch ex As MySqlException
  3148. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again ", 3)
  3149. ex = Nothing
  3150. Catch ex As Exception
  3151. MsgBox(ex.ToString)
  3152. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again", 3)
  3153. ex = Nothing
  3154. Finally
  3155. sql.Close()
  3156. sql.Dispose()
  3157. sql = Nothing
  3158. End Try
  3159. End If
  3160. Else
  3161. MainWindow.Instance.FlyoutSnackBar("Password Fields Required", 3)
  3162. End If
  3163. Finalize()
  3164. End Sub
  3165.  
  3166. Private Sub loadAccounts()
  3167.  
  3168. End Sub
  3169.  
  3170. Private Sub b_cw_apply_Click(sender As Object, e As RoutedEventArgs)
  3171. If (config.io.getDBType = "personal") Then
  3172. Dim sqli As SQLiteConnection = connector.ConnectDBSQLI()
  3173. Try
  3174. Dim cmd As New SQLiteCommand("UPDATE staff_name
  3175. SET first_name = '" & config.io.filter(tb_cw_fname.Text) & "',
  3176. last_name = '" & config.io.filter(tb_cw_lname.Text) & "',
  3177. mid_name = '" & config.io.filter(tb_cw_sname.Text) & "'
  3178. WHERE name_staff_id = " & config.io.getSession("id") & ";
  3179. UPDATE contact
  3180. SET mobile = '" & If(tb_cw_pnumber.Text = String.Empty, String.Empty, config.io.filterNum(tb_cw_pnumber.Text)) & "'
  3181. WHERE contact_id = " & config.io.getSession("id") & ";
  3182. ", sqli)
  3183. cmd.ExecuteNonQuery()
  3184. tc_account_manage.SelectedIndex = 0
  3185. accountUIUpdate()
  3186. MainWindow.Instance.FlyoutSnackBar("Applied", 3)
  3187. cmd.Dispose()
  3188. cmd = Nothing
  3189. Catch ex As SQLiteException
  3190. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again ", 3)
  3191. ex = Nothing
  3192. Catch ex As Exception
  3193. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again", 3)
  3194. ex = Nothing
  3195. Finally
  3196. sqli.Close()
  3197. sqli.Dispose()
  3198. sqli = Nothing
  3199. End Try
  3200.  
  3201. Else
  3202. Dim sqli As MySqlConnection = connector.ConnectDB(True)
  3203. Try
  3204. Dim cmd As New MySqlCommand("UPDATE staff_name
  3205. SET first_name = '" & config.io.filter(tb_cw_fname.Text) & "',
  3206. last_name = '" & config.io.filter(tb_cw_lname.Text) & "',
  3207. mid_name = '" & config.io.filter(tb_cw_sname.Text) & "'
  3208. WHERE name_staff_id = " & config.io.getSession("id") & ";
  3209. UPDATE contact
  3210. SET mobile = '" & If(tb_cw_pnumber.Text = String.Empty, String.Empty, config.io.filterNum(tb_cw_pnumber.Text)) & "'
  3211. WHERE contact_id = " & config.io.getSession("id") & ";
  3212. ", sqli)
  3213. cmd.ExecuteNonQuery()
  3214. tc_account_manage.SelectedIndex = 0
  3215. accountUIUpdate()
  3216. MainWindow.Instance.FlyoutSnackBar("Applied", 3)
  3217. cmd.Dispose()
  3218. cmd = Nothing
  3219. Catch ex As MySqlException
  3220. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again ", 3)
  3221. ex = Nothing
  3222. Catch ex As Exception
  3223. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try Again", 3)
  3224. ex = Nothing
  3225. Finally
  3226. sqli.Close()
  3227. sqli.Dispose()
  3228. sqli = Nothing
  3229. End Try
  3230. End If
  3231. Finalize()
  3232. End Sub
  3233.  
  3234. Private Sub b_cw_cancel_Click(sender As Object, e As RoutedEventArgs)
  3235. tc_account_manage.SelectedIndex = 0
  3236. sender = Nothing
  3237. e = Nothing
  3238. End Sub
  3239.  
  3240. Private Sub AccountEdit(fname As String, mname As String, lname As String, pnumber As String)
  3241. tb_cw_fname.Text = fname
  3242. tb_cw_sname.Text = mname
  3243. tb_cw_lname.Text = lname
  3244. tb_cw_pnumber.Text = pnumber
  3245. fname = Nothing
  3246. mname = Nothing
  3247. lname = Nothing
  3248. pnumber = Nothing
  3249. End Sub
  3250.  
  3251. Public Sub accountUIUpdate()
  3252. If (config.io.getDBType() = "personal") Then
  3253. Dim sqli As SQLiteConnection = connector.ConnectDBSQLI()
  3254. Try
  3255. Dim cmd As New SQLiteCommand("SELECT staff.staff_id, staff.photo, staff_name.first_name, staff_name.mid_name, staff_name.last_name, contact.email_add, contact.mobile, credentials.username, credentials.privilege FROM (((staff INNER JOIN contact ON staff.staff_id = contact.contact_id) INNER JOIN credentials ON staff.staff_id = credentials.cred_id) INNER JOIN staff_name ON staff.staff_id = staff_name.name_staff_id) WHERE staff.staff_id = " & config.io.getSession("id") & " ", sqli)
  3256. Dim sqliREader As SQLiteDataReader = cmd.ExecuteReader()
  3257. If (sqliREader.Read()) Then
  3258. config.io.Session(True)
  3259. config.io.setSession(CInt(sqliREader("staff_id")), sqliREader("username").ToString, sqliREader("first_name").ToString & " " & sqliREader("mid_name").ToString & " " & sqliREader("last_name").ToString, sqliREader("email_add").ToString, sqliREader("mobile").ToString, CInt(sqliREader("privilege")), sqliREader("photo").ToString)
  3260. config.io.deployAccount()
  3261. End If
  3262. cmd.Dispose()
  3263. cmd = Nothing
  3264. sqliREader.Close()
  3265. sqliREader = Nothing
  3266. Catch ex As SQLiteException
  3267. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3268. ex = Nothing
  3269. Catch ex As Exception
  3270. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3271. ex = Nothing
  3272. Finally
  3273. sqli.Close()
  3274. sqli.Dispose()
  3275. sqli = Nothing
  3276. End Try
  3277. Else
  3278. Dim sql As MySqlConnection = connector.ConnectDB(True)
  3279. Try
  3280. Dim cmd As New MySqlCommand("SELECT staff.staff_id,staff.photo, staff_name.first_name, staff_name.mid_name, staff_name.last_name, contact.email_add, contact.mobile, credentials.username, credentials.privilege FROM (((staff INNER JOIN contact ON staff.staff_id = contact.contact_id) INNER JOIN credentials ON staff.staff_id = credentials.cred_id) INNER JOIN staff_name ON staff.staff_id = staff_name.name_staff_id) WHERE staff.staff_id = " & config.io.getSession("id") & " ", sql)
  3281. Dim sqlReader As MySqlDataReader = cmd.ExecuteReader()
  3282. If (sqlReader.Read()) Then
  3283. config.io.Session(True)
  3284. config.io.setSession(CInt(sqlReader("staff_id")), sqlReader("username").ToString, sqlReader("first_name").ToString & " " & sqlReader("mid_name").ToString & " " & sqlReader("last_name").ToString, sqlReader("email_add").ToString, sqlReader("mobile").ToString, CInt(sqlReader("privilege")), sqlReader("photo"))
  3285. config.io.deployAccount()
  3286. End If
  3287. cmd.Dispose()
  3288. cmd = Nothing
  3289. sqlReader.Close()
  3290. sqlReader.Dispose()
  3291. sqlReader = Nothing
  3292.  
  3293. Catch ex As MySqlException
  3294. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3295. ex = Nothing
  3296. Catch ex As Exception
  3297. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. ", 3)
  3298. ex = Nothing
  3299. Finally
  3300. sql.Close()
  3301. sql.Dispose()
  3302. sql = Nothing
  3303. End Try
  3304. End If
  3305. Finalize()
  3306. End Sub
  3307.  
  3308. Private Sub ts_login_background(sender As Object, e As RoutedEventArgs)
  3309. If (ts_l_background.IsChecked) Then
  3310. g_i_panel.Visibility = Visibility.Collapsed
  3311. Else
  3312. g_i_panel.Visibility = Visibility.Visible
  3313. End If
  3314. sender = Nothing
  3315. e = Nothing
  3316. End Sub
  3317.  
  3318. Private Sub ts_l_notify(sender As Object, e As RoutedEventArgs)
  3319. If (ts_l_notification.IsChecked) Then
  3320. 'Todo for notification
  3321. Else
  3322. 'Todo for notification
  3323. End If
  3324. sender = Nothing
  3325. e = Nothing
  3326. End Sub
  3327.  
  3328. Private Sub ts_l_login(sender As Object, e As RoutedEventArgs)
  3329. If (ts_l_name.IsChecked) Then
  3330. loginTitle(True)
  3331. Else
  3332. loginTitle(False)
  3333. End If
  3334. sender = Nothing
  3335. e = Nothing
  3336. End Sub
  3337.  
  3338. Private Sub ts_advance_(sender As Object, e As RoutedEventArgs)
  3339. ts_advance_modes(ts_advance_mode.IsChecked)
  3340. sender = Nothing
  3341. e = Nothing
  3342. End Sub
  3343.  
  3344. Public Sub ts_advance_modes(b As Boolean)
  3345. If (b) Then
  3346. gb_dconn.ToolTip = "Go to General > Advance > Turn OFF Advance Mode"
  3347. Else
  3348. gb_dconn.ToolTip = Nothing
  3349. End If
  3350. ts_advance_mode.IsChecked = b
  3351. db_conn.IsEnabled = Not (b)
  3352. config.io.conf.SetValue("Misc Configuration", "LocalAdvanceMode", b)
  3353. b = Nothing
  3354. End Sub
  3355.  
  3356. Private Sub loginTitle(b As Boolean)
  3357. If (b) Then
  3358. ts_l_name.IsChecked = True
  3359. MainWindow.Instance.l_sys_name.Visibility = Visibility.Visible
  3360. Else
  3361. ts_l_name.IsChecked = False
  3362. MainWindow.Instance.l_sys_name.Visibility = Visibility.Collapsed
  3363. End If
  3364. config.io.conf.SetValue("Misc Configuration", "loginTitle", b)
  3365. b = Nothing
  3366. End Sub
  3367.  
  3368. Private Sub loginNotification(b As Boolean)
  3369. If (b) Then
  3370. 'Toggle Notification
  3371. Else
  3372. 'Toggle Notification
  3373. End If
  3374. config.io.conf.SetValue("Misc Configuration", "loginNotify", b)
  3375. b = Nothing
  3376. End Sub
  3377.  
  3378. Public Sub loginBackground(src As String, bool As Boolean)
  3379. If Not (src = String.Empty) Then
  3380. Dim b As BitmapImage = New BitmapImage()
  3381. b.BeginInit()
  3382. b.UriSource = New Uri(src, UriKind.RelativeOrAbsolute)
  3383. b.EndInit()
  3384. b.Freeze()
  3385. Dim i As Image = New Image()
  3386. Dim ib As ImageBrush = New ImageBrush()
  3387. i.Stretch = Stretch.Fill
  3388. i.Source = b
  3389. i_image.Source = b
  3390. ib.ImageSource = b
  3391. Home.Instance.g_home.Background = ib
  3392. setLoginB(ib)
  3393. config.io.conf.SetValue("Misc Configuration", "loginBackground", src)
  3394. i.Source = Nothing
  3395. If bool Then
  3396. ib.ImageSource = Nothing
  3397. End If
  3398. Dim t As New Thread(New ThreadStart(Sub()
  3399. Thread.Sleep(500)
  3400. GC.Collect()
  3401.  
  3402. End Sub))
  3403. t.Start()
  3404. b = Nothing
  3405. i = Nothing
  3406. ib = Nothing
  3407. src = Nothing
  3408. UpdateLayout()
  3409. End If
  3410. src = Nothing
  3411. UpdateLayout()
  3412. End Sub
  3413.  
  3414. Private Sub setLoginB(ib As ImageBrush)
  3415. MainWindow.Instance.lockscreen.Background = ib
  3416. End Sub
  3417.  
  3418.  
  3419. Private Sub b_image_browse_Click(sender As Object, e As RoutedEventArgs)
  3420. Dim sf As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog()
  3421. sf.Filter = "Image files (*.jpg)|*.jpg"
  3422. Dim result As System.Windows.Forms.DialogResult = sf.ShowDialog()
  3423. If result Then
  3424. loginBackground(sf.FileName, True)
  3425. End If
  3426. sender = Nothing
  3427. e = Nothing
  3428. sf.Dispose()
  3429. sf = Nothing
  3430. result = Nothing
  3431. Finalize()
  3432. End Sub
  3433.  
  3434. Private Sub b_cw_add_photo_Click(sender As Object, e As RoutedEventArgs)
  3435. Dim sf As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog()
  3436. sf.Filter = "Image files (*.jpg)|*.jpg"
  3437. Dim result As System.Windows.Forms.DialogResult = sf.ShowDialog()
  3438. If result Then
  3439. If Not (sf.FileName = String.Empty) Then
  3440. Dim b As BitmapImage = New BitmapImage()
  3441. Dim i As Image = New Image()
  3442. Dim ib As ImageBrush = New ImageBrush()
  3443. b.BeginInit()
  3444. b.UriSource = New Uri(sf.FileName, UriKind.RelativeOrAbsolute)
  3445. b.EndInit()
  3446. b.Freeze()
  3447. i.Stretch = Stretch.Fill
  3448. i.Source = b
  3449. i_image.Source = b
  3450. ib.ImageSource = b
  3451. image_profile_account.Source = b
  3452. i.Source = Nothing
  3453. i_image.Source = Nothing
  3454. Dim t As New Thread(New ThreadStart(Sub()
  3455. Thread.Sleep(500)
  3456. GC.Collect()
  3457.  
  3458. End Sub))
  3459. t.Start()
  3460. t = Nothing
  3461. End If
  3462. End If
  3463. End Sub
  3464.  
  3465. Private Sub b_account_ChangePassword_Click(sender As Object, e As RoutedEventArgs)
  3466. tc_account_manage.SelectedIndex = 2
  3467. sender = Nothing
  3468. e = Nothing
  3469. End Sub
  3470.  
  3471. Private Sub b_Add_Accounts_Click(sender As Object, e As RoutedEventArgs)
  3472. Add_Account.IsOpen = True
  3473. End Sub
  3474.  
  3475. Private Sub b_new_add_Click(sender As Object, e As RoutedEventArgs)
  3476. If Not (String.IsNullOrEmpty(tb_idNum.Text) Or String.IsNullOrEmpty(tb_new_username.Text) Or String.IsNullOrEmpty(tb_password.Password) Or String.IsNullOrEmpty(tb_email.Text)) Then
  3477. Dim Connector As New SQLConnector
  3478. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  3479. Try
  3480. Dim sql As New MySqlConnection()
  3481. sql = Connector.ConnectDB(True)
  3482. Dim export As New MySqlCommand("INSERT INTO staff_name (name_staff_id) VALUES (" & tb_idNum.Text & ");
  3483. INSERT INTO contact(contact_id, email_add) VALUES (" & tb_idNum.Text & ", '" & tb_email.Text & "');
  3484. INSERT INTO credentials(cred_id, username, password, privilege) VALUES (" & tb_idNum.Text & ", '" & tb_new_username.Text & "', '" & config.io.hash.EncryptData(tb_password.Password) & "');
  3485. INSERT INTO staff(staff_id, name_id, cred_id,contact_id) VALUES (" & tb_idNum.Text & "," & tb_idNum.Text & "," & tb_idNum.Text & "," & tb_idNum.Text & ")", sql)
  3486. export.ExecuteNonQuery()
  3487. sql.Close()
  3488. updateAccounts()
  3489. NewClear()
  3490. Add_Account.IsOpen = False
  3491. MainWindow.Instance.FlyoutSnackBar("Account Added", 3)
  3492. Catch ex As MySqlException
  3493. MainWindow.Instance.FlyoutSnackBar("Connection Error", 3)
  3494. Catch ex As Exception
  3495. MainWindow.Instance.FlyoutSnackBar("Something went wrong", 3)
  3496. End Try
  3497. Else
  3498. Try
  3499. Dim sql As New SQLiteConnection()
  3500. sql = Connector.ConnectDBSQLI()
  3501. Dim export As New SQLiteCommand("INSERT INTO staff_name (name_staff_id) VALUES (" & tb_idNum.Text & ");
  3502. INSERT INTO contact(contact_id, email_add) VALUES (" & tb_idNum.Text & ", '" & tb_email.Text & "');
  3503. INSERT INTO credentials(cred_id, username, password, privilege) VALUES (" & tb_idNum.Text & ", '" & tb_new_username.Text & "', '" & config.io.hash.EncryptData(tb_password.Password) & "', " & 1 & ");
  3504. INSERT INTO staff(staff_id, name_id, cred_id,contact_id) VALUES (" & tb_idNum.Text & "," & tb_idNum.Text & "," & tb_idNum.Text & "," & tb_idNum.Text & ")", sql)
  3505. export.ExecuteNonQuery()
  3506. sql.Close()
  3507. updateAccounts()
  3508. NewClear()
  3509. Add_Account.IsOpen = False
  3510. MainWindow.Instance.FlyoutSnackBar("Account Added", 3)
  3511. Catch ex As SQLiteException
  3512. MainWindow.Instance.FlyoutSnackBar("Connection Error", 3)
  3513. Catch ex As Exception
  3514. MainWindow.Instance.FlyoutSnackBar("Something went wrong", 3)
  3515. End Try
  3516. End If
  3517. Else
  3518. MainWindow.Instance.FlyoutSnackBar("Fill all fields", 3)
  3519. End If
  3520. End Sub
  3521.  
  3522. Private Sub b_new_cancel_Click(sender As Object, e As RoutedEventArgs)
  3523. Add_Account.IsOpen = False
  3524. NewClear()
  3525. End Sub
  3526.  
  3527. Private Sub b_new_reset_Click(sender As Object, e As RoutedEventArgs)
  3528. NewClear()
  3529. End Sub
  3530.  
  3531. Private Sub NewClear()
  3532. tb_new_username.Clear()
  3533. tb_password.Clear()
  3534. tb_idNum.Clear()
  3535. tb_email.Clear()
  3536. End Sub
  3537.  
  3538. Private Sub updateAccounts()
  3539. gb_other_accounts.Children.Clear()
  3540. Dim Connector As New SQLConnector
  3541. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  3542. Dim sqli As MySqlConnection = Connector.ConnectDB(True)
  3543. Try
  3544. Dim cmd1 As New MySqlCommand("select cred_id, username, privilege from credentials", sqli)
  3545. Dim id As MySqlDataReader = cmd1.ExecuteReader()
  3546. While id.Read()
  3547. Dim acc As New accounts()
  3548. acc.l_LocalAccount.Content = id("username").ToString
  3549. acc.Tag = id("cred_id").ToString
  3550. If id("privilege").ToString Like "0" Then
  3551. acc.b_remove.IsEnabled = False
  3552. End If
  3553. acc.b_remove.Tag = acc.Tag
  3554. gb_other_accounts.Children.Add(acc)
  3555. AddHandler acc.b_remove.Click, AddressOf b_remove_acc
  3556. End While
  3557. id.Close()
  3558. cmd1 = Nothing
  3559. Catch ex As Exception
  3560. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try again", 3)
  3561. ex = Nothing
  3562. Finally
  3563. sqli.Close()
  3564. sqli.Dispose()
  3565. sqli = Nothing
  3566. End Try
  3567. Else
  3568. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  3569. Try
  3570. Dim cmd1 As New SQLiteCommand("select cred_id, username, privilege from credentials", sqli)
  3571. Dim id As SQLiteDataReader = cmd1.ExecuteReader()
  3572. While id.Read()
  3573. Dim acc As New accounts()
  3574. acc.l_LocalAccount.Content = id("username").ToString
  3575. acc.Tag = id("cred_id").ToString
  3576. If id("privilege").ToString Like "0" Then
  3577. acc.b_remove.IsEnabled = False
  3578. End If
  3579. acc.b_remove.Tag = acc.Tag
  3580. gb_other_accounts.Children.Add(acc)
  3581. AddHandler acc.b_remove.Click, AddressOf b_remove_acc
  3582. End While
  3583. id.Close()
  3584. cmd1 = Nothing
  3585. Catch ex As Exception
  3586. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try again", 3)
  3587. ex = Nothing
  3588. Finally
  3589. sqli.Close()
  3590. sqli.Dispose()
  3591. sqli = Nothing
  3592. End Try
  3593. End If
  3594. End Sub
  3595.  
  3596. Private Sub b_remove_acc(sender As Object, e As RoutedEventArgs)
  3597. Dim b As String = DirectCast(sender, Button).Tag
  3598. gb_other_accounts.Children.Clear()
  3599. Dim Connector As New SQLConnector
  3600. If (config.io.conf.GetValue("Database", "Type") Like "shared") Then
  3601. Dim sqli As MySqlConnection = Connector.ConnectDB(True)
  3602. Try
  3603. Dim cmd1 As New MySqlCommand("select cred_id, username, privilege from credentials", sqli)
  3604. Dim id As MySqlDataReader = cmd1.ExecuteReader()
  3605. While id.Read()
  3606. Dim acc As New accounts()
  3607. acc.l_LocalAccount.Content = id("username").ToString
  3608. acc.Tag = id("cred_id").ToString
  3609. If id("privilege").ToString Like "0" Then
  3610. acc.b_remove.IsEnabled = False
  3611. End If
  3612. acc.b_remove.Tag = acc.Tag
  3613. gb_other_accounts.Children.Add(acc)
  3614. AddHandler acc.b_remove.Click, AddressOf b_remove_acc
  3615. End While
  3616. id.Close()
  3617. cmd1 = Nothing
  3618. Catch ex As Exception
  3619. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try again", 3)
  3620. ex = Nothing
  3621. Finally
  3622. sqli.Close()
  3623. sqli.Dispose()
  3624. sqli = Nothing
  3625. End Try
  3626. Else
  3627. Dim sqli As SQLiteConnection = Connector.ConnectDBSQLI()
  3628. Try
  3629. Dim cmd1 As New SQLiteCommand("select cred_id, username, privilege from credentials", sqli)
  3630. Dim id As SQLiteDataReader = cmd1.ExecuteReader()
  3631. While id.Read()
  3632. Dim acc As New accounts()
  3633. acc.l_LocalAccount.Content = id("username").ToString
  3634. acc.Tag = id("cred_id").ToString
  3635. If id("privilege").ToString Like "0" Then
  3636. acc.b_remove.IsEnabled = False
  3637. End If
  3638. acc.b_remove.Tag = acc.Tag
  3639. gb_other_accounts.Children.Add(acc)
  3640. AddHandler acc.b_remove.Click, AddressOf b_remove_acc
  3641. End While
  3642. id.Close()
  3643. cmd1 = Nothing
  3644. Catch ex As Exception
  3645. MainWindow.Instance.FlyoutSnackBar("Opps, Something went wrong. Try again", 3)
  3646. ex = Nothing
  3647. Finally
  3648. sqli.Close()
  3649. sqli.Dispose()
  3650. sqli = Nothing
  3651. End Try
  3652. End If
  3653. End Sub
  3654.  
  3655. End Class
  3656. Public Class WeekBox
  3657.  
  3658. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement