Load required assemblies
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
function Show-MessageBox {
param (
[string]$message,
[string]$title
)
[System.Windows.Forms.MessageBox]::Show($message, $title)
}
function Run-Queries {
param (
[string]$selectedDate
)
$queries = @(
"SELECT * FROM your_table WHERE date_column = TO_DATE('$selectedDate', 'YYYY-MM-DD')"
) * 10
$connectionString = "User Id=username;Password=password;Data Source=hostname/service_name"
try {
$connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
$connection.Open()
$excel = Open-ExcelPackage -Path 'your_excel_file.xlsx'
$worksheet = $excel.Workbook.Worksheets[2] # Sheet number 3 (index 2)
$worksheet.Cells.Clear()
$progressBar.Maximum = $queries.Length
$progressBar.Value = 0
for ($i = 0; $i -lt $queries.Length; $i++) {
$statusLabel.Text = "Status: Running query $($i + 1)"
[System.Windows.Forms.Application]::DoEvents()
$command = $connection.CreateCommand()
$command.CommandText = $queries[$i]
$reader = $command.ExecuteReader()
$dataTable = New-Object System.Data.DataTable
$dataTable.Load($reader)
$rowIndex = $worksheet.Dimension?.End.Row + 1
if ($null -eq $rowIndex) { $rowIndex = 1 }
Export-Excel -Worksheet $worksheet -Append -InputObject $dataTable -StartRow $rowIndex -StartColumn 1 -TableName "QueryData"
$progressBar.Value = $i + 1
}
Close-ExcelPackage -ExcelPackage $excel
$connection.Close()
Show-MessageBox -message "All queries executed successfully." -title "Success"
} catch {
Show-MessageBox -message "An error occurred: $_" -title "Failure"
}
}
Create the form
$form = New-Object System.Windows.Forms.Form
$form.Text = “Oracle Query Executor”
$form.Size = New-Object System.Drawing.Size(400, 300)
$form.StartPosition = “CenterScreen”
Create a date picker
$datePicker = New-Object System.Windows.Forms.DateTimePicker
$datePicker.Format = [System.Windows.Forms.DateTimePickerFormat]::Short
$datePicker.Location = New-Object System.Drawing.Point(10, 10)
$form.Controls.Add($datePicker)
Create a progress bar
$progressBar = New-Object System.Windows.Forms.ProgressBar
$progressBar.Location = New-Object System.Drawing.Point(10, 50)
$progressBar.Size = New-Object System.Drawing.Size(360, 30)
$form.Controls.Add($progressBar)
Create a status label
$statusLabel = New-Object System.Windows.Forms.Label
$statusLabel.Text = “Status: Waiting to start”
$statusLabel.Location = New-Object System.Drawing.Point(10, 90)
$form.Controls.Add($statusLabel)
Create a button
$runButton = New-Object System.Windows.Forms.Button
$runButton.Text = “Run Queries”
$runButton.Location = New-Object System.Drawing.Point(10, 130)
$runButton.Add_Click({
$selectedDate = $datePicker.Value.ToString("yyyy-MM-dd")
Run-Queries -selectedDate $selectedDate
})
$form.Controls.Add($runButton)
Show the form
$form.ShowDialog()
I want to install modules but I am not able to do it.
Sekhar K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.