PhoneLog2

 

FrmPhoneLog

 

Option Explicit On

 

Public Class frmPhoneLog

Inherits System.Windows.Forms.Form

Private PhoneCall As PhoneCall

Dim PhoneCalls As New PhoneCalls

Dim s_LogNo As Integer

 

Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click

If txtCaller.Text <> "" Then

txtTimeCall.Enabled = True

txtTimeCall.Text = CStr(Date.Now)

PhoneCalls.Add(CDate(txtTimeCall.Text), txtCaller.Text, txtSubject.Text)

txtLogNo.Enabled = True

txtLogNo.Text = PhoneCalls.Last

txtLogNo.Enabled = False

txtTimeCall.Enabled = False

txtCaller.Enabled = False

txtSubject.Enabled = False

btnNewCall.Focus()

Else

txtCaller.Focus()

End If

End Sub

 

Private Sub btnNewCall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewCall.Click

txtLogNo.Enabled = True

txtLogNo.Text = ""

txtLogNo.Enabled = False

txtTimeCall.Enabled = True

txtTimeCall.Text = ""

txtTimeCall.Enabled = False

txtCaller.Enabled = True

txtCaller.Text = ""

txtSubject.Enabled = True

txtSubject.Text = ""

txtCaller.Focus()

End Sub

 

Private Sub btnListCalls_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnListCalls.Click

lstCalls.Items.Clear()

For Each PhoneCall In PhoneCalls

Dim phoneline As String

phoneline = CStr(PhoneCall.LogNo) & " " _

& CStr(PhoneCall.CallTime) & " " _

& PhoneCall.Caller & " " _

& PhoneCall.Subject

lstCalls.Items.Add(phoneline)

lstCalls.Refresh()

Next PhoneCall

btnNewCall.Focus()

End Sub

 

Private Sub btnRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetrieve.Click

Dim strLogNo As String

strLogNo = InputBox("Enter Log # of call to be retriveved")

Try

PhoneCall = PhoneCalls.Item(strLogNo)

Catch

Dim ErrMsg As String

ErrMsg = CStr(Err.Number) & " " & Err.Source & " " & Err.Description

MsgBox(ErrMsg)

End Try

txtLogNo.Enabled = True

txtLogNo.Text = PhoneCall.LogNo

txtLogNo.Enabled = False

txtTimeCall.Enabled = True

txtTimeCall.Text = PhoneCall.CallTime

txtTimeCall.Enabled = False

txtCaller.Enabled = True

txtCaller.Text = PhoneCall.Caller

txtCaller.Enabled = False

txtSubject.Enabled = True

txtSubject.Text = PhoneCall.Subject

txtSubject.Enabled = False

End Sub

End Class

 

PhoneCall.vb

 

Public Class PhoneCall

Private m_LogNo As Integer

Private m_LogTime As DateTime

Private m_CallTime As DateTime

Private m_Caller As String

Private m_Subject As String

 

Public Sub New(ByVal s_LogNo As Integer)

m_LogNo = s_LogNo

m_LogTime = Date.Now

End Sub

 

Public ReadOnly Property LogNo() As Integer

Get

Return m_LogNo

End Get

End Property

 

Public ReadOnly Property LogTime() As DateTime

Get

Return m_LogTime

End Get

End Property

 

Public Property CallTime() As DateTime

Get

Return m_CallTime

End Get

Set(ByVal s_Calltime As DateTime)

m_CallTime = s_Calltime

End Set

End Property

 

Public Property Caller() As String

Get

Return m_Caller

End Get

Set(ByVal s_Caller As String)

m_Caller = s_Caller

End Set

End Property

 

Public Property Subject() As String

Get

Return m_Subject

End Get

Set(ByVal s_Subject As String)

m_Subject = s_Subject

End Set

End Property

 

Protected Overrides Sub Finalize()

MyBase.Finalize()

End Sub

End Class

 

PhoneCalls.vb

 

ption Explicit On

 

Public Class PhoneCalls

Private colPhoneCalls As Collection

Private LastPhoneCall As PhoneCall

Private LogNoKey As Integer

 

Public Enum PhoneCallsErrors

DupKey = vbObjectError + 512 + 1001

KeyNF = vbObjectError + 512 + 1002

End Enum

 

Public Sub New()

colPhoneCalls = New Collection

LogNoKey = 1

End Sub

 

Protected Overrides Sub Finalize()

colPhoneCalls = Nothing

MyBase.Finalize()

End Sub

 

Public Sub Add(ByVal v_CallTime As DateTime, ByVal v_Caller As String, ByVal v_Subject As String)

Dim NewPhoneCall As New PhoneCall(LogNoKey)

With NewPhoneCall

.Caller = v_Caller

.Subject = v_Subject

.CallTime = v_CallTime

