private ListViewItem CreateViewItem(LovroBaseEvent lovroEvent, LovroContext context) { ListViewItem viewItem = new ListViewItem(lovroEvent.Time.ToString()); viewItem.Tag = lovroEvent.ID; //viewItem.SubItems.Add(GetEnumDescription(typeof(LovroDiaperStatus), lovroEvent.Type.ToString())); viewItem.SubItems.Add(GetEventTypeDescription(lovroEvent.Type)); SetImageIndex(lovroEvent, viewItem); if (lovroEvent.Type == LovroEventType.DiaperChanged) { //viewItem.SubItems.Add(GetEnumDescription(typeof(LovroDiaperChangedEvent), (lovroEvent as LovroDiaperChangedEvent).Status.ToString())); viewItem.SubItems.Add(GetStatusDescription((lovroEvent as LovroDiaperChangedEvent).Status)); } else viewItem.SubItems.Add(""); if (lovroEvent.Type == LovroEventType.DiaperChanged) { LovroBaseEvent diaperLastChanged = context.BaseEvents.Where(item => item.Type == LovroEventType.DiaperChanged && item.ID != lovroEvent.ID && item.Time < lovroEvent.Time).OrderByDescending(item => item.Time).FirstOrDefault(); viewItem.SubItems.Add(diaperLastChanged == null ? "" : (lovroEvent.Time - diaperLastChanged.Time).ToString(@"hh\:mm")); } else if (lovroEvent.Type == LovroEventType.WokeUp) { LovroBaseEvent lastFellAsleepEvent = context.BaseEvents.Where(item => item.Type == LovroEventType.FellAsleep && item.Time < lovroEvent.Time).OrderByDescending(item => item.Time).FirstOrDefault(); if (lastFellAsleepEvent != null) viewItem.SubItems.Add((lovroEvent.Time - lastFellAsleepEvent.Time).ToString(@"hh\:mm")); } else viewItem.SubItems.Add(""); viewItem.SubItems.Add(lovroEvent.Note); return viewItem; }
private void SetImageIndex(LovroBaseEvent lovroEvent, ListViewItem viewItem) { int imageIndex = GetImageIndexForEventType(lovroEvent); if (imageIndex != -1) viewItem.ImageIndex = imageIndex; }
private bool AskForDetails(LovroBaseEvent lovroEvent) { if (askForDetailsCheckBox.Checked || Control.ModifierKeys == Keys.Control || lovroEvent.Type == LovroEventType.Other) { using (var form = new AskForDetailsForm()) { var result = form.ShowDialog(); if (result == DialogResult.OK) { lovroEvent.Note = form.EnteredNote; lovroEvent.Time = form.EnteredTime; } else return false; } } return true; }
//šteka //private string GetEnumDescription(Type type, string value) //{ // FieldInfo fi = type.GetField(value); // DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); // return attributes.FirstOrDefault() != null ? attributes.FirstOrDefault().Description : "UNKNOWN"; //} private int GetImageIndexForEventType(LovroBaseEvent lovroEvent) { int result = -1; switch (lovroEvent.Type) { case LovroEventType.AteFood: return 3; case LovroEventType.Bathed: return 0; case LovroEventType.DiaperChanged: switch ((lovroEvent as LovroDiaperChangedEvent).Status) { case LovroDiaperStatus.Pissed: result = 2; break; case LovroDiaperStatus.Soiled: result = 1; break; default: break; } return result; case LovroEventType.FellAsleep: return 5; case LovroEventType.Pooped: return 4; case LovroEventType.WokeUp: return 6; case LovroEventType.Other: return 7; case LovroEventType.Default: return -1; default: return -1; } }
private void AddEvent(LovroBaseEvent lovroEvent) { if (!AskForDetails(lovroEvent)) { return; } using (var context = new LovroContext(connectionString)) { //context.AddBaseEvent(lovroEvent); context.BaseEvents.Add(lovroEvent); context.SaveChanges(); } }