﻿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 GraphOperation
{
    public partial class GraphOperation : Form
    {
        //----------------------------------------
        // クラスCLoggerインスタンス作成
        //----------------------------------------
        CLogger logger = new CLogger();
        //----------------------------------------
        // グローバル変数の宣言
        //----------------------------------------
        public short g_appid = 0;                             // アプリアクセス用ID

        public GraphOperation()
        {
            InitializeComponent();
        }

        //================================================================================
        // 初期設定
        //================================================================================
        private void Form1_Load(object sender, EventArgs e)
        {
            //----------------------------------------
            // ウィンドウサイズコンボボックスの作成
            //----------------------------------------
            comboBox_OpenMode.Items.Add("最小化");
            comboBox_OpenMode.Items.Add("通常");
            comboBox_OpenMode.Items.Add("最大化");
            //----------------------------------------
            // ウィンドウサイズコンボボックスの選択
            //----------------------------------------
            comboBox_OpenMode.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_WINDOW_OFF;
            //----------------------------------------
            // ウィンドウ操作コンボボックスの作成
            //----------------------------------------
            comboBox_Operation.Items.Add("新規作成");
            comboBox_Operation.Items.Add("閉じる");
            //----------------------------------------
            // ウィンドウ操作コンボボックスの選択
            //----------------------------------------
            comboBox_Operation.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_GRAPH_OPEN;
            //----------------------------------------
            // ウィンドウ操作対象コンボボックスの作成
            //----------------------------------------
            comboBox_Target.Items.Add("ファイル + グラフ");
            comboBox_Target.Items.Add("グラフ");
            //----------------------------------------
            // ウィンドウ操作対象コンボボックスの選択
            //----------------------------------------
            comboBox_Target.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_FILE;
            //----------------------------------------
            // 画面キャプチャ - 保存範囲コンボボックスの作成
            //----------------------------------------
            comboBox_ImageArea.Items.Add("アプリ全体");
            comboBox_ImageArea.Items.Add("グラフウィンドウのみ");
            //----------------------------------------
            // 画面キャプチャ - 保存範囲コンボボックスの選択
            //----------------------------------------
            comboBox_ImageArea.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AREA_ENTIRE;
            //----------------------------------------
            // グラフサイズ変更 - 軸コンボボックスの作成
            //----------------------------------------
            comboBox_ZoomAxis.Items.Add("X軸");
            comboBox_ZoomAxis.Items.Add("Y軸");
            //----------------------------------------
            // グラフサイズ変更 - 軸コンボボックスの選択
            //----------------------------------------
            comboBox_ZoomAxis.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXIS_X;
            //----------------------------------------
            // グラフサイズ変更 - 拡大縮小コンボボックスの作成
            //----------------------------------------
            comboBox_Zoom.Items.Add("拡大（2倍）");
            comboBox_Zoom.Items.Add("縮小（1/2倍）");
            //----------------------------------------
            // グラフサイズ変更 - 拡大縮小コンボボックスの選択
            //----------------------------------------
            comboBox_Zoom.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_ZOOM_IN;
            //----------------------------------------
            // グラフ移動 - 軸コンボボックスの作成
            //----------------------------------------
            comboBox_MoveAxis.Items.Add("X軸");
            comboBox_MoveAxis.Items.Add("Y軸");
            //----------------------------------------
            // グラフ移動 - 軸コンボボックスの選択
            //----------------------------------------
            comboBox_MoveAxis.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXIS_X;
            //----------------------------------------
            // グラフ移動 - 移動量表示を更新
            //----------------------------------------
            textBox_MoveDistance.Text = "1";
            //----------------------------------------
            // グラフ移動 - 移動方向コンボボックスの作成
            //----------------------------------------
            comboBox_MoveDirection.Items.Add("-");
            comboBox_MoveDirection.Items.Add("+");
            //----------------------------------------
            // グラフ移動 - 移動方向コンボボックスの選択
            //----------------------------------------
            comboBox_MoveDirection.SelectedIndex = 0;
            //----------------------------------------
            // チャネル情報 - シーケンス番号コンボボックスの作成
            //----------------------------------------
            comboBox_ChannelSequenceNo.Items.Add("0");
            comboBox_ChannelSequenceNo.Items.Add("1");
            comboBox_ChannelSequenceNo.Items.Add("2");
            comboBox_ChannelSequenceNo.Items.Add("3");
            //----------------------------------------
            // チャネル情報 - シーケンスコンボボックス番号の選択
            //----------------------------------------
            comboBox_ChannelSequenceNo.SelectedIndex = 0;
            //----------------------------------------
            // チャネル情報 - 表示コンボボックスの作成
            //----------------------------------------
            comboBox_ChannelEnable.Items.Add("無効");
            comboBox_ChannelEnable.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - 表示コンボボックスの選択
            //----------------------------------------
            comboBox_ChannelEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - アクティブ化コンボボックスの作成
            //----------------------------------------
            comboBox_ChannelActivate.Items.Add("無効");
            comboBox_ChannelActivate.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - アクティブ化コンボボックスの選択
            //----------------------------------------
            comboBox_ChannelActivate.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - ドット表示コンボボックスの作成
            //----------------------------------------
            comboBox_ChannelDisplayDot.Items.Add("無効");
            comboBox_ChannelDisplayDot.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - ドット表示コンボボックスの選択
            //----------------------------------------
            comboBox_ChannelDisplayDot.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - 時間軸種類コンボボックスの作成
            //----------------------------------------
            comboBox_GraphTimeUnit.Items.Add("絶対時間");
            comboBox_GraphTimeUnit.Items.Add("相対時間");
            //----------------------------------------
            // チャネル情報 - 時間軸種類コンボボックスの選択
            //----------------------------------------
            comboBox_GraphTimeUnit.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXISTYPE_ABSOLUTE;
            //----------------------------------------
            // チャネル情報 - 小数点以下桁数コンボボックスの作成
            //----------------------------------------
            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");
            //----------------------------------------
            // チャネル情報 - 小数点以下桁数コンボボックスの選択
            //----------------------------------------
            comboBox_GraphDigit.SelectedIndex = 0;
            //----------------------------------------
            // チャネル情報 - グラフの2分割表示コンボボックスの作成
            //----------------------------------------
            comboBox_GraphArea2Enable.Items.Add("無効");
            comboBox_GraphArea2Enable.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - グラフの2分割表示コンボボックスの選択
            //----------------------------------------
            comboBox_GraphArea2Enable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - Y軸拡大率表示コンボボックスの作成
            //----------------------------------------
            comboBox_GraphYaxisMagnificationEnable.Items.Add("無効");
            comboBox_GraphYaxisMagnificationEnable.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - Y軸拡大率表示コンボボックスの選択
            //----------------------------------------
            comboBox_GraphYaxisMagnificationEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - チャネル名ライブラリ表示コンボボックスの作成
            //----------------------------------------
            comboBox_GraphChannelDispEnable.Items.Add("無効");
            comboBox_GraphChannelDispEnable.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - チャネル名ライブラリ表示コンボボックスの選択
            //----------------------------------------
            comboBox_GraphChannelDispEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - グラフ自動スクロールコンボボックスの作成
            //----------------------------------------
            comboBox_GraphAutoScrollEnable.Items.Add("無効");
            comboBox_GraphAutoScrollEnable.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - グラフ自動スクロールコンボボックスの選択
            //----------------------------------------
            comboBox_GraphAutoScrollEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - グラフタイトルコンボボックスの作成
            //----------------------------------------
            comboBox_GraphLabelTargetItem.Items.Add("X軸");
            comboBox_GraphLabelTargetItem.Items.Add("Y軸");
            comboBox_GraphLabelTargetItem.Items.Add("グラフタイトル");
            //----------------------------------------
            // チャネル情報 - グラフタイトルコンボボックスの選択
            //----------------------------------------
            comboBox_GraphLabelTargetItem.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_AXIS_X;
            //----------------------------------------
            // チャネル情報 - 表示コンボボックスの作成
            //----------------------------------------
            comboBox_GraphLabelTitleEnable.Items.Add("無効");
            comboBox_GraphLabelTitleEnable.Items.Add("有効");
            //----------------------------------------
            // チャネル情報 - 表示コンボボックスの選択
            //----------------------------------------
            comboBox_GraphLabelTitleEnable.SelectedIndex = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
            //----------------------------------------
            // チャネル情報 - グラフタイトルを更新
            //----------------------------------------
            textBox_GraphLabelTitleText.Text = "グラフタイトル";
            return;
        }

        //================================================================================
        // LoggerOpenApplicationボタンをクリックした際の処理になります
        // アプリを起動し、アクセスを可能にします
        //================================================================================
        private void button_LoggerOpenApplication_Click(object sender, EventArgs e)
        {
            ushort  openmode;        // 画面サイズ
            int     ret;             // 戻り値取得用
            string  error_string;    // エラーコード文字列

            //----------------------------------------
            // コンボボックスから画面サイズを取得
            //----------------------------------------
            openmode = (ushort)comboBox_OpenMode.SelectedIndex;
            //----------------------------------------
            // アプリの初期化処理を行う
            //----------------------------------------
            ret = logger.OpenApplication("", out g_appid, openmode);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerOpenApplication = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // LoggerLoadDataFileボタンをクリックした際の処理になります
        // 収集したデータを読み込みます
        //================================================================================
        private void button_LoggerLoadDataFile_Click(object sender, EventArgs e)
        {
            string  filepath;        // ファイルパス
            int     ret;             // 戻り値取得用
            string  error_string;    // エラーコード文字列

            //----------------------------------------
            // テキストボックスから保存ファイルパスを取得
            //----------------------------------------
            filepath = textBox_DataFile.Text;
            //----------------------------------------
            // 収集したデータの読み込み
            //----------------------------------------
            ret = logger.LoadDataFile(g_appid, filepath);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerLoadDataFile = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // ...ボタンをクリックした際の処理になります 
        // データファイルを選択するダイアログを表示します
        //================================================================================
        private void button_DataFile_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // ファイル名が存在するかどうかをチェックしない
            //----------------------------------------
            openFileDialog1.CheckFileExists = false;
            //----------------------------------------
            // ファイルのパスが存在する場合は、ファイルのパスをダイアログの初期パスに設定します
            //----------------------------------------
            if (textBox_DataFile.Text.Length > 0)
            {
                openFileDialog1.InitialDirectory = textBox_DataFile.Text;
                openFileDialog1.FileName = openFileDialog1.SafeFileName;
            }
            //----------------------------------------
            // ファイルのパスが存在しない場合は、MyDocumentsをダイアログの初期パスに設定します
            //----------------------------------------
            else
            {
                openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog1.FileName = "";
            }
            //----------------------------------------
            // 選択したパスを表示
            //----------------------------------------
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox_DataFile.Text = System.IO.Path.GetFullPath(openFileDialog1.FileName);
            }
            return;
        }

        //================================================================================
        // LoggerGraphWindowOperationボタンをクリックした際の処理になります
        // ウィンドウの操作を行います
        //================================================================================
        private void button_LoggerGraphWindowOperation_Click(object sender, EventArgs e)
        {
            int     ret;             // 戻り値取得用
            string  error_string;    // エラーコード文字列
            ushort  target;          // 対象
            ushort  operation;       // 操作

            //----------------------------------------
            // コンボボックスから対象を取得
            //----------------------------------------
            target = (ushort)comboBox_Target.SelectedIndex;
            //----------------------------------------
            // コンボボックスからウィンドウの操作を取得
            //----------------------------------------
            operation = (ushort)comboBox_Operation.SelectedIndex;
            //----------------------------------------
            // ウィンドウの操作
            //----------------------------------------
            ret = logger.GraphWindowOperation(g_appid, operation, target, 0);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerGraphWindowOperation = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // LoggerCaptureScreenボタンをクリックした際の処理になります
        // 画像の保存を行います
        //================================================================================
        private void button_LoggerCaptureScreen_Click(object sender, EventArgs e)
        {
            string  filepath;        // ファイルパス
            int     ret;             // 戻り値取得用
            string  error_string;    // エラーコード文字列
            ushort  image_area;

            //----------------------------------------
            // テキストボックスから保存ファイルパスを取得
            //----------------------------------------
            filepath = textBox_CaptureFile.Text;
            //----------------------------------------
            // コンボボックスから保存範囲を取得
            //----------------------------------------
            image_area = (ushort)comboBox_ImageArea.SelectedIndex;
            //----------------------------------------
            // 画像の保存
            //----------------------------------------
            ret = logger.CaptureScreen(g_appid, 0, image_area, filepath);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerCaptureScreen = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // ...ボタンをクリックした際の処理になります 
        // 画像ファイルを選択するダイアログを表示します
        //================================================================================
        private void button_CaptureFile_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // ファイル名が存在するかどうかをチェックしない
            //----------------------------------------
            openFileDialog1.CheckFileExists = false;
            //----------------------------------------
            // ファイルのパスが存在する場合は、ファイルのパスをダイアログの初期パスに設定します
            //----------------------------------------
            if (textBox_CaptureFile.Text.Length > 0)
            {
                openFileDialog1.InitialDirectory = textBox_CaptureFile.Text;
                openFileDialog1.FileName = openFileDialog1.SafeFileName;
            }
            //----------------------------------------
            // ファイルのパスが存在しない場合は、MyDocumentsをダイアログの初期パスに設定します
            //----------------------------------------
            else
            {
                openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog1.FileName = "";
            }
            //----------------------------------------
            // 選択したパスを表示
            //----------------------------------------
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox_CaptureFile.Text = System.IO.Path.GetFullPath(openFileDialog1.FileName);
            }
            return;
        }

        //================================================================================
        // LoggerSetGraphZoomボタンをクリックした際の処理になります
        // グラフのズームを行います
        //================================================================================
        private void button_LoggerSetGraphZoom_Click(object sender, EventArgs e)
        {
            int     ret;             // 戻り値取得用
            string  error_string;    // エラーコード文字列
            ushort  axis;            // 軸
            ushort  zoom;            // 拡大縮小

            //----------------------------------------
            // コンボボックスから軸を取得
            //----------------------------------------
            axis = (ushort)comboBox_ZoomAxis.SelectedIndex;
            //----------------------------------------
            // コンボボックスから拡大縮小を取得
            //----------------------------------------
            zoom = (ushort)comboBox_Zoom.SelectedIndex;
            //----------------------------------------
            // グラフのズーム
            //----------------------------------------
            ret = logger.SetGraphZoom(g_appid, 0, axis, zoom);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraphZoom = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // LoggerMoveGraphPosボタンをクリックした際の処理になります
        // グラフの移動を行います
        //================================================================================
        private void button_LoggerMoveGraphPos_Click(object sender, EventArgs e)
        {
            int     ret;            // 戻り値取得用
            string  error_string;   // エラーコード文字列
            ushort  axis;           // 軸
            int     distance;       // 移動量
            int     direction;      // 移動方向
            uint    status;         // ステータス格納用

            //----------------------------------------
            // コンボボックスから軸を取得
            //----------------------------------------
            axis = (ushort)comboBox_MoveAxis.SelectedIndex;
            //----------------------------------------
            // テキストボックスから移動量を取得
            //----------------------------------------
            if(int.TryParse(textBox_MoveDistance.Text, out distance) != true)
            {
                textBox_ReturnNum.Text = string.Format("移動量取得異常");
                return;
            }
            //----------------------------------------
            // コンボボックスから移動方向を取得
            //----------------------------------------
            direction = (ushort)comboBox_MoveDirection.SelectedIndex;
            //----------------------------------------
            // -方向の場合、移動量をマイナス値に変換
            //----------------------------------------
            if (direction == 0)
            {
                distance = distance * (-1);
            }
            //----------------------------------------
            // グラフの移動
            //----------------------------------------
            ret = logger.MoveGraphPos(g_appid, 0, axis, distance, out status);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerMoveGraphPos = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // LoggerSetGraphChannelボタンをクリックした際の処理になります
        // チャネルの表示を切り替えます
        //================================================================================
        private void button_LoggerSetGraphChannel_Click(object sender, EventArgs e)
        {
            int     ret;             // 戻り値取得用
            string  error_string;    // エラーコード文字列
            ushort  sequence_no;     // シーケンス番号
            ushort  channel_enable;  // 表示／非表示
            ushort  activate;        // アクティブ化
            ushort  display_dot;     // ドット表示

            //----------------------------------------
            // コンボボックスからシーケンス番号を取得(index)
            //----------------------------------------
            sequence_no = (ushort)comboBox_ChannelSequenceNo.SelectedIndex;
            //----------------------------------------
            // コンボボックスから表示を取得
            //----------------------------------------
            channel_enable = (ushort)comboBox_ChannelEnable.SelectedIndex;
            //----------------------------------------
            // コンボボックスからアクティブ化を取得
            //----------------------------------------
            activate = (ushort)comboBox_ChannelActivate.SelectedIndex;
            //----------------------------------------
            // コンボボックスからドット表示を取得
            //----------------------------------------
            display_dot = (ushort)comboBox_ChannelDisplayDot.SelectedIndex;
            //----------------------------------------
            // チャネルの表示切り替え
            //----------------------------------------
            ret = logger.SetGraphChannel(g_appid, 0, sequence_no, channel_enable, activate, display_dot);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraphChannel = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // LoggerSetGraphボタンをクリックした際の処理になります
        // グラフウィンドウの詳細をセットします
        //================================================================================
        private void button_LoggerSetGraph_Click(object sender, EventArgs e)
        {
            int     ret;                            // 戻り値取得用
            string  error_string;                   // エラーコード文字列
            ushort  time_unit;                      // 時間軸種類の格納用
            ushort  digit;                          // 小数点以下桁数の格納用
            ushort  aria2_enable;                   // グラフの2分割表示の格納用 
            ushort  y_axis_magnification_enable;    // Y軸拡大表示の格納用
            ushort  channel_disp_enable;            // チャネル名ライブラリ表示の格納用
            ushort  auto_scroll_enable;             // グラフ自動スクロールの格納用

            //----------------------------------------
            // コンボボックスから時間軸種類を取得
            //----------------------------------------
            time_unit = (ushort)comboBox_GraphTimeUnit.SelectedIndex;
            //----------------------------------------
            // コンボボックスから小数点以下桁数を取得
            //----------------------------------------
            digit = (ushort)comboBox_GraphDigit.SelectedIndex;
            //----------------------------------------
            // コンボボックスからグラフの2分割表示を取得
            //----------------------------------------
            aria2_enable = (ushort)comboBox_GraphArea2Enable.SelectedIndex;
            //----------------------------------------
            // コンボボックスからY軸拡大表示を取得
            //----------------------------------------
            y_axis_magnification_enable = (ushort)comboBox_GraphYaxisMagnificationEnable.SelectedIndex;
            //----------------------------------------
            // コンボボックスからチャネル名ライブラリ表示を取得
            //----------------------------------------
            channel_disp_enable = (ushort)comboBox_GraphChannelDispEnable.SelectedIndex;
            //----------------------------------------
            // コンボボックスからグラフ自動スクロールを取得
            //----------------------------------------
            auto_scroll_enable = (ushort)comboBox_GraphAutoScrollEnable.SelectedIndex;
            //----------------------------------------
            // グラフウィンドウの詳細をセット
            //----------------------------------------
            ret = logger.SetGraph(g_appid, 0, time_unit, digit, aria2_enable, y_axis_magnification_enable, channel_disp_enable, auto_scroll_enable);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraph = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // LoggerSetGraphLabelTextボタンをクリックした際の処理になります
        // グラフウィンドウの詳細をセットします
        //================================================================================
        private void button_LoggerSetGraphLabelText_Click(object sender, EventArgs e)
        {
            string  title;          // タイトル
            int     ret;            // 戻り値取得用
            string  error_string;   // エラーコード文字列
            ushort  target_item;    // タイトル軸の格納用
            ushort  title_enable;   // 表示の格納用

            //----------------------------------------
            // コンボボックスからタイトル軸を取得
            //----------------------------------------
            target_item = (ushort)comboBox_GraphLabelTargetItem.SelectedIndex;
            //----------------------------------------
            // コンボボックスから表示を取得
            //----------------------------------------
            title_enable = (ushort)comboBox_GraphLabelTitleEnable.SelectedIndex;
            //----------------------------------------
            // テキストボックスからタイトルを取得
            //----------------------------------------
            title = textBox_GraphLabelTitleText.Text;
            //----------------------------------------
            // グラフウィンドウ詳細をセット
            //----------------------------------------
            ret = logger.SetGraphLabelText(g_appid, 0, target_item, title_enable, title);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerSetGraphLabelText = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // LoggerCloseApplicationボタンをクリックした際の処理になります
        // アプリを停止し、アクセスを不可にします
        //================================================================================
        private void button_LoggerCloseApplication_Click(object sender, EventArgs e)
        {
            uint status = 0;        // ステータス
            int ret;                // 戻り値取得用
            string error_string;    // エラーコード文字列
            string status_string;   //ステータス文字列

            //----------------------------------------
            // アプリ停止し、アクセス不可
            //----------------------------------------
            ret = logger.CloseApplication(g_appid, out status);
            //----------------------------------------
            // エラー文字列取得
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // ステータス文字列取得
            //----------------------------------------
            switch (status)
            {
                case (uint)CLoggerConst.LOGGER_STATUS_SUCCESS:
                    status_string = "正常終了";
                    break;
                case (uint)CLoggerConst.LOGGER_STATUS_FAILURE:
                    status_string = "C-LOGGER終了エラー";
                    break;
                default:
                    status_string = "不明なエラー";
                    break;
            }
            //----------------------------------------
            // エラーコード,メッセージを表示
            //----------------------------------------
            textBox_ReturnNum.Text = string.Format("LoggerCloseApplication = {0} : {1} \r\nstatus = {2} : {3}", ret, error_string, status, status_string);
            return;
        }

        //================================================================================
        // 閉じるボタンをクリックした際の処理になります
        // 
        //================================================================================
        private void button_Close_Click(object sender, EventArgs e)
        {
            uint    status          = 0;      // ステータス

            //----------------------------------------
            // ファイルを閉じる(先にC-LOGGERが終了することを考慮し、結果を確認しない)
            //----------------------------------------
            logger.GraphWindowOperation(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_GRAPH_CLOSE, (ushort)CLoggerConst.LOGGER_PARAM_FILE, 0);
            //----------------------------------------
            // アプリ停止し、アクセス不可
            //----------------------------------------
            logger.CloseApplication(g_appid, out status);
            //----------------------------------------
            // ダイアログを終了する
            //----------------------------------------
            this.Close();
        }
    }
}
