.NET Programming
--
Questions
--
Followers
Top Experts
TAKT Timer - Time delta calculation
Hello
i have TAKT TIME Tracker application.
1. Timer runs backward using the TAKT Time as START TIME.
2. Cycle completed will be incremented by +1 when Timer hits zero.
3. Timer resets to TAKT time and cycle runs continually.
4. When operator scans the barcode serial:
UNIT Completed will be incremented by +1
TIME DELTA is calculated and displayed.
When time taken is more for the unit than the cycle time - TIME DELTA is negative.
when time taken is less for the unit than the cycle time - TIME DELTA is positive.
Question - how to calculate TIME Delta?
Here is my C# Code:
using System;
using System.Collections.Generic ;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Configuration;
using System.Media;
using System.Data.SqlClient;
namespace CFLineTrackerWindows
{
public partial class CFLineTracker : Form
{
public int hours = 00; // Hours.
public int minutes = 00; // Minutes.
public int seconds = 00; // Seconds.
public int cycleCounter = 0; // CycleCounter
public int unitCounter = 0; // UnitCounter
public DateTime dtTwentySecondsWaitTime = DateTime.Now.AddSeconds(20 );
public DateTime shiftStartTime = DateTime.Today.AddHours(5) .AddMinute s(00); //Shift Start - 5:00 AM
public DateTime shiftEndTime = DateTime.Today.AddHours(17 ).AddMinut es(00); //Shift End - 3:00 PM
public DateTime appShutDowmTime = DateTime.Today.AddHours(18 ).AddMinut es(00); //App Shutdown - 4:00 PM
public DateTime breakTimeStart = DateTime.Today.AddHours(9) .AddMinute s(0); //Break Start time - 9:00 AM
public DateTime breakTimeEnd = DateTime.Today.AddHours(9) .AddMinute s(10); //Break End time - 9:10 AM
public DateTime lunchTimeStart = DateTime.Today.AddHours(11 ).AddMinut es(30); //Lunch Start time - 11:30 AM
public DateTime lunchTimeEnd = DateTime.Today.AddHours(11 ).AddMinut es(50); //Lunch End time - 11:50 AM
Stopwatch stopwatch = new Stopwatch();
public TimeSpan cycleTimeCompleted; // CycleTimeCounter
public TimeSpan unitTimeCompleted; // UnitTimeCounter
public int intTAKTTime = Convert.ToInt32(System.Con figuration .Configura tionManage r.AppSetti ngs["TAKTT ime"]); // TAKT Time
public string strTAKTTime = System.Configuration.Confi gurationMa nager.AppS ettings["T AKTTimeDis play"]; // TAKT Time
public bool bblink = true;
public CFLineTracker()
{
InitializeComponent();
}
private void CFLineTracker_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
txtShiftStartTime.Text = shiftStartTime.ToLongTimeS tring();
txtEnteredCycleTime.Text = strTAKTTime; //TAKT Time
ResetTime();
lblDate.Text = DateTime.Now.ToShortDateSt ring();
ResetSerialNumber();
timer1.Start();
stopwatch.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
//break time - stop timer
if (now >= breakTimeStart && now <= breakTimeEnd)
{ return; }
//lunch time - stop timer
if (now >= lunchTimeStart && now <= lunchTimeEnd)
{ return; }
//20 seconds wait time
if (now >= dtTwentySecondsWaitTime)
{ ResetSerialNumber(); }
//shift end - stop timer
if (now >= shiftEndTime)
{
timer1.Stop();
ResetTime();
ResetSerialNumber();
}
//app shut down
if (now >= appShutDowmTime)
{ System.Windows.Forms.Appli cation.Exi t(); }
if (now > shiftStartTime)
{
if (minutes == 0 && seconds == 0)
{
cycleCounter += 1; //cycle completed incremented by 1.
txtCyclesCompleted.Text = cycleCounter.ToString();
cycleTimeCompleted = stopwatch.Elapsed;
TimeSpan minutesRounded = (unitTimeCompleted - cycleTimeCompleted);
txtTimeDelta.Text = minutesRounded.ToString(@" hh\:mm\:ss ");
//TIME DELTA - color setting
if (minutesRounded.Minutes >= 0)
{
lblTimeDelta.BackColor = Color.Green;
txtTimeDelta.BackColor = Color.Green;
pnlTimeDelta.BackColor = Color.Green;
}
else
{
lblTimeDelta.BackColor = Color.Red;
txtTimeDelta.BackColor = Color.Red;
pnlTimeDelta.BackColor = Color.Red;
}
if (unitTimeCompleted.Minutes == 0)
{
lblTimeDelta.BackColor = Color.Red;
txtTimeDelta.BackColor = Color.Red;
pnlTimeDelta.BackColor = Color.Red;
}
PlaySound();
ResetTime();
}
if (seconds < 1)
{
seconds = 59;
if (minutes == 0)
{
minutes = 59;
if (hours != 0) hours -= 1;
}
else
{
minutes -= 1;
}
}
else seconds -= 1;
if (minutes < 2) //less than 2 minutes - screen flashing
{
if (bblink)
{ txtDigitalClock.BackColor = Color.CornflowerBlue; }
else
{ txtDigitalClock.BackColor = Color.Yellow; }
bblink = !bblink;
}
else
{
txtDigitalClock.BackColor = Color.CornflowerBlue;
txtDigitalClock.ForeColor = Color.Black;
}
txtDigitalClock.Text = hours.ToString().PadLeft(2 , '0') + ":" + minutes.ToString().PadLeft (2, '0') + ":" + seconds.ToString().PadLeft (2, '0');
}
}
private void ResetTime()
{
string[] words = txtEnteredCycleTime.Text.S plit(':');
if (words != null)
{
hours = Convert.ToInt32(words[0]);
minutes = Convert.ToInt32(words[1]);
seconds = Convert.ToInt32(words[2]);
}
txtDigitalClock.Text = txtEnteredCycleTime.Text;
}
private void txtSerialNumber_TextChange d(object sender, EventArgs e)
{
if (txtSerialNumber.Text.Leng th > 1)
{
if (txtSerialNumber.Text.Leng th == 15 && txtSerialNumber.Text.Subst ring(0, 1) == "2")
{
//increment unit completed by +1
unitCounter += 1;
txtUnitsCompleted.Text = unitCounter.ToString();
txtSerialNumber.Enabled = false;
HiddenBoxGotFocus();
//Calculate time delta
unitTimeCompleted = stopwatch.Elapsed;
TimeSpan minutesRounded = (unitTimeCompleted - cycleTimeCompleted);
txtTimeDelta.Text = minutesRounded.ToString(@" hh\:mm\:ss ");
InsertTAKTTimerDetails();
if (minutesRounded.Minutes >= 0)
{
lblTimeDelta.BackColor = Color.Green;
txtTimeDelta.BackColor = Color.Green;
pnlTimeDelta.BackColor = Color.Green;
}
else
{
lblTimeDelta.BackColor = Color.Red;
txtTimeDelta.BackColor = Color.Red;
pnlTimeDelta.BackColor = Color.Red;
}
}
else if (txtSerialNumber.Text.Subs tring(0, 1) != "2")
{
txtSerialNumber.Text = string.Empty;
}
}
}
private void ResetSerialNumber()
{
txtSerialNumber.Enabled = true;
txtSerialNumber.Focus();
this.ActiveControl = txtSerialNumber;
txtSerialNumber.Text = String.Empty;
}
private void ResetCounters()
{
txtCyclesCompleted.Text = "0";
txtUnitsCompleted.Text = "0";
txtTimeDelta.Text = "";
}
private void HiddenBoxGotFocus()
{
txtHiddenBox.Focus();
this.ActiveControl = txtHiddenBox;
txtHiddenBox.Text = String.Empty;
dtTwentySecondsWaitTime = DateTime.Now.AddSeconds(20 );
}
private int GetMinutes(DateTime dt)
{
return (dt.Hour * 60) + dt.Minute;
}
private void PlaySound()
{
SoundPlayer wavPlayer = new SoundPlayer(Properties.Res ources.beb etoambient loop);
wavPlayer.LoadCompleted += new AsyncCompletedEventHandler (wavPlayer _LoadCompl eted);
wavPlayer.LoadAsync();
}
private void wavPlayer_LoadCompleted(ob ject sender, AsyncCompletedEventArgs e)
{
((System.Media.SoundPlayer )sender).P lay();
}
private void InsertTAKTTimerDetails()
{
using (SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["Sq lDBConnect ionString" ].Connecti onString))
{
using (var cmd = new SqlCommand("dbo.InsertTAKT TimerDetai ls"))
{
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Parameters.Add("@GEN", SqlDbType.NVarChar, 50).Value = "CFA";
cmd.Parameters.Add("@Seria lNo", SqlDbType.NVarChar, 50).Value = txtSerialNumber.Text.Trim( );
cmd.Parameters.Add("@TAKTT ime", SqlDbType.NVarChar, 50).Value = intTAKTTime.ToString();
cmd.Parameters.Add("@Units Completed" , SqlDbType.Int).Value = unitCounter;
cmd.Parameters.Add("@Cycle sCompleted ", SqlDbType.Int).Value = cycleCounter;
cmd.Parameters.Add("@Cumul ativeCycle Time", SqlDbType.Int).Value = cycleTimeCompleted.Minutes ;
cmd.Parameters.Add("@Cumul ativeUnitT ime", SqlDbType.Int).Value = unitTimeCompleted.Minutes;
cmd.Parameters.Add("@TimeD elta", SqlDbType.Int).Value = (cycleTimeCompleted.Minute s - unitTimeCompleted.Minutes) ;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
}
}
}
}
}
any help?
Thanks
TAKT-Timer.JPG
i have TAKT TIME Tracker application.
1. Timer runs backward using the TAKT Time as START TIME.
2. Cycle completed will be incremented by +1 when Timer hits zero.
3. Timer resets to TAKT time and cycle runs continually.
4. When operator scans the barcode serial:
UNIT Completed will be incremented by +1
TIME DELTA is calculated and displayed.
When time taken is more for the unit than the cycle time - TIME DELTA is negative.
when time taken is less for the unit than the cycle time - TIME DELTA is positive.
Question - how to calculate TIME Delta?
Here is my C# Code:
using System;
using System.Collections.Generic
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Configuration;
using System.Media;
using System.Data.SqlClient;
namespace CFLineTrackerWindows
{
public partial class CFLineTracker : Form
{
public int hours = 00; // Hours.
public int minutes = 00; // Minutes.
public int seconds = 00; // Seconds.
public int cycleCounter = 0; // CycleCounter
public int unitCounter = 0; // UnitCounter
public DateTime dtTwentySecondsWaitTime = DateTime.Now.AddSeconds(20
public DateTime shiftStartTime = DateTime.Today.AddHours(5)
public DateTime shiftEndTime = DateTime.Today.AddHours(17
public DateTime appShutDowmTime = DateTime.Today.AddHours(18
public DateTime breakTimeStart = DateTime.Today.AddHours(9)
public DateTime breakTimeEnd = DateTime.Today.AddHours(9)
public DateTime lunchTimeStart = DateTime.Today.AddHours(11
public DateTime lunchTimeEnd = DateTime.Today.AddHours(11
Stopwatch stopwatch = new Stopwatch();
public TimeSpan cycleTimeCompleted; // CycleTimeCounter
public TimeSpan unitTimeCompleted; // UnitTimeCounter
public int intTAKTTime = Convert.ToInt32(System.Con
public string strTAKTTime = System.Configuration.Confi
public bool bblink = true;
public CFLineTracker()
{
InitializeComponent();
}
private void CFLineTracker_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
txtShiftStartTime.Text = shiftStartTime.ToLongTimeS
txtEnteredCycleTime.Text = strTAKTTime; //TAKT Time
ResetTime();
lblDate.Text = DateTime.Now.ToShortDateSt
ResetSerialNumber();
timer1.Start();
stopwatch.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
//break time - stop timer
if (now >= breakTimeStart && now <= breakTimeEnd)
{ return; }
//lunch time - stop timer
if (now >= lunchTimeStart && now <= lunchTimeEnd)
{ return; }
//20 seconds wait time
if (now >= dtTwentySecondsWaitTime)
{ ResetSerialNumber(); }
//shift end - stop timer
if (now >= shiftEndTime)
{
timer1.Stop();
ResetTime();
ResetSerialNumber();
}
//app shut down
if (now >= appShutDowmTime)
{ System.Windows.Forms.Appli
if (now > shiftStartTime)
{
if (minutes == 0 && seconds == 0)
{
cycleCounter += 1; //cycle completed incremented by 1.
txtCyclesCompleted.Text = cycleCounter.ToString();
cycleTimeCompleted = stopwatch.Elapsed;
TimeSpan minutesRounded = (unitTimeCompleted - cycleTimeCompleted);
txtTimeDelta.Text = minutesRounded.ToString(@"
//TIME DELTA - color setting
if (minutesRounded.Minutes >= 0)
{
lblTimeDelta.BackColor = Color.Green;
txtTimeDelta.BackColor = Color.Green;
pnlTimeDelta.BackColor = Color.Green;
}
else
{
lblTimeDelta.BackColor = Color.Red;
txtTimeDelta.BackColor = Color.Red;
pnlTimeDelta.BackColor = Color.Red;
}
if (unitTimeCompleted.Minutes
{
lblTimeDelta.BackColor = Color.Red;
txtTimeDelta.BackColor = Color.Red;
pnlTimeDelta.BackColor = Color.Red;
}
PlaySound();
ResetTime();
}
if (seconds < 1)
{
seconds = 59;
if (minutes == 0)
{
minutes = 59;
if (hours != 0) hours -= 1;
}
else
{
minutes -= 1;
}
}
else seconds -= 1;
if (minutes < 2) //less than 2 minutes - screen flashing
{
if (bblink)
{ txtDigitalClock.BackColor = Color.CornflowerBlue; }
else
{ txtDigitalClock.BackColor = Color.Yellow; }
bblink = !bblink;
}
else
{
txtDigitalClock.BackColor = Color.CornflowerBlue;
txtDigitalClock.ForeColor = Color.Black;
}
txtDigitalClock.Text = hours.ToString().PadLeft(2
}
}
private void ResetTime()
{
string[] words = txtEnteredCycleTime.Text.S
if (words != null)
{
hours = Convert.ToInt32(words[0]);
minutes = Convert.ToInt32(words[1]);
seconds = Convert.ToInt32(words[2]);
}
txtDigitalClock.Text = txtEnteredCycleTime.Text;
}
private void txtSerialNumber_TextChange
{
if (txtSerialNumber.Text.Leng
{
if (txtSerialNumber.Text.Leng
{
//increment unit completed by +1
unitCounter += 1;
txtUnitsCompleted.Text = unitCounter.ToString();
txtSerialNumber.Enabled = false;
HiddenBoxGotFocus();
//Calculate time delta
unitTimeCompleted = stopwatch.Elapsed;
TimeSpan minutesRounded = (unitTimeCompleted - cycleTimeCompleted);
txtTimeDelta.Text = minutesRounded.ToString(@"
InsertTAKTTimerDetails();
if (minutesRounded.Minutes >= 0)
{
lblTimeDelta.BackColor = Color.Green;
txtTimeDelta.BackColor = Color.Green;
pnlTimeDelta.BackColor = Color.Green;
}
else
{
lblTimeDelta.BackColor = Color.Red;
txtTimeDelta.BackColor = Color.Red;
pnlTimeDelta.BackColor = Color.Red;
}
}
else if (txtSerialNumber.Text.Subs
{
txtSerialNumber.Text = string.Empty;
}
}
}
private void ResetSerialNumber()
{
txtSerialNumber.Enabled = true;
txtSerialNumber.Focus();
this.ActiveControl = txtSerialNumber;
txtSerialNumber.Text = String.Empty;
}
private void ResetCounters()
{
txtCyclesCompleted.Text = "0";
txtUnitsCompleted.Text = "0";
txtTimeDelta.Text = "";
}
private void HiddenBoxGotFocus()
{
txtHiddenBox.Focus();
this.ActiveControl = txtHiddenBox;
txtHiddenBox.Text = String.Empty;
dtTwentySecondsWaitTime = DateTime.Now.AddSeconds(20
}
private int GetMinutes(DateTime dt)
{
return (dt.Hour * 60) + dt.Minute;
}
private void PlaySound()
{
SoundPlayer wavPlayer = new SoundPlayer(Properties.Res
wavPlayer.LoadCompleted += new AsyncCompletedEventHandler
wavPlayer.LoadAsync();
}
private void wavPlayer_LoadCompleted(ob
{
((System.Media.SoundPlayer
}
private void InsertTAKTTimerDetails()
{
using (SqlConnection conn = new SqlConnection(Configuratio
{
using (var cmd = new SqlCommand("dbo.InsertTAKT
{
cmd.CommandType = CommandType.StoredProcedur
cmd.Parameters.Add("@GEN",
cmd.Parameters.Add("@Seria
cmd.Parameters.Add("@TAKTT
cmd.Parameters.Add("@Units
cmd.Parameters.Add("@Cycle
cmd.Parameters.Add("@Cumul
cmd.Parameters.Add("@Cumul
cmd.Parameters.Add("@TimeD
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
}
}
}
}
}
any help?
Thanks
TAKT-Timer.JPG
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Time delta is a fancy term for time difference.
Available Minutes for Production / Required Units of Production = Takt Time
To find the delta value, you reference tekt time and subtract by the current cycle time.
E.g. if the worker takes longer than expected (tekt time) the time delta is negative; otherwise time delta is non-negative: zero (on time) or positive (quicker than tekt).
Available Minutes for Production / Required Units of Production = Takt Time
To find the delta value, you reference tekt time and subtract by the current cycle time.
E.g. if the worker takes longer than expected (tekt time) the time delta is negative; otherwise time delta is non-negative: zero (on time) or positive (quicker than tekt).
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Thanks
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I have recommended this question be closed as follows:
Accept: NerdsOfTech (https:#a42169640)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
frankhelk
Experts-Exchange Cleanup Volunteer
I have recommended this question be closed as follows:
Accept: NerdsOfTech (https:#a42169640)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
frankhelk
Experts-Exchange Cleanup Volunteer






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
.NET Programming
--
Questions
--
Followers
Top Experts
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.