How do I add a countdown timer to a datagridView object? - vb.net

I have a dataGridView object called dgvMonitor that will be used to display pending consultations that are required to be executed within a certain amount of time by a supervisor. The supervisor is given 24hours from the time he submitted an entry, into the program, to complete this task.
dgvMonitor is being filled with an SQL adaptor and once that is completed, I systematically add a new column (REMAINING_TIME) at index 0 or basically to the first column, in the DGV, after I fill the table.
Now, what I need to do is insert a timer, in each cell within column (REMAINING_TIME)
What I would like to do is use the date in column (DATE_SUBMITTED) which is located at index 12 or the 12th column, in the DGV, add 24hours to each date, in that column, and begin counting down. Once the counter is equal to 0, an event will be triggered.
I did some searching on here and all I could find was:
How to create multiple timer handler in vb.net
and
add computed remainingTime to each inserted row of a datagridview
but I couldn't figure out how to apply their scenarios to fit my condition.
I would really appreciate anyone's help. If you need more information to go off of, please let me know and I will edit my question.
Thanks.

Related

Find most recently edited row in MS Access

In Access VBA, is it possible to find the most recently edited row (Record) in a table?
Example below would be ID 3 as the most recently edited row
Since you are using Access 2010 you can use a Before Change data macro to automatically update a Date/Time field in your table. For example, if you add a Date/Time field named [LastUpdated] then the following macro will update that field whenever a record is inserted or updated:
The advantage of this approach is that it takes place at the table level so the [LastUpdated] field is updated regardless of how the record is inserted or modified. (That is, you don't need to rely on form code to update the field.)
You can add a time stamp field to your table and create a form based on the table. When shown as a table, the form will give you the same functionality as the table itself, but you will be able to set an event AfterUpdate The event can then (over)write the time stamp for that record. You can hide the time stamp control on the form if you like, or set Enabled=False

Job/Work scheduler/planner for teams

Currently we use an excel spreadsheet with 4 tabs (as tab for each team), each tab is a planner/diary that week, each day has 4 "slots" for jobs that are planned in.
The people type in the information for each job into one of the 4 slotsfor the day. Each slot contains information in different cells; Job No., Address, Duration, Notes, etc...
The issue/time consuming aspect of this method is when jobs have to be moved about between teams or moved to a different day it involves lots of copying, pasting and deleting.
What I am trying to achieve is some form of drag/drop interface (similar to the way the calendar in Outlook works), where the people who use the spreadsheet can input details for the job in a form and then have a drag an drop "tile" to be able to drag into one of the "slots.
The data contained in these slots needs to be able to produce a report which is a linear list of all the jobs planned that week.
I am at a loss to figure out what method I should use to create this, it seems it is beyond the reach of Excel from what I can find, also beyond the reach of Access, so I suspect it will involve some form of programming. I have basic understanding of VBA, but that's about it.
Can anyone make any suggestions.
Thanks
Working with data in this format will always be hard and I would not reccomend adding any drag and drop until you have sorted out the structure of your data.
You might like to consider another approach, which involves restructuring your data to make it easier to work with...
If you had one sheet with the following columns:
Teamname
Date (instead of Week Number and Day of week,)
Timeslot
JobNo
Address
Duration
Notes
Etc
Then each row would represent a job and have details of when it is occurring.
This is way a database would store the information about the jobs that are happening.
To change when a job is happening, all you have to do is update the date (and timeslot) of the row.
You could then create another worksheet for each team that uses excel formulas to lookup jobs happening this week and display them in a column for each day - like you have now. These sheets would be for display purposes only.
(You would use formulas like VLOOKUP etc)
If you want to change the date of a job you then simply go to the worksheet with the long list and change the date.
Having your data in this long list (ie normalised) format will give you many benefits. For instance you can summerise the report of the data using pivot tables.
If you add filters to the long list (SEE Ribbon>>Data>filters) you can order the data and reduce the list to only show jobs on a selected date, or for a selected team etc...
This is definitely the way forwards. Having restructured the data in this way, you could then add flashy ways to change when a job is taking place by adding buttons on the team worksheets or something.
PART2:
So in you ling list I would recommend excel CONCATENATE function to add an extra column with the text you want displayed elsewhere in your "calendar". #COLUMNA
I would also create another column which is a unique identifier for the row. This will probably be the "Date in YYYMMDD format & timeslot in HHMI format" concatenated together.
In the calendar view sheets say you need a column to display each day of the week with a row for each time slot: You need to
enter a StartDate of the period you want to view
Set up a column for each day (with a formula to calculate the date of the day (ie StartDate, StartDate+1 etc). The date is displayed as a column header (perhaps with a format that shows the dayname, but is stores the date)
each row will have a column that has the timeperiod name and each row will have a value entered. The value is the same as those used in the long list's timeperiod column.
When a user double clicks on a cell you can use the worksheet event
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
in the VBA code, for this event you need to:
see if the cell double clicked is one you want to respond to
if it is find the date and timeperiod from the corresponding column and row header.
use VBA to activate the long list sheet and probably filter to only show the jobs taking place that day or perhaps that week. Then select (or highlight?) the job that was double clicked.
This is quite easy once you know VBA.
There is a lot to know though I would:
use a named range to define the row with the date and another to define the column with the timeperiod
use a named range to define the cells that will respond to a double click
use range functions in VBA like intersection and the entirerow, entirecolumn range properties to find the date and timeperiod of the double clicked cell.
use the macro record to write the initial code that will do the filter.
adjust the code to be well written and to find the date and timeperiod as required.
Create a sheet for all departments? Or just create one sheet where the dept can be chosen.
You could get clever and allow the user to select two cells in the calendar and provide buttons that do things like:
swap the jobs
If they select many cells then a button to Goto the list and only show jobs that were selected in the calendar.
Perhaps the user could select one job and buttons could move the job back or forwards 1,2,7,14 days.
Note that you can use the long list to record other details of the job like time taken, customer, start time, end time etc...
See about Pivot tables here which might give you some ideas about how you can summarise you data to give info like jobs per day, total value of jobs by day, etc...
Before you tie yourself in knots using Excel, you should always consider using Access.... as with someone who know what they are doing, access will deliver a lot more in a shorter period of time and can do nice things like print one page per job etc etc...
(Do you need a contractor?)
mr#HarveyFrench.co.uk

Data Adapter does not update all rows updated

So long story short I have a dgv that gets data from a mysql database and I can make changes to the data in the grid and save back to the table, no problem except this: Changes made by the user on the dgv are not done directly (or manually) on the dgv, rather the user clicks plus or minus buttons and I pragmatically increase or decrease the number in a certain field called Quantity which is actually the only field that can be updated.
Now when I update my adapte command (...da.Update(ds, "salesDet")), the row I changed last does not get updated unless I manually leave that row to another row before pressing the update button. So for instance if I have 3 rows in the dgv and I select row 2 which has a quantity of 1, then I press the plus button, the quantity changes to 2. Then if I immediately press my update button while still on row 2, it will not get updated to my database. It will only work if prior to pressing the update button I leave row 2 to say row 1 or 3. Kind of like because I'm changing the numbers programmatically and not manually, I need to leave the edited row for an "after-update" commitment of the new values to fire? Don't know if I'm making sense but I'm really lost
I have tried dgv.EndEdit(), dgv.RefreshEdit(), dgv.Refresh() before updating but none of that works.
Thanks for your help
Sounds like the current row hasn't been validated yet, so your change has not taken effect. A clumsy hacky way of getting round this might be to set dgv.CurrentRow to nothing at the start of your Update method to force validation.

Adding a row (not a column) of a type (checkbox,dropdown) in datagridview

I have a datagridview that is only two or three rows long. It has 7 text columns, one for each day of the week (Monday - Sunday). I'm creating a scheduler, so basically on the left side I have added text to the row headers to assign to it. I.e. Enabled (let's say for Tuesday), start time and end time. This allows the user to schedule as need be.
Here's a picture of it right now:
What I want to do is possibly change the enabled row, or the start/end time to a particular type. So the enabled will be a checkbox and the start/end times will be drop down menus instead of these text boxes.
My question is, what's the "best" way to add a row of a certain type? Obviously columns are done easily, but is there a common method for a row type other than looping through and adding individual cells of that type to the datagridview?
The type of each cell can only be pre-determined by the column, not the row. As a result, you're going to have to add each cell individually. You can actually put a cell of any type anywhere you want. You simply create a cell of the desired type and assign it to the Item property of the grid, e.g.
myDataGridView(columnIndex, rowIndex) = newCell
You will simply have to use a For loop to do that for each valid column index with a single row index. Note that you'll have to create a new cell for each column, not reuse the same one.

Insert into datagridview column specific values in vb net

i am developing an app for windows in vb net.
I am stuck in the last part which is the following and i would like some help on to where should i look or do.My question:I have one database in mysql called patient.each patient have the usual columns(name,surname etc..).Apart from all the columns there is one column called 'time' and another one called 'date'.I have also one datagrid where these values are displayed.When a new user is to be added,all the fields are filled and in the 'time' he fills the time of visit.I would like to ask if there is any way to restrict the range of time according to date...for example to be able in the beginning before adding the new patient,to say that in august 30 of 2014 the range of time for appointments is from 9 to 10.So when the new patient is added on that date ,to book only between this range every ten minutes eg 9:10,then 9:20 and so on until 10.
I am really stuck and been searching the last week for a solution ,so any ideas on the implementation would be appreciated.
Thank you in advance..If you need some of my code let me know.
If you want to restrict the input data, you have to use the DataGridView's CellValidating event. There you can check wether the input is ok or not. If it's not ok, you can set the ErrorText field of the edited row, where you can explain to the user what's wrong with his input.
Have a look at this HowTo from the MSDN.