Guest User

Untitled

a guest
May 18th, 2016
186
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $entryDate = get-date -Format G
  2. $inputXML = @"
  3. <Window x:Class="WpfApplication2.MainWindow"
  4.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  5.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  6.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8.        xmlns:local="clr-namespace:WpfApplication2"
  9.        mc:Ignorable="d"
  10.        Title="Braen Haledon Quarry Truck Que" Height="680.794" Width="777" Topmost="True">
  11.        <Grid Margin="0,0,45,0">
  12.        <Image x:Name="image" HorizontalAlignment="Left" Height="100" Margin="24,28,0,0" VerticalAlignment="Top" Width="100" Source="\\nas\IT\BRAEN STONE LOGO GREEN.jpg"/>
  13.        <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Height="100" Margin="174,28,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="16"><Run Text="Haledon Truck Que"/><InlineUIContainer>
  14.        </InlineUIContainer></TextBlock>
  15.        <TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Height="100" Margin="224,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="14"><Run Text="Truck ID"/><InlineUIContainer>
  16.        </InlineUIContainer></TextBlock>
  17.        <TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Height="100" Margin="353,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="14"><Run Text="Job ID"/><InlineUIContainer>
  18.        </InlineUIContainer></TextBlock>
  19.        <TextBlock x:Name="textBlock3" HorizontalAlignment="Left" Height="100" Margin="435,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="14"><Run Text="Amount"/><InlineUIContainer>
  20.        </InlineUIContainer></TextBlock>
  21.        <TextBlock x:Name="textBlock4" HorizontalAlignment="Left" Height="100" Margin="515,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="14"><Run Text="Cus ID"/><InlineUIContainer>
  22.        </InlineUIContainer></TextBlock>
  23.        <TextBlock x:Name="textBlock18" HorizontalAlignment="Left" Height="100" Margin="576,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="14"><Run Text="Product ID"/><InlineUIContainer>
  24.        </InlineUIContainer></TextBlock>
  25.        <TextBlock x:Name="textBlock19" HorizontalAlignment="Left" Height="100" Margin="135,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="14"><Run Text="Carrier ID"/><InlineUIContainer>
  26.        </InlineUIContainer></TextBlock>
  27.        <TextBlock x:Name="textBlock20" HorizontalAlignment="Left" Height="100" Margin="15,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text=""/><InlineUIContainer>
  28.        </InlineUIContainer></TextBlock>    
  29.        <TextBlock x:Name="textBlock5" HorizontalAlignment="Left" Height="100" Margin="560,34,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="14"><Run Text="Slot to Delete"/><InlineUIContainer>
  30.        </InlineUIContainer></TextBlock>
  31.        <TextBlock x:Name="textBlock6" HorizontalAlignment="Left" Height="100" Margin="675,203,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 0"/><InlineUIContainer>
  32.        </InlineUIContainer></TextBlock>
  33.        <TextBlock x:Name="textBlock7" HorizontalAlignment="Left" Height="100" Margin="675,228,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 1"/><InlineUIContainer>
  34.        </InlineUIContainer></TextBlock>
  35.        <TextBlock x:Name="textBlock8" HorizontalAlignment="Left" Height="100" Margin="675,251,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 2"/><InlineUIContainer>
  36.        </InlineUIContainer></TextBlock>
  37.        <TextBlock x:Name="textBlock9" HorizontalAlignment="Left" Height="100" Margin="675,274,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 3"/><InlineUIContainer>
  38.        </InlineUIContainer></TextBlock>
  39.        <TextBlock x:Name="textBlock10" HorizontalAlignment="Left" Height="100" Margin="675,297,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 4"/><InlineUIContainer>
  40.        </InlineUIContainer></TextBlock>
  41.        <TextBlock x:Name="textBlock11" HorizontalAlignment="Left" Height="100" Margin="675,321,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 5"/><InlineUIContainer>
  42.        </InlineUIContainer></TextBlock>
  43.        <TextBlock x:Name="textBlock12" HorizontalAlignment="Left" Height="100" Margin="675,345,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 6"/><InlineUIContainer>
  44.        </InlineUIContainer></TextBlock>
  45.        <TextBlock x:Name="textBlock13" HorizontalAlignment="Left" Height="100" Margin="675,368,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 7"/><InlineUIContainer>
  46.        </InlineUIContainer></TextBlock>
  47.        <TextBlock x:Name="textBlock14" HorizontalAlignment="Left" Height="100" Margin="675,389,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 8"/><InlineUIContainer>
  48.        </InlineUIContainer></TextBlock>
  49.        <TextBlock x:Name="textBlock15" HorizontalAlignment="Left" Height="100" Margin="675,412,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 9"/><InlineUIContainer>
  50.        </InlineUIContainer></TextBlock>
  51.        <TextBlock x:Name="textBlock16" HorizontalAlignment="Left" Height="100" Margin="675,435,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 10"/><InlineUIContainer>
  52.        </InlineUIContainer></TextBlock>
  53.        <TextBlock x:Name="textBlock17" HorizontalAlignment="Left" Height="100" Margin="675,458,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="282" FontSize="12"><Run Text="Slot 11"/><InlineUIContainer>
  54.        </InlineUIContainer></TextBlock>
  55.        <Button x:Name="button" Content="Update Que" HorizontalAlignment="Left" Height="35" Margin="174,54,0,0" VerticalAlignment="Top" Width="121" FontSize="18.667"/>
  56.        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="30" Margin="204,104,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" FontSize="16"/>
  57.        <TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="30" Margin="330,104,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="100" FontSize="16"/>
  58.        <TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="30" Margin="445,104,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="30" FontSize="16"/>
  59.        <TextBox x:Name="textBox3" HorizontalAlignment="Left" Height="30" Margin="505,104,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="60" FontSize="16"/>
  60.        <TextBox x:Name="textBox5" HorizontalAlignment="Left" Height="30" Margin="570,104,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="80" FontSize="16"/>
  61.        <TextBox x:Name="textBox6" HorizontalAlignment="Left" Height="30" Margin="145,104,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40" FontSize="16"/>
  62.        <Button x:Name="button1" Content="Enter Truck" HorizontalAlignment="Left" Height="35" Margin="300,54,0,0" VerticalAlignment="Top" Width="121" FontSize="18.667"/>
  63.        <Button x:Name="button2" Content="Remove from Que" HorizontalAlignment="Left" Height="35" Margin="434,54,0,0" VerticalAlignment="Top" Width="121" FontSize="13"/>
  64.        <TextBox x:Name="textBox4" HorizontalAlignment="Left" Height="30" Margin="560,54,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" FontSize="16"/>
  65.        <ListView x:Name="listView" HorizontalAlignment="Left" Height="450" Margin="5,175,0,0" VerticalAlignment="Top" Width="668" FontSize="14">
  66.            <ListView.View>
  67.                <GridView>
  68.                    <GridViewColumn Header="C-ID" DisplayMemberBinding ="{Binding 'Carrier ID'}" Width="45"/>
  69.                    <GridViewColumn Header="Truck ID" DisplayMemberBinding ="{Binding 'Truck ID'}" Width="100"/>
  70.                    <GridViewColumn Header="Job ID" DisplayMemberBinding ="{Binding 'Job ID'}" Width="100"/>
  71.                    <GridViewColumn Header="Amount" DisplayMemberBinding ="{Binding 'Amount'}" Width="60"/>
  72.                    <GridViewColumn Header="Customer ID" DisplayMemberBinding ="{Binding 'Customer ID'}" Width="90"/>
  73.                    <GridViewColumn Header="Product ID" DisplayMemberBinding ="{Binding 'Product ID'}" Width="90"/>
  74.                    <GridViewColumn Header="Date of Entry" DisplayMemberBinding ="{Binding 'date of entry'}" Width="180"/>
  75.                </GridView>
  76.            </ListView.View>
  77.        </ListView>
  78.  
  79.  
  80.    </Grid>
  81. </Window>
  82.  
  83. "@      
  84.  
  85. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  86.  
  87.  
  88. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  89. [xml]$XAML = $inputXML
  90. #Read XAML
  91.  
  92.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  93.   try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  94. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  95.  
  96. #===========================================================================
  97. # Store Form Objects In PowerShell
  98. #===========================================================================
  99.  
  100. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  101.  
  102. Function Get-FormVariables{
  103.   if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  104.   write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  105.   get-variable WPF*
  106. }
  107.  
  108. #Get-FormVariables
  109.  
  110. #===========================================================================
  111. #  make the objects work
  112. #===========================================================================
  113.  
  114.  
  115.  
  116. Function TQue{
  117.   $truckque = @()
  118.  
  119.  
  120.   $adOpenStatic = 3
  121.   $adLockOptimistic = 3
  122.  
  123.   $objConnection = New-Object -comobject ADODB.Connection
  124.   $objRecordset = New-Object -comobject ADODB.Recordset
  125.  
  126.   $objConnection.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = c:\Database\gen3data.mdb")
  127.   $objRecordset.Open("Select * from QueueTrucks", $objConnection,$adOpenStatic,$adLockOptimistic)
  128.  
  129.   $objRecordset.MoveFirst()
  130.  
  131.   do  {   $a = $objRecordset.Fields.Item("Truck_ID").Value
  132.         $b = $objRecordset.Fields.Item("Job_ID").Value
  133.         $c = $objRecordset.Fields.Item("Amount").Value
  134.         $d = $objRecordset.Fields.Item("LastModifieddate").Value
  135.         $e = $objRecordset.Fields.Item("Customer_ID").Value
  136.         $f = $objRecordset.Fields.Item("Product_ID").Value
  137.         $g = $objRecordset.Fields.Item("Carrier_ID").Value
  138.         $truckq    = [PSCustomobject]@{
  139.                                       "Truck ID"          = $a
  140.                                       "Job ID"            = $b
  141.                                       "Amount"            = $c
  142.                                       "date of entry"     = $d
  143.                                       "Customer ID"       = $e
  144.                                       "Product ID"        = $f
  145.                                       "Carrier ID"        = $g
  146.                                       }
  147.         $truckque += $truckq
  148.  
  149.     $objRecordset.MoveNext() }
  150.   until ($objRecordset.EOF -eq $True)
  151.  
  152.   $objRecordset.Close()
  153.   $objConnection.Close()
  154.  
  155.   $truckque | Select-Object       @{Name='Carrier ID';Ex={$_."Carrier ID"}},
  156.                                   @{Name='Truck ID';Ex={$_."Truck ID"}},
  157.                                   @{Name='Customer ID';Ex={$_."Customer ID"}},
  158.                                   @{Name='Job ID';Ex={$_."Job ID"}},
  159.                                   @{Name='Product ID';Ex={$_."Product ID"}},
  160.                                   @{Name='Amount';Ex={$_."Amount"}},
  161.                                   @{Name='Date of Entry';Ex={$_."Date of Entry"}}
  162. }
  163.  
  164. Function AddQue {
  165.   param($truckid,$custid,$jobid,$amt,$proarea,$productID,$carrierID)
  166.  
  167.  
  168.   $adOpenStatic = 3
  169.   $adLockOptimistic = 3
  170.  
  171.   $objConnection = New-Object -comobject ADODB.Connection
  172.   $objRecordset = New-Object -comobject ADODB.Recordset
  173.  
  174.   $objConnection.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = c:\Database\Gen3Data.mdb")
  175.   $objRecordset.Open("Select * from QueueTrucks", $objConnection,$adOpenStatic,$adLockOptimistic)
  176.  
  177.   $objRecordset.MoveLast()
  178.   $objRecordset.AddNew()
  179.   $objRecordset.Fields.Item("Truck_ID").Value          = $truckid
  180.   $objRecordset.Fields.Item("Customer_ID").Value          = $custid
  181.   $objRecordset.Fields.Item("Job_ID").Value            = $JobID
  182.   $objRecordset.Fields.Item("Amount").Value = $amt
  183.   $objRecordset.Fields.Item("LastModifieddate").Value = Get-Date -Format G
  184.   $objRecordset.Fields.Item("ProcessAreaType").Value = 2
  185.   $objRecordset.Fields.Item("Product_ID").Value = $productID
  186.   $objRecordset.Fields.Item("Area_ID").Value = 0
  187.   $objRecordset.Fields.Item("Carrier_ID").Value = $carrierID
  188.   $objRecordset.Update()
  189.   $objRecordset.Close()
  190.   $objConnection.Close()
  191.  
  192. }
  193.  
  194. Function RemoveQue {
  195.   param($trknum)
  196.   $adOpenStatic = 3
  197.   $adLockOptimistic = 3
  198.  
  199.   $objConnection = New-Object -comobject ADODB.Connection
  200.   $objRecordset = New-Object -comobject ADODB.Recordset
  201.  
  202.   $objConnection.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = c:\Database\Gen3Data.mdb")
  203.   $objRecordset.Open("Select * from QueueTrucks", $objConnection,$adOpenStatic,$adLockOptimistic)
  204.  
  205.   $objRecordset.Move($trknum)
  206.   $objRecordset.Delete()
  207.   $objRecordset.Update()
  208.  
  209.   $objRecordset.Close()
  210.   $objConnection.Close()
  211.  
  212. }
  213.                                                                  
  214. Tque | % {$WPFlistView.AddChild($_)}
  215.  
  216. $WPFbutton.Add_Click({
  217.     $WPFlistView.Items.Clear()
  218.     start-sleep -Milliseconds 840
  219.     Tque | % {$WPFlistView.AddChild($_)}
  220. })
  221.  
  222.  
  223. ## Process Area 2 for drum plant
  224.  
  225. $WPFbutton1.Add_Click({
  226.     $WPFlistView.Items.Clear()
  227.     start-sleep -Milliseconds 840
  228.     AddQue -truckid $WPFtextBox.Text -jobid $WPFtextBox1.Text -amt $WPFtextBox2.Text -custid $WPFtextBox3.Text -proarea "2" -productID $WPFtextBox5.text -carrierID $WPFtextBox6.Text
  229.     Tque | % {$WPFlistView.AddChild($_)}
  230. })
  231.  
  232. $WPFbutton2.Add_Click({
  233.     $WPFlistView.Items.Clear()
  234.     start-sleep -Milliseconds 840
  235.    
  236.       RemoveQue -trknum $WPFtextBox4.Text
  237.       Tque | % {$WPFlistView.AddChild($_)}  
  238. })
  239.  
  240. ########-------------# Mount Actions #------------#########
  241.  
  242. $WPFtextBox.add_MouseEnter({$WPFtextBlock20.Text  = "Enter TRUCK ID"})
  243. $WPFtextBox.Add_MouseLeave({$WPFtextBlock20.Text  = ""})
  244.  
  245. $WPFtextBox1.add_MouseEnter({$WPFtextBlock20.Text = "Enter Job ID"})
  246. $WPFtextBox1.Add_MouseLeave({$WPFtextBlock20.Text = ""})
  247.  
  248. $WPFtextBox2.add_MouseEnter({$WPFtextBlock20.Text = "Input Amount"})
  249. $WPFtextBox2.Add_MouseLeave({$WPFtextBlock20.Text = ""})
  250.  
  251. $WPFtextBox3.add_MouseEnter({$WPFtextBlock20.Text = "Input Customer ID"})
  252. $WPFtextBox3.Add_MouseLeave({$WPFtextBlock20.Text = ""})
  253.  
  254. $WPFtextBox5.add_MouseEnter({$WPFtextBlock20.Text = "Input Product ID"})
  255. $WPFtextBox5.Add_MouseLeave({$WPFtextBlock20.Text = ""})
  256.  
  257. $WPFtextBox6.add_MouseEnter({$WPFtextBlock20.Text = "Enter Carrier ID"})
  258. $WPFtextBox6.Add_MouseLeave({$WPFtextBlock20.Text = ""})
  259.  
  260. $WPFtextBox4.add_MouseEnter({$WPFtextBlock20.Text = "Pick Slot from Table"})
  261. $WPFtextBox4.Add_MouseLeave({$WPFtextBlock20.Text = ""})
  262.  
  263. #===========================================================================
  264. # Shows the form
  265. #===========================================================================
  266. #write-host "To show the form, run the following" -ForegroundColor Cyan
  267. $Form.ShowDialog() | out-null
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×