/// <summary> /// コンストラクタ、親ノード、挿入先テーブルと列の並びを指定して初期化する /// </summary> /// <param name="parent">親ノード</param> /// <param name="table">挿入先テーブル</param> /// <param name="columnsExpression">列と設定値を指定する t => new[] { t.A == a, t.B == b } の様な式</param> public InsertInto(IQueryNode parent, TableDef <TColumns> table, Expression <Func <TColumns, bool[]> > columnsExpression) { this.Parent = parent; // new [] { bool, bool... } の様な形式以外はエラーとする var body = columnsExpression.Body; if (body.NodeType != ExpressionType.NewArrayInit) { throw new ApplicationException(); } // 登録 var owner = this.Owner; owner.RegisterTable(table); // bool[] の各要素初期化式を取得する var newexpr = body as NewArrayExpression; var expressions = newexpr.Expressions; var map = new Dictionary <Expression, object> { { columnsExpression.Parameters[0], table.Columns } }; var availableColumns = owner.AllColumns; var tableColumnMap = table.ColumnMap; var columnsOrder = new ColumnMap(); var values = new ElementCode[expressions.Count]; for (int i = 0; i < values.Length; i++) { // t.A == a の様に Equal を代入として扱いたいのでそれ以外はエラーとする var expression = expressions[i]; if (expression.NodeType != ExpressionType.Equal) { throw new ApplicationException(); } var binary = expression as BinaryExpression; // 左辺は代入先の列でなければならない var left = new ElementCode(ParameterReplacer.Replace(binary.Left, map), tableColumnMap); var column = left.FindColumns().FirstOrDefault(); if (column == null) { throw new ApplicationException(); } // 右辺は式 values[i] = new ElementCode(ParameterReplacer.Replace(binary.Right, map), availableColumns); // 列の生成元を右辺の式にして列を登録 columnsOrder.Add(column); } this.Table = table; this.ColumnMap = columnsOrder; this.ValueNode = new ValueSetter(this, columnsOrder, values); }
protected void InitializeColumnMap(DataReaderWrapperParameters parameters) { var columns = new List <string>(); if (parameters?.Columns != null) { columns.AddRange(parameters.Columns); } if (columns.Count <= 0) { for (int i = 0; i < _Reader.FieldCount; i++) { columns.Add(_Reader.GetName(i)); } } if ((parameters.SkipColumns?.Length ?? 0) > 0) { var dictSkip = new StringNoCaseDictionary <int>(); foreach (string skipColumn in parameters.SkipColumns) { if (!dictSkip.ContainsKey(skipColumn)) { dictSkip.Add(skipColumn, 1); } else { dictSkip[skipColumn]++; } } for (int i = columns.Count - 1; i >= 0; i--) { if (dictSkip.ContainsKey(columns[i])) { columns.RemoveAt(i); } } } for (int i = 0; i < columns.Count; i++) { string columnName = columns[i]; int ordinal = _Reader.GetOrdinal(columnName); if (ordinal < 0) { throw new Exception($"Cannot find column '{columnName}'"); } ColumnMap.Add(i, ordinal); ColumnMapReverse.Add(ordinal, i); } }
public void Add(IColumn column) { int order; if (_order.TryGetValue(column.Path, out order)) { _columns[order] = column; } else { _columns.Add(_order.Count, column); _order.Add(column.Path, _order.Count); } }
/// <summary> /// エイリアス用にクローンを作成する /// </summary> /// <returns>クローン</returns> public TableDef <TColumns> AliasedClone() { var c = this.MemberwiseClone() as TableDef <TColumns>; ColumnMap map; TColumns columns; c.ColumnMap = map = new ColumnMap(); c.Columns = columns = TypewiseCache <TColumns> .Creator(); foreach (var column in this.ColumnMap) { map.Add(column.Clone(columns, c)); } return(c); }
private void root_MouseUp(object sender, MouseButtonEventArgs e) { var p = e.GetPosition(root); // 已选中项,红框显示,无法形成链接 VisualTreeHelper.HitTest(root, null, f => { var element = f.VisualHit; if (element is Border) { object tag = ((Border)element).Tag; if (tag != null) { string columnName = tag.ToString(); var target = targetItemList.FirstOrDefault(item => item.ColumnName == columnName); if (target != null && sourceItem != null) { targetItem = target; if (!ColumnMap.ContainsKey(targetItem.ColumnName)) { drawLine(sourceItem.ColumnName, targetItem.ColumnName); ColumnMap.Add(targetItem.ColumnName, sourceItem.ColumnName); targetItem.ColumnValue = sourceItem.ColumnName; TableDAL.Comment(TableName, targetItem.ColumnName, sourceItem.ColumnName); } } } } return(HitTestResultBehavior.Continue); }, new PointHitTestParameters(p)); // 未选中项,记录选中项,画线 root.ReleaseMouseCapture(); root.Children.Remove(tempLine); tempLine = null; sourceItem = null; }
private Dictionary <string, int> MapAllColumnsToProperties(List <string> headers) { try { int column = 0; foreach (PropertyInfo property in PropertyList) { ColumnAttribute att = (ColumnAttribute)property.GetCustomAttribute <ColumnAttribute>(); if (headers.Any(h => h.Contains(att.Name))) { column = headers.FindIndex(h => h.Contains(att.Name)); ColumnMap.Add(att.Name, column); } } return(ColumnMap); } catch (Exception) { Console.WriteLine("Could not map the spreadsheet columns to the properties defined in the data class."); return(null); } }