End With

Try

colPhoneCalls.Add(NewPhoneCall, CStr(NewPhoneCall.LogNo))

LastPhoneCall = NewPhoneCall

LogNoKey = LogNoKey + 1

Catch

Dim ErrDesc As String

ErrDesc = "Phone call with LogNo. " & CStr(NewPhoneCall.LogNo) & " already exists."

Err.Raise(PhoneCallsErrors.DupKey, "PhoneCalls", ErrDesc)

End Try

 

 

 

End Sub

 

Public Function Item(ByVal v_LogNo As String) As PhoneCall

Try

Item = colPhoneCalls.Item(v_LogNo)

Catch

Dim ErrDesc As String

ErrDesc = "No phone call with LogNo '" & v_LogNo & "' exists."

Err.Raise(PhoneCallsErrors.KeyNF, "PhoneCalls", ErrDesc)

End Try

 

End Function

 

Public Function Last() As String

Last = CStr(LastPhoneCall.LogNo)

End Function

 

Public Sub Remove(ByVal v_LogNo As String)

Try

colPhoneCalls.Remove(v_LogNo)

Catch

Dim ErrDesc As String

ErrDesc = "No phone call with this LogNo " & v_LogNo & " exists."

Err.Raise(PhoneCallsErrors.KeyNF, "PhoneCalls", ErrDesc)

End Try

 

End Sub

 

Public Function Count() As Long

Count = colPhoneCalls.Count

End Function

 

Public Function GetEnumerator() As IEnumerator

Return colPhoneCalls.GetEnumerator

End Function

 

End Class

 

PhoneLog DB

 

FrmPhoneLog

 

Option Explicit On

 

Public Class frmPhoneLog

Inherits System.Windows.Forms.Form

Private _PhoneCall As PhoneCall

Dim _PhoneCalls As New PhoneCalls

 

Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click

If txtCaller.Text <> "" Then

txtTimeCall.Enabled = True

txtTimeCall.Text = CStr(Date.Now)

_PhoneCall = _PhoneCalls.Add(CDate(txtTimeCall.Text), txtCaller.Text, txtSubject.Text)

txtLogNo.Enabled = True

txtLogNo.Text = _PhoneCall.LogNo

txtLogNo.Enabled = False

txtTimeCall.Enabled = False

txtCaller.Enabled = False

txtSubject.Enabled = False

btnNewCall.Focus()

Else

txtCaller.Focus()

End If

End Sub

 

Private Sub btnNewCall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewCall.Click

txtLogNo.Enabled = True

txtLogNo.Text = ""

txtLogNo.Enabled = False

txtTimeCall.Enabled = True

txtTimeCall.Text = ""

txtTimeCall.Enabled = False

txtCaller.Enabled = True

txtCaller.Text = ""

txtSubject.Enabled = True

txtSubject.Text = ""

txtCaller.Focus()

End Sub

 

Private Sub btnListCalls_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnListCalls.Click

lstCalls.Items.Clear()

For Each _PhoneCall In _PhoneCalls

Dim phoneline As String

phoneline = CStr(_PhoneCall.LogNo) & " " _

& CStr(_PhoneCall.CallTime) & " " _

& _PhoneCall.Caller & " " _

& _PhoneCall.Subject

lstCalls.Items.Add(phoneline)

lstCalls.Refresh()

Next _PhoneCall

btnNewCall.Focus()

End Sub

 

Private Sub btnRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetrieve.Click

Dim strLogNo As String

strLogNo = InputBox("Enter Log # of call to be retriveved")

Try

_PhoneCall = _PhoneCalls.Item(strLogNo)

Catch

Dim ErrMsg As String

ErrMsg = CStr(Err.Number) & " " & Err.Source & " " & Err.Description

MsgBox(ErrMsg)

End Try

txtLogNo.Enabled = True

txtLogNo.Text = _PhoneCall.LogNo

txtLogNo.Enabled = False

txtTimeCall.Enabled = True

txtTimeCall.Text = _PhoneCall.CallTime

txtTimeCall.Enabled = False

txtCaller.Enabled = True

txtCaller.Text = _PhoneCall.Caller

txtCaller.Enabled = False

txtSubject.Enabled = True

txtSubject.Text = _PhoneCall.Subject

txtSubject.Enabled = False

 

End Sub

 

Protected Overrides Sub Finalize()

MyBase.Finalize()

End Sub

End Class

 

PhoneCall

 

ublic Class PhoneCall

Private m_LogNo As Integer

Private m_LogTime As DateTime

Private m_CallTime As DateTime

Private m_Caller As String

Private m_Subject As String

 

