/*获取指定时间区间中药房所有的交易记录*/ public AllTransactionInfoEntity GetTransactionHistory(string pharmacyID, DateTime? startDate, DateTime? endDate) { DrPEDatabaseEntities DEntities = new DrPEDatabaseEntities(); /*查询[startDate, endDate]区间中产生的交易记录*/ var transactions = from t in DEntities.Transactions where ((startDate <= t.Date) && (t.Date <= endDate) && (t.PharmacyID == pharmacyID)) orderby t.Date descending select t; int cnt = 0; int transactionCount = transactions.Count(); AllTransactionInfoEntity allTransactionInfoEntity = null; if (transactionCount > 0) { allTransactionInfoEntity = new AllTransactionInfoEntity(); allTransactionInfoEntity.Count = transactionCount; allTransactionInfoEntity.transactionInfoEntity = new TransactionInfoEntity[transactionCount]; foreach (var t in transactions) { allTransactionInfoEntity.transactionInfoEntity[cnt] = new TransactionInfoEntity(); User user = (from u in DEntities.Users where u.UserID == t.UserID select u).FirstOrDefault(); allTransactionInfoEntity.transactionInfoEntity[cnt].TransactionID = t.TransactionID; allTransactionInfoEntity.transactionInfoEntity[cnt].LastName = user.LastName; allTransactionInfoEntity.transactionInfoEntity[cnt].FirstName = user.FirstName; allTransactionInfoEntity.transactionInfoEntity[cnt].PharmacyID = pharmacyID; allTransactionInfoEntity.transactionInfoEntity[cnt].Amount = t.Amount; allTransactionInfoEntity.transactionInfoEntity[cnt].Date = t.Date; if (t.Detail == null) { allTransactionInfoEntity.transactionInfoEntity[cnt].Action = "[Pending]"; } else { allTransactionInfoEntity.transactionInfoEntity[cnt].Action = "[Taken]"; } cnt++; } } return allTransactionInfoEntity; }
/*获取指定时间区间中药房所有的交易记录,仅供Pharmacy调用*/ public AllTransactionInfoEntity GetTransactionHistory(DateTime? startDate, DateTime? endDate) { AllTransactionInfoEntity allTransactionInfoEntity = null; if (confirmed == false) { allTransactionInfoEntity = new AllTransactionInfoEntity(); allTransactionInfoEntity.ErrorMessage = "253 Not Logged in Yet! @Logic"; } else { allTransactionInfoEntity = pharmacyDAO.GetTransactionHistory(confirmedPharmacyID, startDate, endDate); if (allTransactionInfoEntity == null) { allTransactionInfoEntity = new AllTransactionInfoEntity(); allTransactionInfoEntity.ErrorMessage = String.Format("254 No Transaction Record of {0} Between {1} and {2}! @Logic", confirmedPharmacyID, startDate, endDate); } } return allTransactionInfoEntity; }
/*获取指定时间区间中药房所有的交易记录*/ public AllTransactionInfo GetTransactionHistory(DateTime? startDate, DateTime? endDate) { AllTransactionInfoEntity allTransactionInfoEntity = null; if (startDate == null) { allTransactionInfoEntity = new AllTransactionInfoEntity(); allTransactionInfoEntity.ErrorMessage = "251 Empty StartDate! @Service"; } else if (endDate == null) { allTransactionInfoEntity = new AllTransactionInfoEntity(); allTransactionInfoEntity.ErrorMessage = "252 Empty EndDate! @Service"; } else { allTransactionInfoEntity = pharmacyLogic.GetTransactionHistory(startDate, endDate); } AllTransactionInfo allTransactionInfo = new AllTransactionInfo(); TranslateAllTransactionInfoEntityToAllTransactionInfoContractData(allTransactionInfoEntity, allTransactionInfo); return allTransactionInfo; }
/*将AllTransactionInfo对应的Entity翻译为数据契约,调用 TranslateTransactionInfoEntityToTransactionInfoContractData()方法*/ private void TranslateAllTransactionInfoEntityToAllTransactionInfoContractData( AllTransactionInfoEntity allTransactionInfoEntity, AllTransactionInfo allTransactionInfo) { allTransactionInfo.ErrorMessage = allTransactionInfoEntity.ErrorMessage; allTransactionInfo.Count = allTransactionInfoEntity.Count; allTransactionInfo.transactionInfo = new TransactionInfo[allTransactionInfo.Count]; for (int i = 0; i < allTransactionInfo.Count; i++) { allTransactionInfo.transactionInfo[i] = new TransactionInfo(); TranslateTransactionInfoEntityToTransactionInfoContractData(allTransactionInfoEntity.transactionInfoEntity[i], allTransactionInfo.transactionInfo[i]); } }
/*获取指定时间区间中药房所有的交易记录*/ public AllTransactionInfoEntity GetTransactionHistory(DateTime? startDate, DateTime? endDate) { if (confirmed == false) { AllTransactionInfoEntity allTransactionInfoEntity = new AllTransactionInfoEntity(); allTransactionInfoEntity.ErrorMessage = "443 Not Logged in Yet! @Logic"; return allTransactionInfoEntity; } else { return userDAO.GetTransactionHistory(confirmedUserID, startDate, endDate); } }