public static bool InsertPrescriptionFromXML(Models.PrescriptionClass obj) { using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()) { var AttachPreObj = new PIPusingWPFModel.Prescription() { PrescriptionId = obj.PrescriptionID, PatientId = obj.Patient.PatientID, Did = obj.Doctor.ID, Date = Convert.ToDateTime(obj.Date).ToString(cultureInfo), Status = false, Diagnosis = obj.Patient.SymptomDescription, Doctor = conn.Doctors.Where(a => a.Did.Equals(obj.Doctor.ID)).FirstOrDefault(), Patient = conn.Patients.Where(a => a.PatientId.Equals(obj.Patient.PatientID)).FirstOrDefault() }; try { conn.Prescriptions.Add(AttachPreObj); conn.SaveChanges(); } catch (Exception e) { MessageBox.Show("InsertPrescriptionFromXML:" + e.Message + "\n" + e.StackTrace); return(false); } } return(true); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool SaveInDB(Models.PrescriptionClass obj) { PIPusingWPFModel.Prescription result; using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()) { try { result = conn.Prescriptions.Where(a => a.PrescriptionId.Equals(obj.PrescriptionID)).FirstOrDefault(); } catch (Exception e) { //MessageBox.Show("Query : " + e.Message); return(false); } } //如果已经存在但有修改的地方,则先删除 if (result != null) { var resultDate = Convert.ToDateTime(result.Date); var targetDate = Convert.ToDateTime(obj.Date); if (resultDate.Equals(targetDate)) { return(true); } else { try { if (!DeletePrescriptionByPrescriptionID(obj.PrescriptionID)) { throw new Exception("DeletePrescriptionByPrescriptionID"); } if (!DeleteDrugByPrescriptionID(obj.PrescriptionID)) { throw new Exception("DeleteDrugByPrescriptionID"); } } catch (Exception e) { MessageBox.Show("1:" + e.Message); return(false); } } } try { UpdatePrescriptionAndDrugsTogether(obj); } catch (Exception e) { MessageBox.Show("3:" + e.Message); return(false); } return(true); }
/// <summary> /// 根据处方ID删除处方 /// </summary> /// <param name="prescriptionID"></param> /// <returns></returns> public static bool DeletePrescriptionByPrescriptionID(string prescriptionID) { using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()){ try{ conn.Prescriptions.Remove(conn.Prescriptions.Where(p => p.PrescriptionId.Equals(prescriptionID)).FirstOrDefault()); conn.SaveChanges(); }catch (Exception ex) { return(false); } return(true); } }
/// <summary> /// /// </summary> /// <param name="list"></param> /// <returns></returns> public static bool InsertDrugsByList(List <PIPusingWPFModel.Drug> list) { using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()){ try{ conn.Drugs.AddRange(list); conn.SaveChanges(); }catch (Exception ex) { return(false); } return(true); } }
/// <summary> /// 根据处方ID来删除处方药品 /// </summary> /// <param name="prescriptionId"></param> /// <returns></returns> public static bool DeleteDrugByPrescriptionID(string prescriptionId) { using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()) { try { var delDrugObjCollection = conn.Drugs.Where(a => a.PrescriptionId.Equals(prescriptionId)).ToList(); conn.Drugs.RemoveRange(delDrugObjCollection); conn.SaveChanges(); } catch (Exception ex) { return(false); } return(true); } }
private void DoWork_handle(object sender, DoWorkEventArgs e) { //1. Query Data object using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()) { var prescriptionResult = conn.Prescriptions.Where(a => a.PrescriptionId.Equals(PrescriptionID)).First(); prescriptionTable = DAO.ToDataTable.ToDataTableMethodForObject(prescriptionResult); var patientResult = conn.Patients.Where(a => a.PatientId.Equals(prescriptionResult.PatientId)).First(); patientTable = DAO.ToDataTable.ToDataTableMethodForObject(patientResult); var doctorResult = conn.Doctors.Where(a => a.Did.Equals(prescriptionResult.Did)).First(); doctorTable = DAO.ToDataTable.ToDataTableMethodForObject(doctorResult); var result = conn.Drugs.Where(a => a.PrescriptionId.Equals(PrescriptionID)).ToList(); drugTable = DAO.ToDataTable.ToDataTableMethodForList(result); } Microsoft.Reporting.WinForms.ReportDataSource reportDataSource = new Microsoft.Reporting.WinForms.ReportDataSource(); reportDataSource.Name = "DrugsDataSet"; reportDataSource.Value = drugTable; //2. Load Data into report System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); _reportViewer.LocalReport.ReportPath = config.AppSettings.Settings["reportPath"].Value; //增加资源 _reportViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource() { Name = "PatientDataSet", Value = patientTable }); _reportViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource() { Name = "DoctorDataSet", Value = doctorTable }); _reportViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource() { Name = "PrescriptionDataSet", Value = prescriptionTable }); _reportViewer.LocalReport.DataSources.Add(reportDataSource); _reportViewer.RefreshReport(); //3. show report }
public void DoctorInfoBlock_Loaded(object send, RoutedEventArgs args) { id = StaticMethod.ConfigManagement.GetConfigValue(StaticMethod.ConfigManagement.ConfigSettingDoctorKey); using (PIPusingWPFModel.PIPEntities pip = new PIPusingWPFModel.PIPEntities()) { try { PIPusingWPFModel.Doctor temp = pip.Doctors.Where(a => a.Did.Equals(id)).First(); if (temp != null) { doctor = new Doctor_InfoDataModel() { ID = id, Department = temp.Department, Name = temp.Name } } ; else { doctor = new Doctor_InfoDataModel(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } this.DoctorName.SetBinding(Label.ContentProperty, new Binding("Name") { Source = doctor, Mode = BindingMode.OneWay }); this.DoctorID.SetBinding(Label.ContentProperty, new Binding("ID") { Source = doctor, Mode = BindingMode.OneWay }); this.Department.SetBinding(Label.ContentProperty, new Binding("Department") { Source = doctor, Mode = BindingMode.OneWay }); }
/// <summary> /// 将处方信息载入进相应区域 InfomationBlock /// </summary> /// <param name="prescriptionID"></param> private void LoadFileToInfomationBlockAction(string prescriptionID) { var result = StaticMethod.PrescriptionListManagement.PrescriptionList.Where(a => a.PrescriptionID.Equals(prescriptionID)).First(); patientInfoSource.PatientName = result.Patient.Name; patientInfoSource.PatientID = result.Patient.PatientID; patientInfoSource.PatientSex = result.Patient.Sex; patientInfoSource.PatientAge = result.Patient.Age; patientInfoSource.Diagnosis = result.Patient.SymptomDescription; this.MyPrescriptionInfoBlock.PrescriptionIDLabel.Content = prescriptionID; using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()) { try { var queryDrugsList = conn.Drugs.Where(drug => drug.PrescriptionId.Equals(prescriptionID)).ToList(); this.MyPrescriptionInfoBlock.DrugsDataGrid.ItemsSource = queryDrugsList; } catch (Exception e) { MessageBox.Show(string.Format("{0} : {1}", e.Message, e.StackTrace)); } } MessageBox.Show("Loading ...:"); }
public void InitializeListBoxItem() { using (PIPusingWPFModel.PIPEntities conn = new PIPusingWPFModel.PIPEntities()) { } }