TicketCounter/Ticket-Counter.ps1

126 lines
No EOL
6 KiB
PowerShell

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()