void LoadTables(Database db, SourceGrid.Grid grid, string title, string nameTitle, NodeBase tableViewNode) { var tc = new TimerCount("LoadTables"); grid.BorderStyle = BorderStyle.FixedSingle; grid.SelectionMode = SourceGrid.GridSelectionMode.Cell; grid.ClipboardMode = SourceGrid.ClipboardMode.All; grid.Rows.Clear(); grid.Columns.Clear(); grid.ColumnsCount = 11; grid.FixedRows = 1; grid.FixedColumns = 2; //int r = 0; SourceGrid.Cells.Views.Cell categoryView = new SourceGrid.Cells.Views.Cell(); categoryView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.Gainsboro, Color.WhiteSmoke, 0); categoryView.ForeColor = Color.Black; categoryView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; categoryView.Border = DevAge.Drawing.RectangleBorder.NoBorder; categoryView.Font = new Font(Font, FontStyle.Bold); //grid.Rows.Insert(r); //grid[r, 0] = new SourceGrid.Cells.Cell(title); //grid[r, 0].View = categoryView; //grid[r, 0].ColumnSpan = grid.ColumnsCount; //r++; int r = 0; grid.Rows.Insert(r); headerView = new SourceGrid.Cells.Views.Cell(); //headerView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.Gainsboro, Color.WhiteSmoke, 0); headerView.ForeColor = Color.FromKnownColor(KnownColor.Black); headerView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter; headerView.Border = DevAge.Drawing.RectangleBorder.NoBorder; headerView.Font = new Font(Font, FontStyle.Bold); addHeader(grid, Col.SchemaName, "Schema Name", 100); addHeader(grid, Col.TableName, "Table Name", 150); addHeader(grid, Col.DataClassName, "DataClass Name", 150); addHeader(grid, Col.BusinessClassName, "BusinessClass Name", 150); addHeader(grid, Col.EnumColumnName, "Enum Column Name", 150); addHeader(grid, Col.EnumColumnId, "Enum Column Id", 150); addHeader(grid, Col.EnumName, "Enum Name", 150); addHeader(grid, Col.EnumAttributes, "Enum Attributes", 150); addHeader(grid, Col.SequenceColumn, "Sequence Column", 150); addHeader(grid, Col.SequenceName, "Sequence Name", 150); addHeader(grid, Col.Attributes, "Attributes", 300); //addHeader(grid, 5, "Sub-directory", 150); for (int c = 0; c < grid.ColumnsCount; c++) { grid[r, c].View = categoryView; } Dictionary <string, GenTable> objects = new Dictionary <string, GenTable>(); tc.Next("GetSequences"); var sequences = db.Provider.GetSequences(); r++; foreach (NodeTable node in tableViewNode.Nodes) { progress.SetProgress(); //progress.SetProgress("Processing table" + node.Text + " ..."); var gtb = node.Item; if (gtb.TableName == "status") { ToString(); } objects.Add(gtb.FullName, null); tc.Next(gtb.TableName); try { //tc.Next("GetTableInfo"); //var tb = db.GetTableInfo(gtb.SchemaName, gtb.TableName); var tbCols = db.GetColumnsInfo(gtb.SchemaName, gtb.TableName); if (tbCols == null) // objeto inválido { continue; } Dictionary <string, GenColumn> dict = new Dictionary <string, GenColumn>(StringComparer.InvariantCultureIgnoreCase); foreach (var col in gtb.Columns) { if (!dict.ContainsKey(col.ColumnName)) { dict.Add(col.ColumnName, col); } } foreach (var col in tbCols) { GenColumn gcol; if (dict.TryGetValue(col.ColumnName, out gcol)) { dict.Remove(col.ColumnName); // remove as existentes // se existe, mas o banco é required, força required; if (!col.IsNullable) { gcol.IsRequired = true; } // o tipo sempre vem do banco gcol.DataType = col.DataTypeDotNet; } else { gcol = new GenColumn(); gcol.ColumnName = col.ColumnName; gcol.PropertyName = null; gcol.Description = null; gcol.IsRequired = !col.IsNullable; gcol.DataType = col.DataTypeDotNet; gtb.Columns.Add(gcol); } } // se sobrou no dict, é pq as colunas foram apagadas da table, ou renomedas foreach (var pair in dict) { gtb.Columns.RemoveAll(p => p.ColumnName.EqualsICIC(pair.Key)); } grid.Rows.Insert(r); //grid.Rows.SetHeight(r, 40); //grid.Rows.AutoSizeRow(r); SourceGrid.GridRow row = grid.Rows[r]; // tags row.AutoSizeMode = SourceGrid.AutoSizeMode.EnableAutoSize | SourceGrid.AutoSizeMode.EnableStretch; row.Tag = node; gtb.Tag = tbCols; node.Tag = row; grid[r, Col.SchemaName] = new SourceGrid.Cells.Cell(gtb.SchemaName); grid[r, Col.TableName] = new SourceGrid.Cells.Cell(gtb.TableName); SourceGrid.Cells.Editors.EditorBase ed; ed = SourceGrid.Cells.Editors.Factory.Create(typeof(string)); ed.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; grid[r, Col.DataClassName] = new SourceGrid.Cells.Cell(gtb.DataClassName, ed); ed = SourceGrid.Cells.Editors.Factory.Create(typeof(string)); ed.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; grid[r, Col.BusinessClassName] = new SourceGrid.Cells.Cell(gtb.BusinessClassName, ed); // EnumColumnName SourceGrid.Cells.Editors.ComboBox cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string)); var cols = (from c in tbCols where c.DataTypeDotNet.ToLower().Contains("string") orderby c.ColumnName select c.ColumnName).ToList(); if (!string.IsNullOrWhiteSpace(gtb.EnumColumnName)) { if (cols.FirstOrDefault(p => p.ToUpper() == gtb.EnumColumnName) == null) { gtb.EnumColumnName = gtb.EnumColumnId = gtb.EnumName = null; } } else { gtb.EnumColumnName = gtb.EnumColumnId = gtb.EnumName = null; } if (cols.Count > 0) { cols.Insert(0, ""); cbEditor.StandardValues = cols; cbEditor.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; } else { cbEditor.EditableMode = SourceGrid.EditableMode.None; } grid[r, Col.EnumColumnName] = new SourceGrid.Cells.Cell(gtb.EnumColumnName, cbEditor); // EnumColumnId cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string)); cols = (from c in tbCols where numericTypes.ContainsKey(c.DataTypeDotNet.Replace("?", "")) orderby c.ColumnName select c.ColumnName).ToList(); if (cols.Count > 0) { cols.Insert(0, ""); cbEditor.StandardValues = cols; cbEditor.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; } else { cbEditor.EditableMode = SourceGrid.EditableMode.None; } grid[r, Col.EnumColumnId] = new SourceGrid.Cells.Cell(gtb.EnumColumnId, cbEditor); // EnumName ed = SourceGrid.Cells.Editors.Factory.Create(typeof(string)); ed.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; grid[r, Col.EnumName] = new SourceGrid.Cells.Cell(gtb.EnumName, ed); // EnumAttributes ed = SourceGrid.Cells.Editors.Factory.Create(typeof(string)); ed.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; grid[r, Col.EnumAttributes] = new SourceGrid.Cells.Cell(gtb.EnumAttributes, ed); // SequenceColumn cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string)); cols = (from c in tbCols where numericTypes.ContainsKey(c.DataTypeDotNet.Replace("?", "")) orderby c.ColumnName select c.ColumnName).ToList(); if (cols.Count > 0) { cols.Insert(0, ""); cbEditor.StandardValues = cols; cbEditor.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; } else { cbEditor.EditableMode = SourceGrid.EditableMode.None; } grid[r, Col.SequenceColumn] = new SourceGrid.Cells.Cell(gtb.SequenceColumn, cbEditor); // SequenceName cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string)); if (sequences.Count > 0) { cols.Insert(0, ""); cbEditor.StandardValues = (from c in sequences select c.FullName).ToList(); cbEditor.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; } else { cbEditor.EditableMode = SourceGrid.EditableMode.None; } grid[r, Col.SequenceName] = new SourceGrid.Cells.Cell(gtb.SequenceName, cbEditor); var ed2 = SourceGrid.Cells.Editors.Factory.Create(typeof(string)); var txt = (SourceGrid.Cells.Editors.TextBox)ed2; txt.Control.Multiline = true; txt.Control.AcceptsReturn = true; //txt.Control.ScrollBars = ScrollBars.Both; //txt.Control.ImeMode = ImeMode.Disable; ed2.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; //if (gtb.Attributes != null) //{ // gtb.Attributes = gtb.Attributes.Replace("\r\n", "\n"); // gtb.Attributes = gtb.Attributes.Replace("\n", "\r\n\r\n"); //} grid[r, Col.Attributes] = new SourceGrid.Cells.Cell(gtb.Attributes, ed2); //ed = SourceGrid.Cells.Editors.Factory.Create(typeof(string)); //ed.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey; //grid[r, 5] = new SourceGrid.Cells.Cell(gtb.SubDirectory, ed); r++; //string time = tc.ToString(); } catch (Exception ex) { //Program.ShowError(ex); } } // remove objetos não mais existentes na base de dados var objs = tableViewNode is NodeTables ? file.Parameters.Tables : file.Parameters.Views; foreach (var obj in objs.ToList()) { if (!objects.ContainsKey(obj.FullName)) { objs.Remove(obj); } } grid.Selection.FocusRowEntered += Selection_FocusRowEntered; grid.Selection.FocusRowLeaving += Selection_FocusRowLeaving; grid.AutoSizeCells(); string time = tc.ToString(); }