Beispiel #1
0
        public Result <DateRecord> Edit(DateRecord oldRecord, DateRecord newRecord)
        {
            int index = -1;

            if (oldRecord != null)
            {
                index = FindIndex(oldRecord.Date);
            }
            var result = new Result <DateRecord>();

            if (index == -1)
            {
                result.Message = "Could not find record to replace.";
                result.Success = false;
                result.Data    = oldRecord;
            }
            else
            {
                _records[index] = newRecord;
                result.Message  = "Successfully replaced record in database";
                result.Success  = true;
                result.Data     = newRecord;
            }
            Save();
            return(result);
        }
Beispiel #2
0
 private void Load()
 {
     if (!File.Exists(_fileName))
     {
         File.Create(_fileName).Close();
     }
     else
     {
         using (StreamReader sr = new StreamReader(_fileName))
         {
             for (string line = sr.ReadLine(); line != null; line = sr.ReadLine())
             {
                 /*
                  * fields[0] DateTime Date
                  * fields[1] decimal HighTemp
                  * fields[2] decimal LowTemp
                  * fields[3] decimal Humidity
                  * fields[4] string Description
                  */
                 string[]   fields = line.Split(',');
                 DateRecord record = new DateRecord();
                 record.Date        = DateTime.Parse(fields[0]);
                 record.HighTemp    = decimal.Parse(fields[1]);
                 record.LowTemp     = decimal.Parse(fields[2]);
                 record.Humidity    = decimal.Parse(fields[3]);
                 record.Description = fields[4];
                 _records.Add(record);
             }
         }
     }
 }
Beispiel #3
0
        public static DateRecord GetDateRecord()
        {
            var dateRecord = new DateRecord();

            dateRecord.Date        = GetDateTime("Enter the Date : ");
            dateRecord.HighTemp    = GetDecimalInRange("Enter the High Temp : ", -100M, 200M);
            dateRecord.LowTemp     = GetDecimalInRange("Enter the Low Temp : ", -100M, 200M);
            dateRecord.Humidity    = GetDecimalInRange("Enter the Humidity : ", 0M, 100M);
            dateRecord.Description = GetString("Enter a discription : ");
            return(dateRecord);
        }
Beispiel #4
0
 public static void DisplayDateRecord(DateRecord record)
 {
     Console.WriteLine();
     WriteWithColor("Date : ", ConsoleColor.Yellow);
     WriteWithColor($"{record.Date}\n", ConsoleColor.Yellow);
     WriteWithColor("   High Temp   : ", ConsoleColor.Yellow);
     WriteWithColor($"{record.HighTemp}\n", ConsoleColor.Yellow);
     WriteWithColor("   Low Temp    : ", ConsoleColor.Yellow);
     WriteWithColor($"{record.LowTemp}\n", ConsoleColor.DarkYellow);
     WriteWithColor("   Humidity    : ", ConsoleColor.Yellow);
     WriteWithColor($"{record.Humidity}\n", ConsoleColor.DarkYellow);
     WriteWithColor("   Discription : ", ConsoleColor.Yellow);
     WriteWithColor($"{record.Description}\n", ConsoleColor.DarkYellow);
 }
        public EnterPeriodPanel()
        {
            InitializeComponent();
            CaptionFont = new Font(FontFamily.GenericSansSerif, 13);
            TextFont    = new Font(FontFamily.GenericSansSerif, 10);
            DateRecord dr;

            DateTime d = DateTime.Now;

            dr = new DateRecord()
            {
                Title = "Year " + d.Year
            };
            dr.StartDate = new GregorianDateTime(DateTime.Now.Year, 1, 1);
            dr.EndDate   = new GregorianDateTime(DateTime.Now.Year, 12, 31);
            dr.UpdateSubtitle();
            listBox1.Items.Add(dr);

            dr = new DateRecord()
            {
                Title = "Year " + (d.Year + 1).ToString()
            };
            dr.StartDate = new GregorianDateTime(DateTime.Now.Year + 1, 1, 1);
            dr.EndDate   = new GregorianDateTime(DateTime.Now.Year + 1, 12, 31);
            dr.UpdateSubtitle();
            listBox1.Items.Add(dr);

            dr = new DateRecord();
            if (d.Month == 12)
            {
                dr.Title = string.Format("{0} {1} - {2} {3}", GregorianDateTime.GetMonthAbreviation(12), d.Year,
                                         GregorianDateTime.GetMonthAbreviation(1), d.Year + 1);
                dr.StartDate = new GregorianDateTime(d.Year, 12, 1);
                dr.EndDate   = new GregorianDateTime(d.Year + 1, 1, 31);
            }
            else
            {
                dr.Title = string.Format("{0} - {1} {2}", GregorianDateTime.GetMonthAbreviation(d.Month),
                                         GregorianDateTime.GetMonthAbreviation(d.Month + 1), d.Year);
                dr.StartDate = new GregorianDateTime(d.Year, d.Month, 1);
                dr.EndDate   = new GregorianDateTime(d.Year, d.Month + 1, GregorianDateTime.GetMonthMaxDays(d.Year, d.Month + 1));
            }
            dr.UpdateSubtitle();
            listBox1.Items.Add(dr);

            dr          = new DateRecord();
            dr.Title    = "Custom Date Range";
            dr.Subtitle = "Enter start date manually";
            listBox1.Items.Add(dr);
        }
