Public Class Dbbase
    Public Shared Function NVL(ByVal Indata As Object, Optional ByVal nullVal As String = vbNullString) As Object

        Try
            'If Indata = "" Then Return nullVal
            If Indata Is DBNull.Value Then Return nullVal
        Catch ex As Exception
            'MsgBox(ex.Message.ToString)
            Return nullVal
        End Try
        If Indata Is vbNullString Then Return nullVal
        If Indata.ToString.Trim = "" Then Return nullVal
        Return Indata
    End Function
    Public Shared Sub DelCrow(ByVal bs As System.Windows.Forms.BindingSource, ByVal prompt As Boolean)
        If bs.Count < 1 Then Return
        If prompt Then
            If MsgBox("선택된 줄을 삭제하시겠습니까?", MsgBoxStyle.OkCancel Or MsgBoxStyle.Information, "삭제확인") <> MsgBoxResult.Ok Then Return
        End If
        bs.RemoveCurrent()
    End Sub
    Public Shared Function Data_Cancel(ByVal SrcDs As Data.DataSet, Optional ByVal DisplayLabel As Windows.Forms.ToolStripStatusLabel = Nothing) As Boolean
        Dim Retval As Boolean = False
        If SrcDs.HasChanges Then
            If MsgBox("취소된 내용은 다시 되돌리지 못합니다" & vbCrLf & vbCrLf & "계속하시겠습니까?", MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then
                SrcDs.RejectChanges()
                Retval = True
                If Not DisplayLabel Is Nothing Then
                    DisplayLabel.Text = "변경된 내용이 취소되었습니다"
                Else
                    MsgBox("변경된 내용이 취소되었습니다", MsgBoxStyle.Information, "확인")
                End If
            Else
                If Not DisplayLabel Is Nothing Then DisplayLabel.Text = "취소되었습니다"
            End If
        End If
        If Not DisplayLabel Is Nothing Then
            DisplayLabel.Text = "변경된 내용이 없습니다"
        Else
            MsgBox("변경된 내용이 없습니다", MsgBoxStyle.Information, "확인")
        End If
        Return Retval
    End Function
    Public Shared Sub Data_Cancel(ByVal BS As System.Windows.Forms.BindingSource, ByVal SrcDs As Data.DataSet, Optional ByVal SrcDT As Data.DataTable = Nothing, Optional ByVal DisplayLabel As Windows.Forms.ToolStripStatusLabel = Nothing, Optional ByVal prompt As Boolean = True)
        Try
            BS.EndEdit()
        Catch ex As Exception
            If MsgBox("마지막으로 편집중인 데이터에 오류가 있습니다" & vbCrLf & "해당데이터를 취소하시겠습니까?", MsgBoxStyle.OkCancel Or MsgBoxStyle.Critical, "확인") = MsgBoxResult.Ok Then
                BS.CancelEdit()
            End If
        End Try
        If SrcDs.HasChanges Then
            If MsgBox("취소된 내용은 다시 되돌리지 못합니다" & vbCrLf & vbCrLf & "계속하시겠습니까?", MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then
                If SrcDT Is Nothing Then
                    SrcDs.RejectChanges()  '//데이터이없으면 데이터셋을 취소하고
                Else
                    SrcDT.RejectChanges()  '//그렇지않으면 해당 테이블만 취소한다.
                End If

                If Not DisplayLabel Is Nothing Then DisplayLabel.Text = "변경된 내용이 취소되었습니다"
                If prompt Then MsgBox("변경된 내용이 취소되었습니다", MsgBoxStyle.Information, "확인")
            Else
                If Not DisplayLabel Is Nothing Then DisplayLabel.Text = "취소되었습니다"
                If prompt Then MsgBox("복원이 취소되었습니다", MsgBoxStyle.Information, "확인")
            End If
        Else
            If Not DisplayLabel Is Nothing Then DisplayLabel.Text = "변경된 내용이 없습니다"
            If prompt Then MsgBox("변경된 내용이 없습니다", MsgBoxStyle.Information, "확인")
        End If

    End Sub
End Class
