public static string InsertTableRows(DataTable sourceTable, string destTableName)
        {
            string    message   = string.Empty;
            DataTable destTable = GetTable(destTableName);
            var       newRows   = new List <DataRow>(sourceTable.Rows.Count);
            var       rowId     = GetNewId(destTableName);

            foreach (DataRow row in sourceTable.Rows)
            {
                try {
                    var decodeRow = KeyValueSwitch.DecodeRow(row, destTable);
                    if (destTable.Columns.Contains("ID"))
                    {
                        decodeRow["ID"] = rowId++;
                    }
                    else
                    {
                        SetNewId(destTableName, decodeRow);
                    }
                    newRows.Add(decodeRow);
                    destTable.Rows.Add(decodeRow);
                } catch (Exception ex) {
                    message += "\n" + ex.Message + " Строка в файле " + sourceTable.Rows.IndexOf(row);
                }
            }
            if (string.IsNullOrEmpty(message))
            {
                try {
                    DataBaseConnector.InserteRecords(newRows);
                    foreach (var row in newRows)
                    {
                        AddRowToTable(destTable, row);
                    }
                } catch (Exception ex) {
                }
            }
            else
            {
                foreach (var row in newRows)
                {
                    destTable.Rows.Remove(row);
                }
            }
            return(message);
        }
Exemple #2
0
        private static Dictionary <string, Dictionary <string, object> > GetCommentsFromBase()
        {
            string    query = @"select
            rf.rdb$relation_name,
            rf.rdb$field_name,
            rf.rdb$description
            from rdb$relation_fields rf
            where (coalesce(rf.rdb$system_flag, 0) = 0) and rf.rdb$description is not null";
            var       dict  = new Dictionary <string, Dictionary <string, object> >();
            DataTable table = DataBaseConnector.GetTableByQuery(query);

            foreach (DataRow row in table.Rows)
            {
                var tableName  = row[0].ToString().Replace(" ", "");
                var columnName = row[1].ToString().Replace(" ", "");
                var comment    = row[2].ToString();
                AddValueToDict(tableName, columnName, comment, dict);
            }
            return(dict);
        }
Exemple #3
0
        private static Dictionary <string, Dictionary <string, object> > GetMaxLendthFromBase()
        {
            string    query = @"select
            rf.rdb$relation_name,
            rf.rdb$field_name,
            case f.rdb$field_type
                    when 8 then 9
                    else f.rdb$field_length / 4
                    end
            from rdb$relation_fields rf
            join rdb$fields f on (f.rdb$field_name = rf.rdb$field_source)
            where (coalesce(rf.rdb$system_flag, 0) = 0)";
            var       dict  = new Dictionary <string, Dictionary <string, object> >();
            DataTable table = DataBaseConnector.GetTableByQuery(query);

            foreach (DataRow row in table.Rows)
            {
                var tableName  = row[0].ToString().Replace(" ", "");
                var columnName = row[1].ToString().Replace(" ", "");
                var length     = Convert.ToInt32(row[2]);
                AddValueToDict(tableName, columnName, length, dict);
            }
            return(dict);
        }