public GridCellGroup Execute() { XQueryNodeIterator res = command.Execute(); XPathGridBuilder builder = new XPathGridBuilder(); GridCellGroup rootCell = new GridCellGroup(); builder.ParseNodes(rootCell, res.ToList()); return rootCell; }
public string GetSourceXML(GridCellGroup rootCell) { StringBuilder sb = new StringBuilder(); for (int s = 0; s < rootCell.Table.Height; s++) { if (s > 0) sb.AppendLine(); GridCell cell = rootCell.Table[0, s]; if (cell is XPathGroupCell) { XPathGroupCell groupCell = (XPathGroupCell)cell; sb.Append(groupCell.Navigator.OuterXml); } else sb.Append(cell.Text); } return sb.ToString(); }
private void UpdateXmlGrid(GridCellGroup rootCell) { workTime.Stop(); queryTask = null; textEditor.IsReadOnly = false; textEditor.Cursor = null; textEditor.ForceCursor = false; textEditor.Focus(); String elapsed; if (workTime.Elapsed.Hours > 0) elapsed = String.Format("{0} hr, {1} min, {2} sec", workTime.Elapsed.Hours, workTime.Elapsed.Minutes, workTime.Elapsed.Seconds); else if (workTime.Elapsed.Minutes > 0) elapsed = String.Format("{0} min, {1} sec", workTime.Elapsed.Minutes, workTime.Elapsed.Seconds); else elapsed = String.Format("{0} sec ({1} ms)", workTime.Elapsed.Seconds, workTime.ElapsedMilliseconds); if (xmlGrid.ShowColumnHeader) status = String.Format("{0} row(s) read. {1} elapsed.", rootCell.Table.Height - 1, elapsed); else status = String.Format("{0} elapsed.", elapsed); OnPropertyChanged("StatusText"); xmlGrid.Cell = rootCell; ShowResultPane = true; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; if (dialog.ShowDialog() == DialogResult.OK) { XmlDataDocument xmldoc = new XmlDataDocument(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.ProhibitDtd = false; XmlUrlResolver resolver = new XmlUrlResolver(); resolver.Credentials = CredentialCache.DefaultCredentials; settings.XmlResolver = resolver; XmlReader render = XmlReader.Create(dialog.FileName, settings); try { try { xmldoc.Load(render); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Parse Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } finally { render.Close(); } GridBuilder builder = new GridBuilder(); if (xmlGrid.ShowColumnHeader) { GridCellGroup xmlgroup = new GridCellGroup(); xmlgroup.Flags = GroupFlags.Overlapped | GroupFlags.Expanded; builder.ParseNodes(xmlgroup, null, xmldoc.ChildNodes); GridCellGroup root = new GridCellGroup(); root.Table.SetBounds(1, 2); root.Table[0, 0] = new GridHeadLabel(); root.Table[0, 0].Text = dialog.FileName; root.Table[0, 1] = xmlgroup; xmlGrid.Cell = root; } else { GridCellGroup root = new GridCellGroup(); builder.ParseNodes(root, null, xmldoc.ChildNodes); xmlGrid.Cell = root; } } }
public void BatchMove(GridCellGroup rootCell, string name) { return; }
public void Collapse(GridCellGroup cell, bool recursive) { if (!cell.Overlaped) { cell.Flags = cell.Flags & ~GroupFlags.Expanded; if (recursive) Expand(cell, false, null); MeasureCells(); UpdateScrollRange(); Refresh(); } }
public void Expand(GridCellGroup cell, bool recursive) { if (!cell.Overlaped) { cell.BeforeExpand(); cell.Flags = cell.Flags | GroupFlags.Expanded; if (recursive) Expand(cell, true, null); MeasureCells(); UpdateScrollRange(); Refresh(); } }
private void DoAutoHeightCells(int row, int count, GridCellGroup cell, Graphics g) { if (cell.Expanded) { if (!cell.Overlaped) row++; for (int s = 0; s < cell.Table.Height; s++) { int rows = cell.Table.RowCount[s]; int height = RangeHeight(row, rows); for (int k = 0; k < cell.Table.Width; k++) if (cell.Table[k, s].IsGroup) DoAutoHeightCells(row, rows, (GridCellGroup)cell.Table[k, s], g); else { int cheight = cell.Table[k, s].GetTextHeight(this, g, Font, _drawInfo, cell.Table.ColumnsWidth[k]); if (height < cheight) { _rowHeight[row] += cheight - height; height = RangeHeight(row, rows); } } row += rows; } } }
private void DrawGroupCell(Graphics g, RectangleF clipRect, int X, int Y, GridCellGroup cell, int pixelWidth, int pixelHeight, bool isSelected) { DrawCell(g, X, Y, cell, pixelWidth, pixelHeight, isSelected); if (cell.Expanded) { int left = pixelWidth - cell.TableWidth - cell.TablePadding; int top = pixelHeight - cell.TableHeight; Pen pen = new Pen(Color.Silver); g.DrawLine(pen, X + left, Y + top, X + left, Y + pixelHeight); g.DrawLine(pen, X + left, Y + top, X + pixelWidth, Y + top); if (cell == _focusedCell) { Rectangle rc = Rectangle.FromLTRB(X + left - 1, Y + top - 1, X + pixelWidth, Y + pixelHeight); ControlPaint.DrawFocusRectangle(g, rc); Pen framePen = new Pen(Color.FromArgb(0xA6, 0xCA, 0xF0)); g.DrawLine(framePen, X + pixelWidth - 1, Y + top, X + pixelWidth - 1, Y + pixelHeight); g.DrawLine(framePen, X + pixelWidth - cell.TablePadding - 1, Y + pixelHeight - 1, X + pixelWidth, Y + pixelHeight - 1); } if (cell.TablePadding > 0) g.DrawLine(pen, X + pixelWidth - cell.TablePadding, Y + Top, X + pixelWidth - cell.TablePadding, Y + pixelHeight); DrawGridTable(g, clipRect, X + left, Y + top, cell.Table, cell.TableWidth, cell.TableHeight, isSelected || cell == _focusedCell); } }
public void BatchMove(GridCellGroup cell, string name) { ResultsetGridBuilder.RootCell rootCell = (ResultsetGridBuilder.RootCell)cell; CreateTableDialog dlg = new CreateTableDialog(); dlg.TableName = name; ResultsetGridBuilder builder = new ResultsetGridBuilder(); Resultset rs = builder.CreateResultset(rootCell); dlg.BatchMove.Source = rs; if (dlg.ShowDialog() == true) { AdoProviderWriter writer = new AdoProviderWriter(dlg.BatchMove); writer.Write(rs); } }
public GridCellTable(GridCellGroup parent) { Parent = parent; }
public void ExportTo(GridCellGroup rootCell, string fileName, ExportTarget target) { string ext = Path.GetExtension(fileName); AbstractWriter writer = null; switch (target) { case ExportTarget.Xml: writer = new XmlFileWriter(fileName); break; case ExportTarget.Csv: writer = new CsvWriter(fileName, CultureInfo.CurrentCulture.TextInfo.ListSeparator, true); break; case ExportTarget.TabDelimited: writer = new CsvWriter(fileName, "\t", true); break; case ExportTarget.FixedLength: writer = new FlvWriter(fileName, true); break; case ExportTarget.AdoNet: writer = new AdoNetWriter(fileName); break; } if (writer != null) { ResultsetGridBuilder builder = new ResultsetGridBuilder(); Resultset rs = builder.CreateResultset((ResultsetGridBuilder.RootCell)rootCell); writer.Write(rs); } }
public string GetSourceXML(GridCellGroup rootCell) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true }; StringBuilder sb = new StringBuilder(); ResultsetGridBuilder builder = new ResultsetGridBuilder(); Resultset rs = builder.CreateResultset((ResultsetGridBuilder.RootCell)rootCell); new XmlFileWriter(XmlWriter.Create(sb, settings)).Write(rs); return sb.ToString(); }
public bool CanExportDS(GridCellGroup rootCell) { return rootCell is ResultsetGridBuilder.RootCell && canExportDS; }
/// <summary> /// Creates a web form with an <c>XmlGridView</c> rendering an <see cref="XmlDocument"/>. /// </summary> /// <param name="xmlDoc">The document to render.</param> /// <param name="width">The width of the window.</param> /// <param name="height">The height of the window.</param> /// <returns></returns> public static Form CreateForm(XmlDocument xmlDoc, int width = 300, int height = 200) { var form = new Form { Height = height, Width = width, ClientSize = new Size(width, height) }; var grid = new XmlGridView { Dock = DockStyle.Fill }; form.Controls.Add(grid); var builder = new GridBuilder(); var xmlgroup = new GridCellGroup(); xmlgroup.Flags = GroupFlags.Overlapped | GroupFlags.Expanded; builder.ParseNodes(xmlgroup, null, xmlDoc.ChildNodes); var root = new GridCellGroup(); root.Table.SetBounds(1, 2); root.Table[0, 0] = new GridHeadLabel(); root.Table[0, 0].Text = "Sample Xml"; root.Table[0, 1] = xmlgroup; grid.Cell = root; return form; }
private void Expand(GridCellGroup cell, bool expand, GridCell stopCell) { for (int k = 0; k < cell.Table.Width; k++) for (int s = 0; s < cell.Table.Height; s++) if (cell.Table[k, s].IsGroup && stopCell != cell.Table[k, s]) { GridCellGroup child = (GridCellGroup)cell.Table[k, s]; if (!child.Overlaped) if (expand) { child.BeforeExpand(); child.Flags = child.Flags | GroupFlags.Expanded; } else child.Flags = child.Flags & ~GroupFlags.Expanded; Expand(child, expand, stopCell); } }
public void Clear() { _focusedCell = null; _rootCell = null; UpdateTextMetrics(); MeasureCells(); UpdateScrollRange(); Invalidate(); }
private GridCell FindCellByPoint(GridCellGroup cell, Point pt, Rectangle cellRect, ref Rectangle rcResult) { if (cell.Expanded) { Rectangle rc = Rectangle.FromLTRB( cellRect.Right - cell.TableWidth - cell.TablePadding, cellRect.Bottom - cell.TableHeight, cellRect.Right - cell.TablePadding, cellRect.Bottom); if (rc.Contains(pt)) { int rcTop = rc.Top; int s = -1; for (int i = 0; i < cell.Table.Height; i++) { if (rcTop < pt.Y && pt.Y <= rcTop + cell.Table.RowHeight[i]) { s = i; break; } rcTop += cell.Table.RowHeight[i]; } int rcLeft = rc.Left; int k = -1; if (s != -1) for (int i = 0; i < cell.Table.Width; i++) { if (rcLeft < pt.X && pt.X <= rcLeft + cell.Table.ColumnsWidth[i]) { k = i; break; } rcLeft += cell.Table.ColumnsWidth[i]; } if (k != -1 && s != -1) { rc = Rectangle.FromLTRB(rcLeft, rcTop, rcLeft + cell.Table.ColumnsWidth[k], rcTop + cell.Table.RowHeight[s]); if (cell.Table[k, s].IsGroup) return FindCellByPoint((GridCellGroup)cell.Table[k, s], pt, rc, ref rcResult); else { rcResult = rc; return cell.Table[k, s]; } } else return null; } } rcResult = cellRect; return cell; }
public void Collapse(GridCellGroup cell) { if (cell.Expanded) Collapse(cell, false); }
private Rectangle FindCellRect(GridCellGroup cell, Rectangle cellRect, GridCell dest) { if (cell.Expanded) { int rcLeft = cellRect.Right - cell.TableWidth - cell.TablePadding; for (int k = 0; k < cell.Table.Width; k++) { int rcRight = rcLeft + cell.Table.ColumnsWidth[k]; int rcTop = cellRect.Bottom - cell.TableHeight; for (int s = 0; s < cell.Table.Height; s++) { int rcBottom = rcTop + cell.Table.RowHeight[s]; Rectangle rc = Rectangle.FromLTRB(rcLeft, rcTop, rcRight, rcBottom); if (cell.Table[k, s] == dest) return rc; else if (cell.Table[k, s].IsGroup) { rc = FindCellRect((GridCellGroup)cell.Table[k, s], rc, dest); if (!rc.IsEmpty) return rc; } rcTop = rcBottom; } rcLeft = rcRight; } } return Rectangle.Empty; }
public void Expand(GridCellGroup cell) { if (! cell.Expanded) Expand(cell, false); }
private void FindColumnMaxWidth(GridCellGroup cell, Rectangle cellRect, Graphics g, int left, int right, ref int iMaxWidth) { if (cell.Expanded) { Rectangle rc = Rectangle.FromLTRB( cellRect.Right - cell.TableWidth - cell.TablePadding, cellRect.Bottom - cell.TableHeight, cellRect.Right - cell.TablePadding, cellRect.Bottom); int rcLeft = rc.Left; for (int k = 0; k < cell.Table.Width; k++) { if (rcLeft > right) break; int rcRight = rcLeft + cell.Table.ColumnsWidth[k]; if (rcLeft <= left && right <= rcRight) { int rcTop = rc.Top; for (int s = 0; s < cell.Table.Height; s++) { if (cell.Table[k, s].IsGroup) { Rectangle rc2 = Rectangle.FromLTRB(rcLeft, rcTop, rcRight, rcTop + cell.Table.RowHeight[s]); FindColumnMaxWidth((GridCellGroup)cell.Table[k, s], rc2, g, left, right, ref iMaxWidth); } else if (rcLeft == left && rcRight == right) iMaxWidth = Math.Max(iMaxWidth, 2 * _drawInfo.cxChar + cell.Table[k, s].GetTextWidth(this, g, Font, _drawInfo)); rcTop += cell.Table.RowHeight[s]; } } rcLeft = rcRight; } } }
private void SaveResults(GridCellGroup rootCell, XmlWriter writer) { for (int s = 0; s < rootCell.Table.Height; s++) { if (s > 0) writer.WriteWhitespace("\n"); GridCell cell = rootCell.Table[0, s]; if (cell is XPathGroupCell) { XPathGroupCell groupCell = (XPathGroupCell)cell; groupCell.Navigator.WriteSubtree(writer); } else writer.WriteString(cell.Text); } }
private void SetCellHeight(int row, int count, GridCellGroup cell) { if (cell.Expanded) { if (cell.Overlaped) cell.TableHeight = RangeHeight(row, count); else { cell.TableHeight = RangeHeight(row + 1, count - 1); row++; } for (int s = 0; s < cell.Table.Height; s++) { int rows = cell.Table.RowCount[s]; cell.Table.RowHeight[s] = RangeHeight(row, rows); for (int k = 0; k < cell.Table.Width; k++) if (cell.Table[k, s].IsGroup) SetCellHeight(row, rows, (GridCellGroup)cell.Table[k, s]); row += rows; } } }
public bool CanExportDS(GridCellGroup rootCell) { return false; }
private void SetCellWidth(int column, int count, GridCellGroup cell) { if (cell.Expanded) { int col = column; if (cell.TableView) { int cols = CountCellColumns(cell); cell.TableWidth = _rowNumWidth + RangeWidth(column + 1, cols - 1); cell.TablePadding = RangeWidth(column + cols, count - cols); } else { if (cell.Overlaped) cell.TableWidth = RangeWidth(column, count); else { cell.TableWidth = RangeWidth(column + 1, count - 1); col++; } cell.TablePadding = 0; } for (int k = 0; k < cell.Table.Width; k++) if (k == 0 && cell.TableView) { cell.Table.ColumnsWidth[0] = _rowNumWidth; col++; } else { int cols; if (k < cell.Table.Width - 1 || cell.TableView) { cols = 1; for (int s = 0; s < cell.Table.Height; s++) cols = Math.Max(cols, CountCellColumns(cell.Table[k, s])); } else cols = count - col + column; cell.Table.ColumnsWidth[k] = RangeWidth(col, cols); for (int s = 0; s < cell.Table.Height; s++) if (cell.Table[k, s].IsGroup) SetCellWidth(col, cols, (GridCellGroup)cell.Table[k, s]); col += cols; } } }
public void ExportTo(GridCellGroup rootCell, string fileName, ExportTarget target) { switch (target) { case ExportTarget.Xml: { FileStream stream = new FileStream(fileName, FileMode.Create); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Auto }; XmlWriter writer = XmlWriter.Create(stream, settings); SaveResults(rootCell, writer); writer.Close(); } break; } }
private void SetTableRows(GridCellGroup cell) { if (cell.Expanded) for (int s = 0; s < cell.Table.Height; s++) { cell.Table.RowCount[s] = 1; for (int k = 0; k < cell.Table.Width; k++) { cell.Table.RowCount[s] = Math.Max(cell.Table.RowCount[s], CountCellRows(cell.Table[k, s])); if (cell.Table[k, s].IsGroup) SetTableRows((GridCellGroup)cell.Table[k, s]); } } }
public void ParseNodes(GridCellGroup cell, XmlNamedNodeMap attrs, XmlNodeList nodes) { ItemList items = new ItemList(); if (attrs != null && attrs.Count > 0) { items.Add(ItemType.Values, attrs); } foreach (XmlNode child in nodes) { if (child is XmlSignificantWhitespace) { continue; } if (CanGroupNodes(items.LastNode(), child)) { if (items.Last().type != ItemType.Table) { items.Fork(); items.Last().type = ItemType.Table; } items.Add(ItemType.Table, child); } else if ((child.NodeType != XmlNodeType.Text && IsPairNode(child)) || child.NodeType == XmlNodeType.XmlDeclaration || child.NodeType == XmlNodeType.DocumentType || child.NodeType == XmlNodeType.ProcessingInstruction) { items.Add(ItemType.Values, child); } else { items.Add(ItemType.List, child); } } if (items.Length == 1 && items[0].type == ItemType.Values) { cell.Table.SetBounds(2, items[0].nodes.Count); for (int s = 0; s < items[0].nodes.Count; s++) { XmlNode node = items[0].nodes[s]; cell.Table[0, s] = new XmlLabelCell(node); cell.Table[1, s] = new XmlValueCell(node); } } else { int k = 0; cell.Table.SetBounds(1, items.CountCells()); for (int i = 0; i < items.Length; i++) { Item item = items[i]; switch (item.type) { case ItemType.Values: { GridCellGroup group = new GridCellGroup(); group.Flags = GroupFlags.Expanded | GroupFlags.Overlapped; group.Table.SetBounds(2, item.nodes.Count); for (int s = 0; s < item.nodes.Count; s++) { XmlNode node = item.nodes[s]; group.Table[0, s] = new XmlLabelCell(node); if (node.NodeType == XmlNodeType.XmlDeclaration || node.NodeType == XmlNodeType.DocumentType) { group.Table[1, s] = new XmlDeclarationCell(node); } else { group.Table[1, s] = new XmlValueCell(node); } } cell.Table[0, k++] = group; } break; case ItemType.List: for (int s = 0; s < item.nodes.Count; s++) { if (item.nodes[s].NodeType == XmlNodeType.Element) { cell.Table[0, k++] = new XmlGroupCell(item.nodes[s]); } else { cell.Table[0, k++] = new XmlLabelCell(item.nodes[s]); } } break; case ItemType.Table: { GridCellGroup group = new XmlGroupCell(item.nodes[0]); group.Flags = group.Flags | GroupFlags.TableView; TableColumns tableColumns = new TableColumns(); for (int s = 0; s < item.nodes.Count; s++) { tableColumns = GroupNode(item.nodes[s], tableColumns); } group.Table.SetBounds(tableColumns.Length + 1, item.nodes.Count + 1); group.Table[0, 0] = new GridRowLabel(); for (int s = 0; s < tableColumns.Length; s++) { group.Table[s + 1, 0] = new XmlColumnLabelCell(tableColumns[s].type, tableColumns[s].name, tableColumns[s].pos); } for (int s = 0; s < item.nodes.Count; s++) { XmlNode node = item.nodes[s]; group.Table[0, s + 1] = new XmlRowLabelCell(s + 1, node); for (int p = 0; p < tableColumns.Length; p++) { NodeList nodeList = GetNodeAtColumn(node, tableColumns[p]); if (nodeList.Count == 0) { group.Table[p + 1, s + 1] = new XmlValueCell(null); } else { XmlNode child = nodeList[0]; if (nodeList.Count == 1) { if (child.NodeType != XmlNodeType.Element || IsPairNode(child)) { group.Table[p + 1, s + 1] = new XmlValueCell(child); } else { group.Table[p + 1, s + 1] = new XmlGroupCell(child); } } else { XmlGroupCell childGroup = new XmlGroupCell(child); childGroup.Flags = GroupFlags.Overlapped | GroupFlags.Expanded; group.Table[p + 1, s + 1] = childGroup; ParseNodes(childGroup, null, nodeList); } } } } cell.Table[0, k++] = group; } break; } } } }