public static string GetSelectList(string type, XElement element) { string jsonData = ""; if (type == "fix") { var items = element.Elements("item").Select(i => new { value = i.Attribute("value").Value, text = i.Value }).ToList(); jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(items); } if (type == "dictionary") { string CodeType = element.Value; List <dynamic> SysCodelist = new List <dynamic>(); using (var db = Db.Context("Sys")) { SysCodelist = db.Sql(string.Format("select Value as value,Text as text,CodeType as codetype from sys_code where CodeType='{0}'", CodeType)).QueryMany <dynamic>(); } jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(SysCodelist); } if (type == "single") { var connName = ReadXml.getXmlElementAttr(element, "connName"); var tableName = ReadXml.getXmlElementAttr(element, "tableName"); var selectField = ReadXml.getXmlElementAttr(element, "selectField"); var whereSql = ReadXml.getXmlElementAttr(element, "whereSql", "1=1"); List <dynamic> SingleList = new List <dynamic>(); using (var db = Db.Context(connName)) { string SearchSql = string.Format(@"select {0} from {1} where {2}", selectField, tableName, whereSql); SingleList = db.Sql(SearchSql).QueryMany <dynamic>(); } jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(SingleList); } return(jsonData); }
public static MvcHtmlString GetDataGridColumns(this HtmlHelper htmlHelper, string xmlName) { XElement targetXml = CommonSearchDialog.GetSearchXml(xmlName); List <XElement> fieldList = targetXml.Element("ColumnList").Elements("column").ToList(); List <Dictionary <string, object> > columsList = new List <Dictionary <string, object> >(); Dictionary <string, string> form = new Dictionary <string, string>(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("<table id='CommonDialogForm' data-bind='datagrid:gridSetting'>"); sb.AppendFormat("<thead><tr>"); foreach (var item in fieldList) { string title = ReadXml.getXmlElementAttr(item, "title"); string field = ReadXml.getXmlElementAttr(item, "field"); string hidden = ReadXml.getXmlElementAttr(item, "hidden"); string align = ReadXml.getXmlElementAttr(item, "align"); string sortable = ReadXml.getXmlElementAttr(item, "sortable"); string width = ReadXml.getXmlElementAttr(item, "width"); string formatter = ReadXml.getXmlElementAttr(item, "formatter"); string checkbox = ReadXml.getXmlElementAttr(item, "checkbox"); string gridFormat = ""; string gridEditor = ReadXml.getXmlElementValue(item, "gridEditor"); if (formatter != "") { if (formatter == "gridFormat") { gridFormat = ReadXml.getXmlElementValue(item, "gridFormat"); formatter = ""; } else { formatter = string.Format("formatter='{0}'", formatter); } } if (hidden != "") { hidden = string.Format("hidden='{0}'", hidden); } if (sortable != "") { sortable = string.Format("sortable='{0}'", sortable); } if (checkbox != "") { checkbox = string.Format("checkbox='{0}'", checkbox); } if (!string.IsNullOrWhiteSpace(gridEditor)) { gridEditor = string.Format("editor=\"{0}\"", gridEditor); } sb.AppendFormat("<th field='{0}' {1} align='{2}' width='{3}' {4} {6} {7} {8} {9}>{5}</th>", field, sortable, align, width, formatter, title, checkbox, gridFormat, hidden, gridEditor); } sb.AppendFormat("</tr></thead></table>"); return(MvcHtmlString.Create(sb.ToString())); }
public ActionResult CommonDialog2(string xmlName, string parm) { XElement targetXml = CommonSearchDialog.GetSearchXml(xmlName); List <XElement> fieldList = targetXml.Element("ColumnList").Elements("column").ToList(); Dictionary <string, string> form = new Dictionary <string, string>(); foreach (var item in fieldList) { var searchType = item.Attribute("searchType"); string field = ReadXml.getXmlElementAttr(item, "field"); if (searchType != null) { var currentValue = ""; if (parm != null) { string[] p = parm.Split(':'); if (field == p[0]) { form.Add(field, p[1]); } else { form.Add(field, currentValue); } } else { form.Add(field, currentValue); } } } var model = new { form = form, xmlName = xmlName }; ViewBag.xmlName = xmlName; return(View(model)); }
public ActionResult CommonDialog3(string xmlName) { XElement targetXml = CommonSearchDialog.GetSearchXml(xmlName); List <XElement> fieldList = targetXml.Element("ColumnList").Elements("column").ToList(); Dictionary <string, string> form = new Dictionary <string, string>(); foreach (var item in fieldList) { var searchType = item.Attribute("searchType"); string field = ReadXml.getXmlElementAttr(item, "field"); if (searchType != null) { form.Add(field, ""); } } var model = new { form = form, xmlName = xmlName }; ViewBag.xmlName = xmlName; return(View(model)); }