Example #1
0
 public RowDefaulter(DataTable table, string[] pCols, object[] pValues, IRowValidator pValidator)
     : base(table, pValidator)
 {
     cols   = pCols;
     values = pValues;
     tableSource.RowChanged += new DataRowChangeEventHandler(table_RowChanged);
 }
Example #2
0
        public IEnumerable <IValidatedRow <T> > Listify <T>(string filePath, IRowValidator <T> rowValidator, bool hasHeaderRow = false)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            string fileExtension = Path.GetExtension(filePath);

            using (var stream = new FileStream(filePath, FileMode.Open))
            {
                IWorkbook workbook;

                switch (fileExtension.ToLower())
                {
                case ".xls":
                    workbook = new HSSFWorkbook(stream);
                    break;

                case ".xlsx":
                    workbook = new XSSFWorkbook(stream);
                    break;

                default:
                    throw new InvalidOperationException("Excelsior can only operate on .xsl and .xlsx files.");
                }

                return(Listify(workbook, rowValidator, hasHeaderRow));
            }
        }
        void add(string col, ITableColumnChange pActivity, IBlockPoint pBlock, IRowValidator pValidator, ColumnChangeEventType pEvent)
        {
            {
                DataRow row = getRow(pEvent, col);
                if (row == null)
                {
                    row = tableRel.Rows.Add(
                        new object[] {
                        pEvent,
                        col,
                        new List <ITableColumnChange>(),
                        new List <IRowValidator>(),
                        new List <IBlockPoint>(),
                    });
                }

                ((List <ITableColumnChange>)row[colACTIVITY]).Add(pActivity);
                ((List <IRowValidator>)row[colVALIDATOR]).Add((pValidator == null) ? new RowValidatorTrue() : pValidator);
                ((List <IBlockPoint>)row[colBLOCK]).Add(pBlock);
            }
            {
                tableRelDistinct.Rows.Add(
                    new object[] {
                    pActivity,
                    pValidator
                });
            }
        }
Example #4
0
        void init(DataTable pTableSource, DataTable pTableDest, IPagedSource pSource, string[] pBindChildCol, string[] pBindParentCol, string[] pChildCol, string[] pParentCol, UpdateTypeFlags pFlags, IRowValidator pValidator, string[] pTriggerCols)
        {
            validator   = (pValidator == null) ? new RowValidatorTrue() : pValidator;
            tableSource = pTableSource;
            tableDest   = pTableDest;
            flags.flagEnable(pFlags);
            source = pSource;

            triggerCols   = pTriggerCols;
            bindChildCol  = pBindChildCol;
            bindParentCol = pBindParentCol;
            childCol      = pChildCol;
            parentCol     = pParentCol;
            allChildCol   = childCol;
            allParentCol  = parentCol;

            //
            for (int i = 0; i < bindChildCol.Length; ++i)
            {
                addColForMapBind(bindChildCol[i], bindParentCol[i]);
            }
            for (int i = 0; i < childCol.Length; ++i)
            {
                addColForMapData(childCol[i], parentCol[i]);
            }

            //

            if (flags.isFlagEnabled(UpdateTypeFlags.activeOnRelColumn))
            {
                columns = bindChildCol;
            }
            else
            {
                int len = allChildCol.Length;
                if (flags.isFlagEnabled(UpdateTypeFlags.activateIgnorLast1DrivedChilCols))
                {
                    len -= 1;
                }
                else
                if (flags.isFlagEnabled(UpdateTypeFlags.activateIgnorLast1DrivedChilCols))
                {
                    len -= 2;
                }
                else
                if (flags.isFlagEnabled(UpdateTypeFlags.activateIgnorLast1DrivedChilCols))
                {
                    len -= 3;
                }
                columns = new string[len];
                Array.Copy(allChildCol, columns, len);
            }
            columns = ToolArray.merge <string>(columns, triggerCols);
            //
            // if (flags.isFlagEnabled(UpdateTypeFlags.updateIgnoreRelColumn))
            updateChildCol = childCol;
            // else
            //     updateChildCol = allChildCol;
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!
        }
 public EventFilerColumnChangedPickAll(DataTable table, string[] trigerCols, EventFilerActivityForRow worker, IRowValidator pValidatorMainRow, IRowValidator pValidator)
     : base(table, trigerCols, pValidator)
 {
     wkrRow                     = worker;
     validatorMainRow           = pValidatorMainRow;
     tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChangedRow);
 }
Example #6
0
 public RowLocalGroupKeeper(DataTable table, IRowsSelector pForTop, IRowsSelector pForSub, IRowValidator pValidator)
 {
     //
     forTop             = pForTop;
     forSub             = pForSub;
     validator          = pValidator;
     table.RowDeleting += new DataRowChangeEventHandler(table_RowDeleting);
 }
 public RowsSelectorExp(string pExpU, string pExpB, DataTable pTable, IRowValidator pValidator)
 {
     evalU = new ImplRowEvaluator(pTable);
     evalU.addExpression(expName, expU = pExpU, typeof(string));
     evalB = new ImplRowEvaluator(pTable);
     evalB.addExpression(expName, expB = pExpB, typeof(string));
     validator = pValidator;
 }
        public RowsSelectorValidator(DataTable pTable, IRowValidator pValidatorSelectT, IRowValidator pValidatorStopT, IRowValidator pValidatorSelectB, IRowValidator pValidatorStopB, IRowValidator pValidator)
        {
            validatorSelectT = pValidatorSelectT;
            validatorStopT   = pValidatorStopT;
            validatorSelectB = pValidatorSelectB;
            validatorStopB   = pValidatorStopB;

            validator = pValidator;
        }
        public void export(XmlDocument doc)
        {
            if (this.getExportDescriptor() == null)
            {
                initExportDescriptor(this, _userAdapter);
            }
            correctDoc(doc);
            DataSet    dataSet    = _userAdapter.getDataSet();
            XmlElement xmlExpRoot = doc.CreateElement(_nodeItemName);

            xmlExpRoot.SetAttribute(_attrRootCode, dataSet.DataSetName);
            char   sepChar = '\t';
            string expTable;

            string[] expCols;
            IEnumerator <KeyValuePair <string, string[]> > expTabsEnumer = _expDesc.GetEnumerator();

            expTabsEnumer.Reset();
            while (expTabsEnumer.MoveNext())
            {
                expTable = expTabsEnumer.Current.Key;
                expCols  = expTabsEnumer.Current.Value;

                DataTable     table     = dataSet.Tables[expTable];
                IRowValidator validator = getValidator(expTable);
                //
                XmlElement xmlExpTab = doc.CreateElement(expTable);
                xmlExpTab.SetAttribute(_attrItemTableCols, ToolString.joinList(sepChar, expCols));
                xmlExpRoot.AppendChild(xmlExpTab);
                //
                StringWriter strData = new StringWriter();
                strData.WriteLine();
                foreach (DataRow expRow in table.Rows)
                {
                    if (validator.check(expRow))
                    {
                        bool isFirstVal = true;
                        foreach (string expCol in expCols)
                        {
                            if (isFirstVal)
                            {
                                isFirstVal = false;
                            }
                            else
                            {
                                strData.Write(sepChar);
                            }
                            strData.Write(_formating.format(expRow[expCol]));
                        }
                        strData.WriteLine();
                    }
                }
                xmlExpTab.InnerText = strData.GetStringBuilder().ToString();
            }
            doc[_nodeRootName].AppendChild(xmlExpRoot);
        }
        public RowDeleteWatcher(DataTable table, IRowValidator pValidator, string[] pCol, object[] pVal)
        {
            //

            columns   = pCol;
            values    = pVal;
            validator = (pValidator == null ? new RowValidatorTrue() : pValidator);

            table.RowDeleting += new DataRowChangeEventHandler(table_RowDeleting);
        }
Example #11
0
        public IEnumerable <IValidatedRow <T> > Listify <T>(byte[] data, IRowValidator <T> rowValidator, bool hasHeaderRow = false)
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentNullException("data");
            }

            IWorkbook workbook = GetWorkbook(data);

            return(Listify <T>(workbook, rowValidator, hasHeaderRow));
        }
 public void setRowValidator(string pTable, IRowValidator pRowValidator)
 {
     if (_validatorCol.ContainsKey(pTable))
     {
         _validatorCol[pTable] = pRowValidator;
     }
     else
     {
         _validatorCol.Add(pTable, pRowValidator);
     }
 }
Example #13
0
 public static DataRow getFirstRealRow(DataTable table, IRowValidator validator)
 {
     for (int i = 0; i < table.Rows.Count; ++i)
     {
         if ((table.Rows[i].RowState != DataRowState.Deleted) && validator.check(table.Rows[i]))
         {
             return(table.Rows[i]);
         }
     }
     return(null);
 }
 public RowMaintainAtTopBottom(RowMaintainDirection pDirection, RowMaintainPlace pPlace, RowMaintainPlace pNoSectionPlace, DataTable table, string[] pCols, object[] pValues, IRowValidator pValidatorRow, IRowValidator pValidator)
     : base(table, pValidator)
 {
     direction               = pDirection;
     place                   = pPlace;
     noSectionPlace          = pNoSectionPlace;
     cols                    = pCols;
     values                  = pValues;
     maintainRow             = (pValidatorRow == null) ? new RowValidatorTrue() : pValidatorRow;
     tableSource.RowDeleted += new DataRowChangeEventHandler(table_RowDeleted);
 }
Example #15
0
 public static int getSectionStart(DataTable table, IRowValidator validator)
 {
     for (int indx = 0; indx < table.Rows.Count; ++indx)
     {
         if ((table.Rows[indx].RowState != DataRowState.Deleted))
         {
             if (validator.check(table.Rows[indx]))
             {
                 return(indx);
             }
         }
     }
     return(-1);
 }
Example #16
0
 public RowColumnsBindingBase(DataTable table, string[] colArr, double coif, ICellMath pForward, ICellMath pBackward, IRowValidator pValidator)
     : base(table, pValidator)
 {
     columns  = colArr;
     padCoif  = coif;
     backward = pBackward;
     forward  = pForward;
 }
Example #17
0
 public RowColumnsBindingBase(DataTable table, string[] colArr, string col, IRowValidator pValidator)
     : base(table, pValidator)
 {
     columns = colArr;
     column  = col;
 }
Example #18
0
 public RowColumnsBindingBase(DataTable table, IRowValidator pValidator)
     : base(table, pValidator)
 {
 }
 public void addRelation(string[] pCols, ITableColumnChange pActivity, IRowValidator pValidator)
 {
     addRelation(pCols, pActivity, new BlockPoint(), pValidator, defaultEvent);
 }
        public RowDateTimeToIntColumnsBinding(DataTable table, string pColDateTime, string pColIntDate, bool pConvertDate, IRowValidator pValidator)
            : base(table, new string[] { pColDateTime, pColIntDate }, pValidator)
        {
            colDateTime = pColDateTime;
            colIntDate  = pColIntDate;

            if (pConvertDate)
            {
                toInt   = new actionToInt(ToolGeneral.date2IntDate);
                fromInt = new actionFromInt(ToolGeneral.intDate2Date);
            }
            else
            {
                toInt   = new actionToInt(ToolGeneral.time2IntTime);
                fromInt = new actionFromInt(ToolGeneral.intTime2Time);
            }

            tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChanged);
        }
 public RowColumnsBindingInner(DataTable table, string[] colArr, double coif, ICellMath pForward, ICellMath pBackward, IRowValidator pValidator)
     : base(table, colArr, coif, pForward, pBackward, pValidator)
 {
     tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChangedForRow);
 }
 public RowColumnsBindingInnerAlwaysLast(DataTable table, string[] colArr, string col, double coif, ICellMath pForward, ICellMath pBackward, IRowValidator pValidator)
     : base(table, colArr, coif, pForward, pBackward, pValidator)
 {
     lastCol = col;
 }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="pCols">first allways FULL DATETIME !</param>
        /// <param name="pParts"></param>
        /// <param name="pValidator"></param>
        public RowDateTimeDistributor(DataTable table, string[] pCols, DateParts[] pParts, IRowValidator pValidator)
            : base(table, pCols, pValidator)
        {
            parts = pParts;
            bool modeCompile = !tableSource.Columns.Contains(columns[0]);

            for (int i = 0; i < columns.Length; ++i)
            {
                if (!tableSource.Columns.Contains(columns[i]))
                {
                    tableSource.Columns.Add(columns[i], partTypeToType(parts[i]));
                }
            }
            for (int i = 0; i < tableSource.Rows.Count; ++i)
            {
                DataRow row = tableSource.Rows[i];
                string  col = string.Empty;
                if (modeCompile)
                {
                    col = columns[1];
                }
                else
                {
                    col = columns[0];
                }
                table_ColumnChanged(tableSource, new DataColumnChangeEventArgs(row, tableSource.Columns[col], row[col]));
            }
            tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChanged);
        }
Example #24
0
        public RowReseter(ResetEvents pEvent, DataTable table, string[] pCols, string[] pColsReset, IRowValidator pValidator)
            : base(table, pCols, pValidator)
        {
            cols = pColsReset;
            switch (pEvent)
            {
            case ResetEvents.changing:
                tableSource.ColumnChanging += new DataColumnChangeEventHandler(tableSource_ColumnChanging);
                break;

            case ResetEvents.deleting:
                tableSource.RowDeleting += new DataRowChangeEventHandler(tableSource_RowDeleting);
                break;
            }
        }
 public ImplRowIniterValidated(string[] pCols, object[] pVals, IRowValidator pValidator)
 {
     cols      = pCols;
     vals      = pVals;
     validator = pValidator;
 }
Example #26
0
 public RowColumnsBindingBase(DataTable table, string[] colArr, string col, string pExpr, IRowValidator pValidator)
     : base(table, pValidator)
 {
     pExpr     = string.Format(pExpr, colArr);
     columns   = colArr;
     column    = col;
     evaluator = new ImplRowEvaluator();
     for (int i = 0; i < columns.Length; ++i)
     {
         evaluator.addVar(columns[i], table.Columns[columns[i]].DataType);
     }
     evaluator.addExpression(column, pExpr, typeof(double));
 }
        public RowColumnsBindingBetweenTablesExpExt(DataTable tableS, DataTable tableD, string[] colS, string colD, string expresionRow, Type typeRow, string expresionAmangRow, Type typeAngRow, string expresionFinal, Object prevDef, IRowValidator filter)
            : base(tableS, filter)
        {
            columns      = colS;
            column       = colD;
            tableDest    = tableD;
            defaultAmang = prevDef;
            evaluatorRow = new ImplRowEvaluator();
            for (int i = 0; i < columns.Length; ++i)
            {
                evaluatorRow.addVar(columns[i], tableSource.Columns[columns[i]].DataType);
            }
            evaluatorRow.addExpression(expresionRow, typeRow);

            evaluatorAmangRow = new ImplRowEvaluator();
            evaluatorAmangRow.addVar(colPrevValue, typeAngRow);
            evaluatorAmangRow.addVar(colCurValue, typeAngRow);
            evaluatorAmangRow.addExpression(expresionAmangRow, typeAngRow);

            evaluatorFinal = new ImplRowEvaluator();
            evaluatorFinal.addVar(colAmangValue, typeAngRow);
            evaluatorFinal.addExpression(expresionFinal, tableD.Columns[column].DataType);

            tableSource.RowDeleted    += new DataRowChangeEventHandler(table_RowDeleted);
            tableSource.RowChanged    += new DataRowChangeEventHandler(table_RowChanged);
            tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChanged);
        }
