Converting from HTML output to GridView
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- cstewart28
- Posts: 12
- Last visit: Thu Sep 01, 2016 8:41 am
Re: Converting from HTML output to GridView
I'm trying to change it, but the only option I have from the Platform drop down is V2 - 32 Bit and V2 - 64 Bit.
- cstewart28
- Posts: 12
- Last visit: Thu Sep 01, 2016 8:41 am
- cstewart28
- Posts: 12
- Last visit: Thu Sep 01, 2016 8:41 am
Re: Converting from HTML output to GridView
I think I have added the progressbar correctly, but now I'm trying to get the rows high lighted based on a value returned from the function and what I found does not seem to work.
Here is the function:
here is the Button:
Also it takes about 30 seconds to return the data and it seems to be all at one, not per line, any ideas on how I can do that with the individually or does it make more since to do it all at once?
Thanks again this is my first attempt at this.
Here is the function:
Code: Select all
# utility function to get camera data
function Get-CameraData
{
Param ($csvfile)
Import-Csv $csvfile |
ForEach-Object{
$progressbaroverlay1.Maximum = $csvfile.count
$item = $_
Try
{
$timetaken = (Measure-Command { $Request = Invoke-WebRequest -Uri $item.ip }).TotalMilliseconds
$progressbaroverlay1.PerformStep()
}
Catch
{
$Request = [PsCustomObject]@{
StatusDescription = $_.Exception.Response
RawContentLength = 0
StatusCode = -1
}
$timetaken = -1
}
[PSCustomObject]@{
#Time = [datetime]::Now
Name = $item.name
Uri = $item.ip
StatusCode = $Request.StatusCode
StatusDescription = $Request.StatusDescription
ResponseLength = $Request.RawContentLength
TimeTaken = $timetaken
}
}
}
here is the Button:
Code: Select all
$buttonCheckCameras_Click = {
$progressbaroverlay1.TextOverlay = 'Checking Camera...'
$progressbaroverlay1.Value = 0
$progressbaroverlay1.Step = 1
$this.enabled = $false
$cameradata = Get-CameraData $CSVFileName.Text
$array = [System.Collections.ArrayList]$cameradata
#$datagridview.DataSource = [System.Collections.ArrayList]$cameradata
$dataGridView.ColumnCount = 6
$dataGridView.ColumnHeadersVisible = $true
$dataGridView.Columns[0].Name = "Name"
$dataGridView.Columns[1].Name = "IP Address"
$dataGridView.Columns[2].Name = "Status Code"
$dataGridView.Columns[3].Name = "Description"
$dataGridView.Columns[4].Name = "Web Response Length"
$dataGridView.Columns[5].Name = "Time Taken(ms)"
foreach ($item in $array)
{
#check if status code is not eqal to 200, which means we can't connect
#statusCode is 3rd item in attay
if ($item[2] -ne "200")
{
#write data to datagridview
$datagridview.Rows.Add($_.name,$_.uri,$_.StatusCode,$_.StatusDescription,$_.ResponseLength,$_.TimeTaken)
#make the row all red
$datagridviewResults_CellFormatting = [System.Windows.Forms.DataGridViewCellFormattingEventHandler]{
$_.CellStyle.BackColor = 'Red'
}
}
else
{
#write data to datagridview
$datagridview.Rows.Add($_.name, $_.uri, $_.StatusCode, $_.StatusDescription, $_.ResponseLength, $_.TimeTaken)
#make the row all green
$datagridviewResults_CellFormatting = [System.Windows.Forms.DataGridViewCellFormattingEventHandler]{
$_.CellStyle.BackColor = 'Green'
}
}
}
$progressbaroverlay1.Value = $progressbaroverlay1.Maximum
$progressbaroverlay1.TextOverlay = 'Complete!'
$this.enabled = $true
Thanks again this is my first attempt at this.
Re: Converting from HTML output to GridView
Start by loading th gris with all data from the CSV plus extra columns for status. Enumerate the grid and test, update progrss and color.
Your approach is lniear and overly complicated. If you simplify things you will find it is easir to do all of this.
I havebeen designing andbuilding Windows based applicaitons for 20+ years. Believe me it should notbethis hard.
THe grid is anexcellent place to start. It is an array of sorts and is a repository for data. Learn how to load it from an object collection or from a CSV file. Enumerate the grid to perform tasks and mark status.
Your approach is lniear and overly complicated. If you simplify things you will find it is easir to do all of this.
I havebeen designing andbuilding Windows based applicaitons for 20+ years. Believe me it should notbethis hard.
THe grid is anexcellent place to start. It is an array of sorts and is a repository for data. Learn how to load it from an object collection or from a CSV file. Enumerate the grid to perform tasks and mark status.
Re: Converting from HTML output to GridView
In an event the system is never updated until the event is exited. THe best way to do thisis to use a background job that enumerates the grid and returns incremental results.cstewart28 wrote: Also it takes about 30 seconds to return the data and it seems to be all at one, not per line, any ideas on how I can do that with the individually or does it make more since to do it all at once?
.
Look into the "Job-Tracker" Control Set to help with this.
Re: Converting from HTML output to GridView
TO update teh format of a row use the row changed event to set teh color or other attirbutes when the row is changed. This allows the form to run in a pure event driven fashion.cstewart28 wrote:I think I have added the progressbar correctly, but now I'm trying to get the rows high lighted based on a value returned from the function and what I found does not seem to work.
Widows and Forms do not work well whenyou use linear programming techniques. Windows is a "state" driven systemm and works best when the state trigegrs and events are used to manage the system/form.