public ActionResult Update(RubberRoller rubberRoller)
        {
            try
            {
                // Check if roller ID exist from DB
                var dbRoller = _db.rubberRollers.Where(r => r.rollerID == rubberRoller.rollerID && r.id != rubberRoller.id).FirstOrDefault();
                if (dbRoller != null)
                {
                    ViewData["rollerCatList"] = getRollerCategories();
                    ModelState.AddModelError("rollerID", "There is already an existing roller with the same roller ID.");
                    return(View("CreateEditForm", rubberRoller));
                }

                // Retrieve existing specific rubber roller from database
                RubberRoller rubberRoll = _db.rubberRollers.SingleOrDefault(c => c.id == rubberRoller.id);

                if (rubberRoll == null)
                {
                    return(RedirectToAction("Index"));
                }

                // Update rubber roller details
                if (rubberRoll.rollerID != rubberRoller.rollerID)
                {
                    rubberRoll.rollerID = rubberRoller.rollerID;
                }
                rubberRoll.rollerCategoryID = rubberRoller.rollerCategoryID;
                rubberRoll.type             = rubberRoller.type;
                rubberRoll.usage            = rubberRoller.usage;
                rubberRoll.shoreHardness    = rubberRoller.shoreHardness;
                rubberRoll.depthOfGroove    = rubberRoller.depthOfGroove;
                rubberRoll.diameter         = rubberRoller.diameter;
                rubberRoll.condition        = rubberRoller.condition;
                rubberRoll.remark           = rubberRoller.remark;
                rubberRoll.status           = rubberRoller.status;

                int result = _db.SaveChanges();

                if (result > 0)
                {
                    LogAction.log(this._controllerName, "POST", "Updated roller record", User.Identity.GetUserId());
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = "<b>STATUS</b>: Rubber roller details has been successfully updated!";
                }

                return(Redirect(Request.UrlReferrer.ToString()));
            }
            catch (Exception ex)
            {
                LogAction.log(this._controllerName, "POST", "Error: " + ex.Message, User.Identity.GetUserId());
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The rubber roller has not been successfully updated.";
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public ActionResult CreateSchedule(int?id)
        {
            RubberRoller rubberRoller = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            if (rubberRoller == null || rubberRoller.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM))
            {
                return(RedirectToAction("CreateSearch"));
            }
            ViewData["roller"] = rubberRoller;
            LogAction.log(this._controllerName, "GET", "Requested Schedule-CreateSchedule webpage", User.Identity.GetUserId());
            return(View("ScheduleCreateEditForm"));
        }
예제 #3
0
        public ActionResult CreateConfirm(FormCollection collection, HttpPostedFileBase file)
        {
            try
            {
                Maintenance  maintenance = new Maintenance();
                int          rollID      = Int32.Parse(collection["rollerID"]);
                RubberRoller rubber      = _db.rubberRollers.FirstOrDefault(r => r.id == rollID);
                if (rubber == null)
                {
                    return(RedirectToAction("CreateSearch"));
                }

                maintenance.title          = collection["title"];
                maintenance.rollerID       = rubber.id;
                maintenance.RubberRoller   = rubber;
                maintenance.sendTo         = collection["sendTo"];
                maintenance.diameterRoller = Double.Parse(collection["diameterRoller"]);
                maintenance.diameterCore   = Double.Parse(collection["diameterCore"]);
                if (collection["openingStockDate"].Length > 0)
                {
                    maintenance.openingStockDate = DateTime.Parse(collection["openingStockDate"]);
                }
                else
                {
                    maintenance.openingStockDate = null;
                }
                maintenance.lastProductionLine = collection["lastProdLine"];
                maintenance.totalMileage       = (collection["totalMileage"] == "0" ? 0 : Int32.Parse(collection["totalMileage"]));
                maintenance.reason             = collection["reason"];
                maintenance.remark             = collection["remark"];
                maintenance.newDiameter        = Double.Parse(collection["newDiameter"]);
                maintenance.newShoreHardness   = collection["newShoreHardness"];
                maintenance.correctiveAction   = collection["correctiveAction"];
                maintenance.sendForRefurbished = Boolean.Parse(collection["sendForRefurbished"]);
                maintenance.reportDateTime     = DateTime.Now;

                if (file != null && file.ContentLength > 0 && imgFormats.Any(item => file.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase)))
                {
                    maintenance.imagePath = UploadImage(file);
                }

                LogAction.log(this._controllerName, "GET", "Redirect Maintenance-CreateConfirm webpage", User.Identity.GetUserId());
                return(View(maintenance));
            }
            catch (Exception ex)
            {
                LogAction.log(this._controllerName, "POST", $"Error: {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("CreateSearch"));
            }
        }
        public ActionResult CreateSchedule(Schedule schedule, FormCollection collection)
        {
            Schedule existingSched = _db.schedules.FirstOrDefault(s => s.rollerID == schedule.rollerID && s.startDateTime == schedule.startDateTime && s.operationLine == schedule.operationLine);

            if (existingSched != null)
            {
                ViewData["schedule"] = existingSched;
                return(View("BeforeChecklist"));
            }

            RubberRoller rubberRoller = _db.rubberRollers.FirstOrDefault(r => r.id == schedule.rollerID);

            schedule.RubberRoller        = rubberRoller;
            schedule.tinplateSize        = $"{collection["thickness"]}x{collection["width"]}x{collection["length"]}";
            schedule.status              = ScheduleStatus.PENDING_BEFORE_CHECKLIST;
            schedule.RubberRoller.status = RollerStatus.getStatus(RollerStatus.IN_USE);

            // Update roller opening stock date
            if (rubberRoller.opening_stock_date == null || rubberRoller.isRefurbished)
            {
                rubberRoller.opening_stock_date = DateTime.Now;
            }

            // Reset roller isRefurbish status
            if (rubberRoller.isRefurbished)
            {
                rubberRoller.isRefurbished = false;
            }

            _db.schedules.Add(schedule);

            int result = _db.SaveChanges();

            if (result > 0)
            {
                TempData["formStatus"]    = true;
                TempData["formStatusMsg"] = "<b>STATUS</b>: New schedule record has been successfully added.";
                ViewData["schedule"]      = schedule;
                LogAction.log(this._controllerName, "POST", "New schedule details successfully added", User.Identity.GetUserId());
                return(View("BeforeChecklist"));
            }
            else
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The schedule record has not been successfully added.";
                LogAction.log(this._controllerName, "POST", "Errpr adding wew schedule detail.", User.Identity.GetUserId());
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public ActionResult StockCard(RubberRoller rubberRoller, int?i)
        {
            RubberRoller rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null)
            {
                return(RedirectToAction("StockCardSearch"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested stock card for Roller: {rubber.id}", User.Identity.GetUserId());
            ViewData["rollerID"] = rubber.rollerID;
            List <RollerLocation> rollerLocations = rubber.RollerLocations.ToList();

            return(View(rollerLocations.ToPagedList(i ?? 1, 40)));
        }
        public ActionResult LocationHistory(int id, int?i)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested webpage RubberRoller-LocationHistory for Roller: {id}", User.Identity.GetUserId());
            RubberRoller rubberRollers = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            ViewData["rollerID"] = rubberRollers.rollerID;
            List <RollerLocation> rollerLocations = rubberRollers.RollerLocations.ToList();

            return(View(rollerLocations.ToPagedList(i ?? 1, 40)));
        }
예제 #7
0
        // GET: Returns create form
        public ActionResult Create(RubberRoller rubberRoller)
        {
            RubberRoller rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null ||
                (rubber.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM) &&
                 rubber.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM_ON_HOLD)
                )
                )
            {
                return(RedirectToAction("CreateSearch"));
            }

            ViewData["rubber"] = rubber;
            LogAction.log(this._controllerName, "GET", "Requested Maintenance-Create form webpage", User.Identity.GetUserId());
            return(View("CreateEditMaintenance"));
        }
        public ActionResult MaintenanceHistory(int id, int?i)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested webpage RubberRoller-MaintenanceHistory for Roller: {id}", User.Identity.GetUserId());
            RubberRoller rubberRollers = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            ViewData["rollerID"] = rubberRollers.rollerID;
            List <Maintenance> maintenances = rubberRollers.Maintenances
                                              .Where(m => m.rollerID == id)
                                              .Where(m => m.status == RollerMaintenance.APPROVED || m.status == RollerMaintenance.COMPLETED)
                                              .ToList();

            return(View(maintenances.ToPagedList(i ?? 1, 40)));
        }
        public ActionResult OperationHistory(int id, int?i)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested webpage RubberRoller-OperationHistory for Roller: {id}", User.Identity.GetUserId());
            RubberRoller rubberRollers = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            ViewData["rollerID"] = rubberRollers.rollerID;
            List <Schedule> schedules = rubberRollers.Schedules
                                        .Where(o => o.status == ScheduleStatus.COMPLETED)
                                        .OrderBy(o => o.startDateTime)
                                        .ToList();

            return(View(schedules.ToPagedList(i ?? 1, 40)));
        }
        public ActionResult Create(RubberRoller rubberRoller, FormCollection collection)
        {
            // Check if roller ID exist from DB
            var dbRoller = _db.rubberRollers.Where(r => r.rollerID == rubberRoller.rollerID).FirstOrDefault();

            if (dbRoller != null)
            {
                ModelState.AddModelError("rollerID", "There is already an existing roller with the same roller ID.");
            }

            if (!ModelState.IsValid || dbRoller != null)
            {
                ViewData["rollerCatList"] = getRollerCategories();
                return(View("CreateEditForm", rubberRoller));
            }

            rubberRoller.isRefurbished = false;
            _db.rubberRollers.Add(rubberRoller);

            // Create initial rubber roller location
            RollerLocation rollerLocation = new RollerLocation();

            rollerLocation.dateTimeIn   = DateTime.Now;
            rollerLocation.rollerID     = rubberRoller.id;
            rollerLocation.RubberRoller = rubberRoller;
            rollerLocation.location     = collection["rollLocat"];
            _db.rollerLocations.Add(rollerLocation);

            int result = _db.SaveChanges();

            if (result > 0)
            {
                LogAction.log(this._controllerName, "POST", "Added new rubber roller", User.Identity.GetUserId());
                TempData["formStatus"]    = true;
                TempData["formStatusMsg"] = "<b>STATUS</b>: New rubber roller has been successfully added!";
            }
            else
            {
                LogAction.log(this._controllerName, "POST", "Error adding new rubber roller", User.Identity.GetUserId());
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The rubber roller has not been successfully added.";
            }
            return(Redirect(Request.UrlReferrer.ToString()));
        }
