Added logging functions to master branch

Add Logger function to master
This commit is contained in:
JackCarterSmith 2017-07-08 17:49:04 +02:00 committed by GitHub
commit 74d1126d8d
6 changed files with 64 additions and 15 deletions

View File

@ -39,6 +39,7 @@ Public Class AddMachine
If cmd.ExecuteNonQuery() <> 1 Then MsgBox("Erreur inconnue au niveau de la base de données !", 16, "Defaillance générale !") : End If cmd.ExecuteNonQuery() <> 1 Then MsgBox("Erreur inconnue au niveau de la base de données !", 16, "Defaillance générale !") : End
con.Close() con.Close()
End Using End Using
Main.log.Info("Computer " & NewIDBox.Text & " added")
Main.StatusLabel.Text = "Ordinateur ajouté avec succés dans la base de données." Main.StatusLabel.Text = "Ordinateur ajouté avec succés dans la base de données."
Main.ListAllInv() Main.ListAllInv()
Me.Close() Me.Close()

View File

@ -34,7 +34,7 @@ Partial Class EditSpecs
Me.OSCheck = New System.Windows.Forms.CheckBox() Me.OSCheck = New System.Windows.Forms.CheckBox()
Me.HWCheck = New System.Windows.Forms.CheckBox() Me.HWCheck = New System.Windows.Forms.CheckBox()
Me.GroupBox2 = New System.Windows.Forms.GroupBox() Me.GroupBox2 = New System.Windows.Forms.GroupBox()
Me.NewIDBox = New System.Windows.Forms.TextBox() Me.IDBox = New System.Windows.Forms.TextBox()
Me.GivedByBox = New System.Windows.Forms.TextBox() Me.GivedByBox = New System.Windows.Forms.TextBox()
Me.Label8 = New System.Windows.Forms.Label() Me.Label8 = New System.Windows.Forms.Label()
Me.EtatBox = New System.Windows.Forms.TextBox() Me.EtatBox = New System.Windows.Forms.TextBox()
@ -168,7 +168,7 @@ Partial Class EditSpecs
' '
'GroupBox2 'GroupBox2
' '
Me.GroupBox2.Controls.Add(Me.NewIDBox) Me.GroupBox2.Controls.Add(Me.IDBox)
Me.GroupBox2.Controls.Add(Me.GivedByBox) Me.GroupBox2.Controls.Add(Me.GivedByBox)
Me.GroupBox2.Controls.Add(Me.Label8) Me.GroupBox2.Controls.Add(Me.Label8)
Me.GroupBox2.Controls.Add(Me.EtatBox) Me.GroupBox2.Controls.Add(Me.EtatBox)
@ -188,14 +188,14 @@ Partial Class EditSpecs
Me.GroupBox2.TabStop = False Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "Information et détails" Me.GroupBox2.Text = "Information et détails"
' '
'NewIDBox 'IDBox
' '
Me.NewIDBox.Location = New System.Drawing.Point(37, 16) Me.IDBox.Location = New System.Drawing.Point(37, 16)
Me.NewIDBox.Name = "NewIDBox" Me.IDBox.Name = "IDBox"
Me.NewIDBox.ReadOnly = True Me.IDBox.ReadOnly = True
Me.NewIDBox.Size = New System.Drawing.Size(79, 20) Me.IDBox.Size = New System.Drawing.Size(79, 20)
Me.NewIDBox.TabIndex = 17 Me.IDBox.TabIndex = 17
Me.NewIDBox.TabStop = False Me.IDBox.TabStop = False
' '
'GivedByBox 'GivedByBox
' '
@ -361,7 +361,7 @@ Partial Class EditSpecs
Friend WithEvents Label4 As Label Friend WithEvents Label4 As Label
Friend WithEvents Label2 As Label Friend WithEvents Label2 As Label
Friend WithEvents Label1 As Label Friend WithEvents Label1 As Label
Friend WithEvents NewIDBox As TextBox Friend WithEvents IDBox As TextBox
Friend WithEvents RAMCmbBox As ComboBox Friend WithEvents RAMCmbBox As ComboBox
Friend WithEvents ProcArchCmbBox As ComboBox Friend WithEvents ProcArchCmbBox As ComboBox
Friend WithEvents OSCmbBox As ComboBox Friend WithEvents OSCmbBox As ComboBox

