Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            //設定と初期化
            SettingValue.OneTimeSetting(FileProccesing.FileRead());

            //1秒ごとに呼び出すイベントを作るスレッドの定義
            eventHandleThread = new Thread(() =>
            {
                DateTime dt, dtbf = DateTime.Now;
                while (true)
                {
                    dt = DateTime.Now;
                    if (dt != dtbf)
                    {
                        Invoke(new everySeconds(everySeconds_event));
                        dtbf = dt;
                    }
                    Thread.Sleep(1);
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// セーブ処理
        /// </summary>
        /// <param name="close"></param>
        /// <returns></returns>
        private bool Save()
        {
            InValue();

            int Value_MaxPeriod;

            string[] SaveDateData_Start;
            string[] SaveDateData_Ended;
            string[] periodGraph = new string[SettingValue.MAX_PERIOD];
            string   saveData    = string.Empty;

            //右下チェックボックスを調べて代入、失敗したらfalseを返す
            {
                //後ろからFalseにどこから変わるか調べる
                int checkFromFront = 10, checkFromButtom = -1;
                for (int i = SettingValue.MAX_PERIOD; i > 0; i--)
                {
                    if (FormControlCheckBoxWeekSet[i - 1].Checked)
                    {
                        checkFromButtom = i;
                        break;
                    }
                }
                //前からTureにどこから変わるか調べる
                for (int i = 0; i < SettingValue.MAX_PERIOD; i++)
                {
                    if (!FormControlCheckBoxWeekSet[i].Checked)
                    {
                        checkFromFront = i;
                        break;
                    }
                }
                //1からつけてなかったり間が空いていたら警告してFlaseを返す
                if (checkFromButtom == checkFromFront)
                {
                    Value_MaxPeriod = checkFromButtom;
                }
                else
                {
                    string waringText;
                    if (checkFromButtom == -1)
                    {
                        waringText = "Please select one or more.";
                    }
                    else
                    {
                        waringText = "Please do not leave during the check.";
                    }
                    MessageBox.Show(waringText, "Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
            }
            //時間が昇順か調べて代入処理、失敗したらFalseを返す
            {
                SaveDateData_Start = new string[Value_MaxPeriod];
                SaveDateData_Ended = new string[Value_MaxPeriod];
                int   MaxPeriodSum = Value_MaxPeriod * 2;
                int[] check        = new int[MaxPeriodSum];
                for (int i = 0; i < MaxPeriodSum; i++)
                {
                    if (i % 2 == 0)
                    {
                        check[i] = Form1.ConvertToSeconds(FormControlDateTimePickerStartTime[i / 2].Value.ToString(SettingValue.DATE_ENCODING));
                    }
                    else
                    {
                        check[i] = Form1.ConvertToSeconds(FormControlDateTimePickerEndedTime[(i - 1) / 2].Value.ToString(SettingValue.DATE_ENCODING));
                    }
                }
                var j = check[0];
                for (int i = 1; i < MaxPeriodSum; i++)
                {
                    if (j > check[i] - SettingValue.LEFT_DISPLAY_TIME)
                    {
                        MessageBox.Show("Set the time in ascending order. and leave at least " + SettingValue.LEFT_DISPLAY_TIME.ToString() + " seconds",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(false);
                    }
                    j = check[i];
                }
                for (int i = 0; i < Value_MaxPeriod; i++)
                {
                    SaveDateData_Start[i] = FormControlDateTimePickerStartTime[i].Value.ToString(SettingValue.DATE_ENCODING);
                    SaveDateData_Ended[i] = FormControlDateTimePickerEndedTime[i].Value.ToString(SettingValue.DATE_ENCODING);
                }
            }
            //グラフデータをまとめる
            {
                for (int i = 0; i < SettingValue.MAX_PERIOD; i++)
                {
                    for (int j = 0; j < SettingValue.MAX_WEEK; j++)
                    {
                        periodGraph[i] +=
                            FormControlCheckBoxGraphSet[i, j].Enabled ? FormControlCheckBoxGraphSet[i, j].Checked ? "1" : "0" : "2";
                    }
                }
            }
            //ファイル書き出せる形に成形
            {
                for (int i = 0; i < DefaultData.CHECK_STR.Length; i++)
                {
                    string sum = DefaultData.CHECK_STR[i] + "\n";

                    switch (i)
                    {
                    case 0:
                    case 2:
                    case 4:
                    case 6:
                        sum += "\n";
                        break;

                    case 1:
                        sum += Value_MaxPeriod.ToString() + "\n";
                        break;

                    case 3:
                        sum += StringSum(SaveDateData_Start);
                        break;

                    case 5:
                        sum += StringSum(SaveDateData_Ended);
                        break;

                    case 7:
                        sum += StringSum(periodGraph);
                        break;

                    case 8:
                    case 9:
                        break;
                    }
                    saveData += sum;
                }
            }
            //ファイルに上書き
            {
                if (MessageBox.Show("Do you want to save?", "Infomation",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    using (var sr = new StreamWriter(SettingValue.DATA_FILE_PATH, false, SettingValue.ENCODING))
                    {
                        sr.Write(saveData);
                    }
                    SettingValue.OneTimeSetting(FileProccesing.FileRead());
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }