Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of Mani Pazhana
Mani Pazhana🇺🇸

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).AddMinutes(00);         //Shift Start - 5:00 AM
        public DateTime shiftEndTime = DateTime.Today.AddHours(17).AddMinutes(00);          //Shift End - 3:00 PM
        public DateTime appShutDowmTime = DateTime.Today.AddHours(18).AddMinutes(00);         //App Shutdown - 4:00 PM
        public DateTime breakTimeStart = DateTime.Today.AddHours(9).AddMinutes(0);          //Break Start time - 9:00 AM
        public DateTime breakTimeEnd = DateTime.Today.AddHours(9).AddMinutes(10);           //Break End time - 9:10 AM
        public DateTime lunchTimeStart = DateTime.Today.AddHours(11).AddMinutes(30);        //Lunch Start time - 11:30 AM
        public DateTime lunchTimeEnd = DateTime.Today.AddHours(11).AddMinutes(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.Configuration.ConfigurationManager.AppSettings["TAKTTime"]);    // TAKT Time
        public string strTAKTTime = System.Configuration.ConfigurationManager.AppSettings["TAKTTimeDisplay"];           // TAKT Time
        public bool bblink = true;

        public CFLineTracker()
        {
            InitializeComponent();
        }

        private void CFLineTracker_Load(object sender, EventArgs e)
        {
            timer1.Interval = 1000;
            txtShiftStartTime.Text = shiftStartTime.ToLongTimeString();
            txtEnteredCycleTime.Text = strTAKTTime;   //TAKT Time
            ResetTime();
            lblDate.Text = DateTime.Now.ToShortDateString();
            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.Application.Exit(); }
           
            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.Split(':');

            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_TextChanged(object sender, EventArgs e)
        {
            if (txtSerialNumber.Text.Length > 1)
            {
                if (txtSerialNumber.Text.Length == 15 && txtSerialNumber.Text.Substring(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.Substring(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.Resources.bebetoambientloop);              
            wavPlayer.LoadCompleted += new AsyncCompletedEventHandler(wavPlayer_LoadCompleted);
            wavPlayer.LoadAsync();
        }  

         private void wavPlayer_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
                ((System.Media.SoundPlayer)sender).Play();            
             
        }

         private void InsertTAKTTimerDetails()
         {
             using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDBConnectionString"].ConnectionString))
             {
                 using (var cmd = new SqlCommand("dbo.InsertTAKTTimerDetails"))
                 {
                     cmd.CommandType = CommandType.StoredProcedure;
                     cmd.Parameters.Add("@GEN", SqlDbType.NVarChar, 50).Value = "CFA";
                     cmd.Parameters.Add("@SerialNo", SqlDbType.NVarChar, 50).Value = txtSerialNumber.Text.Trim();
                     cmd.Parameters.Add("@TAKTTime", SqlDbType.NVarChar, 50).Value = intTAKTTime.ToString();
                     cmd.Parameters.Add("@UnitsCompleted", SqlDbType.Int).Value = unitCounter;
                     cmd.Parameters.Add("@CyclesCompleted", SqlDbType.Int).Value = cycleCounter;
                     cmd.Parameters.Add("@CumulativeCycleTime", SqlDbType.Int).Value = cycleTimeCompleted.Minutes;
                     cmd.Parameters.Add("@CumulativeUnitTime", SqlDbType.Int).Value = unitTimeCompleted.Minutes;
                     cmd.Parameters.Add("@TimeDelta", SqlDbType.Int).Value = (cycleTimeCompleted.Minutes - unitTimeCompleted.Minutes);
                   
                     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.


Avatar of NerdsOfTechNerdsOfTech🇺🇸

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).

ASKER CERTIFIED SOLUTION
Avatar of NerdsOfTechNerdsOfTech🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Mani PazhanaMani Pazhana🇺🇸

ASKER

Thanks

Avatar of Frank HelkFrank Helk🇩🇪

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

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

.NET Programming

.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.