[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1111
  • Last Modified:

Timer Control and Datagrid

Dear all,

I am trying to develop a software where end user will be informed when a particular time has reached.
For example End user puts a plate into an oven. He then creates an entry into the program with the following details Plate Number (1,2,3,4,..etc), Plate Type(round,oval,...etc), Category(Cold,Hot..etc), Time In(This is a clock time)* and Time Out(When he should take the plate out)*.
*(User does not enter Time In and Out, it automatically calculates the time).

Datagridview then displays the entry on to the form. This entry should turn into yellow when the time is reached (lets say after 5 mins). This will inform the user that its time to take the plate out.

I have reached at the point where an end user can make entries, delete entries. I have even made a timer ticker which displays the time on one of the textboxes meaning "Time In" is displaying a current time and when an end user clicks Add button it adds the time along with other entries into the database.

However, I am not sure how to calculate the Time out (i.e. how to make Time out clock to run always 5mins faster than Time In clock) so when a user makes an entry he is shown Time out as 5mins ahead.

maybe something like
textbox1.text=Now.tolongtimestring.tostring() - Timer1 is set at interval 1000 which runs textbox1 clock
textbox2.text=timer1.interval+5000???

not sure at all on this!

In addition to that I am not sure how to highlight a particular row if it reached the time limit. i.e. turning (lets say Row A) into yellow when 5mins are over and turn Row B into yellow when that time has reached.

I have added a 2nd ticker which colours all the rows. here is the code
        Me.LensesdbDataSet.CLtbl.Clear()
        Me.DataGridView1.Refresh()
        Me.DataGridView1.DataSource = Me.LensesdbDataSet.CLtbl
        Me.CLtblTableAdapter.Fill(Me.LensesdbDataSet.CLtbl)
        Me.DataGridView1.RowsDefaultCellStyle.BackColor = Color.Yellow

howerver I want it to colour only that particular row which has reached its time limit.

I am confuse as to how to achive this, can someone please put me to the right path? Pleaseeeeee

######
Please see attached screenshot to get a better idea
######
Many thanks

Regards

Jehanzeb

Edit:
What if I create another database field with the name of Time Counter and set it to integer. This counter should be able to change its values when the datagrid is refreshes and when it reaches 0 the row should colour yellow!

the big question remains the same though, how would I achieve this programmatically.?
TimerApp.JPG
0
jehanzebn
Asked:
jehanzebn
  • 4
  • 2
2 Solutions
 
jehanzebnAuthor Commented:
I think I need to use something along the lines where the datagrid Time Out value keeps changing. i.e. setup datagrid view to refreshes every second and also change value of the column Time out. This way when the Time Out column reaches its limit, it will turn the row into yellow.

But the big question is how do you do it?!!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try this out...
Public Class Form1
 
    Private ds As New DataSet
    Private tb As DataTable
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        tb = ds.Tables.Add("myData")
        tb.Columns.Add("Basket", GetType(String))
        tb.Columns.Add("Lenses", GetType(Integer))
        tb.Columns.Add("Run Type", GetType(String))
        tb.Columns.Add("Time In", GetType(DateTime))
        tb.Columns.Add("Time Out", GetType(DateTime))
 
        DataGridView1.DataSource = tb
        DataGridView1.AllowUserToAddRows = False
        DataGridView1.AllowUserToDeleteRows = False
        DataGridView1.AllowUserToOrderColumns = True
        DataGridView1.AllowUserToResizeColumns = True
        DataGridView1.AllowUserToResizeRows = False
        DataGridView1.Columns("Time In").DefaultCellStyle.Format = "hh:mm:ss"
        DataGridView1.Columns("Time Out").DefaultCellStyle.Format = "hh:mm:ss"
        Timer1.Interval = 500
        Timer1.Enabled = True
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim value As Integer
        If Integer.TryParse(TextBox2.Text, value) Then
            Dim dr As DataRow = tb.NewRow()
            dr("Basket") = TextBox1.Text
            dr("Lenses") = value
            dr("Run Type") = ComboBox1.SelectedItem
            dr("Time In") = DateTime.Now
            dr("Time Out") = DateTime.Now.AddMinutes(15)
            tb.Rows.Add(dr)
        End If
    End Sub
 
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Stop()
        Label1.Text = DateTime.Now.ToString("hh:mm:ss")
        Dim dr As DataGridViewRow
        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            dr = DataGridView1.Rows(i)
            If DateTime.Now > DirectCast(dr.Cells("Time Out").Value, DateTime) Then
                dr.DefaultCellStyle.BackColor = Color.Yellow
            End If
        Next
        Timer1.Start()
    End Sub
 
End Class

Open in new window

0
 
jehanzebnAuthor Commented:
Morning idle,

you are a super star! this worked like a charm. Though I did approach it bit differently however I was stuck on the point where the gridview was not able to turn into yellow on a specific time (as mentioned in my initial post).

One little question though, when I used your code on a new project whenever I close the application and re run it, it opens the datagrid empty. though I was expecting it to be filled with last entries.
This is important as if a user closes the application by accidently or if electricty goes off then they will loose all their entries hence will forget what time they had to take the lense out of the oven.

Is there any way to show those entries when the application starts again (after a shutdown)? I know how to store them into the database (by using Insert command and using ADO connection).
I have tried the tableadapter.fill option but it didn't work.

many thanks for your superb help!

Regards

J
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Whenever you add or remove a record you can save the data like this:

        Dim fs As New System.IO.FileStream("c:\tableData.xml", IO.FileMode.OpenOrCreate)
        tb.WriteXml(fs)
        fs.Close()

When you want to reload the data you can do:

        tb.Clear()
        Dim fs As New System.IO.FileStream("c:\tableData.xml", IO.FileMode.OpenOrCreate)
        tb.ReadXml(fs)
        fs.Close()

I usually only use DataSets/Tables in MEMORY so I don't know much beyond that...  =\
0
 
jehanzebnAuthor Commented:
Superb! I am using microsoft access as a database which connects via dataset. I like your way too and will def going to use it in another application.

I'll take this as your superc answer!

you have been a lifesaver!

Many thanks

Regards

J
0
 
jehanzebnAuthor Commented:
Idle_Mind is one of the best guys around, the code is clear and understandable.Superc Job!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now