Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImportTableViewForm"/> class.
        /// </summary>
        /// <param name="importDbTableOrView">MySQL table or view from which to import data to an Excel spreadsheet.</param>
        /// <param name="importToWorksheetName">Name of the Excel worksheet where the data will be imported to.</param>
        public ImportTableViewForm(DbView importDbTableOrView, string importToWorksheetName)
        {
            if (importDbTableOrView == null)
            {
                throw new ArgumentNullException("importDbTableOrView");
            }

            _dbTableOrView              = importDbTableOrView;
            _importColumns              = null;
            _previewDataTable           = null;
            MySqlTable                  = null;
            _activeWorkbookMaxRowNumber = Globals.ThisAddIn.ActiveWorkbook.GetWorkbookMaxRowNumber();
            var atCell = Globals.ThisAddIn.Application.ActiveCell;

            _atRow = atCell == null ? 1 : atCell.Row;
            InitializeComponent();

            PreviewDataGridView.DataError += PreviewDataGridView_DataError;
            TableNameMainLabel.Text        = importDbTableOrView is DbTable ? "Table Name" : "View Name";
            PickColumnsSubLabel.Text       = string.Format(Resources.ImportTableOrViewSubText, importDbTableOrView is DbTable ? "table" : "view");
            OptionsWarningLabel.Text       = Resources.ImportDataWillBeTruncatedWarning;
            Text = @"Import Data - " + importToWorksheetName;
            TableNameSubLabel.Text = importDbTableOrView.Name;
            FillPreviewGrid();
            InitializeOptions();
        }
Exemple #2
0
        private void MRenderCtrl_Load(object sender, EventArgs e)
        {
            mDocument = new Document();
            mDbView   = mDocument.Initialize("3D");

            mRootSceneNode = new DocumentSceneNode(mDocument);
            mRenderCtrl.ShowSceneNode(mRootSceneNode);

            mContext = new UICommandContext(this);

            mDocument.EnableTransaction(false);
            var material = new MaterialElement();

            material.SetName("Default");
            mMaterialId = mDocument.AddElement(material);

            mDocument.EnableTransaction(true);

            mRenderCtrl.SetSelectCallback((PickedItem item) =>
            {
                var node      = item.GetNode();
                var elementId = node == null ? ElementId.InvalidId : new ElementId(node.GetUserId());
                mSelectionCallback(item, mDocument, elementId);
            });
        }
Exemple #3
0
        public DataSeedViews(DataSeedTestContext db = null)
        {
            DbOwned = db == null;
            Db      = db ?? new DataSeedTestContext();

            var builder = Db.ViewBuilder();

            // Set up views
            Departments = builder.View(d => db.Departments);
            Classes     = builder.View(d => db.Classes);
            Schools     = builder.View(d => db.Schools);
            Students    = builder.View(d => db.Students);

            ScienceDept = Departments.View(depts =>
                                           from d in depts
                                           where d.Name == "Science"
                                           select d
                                           );

            ScienceStudents = ScienceDept.View(depts =>
                                               (
                                                   from d in depts
                                                   join c in Db.Classes on d.Id equals c.DepartmentId
                                                   select c
                                               ).SelectMany(c => c.Students)
                                               );
        }
        /// <summary>
        /// Reads views schema from database
        /// </summary>
        private List <DbView> ReadViews()
        {
            List <DbView> result = new List <DbView>();

            string[] restrictions = null;
            if (!string.IsNullOrWhiteSpace(this.SpecificOwner))
            {
                restrictions = new string[] { SpecificOwner.ToUpper() };
            }

            using (DataTable views = _dbConnection.GetSchema("Views", restrictions)) {
                foreach (DataRow row in views.Rows)
                {
                    string viewName = row["VIEW_NAME"].ToString();

                    if (!IsViewSelected(viewName))
                    {
                        continue;
                    }

                    // View columns
                    List <DbColumn> columns = ReadColumns(viewName);

                    // new view
                    var view = new DbView(viewName, columns);

                    // view schema
                    view.OwnerName = row["OWNER"].ToString();

                    // add to results
                    result.Add(view);
                }
            }
            return(result);
        }
