public void AddColumnTag(string name, int index, object tag) { Add(new ColumnDisplayColumn { ValueTag = tag, ValueSourceIndex = index, ValueRef = DmlfResultField.BuildFromColumn(name) }); }
public void AddColumnTag(DmlfResultField field, int index, object tag) { switch (field.DisplayInfo.Style) { case ColumnDisplayInfo.UsageStyle.Value: Add(new ColumnDisplayColumn { ValueRef = field, ValueSourceIndex = index, ValueTag = tag, }); break; case ColumnDisplayInfo.UsageStyle.Lookup: int vindex = field.DisplayInfo.VisibleColumnIndex; this[vindex].LookupRef = field; this[vindex].LookupSourceIndex = index; this[vindex].LookupTag = tag; break; } }
public void AddColumn(DmlfResultField field, int index) { AddColumnTag(field, index, null); }
public void AddColumn(DmlfResultField field, int index, T tag) { AddColumnTag(field, index, tag); }
//internal static string RowToTableName(DataGridViewRow row) //{ // if (row == null) return "(SOURCE)"; // if (String.IsNullOrEmpty(row.Cells[4].Value.SafeToString())) return row.Cells[2].Value.ToString(); // return row.Cells[4].Value.ToString(); //} public void SavePerspective() { //m_per.Conditions.Server = tbxServer.Text; //m_per.Conditions.ServerChecked = chbServer.Checked; //m_per.Conditions.ServerRegex = chbServerRegex.Checked; //m_per.Conditions.Database = tbxDatabase.Text; //m_per.Conditions.DatabaseChecked = chbDatabase.Checked; //m_per.Conditions.DatabaseRegex = chbDatabaseRegex.Checked; //m_per.Conditions.Schema = tbxSchema.Text; //m_per.Conditions.SchemaChecked = chbSchema.Checked; //m_per.Conditions.SchemaRegex = chbSchemaRegex.Checked; //m_per.Conditions.Table = tbxTable.Text; //m_per.Conditions.TableChecked = chbTable.Checked; //m_per.Conditions.TableRegex = chbTableRegex.Checked; //m_per.Conditions.Columns = (from s in tbxColumns.Text.Split('\n') where !s.IsEmpty() select s.Trim()).ToArray(); //m_per.Conditions.ColumnsChecked = chbColumns.Checked; m_per.Conditions = m_filter.CloneUsingXml(); m_per.Select.From.Relations.Clear(); m_per.Select.Columns.Clear(); foreach (var rel in GetRelations()) { m_per.Select.From.Relations.Add(rel.Clone()); } // data columns foreach (DataGridViewRow row in dataGridViewColumns.Rows) { var datacol = GetColumnSource(row.Cells[1].Value); if (datacol == null) { continue; } var di = new ColumnDisplayInfo { Style = ColumnDisplayInfo.UsageStyle.Value }; var rdata = new DmlfResultField { Expr = new DmlfColumnRefExpression { Column = datacol }, Alias = row.Cells[0].Value.SafeToString(), DisplayInfo = di }; m_per.Select.Columns.Add(rdata); } // lookup columns int colindex = 0; foreach (DataGridViewRow row in dataGridViewColumns.Rows) { var datacol = GetColumnSource(row.Cells[1].Value); var lookup = GetColumnSource(row.Cells[2].Value); if (datacol == null) { continue; } if (lookup != null) { var di = new ColumnDisplayInfo { Style = ColumnDisplayInfo.UsageStyle.Lookup, VisibleColumnIndex = colindex }; var rloo = new DmlfResultField { Expr = new DmlfColumnRefExpression { Column = lookup }, DisplayInfo = di }; m_per.Select.Columns.Add(rloo); } colindex++; } m_per.Select.Columns.NormalizeBaseTables(); m_per.Select.CompleteUpdatingInfo(this); }
/// <summary> /// adds primary key information to query definition, or marks columns as read only, of no PK is available /// </summary> /// <param name="handler">used for obtain table structures with PKs</param> public void CompleteUpdatingInfo(IDmlfHandler handler) { var pks = new Dictionary <DmlfSource, IPrimaryKey>(); var required_pks = new Dictionary <DmlfSource, IPrimaryKey>(); // list of columns var usedcols = new HashSetEx <DmlfColumnRef>(); foreach (var col in Columns) { var di = col.DisplayInfo; if (di == null) { continue; } var tbl = col.Source; if (tbl == null) { tbl = handler.BaseTable; } if (tbl == null) { continue; } var cr = col.Expr as DmlfColumnRefExpression; if (cr == null) { di.IsReadOnly = true; continue; } if (!pks.ContainsKey(tbl)) { pks[tbl] = null; if (handler != null) { var ts = handler.GetStructure(tbl.TableOrView); if (ts != null) { pks[tbl] = ts.FindConstraint <IPrimaryKey>(); } } } var pk = pks[tbl]; if (pk == null) { // no primary key, is readonly di.IsReadOnly = true; continue; } var pkcols = new List <string>(pk.Columns.GetNames()); if (pkcols.Contains(cr.Column.ColumnName)) { di.IsPrimaryKey = true; } usedcols.Add(new DmlfColumnRef { Source = tbl, ColumnName = cr.Column.ColumnName }); if (di.Style == ColumnDisplayInfo.UsageStyle.Value) { required_pks[tbl] = pk; } if (di.Style == ColumnDisplayInfo.UsageStyle.Lookup) { di.IsReadOnly = true; } } // add missing primary key columns as hidden columns foreach (var pkt in required_pks) { foreach (string col in pkt.Value.Columns.GetNames()) { var key = new DmlfColumnRef { Source = pkt.Key, ColumnName = col }; if (usedcols.Contains(key)) { continue; } usedcols.Add(key); var nc = new DmlfResultField { DisplayInfo = new ColumnDisplayInfo { IsPrimaryKey = true, Style = ColumnDisplayInfo.UsageStyle.Hidden, }, Expr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { Source = pkt.Key, ColumnName = col, } } }; Columns.Add(nc); } } }