bool needUpdate(DataRow row, string[] cols) { if (row == null) { return(false); } bool flagResetOnAllNullOrDef = flags.isFlagEnabled(UpdateTypeFlags.resetIfAllCurrentRelColsAreDefaultOrNull); bool flagStopIfOneNullOrDef = !flags.isFlagEnabled(UpdateTypeFlags.continueIfOneOfCurrentRelColsDefaultOrNull); if (ToolCell.isDefaultOrNullAll(row, cols)) { if (flagResetOnAllNullOrDef) { ToolRow.initTableNewRow(row, allChildCol); return(false); } if (flagStopIfOneNullOrDef) { return(false); } } if (ToolCell.hasDefaultOrNull(row, cols)) { if (flagStopIfOneNullOrDef) { return(false); } } return(true); }
public static object[][] getGroups(DataTable table, string[] colsArr) { List <object[]> list = new List <object[]>(); DataColumn[] colsObj = new DataColumn[colsArr.Length]; for (int i = 0; i < colsArr.Length; ++i) { colsObj[i] = table.Columns[colsArr[i]]; } foreach (DataRow row in table.Rows) { object[] curValues = ToolRow.copyRowToArr(colsObj, row); foreach (object[] arr in list) { if (ToolArray.isEqual(arr, curValues)) { curValues = null; break; } } if (curValues != null) { list.Add(curValues); } } list.Sort(new ToolArray.Comparer()); return(list.ToArray()); }
internal static void insertRowAt(DataTable table, int i, object[] arr) { i = Math.Max(i, 0); DataRow rowN = table.NewRow(); ToolRow.copyArrToRow(arr, rowN); table.Rows.InsertAt(rowN, i); }
private static bool hasRow(DataTable table, DataRow row) { DataRow rowS = null; if (table != null && row != null && table.PrimaryKey != null && table.PrimaryKey.Length > 0) { object[] arr = ToolRow.copyRowToArr(table.PrimaryKey, row); rowS = table.Rows.Find(arr); } return(rowS != null); }
public static DataTable create(DataRow row) { DataTable table = null; if (row != null) { table = row.Table.Clone(); ToolRow.copyRowToTable(row, table); } return(table); }
public static void trimColumn(DataTable table, string col) { if ((table != null) && (table.Columns[col].DataType == typeof(string))) { for (int i = 0; i < table.Rows.Count; ++i) { if (!ToolRow.isDeleted(table.Rows[i])) { table.Rows[i][col] = ((string)ToolCell.isNull(table.Rows[i][col], string.Empty)).Trim(); } } } }
static object[] compareData(DataRow row, DataColumn[] cols, object[] values) { bool sameData = true; object[] curValues = ToolRow.copyRowToArr(cols, row); for (int i = 0; i < curValues.Length; ++i) { if (!ToolType.isEqual(curValues[i], values[i])) { sameData = false; break; } } return(sameData ? null : curValues); }
public static double getSumDouble(DataTable table, string col) { double res = 0; if (table != null) { for (int i = 0; i < table.Rows.Count; ++i) { if (!ToolRow.isDeleted(table.Rows[i])) { res += (double)ToolCell.isNull(table.Rows[i][col], 0.0); } } } return(res); }
public static double getSumDouble(DataRow[] rows, string col) { double res = 0; if (rows != null) { for (int i = 0; i < rows.Length; ++i) { if (!ToolRow.isDeleted(rows[i])) { res += (double)ToolCell.isNull(rows[i][col], 0.0); } } } return(res); }
public static double getSum(IEnumerable rows, string col) { IEnumerator enumer = rows.GetEnumerator(); enumer.Reset(); Double sum = 0; while (enumer.MoveNext()) { if (!ToolRow.isDeleted((DataRow)enumer.Current)) { sum += Convert.ToDouble(((DataRow)enumer.Current)[col]); } } return(sum); }
void tableSource_ColumnChanging(object sender, DataColumnChangeEventArgs e) { if (e.Row.RowState != DataRowState.Detached) { if (isMyCollumn(e.Column.ColumnName) && validator.check(e.Row)) { if (block()) { try { ToolRow.initTableNewRow(e.Row, cols); } finally { unblock(); } } } } }
void tableSource_RowDeleting(object sender, DataRowChangeEventArgs e) { if (e.Row.RowState != DataRowState.Detached) { if (validator.check(e.Row)) { if (block()) { try { ToolRow.initTableNewRow(e.Row, cols); } finally { unblock(); } } } } }
public void check() { if (block()) { try { DataRow fRow = null; switch (direction) { case RowMaintainDirection.down: fRow = ToolRow.getFirstRealRow(tableSource, validator); break; case RowMaintainDirection.up: fRow = ToolRow.getLastRealRow(tableSource, validator); break; } if (fRow == null || !maintainRow.check(fRow)) { DataRow nRow = ToolRow.initTableNewRow(tableSource.NewRow()); for (int i = 0; i < cols.Length; ++i) { ToolCell.set(nRow, cols[i], values[i]); } int indx = 0; switch (place) { case RowMaintainPlace.top: indx = ToolRow.getSectionStart(tableSource, validator); break; case RowMaintainPlace.bottom: indx = ToolRow.getSectionEnd(tableSource, validator); if (indx >= 0) { ++indx; } break; } if (indx < 0) { switch (noSectionPlace) { case RowMaintainPlace.top: indx = 0; break; case RowMaintainPlace.bottom: indx = int.MaxValue; break; } } tableSource.Rows.InsertAt(nRow, indx); } } finally { unblock(); } } }
void distribute(DataRow row, string[] cols) { if (validator.check(row)) { if (needUpdate(row, cols)) { bool drivedUpdateMode = flags.isFlagEnabled(UpdateTypeFlags.__spe__updateIfDrived); if (drivedUpdateMode) { bool hasFull = false; for (int i = 0; i < allChildCol.Length; ++i) { if (ToolColumn.isColumnFullName(allChildCol[i])) { hasFull = true; } } if (!hasFull) { return; } } //getData source.getBuilder().reset(); for (int i = 0; i < cols.Length; ++i) { string col = ToolColumn.extractColumnName(getColMap(cols[i])); string tab = ToolColumn.extractTableName(getColMap(cols[i])); object val = row[cols[i]]; if ((tab != string.Empty) && (col != string.Empty)) { source.getBuilder().addParameterValueTable(tab, col, val); } else if (col != string.Empty) { source.getBuilder().addParameterValue(col, val); } else if (col == string.Empty) { source.getBuilder().addFreeParameterValue(val); } } IDictionary dicData = ToolRow.convertFirstToDictionary(source.getAll()); // if (dicData != null) { //Has data string[] tmpChildCol = (drivedUpdateMode ? ToolColumn.selectFullNameCols(updateChildCol) : updateChildCol); for (int i = 0; i < tmpChildCol.Length; ++i) { ToolCell.set(row, tmpChildCol[i], dicData[getColMap(tmpChildCol[i])]); } } else { //No data if (!flags.isFlagEnabled(UpdateTypeFlags.disableEditCancel)) { row.CancelEdit(); } else { if (flags.isFlagEnabled(UpdateTypeFlags.setTypeDefaultToDrivedChild)) { ToolRow.initTableNewRow(row, (drivedUpdateMode ? ToolColumn.selectFullNameCols(childCol) : childCol)); } if (flags.isFlagEnabled(UpdateTypeFlags.setTypeDefaultToRelChild)) { ToolRow.initTableNewRow(row, (drivedUpdateMode ? ToolColumn.selectFullNameCols(bindChildCol) : bindChildCol)); } } } } } }