Exemplo n.º 1
0
        /// <summary>
        /// 清除所有缓存
        /// </summary>
        public override void Clear()
        {
            try
            {
                lock (lockObj)
                {
                    DBSchema.Clear();
                    TableSchema.Clear();

                    theCache.Clear();
                    theTime.Clear();
                    theFileName.Clear();
                    theKeyTime.Clear();
                    for (int i = 0; i < theFolderWatcher.Count; i++)
                    {
                        theFolderWatcher[i].Changed -= new FileSystemEventHandler(fsy_Changed);
                        theFolderWatcher[i]          = null;
                    }
                    theFolderWatcher.Clear();
                    theFolderKeys.Clear();
                    if (!string.IsNullOrEmpty(AppConfig.DB.SchemaMapPath))
                    {
                        if (Directory.Exists(AppConfig.RunPath + AppConfig.DB.SchemaMapPath))
                        {
                            Directory.Delete(AppConfig.RunPath + AppConfig.DB.SchemaMapPath, true);
                        }
                    }
                }
            }
            catch
            {
                errorCount++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 清除所有缓存
        /// </summary>
        public override void Clear()
        {
            try
            {
                lock (lockObj)
                {
                    DBSchema.Clear();
                    TableSchema.Clear();

                    theCache.Clear();
                    theTime.Clear();
                    theFileName.Clear();
                    theKeyTime.Clear();
                    for (int i = 0; i < theFolderWatcher.Count; i++)
                    {
                        theFolderWatcher[i].Changed -= new FileSystemEventHandler(fsy_Changed);
                        theFolderWatcher[i]          = null;
                    }
                    theFolderWatcher.Clear();
                    theFolderKeys.Clear();
                }
            }
            catch
            {
                errorCount++;
            }
        }
Exemplo n.º 3
0
        private bool LoadDBSchema()
        {
            try
            {
                SetSchemaFileName("");
                SetSchemaModified(false);

                _tableSchema.Clear();

                using (SqlConnection connection = new SqlConnection(GetConnectionString(_databaseName)))
                {
                    connection.Open();
                    //Forms.Form1.DoIt(connection);

                    DataTable table = connection.GetSchema("Tables");

                    foreach (DataRow row in table.Rows)
                    {
                        string tableName = (string)row["TABLE_NAME"];
                        TableSchema.TableNamesRow tableNameRow = _tableSchema.TableNames.NewTableNamesRow();
                        tableNameRow.TableName = tableName;
                        tableNameRow.Include   = false;
                        string collection = tableName;
                        string item       = tableName;
                        if (tableName.Substring(tableName.Length - 3, 3) == "ies")
                        {
                            item = tableName.Remove(tableName.Length - 3, 3) + "y";
                        }
                        else if (tableName.Substring(tableName.Length - 2, 2) == "es")
                        {
                            //collection = tableName + "Collection";
                            item = tableName.Remove(tableName.Length - 2, 2);
                        }
                        else if (tableName.Substring(tableName.Length - 1, 1) == "s")
                        {
                            item = tableName.Remove(tableName.Length - 1, 1);
                        }
                        else
                        {
                            item = item + "Item";
                        }

                        tableNameRow.ItemName            = item;
                        tableNameRow.CollectionName      = tableName;
                        tableNameRow.BaseCollectionClass = AppSettings.Default.BaseCollectionClass;
                        tableNameRow.BaseItemClass       = AppSettings.Default.BaseItemClass;
                        tableNameRow.IsDBReadOnly        = false;
                        _tableSchema.TableNames.AddTableNamesRow(tableNameRow);

                        LoadTableSchema(tableName, connection);
                    }

                    tableNamesBindingSource.DataSource = _tableSchema;
                    tableNamesBindingSource.DataMember = "TableNames";
                    tableNamesBindingSource.Sort       = "TableName";
                    fieldsBindingSource.DataSource     = _tableSchema;
                    fieldsBindingSource.DataMember     = "Fields";
                    gridFields.AutoGenerateColumns     = true;
                    gridFields.Columns[0].Visible      = false;
                    gridTables.AutoGenerateColumns     = true;

                    connection.Close();

                    gridFields.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);

                    foreach (DataGridViewColumn column in gridFields.Columns)
                    {
                        if (column.ReadOnly)
                        {
                            column.DefaultCellStyle.BackColor = SystemColors.GradientInactiveCaption;
                        }
                    }
                }
                SetSchemaModified(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to retrieve the database schema.\n\n" + ex.Message);
                return(false);
            }
            return(true);
        }