📄 frmfavourite.vb
字号:
Imports System.Data.SqlServerCe
Imports System.Data.SqlServerCe.SqlCeException
Imports System.Xml
Imports System.Reflection
Imports System.io
Imports System.text
Public Class frmFavourite
Inherits System.Windows.Forms.Form
Dim oMyFav As New clsMyFavourite
Dim mAction As Integer
Dim mKey As Integer
Dim sCaption As String = "My Favourite"
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cmdOK As System.Windows.Forms.Button
Friend WithEvents cmdClose As System.Windows.Forms.Button
Friend WithEvents lblCaption As System.Windows.Forms.Label
Friend WithEvents lblRemarks As System.Windows.Forms.Label
Friend WithEvents lblURL As System.Windows.Forms.Label
Friend WithEvents txtCaption As System.Windows.Forms.TextBox
Friend WithEvents txtRemarks As System.Windows.Forms.TextBox
Friend WithEvents txtURL As System.Windows.Forms.TextBox
Friend WithEvents mnuMain As System.Windows.Forms.MainMenu
Private Sub InitializeComponent()
Me.lblCaption = New System.Windows.Forms.Label
Me.lblRemarks = New System.Windows.Forms.Label
Me.lblURL = New System.Windows.Forms.Label
Me.txtCaption = New System.Windows.Forms.TextBox
Me.txtRemarks = New System.Windows.Forms.TextBox
Me.txtURL = New System.Windows.Forms.TextBox
Me.cmdOK = New System.Windows.Forms.Button
Me.mnuMain = New System.Windows.Forms.MainMenu
Me.cmdClose = New System.Windows.Forms.Button
'
'lblCaption
'
Me.lblCaption.Location = New System.Drawing.Point(10, 9)
Me.lblCaption.Size = New System.Drawing.Size(70, 16)
Me.lblCaption.Text = "Caption"
'
'lblRemarks
'
Me.lblRemarks.Location = New System.Drawing.Point(10, 104)
Me.lblRemarks.Size = New System.Drawing.Size(70, 16)
Me.lblRemarks.Text = "Remarks"
'
'lblURL
'
Me.lblURL.Location = New System.Drawing.Point(10, 50)
Me.lblURL.Size = New System.Drawing.Size(70, 16)
Me.lblURL.Text = "URL"
'
'txtCaption
'
Me.txtCaption.Location = New System.Drawing.Point(84, 6)
Me.txtCaption.MaxLength = 50
Me.txtCaption.Multiline = True
Me.txtCaption.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtCaption.Size = New System.Drawing.Size(152, 34)
Me.txtCaption.Text = ""
'
'txtRemarks
'
Me.txtRemarks.Location = New System.Drawing.Point(84, 104)
Me.txtRemarks.MaxLength = 100
Me.txtRemarks.Multiline = True
Me.txtRemarks.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtRemarks.Size = New System.Drawing.Size(152, 89)
Me.txtRemarks.Text = ""
'
'txtURL
'
Me.txtURL.Location = New System.Drawing.Point(84, 46)
Me.txtURL.MaxLength = 100
Me.txtURL.Multiline = True
Me.txtURL.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtURL.Size = New System.Drawing.Size(152, 51)
Me.txtURL.Text = ""
'
'cmdOK
'
Me.cmdOK.Location = New System.Drawing.Point(184, 208)
Me.cmdOK.Size = New System.Drawing.Size(48, 20)
Me.cmdOK.Text = "OK"
'
'cmdClose
'
Me.cmdClose.Location = New System.Drawing.Point(130, 208)
Me.cmdClose.Size = New System.Drawing.Size(48, 20)
Me.cmdClose.Text = "Close"
'
'frmFavourite
'
Me.ClientSize = New System.Drawing.Size(242, 287)
Me.Controls.Add(Me.cmdClose)
Me.Controls.Add(Me.cmdOK)
Me.Controls.Add(Me.txtURL)
Me.Controls.Add(Me.txtRemarks)
Me.Controls.Add(Me.txtCaption)
Me.Controls.Add(Me.lblURL)
Me.Controls.Add(Me.lblRemarks)
Me.Controls.Add(Me.lblCaption)
Me.MaximizeBox = False
Me.Menu = Me.mnuMain
Me.Text = "My Favourite"
End Sub
#End Region
Public Sub Init(ByVal iAction As Integer, ByVal iId As Integer)
mAction = iAction
mKey = iId
'mKey 1--New, 2--Edit, 3--Delete, 4--View (Trap it from the frmMain menu event)
Initcontrols()
If mAction = 2 Or mAction = 3 Or mAction = 4 Then
'Get the details and fill it
FillData()
If mAction = 2 Then
Me.Text = sCaption & " - Edit"
ElseIf mAction = 3 Then
Me.Text = sCaption & " - Delete"
ElseIf mAction = 4 Then
Me.Text = sCaption & " - View"
End If
Else
Me.Text = sCaption & " - New"
End If
Me.Show()
End Sub
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
'Save the data
Dim sSql As String
Dim oTrn As New clsMyFavouritetrn
Dim oUtil As New Utility
Dim obj As New frmMain
Dim Id As Integer
Try
If mAction = 1 Then
Id = oTrn.GetFavId()
sSql = "Insert Into MyFavourite (ID, Caption, URL, Remarks, UpdatedOn)"
sSql &= " Values("
sSql &= Id & ",'"
sSql &= txtCaption.Text & "','"
sSql &= txtURL.Text & "','"
sSql &= txtRemarks.Text & "',"
sSql &= "GETDATE())"
oTrn.Apply(sSql)
MsgBox("Data added successfully", MsgBoxStyle.Information)
ElseIf mAction = 2 Then
sSql = "Update MyFavourite Set "
sSql &= " Caption='" & txtCaption.Text & "',"
sSql &= " URL='" & txtURL.Text & "',"
sSql &= " Remarks='" & txtRemarks.Text & "',"
sSql &= " UpdatedOn=GETDATE()"
sSql &= " Where Id=" & mKey & ""
oTrn.Apply(sSql)
MsgBox("Data Updates successfully", MsgBoxStyle.Information)
ElseIf mAction = 3 Then
sSql = "Delete MyFavourite "
sSql &= " Where Id=" & mKey & ""
oTrn.Apply(sSql)
MsgBox("Data Deleted successfully", MsgBoxStyle.Information)
End If
obj.Show()
obj.DataView()
obj.Refresh()
Me.Close()
Catch Err As Exception
MsgBox(Err.ToString)
Finally
obj = Nothing
oTrn = Nothing
End Try
End Sub
Private Sub FillData()
Dim Reader As SqlCeDataReader
Try
Reader = oMyFav.Request("MYFAVOURITE", mKey)
'Finally, add the record to the ListView control:
While Reader.Read
txtCaption.Text = Trim(Reader.Item("Caption").ToString)
txtURL.Text = Trim(Reader.Item("URL").ToString)
txtRemarks.Text = Trim(Reader.Item("Remarks").ToString)
End While
If mAction = 3 Or mAction = 4 Then
txtCaption.ReadOnly = True
txtURL.ReadOnly = True
txtRemarks.ReadOnly = True
End If
Catch err As Exception
MsgBox(err.ToString)
Finally
Reader.Close()
End Try
End Sub
Private Sub Initcontrols()
txtCaption.Text = ""
txtURL.Text = ""
txtRemarks.Text = ""
If mAction = 2 Then
cmdOK.Text = "Update"
ElseIf mAction = 3 Then
cmdOK.Text = "Delete"
ElseIf mAction = 4 Then
cmdOK.Enabled = False
End If
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
Dim obj As New frmMain
obj.Show()
obj.DataView()
obj.Refresh()
Me.Close()
obj = Nothing
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -