public void CalculateFinalResult()
        {
            FinalResult newResult = new FinalResult();

            newResult.InterArrivalTime = interArrivalTiemInputed;
            foreach (var finalResult in getAllFinalTableInfo())
            {
                newResult.ArrivalTime = finalResult.ArrivalTime + newResult.InterArrivalTime;
            }
            newResult.ServiceTime = serviceTimeInputed;
            int previousServiceEndTiem = 0;

            foreach (var finalResult in getAllFinalTableInfo())
            {
                previousServiceEndTiem = finalResult.ServiceEndTime;
            }

            if (previousServiceEndTiem <= newResult.ArrivalTime)
            {
                newResult.ServiceStartTime = newResult.ArrivalTime;
            }
            else
            {
                newResult.ServiceStartTime = previousServiceEndTiem;
            }

            newResult.ServiceEndTime = newResult.ServiceStartTime + newResult.ServiceTime;

            int initialQueue = 0;

            if (newResult.ServiceStartTime > newResult.ArrivalTime)
            {
                newResult.Queue = newResult.ServiceStartTime - newResult.ArrivalTime;
            }
            else
            {
                newResult.Queue = initialQueue;
            }

            newResult.TimeSpends = newResult.ServiceEndTime - newResult.ArrivalTime;

            int initialIdleTime = 0;

            if (previousServiceEndTiem < newResult.ArrivalTime)
            {
                newResult.IdleTime = newResult.ArrivalTime - previousServiceEndTiem;
            }
            else
            {
                newResult.IdleTime = initialIdleTime;
            }


            SaveFinalTableData(newResult);
        }
        public void SaveFinalTableData(FinalResult finalResult)
        {
            string     query   = "Insert into tbl_TotalSimulation values(" + arrivalRD + "," + finalResult.InterArrivalTime + "," + finalResult.ArrivalTime + "," + serviceRD + "," + finalResult.ServiceTime + "," + finalResult.ServiceStartTime + "," + finalResult.ServiceEndTime + "," + finalResult.Queue + "," + finalResult.TimeSpends + "," + finalResult.IdleTime + ")";
            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandText = query;
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }