private void SetCommand()
        {
            AddBasePath = new RelayCommand(() =>
            {
                using (var dlg = new FolderBrowserDialog())
                {
                    if (dlg.ShowDialog() != DialogResult.OK) return;
                    foreach (var item in QueryProjectViewModel.GetData(dlg.SelectedPath))
                    {
                        _vm.Add(item);
                        AppSettingsManager.QueryProjectBasePaths.Add(item.FullPath);
                    }
                }
            });

            DeletePath = new RelayCommand(() =>
            {
                if (SelectedItem == null) return;
                AppSettingsManager.QueryProjectBasePaths.Remove(SelectedItem.FullPath);
                _vm.Remove(SelectedItem);
            });

            CloseWindow = new RelayCommand(() =>
            {
                MessengerInstance.Send(new MessageBase(this, "WindowClose"));
            });
        }
 public QueryTabViewModel(string header, string query)
 {
     _header = header;
     _query = query;
     LoadQuery = new RelayCommand(() => LoadQueryMethod());
     GivingNameSave = new RelayCommand(() => GivingNameSaveMethod());
     OverwriteSave = new RelayCommand(() => OverwriteSaveMethod());
     DropFile = new RelayCommand<string>(path =>
     {
         _loadPath = path;
         Query = FileLoad(_loadPath, _fileEncoding);
     });
 }
 private void SetCommand()
 {
     ReloadDatabase = new RelayCommand(async () => await Reload());
     ChangeSystemTables = new RelayCommand<bool>(async (b) =>
     {
         if (b)
         {
             await LoadSystemTables(DbInfo);
         }
         else
         {
             foreach (var table in Tables.Where(x => (x is TableViewModel) && ((TableViewModel)x).IsSystemTable).ToArray())
             {
                 Tables.Remove(table);
             }
             CollectionViewSource.GetDefaultView(Tables).Refresh();
             RaisePropertyChanged(nameof(Tables));
         }
     });
 }
 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 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);
            });
        }