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

using SmartX;

namespace ITC81DB.DialogForms
{
    public partial class DialogFormProductList : Form
    {
        #region Field
        private Collection<string> ProductList;
        private Collection<SmartLabel> LabelCollection;
        private int ListViewIndex = 0;
        private int m_SelectedProductNumber;
        #endregion

        #region Constructor
        public DialogFormProductList(Collection<string> items, int index)
        {
            InitializeComponent();

            this.InitializeForm();
            this.ProductList = items;
            this.ListViewIndex = index;

            this.DisplayProductList(this.ListViewIndex);
        } 
        #endregion

        #region Property
        public int SelectedProductNumber
        {
            get { return this.m_SelectedProductNumber; }
            set { this.m_SelectedProductNumber = value; }
        } 
        #endregion

        #region Method
        private void InitializeForm()
        {
            this.ProductList = new Collection<string>();
            this.LabelCollection = new Collection<SmartX.SmartLabel>();

            this.LabelCollection.Add(this.labelProduct1);
            this.LabelCollection.Add(this.labelProduct2);
            this.LabelCollection.Add(this.labelProduct3);
            this.LabelCollection.Add(this.labelProduct4);
            this.LabelCollection.Add(this.labelProduct5);
            this.LabelCollection.Add(this.labelProduct6);
            this.LabelCollection.Add(this.labelProduct7);
            this.LabelCollection.Add(this.labelProduct8);
            this.LabelCollection.Add(this.labelProduct9);
            this.LabelCollection.Add(this.labelProduct10);

            foreach (SmartX.SmartLabel label in this.LabelCollection)
                label.Text = "";
        }

        //public void SetProductList(Collection<string> productList)
        //{
        //    this.ProductList = productList;

        //    this.DisplayProductList(this.ListViewIndex);
        //}

        private void DisplayProductList(int index)
        {
            for (int i = 0; i < 10; i++)
                this.LabelCollection[i].Text = this.ProductList[index + i];
        }
        #endregion

        #region Event Handler
        private void buttonFunction_Click(object sender, EventArgs e)
        {
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            if (button == this.buttonUp)
            {
                this.ListViewIndex -= 10;
                if (this.ListViewIndex < 0)
                    this.ListViewIndex = 0;

                this.DisplayProductList(this.ListViewIndex);
            }
            else if (button == this.buttonDown)
            {
                this.ListViewIndex += 10;
                if (this.ListViewIndex >= this.ProductList.Count - 10)
                    this.ListViewIndex = this.ProductList.Count - 10;

                this.DisplayProductList(this.ListViewIndex);
            }
            else if (button == this.buttonEsc)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
        }

        private void labelProduct_Click(object sender, EventArgs e)
        {
            SmartLabel label = sender as SmartLabel;

            if (label == null)
                return;

            if (label == this.labelProduct1)
            {
                this.SelectedProductNumber = this.ListViewIndex + 1;
            }
            else if (label == this.labelProduct2)
            {
                this.SelectedProductNumber = this.ListViewIndex + 2;
            }
            else if (label == this.labelProduct3)
            {
                this.SelectedProductNumber = this.ListViewIndex + 3;
            }
            else if (label == this.labelProduct4)
            {
                this.SelectedProductNumber = this.ListViewIndex + 4;
            }
            else if (label == this.labelProduct5)
            {
                this.SelectedProductNumber = this.ListViewIndex + 5;
            }
            else if (label == this.labelProduct6)
            {
                this.SelectedProductNumber = this.ListViewIndex + 6;
            }
            else if (label == this.labelProduct7)
            {
                this.SelectedProductNumber = this.ListViewIndex + 7;
            }
            else if (label == this.labelProduct8)
            {
                this.SelectedProductNumber = this.ListViewIndex + 8;
            }
            else if (label == this.labelProduct9)
            {
                this.SelectedProductNumber = this.ListViewIndex + 9;
            }
            else if (label == this.labelProduct10)
            {
                this.SelectedProductNumber = this.ListViewIndex + 10;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        } 
        #endregion
    }
}