﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CLoggerCs;

namespace CollectionConditions
{
    public partial class ClockSetting : Form
    {
        ushort m_clock_type;
        ushort m_sampling_clock_unit;
        double m_sampling_clock;
        double m_external_clock;
        uint m_sampling_times;
        float m_scan_clock;
        uint m_repeat_times;
        ushort m_start_trigger_type;
        ushort m_stop_trigger_type;
        uint m_delay_time;
        ushort m_start_level_trigger_edge;
        ushort m_start_level_sequence_no;
        float m_start_level_border_value;
        ushort m_start_range_sequence_no;
        float m_start_range_upper_border_value;
        float m_start_range_lower_border_value;
        uint m_start_range_state_times;
        uint m_start_time_time;
        uint m_start_time_hour;
        uint m_start_time_minute;
        uint m_start_time_second;
        ushort m_stop_level_trigger_edge;
        ushort m_stop_level_sequence_no;
        float m_stop_level_border_value;
        ushort m_stop_range_sequence_no;
        float m_stop_range_upper_border_value;
        float m_stop_range_lower_border_value;
        uint m_stop_range_state_times;
        uint m_stop_time_time;
        uint m_stop_time_hour;
        uint m_stop_time_minute;
        uint m_stop_time_second;

        public ClockSetting()
        {
            InitializeComponent();
            m_clock_type = 0;
            m_sampling_clock_unit = 0;
            m_sampling_clock = 0;
            m_external_clock = 0;
            m_sampling_times = 0;
            m_scan_clock = 0;
            m_repeat_times = 0;
            m_start_trigger_type = 0;
            m_stop_trigger_type = 0;
            m_delay_time = 0;
            m_start_level_trigger_edge = 0;
            m_start_level_sequence_no = 0;
            m_start_level_border_value = 0;
            m_start_range_sequence_no = 0;
            m_start_range_upper_border_value = 0;
            m_start_range_lower_border_value = 0;
            m_start_range_state_times = 0;
            m_start_time_time = 0;
            m_start_time_hour = 0;
            m_start_time_minute = 0;
            m_start_time_second = 0;
            m_stop_level_trigger_edge = 0;
            m_stop_level_sequence_no = 0;
            m_stop_level_border_value = 0;
            m_stop_range_sequence_no = 0;
            m_stop_range_upper_border_value = 0;
            m_stop_range_lower_border_value = 0;
            m_stop_range_state_times = 0;
            m_stop_time_time = 0;
            m_stop_time_hour = 0;
            m_stop_time_minute = 0;
            m_stop_time_second = 0;
        }

        //================================================================================
        // Pass the data (Set)
        //================================================================================
        internal void clock_data_set(ushort clock_type, ushort sampling_clock_unit, double sampling_clock, double external_clock, uint sampling_times, float scan_clock, uint repeat_times, ushort start_trigger_type, ushort stop_trigger_type, uint delay_time, ushort start_level_trigger_edge, ushort start_level_sequence_no, float start_level_border_value, ushort start_range_sequence_no, float start_range_upper_border_value, float start_range_lower_border_value, uint start_range_state_times, uint start_time_time, uint start_time_hour, uint start_time_minute, uint start_time_second, ushort stop_level_trigger_edge, ushort stop_level_sequence_no, float stop_level_border_value, ushort stop_range_sequence_no, float stop_range_upper_border_value, float stop_range_lower_border_value, uint stop_range_state_times, uint stop_time_time, uint stop_time_hour, uint stop_time_minute, uint stop_time_second)
        {
            m_clock_type = clock_type;
            m_sampling_clock_unit = sampling_clock_unit;
            m_sampling_clock = sampling_clock;
            m_external_clock = external_clock;
            m_sampling_times = sampling_times;
            m_scan_clock = scan_clock;
            m_repeat_times = repeat_times;
            m_start_trigger_type = start_trigger_type;
            m_stop_trigger_type = stop_trigger_type;
            m_delay_time = delay_time;
            m_start_level_trigger_edge = start_level_trigger_edge;
            m_start_level_sequence_no = start_level_sequence_no;
            m_start_level_border_value = start_level_border_value;
            m_start_range_sequence_no = start_range_sequence_no;
            m_start_range_upper_border_value = start_range_upper_border_value;
            m_start_range_lower_border_value = start_range_lower_border_value;
            m_start_range_state_times = start_range_state_times;
            m_start_time_time = start_time_time;
            m_start_time_hour = start_time_hour;
            m_start_time_minute = start_time_minute;
            m_start_time_second = start_time_second;
            m_stop_level_trigger_edge = stop_level_trigger_edge;
            m_stop_level_sequence_no = stop_level_sequence_no;
            m_stop_level_border_value = stop_level_border_value;
            m_stop_range_sequence_no = stop_range_sequence_no;
            m_stop_range_upper_border_value = stop_range_upper_border_value;
            m_stop_range_lower_border_value = stop_range_lower_border_value;
            m_stop_range_state_times = stop_range_state_times;
            m_stop_time_time = stop_time_time;
            m_stop_time_hour = stop_time_hour;
            m_stop_time_minute = stop_time_minute;
            m_stop_time_second = stop_time_second;
        }

        //================================================================================
        // Pass the data (Get)
        //================================================================================
        internal void clock_data_get(ref ushort clock_type, ref ushort sampling_clock_unit, ref double sampling_clock, ref double external_clock, ref uint sampling_times, ref float scan_clock, ref uint repeat_times, ref ushort start_trigger_type, ref ushort stop_trigger_type, ref uint delay_time, ref ushort start_level_trigger_edge, ref ushort start_level_sequence_no, ref float start_level_border_value, ref ushort start_range_sequence_no, ref float start_range_upper_border_value, ref float start_range_lower_border_value, ref uint start_range_state_times, ref uint start_time_time, ref uint start_time_hour, ref uint start_time_minute, ref uint start_time_second, ref ushort stop_level_trigger_edge, ref ushort stop_level_sequence_no, ref float stop_level_border_value, ref ushort stop_range_sequence_no, ref float stop_range_upper_border_value, ref float stop_range_lower_border_value, ref uint stop_range_state_times, ref uint stop_time_time, ref uint stop_time_hour, ref uint stop_time_minute, ref uint stop_time_second)
        {
            clock_type = m_clock_type;
            sampling_clock_unit = m_sampling_clock_unit;
            sampling_clock = m_sampling_clock;
            external_clock = m_external_clock;
            sampling_times = m_sampling_times;
            scan_clock = m_scan_clock;
            repeat_times = m_repeat_times;
            start_trigger_type = m_start_trigger_type;
            stop_trigger_type = m_stop_trigger_type;
            delay_time = m_delay_time;
            start_level_trigger_edge = m_start_level_trigger_edge;
            start_level_sequence_no = m_start_level_sequence_no;
            start_level_border_value = m_start_level_border_value;
            start_range_sequence_no = m_start_range_sequence_no;
            start_range_upper_border_value = m_start_range_upper_border_value;
            start_range_lower_border_value = m_start_range_lower_border_value;
            start_range_state_times = m_start_range_state_times;
            start_time_time = m_start_time_time;
            start_time_hour = m_start_time_hour;
            start_time_minute = m_start_time_minute;
            start_time_second = m_start_time_second;
            stop_level_trigger_edge = m_stop_level_trigger_edge;
            stop_level_sequence_no = m_stop_level_sequence_no;
            stop_level_border_value = m_stop_level_border_value;
            stop_range_sequence_no = m_stop_range_sequence_no;
            stop_range_upper_border_value = m_stop_range_upper_border_value;
            stop_range_lower_border_value = m_stop_range_lower_border_value;
            stop_range_state_times = m_stop_range_state_times;
            stop_time_time = m_stop_time_time;
            stop_time_hour = m_stop_time_hour;
            stop_time_minute = m_stop_time_minute;
            stop_time_second = m_stop_time_second;
        }

        //================================================================================
        // Initial settings
        //================================================================================
        private void ClockSetting_Load(object sender, EventArgs e)
        {
            //----------------------------------------
            // Create the combobox for clock type
            //----------------------------------------
            comboBox_ClockType.Items.Add("Internal clock");
            comboBox_ClockType.Items.Add("External clock(Falling edge)");
            comboBox_ClockType.Items.Add("External clock(Rising edge)");
            //----------------------------------------
            // Update the selection of clock type combobox
            //----------------------------------------
            comboBox_ClockType.SelectedIndex = m_clock_type;
            comboBox_ClockType_SelectedIndexChanged(comboBox_ClockType, EventArgs.Empty);
            //----------------------------------------
            // Update the display of sampling clock period(frequency)
            //----------------------------------------
            textBox_SamplingClock.Text = string.Format("{0}", m_sampling_clock);
            //----------------------------------------
            // Update the display of external clock update interval
            //----------------------------------------
            textBox_ExternalClock.Text = string.Format("{0}", m_external_clock);
            //----------------------------------------
            // Create the combobox for sampling clock unit
            //----------------------------------------
            comboBox_SamplingClockUnit.Items.Add("usec");
            comboBox_SamplingClockUnit.Items.Add("msec");
            comboBox_SamplingClockUnit.Items.Add("sec");
            comboBox_SamplingClockUnit.Items.Add("Hz");
            comboBox_SamplingClockUnit.Items.Add("kHz");
            comboBox_SamplingClockUnit.Items.Add("MHz");
            //----------------------------------------
            // Update the selection of sampling clock unit combobox
            //----------------------------------------
            comboBox_SamplingClockUnit.SelectedIndex = m_sampling_clock_unit;
            //----------------------------------------
            // Create the combobox for sampling condition
            //----------------------------------------
            comboBox_SamplingTimes.Items.Add("Infinite");
            comboBox_SamplingTimes.Items.Add("Finite");
            //----------------------------------------
            // Update the selection of sampling condition combobox
            //----------------------------------------
            if (m_sampling_times == 0)
            {
                comboBox_SamplingTimes.SelectedIndex = 0;
            }
            else
            {
                comboBox_SamplingTimes.SelectedIndex = 1;
            }
            //----------------------------------------
            // Perform the processing when the value of the sampling condition combobox is changed
            //----------------------------------------
            comboBox_SamplingTimes_SelectedIndexChanged(comboBox_SamplingTimes, EventArgs.Empty);
            //----------------------------------------
            // Update the display of sampling times
            //----------------------------------------
            textBox_SamplingTimes.Text = string.Format("{0}", m_sampling_times);
            //----------------------------------------
            // Update the display of scan clock
            //----------------------------------------
            textBox_ScanClock.Text = string.Format("{0}", m_scan_clock);
            //----------------------------------------
            // Update the display of repeat times
            //----------------------------------------
            textBox_RepeatTimes.Text = string.Format("{0}", m_repeat_times);
            //----------------------------------------
            // Create the combobox for delay condition
            //----------------------------------------
            comboBox_DelayTimes.Items.Add("Disable");
            comboBox_DelayTimes.Items.Add("Enable");
            //----------------------------------------
            // Update the selection of delay condition combobox
            //----------------------------------------
            if (m_delay_time == 0)
            {
                comboBox_DelayTimes.SelectedIndex = 0;
            }
            else
            {
                comboBox_DelayTimes.SelectedIndex = 1;
            }
            //----------------------------------------
            // Perform the processing when the value of the delay condition combobox is changed
            //----------------------------------------
            comboBox_DelayTimes_SelectedIndexChanged(comboBox_DelayTimes, EventArgs.Empty);
            //----------------------------------------
            // Update the display of delay times
            //----------------------------------------
            textBox_DelayTimes.Text = string.Format("{0}", m_delay_time);
            //----------------------------------------
            // Create the combobox for start condition
            //----------------------------------------
            comboBox_StartTrigger_Type.Items.Add("None");
            comboBox_StartTrigger_Type.Items.Add("External trigger rising edge");
            comboBox_StartTrigger_Type.Items.Add("External trigger falling edge");
            comboBox_StartTrigger_Type.Items.Add("Level comparison");
            comboBox_StartTrigger_Type.Items.Add("In range");
            comboBox_StartTrigger_Type.Items.Add("Out range");
            comboBox_StartTrigger_Type.Items.Add("Time (Time[sec])");
            comboBox_StartTrigger_Type.Items.Add("Time (Moment)");
            //----------------------------------------
            // Update the selection of start condition combobox
            //----------------------------------------
            comboBox_StartTrigger_Type.SelectedIndex = m_start_trigger_type;
            //----------------------------------------
            // Perform the processing when the value of the start condition combobox is changed
            //----------------------------------------
            comboBox_StartTrigger_Type_SelectedIndexChanged(comboBox_StartTrigger_Type, EventArgs.Empty);
            //----------------------------------------
            // Start condition -> Level comparison -> Update the display of channel number
            //----------------------------------------
            textBox_StartTrigger_Level_SequenceNo.Text = string.Format("{0}", m_start_level_sequence_no);
            //----------------------------------------
            // Start condition -> Level comparison -> Update the display of comparison level
            //----------------------------------------
            textBox_StartTrigger_Level_BorderValue.Text = string.Format("{0}", m_start_level_border_value);
            //----------------------------------------
            // Start condition -> Level comparison -> Create the combobox for comparison direction
            //----------------------------------------
            comboBox_StartTrigger_Level_Edge.Items.Add("Rising edge");
            comboBox_StartTrigger_Level_Edge.Items.Add("Falling edge");
            comboBox_StartTrigger_Level_Edge.Items.Add("Both edges");
            //----------------------------------------
            // Start condition -> Level comparison -> Update the selection of comparison direction combobox
            //----------------------------------------
            comboBox_StartTrigger_Level_Edge.SelectedIndex = m_start_level_trigger_edge;
            //----------------------------------------
            // Start condition -> In range/out range comparison -> Update the display of channel number
            //----------------------------------------
            textBox_StartTrigger_Range_SequenceNo.Text = string.Format("{0}", m_start_range_sequence_no);
            //----------------------------------------
            // Start condition -> In range/out range comparison -> Update the display of lower limit value
            //----------------------------------------
            textBox_StartTrigger_Range_Lower.Text = string.Format("{0}", m_start_range_lower_border_value);
            //----------------------------------------
            // Start condition -> In range/out range comparison -> Update the display of upper limit value
            //----------------------------------------
            textBox_StartTrigger_Range_Upper.Text = string.Format("{0}", m_start_range_upper_border_value);
            //----------------------------------------
            // Start condition -> In range/out range comparison -> Update the display of state times
            //----------------------------------------
            textBox_StartTrigger_Range_StartTimes.Text = string.Format("{0}", m_start_range_state_times);
            //----------------------------------------
            // Start condition -> Time/Moment -> Update Time display
            //----------------------------------------
            textBox_StartTrigger_Time_Time.Text = string.Format("{0}", m_start_time_time);
            //----------------------------------------
            // Start condition -> Time/Moment -> Update Moment(H) display
            //----------------------------------------
            textBox_StartTrigger_Time_Hour.Text = string.Format("{0}", m_start_time_hour);
            //----------------------------------------
            // Start condition -> Time/Moment -> Update Moment(M) display
            //----------------------------------------
            textBox_StartTrigger_Time_Minute.Text = string.Format("{0}", m_start_time_minute);
            //----------------------------------------
            // Start condition -> Time/Moment -> Update Moment(S) display
            //----------------------------------------
            textBox_StartTrigger_Time_Second.Text = string.Format("{0}", m_start_time_second);
            //----------------------------------------
            // Create the combobox for stop condition
            //----------------------------------------
            comboBox_StopTrigger_Type.Items.Add("None");
            comboBox_StopTrigger_Type.Items.Add("External trigger rising edge");
            comboBox_StopTrigger_Type.Items.Add("External trigger falling edge");
            comboBox_StopTrigger_Type.Items.Add("Level comparison");
            comboBox_StopTrigger_Type.Items.Add("In range");
            comboBox_StopTrigger_Type.Items.Add("Out range");
            comboBox_StopTrigger_Type.Items.Add("Time (Time[sec])");
            comboBox_StopTrigger_Type.Items.Add("Time (Moment)");
            //----------------------------------------
            // Update the selection of stop condition combobox
            //----------------------------------------
            comboBox_StopTrigger_Type_SelectedIndexChanged(comboBox_StopTrigger_Type, EventArgs.Empty);
            //----------------------------------------
            // Perform the processing when the value of the stop condition combobox is changed
            //----------------------------------------
            comboBox_StopTrigger_Type.SelectedIndex = m_stop_trigger_type;
            //----------------------------------------
            // Stop condition -> Level comparison -> Update the display of channel number
            //----------------------------------------
            textBox_StopTrigger_Level_SequenceNo.Text = string.Format("{0}", m_stop_level_sequence_no);
            //----------------------------------------
            // Stop condition -> Level comparison -> Update the display of comparison level
            //----------------------------------------
            textBox_StopTrigger_Level_BorderValue.Text = string.Format("{0}", m_stop_level_border_value);
            //----------------------------------------
            // Stop condition -> Level comparison -> Create the combobox for comparison direction
            //----------------------------------------
            comboBox_StopTrigger_Level_Edge.Items.Add("Rising edge");
            comboBox_StopTrigger_Level_Edge.Items.Add("Falling edge");
            comboBox_StopTrigger_Level_Edge.Items.Add("Both edges");
            //----------------------------------------
            // Stop condition -> Level comparison -> Update the selection of comparison direction combobox
            //----------------------------------------
            comboBox_StopTrigger_Level_Edge.SelectedIndex = m_stop_level_trigger_edge;
            //----------------------------------------
            // Stop condition -> In range/out range comparison -> Update the display of channel number
            //----------------------------------------
            textBox_StopTrigger_Range_SequenceNo.Text = string.Format("{0}", m_stop_range_sequence_no);
            //----------------------------------------
            // Stop condition -> In range/out range comparison -> Update the display of lower limit value
            //----------------------------------------
            textBox_StopTrigger_Range_Lower.Text = string.Format("{0}", m_stop_range_lower_border_value);
            //----------------------------------------
            // Stop condition -> In range/out range comparison -> Update the display of upper limit value
            //----------------------------------------
            textBox_StopTrigger_Range_Upper.Text = string.Format("{0}", m_stop_range_upper_border_value);
            //----------------------------------------
            // Stop condition -> In range/out range comparison -> Update the display of state times
            //----------------------------------------
            textBox_StopTrigger_Range_StartTimes.Text = string.Format("{0}", m_stop_range_state_times);
            //----------------------------------------
            // Stop conditions -> Time/Moment -> Update Time display
            //----------------------------------------
            textBox_StopTrigger_Time_Time.Text = string.Format("{0}", m_stop_time_time);
            //----------------------------------------
            // Stop conditions -> Time/Moment -> Update Moment(H) display
            //----------------------------------------
            textBox_StopTrigger_Time_Hour.Text = string.Format("{0}", m_stop_time_hour);
            //----------------------------------------
            // Stop conditions -> Time/Moment -> Update Moment(M) display
            //----------------------------------------
            textBox_StopTrigger_Time_Minute.Text = string.Format("{0}", m_stop_time_minute);
            //----------------------------------------
            // Stop conditions -> Time/Moment -> Update Moment(S) display
            //----------------------------------------
            textBox_StopTrigger_Time_Second.Text = string.Format("{0}", m_stop_time_second);
        }

