예제 #1
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();
        }
예제 #2
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));
        }