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 EditListViewClasses : hukpiWinApp.BaseEditListViewForm
    {
        string ClassNumber;

        public EditListViewClasses(ListView parentListView, string classNumber) : base(parentListView)
        {
            InitializeComponent();

            this.ClassNumber = classNumber;
            this.Text = "Kategória " + classNumber + " szerkesztése";
            
            fillComboBoxClasses(classNumber);
            fillComboBoxProcessingcodes();
        }

        private void fillComboBoxClasses(string classNumber)
        {
            comboBoxNewItemNumber.DataSource = Utils.getClassesForCombo(classNumber);
            comboBoxNewItemNumber.DisplayMember = "Description";
            comboBoxNewItemNumber.ValueMember = "Id";
        }

        private void fillComboBoxProcessingcodes()
        {
            comboBoxNewProcessCode.DataSource = Utils.getProcessingCodesForCombo();
            comboBoxNewProcessCode.DisplayMember = "Description";
            comboBoxNewProcessCode.ValueMember = "Id";
        }

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

        private void buttonAddNewClass_Click(object sender, EventArgs e)
        {
            if (validateForm())
            {
                ListViewItem newItem = new ListViewItem(comboBoxNewItemNumber.Text.Split('-')[0]);
                ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(newItem, comboBoxNewItemNumber.Text.Split('-')[1]);
                subItem.Tag = comboBoxNewItemNumber.SelectedValue;
                newItem.SubItems.Add(subItem);

                subItem = new ListViewItem.ListViewSubItem(newItem, comboBoxNewProcessCode.Text);
                subItem.Tag = comboBoxNewProcessCode.SelectedValue;
                newItem.SubItems.Add(subItem);
                this.listViewData.Items.Add(newItem);

                clearInputsBoxes();
            }
            else
            {
                MessageBox.Show(ErrorMessages.Default.invalidFormInputData);
            }
        }

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

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

        

        private bool validateForm()
        {
            bool isValidComboNewItemNumber = Utils.validateMustNonEmpty(errorProviderForEditListView, comboBoxNewItemNumber);
            bool isValidComboNewProcessCode = Utils.validateMustNonEmpty(errorProviderForEditListView, comboBoxNewProcessCode);

            return isValidComboNewItemNumber && isValidComboNewProcessCode;
        }

        

        
    }
}
