refactor: Reposition status textbox and add DataGridView in MainForm.ps1

This commit is contained in:
Bobby Abellana (aider) 2025-02-21 10:02:34 -08:00
parent aed44fc07d
commit 2c18235425

View File

@ -10,7 +10,7 @@ Import-Module Microsoft.Graph.Files
# Create main form # Create main form
$form = New-Object System.Windows.Forms.Form $form = New-Object System.Windows.Forms.Form
$form.Text = "SharePoint XLS Converter" $form.Text = "SharePoint XLS Converter"
$form.Size = New-Object System.Drawing.Size(600,500) $form.Size = New-Object System.Drawing.Size(800, 600) # Increased form size
# Set AutoScaleMode to Dpi # Set AutoScaleMode to Dpi
$form.AutoScaleMode = [System.Windows.Forms.AutoScaleMode]::Dpi $form.AutoScaleMode = [System.Windows.Forms.AutoScaleMode]::Dpi
@ -18,68 +18,84 @@ $form.AutoScaleMode = [System.Windows.Forms.AutoScaleMode]::Dpi
# Add controls # Add controls
$lblConfig = New-Object System.Windows.Forms.Label $lblConfig = New-Object System.Windows.Forms.Label
$lblConfig.Text = "SharePoint Configuration:" $lblConfig.Text = "SharePoint Configuration:"
$lblConfig.Location = New-Object System.Drawing.Point(20,20) $lblConfig.Location = New-Object System.Drawing.Point(20, 20)
$lblConfig.Size = New-Object System.Drawing.Size(200,20) $lblConfig.Size = New-Object System.Drawing.Size(200, 20)
$form.Controls.Add($lblConfig) $form.Controls.Add($lblConfig)
$txtSiteUrl = New-Object System.Windows.Forms.TextBox $txtSiteUrl = New-Object System.Windows.Forms.TextBox
$txtSiteUrl.Location = New-Object System.Drawing.Point(20,40) $txtSiteUrl.Location = New-Object System.Drawing.Point(20, 40)
$txtSiteUrl.Size = New-Object System.Drawing.Size(200,20) $txtSiteUrl.Size = New-Object System.Drawing.Size(200, 20)
$txtSiteUrl.PlaceholderText = "Site URL" $txtSiteUrl.PlaceholderText = "Site URL"
$txtProdLib = New-Object System.Windows.Forms.TextBox $txtProdLib = New-Object System.Windows.Forms.TextBox
$txtProdLib.Location = New-Object System.Drawing.Point(20,70) $txtProdLib.Location = New-Object System.Drawing.Point(20, 70)
$txtProdLib.Size = New-Object System.Drawing.Size(200,20) $txtProdLib.Size = New-Object System.Drawing.Size(200, 20)
$txtProdLib.PlaceholderText = "Production Library" $txtProdLib.PlaceholderText = "Production Library"
$txtTempLib = New-Object System.Windows.Forms.TextBox $txtTempLib = New-Object System.Windows.Forms.TextBox
$txtTempLib.Location = New-Object System.Drawing.Point(20,100) $txtTempLib.Location = New-Object System.Drawing.Point(20, 100)
$txtTempLib.Size = New-Object System.Drawing.Size(200,20) $txtTempLib.Size = New-Object System.Drawing.Size(200, 20)
$txtTempLib.PlaceholderText = "Temp Library" $txtTempLib.PlaceholderText = "Temp Library"
$txtFolder = New-Object System.Windows.Forms.TextBox $txtFolder = New-Object System.Windows.Forms.TextBox
$txtFolder.Location = New-Object System.Drawing.Point(20,130) $txtFolder.Location = New-Object System.Drawing.Point(20, 130)
$txtFolder.Size = New-Object System.Drawing.Size(200,20) $txtFolder.Size = New-Object System.Drawing.Size(200, 20)
$txtFolder.PlaceholderText = "Folder Path (optional)" $txtFolder.PlaceholderText = "Folder Path (optional)"
$btnBrowse = New-Object System.Windows.Forms.Button $btnBrowse = New-Object System.Windows.Forms.Button
$btnBrowse.Location = New-Object System.Drawing.Point(230,130) $btnBrowse.Location = New-Object System.Drawing.Point(230, 130)
$btnBrowse.Size = New-Object System.Drawing.Size(80,20) $btnBrowse.Size = New-Object System.Drawing.Size(80, 20)
$btnBrowse.Text = "Browse" $btnBrowse.Text = "Browse"
$btnList = New-Object System.Windows.Forms.Button $btnList = New-Object System.Windows.Forms.Button
$btnList.Location = New-Object System.Drawing.Point(20,170) $btnList.Location = New-Object System.Drawing.Point(20, 170)
$btnList.Size = New-Object System.Drawing.Size(120,30) $btnList.Size = New-Object System.Drawing.Size(120, 30)
$btnList.Text = "List XLS Files" $btnList.Text = "List XLS Files"
$form.Controls.Add($btnList) $form.Controls.Add($btnList)
$btnConvert = New-Object System.Windows.Forms.Button $btnConvert = New-Object System.Windows.Forms.Button
$btnConvert.Location = New-Object System.Drawing.Point(160,170) $btnConvert.Location = New-Object System.Drawing.Point(160, 170)
$btnConvert.Size = New-Object System.Drawing.Size(120,30) $btnConvert.Size = New-Object System.Drawing.Size(120, 30)
$btnConvert.Text = "Convert to XLSX" $btnConvert.Text = "Convert to XLSX"
$form.Controls.Add($btnConvert) $form.Controls.Add($btnConvert)
$btnMove = New-Object System.Windows.Forms.Button $btnMove = New-Object System.Windows.Forms.Button
$btnMove.Location = New-Object System.Drawing.Point(300,170) $btnMove.Location = New-Object System.Drawing.Point(300, 170)
$btnMove.Size = New-Object System.Drawing.Size(120,30) $btnMove.Size = New-Object System.Drawing.Size(120, 30)
$btnMove.Text = "Move Files" $btnMove.Text = "Move Files"
$form.Controls.Add($btnMove) $form.Controls.Add($btnMove)
# Create Status TextBox (Top Right)
$txtStatus = New-Object System.Windows.Forms.TextBox $txtStatus = New-Object System.Windows.Forms.TextBox
$txtStatus.Location = New-Object System.Drawing.Point(20,210) $txtStatus.Location = New-Object System.Drawing.Point(450, 20) # Top Right Corner
$txtStatus.Size = New-Object System.Drawing.Size(540,240) $txtStatus.Size = New-Object System.Drawing.Size(330, 180) # Adjusted size
$txtStatus.Multiline = $true $txtStatus.Multiline = $true
$txtStatus.ScrollBars = "Vertical" $txtStatus.ScrollBars = "Vertical"
# Anchor the textbox to the form's edges
$txtStatus.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor ` $txtStatus.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor `
[System.Windows.Forms.AnchorStyles]::Bottom -bor ` [System.Windows.Forms.AnchorStyles]::Right
[System.Windows.Forms.AnchorStyles]::Left -bor `
[System.Windows.Forms.AnchorStyles]::Right
$form.Controls.Add($txtStatus) $form.Controls.Add($txtStatus)
# Create DataGridView (Lower 2/3)
$dataGridView = New-Object System.Windows.Forms.DataGridView
$dataGridView.Location = New-Object System.Drawing.Point(20, 210)
$dataGridView.Size = New-Object System.Drawing.Size(760, 340) # Lower 2/3 of the form
$dataGridView.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor `
[System.Windows.Forms.AnchorStyles]::Left -bor `
[System.Windows.Forms.AnchorStyles]::Right -bor `
[System.Windows.Forms.AnchorStyles]::Top
$dataGridView.AutoSizeColumnsMode = [System.Windows.Forms.DataGridViewAutoSizeColumnsMode]::Fill
$form.Controls.Add($dataGridView)
# Add columns to DataGridView
$dataGridView.ColumnCount = 3
$dataGridView.Columns[0].Name = "Original Path"
$dataGridView.Columns[1].Name = "Original File Name"
$dataGridView.Columns[2].Name = "Temp Path"
# Add Save Config button # Add Save Config button
$btnSaveConfig = New-Object System.Windows.Forms.Button $btnSaveConfig = New-Object System.Windows.Forms.Button
$btnSaveConfig.Location = New-Object System.Drawing.Point(230,40) $btnSaveConfig.Location = New-Object System.Drawing.Point(230, 40)
$btnSaveConfig.Size = New-Object System.Drawing.Size(80,20) $btnSaveConfig.Size = New-Object System.Drawing.Size(80, 20)
$btnSaveConfig.Text = "Save Config" $btnSaveConfig.Text = "Save Config"
$btnSaveConfig.Add_Click({ $btnSaveConfig.Add_Click({
Save-Config -SiteUrl $txtSiteUrl.Text ` Save-Config -SiteUrl $txtSiteUrl.Text `
@ -89,8 +105,8 @@ $btnSaveConfig.Add_Click({
# Add Connect button # Add Connect button
$btnConnect = New-Object System.Windows.Forms.Button $btnConnect = New-Object System.Windows.Forms.Button
$btnConnect.Location = New-Object System.Drawing.Point(320,40) $btnConnect.Location = New-Object System.Drawing.Point(320, 40)
$btnConnect.Size = New-Object System.Drawing.Size(80,20) $btnConnect.Size = New-Object System.Drawing.Size(80, 20)
$btnConnect.Text = "Connect" $btnConnect.Text = "Connect"
$btnConnect.Add_Click({ $btnConnect.Add_Click({
if (Connect-SharePoint) { if (Connect-SharePoint) {
@ -133,7 +149,6 @@ $btnBrowse.Add_Click({
if ($selectedFolder) { if ($selectedFolder) {
# Use the ServerRelativeUrl directly from the folder browser # Use the ServerRelativeUrl directly from the folder browser
$script:txtFolder.Text = $selectedFolder.ServerRelativeUrl $script:txtFolder.Text = $selectedFolder.ServerRelativeUrl
$script:txtStatus.Text += "Selected folder: $($selectedFolder.ServerRelativeUrl)`n"
} }
} }
catch { catch {
@ -141,6 +156,10 @@ $btnBrowse.Add_Click({
} }
}) })
# Store the DataGridView and txtStatus in script scope
$script:dataGridView = $dataGridView
$script:txtStatus = $txtStatus
# Show form # Show form
$form.Add_Shown({$form.Activate()}) $form.Add_Shown({ $form.Activate() })
[void]$form.ShowDialog() [void]$form.ShowDialog()