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;

namespace db_AI_4
{
    public partial class Dashboard : Form
    {
        //Search Locations start
        List<GetLocations> locations = new List<GetLocations>();
        List<GetLocations> rentlocation = new List<GetLocations>();
        List<GetRents> rentedlocations = new List<GetRents>();

        

        BindingSource locationBinding = new BindingSource();
        BindingSource addlocationBinding = new BindingSource();
        BindingSource showrentBinding = new BindingSource();

        public Dashboard()
        {
            InitializeComponent();
            UpdateBinding();
        }

        private void UpdateBinding()
        {
            // Loading of the Searched Locations
            LocationListBox.DataSource = locations;
            LocationListBox.DisplayMember = "LocationInfo";

            locationBinding.DataSource = locations;
            LocationListBox.DataSource = locationBinding;


            //Loading of the Selected  Locations
            ADDLocationListBox.DataSource = rentlocation;
            ADDLocationListBox.DisplayMember = "LocationInfo";

            addlocationBinding.DataSource = rentlocation;
            ADDLocationListBox.DataSource = addlocationBinding;

            // Rented Locations
            ShowRentListBox.DataSource = rentedlocations;
            ShowRentListBox.DisplayMember = "RentInfo";

            showrentBinding.DataSource = rentedlocations;
            ShowRentListBox.DataSource = showrentBinding;


        }



        private void LocationSearchButton_Click(object sender, EventArgs e)
        {
            DataAccess db = new DataAccess();

            locations = db.GetLocations(LocationTextBox.Text);

            UpdateBinding();

        }
        // Search Locations end

        /*
        //Insert Locations start
        private void LocationInsertButton_Click(object sender, EventArgs e)
        {
            DataAccess db = new DataAccess();

            int CapacityValue;
            CapacityValue = Convert.ToInt32(LocationCapacityInputBox.Text);
            CapacityValue = int.Parse(LocationCapacityInputBox.Text);

            db.InsertLocations(StreetnameInsertBox.Text, Convert.ToInt32(LocationCapacityInputBox.Text), LocationNameInputBox.Text);

            StreetnameInsertBox.Text = "";
            LocationCapacityInputBox.Text = "";
            LocationNameInputBox.Text = "";


        }
        // Insert Locations end
        */

        // Insert Rent start
        private void RentInsertButton_Click(object sender, EventArgs e)
        {
            DataAccess db = new DataAccess();

  

            int RentPriceID;
            RentPriceID = 1;

            int MemberID;
            MemberID = 1;


            db.InsertRent(RentDateTimePicker.Value.Date.ToString("yyyyMMdd"), RentPriceID, MemberID);

            RentDateTimePicker.Text = "";
            
        }
        // Insert Rent end


        //Add Location to ADDBox start
        private void ADDLocationButton_Click(object sender, EventArgs e)
        {
            GetLocations selectedItem = (GetLocations)LocationListBox.SelectedItem;

            rentlocation.Add(selectedItem);

            UpdateBinding();

        }

        private void Dashboard_Load(object sender, EventArgs e)
        {

        }

        private void ShowRentButton_Click(object sender, EventArgs e)
        {
            DataAccess db = new DataAccess();

            rentedlocations = db.GetRentedLocations(RentedTextBox.Text);

            UpdateBinding();
        }
        //Add Location to ADDBox end

    }
}
