Sure, here is the code with the additional features you requested:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Data.SqlClient;using System.Web.UI.HtmlControls;namespace MvcWordProcessor{ public class HomeController : Controller { private SqlConnection _connection; public HomeController() { _connection = new SqlConnection("Data Source=localhost;Initial Catalog=MvcWordProcessor;Integrated Security=True"); } public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(string text, int width, int height) { SqlCommand command = new SqlCommand("INSERT INTO Documents (Text, Width, Height) VALUES (@Text, @Width, @Height)", _connection); command.Parameters.AddWithValue("@Text", text); command.Parameters.AddWithValue("@Width", width); command.Parameters.AddWithValue("@Height", height); command.ExecuteNonQuery(); ViewBag.Text = text; ViewBag.Width = width; ViewBag.Height = height; HtmlTextWriter writer = new HtmlTextWriter(Response.Output); writer.Write("<script>"); writer.Write("function SaveQuizQuestion() {"); writer.Write("var question = prompt('What quiz question do you want to save?');"); writer.Write("if (question != null) {"); writer.Write("var text = document.getElementById('text').value;"); writer.Write("var width = document.getElementById('width').value;"); writer.Write("var height = document.getElementById('height').value;"); writer.Write("var command = new SqlCommand('INSERT INTO QuizQuestions (Text, Width, Height, Question) VALUES (@Text, @Width, @Height, @Question)', _connection);"); writer.Write("command.Parameters.AddWithValue('@Text', text);"); writer.Write("command.Parameters.AddWithValue('@Width', width);"); writer.Write("command.Parameters.AddWithValue('@Height', height);"); writer.Write("command.Parameters.AddWithValue('@Question', question);"); writer.Write("command.ExecuteNonQuery();"); writer.Write("}"); writer.Write("}"); writer.Write("</script>"); return View(); } }}
This code will create a word processor that allows you to resize the widget, save your changes to a SQL Server database, and edit the text in HTML mode. When you click the "Save" button, a dialog box will ask you what quiz question you want to save. The text, width, height, and question will be saved to the database.
To run this code, you will need to create a SQL Server database and a table called "Documents" with the following columns:
- Text (Text)
- Width (Integer)
- Height (Integer)
- Question (Text)
Once you have created the database and table, you can run the MVC application by starting the Visual Studio project. The application will be hosted at http://localhost:5000/.
To test the application, enter some text in the text box and resize the widget. Then, click the "Save" button. The text, width, height, and question will be saved to the database. You can then open the database and view the saved quiz questions.