using CLoggerCs;

namespace GraphOperation
{
    public partial class Form1 : Form
    {
        //----------------------------------------
        // Create instance CLogger class
        //----------------------------------------
        CLogger logger = new CLogger();
        //----------------------------------------
        // Global variable declaration
        //----------------------------------------
        public short g_appid = 0;                             // App access ID

        public Form1()
        {
            InitializeComponent();
        }

        //================================================================================
        // Initial settings
        //================================================================================
        private void Form1_Load(object sender, EventArgs e)
        {
            //----------------------------------------
            // Create the combobox for window size
            //----------------------------------------
            comboBox_OpenMode.Items.Add("Minimize");
            comboBox_OpenMode.Items.Add("Normal");
            comboBox_OpenMode.Items.Add("Maximize");
            //----------------------------------------
            // Window size combobox selection
            //----------------------------------------
            comboBox_OpenMode.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_WINDOW_OFF;
            //----------------------------------------
            // Create the combobox for window operation
            //----------------------------------------
            comboBox_Operation.Items.Add("New");
            comboBox_Operation.Items.Add("Close");
            //----------------------------------------
            // Window operation combobox selection
            //----------------------------------------
            comboBox_Operation.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_GRAPH_OPEN;
            //----------------------------------------
            // Create the combobox for window operation target
            //----------------------------------------
            comboBox_Target.Items.Add("File and Graph");
            comboBox_Target.Items.Add("Graph");
            //----------------------------------------
            // Window operation target combobox selection
            //----------------------------------------
            comboBox_Target.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_FILE;
            //----------------------------------------
            // Screen Capture - Create the combobox for save range
            //----------------------------------------
            comboBox_ImageArea.Items.Add("Entire");
            comboBox_ImageArea.Items.Add("YT Graph");
            //----------------------------------------
            // Screen Capture - Save range combobox selection
            //----------------------------------------
            comboBox_ImageArea.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AREA_ENTIRE;
            //----------------------------------------
            // Graph Resize - Create the combobox for axis
            //----------------------------------------
            comboBox_ZoomAxis.Items.Add("X-axis");
            comboBox_ZoomAxis.Items.Add("Y-axis");
            //----------------------------------------
            // Graph Resize - Axis combobox selection
            //----------------------------------------
            comboBox_ZoomAxis.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXIS_X;
            //----------------------------------------
            // Graph Resize - Create the combobox for zoom
            //----------------------------------------
            comboBox_Zoom.Items.Add("Zoom in(2x)");
            comboBox_Zoom.Items.Add("Zoom out(x/2)");
            //----------------------------------------
            // Graph Resize - Zoom combobox selection
            //----------------------------------------
            comboBox_Zoom.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_ZOOM_IN;
            //----------------------------------------
            // Graph Movement - Create the combobox for axis
            //----------------------------------------
            comboBox_MoveAxis.Items.Add("X-axis");
            comboBox_MoveAxis.Items.Add("Y-axis");
            //----------------------------------------
            // Graph Movement - Axis combobox selection
            //----------------------------------------
            comboBox_MoveAxis.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXIS_X;
            //----------------------------------------
            // Graph Movement - Updated movement amount display
            //----------------------------------------
            textBox_MoveDistance.Text = "1";
            //----------------------------------------
            // Graph Movement - Create the combobox for movement direction
            //----------------------------------------
            comboBox_MoveDirection.Items.Add("-");
            comboBox_MoveDirection.Items.Add("+");
            //----------------------------------------
            // Graph Movement - Movement direction combobox selection
            //----------------------------------------
            comboBox_MoveDirection.SelectedIndex = 0;
            //----------------------------------------
            // Channel Information - Create the combobox for sequence number
            //----------------------------------------
            comboBox_ChannelSequenceNo.Items.Add("0");
            comboBox_ChannelSequenceNo.Items.Add("1");
            comboBox_ChannelSequenceNo.Items.Add("2");
            comboBox_ChannelSequenceNo.Items.Add("3");
            //----------------------------------------
            // Channel Information - Sequence number combobox selection
            //----------------------------------------
            comboBox_ChannelSequenceNo.SelectedIndex = 0;
            //----------------------------------------
            // Channel Information - Create the combobox for display
            //----------------------------------------
            comboBox_ChannelEnable.Items.Add("Disable");
            comboBox_ChannelEnable.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - Display combobox selection
            //----------------------------------------
            comboBox_ChannelEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Create the combobox for Activation
            //----------------------------------------
            comboBox_ChannelActivate.Items.Add("Disable");
            comboBox_ChannelActivate.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - Activation combobox selection
            //----------------------------------------
            comboBox_ChannelActivate.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Create the combobox for dotted
            //----------------------------------------
            comboBox_ChannelDisplayDot.Items.Add("Disable");
            comboBox_ChannelDisplayDot.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - Dotted combobox selection
            //----------------------------------------
            comboBox_ChannelDisplayDot.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Create the combobox for time axis type
            //----------------------------------------
            comboBox_GraphTimeUnit.Items.Add("Absolute time");
            comboBox_GraphTimeUnit.Items.Add("Relative time");
            //----------------------------------------
            // Channel Information - Time axis type combobox selection
            //----------------------------------------
            comboBox_GraphTimeUnit.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXISTYPE_ABSOLUTE;
            //----------------------------------------
            // Channel Information - Create the combobox for decimal places
            //----------------------------------------
            comboBox_GraphDigit.Items.Add("0");
            comboBox_GraphDigit.Items.Add("1");
            comboBox_GraphDigit.Items.Add("2");
            comboBox_GraphDigit.Items.Add("3");
            comboBox_GraphDigit.Items.Add("4");
            comboBox_GraphDigit.Items.Add("5");
            //----------------------------------------
            // Channel Information - Decimal places combobox selection
            //----------------------------------------
            comboBox_GraphDigit.SelectedIndex = 0;
            //----------------------------------------
            // Channel Information - Create the combobox for 2-split window
            //----------------------------------------
            comboBox_GraphArea2Enable.Items.Add("Disable");
            comboBox_GraphArea2Enable.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - 2-split window combobox selection
            //----------------------------------------
            comboBox_GraphArea2Enable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Create the combobox for Y-axis magnification display
            //----------------------------------------
            comboBox_GraphYaxisMagnificationEnable.Items.Add("Disable");
            comboBox_GraphYaxisMagnificationEnable.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - Y-axis magnification display combobox selection
            //----------------------------------------
            comboBox_GraphYaxisMagnificationEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Create the combobox for channel name library display
            //----------------------------------------
            comboBox_GraphChannelDispEnable.Items.Add("Disable");
            comboBox_GraphChannelDispEnable.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - Channel name library display combobox selection
            //----------------------------------------
            comboBox_GraphChannelDispEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Create the combobox for graph auto-scroll
            //----------------------------------------
            comboBox_GraphAutoScrollEnable.Items.Add("Disable");
            comboBox_GraphAutoScrollEnable.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - Graph auto-scroll combobox selection
            //----------------------------------------
            comboBox_GraphAutoScrollEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Create the combobox for graph title
            //----------------------------------------
            comboBox_GraphLabelTargetItem.Items.Add("X-axis");
            comboBox_GraphLabelTargetItem.Items.Add("Y-axis");
            comboBox_GraphLabelTargetItem.Items.Add("Graph title");
            //----------------------------------------
            // Channel Information - Graph title combobox selection
            //----------------------------------------
            comboBox_GraphLabelTargetItem.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXIS_X;
            //----------------------------------------
            // Channel Information - Create the combobox for display
            //----------------------------------------
            comboBox_GraphLabelTitleEnable.Items.Add("Disable");
            comboBox_GraphLabelTitleEnable.Items.Add("Enable");
            //----------------------------------------
            // Channel Information - Display combobox selection
            //----------------------------------------
            comboBox_GraphLabelTitleEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // Channel Information - Update graph title
            //----------------------------------------
            textBox_GraphLabelTitleText.Text = "Graph title";
            return;
        }

