public void LoadContentDatabase(string DatabaseName)
        {
            _projectName = DatabaseName;
            var ProjectDatabase = ProjectTabs.Mongo.GetDatabase(DatabaseName);
            var GetMisc = ProjectDatabase.GetCollection<DatabaseMisc>("DataBaseMisc");
            var filter = Builders<DatabaseMisc>.Filter.Eq("ID", 0);
            var TempList = GetMisc.Find(filter).FirstOrDefault(); 
            DatabaseMisc StartupFile = TempList as DatabaseMisc;
            
            _startdatevalueMW = DateTime.Parse(StartupFile.ProjectStartDate);
            identity = StartupFile.LastAllocatedID;
            DeletedID = StartupFile.LastDeletedList;

            DatePopulate();
            AddColorsToProject();

            var collabentry = ProjectDatabase.GetCollection<BsonDocument>("UserEntry");
            var filter2 = Builders<BsonDocument>.Filter.Empty;
            var TempEntry = collabentry.Find(filter2).ToList();

            UserContent DatabaseInput = new UserContent();

            foreach (var item in TempEntry)
            {
                DatabaseInput.ReturnDiscipline = item["ContentDiscipline"].AsString;
                DatabaseInput.ReturnContent = item["Content"].AsString;
                DatabaseInput.ReturnStartDate = DateTime.Parse(item["ContentStartDate"].AsString);
                DatabaseInput.ReturnEndDate = DateTime.Parse(item["ContentEndDate"].AsString);
                DatabaseInput.ReturnDiscColor = new KeyValuePair<string, System.Windows.Media.SolidColorBrush>(item["ContentColor"].AsString,
                    ProjectColorSelection[item["ContentColor"].AsString]);
                DatabaseInput.MileCheck = item["ContentMilestone"].ToBoolean();

                AddUserContentFromServer(DatabaseInput, item["ContentID"].ToInt32(), item["ContentCompletedState"].ToInt32());
            }

        }
        public void AddUserContentFromServer(UserContent FromServerInput, int FromServerID, int FromServerCompletedState)
        {
            bool _spanExist = FromServerInput.ReturnStartDate != FromServerInput.ReturnEndDate;

            CheckDisciplineExist(FromServerInput);

            if (FromServerInput.ReturnStartDate.HasValue)
            {
                int[] index = CheckDatesExist(FromServerInput);

                if (_spanExist)
                {
                    List<Grid> grids = GridsAddedToProject.Values.ToList();
                    foreach (Grid grid in grids)
                    {
                        RectangleAdd(grid);
                    }
                    TimeSpan temp = (TimeSpan)(FromServerInput.ReturnEndDate - FromServerInput.ReturnStartDate); int temp2 = temp.Days + 1;

                    UserAddedContents[FromServerInput.ReturnDiscipline.ToUpper()].Add(new Collab()
                    {
                        Id = FromServerID,
                        Discipline = FromServerInput.ReturnDiscipline.ToUpper(),
                        Content = FromServerInput.ReturnContent,
                        StartDate = ((DateTime)FromServerInput.ReturnStartDate).Date,
                        DisciplineColor = FromServerInput.ReturnDiscColor,
                        Row = index[0],
                        EndDate = ((DateTime)FromServerInput.ReturnEndDate).Date,
                        MainContent = true,
                        CompletedState = FromServerCompletedState,
                        MileStoneEntry = FromServerInput.MileCheck
                    });

                    AddArrowsExtension(FromServerID, FromServerInput, index);

                    TextBlock _ContentText = new TextBlock()
                    {
                        Tag = FromServerID,
                        Text = FromServerInput.ReturnContent,
                        FontSize = 11,
                        Background = FromServerInput.ReturnDiscColor.Value
                    }; TextBlockStyle(_ContentText);
                    Grid.SetRow(_ContentText, index[0]); Grid.SetColumn(_ContentText, index[1]); Grid.SetColumnSpan(_ContentText, temp2);

                    Grid ContentGrid = GridsAddedToProject[FromServerInput.ReturnDiscipline.ToUpper()];
                    ContentGrid.Children.Add(_ContentText); 
                }
                else
                {
                    List<Grid> grids = GridsAddedToProject.Values.ToList();
                    foreach (Grid grid in grids)
                    {
                        RectangleAdd(grid);
                    }
                    UserAddedContents[FromServerInput.ReturnDiscipline.ToUpper()].Add(new Collab()
                    {
                        Id = FromServerID,
                        Discipline = FromServerInput.ReturnDiscipline.ToUpper(),
                        Content = FromServerInput.ReturnContent,
                        StartDate = ((DateTime)FromServerInput.ReturnStartDate).Date,
                        DisciplineColor = FromServerInput.ReturnDiscColor,
                        Row = index[0],
                        EndDate = ((DateTime)FromServerInput.ReturnEndDate).Date,
                        MainContent = true,
                        CompletedState = FromServerCompletedState,
                        MileStoneEntry = FromServerInput.MileCheck
                    });

                    TextBlock _ContentText = new TextBlock()
                    {
                        Tag = FromServerID,
                        Text = FromServerInput.ReturnContent,
                        Background = FromServerInput.ReturnDiscColor.Value
                    }; TextBlockStyle(_ContentText);
                    Grid.SetRow(_ContentText, index[0]); Grid.SetColumn(_ContentText, index[1]);

                    Grid ContentGrid = GridsAddedToProject[FromServerInput.ReturnDiscipline.ToUpper()];
                    ContentGrid.Children.Add(_ContentText); 
                }

                switch (FromServerCompletedState)
                {
                    case 1:
                        TickFromServer(index, FromServerID);
                        break;
                    case 2:
                        CrossFromServer(index, FromServerID);
                        break;
                    case 3:
                        AddOverlapGrid(index, FromServerInput, FromServerID); StateUpdate(4, 0);
                        break;
                    default:
                        AddOverlapGrid(index, FromServerInput, FromServerID); StateUpdate(4, 0);
                        break;
                }

                if (FromServerInput.MileCheck)
                    MilestoneFunction(FromServerInput.ReturnDiscColor, FromServerInput.ReturnContent, FromServerID, ((DateTime)FromServerInput.ReturnStartDate).ToLongDateString());
            }
        }