Beispiel #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            CSleep newSleep = new CSleep();

            newSleep.Date = curDate;
            newSleep.IsGoToBedBeforeMidNight = chkMinusOneDay.Checked;
            if (chkMinusOneDay.Checked)
            {
                newSleep.GoToBedTime = new DateTime(curDate.AddDays(-1).Year, curDate.AddDays(-1).Month, curDate.AddDays(-1).Day, dtpTimeStart.Value.Hour, dtpTimeStart.Value.Minute, dtpTimeStart.Value.Second);
            }
            else
            {
                newSleep.GoToBedTime = new DateTime(curDate.Year, curDate.Month, curDate.Day, dtpTimeStart.Value.Hour, dtpTimeStart.Value.Minute, dtpTimeStart.Value.Second);
            }
            newSleep.GetUpTime = new DateTime(curDate.Year, curDate.Month, curDate.Day, dtpTimeEnd.Value.Hour, dtpTimeEnd.Value.Minute, dtpTimeEnd.Value.Second);
            if (G.glb.lstSleepLog.Exists(o => o.Date == curDate))
            {
                G.glb.lstSleepLog.RemoveAll(o => o.Date == curDate);
                G.glb.lstSleepLog.Add(newSleep);
            }
            else
            {
                G.glb.lstSleepLog.Add(newSleep);
            }
            DrawLog();
            Dispose();
        }