        //================================================================================
        // This is the process that occurs when you click the LoggerLoadDataFile button
        // Launch the app and enable access
        //================================================================================
        private void button_LoggerOpenApplication_Click(object sender, EventArgs e)
        {
            ushort openmode;        // Screen size
            int    ret;             // Error code string
            string error_string;    // For return code

            //----------------------------------------
            // Get screen size from combobox
            //----------------------------------------
            openmode = (ushort)comboBox_OpenMode.SelectedIndex;
            //----------------------------------------
            // Initialize the app
            //----------------------------------------
            ret = logger.OpenApplication("", out g_appid, openmode);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerOpenApplication = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when you click the LoggerLoadDataFile button
        // Read the collected data
        //================================================================================
        private void button_LoggerLoadDataFile_Click(object sender, EventArgs e)
        {
            string filepath;        // File path
            int    ret;             // Error code string
            string error_string;    // For return code

            //----------------------------------------
            // Get file path from text box
            //----------------------------------------
            filepath = textBox_DataFile.Text;
            //----------------------------------------
            // Loading the collected data
            //----------------------------------------
            ret = logger.LoadDataFile(g_appid, filepath);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerLoadDataFile = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when you click the ... button
        // Displays the dialog to select the data file
        //================================================================================
        private void button_DataFile_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // Don't check if filename exists
            //----------------------------------------
            openFileDialog1.CheckFileExists = false;
            //----------------------------------------
            // If the path exists, set the current path to the initial path of dialog
            //----------------------------------------
            if (textBox_DataFile.Text.Length > 0)
            {
                openFileDialog1.InitialDirectory = textBox_DataFile.Text;
                openFileDialog1.FileName = openFileDialog1.SafeFileName;
            }
            //----------------------------------------
            // If the path not exists, set the MyDocuments path to the initial path of dialog
            //----------------------------------------
            else
            {
                openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog1.FileName = "";
            }
            //----------------------------------------
            // Display the selected path
            //----------------------------------------
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox_DataFile.Text = System.IO.Path.GetFullPath(openFileDialog1.FileName);
            }
            return;
        }

