public async Task <IActionResult> Index(UrlParameter param) { ViewBag.queryString = Request.QueryString.Value; var model = new ViewListModel(); model.Table = (await _tableListService.GetByIdAsync(param.id)).data; var result = await _tableColumnService.GetListAsync(item => item.TableId == param.id && item.ListVisible == 1); model.TableColumn = result.data.OrderBy(c => c.ListOrder).ToList(); ViewBag.TableName = model.Table.Description; var viewEditWidthHeight = string.IsNullOrEmpty(model.Table.ViewEditWidthHeight) || model.Table.ViewEditWidthHeight.Split("|").Length != 2 ? "90%,90%|90%,90%".Split("|") : model.Table.ViewEditWidthHeight.Split("|"); //example: width,height|width,height var viewWidth = viewEditWidthHeight[0].Split(',')[0]; var viewHeight = viewEditWidthHeight[0].Split(',')[1]; var addEditWidth = viewEditWidthHeight[1].Split(',')[0]; var addEditHeight = viewEditWidthHeight[1].Split(',')[1]; ViewBag.viewWidth = viewWidth.Contains("px") || viewWidth.Contains("%") ? viewWidth : "90%"; ViewBag.viewHeight = viewHeight.Contains("px") || viewHeight.Contains("%") ? viewHeight : "90%"; ViewBag.addEditWidth = addEditWidth.Contains("px") || addEditWidth.Contains("%") ? addEditWidth : "90%"; ViewBag.addEditHeight = addEditHeight.Contains("px") || addEditHeight.Contains("%") ? addEditHeight : "90%"; var showBtnModel = new ShowButtonModel { ShowAddBtn = model.Table.AllowAdd == 1, ShowEditBtn = model.Table.AllowEdit == 1, ShowDelBtn = model.Table.AllowDelete == 1, ShowImportBtn = model.Table.AllowImport == 1, ShowExportBtn = model.Table.AllowExport == 1, ShowDetailBtn = model.Table.AllowDetail == 1, TopExtendFunction = model.Table.TopExtendFunction, }; ViewBag.ShowButton = showBtnModel; foreach (var column in model.TableColumn) { if (column.DataType == ColumnType.Out || column.DataType == ColumnType.MultiSelect_Out) { var outSqlModel = new OutSqlModel(column.OutSql); var queryResult = await SysService.GetOutData(outSqlModel); var items = new List <SelectListItem>(); foreach (var row in queryResult) { items.Add(new SelectListItem { Value = row[outSqlModel.PrimaryKey].ToString(), Text = row[outSqlModel.TextKey].ToString(), }); } ViewData[column.Name] = new SelectList(items, "Value", "Text"); } else if (column.DataType == ColumnType.Enum) { var enumStr = column.EnumRange.Split(','); //value,value var items = new List <SelectListItem>(); for (int i = 0; i < enumStr.Length; i++) { items.Add(new SelectListItem { Value = enumStr[i], Text = enumStr[i] }); } ViewData[column.Name] = new SelectList(items, "Value", "Text"); } else if (column.DataType == ColumnType.MultiSelect) { var checkStr = column.SelectRange.Split('|'); //值,选项1|2,选项2 var items = new List <SelectListItem>(); for (int i = 0; i < checkStr.Length; i++) { items.Add(new SelectListItem { Value = checkStr[i].Split(',')[0], Text = checkStr[i].Split(',')[1], }); } ViewData[column.Name] = new SelectList(items, "Value", "Text"); } } return(View(model)); }
public async Task <IActionResult> Edit(UrlParameter param) { var model = new ViewListModel(); model.Table = (await _tableListService.GetByIdAsync(param.extraValue.Ext_ToInt32())).data; var result = await _tableColumnService.GetListAsync(item => item.TableId == model.Table.Id && item.EditVisible == 1); model.TableColumn = result.data.OrderBy(c => c.EditOrder).ToList(); var tbName = model.Table.Name; var columnValue = (await SqlService.Query( string.Format("select {0} from {1} where {2}", "*", tbName, "Id=" + param.id))).First(); ViewBag.ColumnValue = columnValue; var fileData = new Dictionary <string, IList <object> >(); ViewData["FileData"] = ""; foreach (var column in model.TableColumn) { var colValue = string.Empty; if (columnValue.ContainsKey(column.Name)) { colValue = columnValue[column.Name].ToString(); } if (column.DataType == ColumnType.Out) { var outSqlModel = new OutSqlModel(column.OutSql); var queryResult = await SysService.GetOutData(outSqlModel); var items = new List <SelectListItem>(); items.Add(new SelectListItem { Value = "0", Text = "无", }); //遍历outsql查询的数据中全部项 foreach (var row in queryResult) { items.Add(new SelectListItem { Value = row[outSqlModel.PrimaryKey].ToString(), Text = row[outSqlModel.TextKey].ToString(), }); } ViewData[column.Name] = new SelectList(items, "Value", "Text", colValue); } else if (column.DataType == ColumnType.MultiSelect_Out) { var outSqlModel = new OutSqlModel(column.OutSql); var queryResult = await SysService.GetOutData(outSqlModel); var items = new List <SelectListItem>(); //遍历outsql查询的数据中全部项 foreach (var row in queryResult) { items.Add(new SelectListItem { Value = row[outSqlModel.PrimaryKey].ToString(), Text = row[outSqlModel.TextKey].ToString(), }); } var selectValues = new List <object>(); if (outSqlModel.IsSave) { selectValues = (await SysService.GetMultiSelectOutValue(outSqlModel, param.id.ToString())).data.ToList(); } else { foreach (var item in colValue.Split(',')) { selectValues.Add(item); } } ViewData[column.Name] = new MultiSelectList(items, "Value", "Text", selectValues); } else if (column.DataType == ColumnType.Enum) { //获取此条数据列类型为Enum的字段的值,以便之后SelectList的默认选中Selected使用 var enumStr = column.EnumRange.Split(','); //value,value var items = new List <SelectListItem>(); for (int i = 0; i < enumStr.Length; i++) { items.Add(new SelectListItem { Value = enumStr[i], Text = enumStr[i], }); } ViewData[column.Name] = new SelectList(items, "Value", "Text", colValue); } else if (column.DataType == ColumnType.MultiSelect) { var selectValues = colValue.Split(','); var checkStr = column.SelectRange.Split('|'); //1,选项1|2,选项2 var items = new List <SelectListItem>(); foreach (var item in checkStr) { items.Add(new SelectListItem { Selected = selectValues.Contains(item.Split(',')[0]), Value = item.Split(',')[0], Text = item.Split(',')[1], }); } ViewData[column.Name] = new MultiSelectList(items, "Value", "Text", selectValues); } else if (column.DataType == ColumnType.File || column.DataType == ColumnType.Image) { var files = colValue.Split(','); fileData.Add(column.DataType + column.Name, new List <object>()); foreach (var file in files) { fileData[column.DataType + column.Name].Add(new { fileUrl = file, fileType = Path.GetExtension(file).TrimStart('.'), fileName = Path.GetFileNameWithoutExtension(file), columnType = column.DataType }); } } } if (fileData.Keys.Count > 0) { ViewData["FileData"] = JsonConvert.SerializeObject(fileData); } return(View(model)); }
public async Task <IActionResult> Detail(UrlParameter param) { var model = new ViewListModel(); model.Table = (await _tableListService.GetByIdAsync(param.extraValue.Ext_ToInt32())).data; var result = await _tableColumnService.GetListAsync(item => item.TableId == model.Table.Id && item.ViewVisible == 1); model.TableColumn = result.data.OrderBy(c => c.ViewOrder).ToList(); string sql = "select {0} from {1} where {2}"; ViewBag.OutColumn = new Dictionary <string, object>(); var tbName = model.Table.Name; var columnValueResult = await SqlService.Query( string.Format(sql, "*", tbName, "Id=" + param.id)); var columnValue = columnValueResult.First(); ViewBag.ColumnValue = columnValue; foreach (var column in model.TableColumn) { if (column.DataType == ColumnType.Out) { var outSqlModel = new OutSqlModel(column.OutSql); var outColValue = await SysService.GetOutValue(outSqlModel, columnValue[column.Name].ToString()); ViewBag.OutColumn[column.Name] = outColValue.data; } else if (column.DataType == ColumnType.MultiSelect_Out) { var outSqlModel = new OutSqlModel(column.OutSql); var queryResult = await SysService.GetOutData(outSqlModel); //如果保存到外表 查询的是外表值 if (outSqlModel.IsSave) { var selectValues = (await SysService.GetMultiSelectOutValue(outSqlModel, param.id.ToString())).data; var outColValues = queryResult.Where(item => selectValues.Contains(item[outSqlModel.PrimaryKey].ToString())) .Select(item => item[outSqlModel.TextKey]).ToList(); ViewBag.OutColumn[column.Name] = string.Join(",", outColValues); } //否则查询本表此列值 else { ViewBag.OutColumn[column.Name] = columnValue[column.Name]; } } else if (column.DataType == ColumnType.MultiSelect) { var selectValues = columnValueResult.First()[column.Name].ToString().Split(','); var checkStr = column.SelectRange.Split('|'); //1,选项1|2,选项2 var items = new List <SelectListItem>(); var selectText = string.Empty; foreach (var item in checkStr) { if (selectValues.Contains(item.Split(',')[0])) { selectText += item.Split(',')[1] + ","; } } ViewBag.ColumnValue[column.Name] = selectText.Trim(','); } } return(View(model)); }
public async Task <IActionResult> Add(UrlParameter param) { var model = new ViewListModel(); model.Table = (await _tableListService.GetByIdAsync(param.id)).data; var result = await _tableColumnService.GetListAsync(item => item.TableId == param.id && item.AddVisible == 1); model.TableColumn = result.data.OrderBy(c => c.EditOrder).ToList(); foreach (var column in model.TableColumn) { if (column.DataType == ColumnType.Out || column.DataType == ColumnType.MultiSelect_Out) { var outSqlModel = new OutSqlModel(column.OutSql); var queryResult = await SysService.GetOutData(outSqlModel); var items = new List <SelectListItem>(); //items.Add(new SelectListItem //{ // Value = "0", // Text = "无" //}); foreach (var row in queryResult) { items.Add(new SelectListItem { Value = row[outSqlModel.PrimaryKey].ToString(), Text = row[outSqlModel.TextKey].ToString(), }); } ViewData[column.Name] = new SelectList(items, "Value", "Text"); } else if (column.DataType == ColumnType.Enum) { var enumStr = column.EnumRange.Split(','); //value,value var items = new List <SelectListItem>(); for (int i = 0; i < enumStr.Length; i++) { items.Add(new SelectListItem { Value = enumStr[i], Text = enumStr[i] }); } ViewData[column.Name] = new SelectList(items, "Value", "Text"); } else if (column.DataType == ColumnType.MultiSelect) { var checkStr = column.SelectRange.Split('|'); //1,选项1|2,选项2 var items = new List <SelectListItem>(); foreach (var item in checkStr) { items.Add(new SelectListItem { Value = item.Split(',')[0], Text = item.Split(',')[1], }); } ViewData[column.Name] = new SelectList(items, "Value", "Text"); } } return(View(model)); }