protected override async void OnNavigatedTo(NavigationEventArgs e) { Puzzle = e.Parameter as PlayPuzzle; await Puzzle.GeneratePuzzle(); Grid.SetColumn(Puzzle.PuzzleBox, 0); Grid.SetColumn(Puzzle.PuzzleImage, 1); PuzzleGrid.Children.Add(Puzzle.PuzzleBox); PuzzleGrid.Children.Add(Puzzle.PuzzleImage); base.OnNavigatedTo(e); }
public ActionResult ShowPuzLec() { Session["LecID"] = Session["LecID"]; Session["Puzzle"] = Session["Puzzle"]; string PuzzleID = Session["Puzzle"].ToString(); List <String> AnswerList = new List <String>(); List <String> QuestionList = new List <String>(); string connectionString = @"Data Source=msi;Initial Catalog=SEFASSIGNMENT;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString); sqlConnection.Open(); System.Data.SqlClient.SqlCommand sqlCommand = new System.Data.SqlClient.SqlCommand( "SELECT Answer_Content FROM [SEFASSIGNMENT].[dbo].[Answer] WHERE Puzzle_ID='" + PuzzleID + "'"); sqlCommand.Connection = sqlConnection; SqlDataReader myreader = sqlCommand.ExecuteReader(); while (myreader.Read()) { AnswerList.Add(myreader[0].ToString()); } Session["TotalAns"] = AnswerList.Count; string words = string.Join(" ", AnswerList.ToArray()); myreader.Close(); sqlCommand = new System.Data.SqlClient.SqlCommand( "SELECT Question_Content FROM [SEFASSIGNMENT].[dbo].[Question] WHERE Puzzle_ID='" + PuzzleID + "'"); sqlCommand.Connection = sqlConnection; SqlDataReader newreader = sqlCommand.ExecuteReader(); while (newreader.Read()) { QuestionList.Add(newreader[0].ToString().ToUpper()); } newreader.Close(); string[] input = AnswerList.ToArray(); for (ushort i = 0; i < input.Length; i++) { input[i] = Regex.Replace((i + 1) + input[i], "[^\\w\\d]", ""); } ushort width = 30; ushort height = 30; Canvas canvas = new CrosswordFactory(input, width, height, true).createCanvas(); canvas.Build(); ICanvasWriter canvasWriter = new HtmlCanvasWriter(); ViewData["Width"] = width; ViewData["Height"] = height; ViewData["Words"] = words; ViewData["Canvas"] = canvas; ViewData["CanvasWriter"] = canvasWriter; sqlCommand = new System.Data.SqlClient.SqlCommand( "SELECT COUNT(*) FROM [SEFASSIGNMENT].[dbo].[Answer] WHERE Puzzle_ID='" + PuzzleID + "'"); sqlCommand.Connection = sqlConnection; int sumquestion = Convert.ToInt32(sqlCommand.ExecuteScalar()); TempData["SumQuestion"] = sumquestion; var model = new PlayPuzzle { QuestionList = QuestionList, }; return(View(model)); }