        //================================================================================
        // This is the process when the LoggerGraphWindowOperation button is clicked
        // Operate the window
        //================================================================================
        private void button_LoggerGraphWindowOperation_Click(object sender, EventArgs e)
        {
            int    ret;             // Error code string
            string error_string;    // For return code
            ushort target;          // For storing the target
            ushort operation;       // For storing window operations

            //----------------------------------------
            // Get target from combobox
            //----------------------------------------
            target = (ushort)comboBox_Target.SelectedIndex;
            //----------------------------------------
            // Get window operation from combobox
            //----------------------------------------
            operation = (ushort)comboBox_Operation.SelectedIndex;
            //----------------------------------------
            // Window operations
            //----------------------------------------
            ret = logger.GraphWindowOperation(g_appid, operation, target, 0);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerGraphWindowOperation = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when you click the LoggerCaptureScreen button
        // Save the image
        //================================================================================
        private void button_LoggerCaptureScreen_Click(object sender, EventArgs e)
        {
            string filepath;        // File path
            int    ret;             // Error code string
            string error_string;    // For return code
            ushort image_area;      // For storing the storage range

            //----------------------------------------
            // Get file path from textbox
            //----------------------------------------
            filepath = textBox_CaptureFile.Text;
            //----------------------------------------
            // Get the saved range from the combobox
            //----------------------------------------
            image_area = (ushort)comboBox_ImageArea.SelectedIndex;
            //----------------------------------------
            // Save image
            //----------------------------------------
            ret = logger.CaptureScreen(g_appid, 0, image_area, filepath);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerCaptureScreen = {0} : {1} ", ret, error_string);
            return;
        }
        
        //================================================================================
        // This is the process that occurs when you click the ... button
        // Displays the dialog to select the image file
        //================================================================================
        private void button_CaptureFile_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // Don't check if filename exists
            //----------------------------------------
            openFileDialog1.CheckFileExists = false;
            //----------------------------------------
            // If the path exists, set the current path to the initial path of dialog
            //----------------------------------------
            if (textBox_CaptureFile.Text.Length > 0)
            {
                openFileDialog1.InitialDirectory = textBox_CaptureFile.Text;
                openFileDialog1.FileName = openFileDialog1.SafeFileName;
            }
            //----------------------------------------
            // If the path not exists, set the MyDocuments path to the initial path of dialog
            //----------------------------------------
            else
            {
                openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog1.FileName = "";
            }
            //----------------------------------------
            // Display the selected path
            //----------------------------------------
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox_CaptureFile.Text = System.IO.Path.GetFullPath(openFileDialog1.FileName);
            }
            return;
        }

