Esempio n. 1
0
        public DmlfConditionBase GetCondition(BedRow masterRow)
        {
            var res = new DmlfAndCondition();

            if (masterRow == null)
            {
                return(res);
            }
            for (int i = 0; i < SourceColumns.Count; i++)
            {
                int srcindex = masterRow.GetOrdinal(SourceColumns[i]);
                if (masterRow.Table.ResultFields != null)
                {
                    srcindex = masterRow.Table.ResultFields.GetColumnIndex(DmlfColumnRef.GetBaseColumn(SourceColumns[i]));
                }
                res.Conditions.Add(
                    new DmlfEqualCondition
                {
                    LeftExpr = new DmlfColumnRefExpression
                    {
                        Column = new DmlfColumnRef
                        {
                            ColumnName = ReferenceColumns[i]
                        }
                    },
                    RightExpr = new DmlfLiteralExpression {
                        Value = masterRow[srcindex]
                    }
                });
            }
            return(res);
        }
Esempio n. 2
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            contextMenuStrip1.Items.Clear();
            var mb = new MenuBuilder();

            if (AvailableSources != null && Handler != null)
            {
                foreach (var src in AvailableSources)
                {
                    int weight = 0;
                    var tbl    = Handler.GetStructure(src != null ? src.TableOrView : null);
                    foreach (var col in tbl.Columns)
                    {
                        var cref = new DmlfColumnRef {
                            Source = src, ColumnName = col.ColumnName
                        };
                        mb.AddItem(
                            src != null ? src.AliasOrName + "/" + col.ColumnName : "(SOURCE)/" + col.ColumnName,
                            new ColumnHandler {
                            Column = cref, Edit = tbxValue
                        }.Click,
                            weight
                            );
                        weight++;
                    }
                }
            }
            if (SupportsVars)
            {
                mb.AddItem("s_variable", InsertVariable, CoreIcons.variable);
            }
            mb.GetMenuItems(contextMenuStrip1.Items);
            contextMenuStrip1.Show(btnChange, new Point(0, btnChange.Height));
        }
Esempio n. 3
0
 public int GetColumnIndex(DmlfColumnRef col)
 {
     for (int i = 0; i < Count; i++)
     {
         if (this[i].Column == col)
         {
             return(i);
         }
     }
     return(-1);
 }
Esempio n. 4
0
 public NameWithSchema FindTableName(DmlfColumnRef col)
 {
     if (col.Source == null)
     {
         return(null);
     }
     if (col.Source.TableOrView != null)
     {
         return(col.Source.TableOrView);
     }
     return(FindTableAlias(col.Source.Alias));
 }
Esempio n. 5
0
 private DmlfColumnRef[] GetBaseWhereCols()
 {
     if (ResultFields != null)
     {
         return(ResultFields.GetPrimaryKey(DmlfSource.BaseTable).ToArray());
     }
     else
     {
         IPrimaryKey pk = Structure.FindConstraint <IPrimaryKey>();
         return(DmlfColumnRef.BuildFromArray(pk != null ? pk.Columns.GetNames() : Structure.Columns.GetNames(), null));
     }
 }
 private void FillAvailableColSources(DataGridViewComboBoxColumn col, DmlfRelation rel, ITableStructure ts)
 {
     foreach (var cs in ts.Columns)
     {
         var tpc = new DmlfColumnRef
         {
             Source     = rel != null ? rel.Reference : DmlfSource.BaseTable,
             ColumnName = cs.ColumnName,
         };
         m_colSources[tpc.ToString()] = tpc;
         col.Items.Add(tpc.ToString());
     }
 }
        void addTableItem_Click(object sender, EventArgs e)
        {
            var item = (ToolStripItem)sender;
            var rel  = (DmlfRelation)item.Tag;
            var ts   = GetTableStruct(rel);

            foreach (var col in ts.Columns)
            {
                var tpc = new DmlfColumnRef {
                    Source = rel != null ? rel.Reference : DmlfSource.BaseTable, ColumnName = col.ColumnName
                };
                dataGridViewColumns.Rows.Add(col.ColumnName, tpc.ToString(), null);
            }
        }
Esempio n. 8
0
 public static bool IsValid(this DmlfColumnRef col)
 {
     return(col != null && col.ColumnName != null);
 }
Esempio n. 9
0
 public override void LoadFromXml(XmlElement xml)
 {
     base.LoadFromXml(xml);
     Column = new DmlfColumnRef();
     Column.LoadProperties(xml);
 }
Esempio n. 10
0
        /// <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);
                }
            }
        }