Imports System.ComponentModel
Imports System.Data.SqlClient

Public Class usrCntlUSTV


    Dim kundenSQL As New kundenSQL
    Dim SQL As New SQL
    Dim FUNC As New cProgramFunctions
    Dim aktbtn As String = ""
    Dim dgvInitWait As Boolean = False


    Sub init()
        pnlFilter.AutoScroll = False

        With dgvUSTV
            .ClearSelection()

            '      If KdSearchBox1.KdNr <= 0 Then Exit Sub
            If cboJahr._value = "" Then Exit Sub

            .SET_SQL("SELECT TOP (1000) [UStVAn_ID],[UStVAn_KuNr],[UStVAn_Name],LandKz,[UStVAn_ReDatVon],[UStVAn_ReDatBis] ,[UStVAn_3470] ,[UStVAn_Währungscode],[UStVAn_USteuerbetrag],[UStVAn_Erstattungsbetrag],[UStVAn_USteuerbetragEUR],[UStVAn_ErstattungsbetragEUR],[UStVAn_Sachbearbeiter]
                  FROM [tblUStVAntrag] inner join [Länderverzeichnis für die Außenhandelsstatistik] on UStVAn_LandNr=Landnr
                  where UStVAn_ReDatVon>='01.01." & cboJahr._value & "' AND UStVAn_ReDatBis<='31.12." & cboJahr._value & "' " & If(KdSearchBox1.KdNr > 0, " and UStVAn_KuNr=" & KdSearchBox1.KdNr & "", "") & "
                  order by UStVAn_KuNr,UStVAn_Name,LandKz,[UStVAn_ReDatVon]", "FMZOLL")
            .LOAD()
            .RowTemplate.Height = 20
            .AllowUserToOrderColumns = False
            .AllowUserToResizeRows = False

            If .Columns.Count > 0 Then

                .Columns("UStVAn_ID").Visible = False
                .Columns("UStVAn_KuNr").HeaderText = "KundenNr"
                .Columns("UStVAn_Name").MinimumWidth = 70


                .Columns("UStVAn_Name").HeaderText = "Firma"
                .Columns("UStVAn_Name").Width = 200
                ' .Columns("UStVAn_Name").MinimumWidth = 150
                ' .Columns("UStVAn_Name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

                .Columns("LandKz").Width = 60

                .Columns("UStVAn_ReDatVon").HeaderText = "Von"
                .Columns("UStVAn_ReDatVon").Width = 100

                .Columns("UStVAn_ReDatBis").HeaderText = "Bis"
                .Columns("UStVAn_ReDatBis").Width = 100

                .Columns("UStVAn_3470").HeaderText = "3470"
                .Columns("UStVAn_3470").Width = 150
                .Columns("UStVAn_3470").DefaultCellStyle.Format = "N2"
                .Columns("UStVAn_3470").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

                .Columns("UStVAn_Währungscode").HeaderText = "Währung"
                .Columns("UStVAn_Währungscode").Width = 80

                .Columns("UStVAn_USteuerbetrag").HeaderText = "USt-Betrag"
                .Columns("UStVAn_USteuerbetrag").Width = 150
                .Columns("UStVAn_USteuerbetrag").DefaultCellStyle.Format = "N2"
                .Columns("UStVAn_USteuerbetrag").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

                .Columns("UStVAn_Erstattungsbetrag").HeaderText = "Erstattung-Betrag"
                .Columns("UStVAn_Erstattungsbetrag").Width = 150
                .Columns("UStVAn_Erstattungsbetrag").DefaultCellStyle.Format = "N2"
                .Columns("UStVAn_Erstattungsbetrag").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

                .Columns("UStVAn_ErstattungsbetragEUR").HeaderText = "Erstattung-Betrag  EUR"
                .Columns("UStVAn_ErstattungsbetragEUR").Width = 150
                .Columns("UStVAn_ErstattungsbetragEUR").DefaultCellStyle.Format = "N2"
                .Columns("UStVAn_ErstattungsbetragEUR").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

                .Columns("UStVAn_USteuerbetragEUR").HeaderText = "USt-Betrag EUR"
                .Columns("UStVAn_USteuerbetragEUR").Width = 150
                .Columns("UStVAn_USteuerbetragEUR").DefaultCellStyle.Format = "N2"
                .Columns("UStVAn_USteuerbetragEUR").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

                .Columns("UStVAn_Sachbearbeiter").HeaderText = "Sachbearbeiter"
                .Columns("UStVAn_Sachbearbeiter").MinimumWidth = 150
                .Columns("UStVAn_Sachbearbeiter").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            End If


        End With

    End Sub

    Private Sub usrCntlVERAGCard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' btnFilter.Left = Panel4.Width - btnFilter.Width
        KdSearchBox1.initKdBox(Me.FindForm)
        init()
        cboJahr.Items.Clear()
        For i = 0 To 10
            cboJahr.Items.Add(New VERAG_PROG_ALLGEMEIN.MyListItem(Now.Year - i, Now.Year - i))
        Next
        cboJahr.SelectedIndex = 0


        If Not VERAG_PROG_ALLGEMEIN.cBerechtignunen.CHECK_BERECHTIGUNG_bool("MDM_Leistungen_bearbeiten", Me.FindForm) Then
            FlatButton1.Enabled = False
            FlatButton2.Enabled = False
            Button14.Enabled = False
        End If
        '   Panel3.Height = Me.Height / 2 + 300
    End Sub


    Private Sub dgvUSTV_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvUSTV.CellDoubleClick
        If dgvUSTV.SelectedRows.Count > 0 Then

            Dim f As New frmMDM_USTVAntrag(dgvUSTV.SelectedRows(0).Cells("UStVAn_ID").Value)
            f.ShowDialog(Me)
        End If
    End Sub

    Private Sub cboJahr_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboJahr.SelectedIndexChanged
        init()
    End Sub

    Private Sub KdSearchBox1_PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Handles KdSearchBox1.PropertyChanged
        init()
    End Sub
End Class