Beispiel #2
0
        /// <summary>
        /// 绘制计划图或日志图 Done: 01/03/2019
        /// </summary>
        /// <param name="picMap">画布</param>
        /// <param name="date">日期</param>
        /// <param name="logs">日志</param>
        /// <param name="healths">健康日志</param>
        /// <param name="IsLabelShown">是否显示标签</param>
        /// <param name="LocationMode">位置模式:"all" - 全部; "left" - 左侧; "right" - 右侧</param>
        public void DrawScheduleAndLogController(PictureBox picMap, DateTime date, List <CLog> logs, List <CSleep> healths, string LocationMode)
        {
            int left  = 0;
            int width = picMap.Width;

            if (LocationMode == "all")
            {
                left  = 0;
                width = picMap.Width;
            }
            else if (LocationMode == "left")
            {
                left  = 0;
                width = picMap.Width / 2;
            }
            else if (LocationMode == "right")
            {
                left  = picMap.Width / 2;
                width = picMap.Width / 2;
            }
            else if (LocationMode == "allWithSupp")
            {
                left  = 0;
                width = (picMap.Width = 30) > 0 ? picMap.Width - 30 : 0;
            }
            else if (LocationMode == "leftWithSupp")
            {
                left  = 0;
                width = (picMap.Width - 30) > 0 ? (picMap.Width - 30) / 2 : 0;
            }
            else if (LocationMode == "rightWithSupp")
            {
                left  = (picMap.Width - 30) > 0 ? (picMap.Width - 30) / 2 : 0;
                width = (picMap.Width - 30) > 0 ? (picMap.Width - 30) / 2 : 0;
            }
            int        height         = picMap.Height;
            PictureBox picTimePointer = new PictureBox();
            PictureBox picToday       = new PictureBox();
            Label      lblNow         = new Label();

            if (date < DateTime.Today.Date)
            {
                picMap.BackColor = Color.FromArgb(19, 92, 08, 21);
            }
            else if (date == DateTime.Today.Date)
            {
                picMap.BackColor = Color.FromArgb(19, 92, 08, 21);
            }
            else
            {
                picMap.BackColor = Color.White;
            }
            if (date == DateTime.Today.Date)
            {
                picTimePointer.Width     = picMap.Width;
                picTimePointer.Height    = 2;
                picTimePointer.Left      = 0;
                picTimePointer.Top       = (int)(height * DateTime.Now.TimeOfDay.TotalMinutes / (24 * 60));
                picTimePointer.BackColor = Color.DarkRed;
                picMap.Controls.Add(picTimePointer);
                lblNow.Text   = DateTime.Now.ToShortTimeString();
                lblNow.Top    = (int)(height * DateTime.Now.TimeOfDay.TotalMinutes / (24 * 60)) - 14;
                lblNow.Left   = picMap.Width - 50;
                lblNow.Height = 14;
                lblNow.BringToFront();
                lblNow.BackColor = Color.DarkRed;
                lblNow.ForeColor = Color.White;
                picMap.Controls.Add(lblNow);
            }

            List <CLog> todayLogs     = logs.FindAll(o => o.StartTime.Date == date).ToList();
            List <CLog> yesterdayLogs = logs.FindAll(o => o.StartTime.Date == date.AddDays(-1) && o.EndTime.Date == date).ToList();
            CSleep      todaySleep    = healths.Find(o => o.Date == date);
            CSleep      tomorrowSleep = healths.Find(o => o.Date == date.AddDays(1));

            PictureBox picSleep = new PictureBox();
            Label      lblSleep = new Label();

            if (healths.Exists(o => o.Date == date))
            {
                double start;
                if (todaySleep.IsGoToBedBeforeMidNight)
                {
                    start = 0;
                }
                else
                {
                    start = (todaySleep.GoToBedTime.Hour + todaySleep.GoToBedTime.Minute / 60d) / 24d * height;
                }
                double end       = (todaySleep.GetUpTime.Hour + todaySleep.GetUpTime.Minute / 60d) / 24d * height;
                double totalHour = (todaySleep.GetUpTime - todaySleep.GoToBedTime).TotalHours;
                totalHour = Math.Round(totalHour, 2);
                string SleepTime = (todaySleep.IsGoToBedBeforeMidNight ? "(-1d)" : "") + todaySleep.GoToBedTime.ToShortTimeString() + " - " + todaySleep.GetUpTime.ToShortTimeString() + " [" + totalHour.ToString() + "h]";
                picSleep.Width     = width;
                picSleep.Height    = (int)(end - start);
                picSleep.Left      = left;
                picSleep.Top       = (int)start;
                picSleep.BackColor = Color.LightBlue;
                picMap.Controls.Add(picSleep);
                lblSleep.Text   = SleepTime + "\n" + "Sleep";
                lblSleep.Dock   = DockStyle.Fill;
                lblSleep.Click += (e, a) => CallInfoLog(SleepTime, "Sleep", "", "", "", picSleep.BackColor, false);
                picSleep.Controls.Add(lblSleep);
            }

            PictureBox picSleepYesterday = new PictureBox();
            Label      lblSleepYesterday = new Label();

            if (healths.Exists(o => o.Date == date.AddDays(1)))
            {
                if (tomorrowSleep.IsGoToBedBeforeMidNight)
                {
                    double start     = (tomorrowSleep.GoToBedTime.Hour + tomorrowSleep.GoToBedTime.Minute / 60d) / 24d * height;
                    double end       = height;
                    double totalHour = (tomorrowSleep.GetUpTime - tomorrowSleep.GoToBedTime).TotalHours;
                    totalHour = Math.Round(totalHour, 2);
                    string SleepTime = tomorrowSleep.GoToBedTime.ToShortTimeString() + " - " + tomorrowSleep.GetUpTime.ToShortTimeString() + "(+1d)" + " [" + totalHour.ToString() + "h]";
                    picSleepYesterday.Width     = width;
                    picSleepYesterday.Height    = (int)(end - start);
                    picSleepYesterday.Left      = left;
                    picSleepYesterday.Top       = (int)start;
                    picSleepYesterday.BackColor = Color.LightBlue;
                    picMap.Controls.Add(picSleepYesterday);
                    lblSleepYesterday.Text   = SleepTime + "\n" + "Sleep";
                    lblSleepYesterday.Dock   = DockStyle.Fill;
                    lblSleepYesterday.Click += (e, a) => CallInfoLog("", "Sleep", "", "", "", picSleepYesterday.BackColor, false);
                    picSleepYesterday.Controls.Add(lblSleepYesterday);
                }
            }

            List <PictureBox> lstPicLog = new List <PictureBox>();
            List <Label>      lstLblLog = new List <Label>();

            for (int i = 0; i < yesterdayLogs.Count; i++)
            {
                lstPicLog.Add(new PictureBox());
                lstLblLog.Add(new Label());
                double start     = 0;
                double end       = (yesterdayLogs[i].EndTime.Hour + yesterdayLogs[i].EndTime.Minute / 60d) / 24d * height;
                double totalHour = (yesterdayLogs[i].EndTime - yesterdayLogs[i].StartTime).TotalHours;
                totalHour = Math.Round(totalHour, 2);
                string TimePeriod = yesterdayLogs[i].StartTime.ToShortTimeString() + "(-1d)" + " - " + yesterdayLogs[i].EndTime.ToShortTimeString() + " [" + totalHour.ToString() + "h]";
                string LogName    = yesterdayLogs[i].LogName;
                string Location   = yesterdayLogs[i].Location;
                string WithWho    = yesterdayLogs[i].WithWho;
                string TaskName   = yesterdayLogs[i].ContributionToTask;
                bool   IsAlarm    = yesterdayLogs[i].Alarm;
                Color  backColor  = GetColor(yesterdayLogs[i].Color);
                lstPicLog[i].Width     = width;
                lstPicLog[i].Height    = (int)(end - start);
                lstPicLog[i].Left      = left;
                lstPicLog[i].Top       = (int)start;
                lstPicLog[i].BackColor = backColor;
                picMap.Controls.Add(lstPicLog[i]);
                lstLblLog[i].Text      = TimePeriod + "\n" + LogName + "\n" + Location + "\n" + WithWho;
                lstLblLog[i].Dock      = DockStyle.Fill;
                lstLblLog[i].ForeColor = Color.FromArgb(255 - backColor.R, 255 - backColor.G, 255 - backColor.B);
                lstLblLog[i].Click    += (e, a) => CallInfoLog(TimePeriod, LogName, Location, WithWho, TaskName, backColor, IsAlarm);
                lstPicLog[i].Controls.Add(lstLblLog[i]);
            }

            for (int i = 0; i < todayLogs.Count; i++)
            {
                lstPicLog.Add(new PictureBox());
                lstLblLog.Add(new Label());
                double start = (todayLogs[i].StartTime.Hour + todayLogs[i].StartTime.Minute / 60d) / 24d * height;
                double end;
                double totalHour = (todayLogs[i].EndTime - todayLogs[i].StartTime).TotalHours;
                totalHour = Math.Round(totalHour, 2);
                string TimePeriod;
                if (todayLogs[i].EndTime.Date == date)
                {
                    end        = (todayLogs[i].EndTime.Hour + todayLogs[i].EndTime.Minute / 60d) / 24d * height;
                    TimePeriod = todayLogs[i].StartTime.ToShortTimeString() + " - " + todayLogs[i].EndTime.ToShortTimeString() + " [" + totalHour.ToString() + "h]";
                }
                else
                {
                    end        = height;
                    TimePeriod = todayLogs[i].StartTime.ToShortTimeString() + " - " + todayLogs[i].EndTime.ToShortTimeString() + "(+1d)" + " [" + totalHour.ToString() + "h]";
                }
                string LogName   = todayLogs[i].LogName;
                string Location  = todayLogs[i].Location;
                string WithWho   = todayLogs[i].WithWho;
                string TaskName  = todayLogs[i].ContributionToTask;
                bool   IsAlarm   = todayLogs[i].Alarm;
                Color  backColor = GetColor(todayLogs[i].Color);
                lstPicLog[i + yesterdayLogs.Count].Width     = width;
                lstPicLog[i + yesterdayLogs.Count].Height    = (int)(end - start);
                lstPicLog[i + yesterdayLogs.Count].Left      = left;
                lstPicLog[i + yesterdayLogs.Count].Top       = (int)start;
                lstPicLog[i + yesterdayLogs.Count].BackColor = backColor;
                picMap.Controls.Add(lstPicLog[i + yesterdayLogs.Count]);
                lstLblLog[i + yesterdayLogs.Count].Text      = TimePeriod + "\n" + LogName + "\n" + Location + "\n" + WithWho;
                lstLblLog[i + yesterdayLogs.Count].Dock      = DockStyle.Fill;
                lstLblLog[i + yesterdayLogs.Count].ForeColor = Color.FromArgb(255 - backColor.R, 255 - backColor.G, 255 - backColor.B);
                lstLblLog[i + yesterdayLogs.Count].Click    += (e, a) => CallInfoLog(TimePeriod, LogName, Location, WithWho, TaskName, backColor, IsAlarm);
                lstPicLog[i + yesterdayLogs.Count].Controls.Add(lstLblLog[i + yesterdayLogs.Count]);
            }

            if (date == DateTime.Today.Date)
            {
                picToday.Width     = picMap.Width;
                picToday.Height    = (int)(height - height * DateTime.Now.TimeOfDay.TotalMinutes / (24 * 60));
                picToday.Left      = 0;
                picToday.Top       = (int)(height * DateTime.Now.TimeOfDay.TotalMinutes / (24 * 60));
                picToday.BackColor = Color.White;
                picMap.Controls.Add(picToday);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DateTime startDate = dtpPeriodStart.Value.Date.Date;
            DateTime endDate   = dtpPeriodEnd.Value.Date.Date;

            for (DateTime day = startDate; day <= endDate; day = day.AddDays(1))
            {
                bool IsAddSchedule = false;
                switch (day.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    if (chkSu.Checked)
                    {
                        IsAddSchedule = true;
                    }
                    break;

                case DayOfWeek.Monday:
                    if (chkMo.Checked)
                    {
                        IsAddSchedule = true;
                    }
                    break;

                case DayOfWeek.Tuesday:
                    if (chkTu.Checked)
                    {
                        IsAddSchedule = true;
                    }
                    break;

                case DayOfWeek.Wednesday:
                    if (chkWe.Checked)
                    {
                        IsAddSchedule = true;
                    }
                    break;

                case DayOfWeek.Thursday:
                    if (chkTu.Checked)
                    {
                        IsAddSchedule = true;
                    }
                    break;

                case DayOfWeek.Friday:
                    if (chkFr.Checked)
                    {
                        IsAddSchedule = true;
                    }
                    break;

                case DayOfWeek.Saturday:
                    if (chkSa.Checked)
                    {
                        IsAddSchedule = true;
                    }
                    break;

                default:
                    break;
                }
                if (IsAddSchedule)
                {
                    CSleep newSleep = new CSleep();
                    newSleep.Date = day.Date;
                    newSleep.IsGoToBedBeforeMidNight = chkMinusOneDay.Checked;
                    if (chkMinusOneDay.Checked)
                    {
                        newSleep.GoToBedTime = new DateTime(day.AddDays(-1).Year, day.AddDays(-1).Month, day.AddDays(-1).Day, dtpTimeStart.Value.Hour, dtpTimeStart.Value.Minute, dtpTimeStart.Value.Second);
                    }
                    else
                    {
                        newSleep.GoToBedTime = new DateTime(day.Year, day.Month, day.Day, dtpTimeStart.Value.Hour, dtpTimeStart.Value.Minute, dtpTimeStart.Value.Second);
                    }
                    newSleep.GetUpTime = new DateTime(day.Year, day.Month, day.Day, dtpTimeEnd.Value.Hour, dtpTimeEnd.Value.Minute, dtpTimeEnd.Value.Second);
                    if (G.glb.lstSleepSchedule.Exists(o => o.Date == day))
                    {
                        G.glb.lstSleepSchedule.RemoveAll(o => o.Date == day);
                        G.glb.lstSleepSchedule.Add(newSleep);
                    }
                    else
                    {
                        G.glb.lstSleepSchedule.Add(newSleep);
                    }
                }
            }
            DrawLog();
            Dispose();
        }