Example #1
0
        /// <summary>
        /// Сохранение данных таблицы
        /// </summary>
        /// <param name="writer">Поток записи в файл</param>
        /// <param name="fbConnection">Соединение с базой данных</param>
        /// <param name="fbTransaction">Открытая транзакция</param>
        /// <param name="tableName">Имя таблицы</param>
        private void CopyTable(ICashDataWriter writer, FbConnection fbConnection, FbTransaction fbTransaction, string tableName)
        {
            writer.AppendTable(tableName);

            using (FbCommand selectCommand = new FbCommand("select * from " + tableName, fbConnection, fbTransaction))
            using (FbDataReader dataReader = selectCommand.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    writer.AppendRecord();

                    for (int i = 0; i < dataReader.FieldCount; i++)
                    {
                        string fieldValue = string.Empty;

                        if (!dataReader.IsDBNull(i))
                        {
                            switch (Type.GetTypeCode(dataReader.GetFieldType(i)))
                            {
                                case TypeCode.DateTime:
                                    writer.AppendField(dataReader.GetName(i), 
                                        dataReader.GetDateTime(i));
                                    break;
                                case TypeCode.Decimal:
                                    writer.AppendField(dataReader.GetName(i), 
                                        dataReader.GetDecimal(i));
                                    break;
                                case TypeCode.Double:
                                    writer.AppendField(dataReader.GetName(i),
                                        dataReader.GetDecimal(i));
                                    break;
                                default:
                                    writer.AppendField(dataReader.GetName(i),
                                        dataReader.GetString(i).Trim());
                                    break;
                            }
                        }
                    }

                }
            }
        }
Example #2
0
        /// <summary>
        /// Сохранение значений генераторов
        /// </summary>
        /// <param name="writer">Поток записи в файл</param>
        /// <param name="fbConnection">Соединение с базой данных</param>
        /// <param name="fbTransaction">Открытая транзакция</param>
        private void CopyGenerators(ICashDataWriter writer, FbConnection fbConnection, FbTransaction fbTransaction)
        {
            writer.AppendTable("Generators");
            writer.AppendRecord();

            using (FbCommand selectCommand = new FbCommand("select RDB$GENERATOR_NAME from RDB$GENERATORS", fbConnection, fbTransaction))
            using (FbDataReader dataReader = selectCommand.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    if (dataReader.GetString(0).StartsWith("RDB$") || dataReader.GetString(0).StartsWith("SQL$"))
                        continue;
                    using (FbCommand genCommand = new FbCommand("select GEN_ID(" + dataReader.GetString(0).Trim() + ", 0) from RDB$DATABASE", fbConnection, fbTransaction))
                    {
                        writer.AppendField(dataReader.GetString(0).Trim(), 
                            genCommand.ExecuteScalar().ToString());
                    }
                }
            }
        }