diff --git a/Ticket-Counter.ps1 b/Ticket-Counter.ps1 index 32c08af..a4f5570 100644 --- a/Ticket-Counter.ps1 +++ b/Ticket-Counter.ps1 @@ -1,98 +1,126 @@ - - -function Get-HotReload { - - $Form.Close() - $headers = @{Authorization = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3ZDcwYTQ5Y2Y0MzhmZGU0NGM2ZWY4YyIsImlhdCI6MTc0MjE0NjMyNSwiZXhwIjoxNzQyMTQ2NjI1fQ.8I2KXZOjUSMVsNxKHYCimnhKlUPkv4cFrx2v5Xdx4E4"} - $response = Invoke-RestMethod -Uri "https://app.poshgui.com/api/hotreload/winform/67d70a49cf438fde44c6ef8c" -Method Get -Headers $headers - iex $response - } - - - -Add-Type -Name Window -Namespace Console -MemberDefinition ' -[DllImport("Kernel32.dll")] -public static extern IntPtr GetConsoleWindow(); - -[DllImport("user32.dll")] -public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);' - -[Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0) - -<# -.NAME - Ticket-Counter - -#> - -Add-Type -AssemblyName System.Windows.Forms -[System.Windows.Forms.Application]::EnableVisualStyles() - -$Form = New-Object system.Windows.Forms.Form -$Form.ClientSize = New-Object System.Drawing.Point(241,91) -$Form.text = "Form" -$Form.TopMost = $false - -$Label1 = New-Object system.Windows.Forms.Label -$Label1.text = "Month Count" -$Label1.AutoSize = $true -$Label1.width = 50 -$Label1.height = 10 -$Label1.location = New-Object System.Drawing.Point(12,71) -$Label1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) - -$Label2 = New-Object system.Windows.Forms.Label -$Label2.text = "Day Count" -$Label2.AutoSize = $true -$Label2.width = 50 -$Label2.height = 10 -$Label2.location = New-Object System.Drawing.Point(12,48) -$Label2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) - -$Button1 = New-Object system.Windows.Forms.Button -$Button1.text = "button" -$Button1.width = 167 -$Button1.height = 30 -$Button1.location = New-Object System.Drawing.Point(7,7) -$Button1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) - -$Button2 = New-Object system.Windows.Forms.Button -$Button2.text = "button" -$Button2.width = 57 -$Button2.height = 30 -$Button2.location = New-Object System.Drawing.Point(178,7) -$Button2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) - -$Label3 = New-Object system.Windows.Forms.Label -$Label3.text = "1" -$Label3.AutoSize = $true -$Label3.width = 50 -$Label3.height = 10 -$Label3.location = New-Object System.Drawing.Point(102,48) -$Label3.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) - -$Label4 = New-Object system.Windows.Forms.Label -$Label4.text = "0" -$Label4.AutoSize = $true -$Label4.width = 50 -$Label4.height = 10 -$Label4.location = New-Object System.Drawing.Point(102,71) -$Label4.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) - -$hotreload = New-Object system.Windows.Forms.PictureBox -$hotreload.width = 60 -$hotreload.height = 30 -$hotreload.location = New-Object System.Drawing.Point(181,1) -$hotreload.imageLocation = "https://app.poshgui.com/images/refresh.png" -$hotreload.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::zoom -$Form.controls.AddRange(@($Label1,$Label2,$Button1,$Button2,$Label3,$Label4,$hotreload)) - - - - - - -$hotreload.Add_Click({Get-HotReload}) - - + +Add-Type -Name Window -Namespace Console -MemberDefinition ' +[DllImport("Kernel32.dll")] +public static extern IntPtr GetConsoleWindow(); + +[DllImport("user32.dll")] +public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);' + +[Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0) + +<# +.NAME + Ticket-Counter + +#> + +# Config + +$LogDir = "$env:USERPROFILE\Documents\TicketCounter" +if (!(Test-Path $LogDir)) { + New-Item -ItemType Directory "$LogDir" + New-Item -ItemType Directory "$LogDir\Monthly" + New-Item -ItemType Directory "$LogDir\Daily" +} + +$TotalLogFile = "$LogDir\TicketCounter_Total.txt" +$DailyLogFile = "$LogDir\TicketCounter_Daily.txt" + +if (!(Test-Path $TotalLogFile)) { + Write-Output "0" | Out-File $TotalLogFile +} +if (!(Test-Path $DailyLogFile)) { + Write-Output "0" | Out-File $DailyLogFile +} + +[int]$CurrentMonthly = Get-Content $TotalLogFile +[int]$CurrentDaily = Get-Content $DailyLogFile +######### +Add-Type -AssemblyName System.Windows.Forms +[System.Windows.Forms.Application]::EnableVisualStyles() + +## SCREEN DETECT +$ScreenPrimary = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea +################## + +$Form = New-Object system.Windows.Forms.Form +$Form.ClientSize = New-Object System.Drawing.Point(241,95) +$Form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual +$Form.Left = $ScreenPrimary.Left +$Form.Top = $ScreenPrimary.Height + $ScreenPrimary.Top - $Form.Height +$Form.text = "Ticket Counter" +$Form.TopMost = $true + +$TotalCounter = New-Object system.Windows.Forms.Label +$TotalCounter.text = "Total Count" +$TotalCounter.AutoSize = $true +$TotalCounter.width = 50 +$TotalCounter.height = 10 +$TotalCounter.location = New-Object System.Drawing.Point(12,71) +$TotalCounter.Font = New-Object System.Drawing.Font('Segoe UI',10) + +$DailyCounter = New-Object system.Windows.Forms.Label +$DailyCounter.text = "Day Count" +$DailyCounter.AutoSize = $true +$DailyCounter.width = 50 +$DailyCounter.height = 10 +$DailyCounter.location = New-Object System.Drawing.Point(12,48) +$DailyCounter.Font = New-Object System.Drawing.Font('Segoe UI',10) + +$DailyAddTicketToCount = New-Object system.Windows.Forms.Button +$DailyAddTicketToCount.text = "ADD TICKET" +$DailyAddTicketToCount.width = 167 +$DailyAddTicketToCount.height = 30 +$DailyAddTicketToCount.location = New-Object System.Drawing.Point(7,7) +$DailyAddTicketToCount.Font = New-Object System.Drawing.Font('Segoe UI',10) +$DailyAddTicketToCount.Add_Click{ + [int]$CurrentDailyCounter.text = [int]$CurrentDailyCounter.text + 1 + Write-Output $CurrentDailyCounter.text | Out-File $DailyLogFile +} + +$MonthlyAddDailyCountToTotal = New-Object system.Windows.Forms.Button +$MonthlyAddDailyCountToTotal.text = "SAVE" +$MonthlyAddDailyCountToTotal.width = 57 +$MonthlyAddDailyCountToTotal.height = 30 +$MonthlyAddDailyCountToTotal.location = New-Object System.Drawing.Point(178,7) +$MonthlyAddDailyCountToTotal.Font = New-Object System.Drawing.Font('Segoe UI',10) +$MonthlyAddDailyCountToTotal.Add_Click{ + Copy-Item $TotalLogFile "$LogDir\Daily\DailyTickets-$(Get-Date -Format "dddd-dd-MM-yyyy_$(Get-Random)").txt" + [int]$CurrentTotalCounter.text = [int]$CurrentTotalCounter.text + [int]$CurrentDailyCounter.text + Write-Output $CurrentTotalCounter.text | Out-File $TotalLogFile + [int]$CurrentDailyCounter.text = 0 + Write-Output $CurrentDailyCounter.text | Out-File $DailyLogFile + Start-Process "rundll32.exe" "user32.dll, LockWorkStation" +} + +$LogMonthlyCounterToMonthFile = New-Object system.Windows.Forms.Button +$LogMonthlyCounterToMonthFile.text = "Export Month" +$LogMonthlyCounterToMonthFile.width = 50 +$LogMonthlyCounterToMonthFile.height = 30 +$LogMonthlyCounterToMonthFile.location = New-Object System.Drawing.Point(185,60) +$LogMonthlyCounterToMonthFile.Font = New-Object System.Drawing.Font('Segoe UI',8) +$LogMonthlyCounterToMonthFile.Add_Click{ + Copy-Item $TotalLogFile "$LogDir\Monthly\MonthTickets-$(Get-Date -Format "MMMM-yyyy_$(Get-Random)").txt" + [int]$CurrentTotalCounter.text = 0 + Write-Output $CurrentTotalCounter.text | Out-File $TotalLogFile +} + +$CurrentDailyCounter = New-Object system.Windows.Forms.Label +$CurrentDailyCounter.text = [int]$CurrentDaily +$CurrentDailyCounter.AutoSize = $true +$CurrentDailyCounter.width = 50 +$CurrentDailyCounter.height = 10 +$CurrentDailyCounter.location = New-Object System.Drawing.Point(102,48) +$CurrentDailyCounter.Font = New-Object System.Drawing.Font('Segoe UI',10) + +$CurrentTotalCounter = New-Object system.Windows.Forms.Label +$CurrentTotalCounter.text = [int]$CurrentMonthly +$CurrentTotalCounter.AutoSize = $true +$CurrentTotalCounter.width = 50 +$CurrentTotalCounter.height = 10 +$CurrentTotalCounter.location = New-Object System.Drawing.Point(102,71) +$CurrentTotalCounter.Font = New-Object System.Drawing.Font('Segoe UI',10) + +$Form.controls.AddRange(@($LogMonthlyCounterToMonthFile,$TotalCounter,$DailyCounter,$DailyAddTicketToCount,$MonthlyAddDailyCountToTotal,$CurrentDailyCounter,$CurrentTotalCounter)) + [void]$Form.ShowDialog() \ No newline at end of file