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

using SmartX;
using INT69DC_7C.Forms;

namespace INT69DC_7C.DialogForms
{
    public partial class DialogFormPrinter : Form
    {
        #region Field
        private FormDataStatistics m_ParentForm;

        #endregion

        #region Constructor
        public DialogFormPrinter(FormDataStatistics parent)
        {
            InitializeComponent();

            this.ParentForm = parent;
            this.InitializeControl();
            this.DefaultSetting();
        }
        #endregion

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

        #region Method
        private void InitializeControl()
        {
            int x = 0, y = 0;

            x = Screen.PrimaryScreen.Bounds.Width / 2 - this.Size.Width / 2;
            y = Screen.PrimaryScreen.Bounds.Height / 2 - this.Size.Height / 2;

            this.Location = new Point(x, y);
            this.Size = new Size(350, 470);
        }
        private void DefaultSetting()
        {
            this.checkBoxStatistics.Checked = false;
            this.checkBoxAllLane.Checked = false;
            this.checkBoxLane1.Checked = false;
            this.checkBoxLane2.Checked = false;
            this.checkBoxLane3.Checked = false;
            this.checkBoxLane4.Checked = false;
            this.checkBoxLane5.Checked = false;
            this.checkBoxLane6.Checked = false;
            this.checkBoxLane7.Checked = false;
            this.checkBoxLane8.Checked = false;
            this.checkBoxLane9.Checked = false;
            this.checkBoxLane10.Checked = false;
            this.checkBoxLane11.Checked = false;
            this.checkBoxLane12.Checked = false;

            switch (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 7:
                    this.checkBoxLane8.Visible = false;
                    this.checkBoxLane9.Visible = false;
                    this.checkBoxLane10.Visible = false;
                    this.checkBoxLane11.Visible = false;
                    this.checkBoxLane12.Visible = false;
                    break;
                case 8:
                    this.checkBoxLane9.Visible = false;
                    this.checkBoxLane10.Visible = false;
                    this.checkBoxLane11.Visible = false;
                    this.checkBoxLane12.Visible = false;
                    break;
                case 10:
                    this.checkBoxLane11.Visible = false;
                    this.checkBoxLane12.Visible = false;
                    break;
                case 11:
                    this.checkBoxLane12.Visible = false;
                    break;
                case 12:
                    break;
                default:
                    break;
            }
        }

