Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Start up Config
- $UITitle = "Make Quote Folder"
- $host.UI.RawUI.WindowTitle = $UITitle
- Set-Location "F:\Sales\D. Blasdell\_Quotes"
- #define default Vaules
- $S0 = ""
- $jobname = ""
- $contractor = ""
- $exit = ""
- $Filenames = "F:\Sales\D. Blasdell\Spread Sheets\Folder_names.txt"
- $error = 1
- #Inport .NET framewoks
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- Add-Type -AssemblyName PresentationCore,PresentationFramework
- #ERROR loop
- Do{
- ############################################################################
- ######################## Text Box Start ####################################
- ############################################################################
- #make Box
- $form = New-Object System.Windows.Forms.Form
- $form.Text = 'Make Quote Folder'
- $form.Size = New-Object System.Drawing.Size(500,230)
- $form.StartPosition = 'CenterScreen'
- #Make buttons
- $OKButton = New-Object System.Windows.Forms.Button
- $OKButton.Location = New-Object System.Drawing.Point(300,150)
- $OKButton.Size = New-Object System.Drawing.Size(75,23)
- $OKButton.Text = 'OK'
- $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
- $form.AcceptButton = $OKButton
- $form.Controls.Add($OKButton)
- $CancelButton = New-Object System.Windows.Forms.Button
- $CancelButton.Location = New-Object System.Drawing.Point(400,150)
- $CancelButton.Size = New-Object System.Drawing.Size(75,23)
- $CancelButton.Text = 'Cancel'
- $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
- $form.Controls.Add($CancelButton)
- #Add Text
- $label0 = New-Object System.Windows.Forms.Label
- $label0.Location = New-Object System.Drawing.Point (145,20)
- $label0.Size = New-Object System.Drawing.Size(250,20)
- $label0.Text = "Fill out the Boxes Below with a-z,A-Z,0-9 #_&."
- $form.Controls.Add($label0)
- $label = New-Object System.Windows.Forms.Label
- $label.Location = New-Object System.Drawing.Point(10,50)
- $label.Size = New-Object System.Drawing.Size(30,20)
- $label.Text = 'S0#:'
- $form.Controls.Add($label)
- $label2 = New-Object System.Windows.Forms.Label
- $label2.Location = New-Object System.Drawing.Point(10,80)
- $label2.Size = New-Object System.Drawing.Size(60,20)
- $label2.Text = 'Job Name:'
- $form.Controls.Add($label2)
- $label3 = New-Object System.Windows.Forms.Label
- $label3.Location = New-Object System.Drawing.Point(10,110)
- $label3.Size = New-Object System.Drawing.Size(60,20)
- $label3.Text = 'Contractor:'
- $form.Controls.Add($label3)
- #Add Boxes
- $textBox1 = New-Object System.Windows.Forms.TextBox
- $textBox1.Location = New-Object System.Drawing.Point(160,50)
- $textBox1.Size = New-Object System.Drawing.Size(310,20)
- $form.Controls.Add($textBox1)
- $textBox2 = New-Object System.Windows.Forms.TextBox
- $textBox2.Location = New-Object System.Drawing.Point(160,80)
- $textBox2.Size = New-Object System.Drawing.Size(310,20)
- $form.Controls.Add($textBox2)
- $textBox3 = New-Object System.Windows.Forms.TextBox
- $textBox3.Location = New-Object System.Drawing.Point(160,110)
- $textBox3.Size = New-Object System.Drawing.Size(310,20)
- $form.Controls.Add($textBox3)
- #Move to top
- $form.Top = $true
- $form.Add_Shown({$textBox1.Select()})
- $result = $form.ShowDialog()
- #Check inputs
- if ($result -eq [System.Windows.Forms.DialogResult]::Cancel){
- exit
- }
- if ($result -eq [System.Windows.Forms.DialogResult]::OK)
- {
- $error = 1
- $ErrorMessage = "Invalid Input:"
- #Error Function
- Function is-Good($Vaule,$ErrVaule){
- if($Vaule -eq ""){
- $ErrorMessage = $ErrorMessage + "`n" + "Please Fill in the"+ "$ErrVaule" + "Box"
- $Error = 2
- }
- if ($Vaule -notmatch '[^a-z0-9 _&-]') {
- $ErrorMessage = $ErrorMessage + "`n" + "Please Use A-Z, a-z and 0-9 in the"+"$ErrVaule" +"Box"
- $Error = 2
- }
- }
- #Name Holders
- $Temp1 = "S0#"
- $Temp2 = "Job Name"
- $Temp3 = "Contractor"
- #Call Error Function
- is-Good($TextBox1.Text,$Temp1)
- is-Good($TextBox2.Text,$Temp2)
- is-Good($TextBox3.Text,$Temp3)
- #IF error show error box
- if($Error -eq 2)
- {
- [System.Windows.MessageBox]::Show($ErrorMessage,"Make Quote Folder ERROR",0,16)
- }
- #Export good inputs#>
- if ($error -eq 1){
- $S0 = $textBox1.Text
- $jobname = $textBox2.Text
- $contractor = $TextBox3.Text
- $end = $exit
- $error = 0
- }
- }
- Write-host $Texbox1.Text
- ############################################################################
- ########################## Text Box End ####################################
- ############################################################################
- }until ($error -eq 0)
- #Set combined Veriables
- $folder = "$S0" + "_" + "$jobname" + "_" + "$contractor"
- $subsubfolder = "./"+"$folder" + "/1 - Estimating Orginal Quote Material"
- $takeoffname = "$s0" + "_takeoff.xlsx"
- $PILname = "PIL_" + "$S0" +".xlsx"
- #Make master folder
- New-Item -ItemType Directory "./$folder"
- #Make Subfolder
- foreach($line in Get-Content $Filenames)
- {
- New-Item $folder\$line -ItemType Directory
- }
- #Copy Files
- Copy-Item '.\_master_takeoff.xlsx' "$subsubfolder\_master_takeoff.xlsx"
- Copy-Item '.\PIL_SOXXXXX.xlsx' $subsubfolder
- #Rename Files
- Rename-Item -Path "$subsubfolder\_master_takeoff.xlsx" -newname $takeoffname
- Rename-Item -Path "$subsubfolder\PIL_SOXXXXX.xlsx" -newname $PILname
- ############################
- #Write to new take off file
- ############################
- #Call excel and open file
- $xl = New-Object -ComObject excel.application
- Start-Sleep -Seconds 5
- $xl.Visible = $true
- Start-Sleep -Seconds 5
- $wb = $xl.Workbooks.Open("$subsubfolder\$takeoffname")
- $data = $wb.Worksheets.Item("Storm")
- $Data.Cells.Item(1,2) = "$jobname"
- $data.Cells.Item(1,7) = "$S0"
- $wb.Save()
- $xl.Quit()
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement