private Border getButton(int dif, int buttonName, DataTable finished, int scroll, int exnum, string name, int packageID) { //Create the main button. BorderButton button = new BorderButton(packageID, dif); Border borderButton = button.getButton(); Grid borderGrid = (Grid)borderButton.Child; Image completedIcon = (Image)borderGrid.Children[2]; TextBlock l1 = (TextBlock)borderGrid.Children[0]; if (packageID - 1 == 1) { l1.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Fonts/#Orwell"); } if (packageID - 1 == 2) { l1.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Fonts/#Code"); } if (packageID - 1 == 4) { l1.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Fonts/#Orwell"); } borderButton.Name = $"E{buttonName}"; //Add the mouseEnter and mouseLeave event to the borderButton; borderButton.MouseEnter += BorderButton_MouseEnter; borderButton.MouseLeave += BorderButton_MouseLeave; //iets met stackpanel l1.Text = $"{name}: {exnum}"; if (finished.Rows.Count > 0) { completedIcon.Visibility = Visibility.Visible; scroll++; } else { completedIcon.Visibility = Visibility.Hidden; } borderButton.PreviewMouseDown += B1_Click; return(borderButton); }
public void createExercisesGrid() { BoxGrid.Children.Clear(); DataTable packages; if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("username"))) { //Get the owned packages from the database and if there are less than four it will add some locked packages. With the NOT IN all packages that cant quick start are filtered out packages = c.PullData($"SELECT TOP 4 P.description, L.packageID FROM License L LEFT JOIN Package P ON L.packageID = P.packageID WHERE userID = {ConfigurationManager.AppSettings.Get("userID")} AND P.packageID NOT IN (1,7,8,9) ORDER BY NEWID()"); packages.Columns.Add("owned", typeof(int)); foreach (DataRow dr in packages.Rows) { dr["owned"] = 1; } if (packages.Rows.Count < 4) { int toBePulled = 4 - packages.Rows.Count; DataTable randPackages = c.PullData($"SELECT TOP {toBePulled} description, packageID FROM Package WHERE PackageID NOT IN (SELECT packageID FROM License WHERE userID = {ConfigurationManager.AppSettings.Get("userID")}) AND packageID != 1 ORDER BY NEWID()"); randPackages.Columns.Add("owned", typeof(int)); foreach (DataRow dr in randPackages.Rows) { packages.Rows.Add(dr.ItemArray); } } } else { packages = c.PullData("SELECT TOP 4 description, packageID FROM Package WHERE PackageID != 1 ORDER BY NEWID()"); } //Going thru all the TextBlocs in the grid to add the hover events. for (int i = 0; i < packages.Rows.Count; i++) { //Setting a standard text to each TextBlock //Here will the random exercises from the database come. BorderButton button = new BorderButton(); Border borderButton = button.getButton(); Grid borderGrid = (Grid)borderButton.Child; Image completedIcon = (Image)borderGrid.Children[1]; TextBlock l1 = (TextBlock)borderGrid.Children[0]; borderButton.Name = $"B{packages.Rows[i]["packageID"]}"; borderButton.Margin = new Thickness(5); l1.TextWrapping = TextWrapping.Wrap; l1.FontSize = 17; l1.FontWeight = FontWeights.Bold; l1.Foreground = Brushes.White; l1.Text = packages.Rows[i]["description"].ToString(); //Adding the events if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("username")) && packages.Rows[i]["owned"].ToString() == "1") { borderButton.Background = new SolidColorBrush(Color.FromRgb(51, 204, 51)); borderButton.BorderBrush = new SolidColorBrush(Color.FromRgb(51, 204, 51)); borderButton.Background.Opacity = 0.7; completedIcon.Visibility = Visibility.Hidden; borderButton.MouseDown += BorderButton_MouseDown; borderButton.MouseEnter += OnBoxEnter; borderButton.MouseLeave += OnBoxLeave; } Grid.SetColumn(button.getButton(), i); BoxGrid.Children.Add(button.getButton()); } }