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);
 }
        public void SaveAsXMLFile(Models.PrescriptionClass info, string filename)
        {
            System.IO.FileStream   fs = new System.IO.FileStream(filename, System.IO.FileMode.OpenOrCreate);
            DataContractSerializer sr = new DataContractSerializer(info.GetType());

            sr.WriteObject(fs, info);
            fs.Close();
        }
Esempio n. 3
0
        /// <summary>
        /// 业务逻辑处理:执行载入文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pListLoaderWorker(object sender, DoWorkEventArgs e)
        {
            //获得处方文件数量
            List <string> fList = System.IO.Directory.GetFiles(@path).Where(file => file.Contains("P100") && file.Contains("RX100") && file.Contains(@"_")).ToList();
            int           total = fList.Count();
            string        msg   = total <= 0 ? "There is no file" : string.Empty;

            if (!string.IsNullOrEmpty(msg))
            {
                MessageBox.Show(msg);
                worker.CancelAsync();
                //this.LoadCancelAction();
                return;
            }

            //loadingProgressValue.TotalValue = total;
            //loadingProgressValue.DoingValue = 1;
            loadStartedAction(total);

            Dispatcher.Invoke(new Action(() =>
            {
                SetMaskLay(System.Windows.Visibility.Visible);
            }));
            try
            {
                for (int i = 1; i <= total; i++)
                {
                    Models.PrescriptionClass prescription = DAO.XmlSerializer.LoadFromXml(fList[i - 1], typeof(Models.PrescriptionClass)) as Models.PrescriptionClass;
                    var temp = new PrescriptionFileInfoListItemModel()
                    {
                        PrescriptionID = prescription.PrescriptionID, PatientName = prescription.Patient.Name, CreationDate = prescription.Date
                    };
                    //直接修改source也等于直接修改UI,从而导致异常。解决方案就是使用调解委托。
                    //第一次是全部载入进静态链表
                    if (!StaticMethod.PrescriptionListManagement.PrescriptionList.Contains(prescription))
                    {
                        StaticMethod.PrescriptionListManagement.PrescriptionList.Add(prescription);
                        DAO.PrescriptionDBHandle.SaveInDB(prescription);
                    }
                    ////update时候此判断可减少次数
                    //if (ListBoxItems.Where(obj=>obj.CreationDate.Equals(temp.CreationDate)).FirstOrDefault()==null)
                    //{
                    Dispatcher.Invoke(new Action(() =>
                    {
                        ListBoxItems.Add(temp);
                    }));
                    //}
                    worker.ReportProgress(i);
                    System.Threading.Thread.Sleep(100);
                }
                //this.PrescriptionListBox.ItemsSource = _ListBoxItems;
            }
            catch (Exception ex)
            {
                MessageBox.Show("pListLoaderWorker : " + ex.Message);
            }
        }
 /// <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>
 /// 载入文件信息by处方ID
 /// </summary>
 /// <param name="prescriptonID"></param>
 private void LoadFileInfoAction(string prescriptonID)
 {
     try
     {
         Models.PrescriptionClass obj = StaticMethod.PrescriptionListManagement.PrescriptionList.Where(a => a.PrescriptionID.Equals(prescriptonID)).First();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.StackTrace + "\n" + e.Message);
     }
 }
 /// <summary>
 /// 转换药品类型
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="drug"></param>
 /// <returns></returns>
 private static PIPusingWPFModel.Drug xmlDrugObjToDBDrugObj(Models.PrescriptionClass obj, Models.DrugClass drug)
 {
     return(new PIPusingWPFModel.Drug()
     {
         PrescriptionId = obj.PrescriptionID,
         DrugName = drug.DrugName,
         DosagePerTime = drug.DosagePerTime_Value + drug.DosagePerTime_Unit,
         Instruction = drug.Instruction,
         TimeDuration = drug.TimeDuration,
         TimesPerDay = drug.TimesPerDay,
         Usage = drug.Usage,
         WhenAfternoon = drug.WhenAfternoon ? "√" : "x",
         WhenEvening = drug.WhenEvening ? "√" : "x",
         WhenMorning = drug.WhenMorning ? "√" : "x"
     });
 }
        private ListViewItem CreateViewItemByClass(Models.PrescriptionClass sourceObj)
        {
            ListViewItem newItem = new ListViewItem();

            try
            {
                newItem.SubItems.Clear();
                newItem.SubItems[0].Text = sourceObj.PrescriptionID;
                newItem.SubItems.Add(sourceObj.Patient.Name);
                newItem.SubItems.Add(sourceObj.Date);
            }
            catch
            {
                MessageBox.Show("CreateViewItemByClass");
                return(null);
            }
            return(newItem);
        }
        /// <summary>
        /// 同时更新药品及处方信息
        /// </summary>
        /// <param name="obj"></param>
        public static void UpdatePrescriptionAndDrugsTogether(Models.PrescriptionClass obj)
        {
            if (!InsertPrescriptionFromXML(obj))
            {
                throw new Exception("InsertPrescriptionFromXML");
            }
            List <PIPusingWPFModel.Drug> list = new List <PIPusingWPFModel.Drug>();

            foreach (var drug in obj.Drugs)
            {
                var AttachDrugObj = xmlDrugObjToDBDrugObj(obj, drug);
                list.Add(AttachDrugObj);
            }
            if (!InsertDrugsByList(list))
            {
                throw new Exception("InsertDrugsByList");
            }
        }
 private void LoadingPrescriptionFiles()
 {
     prescriptionList = new List <Models.PrescriptionClass>();
     foreach (string file in fileList)
     {
         Models.PrescriptionClass obj = DAO.XmlSerializer.LoadFromXml(file, typeof(Models.PrescriptionClass)) as Models.PrescriptionClass;
         try
         {
             if (obj.Doctor.ID.Equals(Doctor.ID))
             {
                 prescriptionList.Add(obj);
             }
         }
         catch
         {
             MessageBox.Show("LoadingPrescriptionFiles");
             break;
         }
     }
 }