示例#1
0
        public MatrixRow AddRow()
        {
            var row = new MatrixRow(this, new object[Columns.Count]);

            Rows.Add(row);
            return(row);
        }
示例#2
0
 public object GetValue(MatrixRow row)
 {
     if (ValueGenerator != null)
     {
         return(ValueGenerator(row));
     }
     return(null);
 }
示例#3
0
 public MatrixRow AddRow()
 {
     var row = new MatrixRow(this, new object[Columns.Count]);
     Rows.Add(row);
     return row;
 }
示例#4
0
 public object GetValue(MatrixRow row)
 {
     if (ValueGenerator != null) {
         return ValueGenerator(row);
     }
     return null;
 }
示例#5
0
        public void InsertRow(string tableName, MatrixRow row)
        {
            int numCols = row.Matrix.Columns.Count;
            StringBuilder b = new StringBuilder();

            foreach (MatrixColumn col in row.Matrix.Columns) {
                if (!col.IsHidden) {
                    b.Append("@").Append(col.Name.Replace(" ", ""));
                    b.Append(", ");
                }
            }

            b.Remove(b.Length - 2, 2);

            Command((cmd) => {
                cmd.CommandText = String.Format(@"INSERT INTO [{0}] VALUES ({1})", tableName, b.ToString());
                int currentCol = 0;
                foreach (MatrixColumn col in row.Matrix.Columns) {
                    if (!col.IsHidden) {
                        cmd.Parameters.Add(new SQLiteParameter("@" + col.Name.Replace(" ", ""), row[currentCol++]));
                    }
                }
                cmd.ExecuteNonQuery();
            });
        }
示例#6
0
        public DataMatrix StoredProcDataMatrix(string proc, Dictionary <string, ColumnDataFormatter> formatterMap, List <MatrixColumn> additionalColumns, params DbParameter[] @params)
        {
            DataMatrix[]          matrix     = { null };
            ColumnDataFormatter[] formatters = null;

            var defaultFormatter = new ColumnDataFormatter((value, rdr) => value);

            StoredProcReaderForEach(proc, (reader) => {
                if (matrix[0] == null)
                {
                    // Set up formatter array...
                    formatters = new ColumnDataFormatter[reader.FieldCount];

                    matrix[0] = new DataMatrix();
                    for (int i = 0; i < reader.FieldCount; ++i)
                    {
                        var columnName = reader.GetName(i);

                        bool hidden = false;
                        if (columnName.StartsWith(HIDDEN_COLUMN_PREFIX))
                        {
                            columnName = columnName.Substring(HIDDEN_COLUMN_PREFIX.Length);
                            hidden     = true;
                        }

                        matrix[0].Columns.Add(new MatrixColumn {
                            Name = columnName, IsHidden = hidden
                        });
                        if (formatterMap != null && formatterMap.ContainsKey(columnName))
                        {
                            formatters[i] = formatterMap[columnName];
                        }
                        else
                        {
                            formatters[i] = defaultFormatter;
                        }
                    }
                }

                if (additionalColumns != null && additionalColumns.Count > 0)
                {
                    foreach (MatrixColumn col in additionalColumns)
                    {
                        matrix[0].Columns.Add(col);
                    }
                }

                MatrixRow row = matrix[0].AddRow();
                for (int i = 0; i < reader.FieldCount; ++i)
                {
                    if (!reader.IsDBNull(i))
                    {
                        row[i] = formatters[i](reader[i], reader);
                    }
                }
            }, @params);

            if (matrix[0] == null)
            {
                matrix[0] = new DataMatrix();
            }

            return(matrix[0]);
        }
示例#7
0
        private void AddFieldData(MatrixRow targetRow, int objectId, string objectFieldName, DataMatrix srcData)
        {
            var srcRow = srcData.FindRow(objectFieldName, objectId);
            if (srcRow != null) {
                for (int srcIndex = 0; srcIndex < srcData.Columns.Count; srcIndex++) {
                    var col = srcData.Columns[srcIndex];
                    int targetIndex = targetRow.Matrix.IndexOf(col.Name);

                    if (targetIndex >= 0) {
                        targetRow[targetIndex] = srcRow[srcIndex];
                    }
                }
            }
        }
示例#8
0
 private void CopyRow(DataMatrix dest, MatrixRow srcRow, int numCopies)
 {
     for (int i = 0; i < numCopies; ++i) {
         var newRow = dest.AddRow();
         foreach (MatrixColumn col in dest.Columns) {
             int index = dest.IndexOf(col.Name);
             newRow[index] = srcRow[index];
         }
     }
 }
示例#9
0
        private string BuildDescription(MatrixRow row)
        {
            StringBuilder b = new StringBuilder("<![CDATA[\n<table>");
            foreach (MatrixColumn col in row.Matrix.Columns) {
                b.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", col.Name, row[row.Matrix.IndexOf(col.Name)]);
            }

            b.Append("</table>\n]]>");

            return b.ToString();
        }