Exemple #5
0
        }//End DataEnteredCorrectly.

        /// <summary>
        /// Processes the result of the player's confirmation of registration.
        /// Adds the player to the database if needed.
        /// </summary>
        /// <param name="p">The Player object that holds the player's details.</param>
        /// <param name="submit">The button result.  Determines if the player gets added to the database.</param>
        /// <returns>the Index view.</returns>
        public ActionResult ConfirmProcess(Player p, string submit)
        {
            //Error checking to prevent the player being re-entered into the database
            //when the user clicks on refresh after submission
            bool playerInDb = PlayerAlreadyInDb(p.Name, p.EmailAddress);

            //Check if they clicked the submit button...
            if (submit.CompareTo(BTN_SUBMIT_STRING) == 0 && !playerInDb)
            {
                //if they did, add the user to the database.
                raceDb.Players.Add(p);
                raceDb.SaveChanges();

                //Get the player's primary key and use that to randomly assign the horse's
                //the player bets on.
                int playerID = GetPlayerID(p);
                SelectRandomHorses(playerID, p.TotalBets);
            }

            ProcessIndex();
            //Get the database view and the bets select item list.
            DbView dbView = GetDbView();


            return(View(VIEW_INDEX, dbView));
        }//End ConfirmProcess
Exemple #6
0
        public void ResetDocument(Document doc)
        {
            mDocument = doc;
            mRootSceneNode.SetDocument(mDocument);
            mDbView = DbView.Cast(mDocument.FindElement(mDocument.GetActiveDbViewId()));

            mContext.RequestUpdate();
            mRenderCtrl.ZoomAll(0.8f);
        }
Exemple #7
0
        public override void TestSetup()
        {
            var testDb = new DataSeedTestContext(Db.Database.Connection);

            testDb.Database.UseTransaction(Db.Database.CurrentTransaction.UnderlyingTransaction);
            var builder = testDb.ViewBuilder();

            ProtectedEntities = builder.View(db => db.Protected);
        }
Exemple #8
0
        public ActionResult Index()
        {
            //Get the total Prize pool.
            ViewBag.PrizePool =
                GetHorseTable().FindAll(h => h.PlayerID != null).Count() * BET_SIZE;

            DbView dbView = GetDbView();

            return(View(dbView));
        }//End Index
Exemple #9
0
        public ActionResult Index()
        {
            //Get a view of the database (all data from all tables).
            DbView dbView = GetDbView();

            ProcessIndex();

            //Return the Index view with the database view model
            return(View(dbView));
        }//End HttpGet Index.
Exemple #10
0
 /// <summary>
 /// Sets the import parameter values into the given database object.
 /// This is needed before getting any data from it.
 /// </summary>
 private void SetImportParameterValues(DbView dbTableOrView)
 {
     dbTableOrView.ImportParameters.AddSummaryRow        = AddSummaryFieldsCheckBox.Checked;
     dbTableOrView.ImportParameters.ColumnsNamesList     = null;
     dbTableOrView.ImportParameters.CreatePivotTable     = CreatePivotTableCheckBox.Checked && PivotTablesComboBox.SelectedIndex == 1;
     dbTableOrView.ImportParameters.FirstRowIndex        = -1;
     dbTableOrView.ImportParameters.ForEditDataOperation = false;
     dbTableOrView.ImportParameters.IncludeColumnNames   = true;
     dbTableOrView.ImportParameters.IntoNewWorksheet     = true;
     dbTableOrView.ImportParameters.RowsCount            = -1;
 }
Exemple #11
0
        internal UserFormService(BusinessContext context)
        {
            this.Context = context;

            var db      = Context.Db;
            var builder = db.ViewBuilder();

            // Build views
            this.ActiveForms = builder.View(d =>
                                            from form in db.UserForms
                                            where form.IsActive
                                            select form);
        }
Exemple #12
0
 public bool TryGetDbView(RdbDescriptor db, string dbViewId, out DbView dbView)
 {
     if (!_initialized)
     {
         Init();
     }
     if (!_dicById.ContainsKey(db))
     {
         dbView = null;
         return false;
     }
     return _dicById[db].TryGetValue(dbViewId, out dbView);
 }
