Imports System
Imports System.Xml
Namespace DrWhoLib
Public Class DrWhoQuotes
Private quoteDoc As XmlDocument
Private quoteCount As Integer
Public Sub New(ByVal fileName As String)
quoteDoc = New XmlDocument()
quoteDoc.Load(fileName)
quoteCount = quoteDoc.DocumentElement.ChildNodes.Count
End Sub
Public Function GetRandomQuote() As Quotation
Dim i As Integer
Dim x As New Random()
i = x.Next(quoteCount - 1)
Return New Quotation(quoteDoc.DocumentElement.ChildNodes(i))
End Function
End Class
Public Class Quotation
Private qSource As String
Public Property Source() As String
Get
Return qSource
End Get
Set(ByVal value As String)
qSource = value
End Set
End Property
Private dteDate As String
Public Property MyDate() As String
Get
Return dteDate
End Get
Set(ByVal value As String)
dteDate = value
End Set
End Property
Private strQuotation As String
Public Property QuotationText() As String
Get
Return strQuotation
End Get
Set(ByVal value As String)
strQuotation = value
End Set
End Property
Public Sub New(ByVal quoteNode As XmlNode)
If quoteNode.SelectSingleNode("source") IsNot Nothing Then
qSource = quoteNode.SelectSingleNode("source").InnerText
End If
If quoteNode.Attributes.GetNamedItem("date") IsNot Nothing Then
dteDate = quoteNode.Attributes.GetNamedItem("date").Value
End If
strQuotation = quoteNode.FirstChild.InnerText
End Sub
End Class
End Namespace
Partial Class DrWhoQuotes
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim quotes As New DrWhoLib.DrWhoQuotes(Server.MapPath("~/doctorWho.xml"))
Dim quote As DrWhoLib.Quotation = quotes.GetRandomQuote()
Response.Write(" " & quote.Source & " ( " & quote.MyDate & ")")
Response.Write("
" & quote.QuotationText & "")
End Sub
End Class
Protected Sub btnCmd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCmd.Click
Dim connectionString As String = WebConfigurationManager.ConnectionStrings("Northwind").ConnectionString
Dim con As SqlConnection = New SqlConnection(connectionString)
Dim sql As String = "DELETE FROM Employees WHERE EmployeeID = " & empID.Text
Dim cmd As New SqlCommand(sql, con)
Try
con.Open()
Dim numAff As Integer = cmd.ExecuteNonQuery()
HtmlContent.Text &= String.Format("
Deleted {0} record(s)
", numAff)
Catch ex As Exception
HtmlContent.Text &= String.Format("Error: {0}
", ex.Message)
Finally
con.Close()
End Try
End Sub
CREATE PROCEDURE InsertEmployee(
@TitleOfCourtesy varchar(25),
@LastName varchar(20),
@FirstName varchar(10),
@EmployeeID int OUTPUT)
AS
INSERT INTO Employees
(TitleOfCourtesy, LastName, FirstName, HireDate)
VALUES (@TitleOfCourtesy, @LastName, @FirstName, GETDATE());
SET @EmployeeID = @@IDENTITY
GO
No comments:
Post a Comment