📄 productdetails.aspx
字号:
<%@ Page Language="C#" MasterPageFile="~/CommonMaster.master" Title="Product Details" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Serialization" %>
<%@ Import Namespace="ProductsProxy" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
/* Synchronous Web Service Call approach
ProductsProxy.ProductsService obj = new ProductsProxy.ProductsService();
int productID = Convert.ToInt32(Request.QueryString["ProductID"]);
formProductDetails.DataSource = obj.GetProductDetails(productID);
formProductDetails.DataBind();
* /
*
/* Asynchronous Web Service call through the XML file generated by the Windows Service */
int categoryID = 0;
int productID = Convert.ToInt32(Request.QueryString["ProductID"]);
List<Product> prodList = new List<Product>();
string xmlFilePath = @"C:\Projects\Wrox\Products.xml";
XmlSerializer serializer = new XmlSerializer(typeof(Product[]));
TextReader reader = new StreamReader(xmlFilePath);
Product[] prodArray = (Product[])serializer.Deserialize(reader);
//Loop through the array and retrieve the products with the matching product id
for (int i = 0; i < prodArray.Length; i++)
{
Product temp = prodArray[i];
//Only add the matching products to the new collection
if (temp.ProductID == productID)
{
prodList.Add(temp);
categoryID = temp.CategoryID;
}
}
reader.Close();
formProductDetails.DataSource = prodList;
formProductDetails.DataBind();
//Store the parameters related to the Request into local variables
string browser = Request.UserAgent.ToString();
string requestType = Request.RequestType.ToString();
string authenticated = Request.IsAuthenticated.ToString();
//Call the CreateXMLDocument method to save the details related to reporting to the database
CreateXMLDocument(browser, requestType, authenticated, categoryID, productID);
}
public bool CreateXMLDocument(string browser, string requestType, string authenticated, int categoryID, int productID)
{
try
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
string fileName = System.Guid.NewGuid().ToString() + ".xml";
XmlWriter writer = XmlWriter.Create(@"C:\Projects\Wrox\Drop\" + fileName, settings);
writer.WriteStartDocument(false);
writer.WriteComment("This file represents the information collected for reporting purposes");
writer.WriteStartElement("ReportInfo", null);
writer.WriteElementString("Browser", browser);
writer.WriteElementString("RequestType", requestType);
writer.WriteElementString("Authenticated", authenticated);
writer.WriteElementString("CategoryID", categoryID.ToString());
writer.WriteElementString("ProductID", productID.ToString());
writer.WriteEndElement();
//Write the XML to file and close the objWriter
writer.Flush();
writer.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return true;
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContent" Runat="Server">
<table width="95%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<asp:FormView ID="formProductDetails" runat="server">
<HeaderTemplate>
<tr>
<td height="40" align="center" colspan="2">
<asp:Label runat="server" Font-Bold="true" ForeColor="Brown"
ID="heading">Product Details</asp:Label>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td height="60" width="30%" bgcolor="buttonface">
<asp:label Font-Bold=true Text="Model Number : " runat="server" ID="lblModelNumber" />
<br>
</td>
<td height="60" bgcolor="buttonface">
<asp:label Text='<%#Eval("ModelNo")%>' runat="server" ID="lblModelNumberValue" />
<br>
</td>
</tr>
<tr>
<td height="60" width="30%" bgcolor="buttonface">
<asp:label Font-Bold=true Text="Model Name : " runat="server" ID="lblModelName" />
<br>
</td>
<td height="60" bgcolor="buttonface">
<asp:label Text='<%#Eval("ModelName")%>' runat="server" ID="lblModelNameValue" />
<br>
</td>
</tr>
<tr>
<td height="60" width="30%" bgcolor="buttonface">
<asp:label Font-Bold=true Text="Description : " runat="server" ID="lblDescription" />
<br>
</td>
<td height="60" bgcolor="buttonface">
<asp:label Text='<%#Eval("Description")%>' runat="server" ID="lblDescriptionValue" />
<br>
</td>
</tr>
<tr>
<td height="60" width="30%" bgcolor="buttonface">
<asp:label Font-Bold=true Text="Price : " runat="server" ID="lblPrice" />
<br>
</td>
<td height="60" bgcolor=buttonface>
<asp:label Text='<%#Eval("Price")%>' runat="server" ID="lblPriceValue" />
<br>
</td>
</tr>
</ItemTemplate>
</asp:FormView>
</td>
</tr>
</table>
</asp:Content>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -