예제 #1
0
        /// <summary>
        /// 静的な設定
        /// </summary>
        /// <param 読み込んだファイルデータ="inData"></param>
        public static void OneTimeSetting(string inData)
        {
            string[] Data = inData.Split('\n');

            //使用時間と最大値の定義と配列の初期化
            ReadValue_MaxTimeTable   = int.Parse(Data[FindIndex(Data, DefaultData.CHECK_STR[1]) + 1]);
            ReadValue_StartTime      = new string[ReadValue_MaxTimeTable];
            ReadValue_EndedTime      = new string[ReadValue_MaxTimeTable];
            MakeValue_StartTimeValue = new int[ReadValue_MaxTimeTable];
            MakeValue_EndedTimeValue = new int[ReadValue_MaxTimeTable];

            //使用時間の定義
            for (int i = 0; i < ReadValue_MaxTimeTable; i++)
            {
                ReadValue_StartTime[i] = Data[FindIndex(Data, DefaultData.CHECK_STR[3]) + 1 + i];
                ReadValue_EndedTime[i] = Data[FindIndex(Data, DefaultData.CHECK_STR[5]) + 1 + i];
            }

            //チェックデータの作成
            int x = FindIndex(Data, DefaultData.CHECK_STR[7]) + 1;

            for (int i = 0; i < MAX_PERIOD; i++)
            {
                string weekData = Data[x + i];

                for (int j = 0; j < MAX_WEEK; j++)
                {
                    int val = int.Parse(weekData[j].ToString());
                    if (val == 0)
                    {
                        ReadValue_DateSetData[i, j] = 0;
                    }
                    if (val == 1)
                    {
                        ReadValue_DateSetData[i, j] = 1;
                    }
                    if (ReadValue_MaxTimeTable <= i)
                    {
                        ReadValue_DateSetData[i, j] = 2;
                    }
                }
            }

            //文字列表記の時間を秒数に直して配列に格納
            for (int i = 0; i < ReadValue_MaxTimeTable; i++)
            {
                int j = Form1.ConvertToSeconds(ReadValue_StartTime[i]);
                MakeValue_StartTimeValue[i] = j;
                MakeValue_EndedTimeValue[i] = Form1.ConvertToSeconds(ReadValue_EndedTime[i]);
            }

            MoreTimeSetting();
        }
예제 #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);
                }
            }
        }