Public Class frmServiceImportLog

    Sub New()

        InitializeComponent()
    End Sub

    Private Sub frmServiceImportLog_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        SaveLayout()
    End Sub

    Private Sub frmServiceImportLog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Me.TBSERVICE_IMP_LOGTableAdapter.Connection.ConnectionString = My.Settings.ConfigConnectionString
            Me.VWGERAETE_MELDUNG_STATUSTableAdapter.Connection.ConnectionString = My.Settings.ConfigConnectionString
            LoadLayout()
            Load1()
        Catch ex As Exception
            MsgBox("Fehler in Load Form" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub

    Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
        Load1()
    End Sub
    Private Sub Load1()
        Try
            Me.TBSERVICE_IMP_LOGTableAdapter.Fill(Me.MyDataset.TBSERVICE_IMP_LOG)
        Catch ex As Exception
            MsgBox("Fehler in Refresh" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try


    End Sub
    Private Sub Load2()
        Try
            Me.Cursor = Cursors.WaitCursor
            Me.VWGERAETE_MELDUNG_STATUSTableAdapter.Fill(Me.MyDataset.VWGERAETE_MELDUNG_STATUS)
        Catch ex As Exception
            MsgBox("Fehler in Refresh Gerätemeldung" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
        Me.Cursor = Cursors.Default
    End Sub
    Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
        Me.Cursor = Cursors.WaitCursor

        Try
            Me.Cursor = Cursors.WaitCursor
            Dim saveFileDialog1 As New SaveFileDialog()
            With saveFileDialog1
                .Filter = "Excel-Mappe (*.xlsx)|*.xlsx|All files (*.*)|*.*"
                .FilterIndex = 1
                .RestoreDirectory = True
                .Title = "Excel-Speicherort wählen:"
            End With
            If saveFileDialog1.ShowDialog() = DialogResult.OK Then
                GridControl1.ExportToXlsx(saveFileDialog1.FileName)
                MsgBox("Export nach Excel erfolgreich abgeschlossen!", MsgBoxStyle.Information, "Erfolg:")
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler bei tsbExcel_Supplies.Click:")
        End Try
        Me.Cursor = Cursors.Default
    End Sub
    Private Sub SaveLayout()
        Try
            Dim XMLPath = System.IO.Path.Combine(Application.UserAppDataPath(), "frmServiceImportLog_dgv1UserLayout.xml")
            GridControl1.MainView.SaveLayoutToXml(XMLPath)
            XMLPath = System.IO.Path.Combine(Application.UserAppDataPath(), "frmServiceImportLog_dgv2UserLayout.xml")
            GridControl2.MainView.SaveLayoutToXml(XMLPath)
        Catch ex As Exception
            MsgBox("Error while saving custom Layout!" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub LoadLayout()
        Try
            Dim XMLPath = System.IO.Path.Combine(Application.UserAppDataPath(), "frmServiceImportLog_dgv1UserLayout.xml")
            GridControl1.MainView.RestoreLayoutFromXml(XMLPath)
            XMLPath = System.IO.Path.Combine(Application.UserAppDataPath(), "frmServiceImportLog_dgv2UserLayout.xml")
            GridControl2.MainView.RestoreLayoutFromXml(XMLPath)
        Catch notFoundEx As System.IO.FileNotFoundException
            ' MsgBox("Datagridview-Layout could not be loaded. Layout will be saved after closing", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox("Error while loading custom Layout!" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub ToolStripButton7_Click(sender As Object, e As EventArgs) Handles ToolStripButton7.Click
        Load2()
    End Sub
End Class