private static Control GenerateSliderIE(AMLParam param, string stepvalue) { LiteralControl lit = new LiteralControl(); lit.Text += string.Format("{0:#,###0}",int.Parse(param.MinValue)); lit.Text += string.Format("<div id=\"IEslider_{0}\" class = \"IEslider slider-displayIE\" data-begin=\"{1}\" data-end=\"{2}\" data-def=\"{3}\" data-step=\"{4}\"></div>", param.Name, param.MinValue, param.MaxValue, param.DefaultValue, stepvalue); lit.Text += string.Format("{0:#,###0}", int.Parse(param.MaxValue)); return lit; }
List<AMLParam> ParseMLParmeter(string jsonStr, string ParameterXPath) { try { List<AMLParam> result = new List<AMLParam>(); var objects = JObject.Parse(jsonStr); JToken jtoken = objects.SelectToken(ParameterXPath); //JArray jarrRequired = JArray.Parse(jtoken["required"].ToString()); JObject ParameterObj = JObject.Parse(jtoken["properties"].ToString()); //var listRequired = jarrRequired.ToList(); foreach (var obj in ParameterObj) { AMLParam param = new AMLParam(); param.Name = obj.Key; param.Type = obj.Value["type"] != null? obj.Value["type"].ToString() : ""; param.Format = obj.Value["format"] != null ? obj.Value["format"].ToString() : ""; param.Description = obj.Value["description"] != null ? obj.Value["description"].ToString() : ""; param.DefaultValue = obj.Value["default"] != null ? obj.Value["default"].ToString() : ""; // Parse Description string to get Alias string[] desSplit = param.Description.Split('|'); if (desSplit.Length == 2) { param.Alias = desSplit[0]; param.Description = desSplit[1]; } if (param.Type == "boolean") { param.StrEnum = new List<string>(); param.StrEnum.Add("true"); param.StrEnum.Add("false"); } // Fill list Emum and set Default Value if (obj.Value["enum"] != null) { JArray strEnum = JArray.Parse(obj.Value["enum"].ToString()); param.StrEnum = strEnum.ToObject<List<string>>(); if (string.IsNullOrEmpty(param.DefaultValue)) param.DefaultValue = param.StrEnum[0]; } else { if (param.Type == "integer" || param.Type == "number") if (string.IsNullOrEmpty(param.DefaultValue)) param.DefaultValue = "0"; else if (param.Type == "bool") if (string.IsNullOrEmpty(param.DefaultValue)) param.DefaultValue = "true"; } result.Add(param); } return result; } catch (Exception) { return new List<AMLParam>(); } }
private static Control GenerateScriptSlideIE(AMLParam param) { LiteralControl lit = new LiteralControl(); lit.Text += "<script>"; lit.Text += "document.getElementById(\"slider_{0}\").onchange = function(event){document.getElementById(\"{0}\").value = event.target.value};".Replace("{0}", param.Name); lit.Text += "document.getElementById(\"{0}\").onchange = function(event){document.getElementById(\"slider_{0}\").value = event.target.value};".Replace("{0}", param.Name); lit.Text += "</script>"; return lit; }
/// <summary> /// Create slider by HTML5, we don't need default value because jQuery will update slider's value from textbox /// </summary> /// <param name="param"></param> /// <param name="stepvalue"></param> /// <returns></returns> private static Control GenerateSliderHTML(AMLParam param, string stepvalue) { LiteralControl lit = new LiteralControl(); lit.Text += "<div class=\"input-group\">"; lit.Text += "<span class=\"input-group-addon\">" + string.Format("{0:#,###0}",int.Parse(param.MinValue)) + "</span>"; lit.Text += string.Format("<input id=\"slider_{0}\" type=\"range\" min=\"{1}\" max=\"{2}\" step=\"{3}\" class=\"slider slider-displayHTML form-control\"/>", param.Name, param.MinValue, param.MaxValue, stepvalue); lit.Text += "<span class=\"input-group-addon\">" + string.Format("{0:#,###0}",int.Parse(param.MaxValue)) + "</span>"; //lit.Text += "</div>"; // sitll miss this end div for txt control //lit.Text += param.MaxValue; return lit; }
static IEnumerable<Control> GenerateInputControl(AMLParam param, HttpBrowserCapabilities browser) { if (param.StrEnum != null && param.StrEnum.Count > 3) // Drop list { yield return GenerateDropdownList(param); } else if (param.StrEnum != null && param.StrEnum.Count <= 3 && param.StrEnum.Count > 0) // Radio Button { yield return GenerateRadio(param); } else if (param.Type.ToLower() == "integer") // slider number Integer { TextBox txt = new TextBox(); txt.ID = param.Name; txt.Text = param.DefaultValue; txt.Attributes.Add("Class", "amount form-control form-control-number"); if (param.Type == "integer") txt.TextMode = TextBoxMode.Number; if(browser.Browser.ToLower() == "internetexplorer") { yield return GenerateSliderHTML(param, "1"); yield return txt; yield return new LiteralControl("</div>"); // end of div yield return GenerateScriptSlideIE(param); } else { yield return GenerateSliderHTML(param, "1"); yield return txt; yield return new LiteralControl("</div>"); // end of div yield return GenerateScriptSlideHTML(param); } } else if (param.Type.ToLower() == "number") // slider number Integer { TextBox txt = new TextBox(); txt.ID = param.Name; txt.Text = param.DefaultValue; txt.Attributes.Add("Class", "amount form-control form-control-number"); if (browser.Browser.ToLower() == "internetexplorer") { yield return GenerateSliderHTML(param, "0.01"); yield return txt; yield return new LiteralControl("</div>"); // end of div yield return GenerateScriptSlideIE(param); } else { yield return GenerateSliderHTML(param, "0.01"); yield return txt; yield return new LiteralControl("</div>"); // end of div yield return GenerateScriptSlideHTML(param); } } else { TextBox txt = new TextBox(); txt.ID = param.Name; txt.Text = param.DefaultValue; txt.Attributes.Add("Class", "form-control"); if (param.Type == "integer") txt.TextMode = TextBoxMode.Number; yield return txt; } }
private static Control GenerateRadio(AMLParam param) { RadioButtonList rabtnList = new RadioButtonList(); rabtnList.ID = param.Name; var listEmum = param.StrEnum.OrderBy(x => x.Length).ToList(); foreach (string ele in listEmum) { ListItem litem = new ListItem(); litem.Text = ele; if (litem.Text.ToLower() == param.DefaultValue.ToLower()) litem.Selected = true; rabtnList.Items.Add(litem); } rabtnList.RepeatLayout = RepeatLayout.Flow; rabtnList.RepeatDirection = RepeatDirection.Horizontal; return rabtnList; }
List <AMLParam> ParseMLParmeter(string jsonStr, string ParameterXPath) { try { List <AMLParam> result = new List <AMLParam>(); var objects = JObject.Parse(jsonStr); JToken jtoken = objects.SelectToken(ParameterXPath); //JArray jarrRequired = JArray.Parse(jtoken["required"].ToString()); JObject ParameterObj = JObject.Parse(jtoken["properties"].ToString()); //var listRequired = jarrRequired.ToList(); foreach (var obj in ParameterObj) { AMLParam param = new AMLParam(); param.Name = obj.Key; param.Type = obj.Value["type"] != null ? obj.Value["type"].ToString() : ""; param.Format = obj.Value["format"] != null ? obj.Value["format"].ToString() : ""; param.Description = obj.Value["description"] != null ? obj.Value["description"].ToString() : ""; param.DefaultValue = obj.Value["default"] != null ? obj.Value["default"].ToString() : ""; // Parse Description string to get Alias string[] desSplit = param.Description.Split('|'); if (desSplit.Length == 2) { param.Alias = desSplit[0]; param.Description = desSplit[1]; } if (param.Type == "boolean") { param.StrEnum = new List <string>(); param.StrEnum.Add("true"); param.StrEnum.Add("false"); //if (string.IsNullOrEmpty(param.DefaultValue)) param.DefaultValue = "true"; } // Fill list Emum and set Default Value if (obj.Value["enum"] != null) { JArray strEnum = JArray.Parse(obj.Value["enum"].ToString()); param.StrEnum = strEnum.ToObject <List <string> >(); if (string.IsNullOrEmpty(param.DefaultValue)) { param.DefaultValue = param.StrEnum[0]; } } else { if (param.Type == "integer" || param.Type == "number") { if (string.IsNullOrEmpty(param.DefaultValue)) { param.DefaultValue = "0"; } } else if (param.Type == "boolean") { if (string.IsNullOrEmpty(param.DefaultValue)) { param.DefaultValue = "true"; } } } param.Group = ParameterXPath.Replace("definitions.", "").Replace("Item", ""); result.Add(param); } return(result); } catch (Exception) { return(null); } }
private static Control GenerateDropdownList(AMLParam param) { DropDownList drop = new DropDownList(); drop.ID = param.Name; drop.Attributes.Add("Class", "form-control"); foreach (string ele in param.StrEnum) { ListItem litem = new ListItem(); litem.Text = ele; if (litem.Text.ToLower() == param.DefaultValue.ToLower()) litem.Selected = true; drop.Items.Add(litem); } return drop; }
private Control GenerateCOntrolEnable(AMLParam param, string id) { CheckBox chb = new CheckBox(); chb.ID = id; chb.Checked = param.Enable; return chb; }
private Control GenerateControlMin(AMLParam param, string id) { TextBox txt = new TextBox(); txt.ID = id; txt.Text = param.MinValue; txt.Attributes.Add("Class", "amount form-control form-control-number"); if (param.Type == "integer") { txt.TextMode = TextBoxMode.Number; return txt; } else if (param.Type == "number") { return txt; } else { txt.Text = "Null"; txt.ReadOnly = true; return txt; } }
private Control GenerateControlDescription(AMLParam param, string id) { TextBox txt = new TextBox(); txt.ID = id; txt.Text = param.Description; txt.Attributes.Add("Class", "amount form-control"); txt.TextMode = TextBoxMode.MultiLine; return txt; }
private Control GenerateControlDefault(AMLParam param, string id) { TextBox txt = new TextBox(); txt.ID = id; txt.Text = param.DefaultValue; txt.Attributes.Add("Class", "amount form-control form-control-number"); if (param.Type == "integer") { txt.TextMode = TextBoxMode.Number; return txt; } else if (param.StrEnum != null && param.StrEnum.Count > 0) // Droplist return GenerateDropdownList(param, id); else return txt; }
private Control GenerateControlAlias(AMLParam param, string id) { TextBox txt = new TextBox(); txt.ID = id; txt.Text = param.Alias; txt.Attributes.Add("Class", "amount form-control"); return txt; }
private static string GenerateID(AMLParam param) { return param.Group + param.Name; }
private Control GenerateControlMax(AMLParam param, string id) { TextBox txt = new TextBox(); txt.ID = id; txt.Text = param.MaxValue; txt.Attributes.Add("Class", "amount form-control form-control-number"); if (param.StrEnum != null && param.StrEnum.Count > 0) // Droplist { txt.Text = ""; txt.ReadOnly = true; return txt; } if (param.Type == "integer") { txt.TextMode = TextBoxMode.Number; return txt; } else if (param.Type == "number") { return txt; } else { txt.Text = ""; txt.ReadOnly = true; return txt; } }