Option Strict On
Imports System.Xml
Public Class deleteForm
    Inherits System.Windows.Forms.Form
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Button1 As System.Windows.Forms.Button

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        MyBase.Dispose(disposing)
    End Sub

    ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。
    'Windows フォーム デザイナを使って変更してください。  
    ' コード エディタを使って変更しないでください。
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(16, 48)
        Me.ListBox1.Size = New System.Drawing.Size(120, 146)
        '
        'Button1
        '
        Me.Button1.Enabled = False
        Me.Button1.Location = New System.Drawing.Point(16, 200)
        Me.Button1.Text = "削除実行"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(96, 200)
        Me.Button2.Size = New System.Drawing.Size(40, 20)
        Me.Button2.Text = "戻る"
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(152, 80)
        Me.PictureBox1.Size = New System.Drawing.Size(70, 70)
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(144, 160)
        Me.Label1.Size = New System.Drawing.Size(88, 20)
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("MS UI Gothic", 9.75!, System.Drawing.FontStyle.Regular)
        Me.Label2.ForeColor = System.Drawing.Color.Blue
        Me.Label2.Location = New System.Drawing.Point(16, 16)
        Me.Label2.Size = New System.Drawing.Size(144, 32)
        Me.Label2.Text = "予定が記録された順番に日付が表示されています。"
        '
        'deleteForm
        '
        Me.ClientSize = New System.Drawing.Size(240, 232)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.ListBox1)
        Me.Text = "予定削除画面"

    End Sub

#End Region

    Dim xReader As XmlTextReader
    Dim delNo As Integer
    Dim imageArray As ArrayList
    Dim titleArray As ArrayList
    Dim nenStr, tukiStr, hiStr As String
    Private Sub deleteForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        xReader = New XmlTextReader("\Program Files\Rainman_calendar\data\calendarInfo.xml")

        imageArray = New ArrayList
        titleArray = New ArrayList
        Button1.BackColor = Color.LightSeaGreen
        Button1.ForeColor=Color.Crimson
        While xReader.Read
            If xReader.IsStartElement("画像名") = True Then
                imageArray.Add(xReader.ReadElementString)
            End If

            If xReader.IsStartElement("年") = True Then
                nenStr = xReader.ReadElementString
            End If

            If xReader.IsStartElement("月") = True Then
                tukiStr = xReader.ReadElementString
            End If

            If xReader.IsStartElement("日") = True Then
                hiStr = xReader.ReadElementString
                ListBox1.Items.Add(nenStr & "-" & tukiStr & "-" & hiStr)
            End If

            If xReader.IsStartElement("タイトル") = True Then
                titleArray.Add(xReader.ReadElementString)
            End If
        End While
        xReader.Close()
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Button1.Enabled = True
        delNo = ListBox1.SelectedIndex
        Dim myImage As Image
        myImage = New Bitmap("\Program Files\Rainman_calendar\calendar_image\image70\" & CType(imageArray(delNo), String))
        PictureBox1.Image = myImage
        Label1.Text = CType(titleArray(delNo), String)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim doc As XmlDocument = New XmlDocument
        doc.Load("\Program Files\Rainman_calendar\data\calendarInfo.xml")
        Dim kakunin As Integer = MsgBox(ListBox1.Text & "の予定を削除しますか？", MsgBoxStyle.OKCancel)

        Select Case kakunin
            Case 1
                nenTukiCheck = 2525
                nen = CType(nenStr, Integer) 'CType(ListBox1.Text.Substring(0, 4), Integer)
                'Dim myLen As Integer = Len(ListBox1.Text)
                'Dim dummyLen As Integer = myLen - 5
                'Dim tukihi As String = Microsoft.VisualBasic.Right(ListBox1.Text, dummyLen)
                'Dim hyphonNo As Integer = tukihi.IndexOf("-")
                'Dim hyphonData As Integer = tukihi.Length - hyphonNo
                'Dim tukiStr As String = tukihi.Remove(hyphonNo, hyphonData)

                tuki = CType(tukiStr, Integer)
                Dim root As XmlNode = doc.DocumentElement
                root.RemoveChild(root.ChildNodes.Item(delNo))
                doc.Save("\Program Files\Rainman_calendar\data\calendarInfo.xml")
                Dim myForm1 As Form1 = New Form1
                myForm1.Show()
            Case Else
                doc = Nothing
                Exit Sub
        End Select



        'MsgBox(doc.OuterXml)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim myForm1 As Form1 = New Form1
        myForm1.Show()
    End Sub
End Class
