public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values != null && values.Count() == 3)
            {
                if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue || values[2] == DependencyProperty.UnsetValue)
                {
                    return(Binding.DoNothing);
                }


                string      columnName = values[0].ConvertToString();
                DataRowView dataRow    = values[1] as DataRowView;
                DataTable   dataTable  = values[2] as DataTable;
                if (columnName != null && dataRow != null && columnName != Constants.DatabaseTypeColumnName)
                {
                    var isColumnPresent = DynamicColumn.GetIsColumnPresentColumnName(columnName);
                    if (!dataRow[isColumnPresent].ConvertToBool())
                    {
                        return(Brushes.Orange);
                    }

                    var isEqualColumnName = DynamicColumn.GetIsDataEqualColumnName(columnName);
                    if (!dataRow[isEqualColumnName].ConvertToBool())
                    {
                        return(Brushes.Red);
                    }
                }
            }
            return(Binding.DoNothing);
        }
예제 #2
0
 public int CreateDynamicColumn(DataTable table)
 {
     if (DynamicColumn == null)
     {
         return(0);
     }
     ColumnsCount -= DynamicColumn.GroupColumnCount;
     if ((table == null) || (table.Rows.Count <= 0))
     {
         return(0);
     }
     for (var i = 0; i < table.Rows.Count; i++)
     {
         DynamicColumn.CheckEachColumn(this, Holder, 0, table, i);
     }
     IsDynamicCloumnsCreated = true;
     RangeHelper.GetRange(TplRange.Worksheet, DynamicColumn.StartColIndex + DynamicColumn.GroupColumnCount,
                          TplRange.Row,
                          ((TplColumCount - DynamicColumn.StartCellIndex) - DynamicColumn.GroupColumnCount) - 1, TplRowCount)
     .Copy(
         RangeHelper.GetRange(TplRange.Worksheet, DynamicColumn.StartColIndex, TplRange.Row,
                              ((TplColumCount - DynamicColumn.StartCellIndex) - DynamicColumn.GroupColumnCount) - 1,
                              TplRowCount), true, true);
     TplColumCount -= DynamicColumn.GroupColumnCount;
     foreach (var line in TplLineList)
     {
         line.CellList.RemoveRange(DynamicColumn.StartCellIndex, DynamicColumn.GroupColumnCount);
         line.TplCellCount -= DynamicColumn.GroupColumnCount;
         line.TplRange      = RangeHelper.GetRange(TplRange.Worksheet, 3, line.TplRange.Row, TplColumCount, 1);
     }
     return(1);
 }
예제 #3
0
        private DataTable ConvertToDataTable(SortedDictionary <string, CellComparison> allColumnDictionary)
        {
            DataTable dataTable = new DataTable();

            var column = new DataColumn(Constants.DatabaseTypeColumnName);

            dataTable.Columns.Add(column);

            // Add Columns
            foreach (var cellComparison in allColumnDictionary)
            {
                column = new DataColumn(cellComparison.Value.ColumnName);
                dataTable.Columns.Add(column);

                column          = new DataColumn(DynamicColumn.GetIsColumnPresentColumnName(cellComparison.Value.ColumnName));
                column.DataType = typeof(bool);
                dataTable.Columns.Add(column);

                column          = new DataColumn(DynamicColumn.GetIsDataEqualColumnName(cellComparison.Value.ColumnName));
                column.DataType = typeof(bool);
                dataTable.Columns.Add(column);

                column          = new DataColumn(DynamicColumn.GetIsVisibleColumnName(cellComparison.Value.ColumnName));
                column.DataType = typeof(bool);
                dataTable.Columns.Add(column);
            }

            // Add Rows
            DataRow firstDbDataRow  = dataTable.NewRow();
            DataRow secondDbDataRow = dataTable.NewRow();

            foreach (var columnComparisonDetail in allColumnDictionary)
            {
                var columnName = columnComparisonDetail.Value.ColumnName;
                // DATABASE
                firstDbDataRow[Constants.DatabaseTypeColumnName]  = ConfigurationManager.AppSettings[Constants.AppSettingKeyDatabaseOneType];
                secondDbDataRow[Constants.DatabaseTypeColumnName] = ConfigurationManager.AppSettings[Constants.AppSettingKeyDatabaseTwoType];;

                // Value
                firstDbDataRow[columnName]  = columnComparisonDetail.Value.FirstDatabaseColumnValue;
                secondDbDataRow[columnName] = columnComparisonDetail.Value.SecondDatabaseColumnValue;

                // IsColumnPresent
                firstDbDataRow[DynamicColumn.GetIsColumnPresentColumnName(columnName)]  = columnComparisonDetail.Value.IsColumnAvailableInFirstDatabase;
                secondDbDataRow[DynamicColumn.GetIsColumnPresentColumnName(columnName)] = columnComparisonDetail.Value.IsColumnAvailableInSecondDatabase;

                // IsDataEqual
                firstDbDataRow[DynamicColumn.GetIsDataEqualColumnName(columnName)]  = columnComparisonDetail.Value.IsDataEqual;
                secondDbDataRow[DynamicColumn.GetIsDataEqualColumnName(columnName)] = columnComparisonDetail.Value.IsDataEqual;

                // IsVisible
                firstDbDataRow[DynamicColumn.GetIsVisibleColumnName(columnName)]  = true;
                secondDbDataRow[DynamicColumn.GetIsVisibleColumnName(columnName)] = true;
            }

            dataTable.Rows.Add(firstDbDataRow);
            dataTable.Rows.Add(secondDbDataRow);

            return(dataTable);
        }
        private void EditColumn(DynamicColumn column)
        {
            var viewModel = _editViewModelFactory();

            viewModel.Initialise(column);

            EditViewModel = viewModel;
        }
예제 #5
0
        /// <summary>
        /// 校验头部
        /// </summary>
        public override void ValidationHead()
        {
            //基类实体校验
            base.ValidationHead();

            //动态列验证
            DynamicColumn <TEntity> .ValidationHead(ExcelGlobalDTO);

            //头部校验后处理,用于特殊处理
            ValidationHeaderAfter();
        }
예제 #6
0
        /// <summary>
        /// 验证内容
        /// </summary>
        public override void ValidationValue()
        {
            //调用基类实体验证
            base.ValidationValue();

            //动态列验证
            DynamicColumn <TEntity> .ValidationValue(ExcelGlobalDTO);

            //验证值后
            this.ValidationValueAfter();
        }
예제 #7
0
        public TestDefinition DynamicColumn_ControlArray()
        {
            DynCol1 = new DynamicColumn(typeof(Gtk.Button), new object[] { "button" });

            TestDefinition info = new TestDefinition();

            info.testName   = "DynamicColumn_ControlArray";
            info.testDesc   = "Test that sets a DynamicColumn with a control type.";
            info.testWidget = DynCol1;

            return(info);
        }
예제 #8
0
        public TestDefinition DynamicColumn_UpdatedArray()
        {
            DynCol3 = new DynamicColumn(typeof(Gtk.Button), new object[] { "button" });

            TestDefinition info = new TestDefinition();

            info.testName     = "DynamicColumn_UpdatedArray";
            info.testDesc     = "Test that sets a DynamicColumn and on the button click, updates the set of control.";
            info.testWidget   = DynCol3;
            info.buttonClick1 = OnClickUpdateArray;

            return(info);
        }
예제 #9
0
        public TestDefinition DynamicColumn_ChangedMax()
        {
            DynCol2 = new DynamicColumn(typeof(Gtk.Button), new object[] { "button" });
            DynCol2.UpdateMaxCount(12);

            TestDefinition info = new TestDefinition();

            info.testName   = "DynamicColumn_ChangedMax";
            info.testDesc   = "Test that sets a DynamicColumn with a larger number of controls.";
            info.testWidget = DynCol2;

            return(info);
        }
예제 #10
0
        public int FillBlock(DataTable table)
        {
            var rowIndex = StartParseRowIndex;

            for (var i = 0; i < table.Rows.Count; i++)
            {
                CountedMap.Clear();
                if ((DynamicColumn != null) && !IsDynamicCloumnsCreated)
                {
                    DynamicColumn.CheckColumn(this, Holder, rowIndex, table, i);
                }
                foreach (var groupKey in GroupKeyList)
                {
                    if (groupKey.ReusedKey == null)
                    {
                        groupKey.ReusedKey = SearchKey.FindReusedKey(groupKey.ValueColName);
                    }
                    var copyKey = groupKey.Copy();
                    if (copyKey.SearchKey != null)
                    {
                        copyKey.SearchKey.FillKey(table, i);
                    }
                    Holder.AddValue(CountedMap, copyKey, table, i);
                }
                for (var k = 0; k < TplLineList.Count; k++)
                {
                    var updateLine = TplLineList[k];
                    var isNewLine  = updateLine.FillLine(Holder, rowIndex, table, i);
                    if (isNewLine)
                    {
                        FillLastLine(k, LastUsedLine, rowIndex - 1, table, LastUsedLineValueIndex); //?填充上一行值
                        LastUsedLine           = updateLine;
                        LastUsedLineValueIndex = i;
                        if ((i + 1) >= table.Rows.Count)
                        {
                            FillLastLine(k, updateLine, rowIndex, table, LastUsedLineValueIndex);
                        }

                        rowIndex  += 1;
                        RowsCount += 1;
                    }
                }
            }
            MergeHGroupCells();
            if (!table.ExtendedProperties.ContainsKey("TableType") ||
                (table.ExtendedProperties["TableType"].ToString() != "CustumEmpty"))
            {
                MergeVGroupCells();
            }
            return(RowsCount);
        }
예제 #11
0
        private void DgResult_OnAutoGeneratedColumns(object sender, EventArgs e)
        {
            if (RbOnlyMismatchedData.IsChecked != null && RbOnlyMismatchedData.IsChecked.Value)
            {
                var dataTable = DgResult.DataContext as DataTable;
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    List <DataGridColumn> toRemoveList = new List <DataGridColumn>();
                    foreach (var dataGridColumn in DgResult.Columns)
                    {
                        if (dataGridColumn.Header.ToString() == Constants.DatabaseTypeColumnName)
                        {
                            continue;
                        }

                        var columnName = DynamicColumn.GetIsDataEqualColumnName(dataGridColumn.Header.ToString());
                        if (dataTable.Rows[0][columnName].ConvertToBool())
                        {
                            toRemoveList.Add(dataGridColumn);
                        }
                    }

                    foreach (var dataGridColumn in toRemoveList)
                    {
                        DgResult.Columns.Remove(dataGridColumn);
                    }
                }
            }

            if (RbAllData.IsChecked != null && RbAllData.IsChecked.Value)
            {
                foreach (var dataGridColumn in DgResult.Columns)
                {
                    dataGridColumn.Visibility = Visibility.Visible;
                }
            }
        }
