コード例 #1
0
        public override void Load()
        {
            try
            {
                if (File.Exists("listInformationOfDay.txt"))
                {
                    List <InformationOfDay> list  = new List <InformationOfDay>();
                    StreamReader            file  = File.OpenText("listInformationOfDay.txt");
                    string[]         data         = new string[14];
                    string[]         date         = new string[3];
                    string[]         timeSleepMor = new string[4];
                    string[]         timeSleepAft = new string[4];
                    string           line;
                    InformationOfDay info;

                    do
                    {
                        line = file.ReadLine();
                        if (line != null && line.Length > 1)
                        {
                            data         = line.Split('|');
                            date         = data[2].Split(',');
                            timeSleepMor = data[9].Split(',');
                            timeSleepMor = data[11].Split(',');

                            info = new InformationOfDay(Convert.ToInt32(data[0]),
                                                        Convert.ToInt32(data[3]), Convert.ToInt32(data[4]),
                                                        Convert.ToInt32(data[5]), data[12], data[13],
                                                        Convert.ToInt32(data[6]),
                                                        Convert.ToInt32(data[7]),
                                                        Convert.ToInt32(data[8]),
                                                        Convert.ToInt32(data[10]));
                            info.AddTimeSleepMor(Convert.ToInt32(timeSleepMor[0]),
                                                 Convert.ToInt32(timeSleepMor[1]),
                                                 Convert.ToInt32(timeSleepMor[2]),
                                                 Convert.ToInt32(timeSleepMor[3]));
                            info.AddTimeSleepAft(Convert.ToInt32(timeSleepAft[0]),
                                                 Convert.ToInt32(timeSleepAft[1]),
                                                 Convert.ToInt32(timeSleepAft[2]),
                                                 Convert.ToInt32(timeSleepAft[3]));
                            info.AddDaySave(Convert.ToInt32(date[0]),
                                            Convert.ToInt32(date[1]), Convert.ToInt32(date[2]));

                            info.SetMeal(data[1]);
                            list.Add(info);
                        }
                    } while (line != null);
                    file.Close();
                    listInfo = list;
                }
                else
                {
                    listInfo = new List <InformationOfDay>();
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("Eror: " + e.Message);
            }
        }
コード例 #2
0
        private void btOk_Click(object sender, EventArgs e)
        {
            Day today = new Day();

            today.day   = time.Day;
            today.month = time.Month;
            today.year  = time.Year;

            int eatB = cbEatBreakAll.Checked ? 1 : cbEatBreakHalf.Checked ? 2
                : cbEatBreakLittle.Checked ? 3 : 0;
            int eatL = cbEatLunchAll.Checked ? 1 : cbEatLunchHalf.Checked ? 2
                : cbEatLunchLittle.Checked ? 3 : 0;
            int eatS = cbEatSnackAll.Checked ? 1 : cbEatSnackHalf.Checked ? 2
                : cbEatSnackLittle.Checked ? 3 : 0;
            int deposMor = cbDepositionsMorYes.Checked ? 1 : cbDepositionsMorNo.Checked ? 2 : 0;
            int deposAft = cbDepositionsAftYes.Checked ? 1 : cbDepositionsAftNo.Checked ? 2 : 0;
            int sleepMor = cbSleepMorGood.Checked ? 1 : cbSleepMorBad.Checked ? 2 : 0;
            int sleepAft = cbSleepAftGood.Checked ? 1 : cbSleepAftBad.Checked ? 2 : 0;

            InformationOfDay information = new InformationOfDay(
                Convert.ToInt32(tbCod.Text), eatB, eatL, eatS,
                tbMessageForHome.Text, tbMessageForSchool.Text,
                deposMor, deposAft, sleepMor, sleepMor);
            TimeSleep timMor1 = new TimeSleep();
            TimeSleep timMor2 = new TimeSleep();
            TimeSleep timAft1 = new TimeSleep();
            TimeSleep timAft2 = new TimeSleep();
            Day       t;

            timMor1.hour = dtpSinceSleepMor.Checked ?
                           dtpSinceSleepMor.Value.Hour : 0;
            timMor1.minute = dtpSinceSleepMor.Checked ?
                             dtpSinceSleepMor.Value.Minute : 0;
            timMor2.hour = dtpUntilSleepMor.Checked ?
                           dtpUntilSleepMor.Value.Hour : 0;
            timMor2.minute = dtpUntilSleepMor.Checked ?
                             dtpUntilSleepMor.Value.Minute : 0;
            information.AddTimeSleepMor(timMor1.hour,
                                        timMor1.minute, timMor2.hour, timMor2.minute);

            timAft1.hour = dtpSinceSleepAft.Checked ?
                           dtpSinceSleepAft.Value.Hour : 0;
            timAft1.minute = dtpSinceSleepAft.Checked ?
                             dtpSinceSleepAft.Value.Minute : 0;
            timAft2.hour = dtpUntilSleepAft.Checked ?
                           dtpSinceSleepAft.Value.Hour : 0;
            timAft2.minute = dtpUntilSleepAft.Checked ?
                             dtpSinceSleepAft.Value.Minute : 0;
            information.AddTimeSleepAft(timAft1.hour,
                                        timAft1.minute, timAft2.hour, timAft2.minute);

            t.day   = time.Day;
            t.month = time.Month;
            t.year  = time.Year;
            information.SetDay(t);
            information.SetMeal(meal.GetBreakfast() + "?"
                                + meal.GetLunch() + "?" + meal.GetSnack());

            InformationOfDay info = list.GetInformationOfAChildFromDate(
                today, listChildren.GetChildOfList(index).GetCod());

            if (info == null)
            {
                list.SetInformation(information);
            }

            else
            {
                list.SetEditInformation(information);
            }

            this.Close();
        }