public IActionResult FreeFormSet(string fid) { CfgFreeForm ffModel = _dbContext.Get <CfgFreeForm>(fid); IEnumerable <FapTable> childTables = _platformDomain.TableSet.Where(t => t.MainTable == ffModel.BillTable); ViewBag.DbFields = _dbContext.Columns(ffModel.BillTable); ViewBag.ChildTables = childTables; return(View(ffModel)); }
/// <summary> /// 获取自由表单设置 /// </summary> private void GetFreeFromSet() { DynamicParameters param = new DynamicParameters(); param.Add("Table", _fapTable.TableName); if (_formTemplate.IsPresent()) { FFrm = _dbContext.Get <CfgFreeForm>(_formTemplate); } else { FFrm = _dbContext.QueryFirstOrDefaultWhere <CfgFreeForm>("BillTable=@Table and Enabled=1", param); } if (FFrm == null) { return; } //得到模板中用到的字段 List <string> existCols = new List <string>(); //子表集合 List <string> childTables = new List <string>(); string vPattern = FapPlatformConstants.VariablePattern; Regex reg = new Regex(vPattern); //匹配字段 MatchCollection matchs = reg.Matches(FFrm.FFContent); if (matchs.Any()) { foreach (var mtch in matchs) { int length = mtch.ToString().Length - 3; string colComment = mtch.ToString().Substring(2, length); existCols.Add(colComment); } } string cPattern = FapPlatformConstants.CollectionPattern; reg = new Regex(cPattern); //匹配子表 matchs = reg.Matches(FFrm.FFContent); if (matchs.Any()) { var childTableList = _dbContext.Tables(t => t.MainTable == _fapTable.TableName); foreach (var mtch in matchs) { string childTableLabel = mtch.ToString().TrimStart(new char[] { '{', '{' }).TrimEnd(new char[] { '}', '}' }); var childTable = childTableList.FirstOrDefault(t => t.TableComment.Equals(childTableLabel)); if (childTable != null && !IsNullOrWhiteSpace(childTable.TableName)) { if (!_childTableList.ContainsKey(mtch.ToString())) { _childTableList.Add(mtch.ToString(), childTable); } else { //替换第一个为空,始终保留一个 FFrm.FFContent = reg.Replace(FFrm.FFContent, "", 1, 0); throw new FapException("自由表单包含两个一样的子表设置"); } } } } //模板中存在的列 _existTemplateFields = formFields.Where(f => existCols.Contains(f.FieldComment)).ToList(); }