Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostArchiveMachineNote()
        {
            var Edit_Machine_Note = await _context.MachineTrainNotes.FirstOrDefaultAsync(n => n.PkMachineTrainNoteId == Machine_Train_Note_Id);

            if (Edit_Machine_Note == null)
            {
                return(NotFound());
            }

            Edit_Machine_Note.MachineTrainNoteIsActive = false;

            _context.Attach(Edit_Machine_Note).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MachineNoteExists(Edit_Machine_Note.PkMachineTrainNoteId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Machinenotes", new { id = Edit_Machine_Note.FkMachineTrainId }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostEditRouteCall()
        {
            GetUserName();

            //Console.WriteLine(" ------------------------------ Edit Route Call ------------------------------");
            //Console.WriteLine(Edit_Route_Call.Schedule_Date);
            //Console.WriteLine(Edit_Route_Call.PK_CallId);

            var Updated_Route_Call = await _context.RouteCall.FirstOrDefaultAsync(m => m.PkCallId == Edit_Route_Call.PkCallId);

            Updated_Route_Call.ScheduleDate = Edit_Route_Call.ScheduleDate;
            Updated_Route_Call.ModifiedBy   = Current_User;

            _context.Attach(Updated_Route_Call).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RouteCallExists(Edit_Route_Call.PkCallId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            //Console.WriteLine(" ------------------------------ Finish Editing ------------------------------");
            return(RedirectToPage("/ScheduleMaintenance"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostUpdateReportFault()
        {
            GetUserName();

            Current_Displayed_Report = _context.VReportSummary.FirstOrDefault(r => r.ReportId == Report_To_Update.PkReportId);


            //--------------- Update Fault if FaultType is null ----------------------------//
            if (Current_Displayed_Report.FaultTypeId == null)
            {
                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(Fault_To_Update))
                {
                    string name  = descriptor.Name;
                    object value = descriptor.GetValue(Fault_To_Update);
                    Console.WriteLine($"{name} = {value}");
                }

                var Updated_Fault = await _context.Fault.FirstOrDefaultAsync(f => f.PkFaultId == Fault_To_Update.PkFaultId);

                Updated_Fault.FkTechnologyId              = Fault_To_Update.FkTechnologyId;
                Updated_Fault.FkPrimaryComponentTypeId    = Fault_To_Update.FkPrimaryComponentTypeId;
                Updated_Fault.FkPrimaryComponentSubtypeId = Fault_To_Update.FkPrimaryComponentSubtypeId;
                Updated_Fault.FkFaultTypeId    = Fault_To_Update.FkFaultTypeId;
                Updated_Fault.FkFaultSubtypeId = Fault_To_Update.FkFaultSubtypeId;
                Updated_Fault.FaultLocation    = Fault_To_Update.FaultLocation;

                _context.Attach(Updated_Fault).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FaultExists(Fault_To_Update.PkFaultId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            //--------------- Update Fault if FaultType is null ----------------------------//

            //--------------- Update Report----------------------------//
            //foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(Report_To_Update))
            //{
            //    string name = descriptor.Name;
            //    object value = descriptor.GetValue(Report_To_Update);
            //    Console.WriteLine($"{name} = {value}");
            //}
            var Updated_Report = await _context.Report.FirstOrDefaultAsync(f => f.PkReportId == Report_To_Update.PkReportId);

            Updated_Report.FkReportTypeId  = Report_To_Update.FkReportTypeId;
            Updated_Report.FkConditionId   = Report_To_Update.FkConditionId;
            Updated_Report.ReportDate      = Report_To_Update.ReportDate;
            Updated_Report.Observations    = Report_To_Update.Observations;
            Updated_Report.Actions         = Report_To_Update.Actions;
            Updated_Report.ExternalNotes   = Report_To_Update.ExternalNotes;
            Updated_Report.NotificationNo  = Report_To_Update.NotificationNo;
            Updated_Report.WorkOrderNo     = Report_To_Update.WorkOrderNo;
            Updated_Report.AnalystNotes    = Report_To_Update.AnalystNotes;
            Updated_Report.FkReportStageId = Report_To_Update.FkReportStageId;

            _context.Attach(Updated_Report).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReportExists(Report_To_Update.PkReportId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            //--------------- Update Report----------------------------//

            //--------------- Upload Attachments----------------------------//
            var UploadFileList = HttpContext.Request.Form.Files;

            foreach (var file in UploadFileList)
            {
                ReportFiles New_ReportFile = new ReportFiles();

                Console.WriteLine(file.FileName);
                New_ReportFile.FileName   = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
                New_ReportFile.FkReportId = Report_To_Update.PkReportId;
                New_ReportFile.UploadDate = DateTime.Now;
                New_ReportFile.UploadedBy = Current_User;

                _context.ReportFiles.Add(New_ReportFile);
                try
                {
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReportFileExists(New_ReportFile.PkFilePathId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                string save_path = $"wwwroot\\MachineAttach\\{New_ReportFile.FileName}";
                //string save_path = $"c:\\MachineAttach\\{New_Machine_Train_File.FileName}";
                using (var fileStream = new FileStream(save_path, FileMode.Create))
                {
                    file.CopyTo(fileStream);
                }
            }

            //--------------- Upload Attachments----------------------------//
            return(RedirectToPage("/ReviewReports", new { id = Report_To_Update.PkReportId }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostCreateReport()
        {
            GetUserName();

            V_Report_Summary_All = await _context.VReportSummary
                                   .AsNoTracking()
                                   .ToListAsync();

            // only process selected machines
            InputReportList = InputReportList.Where(r => MainOptionList.Contains(r.MainOption)).ToList();

            GeneratedReportSummary.Clear();
            foreach (var inputreport in InputReportList)
            {
                Console.WriteLine("{0}--{1}--{2}--{3}--{4}",
                                  inputreport.MachineTrainId, inputreport.MainOption, inputreport.Reason, inputreport.Comments, inputreport.PK_CallId);
                if (inputreport.MainOption == "missed") // Missed
                {
                    if (inputreport.Reason == 0)
                    {
                        log_str = $"Failed to create report for machine {inputreport.Machine_Train} - {inputreport.Machine_Train_Long_Name} in call {inputreport.RouteDescription}. You must SELECT A REASON for the missed machine!";
                        GeneratedReportSummary.Add(log_str);
                        Console.WriteLine(log_str);
                    }
                    else
                    {
                        var new_missed_sruvey = new MissedSurvey()
                        {
                            FkMachineTrainId   = inputreport.MachineTrainId,
                            Reason             = reason_list[inputreport.Reason],
                            Comments           = inputreport.Comments,
                            ReportedMissedDate = DateTime.Now,
                            ReportedMissedBy   = Current_User,
                            OriginCallId       = inputreport.PK_CallId
                        };

                        _context.MissedSurvey.Add(new_missed_sruvey);
                        try
                        {
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!FaultExists(new_missed_sruvey.PkMissedSurveyId))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                        log_str = $"Missed Survey created for machine {inputreport.Machine_Train} - {inputreport.Machine_Train_Long_Name} in route {inputreport.RouteDescription}";
                        GeneratedReportSummary.Add(log_str);
                        Console.WriteLine(log_str);
                    }
                }
                else if (inputreport.MainOption == "good") // No Action
                {
                    // Is there an open fault?
                    if (inputreport.Status == "Open")
                    {
                        // Was the latest condition a 2 (No Action)
                        if (inputreport.Condition == "No Action")
                        {
                            /*
                             *  Create a new report on the same fault.
                             *  -- Set condition_mag = 2, routine and released
                             */

                            var new_report = new Report()
                            {
                                FkFaultId       = inputreport.FaultId,
                                ReportDate      = DateTime.Now,
                                MeasurementDate = DateTime.Now,
                                FkConditionId   = 1, // No Action Mag = 2
                                FkReportTypeId  = 1, // Routine
                                FkReportStageId = 4, //released
                                AnalystName     = Current_User,
                                ReportIsActive  = true,
                                OriginCallId    = inputreport.PK_CallId
                            };

                            _context.Report.Add(new_report);
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!ReportExists(new_report.PkReportId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }
                        }
                        else // Was the latest condition a 2 (No Action)
                        {
                            /*
                             *  Close the existing fault
                             *  -- Stamp the close date field in the fault table
                             *  -- Input the comment to the fault table
                             */

                            var Edit_Fault = await _context.Fault.FirstOrDefaultAsync(n => n.PkFaultId == inputreport.FaultId);

                            if (Edit_Fault == null)
                            {
                                return(NotFound());
                            }

                            Edit_Fault.CloseDate      = DateTime.Now;
                            Edit_Fault.ClosureComment = inputreport.Comments;

                            _context.Attach(Edit_Fault).State = EntityState.Modified;

                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!FaultExists(Edit_Fault.PkFaultId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }



                            /*
                             *  Create a new fault on this machine
                             *  -- set the fault type to no fault
                             *  -- Create a new report on the new fault.
                             *  -- Set condition_mag = 2, routine and released
                             */

                            var new_fault = new Fault()
                            {
                                FkMachineTrainId         = inputreport.MachineTrainId,
                                FkPrimaryComponentTypeId = 1,
                                FkTechnologyId           = 1,
                                FkFaultTypeId            = 1,
                                CreateDate    = DateTime.Now,
                                FaultIsActive = true
                            };

                            _context.Fault.Add(new_fault);
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!FaultExists(new_fault.PkFaultId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }

                            var new_report = new Report()
                            {
                                FkFaultId       = new_fault.PkFaultId,
                                ReportDate      = DateTime.Now,
                                MeasurementDate = DateTime.Now,
                                FkConditionId   = 1,
                                FkReportTypeId  = 1,
                                FkReportStageId = 4,
                                AnalystName     = Current_User,
                                ReportIsActive  = true,
                                OriginCallId    = inputreport.PK_CallId
                            };


                            _context.Report.Add(new_report);

                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!ReportExists(new_report.PkReportId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    else  // Is there an open fault?
                    {
                        /*
                         *      Create a new fault on this machine
                         *      -- set the fault type to no fault
                         *      -- Create a new report on the new fault.
                         *      -- Set condition_mag = 2, routine and released
                         */

                        var new_fault = new Fault()
                        {
                            FkMachineTrainId         = inputreport.MachineTrainId,
                            FkPrimaryComponentTypeId = 1,
                            FkTechnologyId           = 1,
                            FkFaultTypeId            = 1,
                            CreateDate    = DateTime.Now,
                            FaultIsActive = true
                        };

                        _context.Fault.Add(new_fault);
                        try
                        {
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!FaultExists(new_fault.PkFaultId))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }

                        var new_report = new Report()
                        {
                            FkFaultId       = new_fault.PkFaultId,
                            ReportDate      = DateTime.Now,
                            MeasurementDate = DateTime.Now,
                            FkConditionId   = 1,
                            FkReportTypeId  = 1,
                            FkReportStageId = 4,
                            AnalystName     = Current_User,
                            ReportIsActive  = true,
                            OriginCallId    = inputreport.PK_CallId
                        };


                        _context.Report.Add(new_report);

                        try
                        {
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!ReportExists(new_report.PkReportId))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }
                else if (inputreport.MainOption == "anomaly") // Anomaly
                {
                    // Is there an open fault?
                    if (inputreport.Status == "Open")
                    {
                        // Was the latest condition a 2 (No Action)
                        if (inputreport.Condition == "No Action")
                        {
                            /*
                             *  Close the existing fault
                             *  -- Stamp the close date field in the fault table
                             */
                            var Edit_Fault = await _context.Fault.FirstOrDefaultAsync(n => n.PkFaultId == inputreport.FaultId);

                            if (Edit_Fault == null)
                            {
                                return(NotFound());
                            }

                            Edit_Fault.CloseDate = DateTime.Now;

                            _context.Attach(Edit_Fault).State = EntityState.Modified;

                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!FaultExists(Edit_Fault.PkFaultId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }

                            Console.WriteLine("Close the existing fault");


                            /*
                             *  Create a new fault on this machine
                             *  -- Create a new report on the new fault.
                             *  -- Set condition_mag = 3, routine and In progress
                             */

                            var new_fault = new Fault()
                            {
                                FkMachineTrainId         = inputreport.MachineTrainId,
                                FkPrimaryComponentTypeId = 1,
                                FkTechnologyId           = 1,
                                CreateDate    = DateTime.Now,
                                FaultIsActive = true
                            };

                            _context.Fault.Add(new_fault);
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!FaultExists(new_fault.PkFaultId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }

                            var new_report = new Report()
                            {
                                FkFaultId       = new_fault.PkFaultId,
                                ReportDate      = DateTime.Now,
                                MeasurementDate = DateTime.Now,
                                FkConditionId   = 2,
                                FkReportTypeId  = 1,
                                FkReportStageId = 1,
                                AnalystName     = Current_User,
                                ReportIsActive  = true,
                                OriginCallId    = inputreport.PK_CallId
                            };


                            _context.Report.Add(new_report);

                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!ReportExists(new_report.PkReportId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }

                            Console.WriteLine("Set condition_mag = 3, routine and In progress");
                        }
                        else
                        {
                            /*
                             *  Create a new report on the same fault.
                             *  -- Set condition_mag = 2, routine and released
                             */

                            var new_report = new Report()
                            {
                                FkFaultId       = inputreport.FaultId,
                                ReportDate      = DateTime.Now,
                                MeasurementDate = DateTime.Now,
                                FkConditionId   = 1,
                                FkReportTypeId  = 1,
                                FkReportStageId = 4,
                                AnalystName     = Current_User,
                                ReportIsActive  = true,
                                OriginCallId    = inputreport.PK_CallId
                            };


                            _context.Report.Add(new_report);

                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateConcurrencyException)
                            {
                                if (!ReportExists(new_report.PkReportId))
                                {
                                    return(NotFound());
                                }
                                else
                                {
                                    throw;
                                }
                            }

                            Console.WriteLine("Create a new report on the same fault. -- Set condition_mag = 2, routine and released");
                        }
                    }
                    else
                    {
                        /*
                         *      Create a new fault on this machine
                         *      -- Create a new report on the new fault.
                         *      -- Set condition_mag = 3, routine and In progress
                         */

                        var new_fault = new Fault()
                        {
                            FkMachineTrainId         = inputreport.MachineTrainId,
                            FkPrimaryComponentTypeId = 1,
                            FkTechnologyId           = 1,
                            CreateDate    = DateTime.Now,
                            FaultIsActive = true
                        };

                        _context.Fault.Add(new_fault);
                        try
                        {
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!FaultExists(new_fault.PkFaultId))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }

                        var new_report = new Report()
                        {
                            FkFaultId       = new_fault.PkFaultId,
                            ReportDate      = DateTime.Now,
                            MeasurementDate = DateTime.Now,
                            FkConditionId   = 2,
                            FkReportTypeId  = 1,
                            FkReportStageId = 1,
                            AnalystName     = Current_User,
                            ReportIsActive  = true,
                            OriginCallId    = inputreport.PK_CallId
                        };


                        _context.Report.Add(new_report);

                        try
                        {
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!ReportExists(new_report.PkReportId))
                            {
                                return(NotFound());
                            }
                            else
                            {
                                throw;
                            }
                        }
                        Console.WriteLine("Create a new fault on this machine -- Create a new report on the new fault. -- Set condition_mag = 3, routine and In progress");
                    }
                }
                else
                {
                    log_str = $"Nothing changed for machine {inputreport.Machine_Train} - {inputreport.Machine_Train_Long_Name} in route {inputreport.RouteDescription}";
                    GeneratedReportSummary.Add(log_str);
                    Console.WriteLine(log_str);
                }
            }
            Console.WriteLine(GeneratedReportSummary.Count);
            return(RedirectToPage("/CreateReports"));
        }