Ejemplo n.º 1
0
        private Helpers.PageInput getMachineDropdown(string CID, int flgId = 0)
        {
            Helpers.PageInput machineInput = new Helpers.PageInput("select", "Machine Name", "MM_Id", "MM_Id", "");
            try
            {
                Helpers.CtxService service  = new Helpers.CtxService(null, CID);
                List <Machine>     machines = service.getMachines(flgId);

                if (machines == null || machines.Count == 0)
                {
                    machineInput.errorFlag    = true;
                    machineInput.errorMessage = "ERROR: No machines found in database.";
                    return(machineInput);
                }

                foreach (var item in machines)
                {
                    machineInput.input.options.Add(new Helpers.InputObject.option {
                        text = item.MM_Name, value = item.MM_Id.ToString()
                    });
                }
            } catch (Exception ex)
            {
                machineInput.errorFlag    = true;
                machineInput.errorMessage = "ERROR CREATING MACHINE SELECT LIST: " + ex.Message;
            }

            return(machineInput);
        }
Ejemplo n.º 2
0
        private Models.FbPartialViewModel getFbVM()
        {
            Models.FbPartialViewModel m = new Models.FbPartialViewModel();

            Helpers.CtxManagerService s = new Helpers.CtxManagerService();

            if (CID != null && CID.Length == 6)
            {
                Helpers.CtxService ctxs = new Helpers.CtxService(null, CID);

                m.fbdata = ctxs.GetFlagboards();
                m.SelCID = CID;
            }
            else
            {
                m.fbdata = new Models.CtxEF.Maintenance_Flagboard[] { };
                m.SelCID = "000000";
            }

            removeCacheHTML("flagboards");

            m.corpdata = s.getLocations();

            return(m);
        }
Ejemplo n.º 3
0
        private Helpers.PageInput getFlagboardDropdown(string CID, int MFB_Id = 0)
        {
            string selVal = (MFB_Id == 0) ? "" : MFB_Id.ToString();

            Helpers.PageInput fbInput = new Helpers.PageInput("select", "Flagboards", "MFB_Id", "MFB_Id", selVal);
            try
            {
                Helpers.CtxService       service = new Helpers.CtxService(null, CID);
                List <Models.pageInputs> fbs     = service.getFlagBoardsInput();

                if (fbs == null || fbs.Count == 0)
                {
                    fbInput.errorFlag    = true;
                    fbInput.errorMessage = "ERROR: No FlagBoards found in database.";
                    return(fbInput);
                }

                foreach (var item in fbs)
                {
                    fbInput.input.options.Add(new Helpers.InputObject.option {
                        text = "FB " + item.value, value = item.key
                    });
                }
            }
            catch (Exception ex)
            {
                fbInput.errorFlag    = true;
                fbInput.errorMessage = "ERROR CREATING FB SELECT LIST: " + ex.Message;
            }

            return(fbInput);
        }
Ejemplo n.º 4
0
        private Helpers.PageInput getMTypesDropdown(string CID)
        {
            Helpers.PageInput machineInput = new Helpers.PageInput("select", "Maintenance Types", "MT_Id", "MT_Id", "");
            try
            {
                Helpers.CtxService       service = new Helpers.CtxService(null, CID);
                List <Maintenance_Types> mtypes  = service.getMaintenanceTypes();

                if (mtypes == null || mtypes.Count == 0)
                {
                    machineInput.errorFlag    = true;
                    machineInput.errorMessage = "ERROR: No maintenance types found in database.";
                    return(machineInput);
                }

                foreach (var item in mtypes)
                {
                    machineInput.input.options.Add(new Helpers.InputObject.option {
                        text = item.MT_Name, value = item.MT_Id.ToString()
                    });
                }
            }
            catch (Exception ex)
            {
                machineInput.errorFlag    = true;
                machineInput.errorMessage = "ERROR CREATING MAINTENANCE SELECT LIST: " + ex.Message;
            }

            return(machineInput);
        }
