/*药房登录: 向数据库提交select查询,若成功则并更新LastLoginDate域,将结果转写为Entity*/ public PharmacyInfoEntity Login(string pharmacyID, string password) { /*数据库访问实例*/ DrPEDatabaseEntities DEntities = new DrPEDatabaseEntities(); /*查询(pharmacyID,password)对是否匹配*/ Pharmacy pharmacy = (from p in DEntities.Pharmacies where ((p.PharmacyID == pharmacyID) && (p.Password == password)) select p).FirstOrDefault(); /*将结果转写为Entity,仅转写必要登录信息*/ PharmacyInfoEntity pharmacyInfoEntity = null; if (pharmacy != null) { pharmacyInfoEntity = new PharmacyInfoEntity() { PharmacyID = pharmacyID, Name = pharmacy.Name, LastLoginDate = pharmacy.LastLoginDate }; /*更新该Pharmacy的LastLoginDate域*/ pharmacy.LastLoginDate = DateTime.Now; DEntities.SaveChanges(); } return pharmacyInfoEntity; }
/*获取特定药房信息:提交PharmacyID,返回该药房的信息*/ public PharmacyInfoEntity GetPharmacyInfo(string pharmacyID) { PharmacyInfoEntity pharmacyInfoEntity = openAccessDAO.GetPharmacyInfo(pharmacyID); if (pharmacyInfoEntity == null) { pharmacyInfoEntity = new PharmacyInfoEntity(); pharmacyInfoEntity.ErrorMessage = "146 No Pharmacy of " + pharmacyID + "! @Logic"; } return pharmacyInfoEntity; }
/*获取特定药房信息:提交PharmacyID,返回该药房的信息*/ public PharmacyInfo GetPharmacyInfo(string pharmacyID) { PharmacyInfoEntity pharmacyInfoEntity = null; if (pharmacyID == null) { pharmacyInfoEntity = new PharmacyInfoEntity(); pharmacyInfoEntity.ErrorMessage = "116 Empty pharmacyID! @Service"; } else { pharmacyInfoEntity = openAccessLogic.GetPharmacyInfo(pharmacyID); } PharmacyInfo pharmacyInfo = new PharmacyInfo(); TranslatePharmacyInfoEntityToPharmacyInfoContractData(pharmacyInfoEntity, pharmacyInfo); return pharmacyInfo; }
/*药房登录:若ID和Password均不为空,则转发至DL,将结果翻译为数据契约*/ public PharmacyInfo Login(string pharmacyID, string password) { PharmacyInfoEntity pharmacyInfoEntity = null; if (pharmacyID == null) { pharmacyInfoEntity = new PharmacyInfoEntity(); pharmacyInfoEntity.ErrorMessage = "201 Empty PharmacyID! @Service"; } else if (password == null) { pharmacyInfoEntity = new PharmacyInfoEntity(); pharmacyInfoEntity.ErrorMessage = "202 Empty Password! @Service"; } else { pharmacyInfoEntity = pharmacyLogic.Login(pharmacyID, password); } PharmacyInfo pharmacyInfo = new PharmacyInfo(); TranslatePharmacyInfoEntityToPharmacyInfoContractData(pharmacyInfoEntity, pharmacyInfo); return pharmacyInfo; }
/*药房登录: 向DAL提交查询,并推测错误代码*/ public PharmacyInfoEntity Login(string pharmacyID, string password) { PharmacyInfoEntity pharmacyInfoEntity = null; if ((confirmed == true) && (confirmedPharmacyID == pharmacyID)) { pharmacyInfoEntity = new PharmacyInfoEntity(); pharmacyInfoEntity.ErrorMessage = "203 " + pharmacyID + " Already Logged In! @Logic"; } else { pharmacyInfoEntity = pharmacyDAO.Login(pharmacyID, password); if (pharmacyInfoEntity == null) { pharmacyInfoEntity = new PharmacyInfoEntity(); pharmacyInfoEntity.ErrorMessage = "204 Wrong pharmacyID or Password! @Logic"; } else { confirmed = true; confirmedPharmacyID = pharmacyInfoEntity.PharmacyID; } } return pharmacyInfoEntity; }
/*将PharmacyInfo对应的Entity翻译为数据契约*/ private void TranslatePharmacyInfoEntityToPharmacyInfoContractData( PharmacyInfoEntity pharmacyInfoEntity, PharmacyInfo pharmacyInfo) { pharmacyInfo.ErrorMessage = pharmacyInfoEntity.ErrorMessage; pharmacyInfo.PharmacyID = pharmacyInfoEntity.PharmacyID; pharmacyInfo.Name = pharmacyInfoEntity.Name; pharmacyInfo.City = pharmacyInfoEntity.City; pharmacyInfo.Address = pharmacyInfoEntity.Address; pharmacyInfo.Latitude = pharmacyInfoEntity.Latitude; pharmacyInfo.Longitude = pharmacyInfoEntity.Longitude; pharmacyInfo.HospitalID = pharmacyInfoEntity.HospitalID; pharmacyInfo.Phone = pharmacyInfoEntity.Phone; pharmacyInfo.Fax = pharmacyInfoEntity.Fax; pharmacyInfo.LastLoginDate = pharmacyInfoEntity.LastLoginDate; }
/*获取特定药房信息:提交PharmacyID,返回该药房的信息*/ public PharmacyInfoEntity GetPharmacyInfo(string pharmacyID) { DrPEDatabaseEntities DEntities = new DrPEDatabaseEntities(); /*查询PharmacyID是否存在*/ Pharmacy pharmacy = (from p in DEntities.Pharmacies where p.PharmacyID == pharmacyID select p).FirstOrDefault(); PharmacyInfoEntity pharmacyInfoEntity = null; if (pharmacy != null) { pharmacyInfoEntity = new PharmacyInfoEntity(); pharmacyInfoEntity.PharmacyID = pharmacy.PharmacyID; pharmacyInfoEntity.Name = pharmacy.Name; pharmacyInfoEntity.City = pharmacy.City; pharmacyInfoEntity.Address = pharmacy.Address; pharmacyInfoEntity.Latitude = pharmacy.Latitude; pharmacyInfoEntity.Longitude = pharmacy.Longitude; pharmacyInfoEntity.HospitalID = pharmacy.HospitalID; pharmacyInfoEntity.Phone = pharmacy.Phone; pharmacyInfoEntity.Fax = pharmacy.Fax; } return pharmacyInfoEntity; }