using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace hukpiWinApp
{
    public partial class EditListViewRoutes : hukpiWinApp.BaseEditListViewForm
    {
        public EditListViewRoutes(ListView parentListView) : base(parentListView)
        {
            InitializeComponent();

            fillComboBoxRoutes();
        }

        private void fillComboBoxRoutes()
        {
            comboBoxNewRoute.DataSource = Utils.getRoutesForCombo();
            comboBoxNewRoute.DisplayMember = "Description";
            comboBoxNewRoute.ValueMember = "Id";
        }

        private void clearInputsBoxes()
        {
            comboBoxNewRoute.SelectedValue = 0;
        }

        private void buttonAddNewRoute_Click(object sender, EventArgs e)
        {
            if (!validateForm())
            {
                MessageBox.Show(ErrorMessages.Default.invalidFormInputData);
            }
            else
            {
                ListViewItem newItem = new ListViewItem(comboBoxNewRoute.Text.Split('-')[0]);
                ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(newItem, comboBoxNewRoute.Text.Split('-')[1]);
                subItem.Tag = comboBoxNewRoute.SelectedValue;
                newItem.SubItems.Add(subItem);
                this.listViewData.Items.Add(newItem);

                clearInputsBoxes();
            }
        }

        private void comboBoxNewRoute_Validating(object sender, CancelEventArgs e)
        {
            Utils.validateMustNonEmpty(errorProviderForEditListView, comboBoxNewRoute);
        }

        private bool validateForm()
        {
            bool isValidComboNewRoute = Utils.validateMustNonEmpty(errorProviderForEditListView, comboBoxNewRoute);

            return isValidComboNewRoute;
        }
    }
}
