我正在尝试通过检测页面的逗号来更改或更新代码,
下面的代码展示了如何用逗号输入页面,
示例:1,2,5,3,8 不接受 0 或大于最大页数
我要问的是添加可以接受的代码:
2-5,8,9
或
8,9,2-5
或
2-5,8-10
所以这意味着,要打印的页面是 2,3,4,5,8,9,10
但它不会接受像 2-5,4,8,9 这样的输入,因为 4 已经在 2-5 中使用
如果这可能很难,那么可以输入一个简单的范围,例如:2-5 并且没有逗号,所以用户不能输入逗号,如果他们想输入逗号,那么 - 符号也不能输入。
''CODED By: Chris, Combined to MackieChan solution
Public Function isCELLPageNumb(ByRef valyo As String, ByVal origMaxPage As Integer) As Boolean
Dim rgxNumberWithComma As New System.Text.RegularExpressions.Regex("^([0-9]+,?)+$")
Dim match = rgxNumberWithComma.Match(valyo)
If Not match.Success Then
Return False
Else
Dim numbers As New List(Of Integer) 'will store added numbers
For Each Item In valyo.Split(","c)
Dim intValue As Integer
'Check if number is a valid integer
'Check if number is 0
'Check if number has already added the number list
'Check if number is greater that MaxPage
If Not Integer.TryParse(Item, intValue) _
OrElse intValue > origMaxPage _
OrElse intValue = 0 _
OrElse numbers.Contains(intValue) Then
Return False
Else
'Item is valid, continue
numbers.Add(intValue)
End If
Next
End If
Return True
End Function
Private Sub DbGridPapers_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DbGridPapers.CellEndEdit
Dim pagestoprint As String = Nothing
Try
pagestoprint = DbGridPapers.Rows(e.RowIndex).Cells(1).Value.ToString
Catch ex As Exception
End Try
If (e.ColumnIndex = 1) And (pagestoprint IsNot Nothing) Then
If Not isCELLPageNumb(DbGridPapers.Rows(e.RowIndex).Cells(1).Value, OrigPage(e.RowIndex)) Then
MyThreadedControl(lbltest, "Text", "INVALID INPUT FOR [PAGES] AT ROW " & (e.RowIndex).ToString)
DbGridPapers.Rows(e.RowIndex).Cells(1).Value = OrigPage(e.RowIndex)
Return
Else
MyThreadedControl(lbltest, "Text", "The Maximum Page is:" & OrigPage(e.RowIndex).ToString)
End If
Dim pageDest As String = Nothing
If Me.btnpaperpay.Enabled Then
pageDest = DbGridPapers.Rows(e.RowIndex).Tag & "\"
Else
pageDest = docPrintnationPath & "\"
End If
Dim filename As String = pageDest & DbGridPapers.Rows(e.RowIndex).HeaderCell.Value.ToString
Dim OldRegularPrice As Decimal = DbGridPapers.Rows(e.RowIndex).Cells(3).Value
Dim FILEpages As New List(Of Integer)
''IF , AND - CAN BE MIX TO GET THE PAGE THEN ITS BETTER, AND I HAVE TO UPDATE THE CODE HERE ALSO.
If pagestoprint.Split(",").Length > 1 Then 'Split Length is +1 based
Dim pageFILES() As String = pagestoprint.Split(",")
For Each filePids As Integer In pageFILES
FILEpages.Add(filePids) ''GET range in comma sample page1,page3,page8,page2
Next
ElseIf pagestoprint.Split("-").Length > 1 Then 'Split Length is +1 based
Dim pageFILES() As String = pagestoprint.Split("-")
For page As Integer = pageFILES(0) To pageFILES(1)
FILEpages.Add(page) ''GET range sample pages2 to page5
Next
Else
Dim pages As Integer
If (Integer.TryParse(pagestoprint, pages)) Then
If pages = OrigPage(e.RowIndex) Then
DbGridPapers.Rows(e.RowIndex).Cells(2).Value = OrigImage(e.RowIndex)
DbGridPapers.Rows(e.RowIndex).Cells(3).Value = OrigPay(e.RowIndex)
DbGridPapers.Rows(e.RowIndex).Cells(4).Value = OrigCountedImage(e.RowIndex)
GoTo pCounter ''Return Original Cells Value
Else
FILEpages.Add(pages)''GET single page only
End If
End If
End If
pCounter:
Dim paperToTpay As Decimal = txtpapertotpay.Text.Substring(0, txtpapertotpay.Text.LastIndexOf(" "))
paperToTpay -= OldRegularPrice
paperToTpay += DbGridPapers.Rows(e.RowIndex).Cells(3).Value
MyThreadedControl(txtpapertotpay, "Text", paperToTpay.ToString & " dollar(s)")
End If
End Sub
我认为它非常难。