async void saveNewDrug() { int index = GetDrugIndex(); try { Lieky newDrug = new Lieky() { LiekId = index, Nazov = DrugName, Pocet = DrugDose, Dlhodobo = RepeatedDrug, Poznamka = Note }; _context.Drugs.Add(newDrug); } catch (Exception s) { throw s; } try { _context.SaveChanges(); } catch (Exception e) { throw e; } UserDialogs.Instance.Alert("Liek bol pridaný", "", "OK"); await Application.Current.MainPage.Navigation.PushAsync(new AddTimesPage()); }
private void loadDrug() { Lieky l = new Lieky { LiekId = 1, Nazov = "flector" }; Cas_Davkovania cd = new Cas_Davkovania { Cas = "2017-01-01T12:25:04Z", CasDavkovaniaId = 1, LiekyFK = 1 }; _context.Drugs.Add(l); _context.DrugTakeTime.Add(cd); try { _context.SaveChanges(); } catch (Exception e) { //throw e; } }
public string FindActiveDrug(string timestamp) { DateTime convertedDate = DateTime.Parse(timestamp); var allDrugs = context.DrugTakeTime.ToList(); foreach (var d in allDrugs) { try { DateTime takeDate = DateTime.Parse(d.Cas); DateTime takeTime = DateTime.Parse(takeDate.ToShortTimeString()); DateTime convTime = DateTime.Parse(convertedDate.ToShortTimeString()); TimeSpan diff = convTime - takeTime; if (diff.TotalMinutes <= 120) { Lieky liek = context.Drugs.Where(x => x.LiekId == d.LiekyFK).First(); return(liek.Nazov); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception parse date " + e.ToString()); } } return(""); }
private int GetDrugIndex() { int index; if (!_context.Drugs.Any()) { index = 1; } else { Lieky tmp = _context.Drugs.FirstOrDefault(t => t.LiekId == _context.Drugs.Max(x => x.LiekId)); index = tmp.LiekId; } return(index); }
public void FillDrugList() { ContDrugList.Clear(); if (_context.Drugs.Any()) { var mojeLieky = _context.Drugs.ToList(); int i = 0; System.Diagnostics.Debug.WriteLine("Moje som tu "); foreach (var a in mojeLieky) { System.Diagnostics.Debug.WriteLine("moje lieky" + i++ + a.Nazov); ContDrugList.Add(a); } } else { Lieky liek = new Lieky { Nazov = "V systéme nie je žiaden liek" }; ContDrugList.Add(liek); } }