Cac phương thức khác

Một phần của tài liệu Khóa luận tốt nghiệp Toán tin: Lập trình hướng đối tượng trong VB.Net và mô hình MVC (Trang 51 - 58)

AN TOAN Khong thé sử dung được phương thức. thuộc tinh chi thuộc lớp cha

Chương 2. MÔ HÌNH MVC VÀ DO ÁN MINH HỌA

2.1.4.2 Cac phương thức khác

DeleteChar

-Mục đích: xóa một kỷ tự chi ra từ vị trí cấu trúc ColumnL.ine. $6 kỷ tự của

hàng dai nhất thay đổi vì xóa, phương pháp nay nay sinh sự kiện

LongestLineCharCountChanged.

Public Sub DeleteChar(ByVal deletel.ocation As ColumnLine)

Dim oldLongestl.ineCharCount As Integer - Longest! .ineCharCount

list. Item(deleteLocation.Line - 1) =

Getline(deleteLocation.Line).Remove(deletelocation.Column - |. 1) Dim newLongestLineCharCount As Integer - Longestl.ineCharCount

If oldl.ongestL.ineCharCount <> newLongestLineCharCount Then OnLongestLineCharCountChanged(New _

LongestLincEventArgs(newLongestLineCharCount)) End If End Sub

49

GetLine

-Mục dich: Trả lại nội dung của số dòng được chi rõ. Phuong pháp nay phat sinh một ngoại lệ ArgumentOutOfRangeException nếu hàng được chi rõ là

một so âm hay lớn hơn số lượng thành viên trong ArrayList có tên danh sách.

Public Function GetLine(ByVal lineNo As Integer) As String If lineNo > 0 And lineNo <= list.Count Then

Return CType(list.Jtem(lineNo - 1). String)

Else

Throw New ArgumentOutOfRangeFException() End If

End Function

InsertChar

-Mục đích: Chèn một ky tự tại Column ine được chi rõ, phương pháp này nay sinh sự kiện LongestLineCharCountChanged.

Public Sub InsertChar(ByVal c As Char, ByVal insertLocation As ColumnLine)

Dim oửldl.ongestl.ineCharCount As Integer = Longestl.ineCharCount Dim oldline As String © list. tem(insertLocation.Line - L)-EoStrine() Dim newLine As String = -