Exemple #13
0
 public bool TryGetDbView(RdbDescriptor db, string dbViewId, out DbView dbView)
 {
     if (!_initialized)
     {
         Init();
     }
     if (!_dicById.ContainsKey(db))
     {
         dbView = null;
         return(false);
     }
     return(_dicById[db].TryGetValue(dbViewId, out dbView));
 }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PreviewTableViewDialog"/> class.
        /// </summary>
        /// <param name="previewTableOrView">The type of DB object (MySQL table or view) to preview data for.</param>
        /// <param name="showCancelButton">Flag indicating whether the Cancel button is shown along with the OK one, or hidden.</param>
        public PreviewTableViewDialog(DbView previewTableOrView, bool showCancelButton)
        {
            _previewTableOrView = previewTableOrView ?? throw new ArgumentNullException(nameof(previewTableOrView));

            InitializeComponent();

            PreviewDataGridView.SelectAllAfterBindingComplete = true;
            InitializeDialogButtons(showCancelButton);
            RowsNumericUpDown.Value = Math.Min(MAXIMUM_PREVIEW_ROWS_NUMBER, Settings.Default.ImportPreviewRowsQuantity);
            TableNameMainLabel.Text = previewTableOrView is DbTable ? "Table Name" : "View Name";
            TableNameSubLabel.Text  = previewTableOrView.Name;
            FillPreviewGrid();
        }
Exemple #15
0
 public bool TryGetDbViewColumns(RdbDescriptor database, DbView view, out IReadOnlyDictionary<string, DbViewColumn> dbViewColumns)
 {
     if (!_initialized)
     {
         Init();
     }
     if (!_dic.ContainsKey(database))
     {
         dbViewColumns = new Dictionary<string, DbViewColumn>(StringComparer.OrdinalIgnoreCase);
         return false;
     }
     Dictionary<string, DbViewColumn> outDic;
     var r = _dic[database].TryGetValue(view, out outDic);
     dbViewColumns = outDic;
     return r;
 }
        public bool TryGetDbViewColumns(RdbDescriptor database, DbView view, out IReadOnlyDictionary <string, DbViewColumn> dbViewColumns)
        {
            if (!_initialized)
            {
                Init();
            }
            if (!_dic.ContainsKey(database))
            {
                dbViewColumns = new Dictionary <string, DbViewColumn>(StringComparer.OrdinalIgnoreCase);
                return(false);
            }
            Dictionary <string, DbViewColumn> outDic;
            var r = _dic[database].TryGetValue(view, out outDic);

            dbViewColumns = outDic;
            return(r);
        }
Exemple #17
0
        }//End GetBetSelectList.

        /// <summary>
        /// Returns a View of the tables in the database.
        /// </summary>
        /// <returns></returns>
        private DbView GetDbView()
        {
            //Get a list of all horses in the database.
            List <Horse> horseTable = GetHorseTable();

            //Get a list of all players in the database.
            List <Player> playerTable = GetPlayerTable();

            //Put these lists in a DbView object.
            DbView dbView = new DbView
            {
                allHorses  = horseTable,
                allPlayers = playerTable,
            };

            return(dbView);
        }//End GetDbView.
Exemple #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PreviewTableViewDialog"/> class.
        /// </summary>
        /// <param name="previewTableOrView">The type of DB object (MySQL table or view) to preview data for.</param>
        /// <param name="showCancelButton">Flag indicating whether the Cancel button is shown along with the OK one, or hidden.</param>
        public PreviewTableViewDialog(DbView previewTableOrView, bool showCancelButton)
        {
            if (previewTableOrView == null)
            {
                throw new ArgumentNullException("previewTableOrView");
            }

            _previewDataTable   = null;
            _previewTableOrView = previewTableOrView;

            InitializeComponent();

            InitializeDialogButtons(showCancelButton);
            RowsNumericUpDown.Value = Settings.Default.ImportPreviewRowsQuantity;
            TableNameMainLabel.Text = previewTableOrView is DbTable ? "Table Name" : "View Name";
            TableNameSubLabel.Text  = previewTableOrView.Name;
            FillPreviewGrid();
        }
Exemple #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImportTableViewForm"/> class.
        /// </summary>
        /// <param name="importDbTableOrView">MySQL table or view from which to import data to an Excel spreadsheet.</param>
        /// <param name="importToWorksheetName">Name of the Excel worksheet where the data will be imported to.</param>
        public ImportTableViewForm(DbView importDbTableOrView, string importToWorksheetName)
        {
            _dbTableOrView            = importDbTableOrView ?? throw new ArgumentNullException(nameof(importDbTableOrView));
            _importColumns            = null;
            _importingRowsInfo        = null;
            _rowsExceedWorksheetLimit = null;
            MySqlTable = null;
            InitializeComponent();

            PreviewDataGridView.SelectAllAfterBindingComplete = true;
            SetAnchors();
            TableNameMainLabel.Text  = importDbTableOrView is DbTable ? "Table Name" : "View Name";
            PickColumnsSubLabel.Text = string.Format(Resources.ImportTableOrViewSubText, importDbTableOrView is DbTable ? "table" : "view");
            Text = @"Import Data - " + importToWorksheetName;
            TableNameSubLabel.Text = importDbTableOrView.Name;
            FillPreviewGrid();
            InitializeOptions();
            SetCompatibilityWarningControlsVisibility();
        }
Exemple #20
0
        public ActionResult Race()
        {
            //Determine if the players have been paid.
            int paidPlayers = GetPlayerTable().FindAll(p => p.PrizeMoney > 0).Count();

            //Check the number of paid players.
            if (paidPlayers == 0)
            {
                //If none have been paid, run the race and save the results.
                PerformRace();
                raceDb.SaveChanges();
            }
            //Get the total Prize pool.
            ViewBag.PrizePool =
                GetHorseTable().FindAll(h => h.PlayerID != null).Count() * BET_SIZE;

            DbView dbView = GetDbView();

            return(View(VIEW_INDEX, dbView));
        }//End Race
Exemple #21
0
        public ActionResult Index(string playerName, string playerEmail, string numBets, string prizeMoney)
        {
            string view = "";

            //Initialize a DbView.
            DbView dbView = GetDbView();

            //Check that the user entered the required data, and is not already registered as a player.
            if (DataEnteredCorrectly(playerName, playerEmail) &&
                !PlayerAlreadyInDb(playerName, playerEmail))
            {
                //If the check passes, set the view to the Confirm Registration page.
                view = VIEW_CONFIRM_REG;
            }
            else
            {
                //If it didn't, set the view to Index.
                view = VIEW_INDEX;
            }

            //Check if the post data has failed (which would set view to Index).
            if (view.CompareTo(VIEW_INDEX) == 0)
            {
                //Create the bets select item list.
                ViewBag.numBets = GetBetSelectList();

                //Check if there are enough horses to start a race and provide feedback if needed.
                SetHorseBetFeedback();

                //Return Index view.
                return(View(view, dbView));
            }
            else
            {
                //If the post data passed the previous checks, create a new player...
                Player regPlayer = BuildPlayer(playerName, playerEmail, numBets);

                //and return it with the ConfirmRegistration view.
                return(View(view, regPlayer));
            }
        }//End HttpPost Index.
Exemple #22
0
        /// <summary>
        /// Reads views schema from database
        /// </summary>
        private List <DbView> ReadViews()
        {
            var result = new List <DbView>();

            using (var views = _dbConnection.GetSchema("Views"))
            {
                foreach (DataRow row in views.Rows)
                {
                    var viewName  = row["TABLE_NAME"].ToString();
                    var ownerName = row["TABLE_SCHEMA"].ToString();

                    if (String.IsNullOrEmpty(SpecificOwner) || String.Equals(ownerName, SpecificOwner, StringComparison.OrdinalIgnoreCase))
                    {
                        if (!IsViewSelected(viewName))
                        {
                            continue;
                        }

                        // View columns
                        var columns = ReadColumns(viewName, ownerName);

                        // read columns description
                        if (ReadColumnsDescription)
                        {
                            ApplyColumnsDescription(viewName, columns);
                        }

                        // new view and view schema
                        var view = new DbView(viewName, columns)
                        {
                            OwnerName = ownerName
                        };

                        // add to results
                        result.Add(view);
                    }
                }
            }
            return(result);
        }
