/// <summary> /// 在分页加载时,通过移动前端传递过来的列头信息构造数据字符串 /// </summary> /// <param name="columnsInfoString">移动前端传递过来的列头信息字符串</param> /// <param name="report">MobileReport对象</param> /// <returns>结果DSL串</returns> internal static string TransferToRowData(string columnsInfoString, MobileReport report) { var rowBuilder = new StringBuilder(); var semirows = new SemiRows(); if (report != null) { semirows = report.SemiRows; } string[] columns = columnsInfoString.Split(','); foreach (SemiRow semiRow in semirows) { rowBuilder.Append("<row>"); if (semiRow.SectionType == SectionType.ReportSummary) // 如果当前行是总计行 { rowBuilder.Append(@"<column>总计</column>"); for (int i = 0; i < columns.Length; i++) { if (i == 0) { continue; } rowBuilder.Append(string.Format(@"<column>{0}</column>", semiRow[columns[i]])); } } else // 如果当前行是普通数据行 { foreach (string t in columns) { rowBuilder.Append(string.Format(@"<column>{0}</column>", semiRow[t])); } } rowBuilder.Append("</row>"); } return(rowBuilder.ToString()); }
/// <summary> /// 在分页加载时,通过移动前端传递过来的列头信息构造数据字符串 /// </summary> /// <param name="columnsInfoString">移动前端传递过来的列头信息字符串</param> /// <param name="report">MobileReport对象</param> /// <returns>结果DSL串</returns> internal static string TransferToRowDataJson(string columnsInfoString, MobileReport report) { var rowBuilder = new StringBuilder(); var semirows = new SemiRows(); if (report != null) { semirows = report.SemiRows; } string[] columns = columnsInfoString.Split(','); rowBuilder.Append("\"data\":["); int j = 0; foreach (SemiRow semiRow in semirows) { rowBuilder.Append("{\"RowNumber\":"); rowBuilder.Append(string.Format("\"{0}\",", j.ToString())); //rowBuilder.Append(string.Format("{\"RowNumber\":\"{0}\"", j.ToString())); if (semiRow.SectionType == SectionType.ReportSummary) // 如果当前行是总计行 { rowBuilder.Append("\"level\":\"0\","); for (int i = 0; i < columns.Length; i++) { rowBuilder.Append(string.Format("\"{0}\":", columns[i].ToString())); if (i == 0) { rowBuilder.Append("\"总计\","); continue; } if (semiRow.Contains(columns[i])) { rowBuilder.Append(string.Format("\"{0}\",", (semiRow[columns[i]].ToString()).Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\"", ""))); } else { rowBuilder.Append("\"\","); } //rowBuilder.Append(string.Format("\"{0}\":\"{1}\"", columns[i].ToString(), semiRow[columns[i]])); } rowBuilder.Remove(rowBuilder.Length - 1, 1); rowBuilder.Append("},"); } else // 如果当前行是普通数据行 { foreach (string t in columns) { if (semiRow.Contains(t)) { rowBuilder.Append(string.Format("\"{0}\":\"{1}\",", t, semiRow[t].ToString().Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\"", "\\\""))); } else { rowBuilder.Append(string.Format("\"{0}\":\"{1}\",", t, "")); } } rowBuilder.Remove(rowBuilder.Length - 1, 1); rowBuilder.Append("},"); } //rowBuilder.Append("}"); j++; } if (semirows.Count != 0) { rowBuilder.Remove(rowBuilder.Length - 1, 1); } rowBuilder.Append("]}"); return(rowBuilder.ToString()); }
/// <summary> /// 转换为DSL /// </summary> /// <param name="obj">报表对象</param> /// <returns>DSL字符串</returns> public static string TransferToTableSchema(object obj) { bool _isMutiReport = false; var dslsb = new StringBuilder(); var cellList = new List <Cell>(); var mobileReport = obj as MobileReport; var semirows = new SemiRows(); var supperCellList = new List <SuperCell>(); var childCellList = new List <Cell>(); Hashtable ht = new Hashtable(); string headerRow = "1"; if (mobileReport != null) { Report report = mobileReport.Report; if (report != null) { // 这里取pageTitle的一个对象来组成报表标题区域的值 Section section = report.Sections[SectionType.PageTitle]; foreach (object gridDetailCell in section.Cells) { var cell = gridDetailCell as Cell; if (cell != null && cell.Visible) { if (cell is SuperLabel) { headerRow = "2"; _isMutiReport = true; supperCellList.Add(new SuperCell(cell, 0, 0)); } cellList.Add(gridDetailCell as Cell); ht.Add(cell.Name, cell.Caption); } } if (_isMutiReport) //如果出现多表头,则从Detail中取得子列头,并且进行拼接处理 { cellList = new List <Cell>(); section = report.Sections[SectionType.Detail]; foreach (object gridDetailCell in section.Cells) { var cell = gridDetailCell as Cell; if (cell.Visible) { if (ht.Contains(cell.Name)) { cell.Caption = ht[cell.Name].ToString(); } cellList.Add(gridDetailCell as Cell); } } foreach (SuperCell cell in supperCellList) { foreach (Cell gridDetailCell in cellList) { if (gridDetailCell.Super != null && gridDetailCell.Super.Name == cell.Cell.Name) { cell.Span += 1; cell.ChildList.Add(gridDetailCell); } } } } dslsb.Append( string.Format( @"<table id=""report"" width=""fill"" height=""fill"" bindfield=""sss"" column=""{0}"" onDownRefresh=""nextPage""", cellList.Count)); dslsb.Append( string.Format( @" fixedColumn=""{0}"" headerRow=""{1}"" columnWidth=""60dp"" rowHeight=""50dp"" style=""default"">", 1, headerRow)); //dslsb.Append("\n"); dslsb.Append("<property>"); // 下面代码是用来生成报表列的样式 #region 详细描述行列 dslsb.Append("<columns>"); var sort = new SortedList(); foreach (Cell cell in cellList) { sort.Add(cell.Location.X, cell); } int i = 0; foreach (Cell cell in sort.Values) { var tc = new TitleColumn(cell); tc.Col = i.ToString(); dslsb.Append(tc.ColumnsToXmlFormat()); foreach (SuperCell superCell in supperCellList) { if (superCell.ChildList.Contains(cell)) { if (superCell.Col > i || superCell.Col == 0) { superCell.Col = i; } } } i++; } dslsb.Append("</columns>"); if (_isMutiReport) { dslsb.Append("<merges>"); bool isSucced = false; //对每一个supper来说,col为该superCell的col值,而span为该superCell的子cell的个数 foreach (SuperCell superCell in supperCellList) { if (superCell.ChildList.Count != 0) { dslsb.Append(string.Format(@"<merge row=""0"" col=""{0}"" span=""{1}""/>", superCell.Col, superCell.Span)); isSucced = true; } } dslsb.Append("</merges>"); if (!isSucced) { throw new Exception("该报表数据分组层级太多,移动端无法展现!"); } } #endregion dslsb.Append("</property>"); dslsb.Append("</table>"); return(dslsb.ToString()); } } return(string.Empty); }