Ejemplo n.º 5
0
        private Helpers.PageInput getEmployeesDropdown(string CID)
        {
            Helpers.PageInput machineInput = new Helpers.PageInput("select", "Employees", "EMP_ID", "EMP_ID", "");
            try
            {
                Helpers.CtxService service   = new Helpers.CtxService(null, CID);
                List <Employee>    employees = service.getEmployees();

                if (employees == null || employees.Count == 0)
                {
                    machineInput.errorFlag    = true;
                    machineInput.errorMessage = "ERROR: No empoyes found in database.";
                    return(machineInput);
                }

                foreach (var item in employees)
                {
                    machineInput.input.options.Add(new Helpers.InputObject.option {
                        text = item.EMP_First_Name + " " + item.EMP_Last_Name, value = item.EMP_ID.ToString()
                    });
                }
            }
            catch (Exception ex)
            {
                machineInput.errorFlag    = true;
                machineInput.errorMessage = "ERROR CREATING EMPLOYEE SELECT LIST: " + ex.Message;
            }

            return(machineInput);
        }
Ejemplo n.º 6
0
        private Models.MobileEditorModel getEditorModelObject(string CID, int MS_Id, int MFB_Id, int MM_Id)
        {
            Models.MobileEditorModel model = new Models.MobileEditorModel();
            model.CID          = CID;
            model.inputs       = getEditorInputs(CID, MFB_Id, MS_Id);
            model.hiddenInputs = new List <Helpers.InputObject>();

            Helpers.InputObject hidden1 = new Helpers.InputObject();
            hidden1.id    = "CID";
            hidden1.value = CID;
            model.hiddenInputs.Add(hidden1);

            Helpers.InputObject hidden2 = new Helpers.InputObject();
            hidden2.id    = "MS_Id";
            hidden2.value = MS_Id.ToString();
            model.hiddenInputs.Add(hidden2);

            Helpers.InputObject hidden3 = new Helpers.InputObject();
            hidden3.id    = "MM_Id";
            hidden3.value = MM_Id.ToString();
            model.hiddenInputs.Add(hidden3);

            service        = new Helpers.CtxService(null, model.CID);
            model.machines = service.getMachines(MFB_Id).ToArray();

            return(model);
        }
Ejemplo n.º 7
0
        public FileStreamResult MachineFileClick(string CID, string MM_Idp, string number)
        {
            byte[] buffer   = new byte[0];
            string filename = "export.pdf";
            string prefix   = "pdf";
            Dictionary <string, string> mimetypes = getMimeTypes();

            try
            {
                int MM_Id      = 0;
                int fileNumber = Convert.ToInt32(number);
                Int32.TryParse(MM_Idp, out MM_Id);

                if (CID.Length < 6)
                {
                    throw new Exception("location variable incorrectly formatted.");
                }

                if (MM_Id == 0)
                {
                    throw new Exception("Machine primary key cannot be zero.");
                }

                Helpers.CtxService service = new Helpers.CtxService(null, CID);

                List <ActiveMachineImgae> files = service.getmachineFiles(MM_Id);

                for (var i = 1; i <= files.Count; i++)
                {
                    if (i == fileNumber)
                    {
                        buffer   = files[i - 1].filebytes1;
                        filename = files[i - 1].filename1;
                        var splitarr = filename.Split('.');
                        if (splitarr.Length > 1)
                        {
                            prefix = splitarr[splitarr.Length - 1];
                        }

                        break;
                    }
                }
            } catch (Exception ex)
            {
            }
            if (buffer != null && mimetypes.ContainsKey(prefix.ToUpper()))
            {
                MemoryStream stream = new MemoryStream(buffer);
                stream.Flush();
                stream.Position = 0;
                return(File(stream, mimetypes[prefix.ToUpper()], filename));
            }
            else
            {
                MemoryStream stream = new MemoryStream();
                stream.Flush();
                stream.Position = 0;
                return(File(stream, "application/pdf", "export.pdf"));
            }
        }
Ejemplo n.º 8
0
        public JsonResult SaveFB(string method, int MFBId, string Desc, string CID)
        {
            var rObject = new MethodResponse()
            {
                Result       = true,
                ErrorMessage = "",
                Content      = new Models.WorkroomsUserObject[] { }
            };

            Helpers.CtxService service = new Helpers.CtxService(null, CID);

            try
            {
                if (CID.Length < 6)
                {
                    throw new Exception("could not find location variable");
                }

                switch (method)
                {
                case "fb_add":
                    rObject.Result = service.AddFB(Desc);
                    if (!rObject.Result)
                    {
                        rObject.ErrorMessage = service.errorMessage;
                    }
                    break;

                case "fb_edit":

                    rObject.Result = service.EditFB(MFBId, Desc);
                    if (!rObject.Result)
                    {
                        rObject.ErrorMessage = service.errorMessage;
                    }
                    //else
                    //    service.EditCachedWorkroom(id, Name, Abbreviation);

                    break;
                }
            } catch (Exception ex)
            {
                rObject.Result       = false;
                rObject.ErrorMessage = ex.Message;
            }

            if (rObject.Result == true)
            {
                removeCacheHTML();
            }
            else
            {
                rObject.ErrorMessage = service.errorMessage;
            }

            return(Json(rObject));
        }
