Inheritance: FAManagementStudio.Common.BindableBase
 public async Task LoadSystemTables(DatabaseInfo dbInf)
 {
     _dbInfo = dbInf;
     var table = new List<ITableViewModel>();
     await Task.Run(() =>
     {
         using (var con = new FbConnection(_dbInfo.ConnectionString))
         {
             con.Open();
             foreach (var item in _dbInfo.GetSystemTables(con))
             {
                 var vm = new TableViewModel(item.TableName, true);
                 foreach (var colums in item.GetColums(con))
                 {
                     vm.Colums.Add(new ColumViewMoodel(colums));
                 }
                 table.Add(vm);
             }
         }
     });
     Tables.AddRange(table);
     CollectionViewSource.GetDefaultView(Tables).Refresh();
     RaisePropertyChanged(nameof(Tables));
 }
        public async Task LoadDatabase(DatabaseInfo dbInf)
        {
            _dbInfo = dbInf;
            var table = new List<ITableViewModel>();
            await Task.Run(() =>
             {
                 using (var con = new FbConnection(_dbInfo.ConnectionString))
                 {
                     con.Open();
                     foreach (var item in _dbInfo.GetTables(con))
                     {
                         var vm = new TableViewModel(item.TableName);
                         foreach (var colums in item.GetColums(con))
                         {
                             vm.Colums.Add(new ColumViewMoodel(colums));
                         }
                         foreach (var trigger in item.GetTrigger(con))
                         {
                             vm.Triggers.Add(new TriggerViewModel(trigger));
                         }
                         foreach (var idx in item.GetIndex(con))
                         {
                             vm.Indexs.Add(new IndexViewModel(idx));
                         }
                         table.Add(vm);
                     }

                     foreach (var item in _dbInfo.GetViews(con))
                     {
                         var vm = new TableViewViewModel(item.ViewName, item.Source);
                         foreach (var colums in item.GetColums(con))
                         {
                             vm.Colums.Add(new ColumViewMoodel(colums));
                         }
                         table.Add(vm);
                     }
                 }
             });
            Tables = table;
            AdditionalInfo = new AdditionalDbInfoControl(this);
            RaisePropertyChanged(nameof(Tables));
            RaisePropertyChanged(nameof(AdditionalInfo));
        }
 public ConnectionSettingsViewModel(DatabaseInfo inf)
 {
     _inf = inf;
     Init();
     OkCommand = new RelayCommand(() =>
     {
         var properties = _inf.Builder.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
         foreach (var item in NotInputList.Where(x => x.Value != null).Union(InputedList))
         {
             _inf.Builder[_synonyms[item.Name]] = item.Value;
         }
         MessengerInstance.Send(new MessageBase(this, "WindowClose"));
     });
 }
 public async Task CreateDatabase(string path, FirebirdType type, FbCharset charset)
 {
     var dbInfo = new DatabaseInfo(new FirebirdInfo(path, type, charset));
     dbInfo.CreateDatabase();
     await LoadDatabase(dbInfo);
 }
        public void SetCommand()
        {
            CreateDatabase = new RelayCommand(async () =>
            {
                var vm = new NewDatabaseSettingsViewModel();
                MessengerInstance.Send(new MessageBase(vm, "NewDbSettingsWindowOpen"));

                if (string.IsNullOrEmpty(vm.Path)) return;

                var db = new DbViewModel();
                await db.CreateDatabase(vm.Path, vm.Type, vm.CharSet);
                Databases.Add(db);
                _history.DataAdd(vm.Path);
            });

            LoadDatabase = new RelayCommand<string>(async (path) =>
            {
                if (string.IsNullOrEmpty(path)) return;
                if (!File.Exists(path)) return;

                var dbInf = new DatabaseInfo(new FirebirdInfo(path));
                if (!dbInf.CanLoadDatabase) return;

                var db = new DbViewModel();
                Databases.Add(db);
                await db.LoadDatabase(dbInf);
                _history.DataAdd(path);
            });

            ExecuteQuery = new RelayCommand(async () =>
           {
               if (CurrentDatabase == null || !CurrentDatabase.CanExecute()) return;
               if (TagSelectedValue.IsNewResult && 0 < Datasource[0].Result.Count) Datasource[0].Pined = true;
               var QueryResult = Datasource[0];
               QueryResult.Result.Clear();
               await Task.Run(() =>
               {
                   var inf = new QueryInfo { ShowExecutePlan = TagSelectedValue.IsShowExecutionPlan };
                   QueryResult.GetExecuteResult(inf, CurrentDatabase.ConnectionString, TagSelectedValue.Query);
               });
           });

            DropFile = new RelayCommand<string>((string path) =>
            {
                InputPath = path;
                RaisePropertyChanged(nameof(InputPath));
            });

            DbListDropFile = new RelayCommand<string>((string path) =>
            {
                LoadDatabase.Execute(path);
            });

            SetSqlTemplate = new RelayCommand<SqlKind>((SqlKind sqlKind) =>
            {
                TagSelectedValue.Query = CreateSqlSentence(SelectedTableItem, sqlKind);
                RaisePropertyChanged(nameof(Queries));
            });

            ExecLimitedSql = new RelayCommand<string>((count) =>
            {
                TagSelectedValue.Query = CreateSqlSentence(SelectedTableItem, SqlKind.Select, int.Parse(count));
                RaisePropertyChanged(nameof(Queries));
                ExecuteQuery.Execute(null);
            });

            ExecSqlTemplate = new RelayCommand<SqlKind>((SqlKind sqlKind) =>
            {
                SetSqlTemplate.Execute(sqlKind);
                ExecuteQuery.Execute(null);
            });

            ShutdownDatabase = new RelayCommand(() => { Databases.Remove(CurrentDatabase); });

            ChangeConfig = new RelayCommand(() =>
            {
                if (CurrentDatabase == null) return;
                var vm = new ConnectionSettingsViewModel(CurrentDatabase.DbInfo);
                MessengerInstance.Send(new MessageBase(vm, "WindowOpen"));
            });

            ShowEntity = new RelayCommand(() =>
            {
                if (CurrentDatabase == null) return;
                var vm = new EntityRelationshipViewModel(CurrentDatabase);
                MessengerInstance.Send(new MessageBase(vm, "EintityWindowOpen"));
            });

            AddTab = new RelayCommand(() =>
            {
                TagSelectedValue.Header = $"Query{Queries.Count}";
                Queries.Add(QueryTabViewModel.GetNewInstance());
                RaisePropertyChanged(nameof(Queries));
            });

            DeleteTabItem = new RelayCommand(() =>
            {
                var item = TagSelectedValue;
                var idx = Queries.IndexOf(item);
                TagSelectedIndex = idx - 1;
                RaisePropertyChanged(nameof(TagSelectedIndex));
                Queries.Remove(item);
            });

            LoadHistry = new RelayCommand(() => _history.LoadData(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)));

            SaveHistry = new RelayCommand(() => _history.SaveData(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)));

            OpenGitPage = new RelayCommand(() => System.Diagnostics.Process.Start("https://github.com/degarashi0913/FAManagementStudio"));

            PinedCommand = new RelayCommand(() =>
            {
                Datasource[0].Header = $"Pin{Datasource.Count}";
                Datasource.Insert(0, new QueryResultViewModel("Result"));
                SelectedResultIndex = 0;
                RaisePropertyChanged(nameof(SelectedResultIndex));
            }, () => 0 < Datasource[0].Result.Count);

            ReleasePinCommand = new RelayCommand<QueryResultViewModel>((data) =>
            {
                Datasource.Remove(data);
            });

            SetSqlDataTemplate = new RelayCommand<string>((s) =>
            {
                var table = GetTreeViewTableName(CurrentDatabase, SelectedTableItem);
                var result = "";
                if (s == "table")
                {
                    result = table.GetDdl(CurrentDatabase);
                }
                else if (s == "insert")
                {
                    if (table is TableViewViewModel) return;
                    var colums = table.Colums.Select(x => x.ColumName).ToArray();
                    var escapedColumsStr = string.Join(", ", colums.Select(x => EscapeKeyWord(x)).ToArray());

                    var insertTemplate = $"insert into {table.TableName} ({escapedColumsStr})";

                    var qry = new QueryInfo();
                    var res = qry.ExecuteQuery(CurrentDatabase.ConnectionString, CreateSelectStatement(table.TableName, colums, 0)).First();

                    var sb = new StringBuilder();

                    foreach (DataRow row in res.View.Rows)
                    {
                        sb.Append(insertTemplate + " values(");
                        sb.Append(string.Join(", ", row.ItemArray.Select(x => x.GetType() == typeof(string) ? $"\'{x}\'" : $"{x}").ToArray()));
                        sb.AppendLine(");");
                    }
                    result = sb.ToString();
                }

                var idx = Queries.IndexOf(TagSelectedValue);
                Queries[idx].Query = result;
                RaisePropertyChanged(nameof(Queries));
            });

            ShowPathSettings = new RelayCommand(() =>
            {
                var vm = new BasePathSettingsViewModel(QueryProjects);
                MessengerInstance.Send(new MessageBase(vm, "BasePathSettingsWindowOpen"));
            });

            ProjectItemOpen = new RelayCommand<object>((obj) =>
            {
                var item = obj as QueryProjectFileViewModel;
                if (item == null) return;
                var idx = Queries.IndexOf(TagSelectedValue);
                try
                {
                    Queries[idx].Header = Path.GetFileNameWithoutExtension(item.FullPath);
                    Queries[idx].Query = Queries[idx].FileLoad(item.FullPath, Encoding.UTF8);
                }
                catch (IOException) { }
            });
            ProjectItemDrop = new RelayCommand<string>((string path) =>
            {
                QueryProjects.Add(QueryProjectViewModel.GetData(path).First());
                AppSettingsManager.QueryProjectBasePaths.Add(path);
            });
        }