Пример #1
0
        async Task ImportFileIntoLocalDB(string filePath, ImportedFileType fileType)
        {
            readerModelCommon = new FileReaderModels();

            ISQLConnectionSettings newConnection = new SQLConnectionSettings
            {
                Database = $"{Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath))}.db"
            };

            dBOperations = new SQLiteModelDBOperations(newConnection);
            dBOperations.EvntInfoMessage += new SqlAbstractConnector.Message <TextEventArgs>(AddLineAtTextBoxResultShow);

            SetAdminStatusLabelText($"Импорт файла '{filePath}' в базу данных...");
            AddLineAtTextBoxResultShow();

            readerModelCommon.EvntInfoMessage    += new FileReaderModels.Message <TextEventArgs>(AddLineAtTextBoxResultShow);
            readerModelCommon.EvntHeaderReady    += new FileReaderModels.CollectionFull <BoolEventArgs>(ModelCommon_EvntHeaderReady);
            readerModelCommon.EvntCollectionFull += new FileReaderModels.CollectionFull <BoolEventArgs>(ModelCommon_collectionFull);

            await readerModelCommon.SelectImportingMethod(filePath, fileType, MAX_ELEMENTS_COLLECTION);

            readerModelCommon.EvntCollectionFull -= ModelCommon_collectionFull;
            readerModelCommon.EvntHeaderReady    -= ModelCommon_EvntHeaderReady;
            readerModelCommon.EvntInfoMessage    -= AddLineAtTextBoxResultShow;

            SetAdminStatusLabelText($"Всего в БД '{newConnection.Database}' импортировано {readerModelCommon.importedRows} строк.");
            AddLineAtTextBoxResultShow("newConnection: " + newConnection.ToString());
            dBOperations.EvntInfoMessage -= AddLineAtTextBoxResultShow;

            readerModelCommon = null;
            AddLineAtTextBoxResultShow();

            currentSQLConnectionStore.Set(newConnection);
            currentSQLConnectionStore.Refresh();
        }
Пример #2
0
        private void CurrentSQLConnectionStore_EvntConfigChanged(object sender, BoolEventArgs args)
        {
            ISQLConnectionSettings oldSettings = currentSQLConnectionStore?.GetPrevious();
            ISQLConnectionSettings newSettings = currentSQLConnectionStore?.GetCurrent();

            if (!(string.IsNullOrWhiteSpace(newSettings?.Database)) && File.Exists(newSettings?.Database))
            {
                try { dBOperations.EvntInfoMessage -= AddLineAtTextBoxResultShow; } catch { }
                dBOperations = SQLSelector.SetConnector(newSettings);
                dBOperations.EvntInfoMessage += new SqlAbstractConnector.Message <TextEventArgs>(AddLineAtTextBoxResultShow);
            }

            if (oldSettings == null)
            {
                tableStore.Set(SQLSelector.GetTables(newSettings));
            }
            else
            {
                if (oldSettings.Name != newSettings.Name && oldSettings.Database != newSettings.Database)
                {
                    tableStore.Set(SQLSelector.GetTables(newSettings));
                }
            }

            if (!string.IsNullOrWhiteSpace(newSettings?.Database) && !string.IsNullOrWhiteSpace(newSettings?.Table))
            {
                SetAdminStatusLabelText($"Текущая база: {newSettings?.Database}, таблица: {newSettings?.Table}");
            }
        }
Пример #3
0
        /// <summary>
        /// will return current SQL Connector was connected to MS SQL or My SQL or SQLite DB
        /// </summary>
        /// <param name="settings">ISQLConnectionSettings</param>
        public static SqlAbstractConnector SetConnector(ISQLConnectionSettings settings)
        {
            SqlAbstractConnector sqlConnector = null;

            switch (settings.ProviderName)
            {
            case SQLProvider.SQLite:
            {
                sqlConnector = new SQLiteModelDBOperations(settings);
                break;
            }

            case SQLProvider.My_SQL:
            {
                sqlConnector = new MySQLUtils(settings);
                break;
            }

            case SQLProvider.MS_SQL:
            {
                sqlConnector = new MsSqlUtils(settings);
                break;
            }
            }
            return(sqlConnector);
        }
Пример #4
0
        public static DataTableStore GetDataTableStore(ISQLConnectionSettings tmpSettings, string query)
        {
            SqlAbstractConnector sqlConnector = SetConnector(tmpSettings);

            sqlConnector.EvntInfoMessage += SqlConnector_EvntInfoMessage;

            DataTableStore dataTableStore = GetDataTableStore(sqlConnector, query);

            sqlConnector.EvntInfoMessage -= SqlConnector_EvntInfoMessage;
            return(dataTableStore);
        }
Пример #5
0
        static DataTableStore GetDataTableStore(SqlAbstractConnector sqlConnector, string query)
        {
            DataTableStore data = new DataTableStore();

            try
            {
                using DataTable dt = sqlConnector.GetTable(query);
                data.Set(dt);
                dt?.Dispose();
            }
            catch (Exception err) { data.Errors = $"{err.Message}{Environment.NewLine}{message}"; }

            return(data);
        }
Пример #6
0
        static ModelCommonStringStore GetListForModelStore(SqlAbstractConnector sqlConnector, string query)
        {
            ModelCommonStringStore models = new ModelCommonStringStore();
            IModel model;

            try
            {
                using DataTable dt = sqlConnector.GetTable(query);
                foreach (DataRow r in dt?.Rows)
                {
                    model = new ModelCommon
                    {
                        Name  = r[0].ToString(),
                        Alias = r[0].ToString()
                    };
                    models.Add(model);
                }
                dt?.Dispose();
            }
            catch { }

            return(models);
        }