        private void PrintCommonData(DataCommonList data)
        {
            this.ParentForm.ParentForm.SerialCom4TransferData("\n\n################################");
            this.ParentForm.ParentForm.SerialCom4TransferData("       STATISTICS  PRINT        ");
            this.ParentForm.ParentForm.SerialCom4TransferData("################################");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" NAME    = {0}", data.ProductName));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" LOT     = {0}", data.Lot));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" START   = {0:yyyy-MM-dd HH:mm:ss}", data.StartTime));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" END     = {0:yyyy-MM-dd HH:mm:ss}", data.EndTime));

            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format("\n PASS    = {0}g", data.PassRange));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.TotalPassCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.TotalPassPercentage));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" AVG.W   = {0:0.000}g", data.TotalPassAverageWeight));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" SD      = {0:0.00}g", data.TotalPassStandardDeviation));

            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format("\n OVER    = {0}g", data.OverRange));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.TotalOverCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.TotalOverPercentage));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" SUM.W   = {0}kg", Helper.DoubleToString(data.TotalOverSumWeight / 1000, 3)));

            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format("\n UNDER   = {0}g", data.UnderRange));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.TotalUnderCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.TotalUnderPercentage));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" SUM.W   = {0}kg", Helper.DoubleToString(data.TotalUnderSumWeight / 1000, 3)));

            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format("\n TARE    = {0}g", data.TareRange));

            this.ParentForm.ParentForm.SerialCom4TransferData("\n EXNG");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.TotalExNgCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.TotalExNgPercentage));

            this.ParentForm.ParentForm.SerialCom4TransferData("\n TOTAL NG COUNT");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" {0}ea", data.TotalNGCount));
            this.ParentForm.ParentForm.SerialCom4TransferData("\n TOTAL COUNT");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" {0}ea", data.TotalCount));

            this.ParentForm.ParentForm.SerialCom4TransferData("################################\n\n");
           
            Thread.Sleep(2000);
        }
        private void PrintLaneData(int lane, DataCollector data)
        {
            this.ParentForm.ParentForm.SerialCom4TransferData("\n\n################################");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format("        {0} LANE  PRINT         ", lane));
            this.ParentForm.ParentForm.SerialCom4TransferData("################################");
            this.ParentForm.ParentForm.SerialCom4TransferData("\n PASS");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" AVG.W   = {0:0.000}g", data.PassAverage));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.PassTotalCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.PassPercentage));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" SD      = {0:0.00}g", data.PassStandardDeviation));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" MIN.W   = {0}g", Helper.DoubleToString(data.PassMinWeight, 1)));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" MAX.W   = {0}g", Helper.DoubleToString(data.PassMaxWeight, 1)));

            this.ParentForm.ParentForm.SerialCom4TransferData("\n OVER");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.OverTotalCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.OverPercentage));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" SUM.W   = {0}kg", Helper.DoubleToString(data.OverSumWeight / 1000, 3)));

            this.ParentForm.ParentForm.SerialCom4TransferData("\n UNDER");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.UnderTotalCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.UnderPercentage));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" SUM.W   = {0}kg", Helper.DoubleToString(data.UnderSumWeight / 1000, 3)));

            this.ParentForm.ParentForm.SerialCom4TransferData("\n EXNG");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" COUNT   = {0}ea", data.ExNgTotalCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" RATIO   = {0:0.00}%", data.ExNgPercentage));

            this.ParentForm.ParentForm.SerialCom4TransferData("\n TOTAL NG COUNT");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" {0}ea", data.TotalNGCount));
            this.ParentForm.ParentForm.SerialCom4TransferData(" TOTAL COUNT");
            this.ParentForm.ParentForm.SerialCom4TransferData(string.Format(" {0}ea", data.TotalCount));

            this.ParentForm.ParentForm.SerialCom4TransferData("################################\n\n");

            Thread.Sleep(2000);
        }

        #endregion

        #region Event Handler
        private void checkBoxStatistics_Click(object sender, EventArgs e)
        {
        }
        private void checkBoxAllLane_Click(object sender, EventArgs e)
        {
            if (this.checkBoxAllLane.Checked == true)
            {
                switch (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns)
                {
                    case 7:
                        this.checkBoxLane1.Checked = true;
                        this.checkBoxLane2.Checked = true;
                        this.checkBoxLane3.Checked = true;
                        this.checkBoxLane4.Checked = true;
                        this.checkBoxLane5.Checked = true;
                        this.checkBoxLane6.Checked = true;
                        this.checkBoxLane7.Checked = true;
                        break;
                    case 8:
                        this.checkBoxLane1.Checked = true;
                        this.checkBoxLane2.Checked = true;
                        this.checkBoxLane3.Checked = true;
                        this.checkBoxLane4.Checked = true;
                        this.checkBoxLane5.Checked = true;
                        this.checkBoxLane6.Checked = true;
                        this.checkBoxLane7.Checked = true;
                        this.checkBoxLane8.Checked = true;
                        break;
                    case 10:
                        this.checkBoxLane1.Checked = true;
                        this.checkBoxLane2.Checked = true;
                        this.checkBoxLane3.Checked = true;
                        this.checkBoxLane4.Checked = true;
                        this.checkBoxLane5.Checked = true;
                        this.checkBoxLane6.Checked = true;
                        this.checkBoxLane7.Checked = true;
                        this.checkBoxLane8.Checked = true;
                        this.checkBoxLane9.Checked = true;
                        this.checkBoxLane10.Checked = true;
                        break;
                    case 11:
                        this.checkBoxLane1.Checked = true;
                        this.checkBoxLane2.Checked = true;
                        this.checkBoxLane3.Checked = true;
                        this.checkBoxLane4.Checked = true;
                        this.checkBoxLane5.Checked = true;
                        this.checkBoxLane6.Checked = true;
                        this.checkBoxLane7.Checked = true;
                        this.checkBoxLane8.Checked = true;
                        this.checkBoxLane9.Checked = true;
                        this.checkBoxLane10.Checked = true;
                        this.checkBoxLane11.Checked = true;
                        break;
                    case 12:
                        this.checkBoxLane1.Checked = true;
                        this.checkBoxLane2.Checked = true;
                        this.checkBoxLane3.Checked = true;
                        this.checkBoxLane4.Checked = true;
                        this.checkBoxLane5.Checked = true;
                        this.checkBoxLane6.Checked = true;
                        this.checkBoxLane7.Checked = true;
                        this.checkBoxLane8.Checked = true;
                        this.checkBoxLane9.Checked = true;
                        this.checkBoxLane10.Checked = true;
                        this.checkBoxLane11.Checked = true;
                        this.checkBoxLane12.Checked = true;
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns)
                {
                    case 7:
                        this.checkBoxLane1.Checked = false;
                        this.checkBoxLane2.Checked = false;
                        this.checkBoxLane3.Checked = false;
                        this.checkBoxLane4.Checked = false;
                        this.checkBoxLane5.Checked = false;
                        this.checkBoxLane6.Checked = false;
                        this.checkBoxLane7.Checked = false;
                        break;
                    case 8:
                        this.checkBoxLane1.Checked = false;
                        this.checkBoxLane2.Checked = false;
                        this.checkBoxLane3.Checked = false;
                        this.checkBoxLane4.Checked = false;
                        this.checkBoxLane5.Checked = false;
                        this.checkBoxLane6.Checked = false;
                        this.checkBoxLane7.Checked = false;
                        this.checkBoxLane8.Checked = false;
                        break;
                    case 10:
                        this.checkBoxLane1.Checked = false;
                        this.checkBoxLane2.Checked = false;
                        this.checkBoxLane3.Checked = false;
                        this.checkBoxLane4.Checked = false;
                        this.checkBoxLane5.Checked = false;
                        this.checkBoxLane6.Checked = false;
                        this.checkBoxLane7.Checked = false;
                        this.checkBoxLane8.Checked = false;
                        this.checkBoxLane9.Checked = false;
                        this.checkBoxLane10.Checked = false;
                        break;
                    case 11:
                        this.checkBoxLane1.Checked = false;
                        this.checkBoxLane2.Checked = false;
                        this.checkBoxLane3.Checked = false;
                        this.checkBoxLane4.Checked = false;
                        this.checkBoxLane5.Checked = false;
                        this.checkBoxLane6.Checked = false;
                        this.checkBoxLane7.Checked = false;
                        this.checkBoxLane8.Checked = false;
                        this.checkBoxLane9.Checked = false;
                        this.checkBoxLane10.Checked = false;
                        this.checkBoxLane11.Checked = false;
                        break;
                    case 12:
                        this.checkBoxLane1.Checked = false;
                        this.checkBoxLane2.Checked = false;
                        this.checkBoxLane3.Checked = false;
                        this.checkBoxLane4.Checked = false;
                        this.checkBoxLane5.Checked = false;
                        this.checkBoxLane6.Checked = false;
                        this.checkBoxLane7.Checked = false;
                        this.checkBoxLane8.Checked = false;
                        this.checkBoxLane9.Checked = false;
                        this.checkBoxLane10.Checked = false;
                        this.checkBoxLane11.Checked = false;
                        this.checkBoxLane12.Checked = false;
                        break;
                    default:
                        break;
                }
            }
        }
        private void checkBoxLane_Click(object sender, EventArgs e)
        {

        }
        private void buttonPrint_Click(object sender, EventArgs e)
        {
            SmartSplash splash = new SmartSplash();
            splash.CenterPosition = true;
            splash.AnimationInterval = 100;
            splash.LoadingImagePathname = "SmartLoading4";
            splash.Start();

            if (this.checkBoxStatistics.Checked == true)
                this.PrintCommonData(this.ParentForm.CurrentDataCommonList);

            if (this.checkBoxLane1.Checked == true)
                this.PrintLaneData(1, this.ParentForm.CollectionLaneData[0]);
            if (this.checkBoxLane2.Checked == true)
                this.PrintLaneData(2, this.ParentForm.CollectionLaneData[1]);
            if (this.checkBoxLane3.Checked == true)
                this.PrintLaneData(3, this.ParentForm.CollectionLaneData[2]);
            if (this.checkBoxLane4.Checked == true)
                this.PrintLaneData(4, this.ParentForm.CollectionLaneData[3]);
            if (this.checkBoxLane5.Checked == true)
                this.PrintLaneData(5, this.ParentForm.CollectionLaneData[4]);

            if (this.checkBoxLane6.Checked == true)
                this.PrintLaneData(6, this.ParentForm.CollectionLaneData[5]);
            if (this.checkBoxLane7.Checked == true)
                this.PrintLaneData(7, this.ParentForm.CollectionLaneData[6]);
            if (this.checkBoxLane8.Checked == true)
                this.PrintLaneData(8, this.ParentForm.CollectionLaneData[7]);
            if (this.checkBoxLane9.Checked == true)
                this.PrintLaneData(9, this.ParentForm.CollectionLaneData[8]);
            if (this.checkBoxLane10.Checked == true)
                this.PrintLaneData(10, this.ParentForm.CollectionLaneData[9]);

            if (this.checkBoxLane11.Checked == true)
                this.PrintLaneData(11, this.ParentForm.CollectionLaneData[10]);
            if (this.checkBoxLane12.Checked == true)
                this.PrintLaneData(12, this.ParentForm.CollectionLaneData[11]);

            splash.Finish();
        }
        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
        #endregion
    }
}