Skip to content

Commit 7d4dab5

Browse files
committed
fix ops and snippets errors
1 parent 5c15d43 commit 7d4dab5

7 files changed

Lines changed: 181 additions & 5 deletions

File tree

media/gdip-art10.gif

1.09 KB
Loading

media/gdip-art12.gif

1.09 KB
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net4.8</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// <Snippet1>
2+
using System;
3+
using System.Data;
4+
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
// Create two tables and add them into the DataSet
10+
DataTable orderTable = CreateOrderTable();
11+
DataTable orderDetailTable = CreateOrderDetailTable();
12+
DataSet salesSet = new DataSet();
13+
salesSet.Tables.Add(orderTable);
14+
salesSet.Tables.Add(orderDetailTable);
15+
16+
// Set the relations between the tables and create the related constraint.
17+
salesSet.Relations.Add("OrderOrderDetail", orderTable.Columns["OrderId"], orderDetailTable.Columns["OrderId"], true);
18+
19+
Console.WriteLine("After creating the foreign key constriant, you will see the following error if inserting order detail with the wrong OrderId: ");
20+
try
21+
{
22+
DataRow errorRow = orderDetailTable.NewRow();
23+
errorRow[0] = 1;
24+
errorRow[1] = "O0007";
25+
orderDetailTable.Rows.Add(errorRow);
26+
}
27+
catch (Exception e)
28+
{
29+
Console.WriteLine(e.Message);
30+
}
31+
Console.WriteLine();
32+
33+
// Insert the rows into the table
34+
InsertOrders(orderTable);
35+
InsertOrderDetails(orderDetailTable);
36+
37+
Console.WriteLine("The initial Order table.");
38+
ShowTable(orderTable);
39+
40+
Console.WriteLine("The OrderDetail table.");
41+
ShowTable(orderDetailTable);
42+
43+
// Use the Aggregate-Sum on the child table column to get the result.
44+
DataColumn colSub = new DataColumn("SubTotal", typeof(Decimal), "Sum(Child.LineTotal)");
45+
orderTable.Columns.Add(colSub);
46+
47+
// Compute the tax by referencing the SubTotal expression column.
48+
DataColumn colTax = new DataColumn("Tax", typeof(Decimal), "SubTotal*0.1");
49+
orderTable.Columns.Add(colTax);
50+
51+
// If the OrderId is 'Total', compute the due on all orders; or compute the due on this order.
52+
DataColumn colTotal = new DataColumn("TotalDue", typeof(Decimal), "IIF(OrderId='Total',Sum(SubTotal)+Sum(Tax),SubTotal+Tax)");
53+
orderTable.Columns.Add(colTotal);
54+
55+
DataRow row = orderTable.NewRow();
56+
row["OrderId"] = "Total";
57+
orderTable.Rows.Add(row);
58+
59+
Console.WriteLine("The Order table with the expression columns.");
60+
ShowTable(orderTable);
61+
62+
Console.WriteLine("Press any key to exit.....");
63+
Console.ReadKey();
64+
}
65+
66+
private static DataTable CreateOrderTable()
67+
{
68+
DataTable orderTable = new DataTable("Order");
69+
70+
// Define one column.
71+
DataColumn colId = new DataColumn("OrderId", typeof(String));
72+
orderTable.Columns.Add(colId);
73+
74+
DataColumn colDate = new DataColumn("OrderDate", typeof(DateTime));
75+
orderTable.Columns.Add(colDate);
76+
77+
// Set the OrderId column as the primary key.
78+
orderTable.PrimaryKey = new DataColumn[] { colId };
79+
80+
return orderTable;
81+
}
82+
83+
private static DataTable CreateOrderDetailTable()
84+
{
85+
DataTable orderDetailTable = new DataTable("OrderDetail");
86+
87+
// Define all the columns once.
88+
DataColumn[] cols =
89+
{
90+
new DataColumn("OrderDetailId", typeof(Int32)),
91+
new DataColumn("OrderId", typeof(String)),
92+
new DataColumn("Product", typeof(String)),
93+
new DataColumn("UnitPrice", typeof(Decimal)),
94+
new DataColumn("OrderQty", typeof(Int32)),
95+
new DataColumn("LineTotal", typeof(Decimal), "UnitPrice*OrderQty")
96+
};
97+
98+
orderDetailTable.Columns.AddRange(cols);
99+
orderDetailTable.PrimaryKey = new DataColumn[] { orderDetailTable.Columns["OrderDetailId"] };
100+
return orderDetailTable;
101+
}
102+
103+
private static void InsertOrders(DataTable orderTable)
104+
{
105+
// Add one row once.
106+
DataRow row1 = orderTable.NewRow();
107+
row1["OrderId"] = "O0001";
108+
row1["OrderDate"] = new DateTime(2013, 3, 1);
109+
orderTable.Rows.Add(row1);
110+
111+
DataRow row2 = orderTable.NewRow();
112+
row2["OrderId"] = "O0002";
113+
row2["OrderDate"] = new DateTime(2013, 3, 12);
114+
orderTable.Rows.Add(row2);
115+
116+
DataRow row3 = orderTable.NewRow();
117+
row3["OrderId"] = "O0003";
118+
row3["OrderDate"] = new DateTime(2013, 3, 20);
119+
orderTable.Rows.Add(row3);
120+
}
121+
122+
private static void InsertOrderDetails(DataTable orderDetailTable)
123+
{
124+
// Use an Object array to insert all the rows .
125+
// Values in the array are matched sequentially to the columns, based on the order in which they appear in the table.
126+
Object[] rows =
127+
{
128+
new Object[] { 1, "O0001", "Mountain Bike", 1419.5, 36 },
129+
new Object[] { 2, "O0001", "Road Bike", 1233.6, 16 },
130+
new Object[] { 3, "O0001", "Touring Bike", 1653.3, 32 },
131+
new Object[] { 4, "O0002", "Mountain Bike", 1419.5, 24 },
132+
new Object[] { 5, "O0002", "Road Bike", 1233.6, 12 },
133+
new Object[] { 6, "O0003", "Mountain Bike", 1419.5, 48 },
134+
new Object[] { 7, "O0003", "Touring Bike", 1653.3, 8 },
135+
};
136+
137+
foreach (Object[] row in rows)
138+
{
139+
orderDetailTable.Rows.Add(row);
140+
}
141+
}
142+
143+
private static void ShowTable(DataTable table)
144+
{
145+
foreach (DataColumn col in table.Columns)
146+
{
147+
Console.Write("{0,-14}", col.ColumnName);
148+
}
149+
Console.WriteLine();
150+
151+
foreach (DataRow row in table.Rows)
152+
{
153+
foreach (DataColumn col in table.Columns)
154+
{
155+
if (col.DataType.Equals(typeof(DateTime)))
156+
Console.Write("{0,-14:d}", row[col]);
157+
else if (col.DataType.Equals(typeof(Decimal)))
158+
Console.Write("{0,-14:C}", row[col]);
159+
else
160+
Console.Write("{0,-14}", row[col]);
161+
}
162+
Console.WriteLine();
163+
}
164+
Console.WriteLine();
165+
}
166+
}
167+
// </Snippet1>

snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/etwtracesmall.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<StartupObject>Demo.Program</StartupObject>

snippets/csharp/System.Diagnostics.Tracing/EventSource/Overview/program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.Generic;
44
using System.Diagnostics.Tracing;
55

6-
namespace Demo
6+
namespace Demo1
77
{
88
//<InterfaceSource>
99
public interface IMyLogging

xml/System.Drawing.Drawing2D/Matrix.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ The <xref:System.Drawing.Drawing2D.Matrix> class encapsulates a 3-by-3 affine ma
5151
5252
In GDI+, you can store an affine transformation in a <xref:System.Drawing.Drawing2D.Matrix> object. Because the third column of a matrix that represents an affine transformation is always (0, 0, 1), you specify only the six numbers in the first two columns when you construct a <xref:System.Drawing.Drawing2D.Matrix> object. The statement `Matrix myMatrix = new Matrix(0, 1, -1, 0, 3, 4)` constructs the matrix shown in the following figure.
5353
54-
![Matrix.](./media/gdip-art10.gif)
54+
![Matrix.](~/media/gdip-art10.gif)
5555
56-
[!INCLUDE[System.Drawing.Common note](./includes/system-drawing-common.md)]
56+
[!INCLUDE[System.Drawing.Common note](~/includes/system-drawing-common.md)]
5757
5858
## Composite transformations
5959
@@ -75,7 +75,7 @@ Rather than store the three parts of the composite transformation in three separ
7575
7676
The following illustration shows the matrices A, B, C, and D.
7777
78-
![Matrices A, B, C, and D](./media/gdip-art12.gif)
78+
![Matrices A, B, C, and D](~/media/gdip-art12.gif)
7979
8080
The fact that the matrix of a composite transformation can be formed by multiplying the individual transformation matrices means that any sequence of affine transformations can be stored in a single <xref:System.Drawing.Drawing2D.Matrix> object.
8181

0 commit comments

Comments
 (0)