Public Sub New(ByVal s_LogNo As Integer, Optional ByVal s_LogTime As DateTime = #1/1/2000#)

m_LogNo = s_LogNo

If s_LogTime <> #1/1/2000# Then

m_LogTime = s_LogTime

Else

m_LogTime = Date.Now

End If

End Sub

 

Public ReadOnly Property LogNo() As Integer

Get

Return m_LogNo

End Get

End Property

 

Public ReadOnly Property LogTime() As DateTime

Get

Return m_LogTime

End Get

End Property

 

Public Property CallTime() As DateTime

Get

Return m_CallTime

End Get

Set(ByVal s_Calltime As DateTime)

m_CallTime = s_Calltime

End Set

End Property

 

Public Property Caller() As String

Get

Return m_Caller

End Get

Set(ByVal s_Caller As String)

m_Caller = s_Caller

End Set

End Property

 

Public Property Subject() As String

Get

Return m_Subject

End Get

Set(ByVal s_Subject As String)

m_Subject = s_Subject

End Set

End Property

 

Protected Overrides Sub Finalize()

MyBase.Finalize()

End Sub

End Class

 

PhoneCalls

 

ption Explicit On

 

Public Class PhoneCalls

 

Private colPhoneCalls As New Collection

Private PhoneCallsDS As New DataSet

Private PhoneCallsDT As DataTable

Private LogNoKey As Integer

 

Private CurrPath As String = System.Environment.CurrentDirectory

Private ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source = " & CurrPath & "\PhoneLog.mdb"

Private SQLQuery As String = "SELECT * FROM PhoneCalls"

Private PLAdapter As New OleDb.OleDbDataAdapter(SQLQuery, ConnStr)

Private PKCmdBldr As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(PLAdapter)

 

Public Enum PhoneCallsErrors

DupKey = vbObjectError + 512 + 1001

KeyNF = vbObjectError + 512 + 1002

End Enum

 

Public Sub New()

PLAdapter.Fill(PhoneCallsDS)

PhoneCallsDT = PhoneCallsDS.Tables(0)

For Each PLRec As DataRow In PhoneCallsDT.Rows

Dim NewPhoneCall As New PhoneCall(PLRec("LogNo"), PLRec("LogTime"))

With NewPhoneCall

.Caller = PLRec("Caller")

.Subject = PLRec("Subject")

.CallTime = PLRec("CallTime")

End With

Try

colPhoneCalls.Add(NewPhoneCall, CStr(NewPhoneCall.LogNo))

If NewPhoneCall.LogNo > LogNoKey Then

LogNoKey = NewPhoneCall.LogNo

End If

Catch

Dim ErrDesc As String

ErrDesc = "Phone call with LogNo. " & CStr(NewPhoneCall.LogNo) & " already exists."

Err.Raise(PhoneCallsErrors.DupKey, "PhoneCalls", ErrDesc)

End Try

Next

LogNoKey = LogNoKey + 1

End Sub

 

Protected Overrides Sub Finalize()

colPhoneCalls = Nothing

MyBase.Finalize()

End Sub

 

Public Function Add(ByVal v_CallTime As DateTime, ByVal v_Caller As String, ByVal v_Subject As String)

Dim NewPhoneCall As New PhoneCall(LogNoKey)

With NewPhoneCall

.Caller = v_Caller

.Subject = v_Subject

.CallTime = v_CallTime

End With

Try

colPhoneCalls.Add(NewPhoneCall, CStr(NewPhoneCall.LogNo))

Dim NewPLRec As DataRow = PhoneCallsDT.NewRow

With NewPhoneCall

NewPLRec("LogNo") = .LogNo

NewPLRec("CallTime") = .CallTime

NewPLRec("Caller") = .Caller

NewPLRec("Subject") = .Subject

NewPLRec("LogTime") = .LogTime

End With

PhoneCallsDT.Rows.Add(NewPLRec)

PLAdapter.Update(PhoneCallsDS)

LogNoKey = LogNoKey + 1

Return NewPhoneCall

Catch

Dim ErrDesc As String

ErrDesc = "Phone call with LogNo. " & CStr(NewPhoneCall.LogNo) & " already exists."

Err.Raise(PhoneCallsErrors.DupKey, "PhoneCalls", ErrDesc)

End Try

 

End Function

 

Public Function Item(ByVal v_LogNo As String) As PhoneCall

Try

Item = colPhoneCalls.Item(v_LogNo)

Catch

Dim ErrDesc As String

ErrDesc = "No phone call with LogNo '" & v_LogNo & "' exists."

Err.Raise(PhoneCallsErrors.KeyNF, "PhoneCalls", ErrDesc)

End Try

 

End Function

 

Public Function Count() As Long

Count = colPhoneCalls.Count

End Function

 

Public Function GetEnumerator() As IEnumerator

Return colPhoneCalls.GetEnumerator

End Function

 

 

End Class