Exemple #23
0
        /// <summary>
        /// Reads views schema from database
        /// </summary>
        private List <DbView> ReadViews()
        {
            List <DbView> result = new List <DbView>();

            if (_dbConnection.State != ConnectionState.Open)
            {
                _dbConnection.Open();
            }

            using (DataTable views = _dbConnection.GetSchema("Views"))
            {
                foreach (DataRow row in views.Rows)
                {
                    string viewName = row["TABLE_NAME"].ToString();

                    if (!IsViewSelected(viewName))
                    {
                        continue;
                    }

                    // View columns
                    List <DbColumn> columns = ReadColumns(viewName);

                    // read columns description
                    //if (ReadColumnsDescription)
                    //	ApplyColumnsDescription(viewName, columns);

                    // new view
                    var view = new DbView(viewName, columns);

                    // view schema
                    view.OwnerName = row["TABLE_SCHEMA"].ToString();

                    // add to results
                    result.Add(view);
                }
            }
            return(result);
        }
Exemple #24
0
        }//End PayoutPlayers

        /// <summary>
        /// Returns a View of the players that won money, and the horses that participated in the race
        /// with their finishing position.
        /// </summary>
        /// <returns></returns>
        private DbView GetDbView()
        {
            //Get a list of all horses.
            List <Horse> horseTable = GetHorseTable();

            //Sort by placing.
            horseTable.Sort();

            //Get a list of all players that placed winning bets.
            List <Player> playerTable = GetPlayerTable();

            playerTable.Reverse();

            //Create a db view and return it.
            DbView dbView = new DbView
            {
                allHorses  = horseTable,
                allPlayers = playerTable,
            };

            return(dbView);
        }//End GetDbView
        public void NaturalizeNames_TableSchemaName_DuplicateTest_ForView()
        {
            Pattern.LanguageSettings.KeywordsCaseSensitive = true;
            var analyzer = new SchemaAnalyzer_Accessor(Project, Pattern, Database);
            var table0   = new DbView("tbl_Other");
            var table1   = new DbView("tbl_Test");
            var table2   = new DbView("tbl_Test");
            var table3   = new DbView("tbl_Test");
            var table4   = new DbView("tbl_Test");
            var table5   = new DbView("tbl_Test");
            var table6   = new DbView("tbl_Test");

            Database.SchemaViews.AddRange(new[]
            {
                table0,
                table1,
                table2,
                table3,
                table4,
                table5,
                table6,
            });
            try
            {
                foreach (var dbTable in Database.SchemaViews)
                {
                    dbTable.TableNameSchema = analyzer.NaturalizeNames_TableSchemaName_Duplicate(dbTable, true);
                }
            }
            finally
            {
                Database.SchemaViews.Clear();
            }
            Assert.AreEqual("tbl_Test", table1.TableNameSchema);
            Assert.AreEqual("tbl_Test_", table2.TableNameSchema);
            Assert.AreEqual("tbl_Test_1", table3.TableNameSchema);
            Assert.AreEqual("tbl_Test_2", table4.TableNameSchema);
        }
Exemple #26
0
        /// <summary>
        /// 换个文档显示
        /// </summary>
        /// <param name="doc"></param>
        public void ResetDocument(Document doc)
        {
            mDocument = doc;
            mRootSceneNode.SetDocument(mDocument);
            mDbView = DbView.Cast(mDocument.FindElement(mDocument.GetActiveDbViewId()));

            var table   = mDocument.FindTable("UserElement");
            var userIds = table.GetIds();
            var scene   = mContext.RenderView.GetScene();

            foreach (var id in userIds)
            {
                var element = mDocument.FindElement(id);
                if (MyTextElement.IsKindOf(element))
                {
                    var text = new MyTextElement();
                    text.Load(UserElement.Cast(element));
                    text.Show(scene);
                }
            }

            mContext.RequestUpdate();
            mRenderCtrl.ZoomAll(0.8f);
        }
        private DbSchemaObject ParseSchemaObject(FileInfo file)
        {
            DbSchemaObject schemaObject = null;
            var            name         = System.IO.Path.GetFileNameWithoutExtension(file.FullName);
            var            nameparts    = name.Split('_');

            var objectType = (ESchemaObjectType)Enum.Parse(typeof(ESchemaObjectType), nameparts[0]);

            switch (objectType)
            {
            case ESchemaObjectType.Table:
                schemaObject = new DbTable();
                break;

            case ESchemaObjectType.View:
                schemaObject = new DbView();
                break;

            case ESchemaObjectType.StoredProcedure:
                schemaObject = new DbStoredProc();
                break;

            case ESchemaObjectType.ScalarFunction:
                schemaObject = new DbScalarFunction();
                break;

            case ESchemaObjectType.TableFunction:
                schemaObject = new DbTableFunction();
                break;

            case ESchemaObjectType.Trigger:
                schemaObject = new DbTrigger();
                break;

            case ESchemaObjectType.PrimaryKey:
                schemaObject = new DbPrimaryKey();
                break;

            case ESchemaObjectType.ForeignKey:
                schemaObject = new DbForeignKey();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (schemaObject == null)
            {
                throw new Exception("Unable to identify object");
            }

            var objectParts = nameparts[1].Split('.');

            if (objectParts.Length != 2)
            {
                throw new Exception($"Problem with name {nameparts[1]}");
            }

            schemaObject.SchemaName = objectParts[0];
            schemaObject.Name       = objectParts[1];
            schemaObject.Definition = file.ReadAllText();

            return(schemaObject);
        }
        /// <summary>
        /// Reads views schema from database
        /// </summary>
        private List<DbView> ReadViews()
        {
            List<DbView> result = new List<DbView>();

            using (DataTable views = _dbConnection.GetSchema("Views"))
            {
                foreach (DataRow row in views.Rows)
                {
                    string viewName = row["TABLE_NAME"].ToString();
                    string ownerName = row["TABLE_SCHEMA"].ToString();

                    if (!IsViewSelected(viewName))
                        continue;

                    // View columns
                    List<DbColumn> columns = ReadColumns(viewName, ownerName);

                    // read columns description
                    if (ReadColumnsDescription)
                        ApplyColumnsDescription(viewName, columns);

                    // new view
                    var view = new DbView(viewName, columns);

                    // view schema
                    view.OwnerName = ownerName;

                    // add to results
                    result.Add(view);
                }
            }
            return result;
        }
        /// <summary>
        /// Reads views schema from database
        /// </summary>
        private List<DbView> ReadViews()
        {
            List<DbView> result = new List<DbView>();

            string[] restrictions = null;
            if (!string.IsNullOrWhiteSpace(this.SpecificOwner))
            {
                restrictions = new string[] { SpecificOwner.ToUpper() };
            }

            using (DataTable views = _dbConnection.GetSchema("Views", restrictions))
            {
                foreach (DataRow row in views.Rows)
                {
                    string viewName = row["VIEW_NAME"].ToString();

                    if (!IsViewSelected(viewName))
                        continue;

                    // View columns
                    List<DbColumn> columns = ReadColumns(viewName);

                    // new view
                    var view = new DbView(viewName, columns);

                    // view schema
                    view.OwnerName = row["OWNER"].ToString();

                    // add to results
                    result.Add(view);
                }
            }
            return result;
        }
        public void SaveChanges(DbSchemeCommit SchemeCommit)
        {
            DBEntities e = COREobject.i.Context;

            foreach (DbTable schemeTable in SchemeCommit.Tables)
            {
                IEnumerable <DbTable> removeTables = SchemeCommit.Tables.Where(x1 => !e.DbTables.Any(x2 => x2.Id == x1.Id));
                e.DbTables.Except <DbTable>(removeTables);                           //maže všechny tabulky, které se už nenachází na schématu uživatele

                if (e.DbTables.SingleOrDefault(x => x.Id == schemeTable.Id) == null) //pokud je ve schématu uživatele vytvořena nová tabulka
                {
                    e.DbTables.Add(schemeTable);
                }
                else
                {
                    DbTable DatabaseTable = e.DbTables.SingleOrDefault(x => x.Id == schemeTable.Id);
                    if (DatabaseTable.Name != schemeTable.Name)
                    {
                        DatabaseTable.Name = schemeTable.Name;
                    }

                    foreach (DbColumn schemeColumn in schemeTable.Columns)
                    {
                        IEnumerable <DbColumn> removeColumns = schemeTable.Columns.Where(x1 => !DatabaseTable.Columns.Any(x2 => x2.Id == x1.Id));
                        DatabaseTable.Columns.Except <DbColumn>(removeColumns);                          //maže všechny sloupce tabulky, které se už nenachází na schématu uživatele

                        if (DatabaseTable.Columns.SingleOrDefault(x => x.Id == schemeColumn.Id) == null) //pokud je ve schématu uživatele vytvořen nový sloupec
                        {
                            DatabaseTable.Columns.Add(schemeColumn);
                        }
                        else
                        {
                            DbColumn DatabaseColumn = DatabaseTable.Columns.SingleOrDefault(x => x.Id == schemeColumn.Id);

                            if (DatabaseColumn.Name != schemeColumn.Name)
                            {
                                DatabaseColumn.Name = schemeColumn.Name;
                            }
                            if (DatabaseColumn.DisplayName != schemeColumn.DisplayName)
                            {
                                DatabaseColumn.DisplayName = schemeColumn.DisplayName;
                            }
                            if (DatabaseColumn.PrimaryKey != schemeColumn.PrimaryKey)
                            {
                                DatabaseColumn.PrimaryKey = schemeColumn.PrimaryKey;
                            }
                            if (DatabaseColumn.Type != schemeColumn.Type)
                            {
                                DatabaseColumn.Type = schemeColumn.Type;
                            }
                            if (DatabaseColumn.Unique != schemeColumn.Unique)
                            {
                                DatabaseColumn.Unique = schemeColumn.Unique;
                            }
                            if (DatabaseColumn.AllowNull != schemeColumn.AllowNull)
                            {
                                DatabaseColumn.AllowNull = schemeColumn.AllowNull;
                            }
                            if (DatabaseColumn.ColumnLength != schemeColumn.ColumnLength)
                            {
                                DatabaseColumn.ColumnLength = schemeColumn.ColumnLength;
                            }
                            if (DatabaseColumn.ColumnLengthIsMax != schemeColumn.ColumnLengthIsMax)
                            {
                                DatabaseColumn.ColumnLengthIsMax = schemeColumn.ColumnLengthIsMax;
                            }
                            if (DatabaseColumn.DefaultValue != schemeColumn.DefaultValue)
                            {
                                DatabaseColumn.DefaultValue = schemeColumn.DefaultValue;
                            }
                        }
                    }
                    foreach (DbIndex schemeIndex in schemeTable.Indices)
                    {
                        IEnumerable <DbIndex> removeIndeces = schemeTable.Indices.Where(x1 => !DatabaseTable.Indices.Any(x2 => x2.Id == x1.Id));
                        DatabaseTable.Indices.Except <DbIndex>(removeIndeces);                          //maže všechny indexy tabulky, které se už nenachází na schématu uživatele

                        if (DatabaseTable.Indices.SingleOrDefault(x => x.Id == schemeIndex.Id) == null) //pokud je ve schématu uživatele vytvořen nový index
                        {
                            DatabaseTable.Indices.Add(schemeIndex);
                        }
                        else
                        {
                            DbIndex databaseIndex = DatabaseTable.Indices.SingleOrDefault(x => x.Id == schemeIndex.Id);

                            if (databaseIndex.ColumnNames != schemeIndex.ColumnNames)
                            {
                                databaseIndex.ColumnNames = schemeIndex.ColumnNames;
                            }
                            if (databaseIndex.Name != schemeIndex.Name)
                            {
                                databaseIndex.Name = schemeIndex.Name;
                            }
                            if (databaseIndex.Unique != schemeIndex.Unique)
                            {
                                databaseIndex.Unique = schemeIndex.Unique;
                            }
                        }
                    }
                }
            }

            foreach (DbRelation schemeRelation in SchemeCommit.Relations)
            {
                IEnumerable <DbRelation> removeRelations = SchemeCommit.Relations.Where(x1 => !e.DbRelation.Any(x2 => x2.Id == x1.Id));
                e.DbRelation.Except <DbRelation>(removeRelations);                        //maže všechny vztahy, které se už nenachází ve schématu uživatele

                if (e.DbRelation.SingleOrDefault(x => x.Id == schemeRelation.Id) == null) //pokud je ve schématu uživatele vytvořen nový vztah
                {
                    e.DbRelation.Add(schemeRelation);
                }
                else
                {
                    DbRelation databaseRelation = e.DbRelation.SingleOrDefault(x => x.Id == schemeRelation.Id);

                    databaseRelation.SourceTableId  = schemeRelation.SourceTableId;
                    databaseRelation.TargetTableId  = schemeRelation.TargetTableId;
                    databaseRelation.SourceColumnId = schemeRelation.SourceColumnId;
                    databaseRelation.TargetColumnId = schemeRelation.TargetColumnId;
                    databaseRelation.Type           = schemeRelation.Type;
                }
            }

            foreach (DbView schemeView in SchemeCommit.Views)
            {
                IEnumerable <DbView> removeRelations = SchemeCommit.Views.Where(x1 => !e.DbView.Any(x2 => x2.Id == x1.Id));
                e.DbView.Except <DbView>(removeRelations);                        //maže všechny pohledy, které se už nenachází ve schématu uživatele

                if (e.DbView.SingleOrDefault(x => x.Id == schemeView.Id) == null) //pokud je ve schématu uživatele vytvořen nový pohled
                {
                    e.DbView.Add(schemeView);
                }
                else
                {
                    DbView databaseView = e.DbView.SingleOrDefault(x => x.Id == schemeView.Id);

                    if (databaseView.Name != schemeView.Name)
                    {
                        databaseView.Name = schemeView.Name;
                    }
                    if (databaseView.Query != schemeView.Query)
                    {
                        databaseView.Query = schemeView.Query;
                    }
                }
            }
        }
        private void GenerateView(DbSchemeCommit dbSchemeCommit)
        {
            _progressHandler.SetMessage("GenerateView", type: MessageType.InProgress, progressSteps: dbSchemeCommit.Views.Count);

            List <Exception> errors     = new List <Exception>();
            Queue <DbView>   que        = new Queue <DbView>(dbSchemeCommit.Views);
            DbView           firstError = null;

            while (que.Any())
            {
                DbView efView = que.Dequeue();

                DBView newView = new DBView(_db)
                {
                    Name = efView.Name,
                    Sql  = efView.Query
                };

                try
                {
                    if (!_db.Exists(efView.Name, ETabloid.Views))
                    {
                        newView.Create();
                    }
                    else
                    {
                        newView.Alter();
                    }

                    _db.SaveChanges();
                    firstError = null;
                }
                catch (Exception ex)
                {
                    if (firstError == null)
                    {
                        firstError = efView;
                    }
                    else if (firstError == efView)
                    {
                        firstError = null;
                        errors.Add(ex);
                        continue;
                    }

                    que.Enqueue(efView);
                }

                _progressHandler.IncrementProgress();
            }
            if (errors.Any())
            {
                throw new OmniusMultipleException(errors);
            }

            //list of views, which are in database, but not in scheme
            List <string> deleteViews = _db.List(ETabloid.Views)
                                        .Except(dbSchemeCommit.Views.Select(x => x.Name)).ToList();

            //dropping views
            foreach (string viewName in deleteViews)
            {
                _db.ViewDrop(viewName);
            }
            _db.SaveChanges();

            _progressHandler.SetMessage("GenerateView", type: MessageType.Success);
        }
Exemple #32
0
 public IEnumerable <DbBusinessId> GetBusinessIds(string connectionString, DbView dbView)
 {
     return(GetBusinessIds());
 }
Exemple #33
0
 public IEnumerable <DbEntry> GetDbEntries(string connectionString, DbView dbView)
 {
     return(GetDbEntries());
 }