public IEnumerable <IMedRecords> GetMedRecordRange(string regno, string start_date, string end_date) { List <IMedRecords> records = new List <IMedRecords>(); using (SqlConnection conn = new SqlConnection(_connString)) { SqlCommand cmd = new SqlCommand("getPatientsMedRecordsByRange", conn) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@patient_regno", regno); cmd.Parameters.AddWithValue("@start_date", start_date ?? ""); cmd.Parameters.AddWithValue("@end_date", end_date ?? ""); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { IMedRecords record = new MedRecords { Id = Convert.ToInt32(reader["Id"]), entry_date = Convert.ToDateTime(reader["entry_date"]), amount = Convert.ToDecimal(reader["amount"]), patients_regno = reader["patients_regno"].ToString(), treatment = reader["treatment"].ToString() }; records.Add(record); } conn.Close(); } return(records); }
public ActionResult AddMedRecord(MedRecords model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Data not valid"); return(View(nameof(AddMedRecord), model)); } try { _repository.AddMedRecord(model); TempData["success"] = "Record added successfully"; } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(nameof(AddMedRecord), model)); } return(RedirectToAction("patients", new { regno = model.patients_regno })); }
public MedRecordViewModel(Employee employee) { DownloadMedRecords(); currentemployee = employee; FilterCollectionView.Filter = i => { if (_searchKey == "" || _searchKey == null) { return(true); } if (string.IsNullOrEmpty(FilterString)) { return(true); } if (_searchKey == "Фамилия") { MedRecord m = i as MedRecord; return(m.Surname.ToString().StartsWith(FilterString)); } if (_searchKey == "Имя") { MedRecord m = i as MedRecord; return(m.Name.ToString().StartsWith(FilterString)); } if (_searchKey == "Отчество") { MedRecord m = i as MedRecord; return(m.Patronymic.ToString().StartsWith(FilterString)); } if (_searchKey == "Город") { MedRecord m = i as MedRecord; return(m.City.ToString().StartsWith(FilterString)); } if (_searchKey == "Улица") { MedRecord m = i as MedRecord; return(m.Street.ToString().StartsWith(FilterString)); } if (_searchKey == "Дом") { MedRecord m = i as MedRecord; return(m.Home.ToString().StartsWith(FilterString)); } else { return(true); } }; EditMedRecord = new DelegateCommand(() => { editoradd = false; selectedMedRecord?.BeginEdit(); var w = new MedRecordEdit(); w.DataContext = this; w.ShowDialog(); }, () => selectedMedRecord != null); AddMedRecord = new DelegateCommand(() => { editoradd = true; MedRecord NewMedRecord = new MedRecord(); SelectedMedRecord = NewMedRecord; var w = new MedRecordEdit(); w.DataContext = this; w.ShowDialog(); }); SaveMedRecord = new DelegateCommand(() => { if (editoradd == true) { context.MedRecord.Add(selectedMedRecord); context.SaveChanges(); MedRecords.Add(SelectedMedRecord); } else { context.Entry(selectedMedRecord).State = EntityState.Modified; context.SaveChanges(); } }); RemoveMedRecord = new DelegateCommand(() => { if (MessageBox.Show("Удалить?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { context.Entry(selectedMedRecord).State = EntityState.Deleted; MedRecords.Remove(selectedMedRecord); context.SaveChanges(); } else { return; } }, () => selectedMedRecord != null); CanselEdit = new DelegateCommand(() => { if (editoradd == false) { if (selectedMedRecord == null) { return; } SelectedMedRecord.CancelEdit(); } else { return; } }); MedRecordOpen = new DelegateCommand(() => { MedRecordOpenViewModel viewmodel = new MedRecordOpenViewModel(SelectedMedRecord, currentemployee); var w = new OpenMedRecord(); w.DataContext = viewmodel; w.ShowDialog(); }, () => currentemployee.Post.Name == "Врач" || currentemployee.Post.Name == "Администратор"); }