public static List <StandardPackageType> GetAllStandardPackageTypes(SqlConnection connection) { var packageTypes = new List <StandardPackageType>(); string query = "SELECT PackageTypeId, Description, NumberOfMedications, ShelfLifeUnitType, ShelfLifeUnits, TemperatureSensitive, Value FROM StandardPackageType ORDER BY PackageTypeId"; var cmd = new SqlCommand(query); cmd.Connection = connection; using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) { while (reader.Read()) { var packageType = new StandardPackageType(); packageType.PackageTypeId = Convert.ToInt32(reader["PackageTypeId"]); packageType.Description = (string)reader["Description"]; packageType.NumberOfMedications = Convert.ToInt32(reader["NumberOfMedications"]); packageType.ShelfLifeUnitType = (ShelfLifeUnitType)Enum.Parse(typeof(ShelfLifeUnitType), (string)reader["ShelfLifeUnitType"], true); packageType.ShelfLifeUnits = Convert.ToInt32(reader["ShelfLifeUnits"]); packageType.TemperatureSensitive = (bool)reader["TemperatureSensitive"]; packageType.Value = (decimal)reader["Value"]; packageTypes.Add(packageType); } } return(packageTypes); }
public ActionResult Register(PackageRegisterViewModel model) { var packageService = GetPackageService(); var employeeService = GetEmployeeService(); if (ModelState.IsValid) { int packageId = 1; StandardPackageType selectedPackageType = packageService.GetStandardPackageType(model.StandardPackageTypeId); DistributionCentre selectedCentre = employeeService.GetDistributionCentre(model.LocationCentreId); string barCode; Result result = packageService.Register(selectedPackageType, selectedCentre, model.ExpirationDate, out barCode); if (result.Success) { model.BarCode = barCode; return(View("RegisterComplete", model)); } else { ModelState.AddModelError("", result.ErrorMessage); } } model.DistributionCentres = employeeService.GetAllDistributionCentres(); model.StandardPackageTypes = packageService.GetAllStandardPackageTypes(); return(View("Register", model)); }
public int InsertAudit(Employee employee, StandardPackageType packageType, List <string> barCodeList) { int auditId = DataAccess.InsertAudit(_connectionString, employee, packageType); DataAccess.InsertAuditPackages(_connectionString, auditId, packageType, barCodeList); return(auditId); }
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e) { if (e.CurrentStepIndex == 1) { var employeeUser = (EmployeeMembershipUser)System.Web.Security.Membership.GetUser(); Employee employee = _employeeService.Retrieve(employeeUser.UserName); StandardPackageType packageType = new StandardPackageType() { PackageTypeId = int.Parse(ddlPackageType.SelectedValue) }; List <string> barCodeList = ucPackageBarcode.GetBarcodes(); Result result = _packageService.PerformAudit(employee, packageType, barCodeList); if (result.Success) { litCompleteMessage.Text = "Audit completed successfully"; } else { litCompleteMessage.Text = string.Format("Audit Failed: {0}", result.ErrorMessage); } } }
/// <summary> /// Registers and Creates new Packages of a Standard Packahe Type for a given location and /// has the specified expiration date. The Barcode is generated from the Package Type Id, Expiration Date and Package Id /// </summary> /// <param name="packageType"></param> /// <param name="location"></param> /// <param name="expirationDate"></param> /// <param name="barcode"></param> /// <returns></returns> public Result Register(StandardPackageType packageType, DistributionCentre location, DateTime expirationDate, out string barcode) { var result = new Result { Success = true }; barcode = string.Empty; if (expirationDate < DateTime.Today) { result.Success = false; result.ErrorMessage = PackageResult.ExpirationDateCannotBeEarlierThanToday; return(result); } Package package = new Package { PackageType = packageType, CurrentLocation = location, CurrentStatus = PackageStatus.InStock, ExpirationDate = expirationDate }; int packageId = _packageRepository.Insert(package); package.PackageId = packageId; barcode = GenerateBarCode(package); package.BarCode = barcode; _packageRepository.Update(package); result.Id = package.PackageId; return(result); }
public static StandardPackageType GetStandardPackageType(SqlConnection connection, int packageTypeId) { StandardPackageType packageType = null; string query = "SELECT PackageTypeId, Description, NumberOfMedications, ShelfLifeUnitType, ShelfLifeUnits, TemperatureSensitive, Value FROM StandardPackageType WHERE PackageTypeId = @packageTypeId"; var cmd = new SqlCommand(query); cmd.Connection = connection; cmd.Parameters.AddWithValue("@packageTypeId", packageTypeId); using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) { if (reader.Read()) { packageType = new StandardPackageType(); packageType.PackageTypeId = Convert.ToInt32(reader["PackageTypeId"]); packageType.Description = (string)reader["Description"]; packageType.NumberOfMedications = Convert.ToInt32(reader["NumberOfMedications"]); packageType.ShelfLifeUnitType = (ShelfLifeUnitType)Enum.Parse(typeof(ShelfLifeUnitType), (string)reader["ShelfLifeUnitType"], true); packageType.ShelfLifeUnits = Convert.ToInt32(reader["ShelfLifeUnits"]); packageType.TemperatureSensitive = (bool)reader["TemperatureSensitive"]; packageType.Value = (decimal)reader["Value"]; } } return(packageType); }
public static int InsertPackageType(StandardPackageType t) { int newId = mockPackageTypeDb.Count(); t.PackageTypeId = newId; mockPackageTypeDb[newId] = t; return(newId); }
public StandardPackageType GetStandardPackageType(int packageId) { StandardPackageType packageTypes = null; packageTypes = DataAccess.GetStandardPackageType(_connectionString, packageId); return(packageTypes); }
public int UpdateInstockFromAudit(int auditId, DistributionCentre location, StandardPackageType packageType) { using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); return(DataAccess.UpdateInstockFromAudit(connection, auditId, location, packageType)); } }
protected void btnSave_OnClick(object sender, EventArgs e) { if (!Page.IsValid) { pnlErrorMessage.Visible = true; litErrorMessage.Text = "There are errors"; return; } int selectedPackageTypeId = int.Parse(ddlPackageType.SelectedValue); StandardPackageType selectedPackageType = _packageService.GetStandardPackageType(selectedPackageTypeId); int selectedCentreId = int.Parse(ddlLocation.SelectedValue); DistributionCentre selectedCentre = _employeeService.GetDistributionCentre(selectedCentreId); DateTime expirationDate = DateTime.Parse(Request.Form[txtExpirationDate.UniqueID]); SetExpirationDateTextBox(expirationDate); string barcode; Result result = _packageService.Register(selectedPackageType, selectedCentre, expirationDate, out barcode); if (!result.Success) { var err = new CustomValidator(); err.ValidationGroup = "userDetails"; err.IsValid = false; err.ErrorMessage = result.ErrorMessage; Page.Validators.Add(err); pnlErrorMessage.Visible = true; litErrorMessage.Text = "There are errors"; return; } pnlMessage.Visible = true; litMessage.Text = "Successfully saved"; litBarcode.Text = barcode; string strImageURL = "~/Handler/GenerateBarcodeImage.ashx?d=" + barcode; this.ImageBarcode.ImageUrl = strImageURL; this.ImageBarcode.Width = 400; this.ImageBarcode.Height = 150; this.ImageBarcode.Visible = true; ddlPackageType.Enabled = false; txtExpirationDate.Enabled = false; ddlLocation.Enabled = false; btnSave.Enabled = false; btnNext.Enabled = true; }
public void TestCalculateExpirationDate() { IPackageRepository packageRepository = new MockPackageRepository(); PackageService packageService = new PackageService(packageRepository); StandardPackageType packageType = MockDataAccess.GetPackageType(3); DateTime todaysDate = DateTime.Today; DateTime expirationDate = packageService.CalculateExpirationDate(packageType, todaysDate); Assert.AreEqual <DateTime>(todaysDate.AddMonths(packageType.ShelfLifeUnits), expirationDate); }
public static int AddPackage(StandardPackageType Type, string BarCode, DistributionCentre Location, PackageStatus Status, DateTime Expiration) { Package newPackage = new Package(); newPackage.BarCode = BarCode; newPackage.CurrentLocation = Location; newPackage.CurrentStatus = Status; newPackage.ExpirationDate = Expiration; newPackage.PackageType = Type; return(InsertPackage(newPackage)); }
public StandardPackageType GetStandardPackageType(int packageId) { StandardPackageType packageTypes = null; using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); packageTypes = DataAccess.GetStandardPackageType(connection, packageId); } return(packageTypes); }
public static int AddPackageType(string Description, int MedNumber, int ShelfLifeUnits, ShelfLifeUnitType UnitType, int Value) { StandardPackageType newType = new StandardPackageType(); newType.Description = Description; newType.NumberOfMedications = MedNumber; newType.ShelfLifeUnits = ShelfLifeUnits; newType.ShelfLifeUnitType = UnitType; newType.Value = Value; return(InsertPackageType(newType)); }
private Result DiscardPackage(int currentCentreId, string userName, string barCode) { MockPackageRepository packageRepository = new MockPackageRepository(); PackageService _packageService = new PackageService(packageRepository); Employee employee = MockDataAccess.GetEmployee(userName); Package package = MockDataAccess.GetPackage(barCode); package.CurrentLocation = MockDataAccess.GetDistributionCentre(currentCentreId); StandardPackageType spt2 = _packageService.GetStandardPackageType(package.PackageType.PackageTypeId); return(_packageService.Discard(package.BarCode, employee.Location, employee, package.ExpirationDate, spt2, package.PackageId)); }
public void TestRegisterPackageExpirationDateTooEarly() { IPackageRepository packageRepository = new MockPackageRepository(); PackageService packageService = new PackageService(packageRepository); StandardPackageType packageType = MockDataAccess.GetPackageType(3); DistributionCentre location = MockDataAccess.GetDistributionCentre(2); DateTime expirationDate = DateTime.Today.AddDays(-1); string barCode; var result = packageService.Register(packageType, location, expirationDate, out barCode); int newPackageId = result.Id; Assert.AreEqual <bool>(result.Success, false); Assert.AreEqual <string>(result.ErrorMessage, PackageResult.ExpirationDateCannotBeEarlierThanToday); }
public int InsertAudit(Employee employee, StandardPackageType packageType, List <string> barCodes) { using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); int auditId = DataAccess.InsertAudit(connection, employee, packageType); XElement barCodeXml = barCodes.GetBarCodeXML(); DataAccess.InsertAuditPackages(connection, auditId, packageType, barCodeXml); return(auditId); } }
public void TestRegisterPackage() { IPackageRepository packageRepository = new MockPackageRepository(); PackageService packageService = new PackageService(packageRepository); StandardPackageType packageType = MockDataAccess.GetPackageType(3); DistributionCentre location = MockDataAccess.GetDistributionCentre(2); DateTime expirationDate = DateTime.Today.AddMonths(2); string barCode; var result = packageService.Register(packageType, location, expirationDate, out barCode); int newPackageId = result.Id; string compareBarCode = string.Format("{0:D5}{1:yyMMdd}{2:D5}", packageType.PackageTypeId, expirationDate, newPackageId); Assert.AreEqual <string>(compareBarCode, barCode); }
protected void ddlPackageType_SelectedIndexChanged(object sender, EventArgs e) { if (ddlPackageType.SelectedValue == string.Empty) { txtExpirationDate.Text = string.Empty; return; } int selectedPackageTypeId = int.Parse(ddlPackageType.SelectedValue); StandardPackageType selectedPackageType = _packageService.GetStandardPackageType(selectedPackageTypeId); DateTime expirationDate = _packageService.CalculateExpirationDate(selectedPackageType, DateTime.Today); SetExpirationDateTextBox(expirationDate); }
public static int InsertAudit(string connectionString, Employee employee, StandardPackageType packageType) { // define INSERT query with parameters using (var ctx = new Entities(connectionString)) { Audit audit = new Audit(); audit.DateAudited = DateTime.Today; audit.DistributionCentreId = employee.Location.CentreId; audit.EmployeeId = employee.EmployeeId; audit.PackageTypeId = packageType.PackageTypeId; ctx.Audit.Add(audit); ctx.SaveChanges(); return(audit.AuditId); } }
/// <summary> /// Calculates Expiration Date based on the Shelf Life settings of the Standard Package Type /// </summary> /// <param name="packageType"></param> /// <param name="startDate"></param> /// <returns></returns> public DateTime CalculateExpirationDate(StandardPackageType packageType, DateTime startDate) { if (packageType == null) { return(DateTime.MinValue); } if (packageType.ShelfLifeUnitType == ShelfLifeUnitType.Month) { return(startDate.AddMonths(packageType.ShelfLifeUnits)); } else { return(startDate.AddDays(packageType.ShelfLifeUnits)); } }
private Result DistributePackage(int currentCentreId, string userName, string barCode) { DistributionCentre centre = new DistributionCentre(); centre.CentreId = currentCentreId; MockPackageRepository packageRepository = new MockPackageRepository(); PackageService _packageService = new PackageService(packageRepository); MockEmployeeRepository repository = new MockEmployeeRepository(); var employeeService = new EmployeeService(repository); Employee authEmployee = employeeService.Retrieve(userName); DateTime expirationDate = DateTime.Now; Package package = _packageService.Retrieve(barCode); StandardPackageType spt2 = _packageService.GetStandardPackageType(package.PackageType.PackageTypeId); return(_packageService.Distribute(package.BarCode, centre, authEmployee, expirationDate, spt2, package.PackageId)); }
public static void InsertAuditPackages(string connectionString, int auditId, StandardPackageType packageType, List <string> barCodeList) { using (var ctx = new Entities(connectionString)) { var selectedPackages = from p in ctx.Package join b in barCodeList on p.BarCode equals b select p.PackageId; foreach (var packageId in selectedPackages) { var auditPackage = new AuditPackage(); auditPackage.AuditId = auditId; auditPackage.PackageId = packageId; ctx.AuditPackage.Add(auditPackage); } ctx.SaveChanges(); } }
public void TestDiscard_HandleCentreNullReference() { DistributionCentre centre = new DistributionCentre(); centre = null; MockPackageRepository packageRepository = new MockPackageRepository(); PackageService _packageService = new PackageService(packageRepository); MockEmployeeRepository repository = new MockEmployeeRepository(); var employeeService = new EmployeeService(repository); Employee authEmployee = employeeService.Retrieve("rsmith"); DateTime expirationDate = DateTime.Now; Package package = _packageService.Retrieve("1232655456"); StandardPackageType spt2 = _packageService.GetStandardPackageType(package.PackageType.PackageTypeId); var result = _packageService.Discard(package.BarCode, centre, authEmployee, expirationDate, spt2, package.PackageId); Assert.IsNotNull(result); }
/// <summary> /// For a given Standard Package Type and a list of scanned barcodes work out which packages are Lost /// and which packages have been found. Tidy up the transit rows for packages for newly found packages. /// </summary> /// <param name="employee"></param> /// <param name="packageType"></param> /// <param name="barCodes"></param> /// <returns></returns> public Result PerformAudit(Employee employee, StandardPackageType packageType, List <string> barCodes) { Result result = new Result { Success = true }; int auditId = _packageRepository.InsertAudit(employee, packageType, barCodes); result.Id = auditId; _packageRepository.UpdateLostFromAudit(auditId, employee.Location, packageType); _packageRepository.UpdateInstockFromAudit(auditId, employee.Location, packageType); _packageRepository.UpdateTransitReceivedFromAudit(auditId, employee.Location); _packageRepository.UpdateTransitCancelledFromAudit(auditId, employee.Location); return(result); }
public ActionResult RegisterChangePackageType(PackageRegisterViewModel model) { var packageService = GetPackageService(); var employeeService = GetEmployeeService(); model.DistributionCentres = employeeService.GetAllDistributionCentres(); model.StandardPackageTypes = packageService.GetAllStandardPackageTypes(); if (model.StandardPackageTypeId > 0) { StandardPackageType selectedPackageType = packageService.GetStandardPackageType(model.StandardPackageTypeId); model.ExpirationDate = packageService.CalculateExpirationDate(selectedPackageType, DateTime.Today); } else { model.ExpirationDate = DateTime.Today; } return(View("Register", model)); }
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e) { if (e.CurrentStepIndex == 0) { List <string> barCodeList = ucPackageBarcode.GetBarcodes(); StandardPackageType packageType = new StandardPackageType() { PackageTypeId = int.Parse(ddlPackageType.SelectedValue) }; var employeeUser = (EmployeeMembershipUser)System.Web.Security.Membership.GetUser(); var currentLocation = new DistributionCentre() { CentreId = employeeUser.DistributionCentreId }; var reconciledPackages = _reportService.GetReconciledPackages(currentLocation, packageType, barCodeList); grd.DataSource = reconciledPackages; grd.DataBind(); } }
public static int InsertAudit(SqlConnection connection, Employee employee, StandardPackageType packageType) { // define INSERT query with parameters string query = "INSERT Audit (DateAudited, DistributionCentreId, EmployeeId, PackageTypeId) " + "VALUES (@DateAudited, @DistributionCentreId, @EmployeeId, @PackageTypeId); " + "SET @newId = SCOPE_IDENTITY();"; using (var cmd = new SqlCommand(query, connection)) { // define parameters and their values cmd.Parameters.Add("@DateAudited", SqlDbType.DateTime).Value = DateTime.Today; cmd.Parameters.Add("@DistributionCentreId", SqlDbType.Int).Value = employee.Location.CentreId; cmd.Parameters.Add("@EmployeeId", SqlDbType.Int).Value = employee.EmployeeId; cmd.Parameters.Add("@PackageTypeId", SqlDbType.Int).Value = packageType.PackageTypeId; cmd.Parameters.Add("@newId", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.CommandType = CommandType.Text; string qry = cmd.CommandText; cmd.ExecuteScalar(); return((int)cmd.Parameters["@newId"].Value); } }
public ActionResult DistributeSave(PackageDistributeViewModel model) { var packageService = GetPackageService(); var employeeService = GetEmployeeService(); Result result = new Result(); if (ModelState.IsValid && model.SelectedPackages != null && model.SelectedPackages.Any()) { foreach (var package in model.SelectedPackages) { DistributionCentre selectedCentre = employeeService.GetDistributionCentre(package.CentreId); StandardPackageType spt = packageService.GetStandardPackageType(package.PackageTypeId); Employee employee = employeeService.GetEmployeeByUserName(package.CurrentEmployeeUserName); result = packageService.Distribute(package.BarCode, selectedCentre, employee, package.ExpirationDate, spt, package.PackageId); if (result.Success) { package.ProcessResultMessage = "Succeeded"; } else { package.ProcessResultMessage = result.ErrorMessage; } } return(View("DistributeComplete", model)); } if (model.SelectedPackages == null || !model.SelectedPackages.Any()) { model.SelectedPackages = new List <SelectedPackage>(); ModelState.AddModelError("", PackageResult.NoBarCodesSelected); } return(View("Distribute", model)); }
public static int UpdateInstockFromAudit(string connectionString, int auditId, DistributionCentre location, StandardPackageType packageType) { using (var ctx = new Entities(connectionString)) { var receivedPackages = (from p in ctx.Package join ap in ctx.AuditPackage on new { AuditId = auditId, p.PackageId } equals new { ap.AuditId, ap.PackageId } where p.PackageTypeId == packageType.PackageTypeId && (p.CurrentLocationCentreId != location.CentreId || p.CurrentStatus != PackageStatus.InStock) select p).ToList(); int receivedPackageCount = receivedPackages.Count(); foreach (var package in receivedPackages) { package.CurrentStatus = PackageStatus.InStock; package.CurrentLocationCentreId = location.CentreId; package.DistributedByEmployeeId = null; ctx.SaveChanges(); } return(receivedPackageCount); } }