/*查询处方单在特定药房的花费,仅供Pharmacy调用*/ public PrescriptionCostEntity GetPrescriptionCost(string sPrescriptionID, string password) { PrescriptionCostEntity prescriptionCostEntity = null; if (confirmed == false) { prescriptionCostEntity = new PrescriptionCostEntity(); prescriptionCostEntity.ErrorMessage = "213 Not Logged in Yet! @Logic"; } else { prescriptionCostEntity = pharmacyDAO.GetPrescriptionCost(sPrescriptionID, confirmedPharmacyID, password); } return prescriptionCostEntity; }
/*查询处方单在特定药房的花费*/ public PrescriptionCost GetPrescriptionCost(string sPrescriptionID, string password) { PrescriptionCostEntity prescriptionCostEntity = null; if (sPrescriptionID == null) { prescriptionCostEntity = new PrescriptionCostEntity(); prescriptionCostEntity.ErrorMessage = "211 Empty PrescriptionID! @Service"; } else if (password == null) { prescriptionCostEntity = new PrescriptionCostEntity(); prescriptionCostEntity.ErrorMessage = "212 Empty User Password! @Service"; } else { prescriptionCostEntity = pharmacyLogic.GetPrescriptionCost(sPrescriptionID, password); } PrescriptionCost prescriptionCost = new PrescriptionCost(); TranslatePrescriptionCostEntityToPrescriptionCostContractData(prescriptionCostEntity, prescriptionCost); return prescriptionCost; }
/*将PrescriptionCost对应的Entity翻译为数据契约*/ private void TranslatePrescriptionCostEntityToPrescriptionCostContractData( PrescriptionCostEntity prescriptionCostEntity, PrescriptionCost prescriptionCost) { prescriptionCost.ErrorMessage = prescriptionCostEntity.ErrorMessage; prescriptionCost.Count = prescriptionCostEntity.Count; prescriptionCost.LastName = prescriptionCostEntity.LastName; prescriptionCost.FirstName = prescriptionCostEntity.FirstName; prescriptionCost.UserBalance = prescriptionCostEntity.UserBalance; prescriptionCost.Amount = prescriptionCostEntity.Amount; prescriptionCost.PharmacyID = prescriptionCostEntity.PharmacyID; prescriptionCost.physicID = new string[prescriptionCost.Count]; prescriptionCost.number = new int[prescriptionCost.Count]; prescriptionCost.price = new Decimal?[prescriptionCost.Count]; for (int i = 0; i < prescriptionCost.Count; i++) { prescriptionCost.physicID[i] = prescriptionCostEntity.physicID[i]; prescriptionCost.number[i] = prescriptionCostEntity.number[i]; prescriptionCost.price[i] = prescriptionCostEntity.price[i]; } }
/*查询处方单在特定药房的花费,供User调用。*/ public PrescriptionCostEntity GetPrescriptionCost(Guid gPrescriptionID, string pharmacyID) { if (confirmed == false) { PrescriptionCostEntity prescriptionCostEntity = new PrescriptionCostEntity(); prescriptionCostEntity.ErrorMessage = "Not Logged in Yet! @Logic"; return prescriptionCostEntity; } else { return userDAO.GetPrescriptionCost(gPrescriptionID, pharmacyID); } }
/*查询处方单在特定药房的花费,供User和Pharmacy调用。*/ public PrescriptionCostEntity GetPrescriptionCost(string sPrescriptionID, string pharmacyID, string password) { DrPEDatabaseEntities DEntities = new DrPEDatabaseEntities(); PrescriptionCostEntity prescriptionCostEntity = new PrescriptionCostEntity(); /*获取处方信息*/ Guid gPrescriptionID = Guid.Empty; try { gPrescriptionID = new Guid(sPrescriptionID); } catch { prescriptionCostEntity.ErrorMessage = "214 Wrong Prescription GUID! @Data"; return prescriptionCostEntity; } Prescription prescription = (from p in DEntities.Prescriptions where p.PrescriptionID == gPrescriptionID select p).FirstOrDefault(); /*若处方不存在*/ if (prescription == null) { prescriptionCostEntity.ErrorMessage = "215 No Such Prescription! @Data"; return prescriptionCostEntity; } /*获取所属病历信息*/ CaseHistory caseHistory = (from c in DEntities.CaseHistories where c.PrescriptionID == gPrescriptionID select c).FirstOrDefault(); /*若处方不属于任何病历*/ if (caseHistory == null) { prescriptionCostEntity.ErrorMessage = "216 No Case Has This Prescription! @Data"; return prescriptionCostEntity; } /*获取病历所属用户信息*/ User user = (from u in DEntities.Users where ((u.UserID == caseHistory.UserID) && (u.Password == password)) select u).FirstOrDefault(); /*若密码错误*/ if (user == null) { prescriptionCostEntity.ErrorMessage = "217 Wrong Password! @Data"; return prescriptionCostEntity; } /*填入用户名字信息*/ prescriptionCostEntity.LastName = user.LastName; prescriptionCostEntity.FirstName = user.FirstName; /*解析Detail域内容,并计算当前药店处方花费*/ int cnt = 0; int pos = 0; Decimal? amount = 0; string sPhysicID = null; string sNumber = null; string[] detail = prescription.Detail.Split(';'); prescriptionCostEntity.physicID = new string[detail.Length]; prescriptionCostEntity.number = new int[detail.Length]; prescriptionCostEntity.price = new Decimal?[detail.Length]; foreach (string s in detail) { /*逐条解析Detail域内容*/ pos = s.IndexOf(':'); if (pos < 0) { break; } sPhysicID = s.Substring(0, pos); sNumber = s.Substring(pos + 1); prescriptionCostEntity.physicID[cnt] = sPhysicID; prescriptionCostEntity.number[cnt] = Convert.ToInt32(sNumber); /*在药店数据库中查询该药品的价格*/ PharmacyDatabase pharmacyDatabase = (from p in DEntities.PharmacyDatabases where ((p.PhysicID == sPhysicID) && (p.PharmacyID == pharmacyID)) select p).FirstOrDefault(); if (pharmacyDatabase == null) { /*若药店缺少某种药物*/ prescriptionCostEntity.ErrorMessage = "218 Medicine " + sPhysicID + " missing! @Data"; return prescriptionCostEntity; } else if (pharmacyDatabase.Price == null) { /*若药店某种药物价格缺失*/ prescriptionCostEntity.ErrorMessage = "219 Medicine " + sPhysicID + " unknown! @Data"; return prescriptionCostEntity; } else { /*记录价格,并计算总价*/ prescriptionCostEntity.price[cnt] = pharmacyDatabase.Price; amount += (pharmacyDatabase.Price) * (prescriptionCostEntity.number[cnt]); } cnt++; } prescriptionCostEntity.Count = cnt; prescriptionCostEntity.UserBalance = user.Balance; prescriptionCostEntity.PharmacyID = pharmacyID; prescriptionCostEntity.Amount = amount; return prescriptionCostEntity; }