예제 #1
0
        protected void CallBackSaveRules_Rules_OnCallBack(object sender, CallBackEventArgs e)
        {
            string ID                 = e.Parameters[0];
            string IdentifierCode     = e.Parameters[1];
            string Name               = e.Parameters[2];
            string CustomCategoryCode = e.Parameters[3];
            string TypeId             = e.Parameters[4];
            string UserDefined        = e.Parameters[5];
            string Script             = e.Parameters[6];
            string CSharpCode         = e.Parameters[7];
            string JsonObject         = e.Parameters[8];
            string PageState          = e.Parameters[9];

            this.InitializeCulture();

            UIValidationExceptions uiValidationExceptions = new UIValidationExceptions();

            string[] retMessage = new string[4];

            decimal      iID         = 0;
            RuleTemplate RuleRecived = new RuleTemplate();

            RuleRecived.ID = Convert.ToDecimal(StringBuilder.CreateString(ID));

            PageState = StringBuilder.CreateString(PageState);
            if (PageState != "Delete")
            {
                RuleRecived.IdentifierCode     = Convert.ToDecimal(StringBuilder.CreateString(IdentifierCode));
                RuleRecived.Name               = StringBuilder.CreateString(Name);
                RuleRecived.CustomCategoryCode = StringBuilder.CreateString(CustomCategoryCode);
                RuleRecived.TypeId             = Convert.ToDecimal(StringBuilder.CreateString(TypeId));
                RuleRecived.UserDefined        = bool.Parse(StringBuilder.CreateString(UserDefined));
                RuleRecived.Script             = StringBuilder.CreateString(Script);
                RuleRecived.CSharpCode         = StringBuilder.CreateString(CSharpCode);
                RuleRecived.JsonObject         = JsonObject;
            }

            #region Effect on DB

            try
            {
                #region Set UIActionType Enum
                UIActionType uiActionType = UIActionType.ADD;
                switch (PageState.ToUpper())
                {
                    #region Add
                case "ADD":
                    uiActionType = UIActionType.ADD;
                    iID          = RuleBusiness.InsertRule(RuleRecived);
                    break;

                    #endregion
                    #region Edit
                case "EDIT":
                    uiActionType = UIActionType.EDIT;
                    if (RuleRecived.ID == 0)
                    {
                        retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, new Exception(GetLocalResourceObject("NoRuleSelectedforEdit").ToString()), retMessage);
                        hfCallBackDataSaveRules_Rules.Value = Newtonsoft.Json.JsonConvert.SerializeObject(retMessage);
                        this.hfCallBackDataSaveRules_Rules.RenderControl(e.Output);
                    }

                    var concept = RuleBusiness.GetByID(RuleRecived.ID);
                    RuleBusiness.Copy(RuleRecived, ref concept);

                    iID = RuleBusiness.UpdateRule(concept);
                    break;

                    #endregion
                    #region Delete
                case "DELETE":
                    uiActionType = UIActionType.DELETE;
                    if (RuleRecived.ID == 0)
                    {
                        retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, new Exception(GetLocalResourceObject("NoRuleSelectedforDelete").ToString()), retMessage);
                        hfCallBackDataSaveRules_Rules.Value = Newtonsoft.Json.JsonConvert.SerializeObject(retMessage);
                        this.hfCallBackDataSaveRules_Rules.RenderControl(e.Output);
                    }
                    iID = RuleBusiness.DeleteRule(RuleRecived);
                    break;

                    #endregion
                default:
                    break;
                }
                #endregion

                retMessage[0] = GetLocalResourceObject("RetSuccessType").ToString();
                string SuccessMessageBody = string.Empty;
                switch (uiActionType)
                {
                case UIActionType.ADD:
                    SuccessMessageBody = GetLocalResourceObject("AddComplete").ToString();
                    break;

                case UIActionType.EDIT:
                    SuccessMessageBody = GetLocalResourceObject("EditComplete").ToString();
                    break;

                case UIActionType.DELETE:
                    SuccessMessageBody = GetLocalResourceObject("DeleteComplete").ToString();
                    break;

                default:
                    break;
                }
                retMessage[1] = SuccessMessageBody;
                retMessage[2] = "success";
                retMessage[3] = iID.ToString(CultureInfo.InvariantCulture);

                hfCallBackDataSaveRules_Rules.Value = Newtonsoft.Json.JsonConvert.SerializeObject(retMessage);
                this.hfCallBackDataSaveRules_Rules.RenderControl(e.Output);
            }
            catch (UIValidationExceptions ex)
            {
                retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIValidationExceptions, ex, retMessage);
                hfCallBackDataSaveRules_Rules.Value = Newtonsoft.Json.JsonConvert.SerializeObject(retMessage);
                this.hfCallBackDataSaveRules_Rules.RenderControl(e.Output);
            }
            catch (UIBaseException ex)
            {
                retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIBaseException, ex, retMessage);
                hfCallBackDataSaveRules_Rules.Value = Newtonsoft.Json.JsonConvert.SerializeObject(retMessage);
                this.hfCallBackDataSaveRules_Rules.RenderControl(e.Output);
            }
            catch (Exception ex)
            {
                retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, ex, retMessage);
                hfCallBackDataSaveRules_Rules.Value = Newtonsoft.Json.JsonConvert.SerializeObject(retMessage);
                this.hfCallBackDataSaveRules_Rules.RenderControl(e.Output);
            }
            #endregion
        }