Example #28
0
        public IEnumerable <IValidatedRow <T> > Listify <T>(IWorkbook workbook, IRowValidator <T> rowValidator, bool hasHeaderRow = false)
        {
            if (workbook == null)
            {
                throw new ArgumentNullException("workbook");
            }

            ISheet sheet = workbook.GetSheetAt(0);

            if (sheet == null)
            {
                return(Enumerable.Empty <ValidatedRow <T> >());
            }

            int excelColumnCount = sheet.GetRow(0).PhysicalNumberOfCells;

            List <PropertyInfo> mappingTypeProperties = GetMappingTypeProperties(typeof(T));

            if (mappingTypeProperties.Count != excelColumnCount)
            {
                throw new ColumnCountException("Column count in given file does not match columns identified in model T.");
            }

            int firstDataRow = 0;

            if (hasHeaderRow)
            {
                bool isRightColumnOrder = CheckExcelColumnOrder <T>(sheet.GetRow(0));

                if (!isRightColumnOrder)
                {
                    throw new ColumnOrderException("Columns order identified in model T does not match the order in file.");
                }

                firstDataRow = 1;
            }

            ICollection <IValidatedRow <T> > itemList = new List <IValidatedRow <T> >();

            for (int i = firstDataRow; i < sheet.PhysicalNumberOfRows; i++)
            {
                IRow row = sheet.GetRow(i);

                if (!IsRowEmpty(row))
                {
                    T item = GetItemFromRow <T>(row, mappingTypeProperties);

                    IRowValidationResult validationResult = rowValidator.Validate(item);

                    IValidatedRow <T> validatedRow = new ValidatedRow <T>();
                    validatedRow.RowNumber = i;
                    validatedRow.Item      = item;
                    validatedRow.IsValid   = validationResult.IsValid;
                    validatedRow.Errors    = validationResult.Errors;

                    itemList.Add(validatedRow);
                }
            }

            return(itemList);
        }
        public static IEnumerable <IValidatedRow <T> > Listify <T>(this IExcelsior excelsior, HttpPostedFileBase httpPostedFileBase, IRowValidator <T> rowValidator, bool hasHeaderRow = false)
        {
            string fileExtension = Path.GetExtension(httpPostedFileBase.FileName) ?? String.Empty;

            IWorkbook workbook;

            switch (fileExtension.ToLower())
            {
            case ".xls":
                workbook = new HSSFWorkbook(httpPostedFileBase.InputStream);
                break;

            case ".xlsx":
                workbook = new XSSFWorkbook(httpPostedFileBase.InputStream);
                break;

            default:
                throw new InvalidOperationException("Excelsior can only operate on .xsl and .xlsx files.");
            }

            return(excelsior.Listify(workbook, rowValidator, hasHeaderRow));
        }
        public RowColumnsBindingSpaceExp(DataTable table, IRowEvaluator pEvaluator, string[] trigerCols, string pTopExp, string pSubCorrectExp, string[] pSubCols, string[] pSubExp, IRowsSelector pSelectorTop, IRowsSelector pSelectorBot, IRowValidator pValidator)
            : base(table, pValidator)
        {
            //
            columns = trigerCols;

            selectorTop = pSelectorTop;
            selectorBot = pSelectorBot;
            subCols     = pSubCols;
            subExp      = pSubExp;

            topExp        = string.Format(pTopExp, _TOP_VALUE_);
            subCoorectExp = string.Format(pSubCorrectExp, _TOP_VALUE_);
            for (int i = 0; i < subExp.Length; ++i)
            {
                subExp[i] = string.Format(subExp[i], _TOP_VALUE_);
            }

            //

            //
            evaluator = pEvaluator;
            evaluator.addVar(_TOP_VALUE_, typeof(double));
            evaluator.addExpression(nameTopExp, topExp, typeof(double));
            evaluator.addExpression(nameSubCoorectExp, subCoorectExp, typeof(double));
            for (int i = 0; i < pSubExp.Length; ++i)
            {
                evaluator.addExpression(getName(subCols[i]), subExp[i], typeof(double));
            }
            //

            tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChangedForRow);
        }