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

using INT51DB.Forms;
using INT51DB_ImageDll;

namespace INT51DB.Controls
{
    public partial class ControlMainDisplayList : UserControl
    {
        #region Field
        private FormMainDisplay m_ParentForm;
        #endregion
        
        #region Constructor
        public ControlMainDisplayList(FormMainDisplay parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeDesign();
            this.DefaultSetting();
        } 
        #endregion

        #region Property
        public FormMainDisplay ParentForm
        {
            get { return this.m_ParentForm; }
            private set { this.m_ParentForm = value; }
        } 
        #endregion

        #region Method
        public void InitializeDesign()
        {
            Class1 images = new Class1();

            if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
            }
            else
            {
            }
        }
        private void DefaultSetting()
        {

        }

        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {

        }
        public void UpdateCurrentProductDisplay(DataStore.EquipmentStatus status, ProductItem pItem, WeightData wData)
        {
            this.Clear();
        }
        public void UpdateUpdateStartWeightDisplay(DataStore.EquipmentStatus status, WeightData data)
        {
            string value = "", time = "", weight = "";

            time = string.Format(@"{0:MM-dd HH:mm:ss}", DateTime.Now);
            weight = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            value = string.Format("{0,25}{1,40}{2,40}", time, weight, data.JudgmentStatus);

            if (this.smartListBox.Items.Count >= 100)
                this.smartListBox.RemoveItem(0);

            this.smartListBox.AddItem(value);
            this.smartListBox.ScrollDown();
        }

        public void Clear()
        {
            this.smartListBox.ClearAll();
        }
        public void DisplayRefresh(SystemStatus status)
        {

        }
        #endregion
      
        #region Event Handler
        private void buttonListUp_Click(object sender, EventArgs e)
        {
            if (this.smartListBox.ViewStartItemIndex / 6 > 0)
                this.smartListBox.ScrollUp(161);
            else
                this.smartListBox.ScrollUp();

            this.smartListBox.SelectItemIndex = -1;
        }

        private void buttonListDown_Click(object sender, EventArgs e)
        {
            if (this.smartListBox.ViewRemainCount / 6 > 0)
                this.smartListBox.ScrollDown(161);
            else
                this.smartListBox.ScrollDown();

            this.smartListBox.SelectItemIndex = -1;
        }

        private void buttonListRapidDown_Click(object sender, EventArgs e)
        {
            this.smartListBox.ScrollDown(this.smartListBox.ViewRemainCount / 6 * 161);

            for (int i = 0; i < this.smartListBox.ViewRemainCount % 6; i++)
                this.smartListBox.ScrollDown();

            this.smartListBox.SelectItemIndex = -1;
        }
        #endregion
    }
}
