﻿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.Data.SQLite;

namespace Filmi
{
    public partial class Form1 : Form
    {
        public int Leto_od, Leto_do, Dolzina_do, Dolzina_od;
        public double Ocena_od, Ocena_do;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void izvedi_Click(object sender, EventArgs e)
        {
            prikaz.Text = "";
            string pot = @"Data Source=.\filmi.sqlite; Version=3;";
            SQLiteConnection link = new SQLiteConnection(pot);
            link.Open();
            SQLiteCommand ukaz = new SQLiteCommand();
            ukaz.CommandType = CommandType.Text;
            ukaz.Connection = link;
            ukaz.CommandText = "SELECT * FROM filmi";
            try
            {
                Leto_od = int.Parse(leto_od.Text);
                Leto_do = int.Parse(leto_do.Text);
                Dolzina_od = int.Parse(dolzina_od.Text);
                Dolzina_do = int.Parse(dolzina_do.Text);
                Ocena_od = double.Parse(ocena_od.Text);
                Ocena_do = double.Parse(ocena_do.Text);
            }
            catch
            {
                throw new ArgumentException("Izpolni vse okvirčke za leto, dolžino filma in oceno!");
            }
            ukaz.CommandText += $" WHERE naslov LIKE '%{naslov.Text}%' AND reziser LIKE '%{reziser.Text}%' AND leto BETWEEN {Leto_od} AND {Leto_do} AND ocena BETWEEN {Ocena_od} AND {Ocena_do} AND dolzina BETWEEN {Dolzina_od} AND {Dolzina_do}";
            SQLiteDataReader izpis = ukaz.ExecuteReader();
            while (izpis.Read())
            {
                prikaz.Text += (izpis[1].ToString() + " " + izpis[2].ToString() + " " + izpis[3].ToString() + " " + izpis[4].ToString() + " " + izpis[6].ToString() + Environment.NewLine);
            }
        }
    }
}