예제 #11
0
        public ActionResult RollerUsage(RubberRoller rubberRoller, int?i)
        {
            RubberRoller rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null)
            {
                return(RedirectToAction("RollerUsageSearch"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested roller usage report for Roller: {rubber.rollerID}", User.Identity.GetUserId());
            RubberRoller rubberRollers = _db.rubberRollers.FirstOrDefault(r => r.id == rubber.id);

            ViewData["rollerID"] = rubberRollers.rollerID;
            List <Schedule> schedules = rubberRollers.Schedules
                                        .Where(o => o.status == ScheduleStatus.COMPLETED)
                                        .OrderBy(o => o.startDateTime)
                                        .ToList();

            return(View(schedules.ToPagedList(i ?? 1, 40)));
        }
예제 #12
0
        public ActionResult RollerMaintenance(RubberRoller rubberRoller, int?i)
        {
            RubberRoller rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null)
            {
                return(RedirectToAction("RollerMaintenanceSearch"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested roller maintenance history report for Roller: {rubber.rollerID}", User.Identity.GetUserId());
            RubberRoller rubberRollers = _db.rubberRollers.FirstOrDefault(r => r.id == rubber.id);

            ViewData["rollerID"] = rubberRollers.rollerID;
            List <Maintenance> maintenances = rubberRollers.Maintenances
                                              .Where(m => m.rollerID == rubber.id)
                                              .Where(m => m.status == KJCFRubberRoller.Models.RollerMaintenance.APPROVED || m.status == KJCFRubberRoller.Models.RollerMaintenance.COMPLETED)
                                              .ToList();

            return(View(maintenances.ToPagedList(i ?? 1, 40)));
        }
예제 #13
0
        public static bool UpdateRollerLocation(RubberRoller rubberRoller, string location)
        {
            ApplicationDbContext _db    = new ApplicationDbContext();
            RubberRoller         rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null)
            {
                return(false);
            }

            // Update roller location
            RollerLocation currentLocation = rubber.RollerLocations.LastOrDefault();

            if (currentLocation != null)
            {
                currentLocation.dateTimeOut = DateTime.Now;
            }

            RollerLocation rollerLocation = new RollerLocation();

            rollerLocation.dateTimeIn   = DateTime.Now;
            rollerLocation.rollerID     = rubber.id;
            rollerLocation.RubberRoller = rubber;
            rollerLocation.location     = location;
            if (location.StartsWith("Operation Line"))
            {
                rollerLocation.operationLine = int.Parse(location.Substring(15));
            }
            else
            {
                rollerLocation.operationLine = 0;
            }

            // Add new records
            _db.rollerLocations.Add(rollerLocation);
            var result = _db.SaveChanges();

            return(result > 0 ? true : false);
        }
        // GET: Returns edit form with existing rubber roller data
        public ActionResult Edit(int?id)
        {
            // Ensure ID is supplied
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            // Retrieve existing specific roller category from database
            RubberRoller rubberRoller = _db.rubberRollers.SingleOrDefault(c => c.id == id);

            // Ensure the retrieved value is not null
            if (rubberRoller == null)
            {
                return(RedirectToAction("Index"));
            }

            LogAction.log(this._controllerName, "GET", string.Format("Requested RubberRoller-Edit {0} webpage", id), User.Identity.GetUserId());

            // Retrieve roller category
            ViewData["rollerCatList"] = getRollerCategories();
            return(View("CreateEditForm", rubberRoller));
        }