public static string PageBreakTables(CMSDataContext db, string sql, DynamicParameters p) { using (var cn = db.ReadonlyConnection()) { cn.Open(); var sb = new StringBuilder(); int pagebreakcol = 0; var pg = 1; while (true) { var s = sql.Replace("WHERE 1=1", $"WHERE pagebreak={pg}"); var cmd = (SqlCommand)cn.CreateCommand(); cmd.CommandText = s; foreach (var parm in p.ParameterNames) { var value = p.Get <dynamic>(parm); cmd.Parameters.AddWithValue(parm, value); } cmd.CommandTimeout = 1200; using (var rd = cmd.ExecuteReader()) { if (!rd.HasRows) { return(sb.ToString()); } if (pg == 1) { var colnames = Enumerable.Range(0, rd.FieldCount).Select(rd.GetName).ToList(); pagebreakcol = colnames.FindIndex(vv => vv == "pagebreak"); } var t = HtmlTable(rd, $"pagebreak={pagebreakcol}"); t.RenderControl(new HtmlTextWriter(new StringWriter(sb))); sb.AppendLine("<div class='page-break'></div>"); } pg++; } } }
private DbConnection GetReadonlyConnection() { return(db.ReadonlyConnection()); }