Imports System.ComponentModel Imports System.Deployment Imports System.Deployment.Application Public Class frmMain Private _dataPath As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Gaesteliste.xml") 'I should not need this for now - we do not work with mouse pointer rows index for selection but we select them with left-click. ' and with ctrl select (left click, multi-select!) 'Private _rowIndex As Integer = 0 Private Sub LoadWindowPosition() 'http://christ-offer.blogspot.co.at/2012/02/vbnet-remember-application-window-size.html 'TODO: Change this to get loaded from registry. I'm not a huge fan of my.settings ;) Dim ptLocation As System.Drawing.Point = My.Settings.WindowLocation If (ptLocation.X = -1) And (ptLocation.Y = -1) Then Return End If Dim bLocationVisible As Boolean = False For Each S As Screen In Screen.AllScreens If S.Bounds.Contains(ptLocation) Then bLocationVisible = True Exit For End If Next If Not bLocationVisible Then Return End If Me.StartPosition = FormStartPosition.Manual Me.Location = ptLocation Me.Size = My.Settings.WindowSize End Sub Private Sub frmMain_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing Me.GästeDataSet.WriteXml(_dataPath) My.Settings.WindowLocation = Me.Location My.Settings.WindowSize = Me.Size End Sub Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try Me.GästeDataSet.ReadXml(_dataPath) Catch ex As Exception ' do nothing, that file gets created when we close the application ;) End Try LoadWindowPosition() ' Setting colors of grids to some fancy ones :) 'TODO: Save some colors in registry. Me.DataGridView1.RowsDefaultCellStyle.BackColor = Color.Azure Me.DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige Dim Info As UpdateCheckInfo If ApplicationDeployment.IsNetworkDeployed Then Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment Info = AD.CheckForDetailedUpdate If Info.UpdateAvailable Then statusVersionLabel.Text = "Version " & AD.CurrentVersion.ToString & " (Update verfügbar: " & Info.AvailableVersion.ToString & ")" statusVersionLabel.Tag = "update" Else statusVersionLabel.Text = "Version " & AD.CurrentVersion.ToString End If Else statusVersionLabel.Text = "Lokale Version: " & My.Application.Info.Version.ToString End If End Sub Private Sub InfoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InfoToolStripMenuItem.Click Dim oForm As New frmAbout() oForm.ShowDialog() oForm.Dispose() oForm = Nothing End Sub Private Sub OnlineHilfeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OnlineHilfeToolStripMenuItem.Click Process.Start("http://tmsn.at/?tools&gaesteliste&hilfe") End Sub Private Sub UpdateToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UpdateToolStripMenuItem.Click Dim Info As UpdateCheckInfo If ApplicationDeployment.IsNetworkDeployed Then Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment Info = AD.CheckForDetailedUpdate If Info.UpdateAvailable Then statusVersionLabel.Text = "Version " & AD.CurrentVersion.ToString & " (Update verfügbar: " & Info.AvailableVersion.ToString & ")" statusVersionLabel.Tag = "update" If MsgBox("Ein Update ist verfügbar und wird jetzt installiert." + Chr(13) + "Die Anwendung wird danach neu gestartet.", vbOKCancel) = vbOK Then AD.Update() System.Windows.Forms.Application.Restart() End If Else statusVersionLabel.Text = "Version " & AD.CurrentVersion.ToString MsgBox("Es ist kein Update verfügbar.") End If Else statusVersionLabel.Text = "Lokale Version: " & My.Application.Info.Version.ToString MsgBox("Die Anwendung wurde nicht aus dem Internet bezogen und kann daher nicht aktualisiert werden.") End If End Sub Private Sub LöschenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LöschenToolStripMenuItem.Click For Each Row As DataGridViewRow In DataGridView1.SelectedRows Me.DataGridView1.Rows.RemoveAt(Row.Index) Next 'Me.DataGridView1.Rows(Me.DataGridView1.Rows.Count - 1).Selected = True Try Me.DataGridView1.CurrentRow.Selected = True Catch ex As Exception 'nothing :D End Try End Sub Private Sub HinzufügenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HinzufügenToolStripMenuItem.Click Dim oForm As New frmPerson() oForm.Tag = "add" oForm.ShowDialog() 'http://www.vb-helper.com/howto_net_dataset_autonumber.html Dim dt As DataTable = GästeDataSet.Tables("Gäste") Dim dr As DataRow = dt.NewRow() With dr .Item("Nachname") = oForm.txtNachname.Text .Item("Vorname") = oForm.txtVorname.Text .Item("Straße") = oForm.txtStrasse.Text .Item("PLZ") = oForm.txtPLZ.Text .Item("Ort") = oForm.txtOrt.Text .Item("Land") = oForm.cboLand.Text .Item("Telefon") = oForm.txtTelefon.Text .Item("Email") = oForm.txtEmail.Text .Item("Anmerkung") = oForm.txtAnmerkung.Text .Item("Stammgast") = oForm.chkStammgast.Checked .Item("Blockiert") = oForm.chkBlacklist.Checked End With Try dt.Rows.Add(dr) Catch ex As Exception MsgBox("Gast konnte nicht hinzugefügt werden." & vbCrLf & ex.Message) End Try oForm.Dispose() oForm = Nothing End Sub Private Sub BearbeitenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BearbeitenToolStripMenuItem.Click Dim oForm As New frmPerson() oForm.Tag = "edit" With oForm .txtID.Text = Me.DataGridView1.SelectedCells(0).Value.ToString .txtNachname.Text = Me.DataGridView1.SelectedCells(1).Value.ToString .txtVorname.Text = Me.DataGridView1.SelectedCells(2).Value.ToString .txtStrasse.Text = Me.DataGridView1.SelectedCells(3).Value.ToString .txtPLZ.Text = Me.DataGridView1.SelectedCells(4).Value.ToString .txtOrt.Text = Me.DataGridView1.SelectedCells(5).Value.ToString .cboLand.Text = Me.DataGridView1.SelectedCells(6).Value.ToString .txtTelefon.Text = Me.DataGridView1.SelectedCells(7).Value.ToString .txtEmail.Text = Me.DataGridView1.SelectedCells(8).Value.ToString .txtAnmerkung.Text = Me.DataGridView1.SelectedCells(9).Value.ToString '.chkStammgast.Checked = CBool(Me.DataGridView1.SelectedCells(10).Value) '.chkBlacklist.Checked = CBool(Me.DataGridView1.SelectedCells(11).Value) End With 'MsgBox(CType(Me.DataGridView1.SelectedCells(10).Value, Boolean)) oForm.ShowDialog() oForm.Dispose() oForm = Nothing End Sub 'We should not have to use this any more. but for backup we left this here... 'Private Sub DataGridView1_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp ' If e.Button = MouseButtons.Right Then ' Me.DataGridView1.Rows(e.RowIndex).Selected = True ' Me._rowIndex = e.RowIndex ' Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(e.RowIndex).Cells(1) ' Me.mnuContext.Show(Me.DataGridView1, e.Location) ' mnuContext.Show(Cursor.Position) ' End If 'End Sub Private Sub DataGridView1_MouseUp(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseUp If e.Button = MouseButtons.Right Then If Me.DataGridView1.SelectedRows.Count < 1 Then HinzufügenToolStripMenuItem.Visible = True BearbeitenToolStripMenuItem.Visible = False LöschenToolStripMenuItem.Visible = False Else If Me.DataGridView1.SelectedRows.Count > 1 Then HinzufügenToolStripMenuItem.Visible = True BearbeitenToolStripMenuItem.Visible = False LöschenToolStripMenuItem.Visible = True Else HinzufügenToolStripMenuItem.Visible = True BearbeitenToolStripMenuItem.Visible = True LöschenToolStripMenuItem.Visible = True End If End If Me.mnuContext.Show(Me.DataGridView1, e.Location) mnuContext.Show(Cursor.Position) End If End Sub Private Sub statusVersionLabel_Click(sender As Object, e As EventArgs) Handles statusVersionLabel.Click If statusVersionLabel.Tag = "update" Then UpdateToolStripMenuItem_Click(statusVersionLabel, Nothing) End If End Sub End Class