diff --git a/README.md b/README.md index 53b1ce5..f9b389b 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ Easy to use desktop SQL widget ![alt text](https://github.com/MoDevby/SQL-Widget/blob/master/Sql%20Widget/ScreenShots/1.JPG) ![alt text](https://github.com/MoDevby/SQL-Widget/blob/master/Sql%20Widget/ScreenShots/2.JPG) ![alt text](https://github.com/MoDevby/SQL-Widget/blob/master/Sql%20Widget/ScreenShots/3.JPG) +![alt text](https://github.com/MoDevby/SQL-Widget/blob/master/Sql%20Widget/ScreenShots/4.JPG) +![alt text](https://github.com/MoDevby/SQL-Widget/blob/master/Sql%20Widget/ScreenShots/5.JPG) +![alt text](https://github.com/MoDevby/SQL-Widget/blob/master/Sql%20Widget/ScreenShots/6.JPG) ### This Project is using the following open source libraries: * [MaterialDesignInXamlToolkit](https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit) under the MIT license. diff --git a/Sql Widget/Entities/ConditionElement.cs b/Sql Widget/Entities/ConditionElement.cs deleted file mode 100644 index 291734e..0000000 --- a/Sql Widget/Entities/ConditionElement.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Sql_Widget.Helper; - -namespace Sql_Widget.Entities -{ - class ConditionElement - { - public ConditionElement() - { - SelectedField = string.Empty; - SelectedOerator = 0; - Value = string.Empty; - } - public string SelectedField { get; set; } - public CompareOperators SelectedOerator { get; set; } - public string Value { get; set; } - public RelationOperators NextLineOperator{ get; set; } - } -} diff --git a/Sql Widget/Help.md b/Sql Widget/Help.md index fd10e6a..e747f1a 100644 --- a/Sql Widget/Help.md +++ b/Sql Widget/Help.md @@ -4,10 +4,6 @@ * F5: Execute. * Ctrl+Tab: Change the Tab. -## Select Tab: - * Ctrl+Right: Add selected fields to the select clause. - * Ctrl+Left: Remove selected fields from the select clause. - ## Result Page: * F5: Re-Execute. diff --git a/Sql Widget/Helper/Enums.cs b/Sql Widget/Helper/Enums.cs deleted file mode 100644 index ad37e6f..0000000 --- a/Sql Widget/Helper/Enums.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Sql_Widget.Helper -{ - public enum CompareOperators - { - Equal = 1, - NotEqual, - Greater, - Less, - GreaterOrEqual, - LessOrEqual, - Like - } - public enum RelationOperators - { - AND = 1, - OR - } - -} diff --git a/Sql Widget/Models/OperatorsModel.cs b/Sql Widget/Models/OperatorsModel.cs deleted file mode 100644 index a09c9d2..0000000 --- a/Sql Widget/Models/OperatorsModel.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Sql_Widget.Helper; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Sql_Widget.Models -{ - class OperatorsModel - { - public static Dictionary GetCompareOperators() - { - return new Dictionary - { - { CompareOperators.Equal , "=" }, - { CompareOperators.NotEqual, "<>" }, - { CompareOperators.Greater , ">" }, - { CompareOperators.Less , "<" }, - { CompareOperators.GreaterOrEqual , ">=" }, - { CompareOperators.LessOrEqual , "<=" }, - { CompareOperators.Like , "LIKE" }, - }; - } - - public static List GetReleationsOperators() - { - return Enum.GetValues(typeof(RelationOperators)).Cast().ToList(); - } - } -} diff --git a/Sql Widget/ScreenShots/0.JPG b/Sql Widget/ScreenShots/0.JPG index 4dc3357..90bb0d6 100644 Binary files a/Sql Widget/ScreenShots/0.JPG and b/Sql Widget/ScreenShots/0.JPG differ diff --git a/Sql Widget/ScreenShots/1.JPG b/Sql Widget/ScreenShots/1.JPG index a143727..bd3a91a 100644 Binary files a/Sql Widget/ScreenShots/1.JPG and b/Sql Widget/ScreenShots/1.JPG differ diff --git a/Sql Widget/ScreenShots/2.JPG b/Sql Widget/ScreenShots/2.JPG index 717651f..61242a2 100644 Binary files a/Sql Widget/ScreenShots/2.JPG and b/Sql Widget/ScreenShots/2.JPG differ diff --git a/Sql Widget/ScreenShots/3.JPG b/Sql Widget/ScreenShots/3.JPG index 71a8d98..c662775 100644 Binary files a/Sql Widget/ScreenShots/3.JPG and b/Sql Widget/ScreenShots/3.JPG differ diff --git a/Sql Widget/ScreenShots/4.JPG b/Sql Widget/ScreenShots/4.JPG new file mode 100644 index 0000000..80c569f Binary files /dev/null and b/Sql Widget/ScreenShots/4.JPG differ diff --git a/Sql Widget/ScreenShots/5.JPG b/Sql Widget/ScreenShots/5.JPG new file mode 100644 index 0000000..7877583 Binary files /dev/null and b/Sql Widget/ScreenShots/5.JPG differ diff --git a/Sql Widget/ScreenShots/6.JPG b/Sql Widget/ScreenShots/6.JPG new file mode 100644 index 0000000..da4ca4f Binary files /dev/null and b/Sql Widget/ScreenShots/6.JPG differ diff --git a/Sql Widget/Sql Widget.csproj b/Sql Widget/Sql Widget.csproj index 2d818db..8624617 100644 --- a/Sql Widget/Sql Widget.csproj +++ b/Sql Widget/Sql Widget.csproj @@ -86,21 +86,12 @@ HistoryControl.xaml - - SelectControl.xaml - ServerControl.xaml - - WhereControl.xaml - - - - @@ -123,18 +114,10 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile - - Designer - MSBuild:Compile - MSBuild:Compile Designer diff --git a/Sql Widget/ViewModels/MainWindowVM.cs b/Sql Widget/ViewModels/MainWindowVM.cs index ada8a31..0634188 100644 --- a/Sql Widget/ViewModels/MainWindowVM.cs +++ b/Sql Widget/ViewModels/MainWindowVM.cs @@ -18,8 +18,6 @@ class MainWindowVM : INotifyPropertyChanged #pragma warning disable 0067 public event PropertyChangedEventHandler PropertyChanged; #pragma warning restore 0067 - private string _selectedDB; - private string _selectedTable; private DBModel _dbModel = new DBModel(); #region Properties @@ -47,43 +45,16 @@ public bool UseWinAuth public string UserName { get; set; } #endregion #region DB + public string SelectedDB { get; set; } public List DBsList { get; set; } = new List(); - public List TablesList { get; set; } = new List(); - public string SelectedDB - { - get { return _selectedDB; } - set - { - _selectedDB = value; - AsyncUpdateTables(); - SelectedTable = null; - } - } - public string SelectedTable - { - get { return _selectedTable; } - set { _selectedTable = value; IntiateFields(); } - } - public bool SelectTablesIsEnabled => TablesList.Any(); - public List Fields { get; set; } = new List(); - public bool ComponentsEnabled => Fields.Count() > 1; #endregion #region Query public string QueryContent { get; set; } public string ExecutableQuery { get; set; } - public bool QueryEnabled => ValidConnection && !string.IsNullOrWhiteSpace(SelectedDB); - private bool IsValidExecutableQuery => !string.IsNullOrWhiteSpace(SelectedDB) && !string.IsNullOrWhiteSpace(ExecutableQuery); - #endregion - #region Select - public List VisibleFields => Fields.Where(x => !SelectedFields.Contains(x)).ToList(); - public List SelectedFields { get; set; } = new List(); - private bool IsValidSelect => SelectedFields.Any(); - #endregion - #region Where - public List WhereFields { get { return Fields.Where(a => a.Name != "*").ToList(); } } - public List Conditions { get; set; } = new List { new ConditionElement() }; - public Dictionary CompareOperators { get; set; } - public List RelationOperators { get; set; } + public bool CanExecute => ValidConnection && !string.IsNullOrWhiteSpace(SelectedDB) && + (!string.IsNullOrWhiteSpace(QueryContent) || SelectedTab.Header.ToString() != "Query"); + public bool IsValidExecutableQuery => ValidConnection && + !string.IsNullOrWhiteSpace(SelectedDB) && !string.IsNullOrWhiteSpace(ExecutableQuery); #endregion #region History public List HistoryItems { get; set; } = new List(); @@ -93,24 +64,14 @@ public string SelectedTable #region Methods public MainWindowVM() { - CompareOperators = OperatorsModel.GetCompareOperators(); - RelationOperators = OperatorsModel.GetReleationsOperators(); - VerfiyServer(); } - private async void IntiateFields() - { - SelectedFields = new List(); - Conditions = new List { new ConditionElement() }; - Fields = new List { new TableColumn { Name = "*", Position = 0, Type = "*" } } - .Concat(await TableColumnsModel.GetTableColumns(SelectedDB, SelectedTable)).ToList(); - } - private async void VerfiyServer() { ServerName = Properties.Settings.Default.Server; UserName = Properties.Settings.Default.UserName; + ServerMessage = "Connecting...."; if (await _dbModel.CheckConnection()) @@ -118,7 +79,6 @@ private async void VerfiyServer() ValidConnection = true; ServerMessage = "Connected!"; AsyncLoadDBs(); - IntiateFields(); } else { @@ -129,6 +89,8 @@ private async void VerfiyServer() private async void AsyncLoadDBs() { + SelectedDB = null; + _dbModel.InvalidateCache(); try { DBsList = await _dbModel.GetAllDBs(); @@ -141,59 +103,6 @@ private async void AsyncLoadDBs() } } - private async void AsyncUpdateTables() - { - if (!string.IsNullOrWhiteSpace(_selectedDB)) - try - { - TablesList = await TablesModel.GetAllTables(SelectedDB); - return; - } - catch (Exception) - { - ServerMessage = $"Error, Couldn't Load The Tables for {SelectedDB}!"; - ValidConnection = false; - } - TablesList = new List(); - } - - private string GetSelectQuery() - { - var Query = string.Empty; - if (IsValidSelect) - { - var fields = string.Join(", ", SelectedFields.Select(x => x.Name)); - Query = $"SELECT {fields}{Environment.NewLine}FROM {SelectedTable}"; - - var whereConditions = Conditions.Where(x => x.SelectedField != "" && x.SelectedOerator != 0); - Query += ConstructWhereClause(whereConditions); - } - return Query; - } - - private string ConstructWhereClause(IEnumerable whereConditions) - { - if (!whereConditions.Any()) return null; - var where = Environment.NewLine + "Where "; - var index = 0; - whereConditions.ToList().ForEach(condition => - { - where += condition.SelectedField + CompareOperators.First(x => x.Key == condition.SelectedOerator).Value; - where += IsStringType(condition.SelectedField) && condition.Value != "null" - ? string.IsNullOrEmpty(condition.Value) ? "" : $"'{condition.Value}'" - : string.IsNullOrWhiteSpace(condition.Value) ? "null" : condition.Value; - if (index < whereConditions.Count() - 1) - where += condition.NextLineOperator == 0 ? $" {RelationOperators.First()} " : $" {condition.NextLineOperator} "; - index++; - }); - return where; - } - private bool IsStringType(string fieldName) - { - var type = Fields.FirstOrDefault(x => x.Name == fieldName).Type; - return type.Contains("char") || type.Contains("uniqueidentifier") || type.Contains("date"); - } - private async void AddToHistory(string db, string query, ResultVM resultVm) { var historyItem = new HistoryItem @@ -237,24 +146,13 @@ public ICommand SaveServerCommand Properties.Settings.Default.UserName = UserName; Properties.Settings.Default.Password = (obj as PasswordBox).Password; Properties.Settings.Default.Save(); - ResetCacheCommand.Execute(""); + VerfiyServer(); }); } } #endregion #region DB Bar - public ICommand ResetCacheCommand - { - get - { - return new ButtonsCommand((object obj) => - { - SelectedDB = null; - _dbModel.InvalidateCache(); - VerfiyServer(); - }); - } - } + public ICommand HelpCommand { get @@ -285,53 +183,11 @@ public ICommand SelectDBCommand { return new ButtonsCommand((object obj) => { - var db = (string)obj; - SelectedDB = db; - }); - } - } - #endregion - #region Select - public ICommand AddFieldCommand - { - get - { - return new ButtonsCommand((object obj) => - { - var list = (ListBox)obj; - foreach (TableColumn item in list.SelectedItems) - { - SelectedFields.Add(item); - } - SelectedFields = new List(SelectedFields); - }); - } - } - public ICommand RemoveFieldCommand - { - get - { - return new ButtonsCommand((object obj) => - { - var list = (ListBox)obj; - foreach (TableColumn item in list.SelectedItems) - { - SelectedFields.Remove(item); - } - SelectedFields = new List(SelectedFields); - }); - } - } - #endregion - #region Where - public ICommand AddConditionCommand - { - get - { - return new ButtonsCommand((object obj) => - { - Conditions.Add(new ConditionElement()); - Conditions = new List(Conditions); + var comboBox = (ComboBox)obj; + + if (!DBsList.Contains(comboBox.Text)) + comboBox.Text = ""; + SelectedDB = comboBox.Text; }); } } @@ -348,9 +204,6 @@ public ICommand ExecuteCommand case "Query": ExecutableQuery = QueryContent; break; - case "SELECT": - ExecutableQuery = GetSelectQuery(); - break; case "History": ExecutableQuery = string.Join(";", HistoryItems.Where(x => x.Selected).Select(x => x.Query)); break; @@ -381,10 +234,6 @@ public ICommand ClearCommand case "Query": QueryContent = string.Empty; break; - case "SELECT": - SelectedFields = new List(); - Conditions = new List { new ConditionElement() }; - break; case "History": HistoryItems.ForEach(x => x.Selected = false); HistoryItems = new List(HistoryItems); diff --git a/Sql Widget/Views/Controls/DBandTableControl.xaml b/Sql Widget/Views/Controls/DBandTableControl.xaml index 3b36f42..807732f 100644 --- a/Sql Widget/Views/Controls/DBandTableControl.xaml +++ b/Sql Widget/Views/Controls/DBandTableControl.xaml @@ -7,48 +7,27 @@ - - - - + - - --> + - + - - - - - - - - - - - - - - + + - - - - - - diff --git a/Sql Widget/Views/Controls/SelectControl.xaml.cs b/Sql Widget/Views/Controls/SelectControl.xaml.cs deleted file mode 100644 index 47cb899..0000000 --- a/Sql Widget/Views/Controls/SelectControl.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Windows.Controls; - -namespace Sql_Widget.Views.Controls -{ - /// - /// Interaction logic for SelectControl.xaml - /// - public partial class SelectControl : UserControl - { - public SelectControl() - { - InitializeComponent(); - } - } -} diff --git a/Sql Widget/Views/Controls/WhereControl.xaml b/Sql Widget/Views/Controls/WhereControl.xaml deleted file mode 100644 index 33e639e..0000000 --- a/Sql Widget/Views/Controls/WhereControl.xaml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Sql Widget/Views/Controls/WhereControl.xaml.cs b/Sql Widget/Views/Controls/WhereControl.xaml.cs deleted file mode 100644 index 1b80382..0000000 --- a/Sql Widget/Views/Controls/WhereControl.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Windows.Controls; - -namespace Sql_Widget.Views.Controls -{ - /// - /// Interaction logic for WhereControl.xaml - /// - public partial class WhereControl : UserControl - { - public WhereControl() - { - InitializeComponent(); - } - } -} diff --git a/Sql Widget/Views/MainWindow.xaml b/Sql Widget/Views/MainWindow.xaml index adc2d7d..2a5af72 100644 --- a/Sql Widget/Views/MainWindow.xaml +++ b/Sql Widget/Views/MainWindow.xaml @@ -43,15 +43,6 @@ HorizontalAlignment="Stretch" TextWrapping="Wrap" AcceptsReturn="True" Foreground="{DynamicResource MaterialDesignBody}"/> - - - - - - - @@ -66,7 +57,7 @@