        //================================================================================
        // This is the process that occurs when the LoggerSetGraphZoom button is clicked
        // Zoom the graph
        //================================================================================
        private void button_LoggerSetGraphZoom_Click(object sender, EventArgs e)
        {
            int    ret;             // Error code string
            string error_string;    // For return code
            ushort axis;            // For storing the axis
            ushort zoom;            // For scaling storage

            //----------------------------------------
            // Get axis from combobox
            //----------------------------------------
            axis = (ushort)comboBox_ZoomAxis.SelectedIndex;
            //----------------------------------------
            // Get scaling from combobox
            //----------------------------------------
            zoom = (ushort)comboBox_Zoom.SelectedIndex;
            //----------------------------------------
            // Zoom the graph
            //----------------------------------------
            ret = logger.SetGraphZoom(g_appid, 0, axis, zoom);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraphZoom = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when the LoggerMoveGraphPos button is clicked
        // Move the graph
        //================================================================================
        private void button_LoggerMoveGraphPos_Click(object sender, EventArgs e)
        {
            int    ret;            // Error code string
            string error_string;   // For return code
            ushort axis;           // For storing the axis
            int    distance;       // For storing movement amount
            int    direction;      // For storing movement direction
            uint   status;         // For storing status

            //----------------------------------------
            // Get axis from combobox
            //----------------------------------------
            axis = (ushort)comboBox_MoveAxis.SelectedIndex;
            //----------------------------------------
            // Get the movement amount from the textbox
            //----------------------------------------
            if (int.TryParse(textBox_MoveDistance.Text, out distance) != true)
            {
                textBox_ReturnNum.Text = string.Format("Movement amount acquisition error");
                return;
            }
            //----------------------------------------
            // Get the movement direction from the combobox
            //----------------------------------------
            direction = (ushort)comboBox_MoveDirection.SelectedIndex;
            //----------------------------------------
            // In the negative direction, the movement amount is converted to a negative value
            //----------------------------------------
            if (direction == 0)
            {
                distance = distance * (-1);
            }
            //----------------------------------------
            // Move the graph
            //----------------------------------------
            ret = logger.MoveGraphPos(g_appid, 0, axis, distance, out status);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerMoveGraphPos = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when you click the LoggerSetGraphChannel button
        // Switch channel display
        //================================================================================
        private void button_LoggerSetGraphChannel_Click(object sender, EventArgs e)
        {
            int    ret;             // Error code string
            string error_string;    // For return code
            ushort sequence_no;     // For storing sequence number
            ushort channel_enable;  // For storing the display
            ushort activate;        // For storing activation
            ushort display_dot;     // For storing dot display

            //----------------------------------------
            // Get the sequence number from the combobox (index)
            //----------------------------------------
            sequence_no = (ushort)comboBox_ChannelSequenceNo.SelectedIndex;
            //----------------------------------------
            // Get the display from the combobox
            //----------------------------------------
            channel_enable = (ushort)comboBox_ChannelEnable.SelectedIndex;
            //----------------------------------------
            // Get activation from combobox
            //----------------------------------------
            activate = (ushort)comboBox_ChannelActivate.SelectedIndex;
            //----------------------------------------
            // Get dot display from combobox
            //----------------------------------------
            display_dot = (ushort)comboBox_ChannelDisplayDot.SelectedIndex;
            //----------------------------------------
            // Switch channel display
            //----------------------------------------
            ret = logger.SetGraphChannel(g_appid, 0, sequence_no, channel_enable, activate, display_dot);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraphChannel = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when you click the LoggerSetGraph button
        // Set the graph window detail
        //================================================================================
        private void button_LoggerSetGraph_Click(object sender, EventArgs e)
        {
            int    ret;                            // Error code string
            string error_string;                   // For return code
            ushort time_unit;                      // For storing time axis types
            ushort digit;                          // For storing the number of decimal places
            ushort aria2_enable;                   // For storing 2-split graph displays
            ushort y_axis_magnification_enable;    // For storing the Y-axis magnification display
            ushort channel_disp_enable;            // For storing channel name library displays
            ushort auto_scroll_enable;             // For storing automatic graph scrolling

            //----------------------------------------
            // Get the time axis type from the combobox
            //----------------------------------------
            time_unit = (ushort)comboBox_GraphTimeUnit.SelectedIndex;
            //----------------------------------------
            // Get decimal places from combobox
            //----------------------------------------
            digit = (ushort)comboBox_GraphDigit.SelectedIndex;
            //----------------------------------------
            // Get 2-split graph display from combobox
            //----------------------------------------
            aria2_enable = (ushort)comboBox_GraphArea2Enable.SelectedIndex;
            //----------------------------------------
            // Get Y-axis zoom from combobox
            //----------------------------------------
            y_axis_magnification_enable = (ushort)comboBox_GraphYaxisMagnificationEnable.SelectedIndex;
            //----------------------------------------
            // Get channel name library display from combobox
            //----------------------------------------
            channel_disp_enable = (ushort)comboBox_GraphChannelDispEnable.SelectedIndex;
            //----------------------------------------
            // Get graph autoscroll from combobox
            //----------------------------------------
            auto_scroll_enable = (ushort)comboBox_GraphAutoScrollEnable.SelectedIndex;
            //----------------------------------------
            // Set graph window detail
            //----------------------------------------
            ret = logger.SetGraph(g_appid, 0, time_unit, digit, aria2_enable, y_axis_magnification_enable, channel_disp_enable, auto_scroll_enable);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraph = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when you click the LoggerSetGraphLabelText button
        // 
        //================================================================================
        private void button_LoggerSetGraphLabelText_Click(object sender, EventArgs e)
        {
            string title;          // Title
            int    ret;            // Error code string
            string error_string;   // For return code
            ushort target_item;    // For temporary text storage
            ushort title_enable;   // For storing the display

            //----------------------------------------
            // Get title axis from combobox
            //----------------------------------------
            target_item = (ushort)comboBox_GraphLabelTargetItem.SelectedIndex;
            //----------------------------------------
            // Get the display from the combobox
            //----------------------------------------
            title_enable = (ushort)comboBox_GraphLabelTitleEnable.SelectedIndex;
            //----------------------------------------
            // Get title from textbox
            //----------------------------------------
            title = textBox_GraphLabelTitleText.Text;
            //----------------------------------------
            // Set graph window detail
            //----------------------------------------
            ret = logger.SetGraphLabelText(g_appid, 0, target_item, title_enable, title);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraphLabelText = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when the LoggerCloseApplication button is clicked
        // Stop the app and disable access
        //================================================================================
        private void button_LoggerCloseApplication_Click(object sender, EventArgs e)
        {
            uint   status = 0;       // For storing status
            int    ret;              // Error code string
            string error_string;     // For return code
            string status_string;    // Status display string

            //----------------------------------------
            // The app is stopped and cannot be accessed
            //----------------------------------------
            ret = logger.CloseApplication(g_appid, out status);
            //----------------------------------------
            // Get error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Get status string
            //----------------------------------------
            switch (status)
            {
                case (uint)CLoggerConst.LOGGER_STATUS_SUCCESS:
                    status_string = "Successful completion";
                    break;
                case (uint)CLoggerConst.LOGGER_STATUS_FAILURE:
                    status_string = "C-LOGGER exit error";
                    break;
                default:
                    status_string = "Unknown status";
                    break;
            }
            //----------------------------------------
            // Display error code and message
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerCloseApplication = {0} : {1} \r\nstatus = {2} : {3}", ret, error_string, status, status_string);
            return;
        }

        //================================================================================
        // This is the process that occurs when the Close button is clicked
        // Terminate the application
        //================================================================================
        private void button_Close_Click(object sender, EventArgs e)
        {
            uint status = 0;      // For status storage

            //----------------------------------------
            // Close the file(Considering that C-LOGGER may have exited, do not check the result)
            //----------------------------------------
            logger.GraphWindowOperation(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_GRAPH_CLOSE, (ushort)CLoggerConst.LOGGER_PARAM_FILE, 0);
            //----------------------------------------
            // Stop the application and disable access
            //----------------------------------------
            logger.CloseApplication(g_appid, out status);
            //----------------------------------------
            // Exit the dialog
            //----------------------------------------
            this.Close();
        }
    }
}
