using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using ATK;
using Windows.UI.Core;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace Zebra_RFID_Mobile
{ 
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PageStartStop : Page
    {
        ReaderConnect readerobj;
        BaseReciever baserecieverObj;
        int initialstartTriggerIndex = -1;
        int initialstopTriggerIndex = -1; 
        List<string> startTrigger = new List<string>();
        List<string> stopTrigger = new List<string>();
        public PageStartStop()
        {
            this.InitializeComponent();
            readerobj = ReaderConnect.getInstance();
            baserecieverObj = BaseReciever.getInstance();
            startTrigger.Add("Immediate");
            startTrigger.Add("Handheld");
            startTrigger.Add("Periodic");
            combostart.ItemsSource = startTrigger;
            if (ReaderConfig.isReaderConnected == false)
            {
                combostart.SelectedIndex = 0;
                GridStartPeriodic.Visibility = Visibility.Collapsed;
                StackStartHandheldTriggers.Visibility = Visibility.Collapsed;              
            }
            else
            {
                if ((ReaderConfig.startTriggerParams.IgnoreHandHeldTrigger == true) && (ReaderConfig.startTriggerParams.NoRepeat = true))
                {
                    initialstartTriggerIndex = 0;
                    combostart.SelectedIndex = 0;
                    GridStartPeriodic.Visibility = Visibility.Collapsed;
                    StackStartHandheldTriggers.Visibility = Visibility.Collapsed;
                }

                if ((ReaderConfig.startTriggerParams.StartOnHandHeldTrigger == true))
                {
                    initialstartTriggerIndex = 1;
                    combostart.SelectedIndex = 1;
                    GridStartPeriodic.Visibility = Visibility.Collapsed;
                    StackStartHandheldTriggers.Visibility = Visibility.Visible;
                    if (ReaderConfig.startTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_PRESS)
                        CheckBoxStartTriggerPressed.IsChecked = true;
                    else
                        CheckBoxStartTriggerReleased.IsChecked = true;
                }

                if ((ReaderConfig.startTriggerParams.Repeat == true) && (ReaderConfig.startTriggerParams.IgnoreHandHeldTrigger == true))
                {
                    initialstartTriggerIndex = 2;
                    combostart.SelectedIndex = 2;
                    TextBoxStartDuration.Text = ReaderConfig.startTriggerParams.StartDelay.ToString();
                    GridStartPeriodic.Visibility = Visibility.Visible;
                    StackStartHandheldTriggers.Visibility = Visibility.Collapsed;
                }
            }
            stopTrigger.Add("Immediate");
            stopTrigger.Add("Handheld");
            stopTrigger.Add("Duration");
            stopTrigger.Add("Tag Observations");
            stopTrigger.Add("N Attempts");
            combostop.ItemsSource = stopTrigger;
            if (ReaderConfig.isReaderConnected == false)
            {
                combostop.SelectedIndex = 0;
                initialstopTriggerIndex = 0;
            }
            else
            {
                if ((ReaderConfig.stopTriggerParams.IgnoreHandHeldTrigger) && (ReaderConfig.stopTriggerParams.DisableStopOnAccessCount)
                    && (ReaderConfig.stopTriggerParams.DisableStoponInventoryCount) && (ReaderConfig.stopTriggerParams.DisableStopOntagcount)
                    && (ReaderConfig.stopTriggerParams.DisableStopOnTimeout))
                {
                    combostop.SelectedIndex = 0;
                    initialstopTriggerIndex = 0;
                }
                if (ReaderConfig.stopTriggerParams.StopOnHandHeldTrigger)
                {
                    combostop.SelectedIndex = 1;
                    initialstopTriggerIndex = 1;
                    if (ReaderConfig.stopTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_PRESS)
                        CheckBoxStopTriggerPressed.IsChecked = true;
                    else
                        CheckBoxStopTriggerReleased.IsChecked = true;
                    TextStopDurationTrigger.Text = ReaderConfig.stopTriggerParams.StopTimeout.ToString();
                }
                else if (ReaderConfig.stopTriggerParams.EnableStopOntagcount)
                {
                    combostop.SelectedIndex = 3;
                    initialstopTriggerIndex = 3;
                    TextStopTagcount.Text = ReaderConfig.stopTriggerParams.StopTagCount.ToString();
                    TextStopDurationTagCount.Text = ReaderConfig.stopTriggerParams.StopTimeout.ToString();
                }
                else if (ReaderConfig.stopTriggerParams.EnableStopOnInventoryCount)
                {
                    combostop.SelectedIndex = 4;
                    initialstopTriggerIndex = 4;
                    TextInventoryRoundcount.Text = ReaderConfig.stopTriggerParams.StopInventoryCount.ToString();
                    TextStopDurationInventoryCount.Text = ReaderConfig.stopTriggerParams.StopTimeout.ToString();
                }
                else if (ReaderConfig.stopTriggerParams.EnableStopOnTimeout)
                {
                    combostop.SelectedIndex = 2;
                    initialstopTriggerIndex = 2;
                    TextStopDuration.Text = ReaderConfig.stopTriggerParams.StopTimeout.ToString();
                }
            }
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            //Windows.Phone.UI.Input.HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
            SystemNavigationManager.GetForCurrentView().BackRequested -= App_BackRequested;
        }

        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            sendStartStopConfig();
            this.Frame.Navigate(typeof(PageSettings));
        }

        void App_BackRequested(object sender, BackRequestedEventArgs e)
        {
            sendStartStopConfig();
            Frame.Navigate(typeof(PageSettings));
        
        }   
     
        public async void sendStartStopConfig()
        {

            if (ReaderConfig.isReaderConnected == false)
            {
                return;
            }
            bool isStartConfigChanged = false;
            bool isStopConfigChanged = false;
            Command_SetStartTrigger startTriggerConfig = new Command_SetStartTrigger();
            Command_SetStopTrigger stopTriggerConfig = new Command_SetStopTrigger();

            //******************************START Trigger*****************************************//
            if (combostart.SelectedIndex != initialstartTriggerIndex)
            {
                isStartConfigChanged = true;
            }

            if (combostart.SelectedIndex == 0)
            {
                if (isStartConfigChanged)
                {
                    startTriggerConfig.IgnoreHandHeldTrigger = true;
                    startTriggerConfig.StartOnHandHeldTrigger = false;
                    startTriggerConfig.NoRepeat = true;
                    startTriggerConfig.Repeat = false;
                    startTriggerConfig.StartDelay = 0; 
                }
            }
            if (combostart.SelectedIndex == 1)
            {               
                if (isStartConfigChanged)
                {                    
                    startTriggerConfig.IgnoreHandHeldTrigger = false;
                    startTriggerConfig.StartOnHandHeldTrigger = true;
                    startTriggerConfig.NoRepeat = false;
                    startTriggerConfig.Repeat = true;
                    startTriggerConfig.StartDelay = 0;
                    if (CheckBoxStartTriggerPressed.IsChecked == true)
                        startTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_PRESS;
                    if (CheckBoxStartTriggerReleased.IsChecked == true)
                        startTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_RELEASE;
                }
                else
                {
                    if (((ReaderConfig.startTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_PRESS) && (CheckBoxStartTriggerPressed.IsChecked != true))
                        || ((ReaderConfig.startTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_RELEASE) && (CheckBoxStartTriggerReleased.IsChecked != true)))
                    {
                        isStartConfigChanged = true;
                        startTriggerConfig.IgnoreHandHeldTrigger = false;
                        startTriggerConfig.StartOnHandHeldTrigger = true;
                        startTriggerConfig.NoRepeat = false;
                        startTriggerConfig.Repeat = true;
                        startTriggerConfig.StartDelay = 0;
                        if (CheckBoxStartTriggerPressed.IsChecked == true)
                            startTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_PRESS;
                        if (CheckBoxStartTriggerReleased.IsChecked == true)
                            startTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_RELEASE;
                        isStartConfigChanged = true;
                    }
                }
            }
            if (combostart.SelectedIndex == 2)
            {
                if (isStartConfigChanged)
                {                    
                    startTriggerConfig.IgnoreHandHeldTrigger = true;
                    startTriggerConfig.StartOnHandHeldTrigger = false;
                    startTriggerConfig.NoRepeat = false;
                    startTriggerConfig.Repeat = true;
                    if (TextBoxStartDuration.Text != "")
                        startTriggerConfig.StartDelay = Convert.ToInt64(TextBoxStartDuration.Text);
                }
                else
                {
                    if (ReaderConfig.startTriggerParams.StartDelay != Convert.ToInt64(TextBoxStartDuration.Text))
                    {
                        isStartConfigChanged = true;
                        startTriggerConfig.IgnoreHandHeldTrigger = true;
                        startTriggerConfig.StartOnHandHeldTrigger = false;
                        startTriggerConfig.NoRepeat = false;
                        startTriggerConfig.Repeat = true;
                        if (TextBoxStartDuration.Text != "")
                            startTriggerConfig.StartDelay = Convert.ToInt64(TextBoxStartDuration.Text);
                        isStartConfigChanged = true;
                    }
                }               
            }
            
            //**************************STOP Trigger**********************************************//
            if (combostop.SelectedIndex != initialstopTriggerIndex)
            {
                isStopConfigChanged = true;
            }

            if (combostop.SelectedIndex == 0)
            {
                if (isStopConfigChanged)
                {
                    stopTriggerConfig.DisableStopOnAccessCount = true;
                    stopTriggerConfig.enableStopOnAccessCount = false;
                    stopTriggerConfig.DisableStoponInventoryCount = true;
                    stopTriggerConfig.EnableStopOnInventoryCount = false;
                    stopTriggerConfig.DisableStopOnTimeout = true;
                    stopTriggerConfig.EnableStopOnTimeout = false;
                    stopTriggerConfig.DisableStopOntagcount = true;
                    stopTriggerConfig.EnableStopOntagcount = false;
                    stopTriggerConfig.IgnoreHandHeldTrigger = true;
                    stopTriggerConfig.StopOnHandHeldTrigger = false;                    
                }
            }
            if (combostop.SelectedIndex == 1)
            {
                if (isStopConfigChanged)
                {
                    stopTriggerConfig.IgnoreHandHeldTrigger = false;
                    stopTriggerConfig.StopOnHandHeldTrigger = true;
                    stopTriggerConfig.DisableStopOnAccessCount = true;
                    stopTriggerConfig.enableStopOnAccessCount = false;
                    stopTriggerConfig.DisableStoponInventoryCount = true;
                    stopTriggerConfig.EnableStopOnInventoryCount = false;
                    stopTriggerConfig.DisableStopOnTimeout = false;
                    stopTriggerConfig.EnableStopOnTimeout = true;
                    stopTriggerConfig.DisableStopOntagcount = true;
                    stopTriggerConfig.EnableStopOntagcount = false;
                    if (CheckBoxStopTriggerPressed.IsChecked == true)
                        stopTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_PRESS;
                    if (CheckBoxStopTriggerReleased.IsChecked == true)
                        stopTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_RELEASE;
                    if(!TextStopDurationTrigger.Text.Equals(""))
                        stopTriggerConfig.StopTimeout = Convert.ToInt64(TextStopDurationTrigger.Text);
                }
                else
                {
                    if (((ReaderConfig.stopTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_PRESS) && (CheckBoxStopTriggerPressed.IsChecked != true))
                         || ((ReaderConfig.stopTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_RELEASE) && (CheckBoxStopTriggerReleased.IsChecked != true))
                         || (ReaderConfig.stopTriggerParams.StopTimeout != Convert.ToInt64(TextStopDurationTrigger.Text)))
                    {
                        stopTriggerConfig.IgnoreHandHeldTrigger = false;
                        stopTriggerConfig.StopOnHandHeldTrigger = true;
                        stopTriggerConfig.DisableStopOnAccessCount = true;
                        stopTriggerConfig.enableStopOnAccessCount = false;
                        stopTriggerConfig.DisableStoponInventoryCount = true;
                        stopTriggerConfig.EnableStopOnInventoryCount = false;
                        stopTriggerConfig.DisableStopOnTimeout = false;
                        stopTriggerConfig.EnableStopOnTimeout = true;
                        stopTriggerConfig.DisableStopOntagcount = true;
                        stopTriggerConfig.EnableStopOntagcount = false;
                        if (CheckBoxStopTriggerPressed.IsChecked == true)
                            stopTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_PRESS;
                        if (CheckBoxStopTriggerReleased.IsChecked == true)
                            stopTriggerConfig.TriggerType = ENUM_TRIGGER_ID.TRIGGER_RELEASE;
                        if (!TextStopDurationTrigger.Text.Equals(""))
                            stopTriggerConfig.StopTimeout = Convert.ToInt64(TextStopDurationTrigger.Text);
                        isStopConfigChanged = true;
                    }
                }
            }
            if (combostop.SelectedIndex == 2)
            {
                if (isStopConfigChanged)
                {
                    stopTriggerConfig.DisableStopOnAccessCount = true;
                    stopTriggerConfig.enableStopOnAccessCount = false;
                    stopTriggerConfig.DisableStoponInventoryCount = true;
                    stopTriggerConfig.EnableStopOnInventoryCount = false;
                    stopTriggerConfig.DisableStopOnTimeout = false;
                    stopTriggerConfig.EnableStopOnTimeout = true;
                    stopTriggerConfig.DisableStopOntagcount = true;
                    stopTriggerConfig.EnableStopOntagcount = false;
                    stopTriggerConfig.IgnoreHandHeldTrigger = true;
                    stopTriggerConfig.StopOnHandHeldTrigger = false;
                    if (!TextStopDuration.Text.Equals(""))
                        stopTriggerConfig.StopTimeout =Convert.ToInt64(TextStopDuration.Text);
                }
                else
                {
                    if(ReaderConfig.stopTriggerParams.StopTimeout!=Convert.ToInt64(TextStopDuration.Text))
                    {
                        stopTriggerConfig.DisableStopOnAccessCount = true;
                        stopTriggerConfig.enableStopOnAccessCount = false;
                        stopTriggerConfig.DisableStoponInventoryCount = true;
                        stopTriggerConfig.EnableStopOnInventoryCount = false;
                        stopTriggerConfig.DisableStopOnTimeout = false; 
                        stopTriggerConfig.EnableStopOnTimeout = true;
                        stopTriggerConfig.DisableStopOntagcount = true;
                        stopTriggerConfig.EnableStopOntagcount = false;
                        stopTriggerConfig.IgnoreHandHeldTrigger = true;
                        stopTriggerConfig.StopOnHandHeldTrigger = false;
                        if (!TextStopDuration.Text.Equals(""))
                            stopTriggerConfig.StopTimeout = Convert.ToInt64(TextStopDuration.Text);
                        isStopConfigChanged = true;
                    }
                }
            }
            if (combostop.SelectedIndex == 3)
            {
                if (isStopConfigChanged)
                {
                    stopTriggerConfig.DisableStopOnAccessCount = true;
                    stopTriggerConfig.enableStopOnAccessCount = false;
                    stopTriggerConfig.DisableStoponInventoryCount = true;
                    stopTriggerConfig.EnableStopOnInventoryCount = false;
                    stopTriggerConfig.DisableStopOnTimeout = false;
                    stopTriggerConfig.EnableStopOnTimeout = true;
                    stopTriggerConfig.DisableStopOntagcount = false;
                    stopTriggerConfig.EnableStopOntagcount = true;
                    stopTriggerConfig.IgnoreHandHeldTrigger = true;
                    stopTriggerConfig.StopOnHandHeldTrigger = false;
                    if (!TextStopTagcount.Text.Equals(""))
                        stopTriggerConfig.StopTagCount = Convert.ToInt64(TextStopTagcount.Text);
                    if (!TextStopDurationTagCount.Text.Equals(""))
                        stopTriggerConfig.StopTimeout = Convert.ToInt64(TextStopDurationTagCount.Text);
                }
                else
                {
                    if (ReaderConfig.stopTriggerParams.StopTagCount!= Convert.ToInt64(TextStopTagcount.Text)
                        || (ReaderConfig.stopTriggerParams.StopTimeout != Convert.ToInt64(TextStopDurationTagCount.Text)))
                    {
                        stopTriggerConfig.DisableStopOnAccessCount = true;
                        stopTriggerConfig.enableStopOnAccessCount = false;
                        stopTriggerConfig.DisableStoponInventoryCount = true;
                        stopTriggerConfig.EnableStopOnInventoryCount = false;
                        stopTriggerConfig.DisableStopOnTimeout = false;
                        stopTriggerConfig.EnableStopOnTimeout = true;
                        stopTriggerConfig.DisableStopOntagcount = false;
                        stopTriggerConfig.EnableStopOntagcount = true;
                        stopTriggerConfig.IgnoreHandHeldTrigger = true;
                        stopTriggerConfig.StopOnHandHeldTrigger = false;
                        if (!TextStopTagcount.Text.Equals(""))
                            stopTriggerConfig.StopTagCount = Convert.ToInt64(TextStopTagcount.Text);
                        if (!TextStopDurationTagCount.Text.Equals(""))
                            stopTriggerConfig.StopTimeout = Convert.ToInt64(TextStopDurationTagCount.Text);
                        isStopConfigChanged = true;
                    }
                }
            }
            if (combostop.SelectedIndex == 4)
            {
                if (isStopConfigChanged)
                {
                    stopTriggerConfig.DisableStopOnAccessCount = true;
                    stopTriggerConfig.enableStopOnAccessCount = false;
                    stopTriggerConfig.DisableStoponInventoryCount = false;
                    stopTriggerConfig.EnableStopOnInventoryCount = true;
                    stopTriggerConfig.DisableStopOnTimeout = false;
                    stopTriggerConfig.EnableStopOnTimeout = true;
                    stopTriggerConfig.DisableStopOntagcount = true;
                    stopTriggerConfig.EnableStopOntagcount = false;
                    stopTriggerConfig.IgnoreHandHeldTrigger = true;
                    stopTriggerConfig.StopOnHandHeldTrigger = false;
                    if (!TextInventoryRoundcount.Text.Equals(""))
                        stopTriggerConfig.StopInventoryCount = Convert.ToInt64(TextInventoryRoundcount.Text);
                    if (!TextStopDurationInventoryCount.Text.Equals(""))
                        stopTriggerConfig.StopTimeout = Convert.ToInt64(TextStopDurationInventoryCount.Text);

                }
                else
                {
                    if(ReaderConfig.stopTriggerParams.StopInventoryCount!= Convert.ToInt64(TextInventoryRoundcount.Text)
                        || (ReaderConfig.stopTriggerParams.StopTimeout != Convert.ToInt64(TextStopDurationInventoryCount.Text)))
                    {
                        stopTriggerConfig.DisableStopOnAccessCount = true;
                        stopTriggerConfig.enableStopOnAccessCount = false;
                        stopTriggerConfig.DisableStoponInventoryCount = false;
                        stopTriggerConfig.EnableStopOnInventoryCount = true;
                        stopTriggerConfig.DisableStopOnTimeout = false;
                        stopTriggerConfig.EnableStopOnTimeout = true;
                        stopTriggerConfig.DisableStopOntagcount = true;
                        stopTriggerConfig.EnableStopOntagcount = false;
                        stopTriggerConfig.IgnoreHandHeldTrigger = true;
                        stopTriggerConfig.StopOnHandHeldTrigger = false;
                        if (!TextInventoryRoundcount.Text.Equals(""))
                            stopTriggerConfig.StopInventoryCount = Convert.ToInt64(TextInventoryRoundcount.Text);
                        if (!TextStopDurationInventoryCount.Text.Equals(""))
                            stopTriggerConfig.StopTimeout = Convert.ToInt64(TextStopDurationInventoryCount.Text);
                        isStopConfigChanged = true;
                    }
                }
            }

            if (isStartConfigChanged)
            {
                readerobj.writeData(startTriggerConfig.ToString());
                readerobj.writeData(ASCIIProcessor.getCommandConfig(startTriggerConfig.getCommandType(), CONFIG_TYPE.CURRENT));
            }
            if (isStopConfigChanged)
            {
                readerobj.writeData(stopTriggerConfig.ToString());
                await baserecieverObj.isStartStopConfigSetCompltete();
                ReaderConfig.isStartStopSetComplete = false;
                readerobj.writeData(ASCIIProcessor.getCommandConfig(stopTriggerConfig.getCommandType(), CONFIG_TYPE.CURRENT));
            }
        }

        private void combostart_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           
            if (combostart.SelectedIndex == 0)
            {
                GridStartPeriodic.Visibility = Visibility.Collapsed;
                StackStartHandheldTriggers.Visibility= Visibility.Collapsed;                
            }
            if (combostart.SelectedIndex == 1)
            {               
               GridStartPeriodic.Visibility = Visibility.Collapsed;
               StackStartHandheldTriggers.Visibility= Visibility.Visible;
               if (ReaderConfig.startTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_PRESS)
                   CheckBoxStartTriggerPressed.IsChecked = true;
               if (ReaderConfig.startTriggerParams.TriggerType == ENUM_TRIGGER_ID.TRIGGER_RELEASE)
                   CheckBoxStartTriggerReleased.IsChecked = true;                
            }
            if (combostart.SelectedIndex == 2)
            {
                TextBoxStartDuration.Text = ReaderConfig.startTriggerParams.StartDelay.ToString();
                GridStartPeriodic.Visibility = Visibility.Visible;
                StackStartHandheldTriggers.Visibility = Visibility.Collapsed;                
            }               
        }

        private void combostop_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            if(combostop.SelectedIndex==0)
            {
                GridStopDuration.Visibility = Visibility.Collapsed;
                GridRoundCount.Visibility = Visibility.Collapsed;
                GridTotalCount.Visibility = Visibility.Collapsed;
                GridStopHandheldTriggers.Visibility = Visibility.Collapsed;
            }
            if (combostop.SelectedIndex == 1)
            {
                GridStopDuration.Visibility = Visibility.Collapsed;
                GridStopHandheldTriggers.Visibility = Visibility.Visible;
                GridRoundCount.Visibility = Visibility.Collapsed;
                GridTotalCount.Visibility = Visibility.Collapsed;
            }
            if (combostop.SelectedIndex == 2)
            {
                GridStopDuration.Visibility = Visibility.Visible;
                GridStopHandheldTriggers.Visibility = Visibility.Collapsed;
                GridRoundCount.Visibility = Visibility.Collapsed;
                GridTotalCount.Visibility = Visibility.Collapsed;
            }
            if (combostop.SelectedIndex == 3)
            {
                GridStopDuration.Visibility = Visibility.Collapsed;
                GridStopHandheldTriggers.Visibility = Visibility.Collapsed;
                GridRoundCount.Visibility = Visibility.Collapsed;
                GridTotalCount.Visibility = Visibility.Visible;
            }
            if (combostop.SelectedIndex == 4)
            {
                GridStopDuration.Visibility = Visibility.Collapsed;
                GridStopHandheldTriggers.Visibility = Visibility.Collapsed;
                GridRoundCount.Visibility = Visibility.Visible;
                GridTotalCount.Visibility = Visibility.Collapsed;
            }
        }
    }
}
