Beispiel #1
0
        public string GetValue(string formData, string parameter)
        {
            var     result = parameter;
            JObject jObj   = new JObject();

            if (!string.IsNullOrEmpty(formData))
            {
                jObj = JObject.Parse(formData);
            }

            var node = parameter.Replace("field(", "").Replace("emailField(", "").Replace("role(", "").Replace("emailRole(", "").Replace("parameter(", "");

            if (!string.IsNullOrEmpty(node) && node.Last() == ')')
            {
                node = node.Substring(0, node.Length - 1);
            }

            if (parameter.Contains("role(") && XmlForm == null)
            {
                LoadXmlForm(int.Parse(jObj["FormId"].ToString()));
            }

            if (parameter.Contains("field(") && jObj[node] != null)
            {
                if (node.Contains(","))
                {
                    var nodeSplit = node.Split(',');
                    foreach (var field in nodeSplit)
                    {
                        if (jObj[field] != null && !string.IsNullOrEmpty(jObj[field].Value <string>()))
                        {
                            result = jObj[field].Value <string>();
                            break;
                        }
                    }
                }
                else
                {
                    result = jObj[node].Value <string>();
                }
            }
            else if (parameter.Contains("emailField(") && jObj["email" + node] != null)
            {
                if (node.Contains(","))
                {
                    var nodeSplit = node.Split(',');
                    foreach (var field in nodeSplit)
                    {
                        if (jObj[field] != null && !string.IsNullOrEmpty(jObj["email" + field].Value <string>()))
                        {
                            result = jObj["email" + field].Value <string>();
                            break;
                        }
                    }
                }
                else
                {
                    result = jObj["email" + node].Value <string>();
                }
            }
            else if (parameter.Contains("role("))
            {
                var users = XmlForm.SelectNodes("//body/roles/role[id='" + node + "']/users/user");
                if (users.Count > 0)
                {
                    result = "";
                }
                for (var i = 0; i < users.Count; i++)
                {
                    result += users[i].SelectSingleNode("name").InnerXml;
                    if (i != users.Count - 1)
                    {
                        result += ",";
                    }
                }
            }
            else if (parameter.Contains("emailRole("))
            {
                var users = XmlForm.SelectNodes("//body/roles/role[id='" + node + "']/users/user");
                if (users.Count > 0)
                {
                    result = "";
                }
                for (var i = 0; i < users.Count; i++)
                {
                    result += users[i].SelectSingleNode("email").InnerXml;
                    if (i != users.Count - 1)
                    {
                        result += ",";
                    }
                }
            }
            else if (parameter.Contains("parameter("))
            {
                result = XmlForm.SelectSingleNode("//body/parameters/parameter[id='" + node + "']/value").InnerXml;
            }

            return(result);
        }
Beispiel #2
0
        private void LoadActions(string status)
        {
            //UpdateCulture();

            var closeForm = (IActionViewModel)ActionViewModel.Clone();

            HeaderViewModel.CloseForm = closeForm;
            //HeaderViewModel.CloseForm.Title = Resources.Language.lblCloseForm;
            HeaderViewModel.CloseForm.Title = Constants.Close;

            if (FormRequestViewModel.UserAssigned.ToLower() != UserUtil.DisplayUserName.ToLower())
            {
                return;
            }

            var saveForm = (IActionViewModel)ActionViewModel.Clone();

            HeaderViewModel.SaveForm = saveForm;
            //HeaderViewModel.SaveForm.Title = Resources.Language.lblSaveForm;
            HeaderViewModel.SaveForm.Title = Constants.Save;

            if (!string.IsNullOrEmpty(status) && XmlForm != null)
            {
                FormRequestViewModel.HeaderViewModel.FormActions = new List <IActionViewModel>();
                var actionNodes = XmlForm.SelectNodes("//body/statuses/status[name='" + status + "']/actions/action");

                foreach (XmlNode action in actionNodes)
                {
                    var visibleCondition = "";
                    if (action["visible"] != null)
                    {
                        visibleCondition = action["visible"].InnerText;
                        string[] functions = { "parameter(", "role(" };
                        foreach (var func in functions)
                        {
                            while (visibleCondition.Contains(func))
                            {
                                var index     = visibleCondition.IndexOf(func);
                                var endIndex  = visibleCondition.IndexOf(")", index);
                                var parameter = visibleCondition.Substring(index, endIndex - index + 1);
                                var value     = FormXmlService.GetValue(FormRequestViewModel.JSonFormData, parameter);

                                visibleCondition = visibleCondition.Replace(parameter, "'" + value + "'");
                            }
                        }
                    }

                    var newStatusNode = XmlForm.SelectSingleNode("//body/statuses/status[name='" + action["targetStatus"].InnerText + "']");

                    var newAction = new ActionViewModel
                    {
                        Id                    = action["name"].InnerText,
                        RequestFormId         = FormRequestViewModel.Id,
                        Title                 = action["displayName"].InnerText,
                        RequiredFields        = action["requiredFields"] == null ? null : action["requiredFields"].InnerText,
                        SendEmailNotification = action["sendEmailNotification"] == null ? null : action["sendEmailNotification"].InnerText,
                        ConfirmationText      = action["confirmationText"] == null ? "Are you sure you want to realize this action?" : action["confirmationText"].InnerText,
                        CommentRequired       = action["commentRequired"] == null || action["commentRequired"].InnerText != "true" ? false : true,
                        HistoryText           = action["historyText"] == null ? string.Empty : action["historyText"].InnerText,
                        VisibleValidation     = action["visible"] == null ? "" : visibleCondition,
                        JSFunction            = action["jsFunction"] == null ? "" : action["jsFunction"].InnerText,
                        AddCommentToList      = action["addCommentToList"] == null ? "" : action["addCommentToList"].InnerText,
                        CancelStatusChange    = action["cancelStatusChange"] == null || string.IsNullOrEmpty(action["cancelStatusChange"].InnerText) || action["cancelStatusChange"].InnerText.ToLower() != "true" ? false : true,
                        NewStatus             = action["targetStatus"].InnerText,
                        NewStatusDisplayName  = newStatusNode["displayName"].InnerText
                    };

                    FormRequestViewModel.HeaderViewModel.FormActions.Add(newAction);
                }
            }
        }