コード例 #1
0
        private void END_FASTING_Click(object sender, EventArgs e)
        {
            Fasting_Time  fast_time = new Fasting_Time();
            Fasting_Chart fc;

            Read_Date(ref fast_time);
            if (fast_time.Fast_State == false && !fast_time.Marked)
            {
                int total_fasted_hours = 0;
                fast_time.SubtractTime(fast_time, DateTime.Now.Hour, DateTime.Now.Minute
                                       , DateTime.Now.Second);
                int RemaingTime_minutes = (fast_time.Hours * 60) +
                                          (fast_time.Minutes);
                if (fast_time.Fasting_ProtoType == (int)Fasting_Types.OMAD)
                {
                    total_fasted_hours = ((22 * 60) + 59) - RemaingTime_minutes;
                }
                else if (fast_time.Fasting_ProtoType == (int)Fasting_Types.SixtennHours)
                {
                    total_fasted_hours = ((15 * 60) + 59) - RemaingTime_minutes;
                }
                else if (fast_time.Fasting_ProtoType == (int)Fasting_Types.TwentyHours)
                {
                    total_fasted_hours = ((19 * 60) + 59) - RemaingTime_minutes;
                }
                fc.totalFastedTime   = total_fasted_hours;
                fc.Day               = (int)DateTime.Now.DayOfWeek;
                fast_time.Fast_State = true;
                fast_time.Marked     = true;
                Save_Date(fast_time);
                Save_Chart_Date(fc);
            }
        }
コード例 #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Fasting_Time RemaingTime = new Fasting_Time();

            if (File.Exists(FileName))
            {
                Read_Date(ref RemaingTime);

                RemaingTime.SubtractTime(RemaingTime, DateTime.Now.Hour, DateTime.Now.Minute,
                                         DateTime.Now.Second);
                if (RemaingTime.Fast_State)
                {
                    PercentLabel.Text = string.Format("{0:F3}", "100.00").ToString() + "%";
                    angle             = 360.0f;
                    Fasted_hours.Text = "Fast Complete";
                    Save_Date(RemaingTime);
                    timer1.Enabled = false;
                }
                else
                {
                    Fasted_hours.Text = RemaingTime.Hours.ToString().PadLeft(2, '0') + ":" +
                                        RemaingTime.Minutes.ToString().PadLeft(2, '0') + ":" +
                                        RemaingTime.Seconds.ToString().PadLeft(2, '0') + " Hours Left";
                    float percentage = Calculate_Percentage(RemaingTime);
                    angle = ProgressBar_Progress(percentage);


                    PercentLabel.Text = string.Format("{0:F3}", percentage).ToString() + "%";
                }
                this.Invalidate(FastingWindow);
            }
        }
コード例 #3
0
        private void STARTFASTING_Click(object sender, EventArgs e)
        {
            Fasting_Time fast_time = new Fasting_Time();

            fast_time.SetTime(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

            if (ONE.Checked)  // if the user chosse OMAD =current time -1 the other day
            {
                fast_time.Fasting_ProtoType = (int)Fasting_Types.OMAD;
                fast_time.SubtractTime(fast_time, 1, 0, 0);
            }
            else if (TWO.Checked) // 16/8
            {
                fast_time.Fasting_ProtoType = (int)Fasting_Types.SixtennHours;
                fast_time.SubtractTime(fast_time, 8, 0, 0);
            }
            else if (THREE.Checked) // 20/4
            {
                fast_time.Fasting_ProtoType = (int)Fasting_Types.TwentyHours;

                fast_time.SubtractTime(fast_time, 4, 0, 0);
            }
            Save_Date(fast_time);
            timer1.Enabled = true;
        }
コード例 #4
0
        private void Read_Date(ref Fasting_Time TimeObject)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            Stream          stream    = new FileStream(FileName, FileMode.Open, FileAccess.Read);

            TimeObject = (Fasting_Time)formatter.Deserialize(stream);
            stream.Close();
        }
コード例 #5
0
        private void Save_Date(Fasting_Time TimeObject)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            Stream          stream    = new FileStream(FileName, FileMode.Create, FileAccess.Write);

            formatter.Serialize(stream, TimeObject);
            stream.Close();
        }
コード例 #6
0
        private float Calculate_Percentage(Fasting_Time RemTime)
        {
            float total_Fast_time      = 0.0f;
            float remainigTime_Minutes = (RemTime.Hours * 60) + (RemTime.Minutes) + (RemTime.Seconds / 60.0f);

            if (RemTime.Fasting_ProtoType == (int)Fasting_Types.OMAD)
            {
                total_Fast_time = (22 * 60) + 59 + 59 / 60.0f;
            }
            else if (RemTime.Fasting_ProtoType == (int)Fasting_Types.SixtennHours)
            {
                total_Fast_time = (15 * 60) + 59 + 59 / 60.0f;
            }
            else if (RemTime.Fasting_ProtoType == (int)Fasting_Types.TwentyHours)
            {
                total_Fast_time = (19 * 60) + 59 + 59 / 60.0f;
            }
            return((Math.Abs((remainigTime_Minutes - total_Fast_time)) / total_Fast_time) * 100.0f);
        }