2013-01-11 4 views
0

양식이 비어 있는지 확인하고 싶습니다 ... 긴 코드가 있습니다. 나는 아래 주어진 코드를 제공한다.VB.NET의 빈 컨트롤 확인

Public totflag As Boolean 
Private Sub BTNSAVE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTNSAVE.Click 
    CheckMyControls() 
    If totflag = False Then 
     MessageBox.Show("Give Compleate Data!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning) 
     coloring() 
    ElseIf totflag = True Then 
     MessageBox.Show("Success", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information) 
    End If 
End Sub 
Public Sub coloring() 
    Dim txt, cmb, mtxt, rtxt As Control 
    For Each txt In EMPGBDATA.Controls 
     If TypeOf txt Is TextBox Then 
      If txt.Text = "" Then 
       txt.BackColor = Color.Red 
      End If 
     End If 
    Next 
    For Each cmb In EMPGBDATA.Controls 
     If TypeOf cmb Is ComboBox Then 
      If cmb.Text = "Select" Then 
       cmb.BackColor = Color.Red 
      End If 
     End If 
    Next 
    For Each mtxt In EMPGBDATA.Controls 
     If TypeOf mtxt Is MaskedTextBox Then 
      If mtxt.Text = "" AndAlso mtxt.Name <> "MTXTPFESI" Then 
       mtxt.BackColor = Color.Red 
      End If 
     End If 
    Next 
    For Each rtxt In EMPGBDATA.Controls 
     If TypeOf rtxt Is RichTextBox Then 
      If rtxt.Text = "" Then 
       rtxt.BackColor = Color.Red 
      End If 
     End If 
    Next 

End Sub 
Public Function CheckMyControls() As Boolean 
    Dim txt, cmb, mtxt, rtxt As Control 
    Dim flagtxt, flagcmb, flagmtxt, flagrtxt As Boolean 
    flagtxt = False 
    For Each txt In EMPGBDATA.Controls 
     If TypeOf txt Is TextBox Then 
      If txt.Text = "" Then 
       flagtxt = True 
      End If 
     End If 
    Next 
    flagcmb = False 
    For Each cmb In EMPGBDATA.Controls 
     If TypeOf cmb Is ComboBox Then 
      If cmb.Text = "Select" Then 
       flagcmb = True 
      End If 
     End If 
    Next 
    flagmtxt = False 
    For Each mtxt In EMPGBDATA.Controls 
     If TypeOf mtxt Is MaskedTextBox Then 
      If mtxt.Text = "" AndAlso mtxt.Name <> "MTXTPFESI" Then 
       flagmtxt = True 
      End If 
     End If 
    Next 
    flagrtxt = False 
    For Each rtxt In EMPGBDATA.Controls 
     If TypeOf rtxt Is RichTextBox Then 
      If rtxt.Text = "" Then 
       flagrtxt = True 
      End If 
     End If 
    Next 
    If flagtxt = True Or flagcmb = True Or flagmtxt = True Or flagrtxt = True Then 
     totflag = False 
    Else 
     totflag = True 
    End If 
    Return totflag 
End Function 

실제로 하나의 PFESI 텍스트 상자를 확인하고 싶지 않습니다. 비어 있거나없는 경우. 마스크 된 텍스트 상자입니다. 내 문제는 모든 컨트롤에 데이터가있는 제출 버튼을 누르면 메시지 상자에 "Complete Data!"라는 메시지가 표시됩니다. 데이터가없는 컨트롤에서도 동일한 메시지가 표시됩니다. 코드를 확인하고 해결책을 찾으십시오.

답변

0

너무 복잡하게하려고합니다. 나는 컴퓨터 앞에 그래서 아마 코드에서 아닙니다 사소한 오류가 : 나는 모든 내 코드에서 검사와 다른 부분을 추가

If CheckMyControls() = False Then 
     MessageBox.Show("Give Compleate Data!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning) 
     coloring() 
    Else 
     MessageBox.Show("Success", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information) 
    End If 

End Sub 

Public Sub coloring() 
    For Each cntrl In Me.Controls 
     Select Case cntrl.GetType 
      Case GetType(ComboBox) 
       If cntrl.Text = "Select" Then 
        cntrl.BackColor = Color.Red 
        Exit For 
       End If 
      Case GetType(MaskedTextBox) 
       If cntrl.Text = "" AndAlso cntrl.Name <> "MTXTPFESI" Then 
        cntrl.BackColor = Color.Red 
       End If 
      Case Else 
       If cntrl.Text = "" Then 
        cntrl.BackColor = Color.Red 
       End If 

     End Select 
    Next 

End Sub 

Public Function CheckMyControls() As Boolean 
    Dim bEmptyControlFlag As Boolean 
    For Each cntrl In Me.Controls 
     Select Case cntrl.GetType 
      Case GetType(ComboBox) 
       If cntrl.Text = "Select" Then 
        bEmptyControlFlag = True 
        Exit For 
       End If 
      Case Else 
       If cntrl.Text = "" Then 
        bEmptyControlFlag = True 
       End If 

     End Select 
    Next 

    Return Not bEmptyControlFlag 
End Function 
+0

를 .... 그것은 당신이 재생을위한 미세 .... 고맙습니다 작동 .. .. – Thanzeem