ðld].ine.Insert(insert[.ocation.Column - |. c.ToString()) list. tem(insertLoeation.Line - 1) = newline

Dim newLongestlincCharCount As Integer = l.ongest[.ineCharCount If oldLongestLineCharCount <> newLongestlineCharCount Then

50

OnLongestLineCharCountChanged(New _

LongestLineEventArgs(newLongestLineCharC ount))

End If End Sub

InsertData

-Mục đích: Chèn một chuỗi tại ColumnLine được chi. Phuong pháp nảy sinh sự

kiện LongestLineCharCountChanged cũng như sự kiện LineCountChanged.

Public Function [nsertData(ByVal data As String.

ByVal insert[.ocation As ColumnLine) As ColumnLine

data = data.Replace{ Microsoft. VisualBasic.Constants.vbL f.ToString(). "")

Dim initiall.ongestLineCharCount As Integer = LongestLineCharCount Dim x As Integer = insertLocation.Column

Dim y As Integer = inscrtLocation.Line

Dim returnInserted As Boolean

‘data may contain carriage return character Dim thisLine As String = GetLine(y)

Dim head As String = thisLine.Substring(0. x - 1) Dim tail As String = thisLine.Substring(x - 1)

list.RemoveAtly - 1)

Dim startIndex As Integer Do While (startIndex >= 0)

Dim endIindex As Integer = _

data. IndexOf(Microsoft. VisualBasic.Constants. vbCr, startIndex) Dim line As String

If endIndex = -! Then

St

line = đata.Substring(startlndex)

‘don't use SetLine bec it can raise event

Dim newL ine As String = head & line & tail

list. Insert(y - 1, newLine)

x head.Length + linc. Length + |

startIndex = endIndex

Else

line - data.Substring(startIndex. endIndex - startindex)

list.Insert(y - 1. head & line) returnlnserted = True

gxyvi

x |

head = ""

startIndex = endIndex + | ‘without carriage return

End If

Loop

Dim currentCharCount As Integer = LongestlineCharCount If initiallongestl.ineCharCount <> currentCharCount Then

Onl ongestl.ineCharCountChanged(New Longest inel:ventArgs{currentCharCount))

End If

If rcturnInserted Then

Onl. ineCountChanged(New LineCountliventArgs(LineCount)) End If

Return New ColumnLine{x. y) Ind Function

InsertLine

Mục địch: chèn một hàng tại hàng được chỉ rõ số dòng. Nó nảy sinh sự kiện LineCountChanged và có thé tang LongestLineCharCountChangedevent:

Public Sub InsertLine(By Val lineNo As Integer, By Val line As String) If lineNo > 0 And lineNo <= list.Count + | Then

Dim oldLongestLineCharCount As Integer = LongestLincCharCount list. Insert(lineNo - 1, line)

OnLineCountChanged(New LineCountlventArgs(LineCount))

Dim newLongestLineCharCount As Integer = LongestLineCharCount If oldLongest!.ineCharCount <> newLongestl.ineCharCount Then

OnLongestLineCharCountChanged( New _

LongestLineEventArgs(newLongestLineCharCount)) End If

End If End Sub

OnColumnChanged

-Mục đích: được dùng bên trong dé nay sinh sự kiện ColumnChanged

Protected Overridable Sub Onl.ineChanged(By Val e As [.ineEventArps) RaiseEvent LineChanged(Me, c)

End Sub

OnLineChanged

-Mục đích: dược dùng bên trong dé nay sinh sự kiện LineChanged :

Protected Overridable Sub OnLineChanged(ByVal e As l.inelventArps)

RaiseEvent LincChanged(Me, e) End Sub

$3

OnLineCountC hanged

-Mục đích: được dùng bền trong dé nay sinh sự kiện LineCountChanged

Protected Overridable Sub Onl.ineCountChanged(By Val e As

LineCounth:ventArgs)

RaiseEvent LineCountChanged(Me, c)

End Sub

OnLongestLineCharCountChanged

-Mục dich: dược dùng bén trong dé nay sinh sự kiện LongestLineCharCount

Protected Overridable Sub OnLongestl.ineCharCountChanged(

ByVal e As LongestLincEventArgs)

RaiseEvent LongestLineCharCountChanged{Me. e)

End Sub

RemoveLine

-Mục đích: loại bỏ một hàng tai hang được chi rõ ghi số dong. nó nay sinh sự

kiện [.ineCountChanged và có thé nay sinh sự kiện LongestLineCharCount,

Public Sub Removcl.ine(ByVail lineNo As Integer, ByVal trigger vent As

Boolean)

If lineNo > 0 And lineNo <= list.Count Then

Dim oldLongestLineCharCount As Integer = L.ongestLineCharCount

list. RemoveAt(lineNo - 1) If triggerEvent Then

Dim newLongestLineCharCount As Integer ~LongestLineCharCount If oldLongestLineCharCount <> newL ongestlineCharCount Then

54

OnLongestLineCharCountChanged( New

LongestLineLventArgs(newLongestLineCharCount))

End If

Onl ineCountChanged(New LineCountEventArgs(LineCount))

End If End If

End Sub

SetLine

-Mục đích: thay đổi hang tai hàng được chi rõ số dòng với chuỗi được chi

rò. Nó co thẻ nảy sinh sự kiện LongestLineCharCountChanged.

Public Sub SctLine(By Val lineNo As Integer, ByVal line As String)

Dim oldLongestlineCharCount As Integer = LongestLineCharCount If (lineNo > 0 And lineNo <= list.Count) Then

list. tem(lineNo - 1) = line End If

Dim newLongestl.ineCharCount As Integer = LongestlineCharCount If oldl_ongestLineCharCount <> newl.ongestl.ineCharCount Then

OnLongestLineCharCountChanged(New _

Longestl.ineEventArgs(newLongestLineCharCount)) End If

End Sub

$$

Một phần của tài liệu Khóa luận tốt nghiệp Toán tin: Lập trình hướng đối tượng trong VB.Net và mô hình MVC (Trang 51 - 58)

Tải bản đầy đủ (PDF)

(136 trang)