        //================================================================================
        // It is the process when the Apply button is clicked
        // Confirm the setting value
        //================================================================================
        private void button_OK_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // Get the clock type from combobox
            //----------------------------------------
            m_clock_type = (ushort)comboBox_ClockType.SelectedIndex;
            //----------------------------------------
            // Get the sampling clock unit from combobox
            //----------------------------------------
            m_sampling_clock_unit = (ushort)comboBox_SamplingClockUnit.SelectedIndex;
            //----------------------------------------
            // Get the sampling clock period from textbox
            //----------------------------------------
            if (double.TryParse(textBox_SamplingClock.Text, out m_sampling_clock) == false)
            {
                m_sampling_clock = 0;
            }
            //----------------------------------------
            // Get the external clock update interval from textbox
            //----------------------------------------
            if (double.TryParse(textBox_ExternalClock.Text, out m_external_clock) == false)
            {
                m_external_clock = 0;
            }
            //----------------------------------------
            // Get the sampling condition from combobox
            //----------------------------------------
            if (comboBox_SamplingTimes.SelectedIndex == 0)
            {
                //----------------------------------------
                // If infinite, set to 0
                //----------------------------------------
                m_sampling_times = 0;
            }
            else
            {
                //----------------------------------------
                // If finite, get the sampling times from textbox
                //----------------------------------------
                if (uint.TryParse(textBox_SamplingTimes.Text, out m_sampling_times) == false)
                {
                    m_sampling_times = 0;
                }
            }
            //----------------------------------------
            // Get the conversion speed from textbox
            //----------------------------------------
            if (float.TryParse(textBox_ScanClock.Text, out m_scan_clock) == false)
            {
                m_scan_clock = 0;
            }
            //----------------------------------------
            // If enable, get the repeat times from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_RepeatTimes.Text, out m_repeat_times) == false)
            {
                m_repeat_times = 0;
            }
            //----------------------------------------
            // Get the delay condition from combobox
            //----------------------------------------
            if (comboBox_DelayTimes.SelectedIndex == (ushort)CLoggerConst.LOGGER_PARAM_DISABLE)
            {
                //----------------------------------------
                // If disable, set to 0
                //----------------------------------------
                m_delay_time = 0;
            }
            else
            {
                //----------------------------------------
                // If enable, get the delay times from textbox
                //----------------------------------------
                if (uint.TryParse(textBox_DelayTimes.Text, out m_delay_time) == false)
                {
                    m_delay_time = 0;
                }
            }
            //----------------------------------------
            // Get the start condition from combobox
            //----------------------------------------
            m_start_trigger_type = (ushort)comboBox_StartTrigger_Type.SelectedIndex;
            //----------------------------------------
            // Start condition - Level comparison - Get the channel number from textbox
            //----------------------------------------
            if (ushort.TryParse(textBox_StartTrigger_Level_SequenceNo.Text, out m_start_level_sequence_no) == false)
            {
                m_start_level_sequence_no = 0;
            }
            //----------------------------------------
            // Start condition - Level comparison - Get the comparison level from textbox
            //----------------------------------------
            if (float.TryParse(textBox_StartTrigger_Level_BorderValue.Text, out m_start_level_border_value) == false)
            {
                m_start_level_border_value = 0;
            }
            //----------------------------------------
            // Start condition - Level comparison - Get the comparison direction from combobox
            //----------------------------------------
            m_start_level_trigger_edge = (ushort)comboBox_StartTrigger_Level_Edge.SelectedIndex;
            //----------------------------------------
            // Start condition - In range/out range comparison - Get the channel number from textbox
            //----------------------------------------
            if (ushort.TryParse(textBox_StartTrigger_Range_SequenceNo.Text, out m_start_range_sequence_no) == false)
            {
                m_start_range_sequence_no = 0;
            }
            //----------------------------------------
            // Start condition - In range/out range comparison - Get the upper limit value from textbox
            //----------------------------------------
            if (float.TryParse(textBox_StartTrigger_Range_Upper.Text, out m_start_range_upper_border_value) == false)
            {
                m_start_range_upper_border_value = 0;
            }
            //----------------------------------------
            // Start condition - In range/out range comparison - Get the lower limit value from textbox
            //----------------------------------------
            if (float.TryParse(textBox_StartTrigger_Range_Lower.Text, out m_start_range_lower_border_value) == false)
            {
                m_start_range_lower_border_value = 0;
            }
            //----------------------------------------
            // Start condition - In range/out range comparison - Get the state times from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StartTrigger_Range_StartTimes.Text, out m_start_range_state_times) == false)
            {
                m_start_range_state_times = 0;
            }
            //----------------------------------------
            // Get Start condition - Time/Moment - Time from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StartTrigger_Time_Time.Text, out m_start_time_time) == false)
            {
                m_start_time_time = 0;
            }
            //----------------------------------------
            // Get Start condition - Time/Moment - Moment(H) from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StartTrigger_Time_Hour.Text, out m_start_time_hour) == false)
            {
                m_start_time_hour = 0;
            }
            //----------------------------------------
            // Get Start condition - Time/Moment - Moment(M) from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StartTrigger_Time_Minute.Text, out m_start_time_minute) == false)
            {
                m_start_time_minute = 0;
            }
            //----------------------------------------
            // Get Start condition - Time/Moment - Moment(S) from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StartTrigger_Time_Second.Text, out m_start_time_second) == false)
            {
                m_start_time_second = 0;
            }
            //----------------------------------------
            // Get the stop condition from combobox
            //----------------------------------------
            m_stop_trigger_type = (ushort)comboBox_StopTrigger_Type.SelectedIndex;
            //----------------------------------------
            // Stop condition - Level comparison - Get the channel number from textbox
            //----------------------------------------
            if (ushort.TryParse(textBox_StopTrigger_Level_SequenceNo.Text, out m_stop_level_sequence_no) == false)
            {
                m_stop_level_sequence_no = 0;
            }
            //----------------------------------------
            // Stop condition - Level comparison - Get the comparison level from textbox
            //----------------------------------------
            if (float.TryParse(textBox_StopTrigger_Level_BorderValue.Text, out m_stop_level_border_value) == false)
            {
                m_stop_level_border_value = 0;
            }
            //----------------------------------------
            // Stop condition - Level comparison - Get the comparison direction from combobox
            //----------------------------------------
            m_stop_level_trigger_edge = (ushort)comboBox_StopTrigger_Level_Edge.SelectedIndex;
            //----------------------------------------
            // Stop condition - In range/out range comparison - Get the channel number from textbox
            //----------------------------------------
            if (ushort.TryParse(textBox_StopTrigger_Range_SequenceNo.Text, out m_stop_range_sequence_no) == false)
            {
                m_stop_range_sequence_no = 0;
            }
            //----------------------------------------
            // Stop condition - In range/out range comparison - Get the upper limit value from textbox
            //----------------------------------------
            if (float.TryParse(textBox_StopTrigger_Range_Upper.Text, out m_stop_range_upper_border_value) == false)
            {
                m_stop_range_upper_border_value = 0;
            }
            //----------------------------------------
            // Stop condition - In range/out range comparison - Get the lower limit value from textbox
            //----------------------------------------
            if (float.TryParse(textBox_StopTrigger_Range_Lower.Text, out m_stop_range_lower_border_value) == false)
            {
                m_stop_range_lower_border_value = 0;
            }
            //----------------------------------------
            // Stop condition - In range/out range comparison - Get the state times from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StopTrigger_Range_StartTimes.Text, out m_stop_range_state_times) == false)
            {
                m_stop_range_state_times = 0;
            }
            //----------------------------------------
            // Get Stop condition - Time/Moment - Time from textbox
            //----------------------------------------
            if(uint.TryParse(textBox_StopTrigger_Time_Time.Text, out m_stop_time_time) == false)
            {
                m_stop_time_time = 0;
            }
            //----------------------------------------
            // Get Stop condition - Time/Moment - Moment(H) from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StopTrigger_Time_Hour.Text, out m_stop_time_hour) == false)
            {
                m_stop_time_hour = 0;
            }
            //----------------------------------------
            // Get Stop condition - Time/Moment - Moment(M) from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StopTrigger_Time_Minute.Text, out m_stop_time_minute) == false)
            {
                m_stop_time_minute = 0;
            }
            //----------------------------------------
            // Get Stop condition - Time/Moment - Moment(S) from textbox
            //----------------------------------------
            if (uint.TryParse(textBox_StopTrigger_Time_Second.Text, out m_stop_time_second) == false)
            {
                m_stop_time_second = 0;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        //================================================================================
        // It is the process when the Cancel button is clicked
        //================================================================================
        private void button_CANCEL_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        //================================================================================
        // It is the process when the value of clock type combobox is changed
        // Check the setting value and enable/disable the sampling clock period and the external clock update interval
        //================================================================================
        private void comboBox_ClockType_SelectedIndexChanged(object sender, EventArgs e)
        {
            int select_clocktype;   // Clock type

            //----------------------------------------
            // Get the clock type from combobox
            //----------------------------------------
            select_clocktype = comboBox_ClockType.SelectedIndex;
            //----------------------------------------
            // For internal clock
            //----------------------------------------
            if (select_clocktype == (int)CLoggerConst.LOGGER_PARAM_CLOCK_INTERNAL)
            {
                //----------------------------------------
                // Enable the sampling clock period
                //----------------------------------------
                textBox_SamplingClock.Enabled = true;
                comboBox_SamplingClockUnit.Enabled = true;
                //----------------------------------------
                // Disable the external clock update interval
                //----------------------------------------
                textBox_ExternalClock.Enabled = false;
            }
            //----------------------------------------
            // For external clock
            //----------------------------------------
            else
            {
                //----------------------------------------
                // Disable the sampling clock period
                //----------------------------------------
                textBox_SamplingClock.Enabled = false;
                comboBox_SamplingClockUnit.Enabled = false;
                //----------------------------------------
                // Enable the external clock update interval
                //----------------------------------------
                textBox_ExternalClock.Enabled = true;
            }
        }

        //================================================================================
        // It is the process when the value of start condition combobox is changed
        // Check the setting value and enable/disable the level comparison and the in range/out range comparison
        //================================================================================
        private void comboBox_StartTrigger_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            int select_trigger_type;    // Start condition

            //----------------------------------------
            // Get the start condition from combobox
            //----------------------------------------
            select_trigger_type = comboBox_StartTrigger_Type.SelectedIndex;
            //----------------------------------------
            // For level comparison
            //----------------------------------------
            if (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_LEVEL)
            {
                //----------------------------------------
                // Enable the level comparison
                //----------------------------------------
                textBox_StartTrigger_Level_SequenceNo.Enabled = true;
                textBox_StartTrigger_Level_BorderValue.Enabled = true;
                comboBox_StartTrigger_Level_Edge.Enabled = true;
                //----------------------------------------
                // Disable the in range/out range comparison
                //----------------------------------------
                textBox_StartTrigger_Range_SequenceNo.Enabled = false;
                textBox_StartTrigger_Range_Lower.Enabled = false;
                textBox_StartTrigger_Range_Upper.Enabled = false;
                textBox_StartTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StartTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StartTrigger_Time_Hour.Enabled = false;
                textBox_StartTrigger_Time_Minute.Enabled = false;
                textBox_StartTrigger_Time_Second.Enabled = false;
            }
            //----------------------------------------
            // For in range/out range comparison
            //----------------------------------------
            else if ((select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_INRANGE) || (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_OUTRANGE))
            {
                //----------------------------------------
                // Disable the level comparison
                //----------------------------------------
                textBox_StartTrigger_Level_SequenceNo.Enabled = false;
                textBox_StartTrigger_Level_BorderValue.Enabled = false;
                comboBox_StartTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Enable the in range/out range comparison
                //----------------------------------------
                textBox_StartTrigger_Range_SequenceNo.Enabled = true;
                textBox_StartTrigger_Range_Lower.Enabled = true;
                textBox_StartTrigger_Range_Upper.Enabled = true;
                textBox_StartTrigger_Range_StartTimes.Enabled = true;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StartTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StartTrigger_Time_Hour.Enabled = false;
                textBox_StartTrigger_Time_Minute.Enabled = false;
                textBox_StartTrigger_Time_Second.Enabled = false;
            }
            //----------------------------------------
            // For Time (Time(sec))
            //----------------------------------------
            else if (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_ELAPSED_TIME)
            {
                //----------------------------------------
                // Disable level comparison
                //----------------------------------------
                textBox_StartTrigger_Level_SequenceNo.Enabled = false;
                textBox_StartTrigger_Level_BorderValue.Enabled = false;
                comboBox_StartTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Disable in range/out range comparison
                //----------------------------------------
                textBox_StartTrigger_Range_SequenceNo.Enabled = false;
                textBox_StartTrigger_Range_Lower.Enabled = false;
                textBox_StartTrigger_Range_Upper.Enabled = false;
                textBox_StartTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Enable Time
                //----------------------------------------
                textBox_StartTrigger_Time_Time.Enabled = true;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StartTrigger_Time_Hour.Enabled = false;
                textBox_StartTrigger_Time_Minute.Enabled = false;
                textBox_StartTrigger_Time_Second.Enabled = false;
            }
            //----------------------------------------
            // For Time (Moment)
            //----------------------------------------
            else if (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_CURRENT_TIME)
            {
                //----------------------------------------
                // Disable level comparison
                //----------------------------------------
                textBox_StartTrigger_Level_SequenceNo.Enabled = false;
                textBox_StartTrigger_Level_BorderValue.Enabled = false;
                comboBox_StartTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Disable in range/out range comparison
                //----------------------------------------
                textBox_StartTrigger_Range_SequenceNo.Enabled = false;
                textBox_StartTrigger_Range_Lower.Enabled = false;
                textBox_StartTrigger_Range_Upper.Enabled = false;
                textBox_StartTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StartTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Enable Moment
                //----------------------------------------
                textBox_StartTrigger_Time_Hour.Enabled = true;
                textBox_StartTrigger_Time_Minute.Enabled = true;
                textBox_StartTrigger_Time_Second.Enabled = true;
            }
            //----------------------------------------
            // Other than level, range comparison, Time, Moment
            //----------------------------------------
            else
            {
                //----------------------------------------
                // Disable the level comparison
                //----------------------------------------
                textBox_StartTrigger_Level_SequenceNo.Enabled = false;
                textBox_StartTrigger_Level_BorderValue.Enabled = false;
                comboBox_StartTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Disable the in range/out range comparison
                //----------------------------------------
                textBox_StartTrigger_Range_SequenceNo.Enabled = false;
                textBox_StartTrigger_Range_Lower.Enabled = false;
                textBox_StartTrigger_Range_Upper.Enabled = false;
                textBox_StartTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StartTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StartTrigger_Time_Hour.Enabled = false;
                textBox_StartTrigger_Time_Minute.Enabled = false;
                textBox_StartTrigger_Time_Second.Enabled = false;
            }
        }

