Пример #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);
                }
            });
        }
Пример #2
0
        /// <summary>
        /// 毎秒実行される関数
        /// </summary>
        private void everySeconds_event()
        {
            SettingValue.MoreTimeSetting();
            //ローカル変数の定義
            DateTime NowTimeRaw     = DateTime.Now;
            string   NowTimeString  = NowTimeRaw.ToString(SettingValue.DATE_ENCODING);
            int      NowTimeSeconds = ConvertToSeconds(NowTimeString);
            int      NowTimePeriod  = CheckPeriodNumber(NowTimeRaw, SettingValue.MakeValue_StartTimeValue, SettingValue.MakeValue_EndedTimeValue);

            int[]    TodayPeriodData;
            string[] TodayStartTime;
            string[] TodayEndedTime;
            int[]    TodayStartTimeValue;
            int[]    TodayEndedTimeValue;
            int[]    TodayLeftTimeValue;
            int      TodayNowPeriod;
            int      TodayNowLeftPeriod;

            string SettingFrontText;

            int[]    SettingProgressBar      = new int[3];
            string[] SettingButtomText       = new string[3];
            Color[]  SettingProgressBarColor = new Color[2];

            int count = 0;

            //今日の曜日の時間割データを読み込む
            TodayPeriodData = new int[SettingValue.MAX_PERIOD];
            for (int i = 0; i < SettingValue.MAX_PERIOD; i++)
            {
                TodayPeriodData[i] = SettingValue.ReadValue_DateSetData[i, SettingValue.MakeValue_TodayType];
                if (TodayPeriodData[i] == 1)
                {
                    count++;
                }
            }
            TodayStartTime      = new string[count];
            TodayEndedTime      = new string[count];
            TodayStartTimeValue = new int[count];
            TodayEndedTimeValue = new int[count];
            count = 0;
            for (int i = 0; i < SettingValue.MAX_PERIOD; i++)
            {
                if (TodayPeriodData[i] == 1)
                {
                    TodayStartTime[count]      = SettingValue.ReadValue_StartTime[i];
                    TodayEndedTime[count]      = SettingValue.ReadValue_EndedTime[i];
                    TodayStartTimeValue[count] = ConvertToSeconds(TodayStartTime[count]);
                    TodayEndedTimeValue[count] = ConvertToSeconds(TodayEndedTime[count]);
                    count++;
                }
            }

            TodayLeftTimeValue = new int[count];
            for (int i = 0; i < count; i++)
            {
                TodayLeftTimeValue[i] = TodayStartTimeValue[i] - SettingValue.LEFT_DISPLAY_TIME;
            }

            TodayNowPeriod     = CheckPeriodNumber(NowTimeRaw, TodayStartTimeValue, TodayEndedTimeValue);
            TodayNowLeftPeriod = CheckPeriodNumber(NowTimeRaw, TodayLeftTimeValue, TodayStartTimeValue);

            if (NowTimePeriod != -1 && TodayNowPeriod != -1)
            {
                //授業時間中
                SettingProgressBar[0]      = TodayStartTimeValue[TodayNowPeriod];
                SettingProgressBar[1]      = TodayEndedTimeValue[TodayNowPeriod];
                SettingProgressBar[2]      = NowTimeSeconds;
                SettingProgressBarColor[0] = SettingValue.BAR_BACK_COLOR_INTIME;
                SettingProgressBarColor[1] = SettingValue.BAR_FRONT_COLOR_INTIME;
                SettingButtomText[0]       = TodayStartTime[TodayNowPeriod];
                SettingButtomText[1]       = TodayEndedTime[TodayNowPeriod];
                SettingButtomText[2]       = ConvertToReturnTime(TodayEndedTimeValue[TodayNowPeriod] - NowTimeSeconds);
                SettingFrontText           = "During the " + (NowTimePeriod + 1).ToString() + " time period class!";
            }
            else
            {
                if (TodayNowLeftPeriod != -1)
                {
                    //授業まであと何分
                    string RemainingTime = ConvertToReturnTime(TodayStartTimeValue[TodayNowLeftPeriod] - NowTimeSeconds);
                    SettingProgressBar[0]      = TodayLeftTimeValue[TodayNowLeftPeriod];
                    SettingProgressBar[1]      = TodayStartTimeValue[TodayNowLeftPeriod];
                    SettingProgressBar[2]      = NowTimeSeconds;
                    SettingProgressBarColor[0] = SettingValue.BAR_BACK_COLOR_LEFTTIME;
                    SettingProgressBarColor[1] = SettingValue.BAR_FRONT_COLOR_LEFTTIME;
                    SettingButtomText[0]       = ConvertToReturnTime(TodayLeftTimeValue[TodayNowLeftPeriod]);
                    SettingButtomText[1]       = TodayStartTime[TodayNowLeftPeriod];
                    SettingButtomText[2]       = RemainingTime;
                    SettingFrontText           = RemainingTime.Remove(0, 3) + " times left for start class!";
                }
                else
                {
                    //授業時間外
                    SettingProgressBar[0]      = 0;
                    SettingProgressBar[1]      = 0;
                    SettingProgressBar[2]      = 0;
                    SettingProgressBarColor[0] = SettingValue.BAR_BACK_COLOR_OUTTIME;
                    SettingProgressBarColor[1] = SettingValue.BAR_FRONT_COLOR_OUTTIME;
                    SettingFrontText           = "Time without class!";
                    for (int i = 0; i < SettingButtomText.Length; i++)
                    {
                        SettingButtomText[i] = string.Empty;
                    }
                }
            }
            //Formに反映
            progressBar1.Minimum    = SettingProgressBar[0];
            progressBar1.Maximum    = SettingProgressBar[1];
            progressBar1.Value      = SettingProgressBar[2];
            progressBar1.BackColor  = SettingProgressBarColor[0];
            progressBar1.ForeColor  = SettingProgressBarColor[1];
            NowTimeStatusLabel.Text = SettingFrontText;
            NowTimeFormLabel.Text   = NowTimeString;
            StartTimeLabel.Text     = SettingButtomText[0];
            EndedTimeLabel.Text     = SettingButtomText[1];
            leftTimeLabel.Text      = SettingButtomText[2];
        }
Пример #3
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);
                }
            }
        }