i have datagridview shows list of cars in workshop. right of registration number, several columns of phases. duration of each phase each car has been estimated , next need show actual time taken. ideally needs live timer ticking away.
each phase each job can active, paused or completed.
in terms of database tables, have following -
jobdetails
id - pk auto increment jobid - int (joined jobs table) phaseid - string (joined jobphases table) estimatedtime - decimal actualtime decimal status int (entrytype - notstarted, active, paused, complete)
jobphases
id - pk string name - varchar(150)
timelogs
id int jobid int phaseid string userid int dateentry datetime entrytype int
what happens userid, job number, task id , action (notstarted, active, pauused , complete) scanned through barcode. sets job active.
i can set , time taken adding jobdetail.actualtime timelog.lastentry.dateentry. trouble need show live ticker in each cell, or @ least 10 second interval refreshes
the code have far -
private void tstbcommand_leave(object sender, eventargs e) { user u = user.fromid(convert.toint32(tstbuser.text.trimstart('u'))); job j = job.fromid(convert.toint32(tstbjobno.text.trimstart('e', 'n', 'k', 'j', 'c'))); jobdetail jd = jobdetail.jobdetailfromjobidandphaseid(j.id, tstbtaskid.text.trimstart('e', 'n', 'k', 'j', 'c', 'd')); timelog log = new timelog(); switch (tstbcommand.text) { case "cmdactive": if (jd.status == entrytype.active) { //alert active lstalerts.items.add("the scanned job active."); } else { //ok update status active jd.status = entrytype.active; log.entrytype = jd.status; jobphasetimer timer = new jobphasetimer(); timer.uid = jd.id + "_" + jd.phaseid; timer.jobdetailid = jd.id; timer.jobid = j.id; timer.phaseid = jd.phaseid; timer.starttime = datetime.now; timer.stopwatch.start(); timer.start(); timers.add(timer.uid, timer); lstalerts.items.add("the job " + jd.jobid + " has been set active " + u.fullname + "."); } break; case "cmdpause": if (jd.status == entrytype.paused) { lstalerts.items.add("the scanned job paused."); } else { jobphase phase = jobphase.fromid(jd.phaseid); jd.status = entrytype.paused; log.entrytype = jd.status; timelog lastentry = timelog.getlasttimelogentry(j.id, jd.phaseid); lstalerts.items.add(lastentry.entrytype + ", " + lastentry.dateentry); jd.actualtime = convert.todecimal(jd.actualtime) + convert.todecimal(datetime.now.subtract(lastentry.dateentry).totalhours); lstalerts.items.add("the job phase " + phase.name + " job " + jd.jobid + " has been paused " + u.fullname + "."); } break; case "cmdcomplete": if (jd.status == entrytype.complete) { lstalerts.items.add("the scanned job completed."); } else { jd.status = entrytype.complete; log.entrytype = jd.status; lstalerts.items.add("the job " + jd.jobid + " has been completed " + u.fullname + "."); } break; case "cmdqc": if (u.mergedrole.hasright("workshop.qualitycheck")) { if (jd.status == entrytype.qualitychecked) { lstalerts.items.add("the scanned job has been quality checked."); } else { jd.status = entrytype.qualitychecked; log.entrytype = jd.status; lstalerts.items.add("the job " + jd.jobid + " has been quality checked " + u.fullname + "."); } } else { lstalerts.items.add("you not have sufficient rights quality check."); } break; } log.jobid = j.id; log.userid = u.id; log.phaseid = jd.phaseid; log.entrytype = jd.status; jd.updatejobdetail(u.username); log.addnewtimelog(); tstbjobno.text = ""; tstbuser.text = ""; tstbtaskid.text = ""; tstbcommand.text = ""; }
to keep data on datagridview, @ moment calling loaddata() on timer tick -
void loaddata() { foreach (jobphasetimer timer in timers.values) { jobdetail jd = jobdetail.jobdetailfromjobidandphaseid(timer.jobid, timer.phaseid); jd.actualtime = jd.actualtime + convert.todecimal(timer.stopwatch.elapsedmilliseconds); jd.updatejobdetail("test"); } dt = jobmanager.gettodaysjobs(); if (datagridview1.invokerequired) datagridview1.invoke(new methodinvoker(delegate { //access picturebox here# dt = jobmanager.gettodaysjobs(); datagridview1.autogeneratecolumns = false; datagridview1.datasource = dt; datagridview1.autoresizecolumns(); })); else { //access picturebox here dt = jobmanager.gettodaysjobs(); datagridview1.autogeneratecolumns = false; datagridview1.datasource = dt; datagridview1.autoresizecolumns(); } }
finally, must format cell colour according estimatedtime/actualtime. if actualtime (live) below estiamtedtime- green. if actualtime greater estiamtedtime - red, if actualime near (logic not decided on yet), display yellow.
any thoughts/ideas on how can achieve above? have not done live datagrid before!
Comments
Post a Comment