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; }
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); } }
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); } }