View File

@ -8,7 +8,7 @@ Public Class EditSpecs
InitializeComponent() InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
NewIDBox.Text = id IDBox.Text = id
NameBox.Text = name NameBox.Text = name
EtatBox.Text = stat EtatBox.Text = stat
GivedByBox.Text = givedBy GivedByBox.Text = givedBy
@ -68,13 +68,14 @@ Public Class EditSpecs
Using con As New SQLiteConnection("URI=file:db.sqlite") Using con As New SQLiteConnection("URI=file:db.sqlite")
con.Open() con.Open()
Dim cmd As New SQLiteCommand(con) Dim cmd As New SQLiteCommand(con)
cmd.CommandText = "UPDATE `computers_desc` SET `giveTo`='" & EmprunterName.Text & "', `gived`=" & BooleanToNumeric(EmpruntCheckBox.Checked) & " WHERE id='" & NewIDBox.Text & "';" cmd.CommandText = "UPDATE `computers_desc` SET `giveTo`='" & EmprunterName.Text & "', `gived`=" & BooleanToNumeric(EmpruntCheckBox.Checked) & " WHERE id='" & IDBox.Text & "';"
If cmd.ExecuteNonQuery() <> 1 Then MsgBox("Erreur inconnue au niveau de la base de données !", 16, "Defaillance générale !") : End If cmd.ExecuteNonQuery() <> 1 Then MsgBox("Erreur inconnue au niveau de la base de données !", 16, "Defaillance générale !") : End
cmd.CommandText = "UPDATE `computers_progress` SET `hardware_complete`=" & BooleanToNumeric(HWCheck.Checked) & ", `os_complete`=" & BooleanToNumeric(OSCheck.Checked) & ", `drivers_complete`=" & BooleanToNumeric(DrvCheck.Checked) & ", `activate_complete`=" & BooleanToNumeric(ActivateCheck.Checked) & ", `soft_complete`=" & BooleanToNumeric(SoftCheck.Checked) & ", `arch`=" & (ProcArchCmbBox.SelectedIndex + 1) & ", `ram`=" & (RAMCmbBox.SelectedIndex + 1) & ", `os`=" & (OSCmbBox.SelectedIndex + 1) & " WHERE id='" & NewIDBox.Text & "';" cmd.CommandText = "UPDATE `computers_progress` SET `hardware_complete`=" & BooleanToNumeric(HWCheck.Checked) & ", `os_complete`=" & BooleanToNumeric(OSCheck.Checked) & ", `drivers_complete`=" & BooleanToNumeric(DrvCheck.Checked) & ", `activate_complete`=" & BooleanToNumeric(ActivateCheck.Checked) & ", `soft_complete`=" & BooleanToNumeric(SoftCheck.Checked) & ", `arch`=" & (ProcArchCmbBox.SelectedIndex + 1) & ", `ram`=" & (RAMCmbBox.SelectedIndex + 1) & ", `os`=" & (OSCmbBox.SelectedIndex + 1) & " WHERE id='" & IDBox.Text & "';"
If cmd.ExecuteNonQuery() <> 1 Then MsgBox("Erreur inconnue au niveau de la base de données !", 16, "Defaillance générale !") : End If cmd.ExecuteNonQuery() <> 1 Then MsgBox("Erreur inconnue au niveau de la base de données !", 16, "Defaillance générale !") : End
con.Close() con.Close()
End Using End Using
Main.StatusLabel.Text = "Ordinateur enregistré avec succès !" Main.StatusLabel.Text = "Ordinateur enregistré avec succès !"
Main.log.Info("Edited computer " & IDBox.Text)
Catch ex As Exception Catch ex As Exception
Main.StatusLabel.Text = "Une erreur avec la base SQLite s'est produite !" Main.StatusLabel.Text = "Une erreur avec la base SQLite s'est produite !"
MsgBox(ex.Message) MsgBox(ex.Message)

View File