Beispiel #6
0
        public Result <DateRecord> Add(DateRecord record)
        {
            var result = new Result <DateRecord>();

            result.Message = "Successfully added record to database";
            result.Success = true;
            result.Data    = record;
            _records.Add(record);
            try
            {
                Save();
            }
            catch (Exception e)
            {
                _logger.Log(e.Message);
                result.Success = false;
            }

            return(result);
        }
        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index >= 0 && e.Index < listBox1.Items.Count)
            {
                DateRecord cr = listBox1.Items[e.Index] as DateRecord;

                if ((e.State & DrawItemState.Selected) != 0)
                {
                    e.Graphics.FillRectangle(Brushes.LightYellow, e.Bounds);
                }
                else
                {
                    e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds);
                }

                SizeF a = e.Graphics.MeasureString("A", CaptionFont);
                e.Graphics.DrawString(cr.Title, CaptionFont, Brushes.Black, PaddingX, e.Bounds.Top + PaddingX);
                e.Graphics.DrawString(cr.Subtitle, TextFont, Brushes.Gray, PaddingX, e.Bounds.Top + PaddingX + a.Height + Spacing);
            }
        }
Beispiel #8
0
        public void ShouldLogErrorIfFileIsLostDurringExicution()
        {
            // Arrange
            var repo       = new FileRecordRepository("TestAlmanac.csv", new FileLogger("TestErrorLog.txt"));
            var testRecord = new DateRecord
            {
                Date        = DateTime.Now,
                HighTemp    = 100,
                LowTemp     = 20,
                Humidity    = 10,
                Description = "Normal Day"
            };

            // Act
            File.Delete("TestAlmanac.csv");
            var result = repo.Add(testRecord);

            // Assert
            Assert.IsTrue(File.Exists("TestErrorLog.txt"));
            Assert.AreEqual(false, result.Success);

            // Clean Up
            File.Delete("TestErrorLog.txt");
        }
        public Result <DateRecord> Add(DateRecord record) => _repo.Add(record); // TODO: Add check for duplicate entry

        public Result <DateRecord> Edit(DateTime date, DateRecord newRecord) => _repo.Edit(Get(date).Data, newRecord);
 public Result <DateRecord> Add(DateRecord record) => _repo.Add(record); // TODO: Add check for duplicate entry
Beispiel #11
0
 public Result <DateRecord> Edit(DateRecord oldRecord, DateRecord newRecord)
 {
     throw new NotImplementedException();
 }
Beispiel #12
0
 public Result <DateRecord> Add(DateRecord record)
 {
     throw new NotImplementedException();
 }