예제 #12
0
        /// <summary>
        /// 校验头部
        /// </summary>
        public virtual void ValidationHead()
        {
            //遍历Sheet进行头部校验
            foreach (var sheetModel in ExcelGlobalDTO.Sheets)
            {
                ISheet sheet = ExcelGlobalDTO.Workbook.GetSheetAt(sheetModel.SheetIndex);

                //获取头部行
                IRow row = sheet.GetRow(sheetModel.StartRowIndex.Value);
                if (row == null)
                {
                    throw new Exception(ExcelGlobalDTO.ExcelValidationMessage.Clgyl_Common_Import_TempletError);
                }

                //获取表头信息
                List <string> cellValues = row.Cells.Select(s => ExcelHelper.GetCellValue(s)).ToList();

                List <ExcelHeadDTO> headDtoList = ExcelAttributeHelper <TEntity> .GetHeads();

                //头部校验
                foreach (ExcelHeadDTO dto in headDtoList)
                {
                    //校验必填的,判断表头是否在excel中存在
                    if (dto.IsValidationHead == true && cellValues.Contains(dto.HeadName) == false)
                    {
                        throw new Exception(ExcelGlobalDTO.ExcelValidationMessage.Clgyl_Common_Import_TempletError);
                    }
                }
            }

            //动态列验证
            DynamicColumn <TEntity> .ValidationHead(ExcelGlobalDTO, ValidationModelEnum.DynamicColumn);

            //头部校验后处理,用于特殊处理
            ValidationHeaderAfter();
        }
        public void Visit(SelectStatement statement)
        {
            var executedTables = _scope.FetchAllExecutedTablesSameLevel();

            if (executedTables.Length == 0) //no executed tables. nothing to do
            {
                return;
            }

            var dynamicColumns = new List <DynamicColumn>();
            var descriptors    = new List <IResult>();

            if (statement.All) //get all columns
            {
                var selectedIndex = 0;
                foreach (var executeTable in executedTables)
                {
                    foreach (var p in executeTable.Descriptor.Properties)
                    {
                        int propIndex = executeTable.Descriptor.GetDataRowIndex(p.Name);
                        descriptors.Add(new SelectColumn()
                        {
                            Table = executeTable, PropDescriptor = p, PropIndex = propIndex
                        });

                        if (selectedIndex >= statement.Args.Length)
                        {
                            var selectArg = new SelectArgExpression(statement.Bounds);
                            selectArg.Children.Add(new SingleVariableExpression(statement.Bounds)
                            {
                                Id = p.Name
                            });
                            statement.Children.Add(selectArg);
                        }
                        selectedIndex++;
                    }
                }
            }
            else
            {
                for (int selectIndex = 0; selectIndex < statement.Args.Length; selectIndex++)
                {
                    Array.ForEach(executedTables, (x) => x.SelectIndex = selectIndex);
                    var arg = new QueryPhaseArgs();
                    VisitChild(statement.Args[selectIndex], arg);

                    if (arg.BoolQueryArg.Table == null) //can't find selected PropertyDescriptor. Must be a statement
                    {
                        var prop = new PropertyDescriptor()
                        {
                            Name = arg.BoolQueryArg.Variable ?? "(No column name)"
                        };
                        var dynamicColumn = new DynamicColumn {
                            SelectArgExpression = statement.Args[selectIndex], PropDescriptor = prop
                        };
                        descriptors.Add(dynamicColumn);
                        dynamicColumns.Add(dynamicColumn);
                    }
                    else
                    {
                        int propIndex = arg.BoolQueryArg.Table.Descriptor.GetDataRowIndex(arg.BoolQueryArg.Property.Name);
                        arg.BoolQueryArg.Property.Name = arg.BoolQueryArg.Variable;
                        descriptors.Add(new SelectColumn()
                        {
                            Table = arg.BoolQueryArg.Table, PropDescriptor = arg.BoolQueryArg.Property, PropIndex = propIndex
                        });
                    }
                }
            }

            //need to go through every row here of select dynamic statement then add it Properties
            if (executedTables.Length > 0)
            {
                var rowCount = executedTables.First().Rows.Length;
                for (int row = 0; row < rowCount; row++)
                {
                    Array.ForEach(executedTables, (x) => x.RowIndex = row);
                    foreach (var d in dynamicColumns) //run each column. Value goes in data at selected index
                    {
                        var arg = new QueryPhaseArgs();
                        VisitChild(d.SelectArgExpression, arg);
                        d.Values.Add(arg.BoolQueryArg.PropertyValue);
                    }
                }
            }

            var rows = new List <Row>();

            if (executedTables.Length > 0)
            {
                var rowCount = executedTables.First().Rows.Length;
                for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) //select data for only those columns selected
                {
                    var values = new List <PropertyValue>();
                    for (int selectIndex = 0; selectIndex < statement.Args.Length; selectIndex++)
                    {
                        var selectedColumn = descriptors[selectIndex];
                        values.Add(selectedColumn.Fetch(rowIndex));
                    }

                    rows.Add(new Row()
                    {
                        Values = values.ToArray()
                    });
                }
            }

            var             finalDescriptors = descriptors.Select(x => x.Descriptor()).ToArray();
            TableDescriptor tableDescriptor;

            //if nested
            if (statement.IsNestedQuery)
            {
                var dups = finalDescriptors.GroupBy(x => x.Name).Where(g => g.Count() > 1).Select(x => x.Key).ToList();
                if (dups.Count > 1) //error
                {
                }

                tableDescriptor = finalDescriptors;
            }
            else
            {
                FinalSelectTableDescriptor ftableDescriptor = descriptors.Select(x => x.Descriptor()).ToArray();
                tableDescriptor = ftableDescriptor;
            }

            var selectTable = new ExecutedTable(tableDescriptor)
            {
                Rows = rows.ToArray()
            };

            _visitStack.Peek().QueryTable = selectTable;

            if (!statement.IsNestedQuery)
            {
                _selectResult.Add(ToSelectTable(selectTable));
            }
        }