예제 #2
0
        public string[] UpdateRule_RulesPage(
            string ID,
            string IdentifierCode,
            string Name,
            string CustomCategoryCode,
            string TypeId,
            string UserDefined,
            string RuleOrder,
            string RuleOperationalAreaId,
            //string Script,
            //string CSharpCode,
            //string DesinegRuleID,
            //string JsonObject,
            //string ParameterObject,
            //string VariableObject,
            //string RuleObject,
            //string RuleStateobject,
            //string RulePriority,
            //string RuleTemplateID,
            string PageState)
        {
            this.InitializeCulture();

            UIValidationExceptions uiValidationExceptions = new UIValidationExceptions();

            string[] retMessage = new string[4];

            decimal      iID         = 0;
            RuleTemplate RuleRecived = new RuleTemplate();

            //DesignedRule DesignedRuleObj = new DesignedRule();
            //RuleRecived.OperationalArea = 0;
            RuleRecived.ID = Convert.ToDecimal(StringBuilder.CreateString(ID));
            //DesignedRuleObj.ID = Convert.ToDecimal(StringBuilder.CreateString(DesinegRuleID));
            PageState = StringBuilder.CreateString(PageState);
            if (PageState != "Delete")
            {
                //Decimal RuleId = Convert.ToDecimal(StringBuilder.CreateString(IdentifierCode));
                //Decimal RuleIdentifierCode = this.RuleIdentifierCode(RuleId);
                RuleRecived.Name = StringBuilder.CreateString(Name);
                RuleRecived.CustomCategoryCode = StringBuilder.CreateString(CustomCategoryCode);
                RuleRecived.TypeId             = Convert.ToDecimal(StringBuilder.CreateString(TypeId));
                Decimal TypeID = Convert.ToDecimal(StringBuilder.CreateString(TypeId));
                RuleRecived.IdentifierCode = this.RuleIdentifierCode(TypeID);

                RuleRecived.UserDefined     = bool.Parse(StringBuilder.CreateString(UserDefined));
                RuleRecived.Order           = Convert.ToInt32(StringBuilder.CreateString(RuleOrder));
                RuleRecived.OperationalArea = Convert.ToDecimal(StringBuilder.CreateString(RuleOperationalAreaId));
            }

            #region Effect on DB

            try
            {
                #region Set UIActionType Enum
                UIActionType uiActionType = UIActionType.ADD;
                switch (PageState.ToUpper())
                {
                    #region Add
                case "ADD":
                    uiActionType = UIActionType.ADD;
                    iID          = RuleBusiness.InsertRule(RuleRecived);
                    break;

                    #endregion
                    #region Edit
                case "EDIT":
                    uiActionType = UIActionType.EDIT;
                    if (RuleRecived.ID == 0)
                    {
                        retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, new Exception(GetLocalResourceObject("NoRuleSelectedforEdit").ToString()), retMessage);
                        return(retMessage);
                    }

                    var concept = RuleBusiness.GetByID(RuleRecived.ID);
                    RuleBusiness.Copy(RuleRecived, ref concept);

                    iID = RuleBusiness.UpdateRule(concept);
                    break;

                    #endregion
                    #region Delete
                case "DELETE":
                    uiActionType = UIActionType.DELETE;
                    if (RuleRecived.ID == 0)
                    {
                        retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, new Exception(GetLocalResourceObject("NoRuleSelectedforDelete").ToString()), retMessage);
                        return(retMessage);
                    }
                    iID = RuleBusiness.DeleteRule(RuleRecived);
                    break;

                    #endregion
                default:
                    break;
                }
                #endregion

                retMessage[0] = GetLocalResourceObject("RetSuccessType").ToString();
                string SuccessMessageBody = string.Empty;
                switch (uiActionType)
                {
                case UIActionType.ADD:
                    SuccessMessageBody = GetLocalResourceObject("AddComplete").ToString();
                    break;

                case UIActionType.EDIT:
                    SuccessMessageBody = GetLocalResourceObject("EditComplete").ToString();
                    break;

                case UIActionType.DELETE:
                    SuccessMessageBody = GetLocalResourceObject("DeleteComplete").ToString();
                    break;

                default:
                    break;
                }
                retMessage[1] = SuccessMessageBody;
                retMessage[2] = "success";
                retMessage[3] = iID.ToString();
                return(retMessage);
            }
            catch (UIValidationExceptions ex)
            {
                retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIValidationExceptions, ex, retMessage);
                return(retMessage);
            }
            catch (UIBaseException ex)
            {
                retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIBaseException, ex, retMessage);
                return(retMessage);
            }
            catch (Exception ex)
            {
                retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, ex, retMessage);
                return(retMessage);
            }
            #endregion
        }