/// <summary>
        /// Реализация метода экспорта таблицы
        /// </summary>
        /// <param name="table"></param>
        /// <param name="additionaldata"></param>
        public void Export(DataTable table, DataInsertMethod InsertMethod, bool CaseSensivity, bool PrepareTableForInsert)
        {
            try
            {
                writer = new CSV_TXT_TableWriter(_fname);
                writer.SetDelimeter(_delimeter);
                writer.IsStringColumnsQuoted = _is_string_quoted;
                writer.WriteTableToFile(table);

                if (ExportComplete != null)
                {
                    ExportComplete(this, new EventArgs());
                }
            }
            catch (Exception e)
            {
                if (ExportException != null)
                {
                    ExportException(e, new EventArgs());
                }
                else
                {
                    throw e;
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Метод вызывающи у "Способа" экспорта, метод экспорта.
 /// </summary>
 /// <param name="ExportMethod"></param>
 /// <param name="table"></param>
 /// <param name="additionaldata">Здесь передаются такие параметры как имя файла или база данных в которую писать</param>
 public static void Export(IExportTableMethod ExportMethod, DataTable table, DataInsertMethod InsertMethod, bool CaseSensivity, bool PrepareTableForInsert)
 {
     if (ExportMethod != null)
     {
         ExportMethod.Export(table, InsertMethod, CaseSensivity, PrepareTableForInsert);
     }
 }
Exemple #3
0
        /// <summary>
        /// Реализация метода экспорта таблицы
        /// </summary>
        /// <param name="table"></param>
        /// <param name="additionaldata"></param>
        public void Export(DataTable table, DataInsertMethod InsertMethod, bool CaseSensivity, bool PrepareTableForInsert)
        {
            if (sqlmgr != null && sqlmgr.Connected)
            {
                //--пока так, но лучше всетаки сделать еще и апдейт в будущем!
                try
                {
                    if (!sqlmgr.IsDBObjectExists(table.TableName, DataBaseObjects.table, CaseSensivity))
                    {
                        sqlmgr.CreateTable(table, InsertMethod, PrepareTableForInsert);
                    }
                    else
                    {
                        sqlmgr.DropTable(table.TableName);
                        sqlmgr.CreateTable(table, InsertMethod, PrepareTableForInsert);
                    }

                    if (ExportComplete != null)
                    {
                        ExportComplete(this, new EventArgs());
                    }
                }
                catch (Exception e)
                {
                    if (ExportException != null)
                    {
                        ExportException(e, new EventArgs());
                    }
                    else
                    {
                        throw e;
                    }
                }
            }
            else
            {
                throw new Exception("You must connect first!");
            }
        }
Exemple #4
0
        public virtual void CreateTable(DataTable table, DataInsertMethod insert_method, bool PrepareTableForInsert)
        {
            if (string.IsNullOrEmpty(table.TableName))
            {
                if (MessagePrinter != null)
                {
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.DatatableNameNotFoundMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
                }

                return;
            }

            if (table.Columns.Count <= 0)
            {
                if (MessagePrinter != null)
                {
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.DatatableColumnsNotFoundMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
                }

                return;
            }
        }
        public override void CreateTable(DataTable table, DataInsertMethod insert_method)
        {
            if (Connected)
            {
                base.CreateTable(table, insert_method);

                string sqlsc;
                sqlsc = "CREATE TABLE " + table.TableName + "(";
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    sqlsc += "\n" + table.Columns[i].ColumnName;
                    if (table.Columns[i].DataType.ToString().Contains("System.Int32"))
                        sqlsc += " int";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int64"))//--если будут ошибки, то заменить на bigint
                        sqlsc += " bigint";
                    else if (table.Columns[i].DataType.ToString().Contains("System.DateTime"))
                        sqlsc += " datetime";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Decimal"))
                        sqlsc += " decimal";//--возможны ошибки
                    else if (table.Columns[i].DataType.ToString().Contains("System.String"))
                    {
                        if (table.Columns[i].MaxLength <= 255)
                            sqlsc += " varchar(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";
                        else
                            sqlsc += " text";
                    }
                    /*else if (table.Columns[i].DataType.ToString().Contains("System.Single")) //--незнаю какой тип его подменяет
                        sqlsc += " single";*/
                    else if (table.Columns[i].DataType.ToString().Contains("System.Double"))
                        sqlsc += " double";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Guid"))
                        sqlsc += " char(36)";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Boolean"))
                        sqlsc += " tinyint(1)";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Byte"))
                        sqlsc += " tinyint";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int16"))
                        sqlsc += " smallint";
                    else
                        sqlsc += " varchar(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";

                    if (table.Columns[i].AutoIncrement)
                        sqlsc += " AUTO_INCREMENT";// +table.Columns[i].AutoIncrementSeed.ToString() + "," + table.Columns[i].AutoIncrementStep.ToString() + ")";
                    if (!table.Columns[i].AllowDBNull)
                        sqlsc += " NOT NULL ";
                    if (table.Columns[i].DefaultValue != null && table.Columns[i].DefaultValue != DBNull.Value)
                        sqlsc += " DEFAULT " + table.Columns[i].DefaultValue.ToString();
                    sqlsc += ",";
                }

                if (table.PrimaryKey.Length > 0)
                {
                    string pks = "\nCONSTRAINT PK_" + table.TableName + " PRIMARY KEY (";
                    for (int i = 0; i < table.PrimaryKey.Length; i++)
                    {
                        pks += table.PrimaryKey[i].ColumnName + ",";
                    }
                    pks = pks.Substring(0, pks.Length - 1) + ")";
                    sqlsc += pks;
                    sqlsc = sqlsc + ");";
                }
                else
                    sqlsc = sqlsc.Substring(0, sqlsc.Length - 1) + ");";

                ExecuteCommand(CreateCommand(sqlsc).ExecuteNonQuery);

                if (_last_error == 0)//--Если табличка успешно создана, то надо ее заполнить
                {
                    if (insert_method == DataInsertMethod.Normal)
                        InsertDataToDb(table, _parameters_prefix);
                    if (insert_method == DataInsertMethod.FastIfPossible)
                    {
                        BeginTransaction();
                        InsertDataToDb(table, _parameters_prefix);
                        CommitTransaction();
                    }
                }
            }
            else
            {
                if (MessagePrinter != null)
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.NotConnectedMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
            }
        }
        public override void CreateTable(DataTable table, DataInsertMethod insert_method, bool PrepareTableForInsert)
        {
            //insert_method = DataInsertMethod.Normal;
            if (Connected)
            {
                base.CreateTable(table, insert_method, PrepareTableForInsert);

                string sqlsc;
                sqlsc = "CREATE TABLE " + table.TableName + "(";
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    sqlsc += "\n" + table.Columns[i].ColumnName;
                    if (table.Columns[i].DataType.ToString().Contains("System.Int32") && !table.Columns[i].AutoIncrement)
                    {
                        sqlsc += " integer";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int32") && table.Columns[i].AutoIncrement)
                    {
                        sqlsc += " serial";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int64"))//--если будут ошибки, то заменить на bigint
                    {
                        sqlsc += " integer";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.DateTime"))
                    {
                        sqlsc += " date";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Decimal"))
                    {
                        sqlsc += " decimal";//--возможны ошибки
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.String"))
                    {
                        if (table.Columns[i].MaxLength <= 8000)
                        {
                            sqlsc += " varchar(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";
                        }
                        else
                        {
                            sqlsc += " text";
                        }
                    }

                    /*else if (table.Columns[i].DataType.ToString().Contains("System.Single"))
                     *  sqlsc += " single";*/
                    else if (table.Columns[i].DataType.ToString().Contains("System.Double"))
                    {
                        sqlsc += " real";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Guid"))
                    {
                        sqlsc += " UUID";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Boolean"))
                    {
                        sqlsc += " boolean";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Byte"))
                    {
                        sqlsc += " smallint";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int16"))
                    {
                        sqlsc += " smallint";
                    }
                    else
                    {
                        sqlsc += " varchar(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";
                    }


                    //if (table.Columns[i].AutoIncrement)//--будут проблемы....
                    //    sqlsc += " serial";// +table.Columns[i].AutoIncrementSeed.ToString() + "," + table.Columns[i].AutoIncrementStep.ToString() + ")";
                    if (!table.Columns[i].AllowDBNull)
                    {
                        sqlsc += " NOT NULL ";
                    }
                    if (table.Columns[i].DefaultValue != null && table.Columns[i].DefaultValue != DBNull.Value)
                    {
                        sqlsc += " DEFAULT " + table.Columns[i].DefaultValue.ToString();
                    }
                    sqlsc += ",";
                }

                if (table.PrimaryKey.Length > 0)
                {
                    string pks = "\nCONSTRAINT PK_" + table.TableName + " PRIMARY KEY (";
                    for (int i = 0; i < table.PrimaryKey.Length; i++)
                    {
                        pks += table.PrimaryKey[i].ColumnName + ",";
                    }
                    pks    = pks.Substring(0, pks.Length - 1) + ")";
                    sqlsc += pks;
                    sqlsc  = sqlsc + ");";
                }
                else
                {
                    sqlsc = sqlsc.Substring(0, sqlsc.Length - 1) + ");";
                }

                ExecuteCommand(CreateCommand(sqlsc).ExecuteNonQuery);

                if (_last_error == 0)//--Если табличка успешно создана, то надо ее заполнить
                {
                    if (insert_method == DataInsertMethod.Normal)
                    {
                        InsertDataToDb(table, _parameters_prefix, PrepareTableForInsert);
                    }
                    if (insert_method == DataInsertMethod.FastIfPossible)
                    {
                        BeginTransaction();
                        InsertDataToDbBulkMethod(table);
                        CommitTransaction();
                    }
                }
                else
                {
                    if (MessagePrinter != null)
                    {
                        MessagePrinter.PrintMessage(ErrorsManager.Messages.DBErrorMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
                    }
                }
            }
            else
            {
                if (MessagePrinter != null)
                {
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.NotConnectedMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
                }
            }
        }
        public override void CreateTable(DataTable table, DataInsertMethod insert_method)
        {
            if (Connected)
            {
                base.CreateTable(table, insert_method);

                string sqlsc;
                sqlsc = "CREATE TABLE " + table.TableName + "(";
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    sqlsc += "" + table.Columns[i].ColumnName;
                    if (table.Columns[i].DataType.ToString().Contains("System.Int32"))
                        sqlsc += " number";
                    else if (table.Columns[i].DataType.ToString().Contains("System.DateTime"))
                        sqlsc += " datetime";
                    else if (table.Columns[i].DataType.ToString().Contains("System.String"))
                        sqlsc += " varchar2(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";
                    /*else if (table.Columns[i].DataType.ToString().Contains("System.Single"))
                        sqlsc += " single ";*/
                    else if (table.Columns[i].DataType.ToString().Contains("System.Double"))
                        sqlsc += " float";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Guid"))
                        sqlsc += " raw(32)";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Boolean"))
                        sqlsc += " number(1)";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Byte"))
                        sqlsc += " number(1)";
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int16"))
                        sqlsc += " number";
                    else
                        sqlsc += " varchar2(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";

                    #warning Придумать как сделать создание сиквенцов и привязку триггера
                    /*if (table.Columns[i].AutoIncrement)
                        sqlsc += " IDENTITY(" + table.Columns[i].AutoIncrementSeed.ToString() + "," + table.Columns[i].AutoIncrementStep.ToString() + ") ";*/
                    if (!table.Columns[i].AllowDBNull)
                        sqlsc += " NOT NULL";
                    if (table.Columns[i].DefaultValue != null && table.Columns[i].DefaultValue != DBNull.Value)
                        sqlsc += " DEFAULT " + table.Columns[i].DefaultValue.ToString();
                    sqlsc += ",";
                }

                if (table.PrimaryKey.Length > 0)
                {
                    string pks = "CONSTRAINT PK_" + table.TableName + " PRIMARY KEY (";
                    for (int i = 0; i < table.PrimaryKey.Length; i++)
                    {
                        pks += table.PrimaryKey[i].ColumnName + ",";
                    }
                    pks = pks.Substring(0, pks.Length - 1) + ")";
                    sqlsc += pks;
                    sqlsc = sqlsc + ")";
                }
                else
                    sqlsc = sqlsc.Substring(0, sqlsc.Length - 1) + ");";

                ExecuteCommand(CreateCommand(sqlsc).ExecuteNonQuery);

                if (_last_error == 0)//--Если табличка успешно создана, то надо ее заполнить
                {
                    if (insert_method == DataInsertMethod.Normal)
                        InsertDataToDb(table, _parameters_prefix);
                    if (insert_method == DataInsertMethod.FastIfPossible)
                        InsertDataToDbBulkMethod(table);
                }
            }
            else
            {
                if (MessagePrinter != null)
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.NotConnectedMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
            }
        }
Exemple #8
0
        public override void CreateTable(DataTable table, DataInsertMethod insert_method, bool PrepareTableForInsert)
        {
            if (Connected)
            {
                base.CreateTable(table, insert_method, PrepareTableForInsert);

                string sqlsc;
                sqlsc = "CREATE TABLE " + table.TableName + "(";
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    sqlsc += "" + table.Columns[i].ColumnName;
                    if (table.Columns[i].DataType.ToString().Contains("System.Int32"))
                    {
                        sqlsc += " number";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.DateTime"))
                    {
                        sqlsc += " datetime";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.String"))
                    {
                        sqlsc += " varchar2(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";
                    }

                    /*else if (table.Columns[i].DataType.ToString().Contains("System.Single"))
                     *  sqlsc += " single ";*/
                    else if (table.Columns[i].DataType.ToString().Contains("System.Double"))
                    {
                        sqlsc += " float";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Guid"))
                    {
                        sqlsc += " raw(32)";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Boolean"))
                    {
                        sqlsc += " number(1)";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Byte"))
                    {
                        sqlsc += " number(1)";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int16"))
                    {
                        sqlsc += " number";
                    }
                    else
                    {
                        sqlsc += " varchar2(" + (table.Columns[i].MaxLength > -1 ? table.Columns[i].MaxLength.ToString() : "50") + ")";
                    }


                    #warning Придумать как сделать создание сиквенцов и привязку триггера

                    /*if (table.Columns[i].AutoIncrement)
                     *  sqlsc += " IDENTITY(" + table.Columns[i].AutoIncrementSeed.ToString() + "," + table.Columns[i].AutoIncrementStep.ToString() + ") ";*/
                    if (!table.Columns[i].AllowDBNull)
                    {
                        sqlsc += " NOT NULL";
                    }
                    if (table.Columns[i].DefaultValue != null && table.Columns[i].DefaultValue != DBNull.Value)
                    {
                        sqlsc += " DEFAULT " + table.Columns[i].DefaultValue.ToString();
                    }
                    sqlsc += ",";
                }

                if (table.PrimaryKey.Length > 0)
                {
                    string pks = "CONSTRAINT PK_" + table.TableName + " PRIMARY KEY (";
                    for (int i = 0; i < table.PrimaryKey.Length; i++)
                    {
                        pks += table.PrimaryKey[i].ColumnName + ",";
                    }
                    pks    = pks.Substring(0, pks.Length - 1) + ")";
                    sqlsc += pks;
                    sqlsc  = sqlsc + ")";
                }
                else
                {
                    sqlsc = sqlsc.Substring(0, sqlsc.Length - 1) + ");";
                }

                ExecuteCommand(CreateCommand(sqlsc).ExecuteNonQuery);

                if (_last_error == 0)//--Если табличка успешно создана, то надо ее заполнить
                {
                    if (insert_method == DataInsertMethod.Normal)
                    {
                        InsertDataToDb(table, _parameters_prefix, PrepareTableForInsert);
                    }
                    if (insert_method == DataInsertMethod.FastIfPossible)
                    {
                        InsertDataToDbBulkMethod(table);
                    }
                }
            }
            else
            {
                if (MessagePrinter != null)
                {
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.NotConnectedMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
                }
            }
        }
Exemple #9
0
        public virtual void CreateTable(DataTable table, DataInsertMethod insert_method)
        {
            if (string.IsNullOrEmpty(table.TableName))
            {
                if (MessagePrinter != null)
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.DatatableNameNotFoundMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);

                return;
            }

            if (table.Columns.Count <= 0)
            {
                if (MessagePrinter != null)
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.DatatableColumnsNotFoundMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);

                return;
            }
        }
Exemple #10
0
        public override void CreateTable(DataTable table, DataInsertMethod insert_method, bool PrepareTableForInsert)
        {
            if (Connected)
            {
                base.CreateTable(table, insert_method, PrepareTableForInsert);

                string sqlsc;
                sqlsc = "CREATE TABLE " + table.TableName + "(";
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    sqlsc += "\n" + table.Columns[i].ColumnName;
                    if (table.Columns[i].DataType.ToString().Contains("System.Int32"))
                    {
                        sqlsc += " integer";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.DateTime"))
                    {
                        sqlsc += " text";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.String"))
                    {
                        sqlsc += " text";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Single"))
                    {
                        sqlsc += " integer";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Double"))
                    {
                        sqlsc += " real";
                    }

                    /*else if (table.Columns[i].DataType.ToString().Contains("System.Double"))
                     *  sqlsc += " integer";*/
                    else if (table.Columns[i].DataType.ToString().Contains("System.Guid"))
                    {
                        sqlsc += " text";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Boolean"))
                    {
                        sqlsc += " integer";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Byte"))
                    {
                        sqlsc += " integer";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Int16"))
                    {
                        sqlsc += " integer";
                    }
                    else if (table.Columns[i].DataType.ToString().Contains("System.Byte[]"))
                    {
                        sqlsc += " blob";
                    }
                    else
                    {
                        sqlsc += " text";
                    }

                    /*if (table.Columns[i].AutoIncrement)
                     *  sqlsc += " AUTOINCREMENT(" + table.Columns[i].AutoIncrementSeed.ToString() + "," + table.Columns[i].AutoIncrementStep.ToString() + ")";*/
                    if (!table.Columns[i].AllowDBNull)
                    {
                        sqlsc += " NOT NULL";
                    }
                    if (table.Columns[i].DefaultValue != null && table.Columns[i].DefaultValue != DBNull.Value)
                    {
                        sqlsc += " DEFAULT " + table.Columns[i].DefaultValue.ToString();
                    }
                    sqlsc += ",";
                }

                if (table.PrimaryKey.Length > 0)
                {
                    string pks = "\nCONSTRAINT PK_" + table.TableName + " PRIMARY KEY (";
                    for (int i = 0; i < table.PrimaryKey.Length; i++)
                    {
                        pks += table.PrimaryKey[i].ColumnName + ",";
                    }
                    pks    = pks.Substring(0, pks.Length - 1) + ")";
                    sqlsc += pks;
                    sqlsc  = sqlsc + ")";
                }
                else
                {
                    sqlsc = sqlsc.Substring(0, sqlsc.Length - 1) + ");";
                }

                ExecuteCommand(CreateCommand(sqlsc).ExecuteNonQuery);

                if (_last_error == 0)//--Если табличка успешно создана, то надо ее заполнить
                {
                    if (insert_method == DataInsertMethod.Normal)
                    {
                        InsertDataToDb(table, _parameters_prefix, PrepareTableForInsert);
                    }
                    if (insert_method == DataInsertMethod.FastIfPossible)
                    {
                        BeginTransaction();
                        InsertDataToDb(table, _parameters_prefix, PrepareTableForInsert);
                        CommitTransaction();
                    }
                }
            }
            else
            {
                if (MessagePrinter != null)
                {
                    MessagePrinter.PrintMessage(ErrorsManager.Messages.NotConnectedMsg, ErrorsManager.Messages.ErrorMsg, 1, 1);
                }
            }
        }