예제 #14
0
 public void Initialise(DynamicColumn column)
 {
     Header    = column.HeaderName;
     IsVisible = column.IsVisible;
 }
예제 #15
0
        public static List<DynamicColumn> GetColumns(
			this DbDataReader reader)
        {
            var list = new List<DynamicColumn>();
            if(null == reader) { return list; }

            var schema = reader.GetSchemaTable();

            foreach(DataRow row in schema.Rows) {
                DynamicColumn column = new DynamicColumn();
                foreach(DataColumn col in schema.Columns) {
                    //Console.WriteLine(string.Format(
                    //	"{0}={1}", col.ColumnName, row[col]
                    //));
                    switch(col.ColumnName) {
                        case "AllowDBNull":
                            column.AllowDBNull = row[col].ToBoolean();
                            break;
                        case "AutoIncrement":
                        case "IsAutoIncrement":
                            column.AutoIncrement = row[col].ToBoolean();
                            break;
                        case "AutoIncrementSeed":
                            column.AutoIncrementSeed = row[col].ToLong();
                            break;
                        case "AutoIncrementStep":
                            column.AutoIncrementStep = row[col].ToLong();
                            break;
                        case "Caption":
                            column.Caption = row[col].ToString();
                            break;
                        case "ColumnName":
                            column.ColumnName = row[col].ToString();
                            break;
                        case "BaseColumnName":
                            column.BaseColumnName = row[col].ToString();
                            break;
                        case "IsAliased":
                            column.IsAliased = row[col].ToBoolean();
                            break;
                        case "DataType":
                            column.DataType = Reflector.GetPrimitiveType(
                                row[col].ToString()
                            );
                            break;
                        case "DefaultValue":
                            column.DefaultValue = row[col];
                            break;
                        case "Expression":
                            column.Expression = row[col].ToString();
                            break;
                        case "MaxLength":
                            column.MaxLength = row[col].ToInteger();
                            break;
                        case "Namespace":
                            column.Namespace = row[col].ToString();
                            break;
                        case "Prefix":
                            column.Prefix = row[col].ToString();
                            break;
                        case "ReadOnly":
                            column.ReadOnly = row[col].ToBoolean();
                            break;
                        case "Unique":
                            column.Unique = row[col].ToBoolean();
                            break;
                        case "BaseTableName":
                            column.BaseTableName = row[col].ToString();
                            break;
                        case "IsKey":
                            column.IsKey = row[col].ToBoolean();
                            break;
                        case "IsRowID":
                        case "IsRowVersion":
                            column.IsRowID = row[col].ToBoolean();
                            break;
                        case "ProviderType":
                            column.ProviderType = row[col].ToInteger();
                            break;
                        case "IsHidden":
                            column.IsHidden = row[col].ToBoolean();
                            break;
                        case "IsLong":
                            column.IsLong = row[col].ToBoolean();
                            break;
                        default:
                            break;
                    }
                }
                list.Add(column);
            }
            return list;
        }
