Example #1
0
        private void LoadCurTimeTable()
        {
            try
            {
                FormClearTimeTable();
                //CurTimeTable.Date = dateTimePicker1.Value;
                //CurTimeTable.Columns.Clear();
                CurTimeTable = null;
                foreach (var ctb in TBData.TimeTable.Items)
                {
                    if (ctb.Date == dateTimePicker1.Value)
                    {
                        CurTimeTable = ctb;
                        break;
                    }
                }
                if (CurTimeTable == null)
                {
                    CurTimeTable      = new DTimeTableItem();
                    CurTimeTable.Date = dateTimePicker1.Value;
                }
                foreach (var col in CurTimeTable.Columns)
                {
                    foreach (Control c in TimeTable.Controls)
                    {
                        if (c is TextBox &&
                            c.Name == col.Name)
                        {
                            if (((TextBox)c).ReadOnly == false)
                            {
                                c.Text = col.Duration.ToString();
                            }
                        }
                    }

                    //((TextBox)(TimeTable.Find(col.Name, false)[0])).Text = col.Duration.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #2
0
        private void LoadCurTimeTable()
        {
            try
            {
                FormClearTimeTable();
                CurTimeTable = null;
                CurMonthDays = 0;
                foreach (var ctb in TBData.TimeTable.Items)
                {
                    if (ctb.Date >= new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, 1) &&
                        ctb.Date < new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month + 1, 1))
                    {
                        CurMonthDays++;
                        foreach (var col in ctb.Columns)
                        {
                            foreach (Control c in TimeTable.Controls)
                            {
                                if (c is TextBox &&
                                    c.Name == col.Name)
                                {
                                    if (((TextBox)c).ReadOnly == false)
                                    {
                                        c.Text = (DConvert.ToDoble(c.Text) + col.Duration).ToString();
                                    }
                                }
                            }
                        }
                    }
                }
                if (CurMonthDays == 0)
                {
                    CurMonthDays = DateTime.DaysInMonth(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month);
                }

                foreach (Control c in TimeTable.Controls)
                {
                    if (c is TextBox)
                    {
                        if (((TextBox)c).ReadOnly == false)
                        {
                            Object obj = TimeTable.Controls.Find(c.Name + "Description", false).First();
                            if (obj != null)
                            {
                                ((Label)obj).Text = "% Cnt: ";
                            }
                        }
                    }
                }

                foreach (Control c in TimeTable.Controls)
                {
                    if (c is TextBox)
                    {
                        if (((TextBox)c).ReadOnly == true)
                        {
                            double d = 0.0;
                            switch (c.Name)
                            {
                            case "work":
                                d        += DConvert.ToDoble(business.Text);
                                d        += DConvert.ToDoble(note.Text);
                                d        += DConvert.ToDoble(project.Text);
                                d        += DConvert.ToDoble(language.Text);
                                d        += DConvert.ToDoble(fantasy.Text);
                                work.Text = Convert.ToString(d);
                                break;

                            case "life":
                                d        += DConvert.ToDoble(live.Text);
                                d        += DConvert.ToDoble(sleep.Text);
                                d        += DConvert.ToDoble(communication.Text);
                                d        += DConvert.ToDoble(discipline.Text);
                                d        += DConvert.ToDoble(exercise.Text);
                                life.Text = Convert.ToString(d);
                                break;

                            case "play":
                                d        += DConvert.ToDoble(book.Text);
                                d        += DConvert.ToDoble(animation.Text);
                                d        += DConvert.ToDoble(game.Text);
                                d        += DConvert.ToDoble(ero.Text);
                                d        += DConvert.ToDoble(other.Text);
                                play.Text = Convert.ToString(d);
                                break;
                            }
                        }
                    }
                }

                double w = DConvert.ToDoble(work.Text);
                double l = DConvert.ToDoble(life.Text);
                double p = DConvert.ToDoble(play.Text);
                total.Text      = Convert.ToString(w + l + p);
                workLabel.Text  = Convert.ToString(Convert.ToInt32(w / 24 / CurMonthDays * 100)) + "%";
                lifeLabel.Text  = Convert.ToString(Convert.ToInt32(l / 24 / CurMonthDays * 100)) + "%";
                playLabel.Text  = Convert.ToString(Convert.ToInt32(p / 24 / CurMonthDays * 100)) + "%";
                totalLabel.Text = Convert.ToString(Convert.ToInt32((w + l + p) / 24.0 / CurMonthDays * 100)) + "%";
                totalCount.Text = "Count: " + CurMonthDays.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #3
0
 // --- Initialize ---
 private void LoadTimeTable()
 {
     TBData       = TimeTableData.GetData();
     CurTimeTable = new DTimeTableItem();
     LoadCurTimeTable();
 }
Example #4
0
        // --- Event ---
        private void SaveTimeTable()
        {
            if (CheckVaildTimeTable() == false)
            {
                MessageBox.Show("Invalid TimeTable data.");
                return;
            }

            bool exist = false;

            foreach (var ctb in TBData.TimeTable.Items)
            {
                if (ctb.Date == dateTimePicker1.Value)
                {
                    CurTimeTable = ctb;
                    exist        = true;
                    break;
                }
            }
            if (!exist)
            {
                int curDiaryIndex = TBData.TimeTable.Items.Count;
                for (int i = 0; i < TBData.TimeTable.Items.Count; i++)
                {
                    if (dateTimePicker1.Value < TBData.TimeTable.Items[i].Date)
                    {
                        curDiaryIndex = i;
                        break;
                    }
                }
                TBData.TimeTable.Items.Insert(curDiaryIndex, CurTimeTable);
            }

            foreach (Control c in TimeTable.Controls)
            {
                if (c is TextBox)
                {
                    bool existCol = false;
                    foreach (var itr in CurTimeTable.Columns)
                    {
                        if (itr.Name == c.Name)
                        {
                            try { itr.Duration = Convert.ToDouble(c.Text); }
                            catch (Exception ex) { itr.Duration = 0; ex.ToString(); }
                            if (itr.Duration == 0)
                            {
                                c.Text = "";
                                CurTimeTable.Columns.Remove(itr);
                            }
                            existCol = true;
                            break;
                        }
                    }
                    if (!existCol)
                    {
                        DTimeTableColumn col = new DTimeTableColumn();
                        col.Name = c.Name;
                        try { col.Duration = Convert.ToDouble(c.Text); }
                        catch (Exception ex) { col.Duration = 0; ex.ToString(); }
                        if (col.Duration != 0)
                        {
                            CurTimeTable.Columns.Add(col);
                        }
                        else
                        {
                            c.Text = "";
                        }
                    }
                }
            }
            CurTimeTable.Date = dateTimePicker1.Value.Date;
            TBData.Save(TBData.TimeTable);
        }