public void ShowGrid()
 {
     ResultsetGrid = new ResultsetGrid();
     ResultsetGrid.DatabaseInfo = this.DatabaseInfo;
     ResultsetGrid.TableName = this.TableName;
     ResultsetGrid.ReadOnly = this.ReadOnly;
     ResultsetGrid.ReadOnlyColumns = this.ReadOnlyColumns;
     ResultsetGrid.SqlText = this.SqlText;
     this.winFormHost.Child = ResultsetGrid;
 }
示例#2
0
 public void ShowGrid()
 {
     ResultsetGrid = new ResultsetGrid();
     ResultsetGrid.DatabaseInfo    = this.DatabaseInfo;
     ResultsetGrid.TableName       = this.TableName;
     ResultsetGrid.ReadOnly        = this.ReadOnly;
     ResultsetGrid.ReadOnlyColumns = this.ReadOnlyColumns;
     ResultsetGrid.SqlText         = this.SqlText;
     this.winFormHost.Child        = ResultsetGrid;
 }
 public void ShowGrid()
 {
     ResultsetGrid = new ResultsetGrid
     {
         DatabaseInfo    = DatabaseInfo,
         TableName       = TableName,
         ReadOnly        = ReadOnly,
         ReadOnlyColumns = ReadOnlyColumns,
         SqlText         = SqlText
     };
     winFormHost.Child = ResultsetGrid;
 }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    ResultsetGrid?.Dispose();
                    winFormHost?.Dispose();
                }

                disposedValue = true;
            }
        }
        public void SpawnDataEditorWindow(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                var menuItem = sender as MenuItem;
                if (menuItem == null)
                    return;
                var menuInfo = menuItem.CommandParameter as MenuCommandParameters;
                if (menuInfo == null)
                    return;

                WindowsFormsHost wh = new WindowsFormsHost();
                ResultsetGrid rg = new ResultsetGrid();
                List<int> readOnlyColumns = new List<int>();

                using (IRepository repository = RepoHelper.CreateRepository(menuInfo.Connectionstring))
                {
                    System.Collections.Generic.List<PrimaryKey> pks = repository.GetAllPrimaryKeys();
                    var tpks = repository.GetAllPrimaryKeys().Where(pk => pk.TableName == menuInfo.Name).ToList();
                    if (tpks.Count == 0)
                    {
                        rg.ReadOnly = true;
                    }
                    List<Column> cols = repository.GetAllColumns();
                    cols = cols.Where(c => c.TableName == menuInfo.Name).ToList();
                    int x = 0;
                    foreach (Column col in cols)
                    {
                        if (col.AutoIncrementBy > 0 || col.RowGuidCol)
                        {
                            readOnlyColumns.Add(x);
                        }
                        x++;
                    }
                }
                var sqlText = string.Format(Environment.NewLine + "SELECT TOP({0}) * FROM [{1}]", Properties.Settings.Default.MaxRowsToEdit, menuInfo.Name);
                rg.TableName = sqlText;
                rg.ConnectionString = menuInfo.Connectionstring;
                rg.Tag = wh;
                rg.ReadOnlyColumns = readOnlyColumns;
                wh.Child = rg;
                
                string tabTitle = System.IO.Path.GetFileNameWithoutExtension(menuInfo.Caption) + "-" + menuInfo.Name + "-Edit";
                if (rg.ReadOnly)
                    tabTitle = System.IO.Path.GetFileNameWithoutExtension(menuInfo.Caption) + "-" + menuInfo.Name + "-ReadOnly";
                bool alreadyThere = false;
                int i = -1;
                foreach (var item in _parent.FabTab.Items)
                {
                    i++;
                    if (item is FabTabItem)
                    {
                        FabTabItem ftItem = (FabTabItem)item;
                        if (ftItem.Header.ToString() == tabTitle)
                        {
                            alreadyThere = true;
                        }
                    }
                }
                if (alreadyThere)
                {
                    _parent.FabTab.SelectedIndex = i;
                    _parent.FabTab.Focus();
                }
                else
                {
                    FabTabItem tab = new FabTabItem();
                    tab.Content = wh;
                    tab.Header = tabTitle;
                    _parent.FabTab.Items.Add(tab);
                    _parent.FabTab.SelectedIndex = _parent.FabTab.Items.Count - 1;
                    rg.Focus();
                }
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex));
            } 
        }