예제 #16
0
        /// <summary>
        /// 验证内容
        /// </summary>
        public virtual void ValidationValue()
        {
            //遍历Sheet实体集合
            foreach (var sheet in ExcelGlobalDTO.Sheets)
            {
                //获取Sheet头部实体集合
                var headDtoList = sheet.SheetHeadList;

                //为空判断
                if (sheet.SheetEntityList == null)
                {
                    continue;
                }

                var pairs           = new ConcurrentDictionary <int, List <ValidationResult> >();
                var parallelOptions = MultiThreadingHelper.GetParallelOptions();
                Parallel.ForEach(sheet.SheetEntityList, parallelOptions, entity =>
                {
                    pairs.TryAdd(entity.RowNumber, ValidationHelper.Exec <TEntity>(entity));
                });

                foreach (var item in sheet.SheetEntityList)
                {
                    #region  项值校验
                    //校验文本框的值是否在下拉框选项中
                    foreach (var headDto in headDtoList)
                    {
                        #region 基础判断
                        //判断是否为选项列
                        if (headDto.ColumnType != Attribute.Enum.ColumnTypeEnum.Option)
                        {
                            continue;
                        }
                        //判断选项是否存在
                        if (sheet.ColumnOptions == null)
                        {
                            continue;
                        }

                        //判断属性是否存在
                        if (string.IsNullOrEmpty(headDto.PropertyName))
                        {
                            continue;
                        }
                        #endregion

                        //其他列的键值
                        string key = null;

                        #region 获其他列的键值
                        if (sheet.ColumnOptions.Keys.Contains(headDto.HeadName))
                        {
                            key = headDto.HeadName;
                        }
                        if (sheet.ColumnOptions.Keys.Contains(headDto.PropertyName))
                        {
                            key = headDto.PropertyName;
                        }
                        //判断键是否为空
                        if (key == null)
                        {
                            continue;
                        }
                        #endregion

                        //变量设置
                        PropertyInfo propertyInfo = item.GetType().GetProperty(headDto.PropertyName);
                        string       value        = propertyInfo.GetValue(item).ToString();

                        #region 校验
                        //类型判断decimal
                        if (propertyInfo.PropertyType == typeof(decimal) || propertyInfo.PropertyType == typeof(decimal?))
                        {
                            List <decimal> options = sheet.ColumnOptions[key].Select(n => Convert.ToDecimal(n)).ToList();
                            if (options.Contains(Convert.ToDecimal(value)) == true)
                            {
                                continue;
                            }
                        }

                        //类型判断double
                        if (propertyInfo.PropertyType == typeof(double) || propertyInfo.PropertyType == typeof(double?))
                        {
                            List <double> options = sheet.ColumnOptions[key].Select(n => Convert.ToDouble(n)).ToList();
                            if (options.Contains(Convert.ToDouble(value)) == true)
                            {
                                continue;
                            }
                        }

                        //判断输入的值是否在选项值中
                        if (sheet.ColumnOptions[key].Contains(value) == true)
                        {
                            continue;
                        }

                        #endregion

                        #region  通过则提示异常
                        //异常信息
                        ColumnErrorMessage errorMsg = new ColumnErrorMessage
                        {
                            PropertyName = headDto.PropertyName,
                            ColumnName   = headDto.HeadName,
                            ErrorMessage = ExcelGlobalDTO.ExcelValidationMessage.Clgyl_Common_Import_NotExistOptions
                        };
                        item.ColumnErrorMessage.Add(errorMsg);
                        #endregion
                    }
                    #endregion

                    #region  实体特性验证
                    List <ValidationResult> result = pairs[item.RowNumber];
                    if (result == null)
                    {
                        continue;
                    }
                    foreach (var msg in result)
                    {
                        //异常信息
                        ColumnErrorMessage errorMsg = new ColumnErrorMessage
                        {
                            PropertyName = msg.PropertyName,
                            ErrorMessage = msg.ErrorMessage
                        };

                        //设置列信息
                        var headDto = headDtoList.Where(w => w.PropertyName == msg.PropertyName).FirstOrDefault();
                        if (headDto != null)
                        {
                            errorMsg.ColumnName = headDto.HeadName;
                        }

                        //添加至集合
                        item.ColumnErrorMessage.Add(errorMsg);
                    }
                    #endregion
                }
            }

            //动态列验证
            DynamicColumn <TEntity> .ValidationValue(ExcelGlobalDTO, ValidationModelEnum.DynamicColumn);

            //验证值后
            this.ValidationValueAfter();
        }