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 ITC81DB_2.Forms;
using ITC81DB_2_ImageDll;

namespace ITC81DB_2.Controls
{
    public partial class ControlMainList : UserControl
    {
        #region Field
        private FormMainDisplay m_ParentForm;
        #endregion

        #region Constructor
        public ControlMainList(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 == Define.E_LanguageID.English)
            {
                this.labelTitleTime1.Text = this.labelTitleTime2.Text = "Time";
                this.labelTitleWeight1.Text = this.labelTitleWeight2.Text = "Weight";
                this.labelTitleGrade1.Text = this.labelTitleGrade2.Text = "Grade";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
            {
                this.labelTitleTime1.Text = this.labelTitleTime2.Text = "时间";
                this.labelTitleWeight1.Text = this.labelTitleWeight2.Text = "重量";
                this.labelTitleGrade1.Text = this.labelTitleGrade2.Text = "等级";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
                this.labelTitleTime1.Text = this.labelTitleTime2.Text = "Tiempo";
                this.labelTitleWeight1.Text = this.labelTitleWeight2.Text = "Peso";
                this.labelTitleGrade1.Text = this.labelTitleGrade2.Text = "Calificación";
            }
            else
            {
                this.labelTitleTime1.Text = this.labelTitleTime2.Text = "시간";
                this.labelTitleWeight1.Text = this.labelTitleWeight2.Text = "중량";
                this.labelTitleGrade1.Text = this.labelTitleGrade2.Text = "등급";
            }
        }
        private void DefaultSetting()
        {

        }

        private void UpdateDisplayListBox1(Define.E_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,20}{1,25}{2,28}", time, weight, data.JudgmentStatus);

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

            this.listBox1.AddItem(value);
            this.listBox1.ScrollDown();
        }
        private void UpdateDisplayListBox2(Define.E_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,20}{1,25}{2,28}", time, weight, data.JudgmentStatus);

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

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

        public void UpdateStartWeightDisplay1(Define.E_EquipmentStatus status, WeightData data)
        {
            string value = "";

            if (data.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return;

            this.UpdateDisplayListBox1(status, data);
        }
        public void UpdateStartWeightDisplay2(Define.E_EquipmentStatus status, WeightData data)
        {
            string value = "";

            if (data.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return;

            this.UpdateDisplayListBox2(status, data);
        }

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

        }
        #endregion

        #region Event Handler
        private void buttonListUp1_Click(object sender, EventArgs e)
        {
            if (this.listBox1.ViewStartItemIndex / 7 > 0)
                this.listBox1.ScrollUp(130);
            else
                this.listBox1.ScrollUp();

            this.listBox1.SelectItemIndex = -1;
        }
        private void buttonListDown1_Click(object sender, EventArgs e)
        {
            if (this.listBox1.ViewRemainCount / 7 > 0)
                this.listBox1.ScrollDown(130);
            else
                this.listBox1.ScrollDown();

            this.listBox1.SelectItemIndex = -1;
        }
        private void buttonListRapidDown1_Click(object sender, EventArgs e)
        {
            this.listBox1.ScrollDown(this.listBox1.ViewRemainCount / 7 * 160);

            for (int i = 0; i < this.listBox1.ViewRemainCount % 7; i++)
                this.listBox1.ScrollDown();

            this.listBox1.SelectItemIndex = -1;
        }

        private void buttonListUp2_Click(object sender, EventArgs e)
        {
            if (this.listBox2.ViewStartItemIndex / 7 > 0)
                this.listBox2.ScrollUp(150);
            else
                this.listBox2.ScrollUp();

            this.listBox2.SelectItemIndex = -1;
        }
        private void buttonListDown2_Click(object sender, EventArgs e)
        {
            if (this.listBox2.ViewRemainCount / 7 > 0)
                this.listBox2.ScrollDown(150);
            else
                this.listBox2.ScrollDown();

            this.listBox2.SelectItemIndex = -1;
        }
        private void buttonListRapidDown2_Click(object sender, EventArgs e)
        {
            this.listBox2.ScrollDown(this.listBox2.ViewRemainCount / 7 * 170);

            for (int i = 0; i < this.listBox2.ViewRemainCount % 7; i++)
                this.listBox2.ScrollDown();

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