Ejemplo n.º 9
0
        public JsonResult getNewWorkorder(string CID)
        {
            Helpers.CtxService service = new Helpers.CtxService(null, CID);
            int workorder = 0;

            try
            {
                workorder = service.getNewWorkoder();
            } finally
            {
                service.Dispose();
            }
            return(Json(workorder, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 10
0
        public ActionResult Index()
        {
            model.CID = getCID();

            if (model.CID.Trim().Length < 6)
            {
                return(RedirectToAction("Locations", "Manage"));
            }

            service = new Helpers.CtxService(null, model.CID);
            Helpers.ManagerService manageservice = new Helpers.ManagerService();
            try
            {
                model.MFB_Id        = getSelectedFlagboard();
                model.machines      = service.getMachines(model.MFB_Id);
                model.types         = service.getMaintenanceTypes();
                model.employees     = service.getEmployees();
                model.MS_Maint_Code = getMaintCode();
                model.schedule      = getSchedule();
                model.Location      = manageservice.getRecord(model.CID.Trim());
                model.flagboards    = service.getFlagBoards().ToArray();
                model.MFB_label     = getFBLabel(model.MFB_Id);
                model.UserName      = User.Identity.Name;
                UpdateCachedTimers(model.CID);

                model.ActiveTimers = GetActiveTimers(model.CID);
                model.isMobile     = isMobile();
                model.canDelete    = IsAdmin();
                model.ticketname   = ticketname;
            } finally
            {
                service.Dispose();
                model.schedule = filterSchedule(model.schedule);
            }

            if (service.error == true)
            {
                model.errorMessage = service.errorMessage;
            }

            if (model.CID.Length < 6)
            {
                return(RedirectToAction("Locations", "Manage"));
            }

            addLocationCookie(model.CID.Trim());

            return(View(model));
        }
Ejemplo n.º 11
0
        public JsonResult Refresh(short MS_Maint_Code, string hidecompleted, int MFB_Id, string CID, bool Forced)
        {
            //int cpuUsage = cpuPercentage();
            //if (cpuUsage > 80 && Forced == false)
            //    return Json("CPUERR", JsonRequestBehavior.AllowGet);

            Helpers.CtxService service = new Helpers.CtxService(null, CID);
            System.Web.Script.Serialization.JavaScriptSerializer jser = new System.Web.Script.Serialization.JavaScriptSerializer();
            string objSerialized = "";

            try
            {
                List <schedule> updated = new List <schedule>();
                updated = service.getSchedule();

                model.MS_Maint_Code = MS_Maint_Code;
                model.MFB_Id        = MFB_Id;
                updated             = filterSchedule(updated);
                if (hidecompleted == "true")
                {
                    List <schedule> uncompleted = new List <schedule>();
                    foreach (var item in updated)
                    {
                        if (item.MS_WOClosed_Timestamp.Trim().Length == 0)
                        {
                            uncompleted.Add(item);
                        }
                    }
                    objSerialized = jser.Serialize(uncompleted);
                    return(Json(objSerialized, JsonRequestBehavior.AllowGet));
                }

                objSerialized = jser.Serialize(updated);
            }
            catch (Exception ex)
            {
                objSerialized = "ERROR";
            }
            finally
            {
                service.Dispose();
            }
            return(Json(objSerialized, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 12
0
        private void Save(string CID, schedule record)
        {
            Helpers.CtxService service = new Helpers.CtxService(null, CID);
            switch (record.MS_Id)
            {
            case 0:
                service.Add(record);
                break;

            default:
                service.Update(record);
                if (record.MS_Maint_Code == 1 && record.MS_Main_Comp_Date.ToUpper() == "TRUE")
                {
                    if (record.MS_Frequency < 1)
                    {
                        throw new Exception("Interval must be greater than 0");
                    }
                    System.Threading.Tasks.Task.Run(() => AutoAddScheduledOrder(record, service));
                }
                break;
            }
            service.clearCache();
        }
Ejemplo n.º 13
0
        private List <schedule> getSchedule(int maint_code = 1)
        {
            //if (HttpContext.Cache["MaintenanceSchedule_" + model.CID] != null)
            //{
            //    try
            //    {
            //        List<schedule> cachedrecs = (List<schedule>)HttpContext.Cache["MaintenanceSchedule_" + model.CID];
            //        if (cachedrecs.Count > 0)
            //        {
            //            if (maint_code == 1)
            //            {
            //                return (from x in cachedrecs orderby x.MS_Next_Main_Datetime ascending select x).ToList();
            //            }
            //            else
            //            {
            //                return (from x in cachedrecs select x).OrderBy(x => x.MS_WOCreate_Date).ToList();
            //            }

            //        }


            //    }
            //    catch (Exception ex)
            //    {
            //        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            //    }

            //}
            Helpers.CtxService service = new Helpers.CtxService(null, model.CID);

            var recs = service.getSchedule();

            //if (recs.Count > 0)
            //    service.cache(recs, model.CID);

            return(recs);
        }
Ejemplo n.º 14
0
 public JsonResult RefreshFB(string CID)
 {
     Helpers.CtxService service = new Helpers.CtxService(null, CID);
     return(Json(service.GetFlagboards()));
 }
Ejemplo n.º 15
0
        private IList <Helpers.PageInput> mapScheduleValues(IList <Helpers.PageInput> mobileInputs, int MS_Id, string CID)
        {
            if (MS_Id == 0)
            {
                return(mobileInputs);
            }

            Helpers.CtxService service = new Helpers.CtxService(null, CID);

            Models.EF.Maintenance_Schedule schedule = service.getScheduleRecord(MS_Id);

            if (schedule == null)
            {
                return(mobileInputs);
            }

            Helpers.objectMapper <Maintenance_Schedule> mapper = new Helpers.objectMapper <Maintenance_Schedule>();

            Hashtable hash = mapper.createPropertyInfoHash();

            ICollection keys = hash.Keys;

            if (keys.Count > 0)
            {
                foreach (var item in mobileInputs)
                {
                    try
                    {
                        if (hash[item.input.id.ToUpper()] != null)
                        {
                            PropertyInfo info = (PropertyInfo)hash[item.input.id.ToUpper()];
                            if (info != null && item.input != null)
                            {
                                var val = info.GetValue(schedule);
                                if (val == null)
                                {
                                    val = "";
                                }
                                if (info.PropertyType.Name.ToUpper() == "DATETIME")
                                {
                                    DateTime realdate = Convert.ToDateTime(val);
                                    item.input.value = realdate.ToString("yyyy-MM-dd");
                                }
                                else
                                {
                                    item.input.value = mapper.ConvertType(val.ToString(), "STRING").ToString();
                                }
                            }
                        }
                    } catch (Exception ex)
                    {
                        if (item.input != null)
                        {
                            item.errorFlag    = true;
                            item.errorMessage = ex.Message;
                        }
                    }
                }
            }

            return(mobileInputs);
        }
Ejemplo n.º 16
0
        private List <Helpers.PageInput> getEditorInputs(string CID, int MFB_Id, int MS_Id = 0)
        {
            List <Helpers.PageInput> inputs = new List <Helpers.PageInput>();

            inputs.Add(getFlagboardDropdown(CID, MFB_Id));

            inputs.Add(getMachineDropdown(CID, MFB_Id));

            inputs.Add(getMTypesDropdown(CID));

            inputs.Add(getEmployeesDropdown(CID));

            if (MS_Id == 0)
            {
                foreach (var item in inputs[inputs.Count - 1].input.options)
                {
                    if (item.text == ". .")
                    {
                        inputs[inputs.Count - 1].input.value = item.value;
                        break;
                    }
                }
            }

            inputs.Add(new Helpers.PageInput("default", "Unscheduled Reason", "MS_Unscheduled_Reason", "MS_Unscheduled_Reason", ""));

            if (MS_Id == 0)
            {
                Helpers.CtxService service = new Helpers.CtxService(null, CID);
                try
                {
                    inputs.Add(new Helpers.PageInput("default", "WorkOrder Number", "MS_Workorder", "MS_Workorder", service.getNewWorkoder().ToString()));
                }
                finally
                {
                    service.Dispose();
                }
            }
            else
            {
                inputs.Add(new Helpers.PageInput("default", "WorkOrder Number", "MS_Workorder", "MS_Workorder", ""));
            }

            Helpers.PageInput lastDate = new Helpers.PageInput("default", "Last Maintenance Date", "MS_Last_Main_Date", "MS_Last_Main_Date", "");
            lastDate.function = "date";
            inputs.Add(lastDate);

            Helpers.PageInput nextDate = new Helpers.PageInput("default", "Next Maintenance Date", "MS_Next_Main_Date", "MS_Next_Main_Date", "");
            nextDate.function = "date";
            inputs.Add(nextDate);

            Helpers.PageInput completed = new Helpers.PageInput("default", "Completed by", "MS_Main_Comp_Date", "MS_Main_Comp_Date", "false");
            completed.function = "checkbox";
            inputs.Add(completed);

            inputs.Add(getMaintCodeDropdown());

            Helpers.PageInput timeAlotted = new Helpers.PageInput("default", "Time Alloted", "MS_Maint_Time_Alotted", "MS_Maint_Time_Alotted", "0");
            timeAlotted.function = "number";
            inputs.Add(timeAlotted);

            Helpers.PageInput timeRequired = new Helpers.PageInput("default", "Time Required", "MS_Maint_Time_Required", "MS_Maint_Time_Required", "0");
            timeRequired.function = "number";
            inputs.Add(timeRequired);

            Helpers.PageInput timeInterval = new Helpers.PageInput("default", "Time Interval", "MS_Frequency", "MS_Frequency", "0");
            timeInterval.function = "number";
            inputs.Add(timeInterval);

            Helpers.PageInput downtime = new Helpers.PageInput("timer", "Total Machine Downtime", "MS_Total_Machine_Downtime", "MS_Total_Machine_Downtime", "0");
            downtime.function = "timer";
            inputs.Add(downtime);

            Helpers.PageInput machineHours = new Helpers.PageInput("default", "Machine Hours", "MS_Machine_Hours", "MS_Machine_Hours", "0");
            machineHours.function = "number";
            inputs.Add(machineHours);

            inputs.Add(new Helpers.PageInput("default", "Notes", "MS_Notes", "MS_Notes", ""));

            return(inputs);
        }
Ejemplo n.º 17
0
        public JsonResult dispatch(string inputs, string type, string CID)
        {
            System.Web.Script.Serialization.JavaScriptSerializer jser = new System.Web.Script.Serialization.JavaScriptSerializer();
            Helpers.CtxService service     = new Helpers.CtxService(null, CID);
            string             userMessage = "";
            int msid = 0;

            if (inputs.Length == 0)
            {
                return(Json("Input Box Objects cannot be empty.", JsonRequestBehavior.AllowGet));
            }

            try
            {
                FlagBoard_mvc.Models.pageInputs[] inputObjects    = jser.Deserialize <FlagBoard_mvc.Models.pageInputs[]>(inputs);
                Helpers.jqGrid <FlagBoard_mvc.Models.schedule> jq = new Helpers.jqGrid <FlagBoard_mvc.Models.schedule>();
                FlagBoard_mvc.Models.schedule record = jq.mapToObjectProperty(inputObjects);
                switch (type)
                {
                case "edit":
                    if (record.MS_Unscheduled_Reason.Trim().Length > 50)
                    {
                        throw new Exception("Unscheduled Reason cannot be greater than 50 characters long.");
                    }

                    int rows = service.Update(record);
                    if (rows > 0 && record.MS_Maint_Code == 1 && record.MS_Main_Comp_Date == "True")
                    {
                        if (record.MS_Frequency < 1)
                        {
                            throw new Exception("Interval must be greater than 0");
                        }
                        AutoAddScheduledOrder(record, service);
                    }
                    userMessage = "true";
                    break;

                case "add":
                    if (record.MS_Unscheduled_Reason.Length > 50)
                    {
                        throw new Exception("Unscheduled Reason cannot be greater than 50 characters long.");
                    }

                    int rowsaff = service.Add(record);
                    service.Dispose();
                    if (rowsaff == 0)
                    {
                        throw new Exception("unknown error adding rows. ");
                    }
                    userMessage = "true";
                    msid        = service.rowKey;
                    break;

                case "delete":
                    service.delete(record.MS_Id);
                    userMessage = "true";
                    break;
                }
            } catch (Exception ex)
            {
                userMessage = "ERROR: " + ex.Message;
            } finally
            {
                service.Dispose();
                service.clearCache();
            }

            return(Json(new { message = userMessage, id = msid }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 18
0
 private void delete(string CID, schedule record)
 {
     Helpers.CtxService service = new Helpers.CtxService(null, CID);
     service.deleteAsync(record.MS_Id);
     service.clearCache();
 }