@ -33,7 +33,7 @@
<SuiteName>ISEN-Repair</SuiteName> <SuiteName>ISEN-Repair</SuiteName>
<MinimumRequiredVersion>0.8.1.0</MinimumRequiredVersion> <MinimumRequiredVersion>0.8.1.0</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish> <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage> <WebPage>index.htm</WebPage>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish> <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>2</ApplicationRevision> <ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>0.9.5.%2a</ApplicationVersion> <ApplicationVersion>0.9.5.%2a</ApplicationVersion>
@ -171,6 +171,7 @@
<Compile Include="IDGenerator.vb"> <Compile Include="IDGenerator.vb">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Logger.vb" />
<Compile Include="Main.vb"> <Compile Include="Main.vb">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View File

@ -0,0 +1,42 @@
Imports System.IO
Public Class Logger
'DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
Dim logFileName As String = "logs\" & DateTime.Now.ToString("yyyy-MM-dd") & ".txt"
Public Sub Load()
If Not My.Computer.FileSystem.DirectoryExists("logs") Then My.Computer.FileSystem.CreateDirectory("logs")
If Not My.Computer.FileSystem.FileExists(logFileName) Then File.WriteAllLines(logFileName, {"LOG FILE - " & DateTime.Now.ToString("dd/MM/yyyy"), "--------------------", "[" & DateTime.Now.ToString("HH:mm:ss") & "][INFO] Loading software"})
End Sub
Public Sub Info(str As String)
Dim objWriter As New StreamWriter(logFileName, True)
Try
objWriter.WriteLineAsync("[" & DateTime.Now.ToString("HH:mm:ss") & "][INFO] " & str)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
objWriter.Close()
End Sub
Public Sub Warn(str As String)
Dim objWriter As New StreamWriter(logFileName, True)
Try
objWriter.WriteLineAsync("[" & DateTime.Now.ToString("HH:mm:ss") & "][WARN] " & str)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
objWriter.Close()
End Sub
Public Sub Critical(str As String)
Dim objWriter As New StreamWriter(logFileName, True)
Try
objWriter.WriteLineAsync("[" & DateTime.Now.ToString("HH:mm:ss") & "][CRITICAL] " & str)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
objWriter.Close()
End Sub
End Class

View File

@ -4,8 +4,10 @@ Imports System.Text
Public Class Main Public Class Main
Dim manualID_selected As Boolean = False Dim manualID_selected As Boolean = False
Dim idList As New ArrayList Dim idList As New ArrayList
Public log As New Logger
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
log.Load()
CheckIfFirstRun() CheckIfFirstRun()
ListAllInv() ListAllInv()
End Sub End Sub
@ -14,8 +16,9 @@ Public Class Main
''' Function to check if app is running for the first time ''' Function to check if app is running for the first time
''' </summary> ''' </summary>
Private Sub CheckIfFirstRun() Private Sub CheckIfFirstRun()
log.Info("Check and load of database")
If Not My.Computer.FileSystem.FileExists("db.sqlite") Then If Not My.Computer.FileSystem.FileExists("db.sqlite") Then
If MsgBox("La base de données SQLite est introuvable ou inaccesible, souhaitez-vous la régénérer ?", 4161, "Base SQLite absente ou inacessible") = 1 Then If MsgBox("La base de données SQLite est introuvable ou inaccessible, souhaitez-vous la régénérer ?", 4161, "Base SQLite absente ou inaccessible") = 1 Then
RegenerateDB() RegenerateDB()
Else Else
End End
@ -106,6 +109,7 @@ Public Class Main
''' Construct the basic structure of SQLite DB ''' Construct the basic structure of SQLite DB
''' </summary> ''' </summary>
Private Sub RegenerateDB() Private Sub RegenerateDB()
log.Warn("Reconstruct database...")
Dim genesis_seq As String = " Dim genesis_seq As String = "
CREATE TABLE `computers_desc` ( CREATE TABLE `computers_desc` (
`id` TEXT NOT NULL DEFAULT 0000000000 UNIQUE, `id` TEXT NOT NULL DEFAULT 0000000000 UNIQUE,