(c) 2003 Visual Studio Magazine 
Fawcette Technical Publications


VB.NET	Display Product Reviews
Listing 1	ListReviews' Render method prepares the HTML code to display either a table with every review for the specified product or only the last review.


If ProductID > 0 Then
	If m_strXMLPath.EndsWith("\") = _
		False Then
		strXMLPath = m_strXMLPath & "\" _
			& m_lProductID.ToString() & _
			".xml"
	Else
		strXMLPath = m_strXMLPath & _
			m_lProductID.ToString() & ".xml"
	End If

m_dsReviews.ReadXml(strXMLPath)
If m_bLastReview = True Then
	m_dsReviews.REVIEW.DefaultView. _
		Sort = "ID_REVIEW DESC"
	Dim dv As DataRowView = _
		m_dsReviews.REVIEW.DefaultView(0) 


VB.NET	Create an Enum Type
Listing 2	This code creates a new Enum type useful for choosing the image output type. The control provides three output types: Book, Music, and Generic.

Public Enum OutputType
	Generic
	Music
	Book
End Enum

<Bindable(True), Category("Appereance"), _
	DefaultValue("OutputType.Generic"), _
	Description(
	"Choose the image type you want to display.")> _
	Property Type() As OutputType
		Get
			Return m_otType
		End Get
		Set(ByVal Value As OutputType)
			m_otType = Value
		End Set
	End Property

VB.NET	Insert a New Review
Listing 3	You add a new review either by appending it to the existing XML product file or by creating a new one.The InsertReview method accepts the author name, the review content, and the vote as parameters.

Public Sub InsertReview(ByVal Author As String, _
	ByVal Review As String, ByVal Vote As Integer)
	Try
		Dim strXMLPath As String

		If ProductID > 0 Then
			If m_strXMLPath.EndsWith("\") = False Then
				strXMLPath = m_strXMLPath & "\" & _
					m_lProductID.ToString() & ".xml"
			Else
				strXMLPath = m_strXMLPath & _
					m_lProductID.ToString() & ".xml"
			End If
			Dim fe As New FileInfo(strXMLPath)
			Dim r As dsReviews.REVIEWRow
			r = m_dsReviews.REVIEW.NewREVIEWRow()
			If fe.Exists() Then
				m_dsReviews.ReadXml(strXMLPath)
				m_dsReviews.REVIEW.DefaultView.Sort _
					= "ID_REVIEW DESC"
				Dim iNewID As Integer = _
					m_dsReviews.REVIEW.DefaultView(0)(0) _
					+ 1
				r.ID_REVIEW = iNewID
			Else
				r.ID_REVIEW = 1
			End If

			r.AUTHOR = Author
			r.REVIEW = Review
			r.VOTE = Vote
			m_dsReviews.REVIEW.AddREVIEWRow(r)
			m_dsReviews.WriteXml(strXMLPath)
		End If
	Catch ex As Exception

	End Try

End Sub