        //================================================================================
        // It is the process when the value of stop condition combobox is changed
        // Check the setting value and enable/disable the level comparison and the in range/out range comparison
        //================================================================================
        private void comboBox_StopTrigger_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            int select_trigger_type;    // Stop condition

            //----------------------------------------
            // Get the stop condition from combobox
            //----------------------------------------
            select_trigger_type = comboBox_StopTrigger_Type.SelectedIndex;
            //----------------------------------------
            // For level comparison
            //----------------------------------------
            if (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_LEVEL)
            {
                //----------------------------------------
                // Enable the level comparison
                //----------------------------------------
                textBox_StopTrigger_Level_SequenceNo.Enabled = true;
                textBox_StopTrigger_Level_BorderValue.Enabled = true;
                comboBox_StopTrigger_Level_Edge.Enabled = true;
                //----------------------------------------
                // Disable the in range/out range comparison
                //----------------------------------------
                textBox_StopTrigger_Range_SequenceNo.Enabled = false;
                textBox_StopTrigger_Range_Lower.Enabled = false;
                textBox_StopTrigger_Range_Upper.Enabled = false;
                textBox_StopTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StopTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StopTrigger_Time_Hour.Enabled = false;
                textBox_StopTrigger_Time_Minute.Enabled = false;
                textBox_StopTrigger_Time_Second.Enabled = false;
            }
            //----------------------------------------
            // For in range/out range comparison
            //----------------------------------------
            else if ((select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_INRANGE) || (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_OUTRANGE))
            {
                //----------------------------------------
                // Disable the level comparison
                //----------------------------------------
                textBox_StopTrigger_Level_SequenceNo.Enabled = false;
                textBox_StopTrigger_Level_BorderValue.Enabled = false;
                comboBox_StopTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Enable the in range/out range comparison
                //----------------------------------------
                textBox_StopTrigger_Range_SequenceNo.Enabled = true;
                textBox_StopTrigger_Range_Lower.Enabled = true;
                textBox_StopTrigger_Range_Upper.Enabled = true;
                textBox_StopTrigger_Range_StartTimes.Enabled = true;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StopTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StopTrigger_Time_Hour.Enabled = false;
                textBox_StopTrigger_Time_Minute.Enabled = false;
                textBox_StopTrigger_Time_Second.Enabled = false;
            }
            //----------------------------------------
            // For Time (Time(sec)
            //----------------------------------------
            else if (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_ELAPSED_TIME)
            {
                //----------------------------------------
                // Disable level comparison
                //----------------------------------------
                textBox_StopTrigger_Level_SequenceNo.Enabled = false;
                textBox_StopTrigger_Level_BorderValue.Enabled = false;
                comboBox_StopTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Disable in range/out range comparison
                //----------------------------------------
                textBox_StopTrigger_Range_SequenceNo.Enabled = false;
                textBox_StopTrigger_Range_Lower.Enabled = false;
                textBox_StopTrigger_Range_Upper.Enabled = false;
                textBox_StopTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Enable Time
                //----------------------------------------
                textBox_StopTrigger_Time_Time.Enabled = true;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StopTrigger_Time_Hour.Enabled = false;
                textBox_StopTrigger_Time_Minute.Enabled = false;
                textBox_StopTrigger_Time_Second.Enabled = false;
            }
            //----------------------------------------
            // For Time (Moment)
            //----------------------------------------
            else if (select_trigger_type == (int)CLoggerConst.LOGGER_PARAM_TRIGGER_CURRENT_TIME)
            {
                //----------------------------------------
                // Disable level comparison
                //----------------------------------------
                textBox_StopTrigger_Level_SequenceNo.Enabled = false;
                textBox_StopTrigger_Level_BorderValue.Enabled = false;
                comboBox_StopTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Disable in range/out range comparison
                //----------------------------------------
                textBox_StopTrigger_Range_SequenceNo.Enabled = false;
                textBox_StopTrigger_Range_Lower.Enabled = false;
                textBox_StopTrigger_Range_Upper.Enabled = false;
                textBox_StopTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StopTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Enable Moment
                //----------------------------------------
                textBox_StopTrigger_Time_Hour.Enabled = true;
                textBox_StopTrigger_Time_Minute.Enabled = true;
                textBox_StopTrigger_Time_Second.Enabled = true;
                //----------------------------------------
                // Other than level, range comparison, Time, Moment
                //----------------------------------------
            }
            else
            {
                //----------------------------------------
                // Disable the level comparison
                //----------------------------------------
                textBox_StopTrigger_Level_SequenceNo.Enabled = false;
                textBox_StopTrigger_Level_BorderValue.Enabled = false;
                comboBox_StopTrigger_Level_Edge.Enabled = false;
                //----------------------------------------
                // Disable the in range/out range comparison
                //----------------------------------------
                textBox_StopTrigger_Range_SequenceNo.Enabled = false;
                textBox_StopTrigger_Range_Lower.Enabled = false;
                textBox_StopTrigger_Range_Upper.Enabled = false;
                textBox_StopTrigger_Range_StartTimes.Enabled = false;
                //----------------------------------------
                // Disable Time
                //----------------------------------------
                textBox_StopTrigger_Time_Time.Enabled = false;
                //----------------------------------------
                // Disable Moment
                //----------------------------------------
                textBox_StopTrigger_Time_Hour.Enabled = false;
                textBox_StopTrigger_Time_Minute.Enabled = false;
                textBox_StopTrigger_Time_Second.Enabled = false;
            }
        }

        //================================================================================
        // It is the process when the value of sampling condition combobox is changed
        // Check the setting value and enable/disable the sampling times
        //================================================================================
        private void comboBox_SamplingTimes_SelectedIndexChanged(object sender, EventArgs e)
        {
            int sampling_times; // Sampling condition

            //----------------------------------------
            // Get the sampling condition from combobox
            //----------------------------------------
            sampling_times = comboBox_SamplingTimes.SelectedIndex;
            //----------------------------------------
            // For infinite
            //----------------------------------------
            if (sampling_times == (int)CLoggerConst.LOGGER_PARAM_DISABLE)
            {
                //----------------------------------------
                // Disable the sampling times
                //----------------------------------------
                textBox_SamplingTimes.Enabled = false;
            }
            //----------------------------------------
            // For finite
            //----------------------------------------
            else
            {
                //----------------------------------------
                // Enable the sampling times
                //----------------------------------------
                textBox_SamplingTimes.Enabled = true;
            }
        }

        //================================================================================
        // It is the process when the value of delay condition combobox is changed
        // Check the setting value and enable/disable the delay times
        //================================================================================
        private void comboBox_DelayTimes_SelectedIndexChanged(object sender, EventArgs e)
        {
            int delay_time; // Delay condition

            //----------------------------------------
            // Get the delay condition from combobox
            //----------------------------------------
            delay_time = comboBox_DelayTimes.SelectedIndex;
            //----------------------------------------
            // For disable
            //----------------------------------------
            if (delay_time == (int)CLoggerConst.LOGGER_PARAM_DISABLE)
            {
                //----------------------------------------
                // Disable the delay times
                //----------------------------------------
                textBox_DelayTimes.Enabled = false;
            }
            //----------------------------------------
            // For enable
            //----------------------------------------
            else
            {
                //----------------------------------------
                // Enable the delay times
                //----------------------------------------
                textBox_DelayTimes.Enabled = true;
            }
        }
    }
}
