@{
var db = Database.Open("SmallBakery");
var ProductId = UrlData[0];
if (ProductId.IsEmpty()) {
Response.Redirect("~/ListProductsForDelete");
}
var prod = db.QuerySingle("SELECT * FROM PRODUCT WHERE ID = @0", ProductId);
if( IsPost && !ProductId.IsEmpty()) {
var deleteQueryString = "DELETE FROM Product WHERE Id=@0";
db.Execute(deleteQueryString, ProductId);
Response.Redirect("~/ListProductsForDelete");
}
}
SELECT NOM_EMPLOYE
, 'Total' AS [MOIS_INTERVENTION]
, SUM( FACTURATION ) AS [SOMME_FACTUREE]
FROM dbo.TB_EMPLOYES E
INNER JOIN dbo.INTERVENTION_CLIENT I ON E.ID_EMPLOYE = I.EMPLOYE_ID
GROUP BY NOM_EMPLOYE;
<!DOCTYPE html><html><head><title></title></head><body>
@{
var weekday = DateTime.Now.DayOfWeek;
// As a test, add 1 day to the current weekday.
if(weekday.ToString() != "Saturday") {
// If weekday is not Saturday, simply add one day.
weekday = weekday + 1;
}
else {
// If weekday is Saturday, reset the day to 0, or Sunday.
weekday = 0;
}
// Convert weekday to a string value for the switch statement.
var weekdayText = weekday.ToString();
var greeting = "";
switch(weekdayText)
{
case "Monday":
greeting = "Ok, it's a marvelous Monday.";
break;
case "Tuesday":
greeting = "It's a tremendous Tuesday.";
break;
case "Wednesday":
greeting = "Wild Wednesday is here!";
break;
case "Thursday":
greeting = "All right, it's thrifty Thursday.";
break;
case "Friday":
greeting = "It's finally Friday!";
break;
case "Saturday":
greeting = "Another slow Saturday is here.";
break;
case "Sunday":
greeting = "The best day of all: serene Sunday.";
break;
default:
break;
}
}
<h2>@greeting</h2></body></html>
@{
var db = Database.Open("SmallBakery");
var selectQueryString = "SELECT * FROM Product ORDER BY Name";
}
<!DOCTYPE html>
{
"results": [
{
"orders":
SELECT 'Total' AS NOM_EMPLOYE
, NULL AS [MOIS_INTERVENTION], SUM( FACTURATION ) AS [SOMME_FACTUREE]FROM dbo.TB_EMPLOYES E
INNER JOIN dbo.INTERVENTION_CLIENT I ON E.ID_EMPLOYE = I.EMPLOYE_ID;
@{
Validation.RequireField("Name", "Product name is required.");
Validation.RequireField("Description", "Product description is required.");
Validation.RequireField("Price", "Product price is required.");
var db = Database.Open("SmallBakery");
var Name = Request.Form["Name"];
var Description = Request.Form["Description"];
var Price = Request.Form["Price"];
if (IsPost && Validation.IsValid()) {
// Define the insert query. The values to assign to the
// columns in the Product table are defined as parameters
// with the VALUES keyword.
if(ModelState.IsValid) {
var insertQuery = "INSERT INTO Product (Name, Description, Price) " +
"VALUES (@0, @1, @2)";
db.Execute(insertQuery, Name, Description, Price);
// Display the page that lists products.
Response.Redirect("~/ListProducts");
}
}
}
<!DOCTYPE html><html><head><title>Add Products</title><styletype="text/css">
label {float:left;width:8em;text-align: right;margin-right:0.5em;}
fieldset {padding:1em;border:1px solid;width:50em;}
legend {padding:2px4px;border:1px solid;font-weight:bold;}.validation-summary-errors {font-weight:bold;color:red;font-size:11pt;}</style></head><body><h1>Add New Product</h1>
@Html.ValidationSummary("Errors with your submission:")
<formmethod="post"action=""><fieldset><legend>Add Product</legend><div><label>Name:</label><inputname="Name"type="text"size="50"value="@Name"/></div><div><label>Description:</label><inputname="Description"type="text"size="50"value="@Description"/></div><div><label>Price:</label><inputname="Price"type="text"size="50"value="@Price"/></div><div><label> </label><inputtype="submit"value="Insert"class="submit"/></div></fieldset></form></body></html>
The body of the page contains an HTML form with three text boxes that let users enter a name, description, and price. When users click the Insert button, the code at the top of the page opens a connection to the SmallBakery.sdf database. You then get the values that the user has submitted by using the Request object and assign those values to local variables.
To validate that the user entered a value for each required column, you register each <input> element that you want to validate:
Validation.RequireField("Name","Product name is required.");Validation.RequireField("Description","Product description is required.");Validation.RequireField("Price","Product price is required.");
The Validation helper checks that there is a value in each of the fields that you've registered. You can test whether all the fields passed validation by checking Validation.IsValid(), which you typically do before you process the information you get from the user:
if(IsPost&&Validation.IsValid()){// Process information here}
(The && operator means AND — this test is If this is a form submission AND all the fields have passed validation.)
If all the columns validated (none were empty), you go ahead and create a SQL statement to insert the data and then execute it as shown next:
var insertQuery ="INSERT INTO Product (Name, Description, Price) VALUES (@0, @1, @2)";
Aucun commentaire:
Enregistrer un commentaire