﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace MyXMLApplication
{
    public partial class Form1 : Form
    {
        private XmlTextWriter xtw;
        public Form1()
        {
            InitializeComponent();
            cmbRating.SelectedIndex = 3;

            xtw = new XmlTextWriter(@"C:\ucenik\Videos.xml", null);
            xtw.Formatting = Formatting.Indented;
            xtw.Indentation = 3;

            // Start the XML document.
            xtw.WriteStartDocument();

            xtw.WriteComment("Video Biblioteka");
            xtw.WriteComment("Ovo je fajl i kojem je nabrojano dosta video snimaka.");
            // Create the root element.
            xtw.WriteStartElement("VideoBiblioteka");
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            // Close the root element, and close the file.
            xtw.WriteEndElement();
            xtw.WriteEndDocument();
            xtw.Flush();  // Flush the stream.
            xtw.Close();  // Close the XmlTextWriter object.

            Application.Exit();
        }

        private void btnName_Click(object sender, EventArgs e)
        {
            // Add the data on the screen to the XML file.
            // Start a Video element.
            xtw.WriteStartElement("Video");
            // Add a Title element.
            xtw.WriteElementString("Title", txtVideo.Text);
            // Start a Length element.
            xtw.WriteStartElement("Length");
            // Add the Measurement attribute to the Length element.
            xtw.WriteAttributeString("Measurement", "minutes");
            // Add the data to the Length element. 
            xtw.WriteString(txtLength.Text);
            xtw.WriteEndElement();  // End Length element.
            xtw.WriteElementString("star", txtStar.Text);
            xtw.WriteElementString("rating", cmbRating.Text);
            xtw.WriteEndElement(); // End Video element.
            // Put insertion point back in first field.
            txtVideo.Focus();
            // Clear the fields on the screen.
            txtVideo.Text = "";
            txtLength.Text = "";
            txtStar.Text = "";
            cmbRating.Text = "";
        }
    }
}
