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

using SmartX;

using ITC81DB_2.DialogForms;
using ITC81DB_2.Forms;
using ITC81DB_2_ImageDll;

namespace ITC81DB_2.Controls
{
    public partial class ControlCenterBasicDataStatistics : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;

        private int SelectedProductNo;
        private WeightData SelectedWeightData1;
        private WeightData SelectedWeightData2;
        private ProductItem SelectedProductItem1;
        private ProductItem SelectedProductItem2;
        #endregion

        #region Constructor
        public ControlCenterBasicDataStatistics(FormMenu parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

        #region Property
        public FormMenu 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.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundDataStatistics));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundDataStatistics));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.spnBackgroundDataStatistics));
            }
            else
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundDataStatistics));
            }
        }
        private void DefaultSetting()
        {
            this.SelectedProductNo = 1;
            this.SelectedWeightData1 = new WeightData();
            this.SelectedWeightData2 = new WeightData();
            this.SelectedProductItem1 = new ProductItem();
            this.SelectedProductItem2 = new ProductItem();

            this.DisplayPrintButton(this.ParentForm.ParentForm.SystemConfig);
        }

        private void UpdateDisplay1(WeightData data, ProductItem item)
        {
            string value = "";

            #region Range
            value = Helper.StringToDecimalPlaces(item.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelUnderRange1.Text != value)
                this.labelUnderRange1.Text = value;

            value = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelPassRange1.Text != value)
                this.labelPassRange1.Text = value;

            value = Helper.StringToDecimalPlaces(item.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelOverRange1.Text != value)
                this.labelOverRange1.Text = value;
            #endregion

            #region Count
            value = data.UnderCount.ToString();
            if (this.labelUnderCount1.Text != value)
                this.labelUnderCount1.Text = value;

            value = data.PassCount.ToString();
            if (this.labelPassCount1.Text != value)
                this.labelPassCount1.Text = value;

            value = data.OverCount.ToString();
            if (this.labelOverCount1.Text != value)
                this.labelOverCount1.Text = value;
            #endregion

            #region Average
            value = Helper.DoubleToString(data.UnderAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelUnderAverage1.Text != value)
                this.labelUnderAverage1.Text = value;

            value = Helper.DoubleToString(data.PassAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelPassAverage1.Text != value)
                this.labelPassAverage1.Text = value;

            value = Helper.DoubleToString(data.OverAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelOverAverage1.Text != value)
                this.labelOverAverage1.Text = value;
            #endregion

            #region Sum Weight
            value = data.UnderSumWeightKG;
            if (this.labelUnderSumWeight1.Text != value)
                this.labelUnderSumWeight1.Text = value;

            value = data.PassSumWeightKG;
            if (this.labelPassSumWeight1.Text != value)
                this.labelPassSumWeight1.Text = value;

            value = data.OverSumWeightKG;
            if (this.labelOverSumWeight1.Text != value)
                this.labelOverSumWeight1.Text = value;
            #endregion

            #region Ratio
            value = data.UnderRatio;
            if (this.labelUnderRatio1.Text != value)
                this.labelUnderRatio1.Text = value;

            value = data.PassRatio;
            if (this.labelPassRatio1.Text != value)
                this.labelPassRatio1.Text = value;

            value = data.OverRatio;
            if (this.labelOverRatio1.Text != value)
                this.labelOverRatio1.Text = value;
            #endregion

            value = data.TotalUnderOverCount.ToString();
            if (this.labelNGCount1.Text != value)
                this.labelNGCount1.Text = value;

            value = data.ETCExNGCount.ToString();
            if (this.labelExNGCount1.Text != value)
                this.labelExNGCount1.Text = value;

            value = data.TotalCount.ToString();
            if (this.labelTotalCount1.Text != value)
                this.labelTotalCount1.Text = value;

            if (data.StartTime.Year == 1111)
            {
                data.StartTime = DateTime.Now;
                this.SelectedWeightData1.StartTime = data.StartTime;
                this.ParentForm.ParentForm.SaveCounterFile1(this.SelectedWeightData1, this.SelectedProductNo - 1);
            }
            if (data.StopTime.Year == 1111)
            {
                data.StopTime = DateTime.Now;
                this.SelectedWeightData1.StopTime = data.StopTime;
                this.ParentForm.ParentForm.SaveCounterFile1(this.SelectedWeightData1, this.SelectedProductNo - 1);
            }

            value = data.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
            if (this.labelStartTime.Text != value)
                this.labelStartTime.Text = value;

            value = data.StopTime.ToString("yyyy-MM-dd HH:mm:ss");
            if (this.labelStopTime.Text != value)
                this.labelStopTime.Text = value;
        }
        private void UpdateDisplay2(WeightData data, ProductItem item)
        {
            string value = "";

            #region Range
            value = Helper.StringToDecimalPlaces(item.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelUnderRange2.Text != value)
                this.labelUnderRange2.Text = value;

            value = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelPassRange2.Text != value)
                this.labelPassRange2.Text = value;

            value = Helper.StringToDecimalPlaces(item.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelOverRange2.Text != value)
                this.labelOverRange2.Text = value;
            #endregion

            #region Count
            value = data.UnderCount.ToString();
            if (this.labelUnderCount2.Text != value)
                this.labelUnderCount2.Text = value;

            value = data.PassCount.ToString();
            if (this.labelPassCount2.Text != value)
                this.labelPassCount2.Text = value;

            value = data.OverCount.ToString();
            if (this.labelOverCount2.Text != value)
                this.labelOverCount2.Text = value;
            #endregion

            #region Average
            value = Helper.DoubleToString(data.UnderAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelUnderAverage2.Text != value)
                this.labelUnderAverage2.Text = value;

            value = Helper.DoubleToString(data.PassAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelPassAverage2.Text != value)
                this.labelPassAverage2.Text = value;

            value = Helper.DoubleToString(data.OverAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelOverAverage2.Text != value)
                this.labelOverAverage2.Text = value;
            #endregion

            #region Sum Weight
            value = data.UnderSumWeightKG;
            if (this.labelUnderSumWeight2.Text != value)
                this.labelUnderSumWeight2.Text = value;

            value = data.PassSumWeightKG;
            if (this.labelPassSumWeight2.Text != value)
                this.labelPassSumWeight2.Text = value;

            value = data.OverSumWeightKG;
            if (this.labelOverSumWeight2.Text != value)
                this.labelOverSumWeight2.Text = value;
            #endregion

            #region Ratio
            value = data.UnderRatio;
            if (this.labelUnderRatio2.Text != value)
                this.labelUnderRatio2.Text = value;

            value = data.PassRatio;
            if (this.labelPassRatio2.Text != value)
                this.labelPassRatio2.Text = value;

            value = data.OverRatio;
            if (this.labelOverRatio2.Text != value)
                this.labelOverRatio2.Text = value;
            #endregion

            value = data.TotalUnderOverCount.ToString();
            if (this.labelNGCount2.Text != value)
                this.labelNGCount2.Text = value;

            value = data.ETCExNGCount.ToString();
            if (this.labelExNGCount2.Text != value)
                this.labelExNGCount2.Text = value;

            value = data.TotalCount.ToString();
            if (this.labelTotalCount2.Text != value)
                this.labelTotalCount2.Text = value;

            if (data.StartTime.Year == 1111)
            {
                data.StartTime = DateTime.Now;
                this.SelectedWeightData2.StartTime = data.StartTime;
                this.ParentForm.ParentForm.SaveCounterFile2(this.SelectedWeightData2, this.SelectedProductNo - 1);
            }
            if (data.StopTime.Year == 1111)
            {
                data.StopTime = DateTime.Now;
                this.SelectedWeightData2.StopTime = data.StopTime;
                this.ParentForm.ParentForm.SaveCounterFile2(this.SelectedWeightData2, this.SelectedProductNo - 1);
            }
        }

        public void DisplayPrintButton(SystemConfigurationItem system)
        {
            if (system.SerialCOM1Mode == 3 || system.SerialCOM3Mode == 3)
                this.buttonPrint.Visible = true;
            else
                this.buttonPrint.Visible = false;
        }
        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.BasicDataStatistics;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.SelectedProductNo = this.ParentForm.ParentForm.SystemConfig.ProductNumber;

            if (this.buttonItemNo.Text != this.SelectedProductNo.ToString())
                this.buttonItemNo.Text = this.SelectedProductNo.ToString();

            this.ParentForm.ParentForm.LoadCounterFile1(ref this.SelectedWeightData1, this.SelectedProductNo - 1);
            this.ParentForm.ParentForm.LoadCounterFile2(ref this.SelectedWeightData2, this.SelectedProductNo - 1);

            this.ParentForm.ParentForm.LoadProductFile1(ref this.SelectedProductItem1, this.SelectedProductNo - 1);
            this.ParentForm.ParentForm.LoadProductFile2(ref this.SelectedProductItem2, this.SelectedProductNo - 1);

            this.UpdateDisplay1(this.SelectedWeightData1, this.SelectedProductItem1);
            this.UpdateDisplay2(this.SelectedWeightData2, this.SelectedProductItem2);
        }
        #endregion

        #region Event Handler
        private void buttonItemNo_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonItemNo.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 1000)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.buttonItemNo.Text = myKeyPad.StringValue;
                    this.SelectedProductNo = myKeyPad.IntValue;

                    this.ParentForm.ParentForm.LoadCounterFile1(ref this.SelectedWeightData1, this.SelectedProductNo - 1);
                    this.ParentForm.ParentForm.LoadCounterFile2(ref this.SelectedWeightData2, this.SelectedProductNo - 1);
                    this.ParentForm.ParentForm.LoadProductFile1(ref this.SelectedProductItem1, this.SelectedProductNo - 1);
                    this.ParentForm.ParentForm.LoadProductFile2(ref this.SelectedProductItem2, this.SelectedProductNo - 1);

                    this.UpdateDisplay1(this.SelectedWeightData1, this.SelectedProductItem1);
                    this.UpdateDisplay2(this.SelectedWeightData2, this.SelectedProductItem2);
                }
            }
        }

        private void buttonBackup_Click(object sender, EventArgs e)
        {
            string filePath = "";
            Bitmap bitMap = new Bitmap(800, 480);

            bitMap = IntechGraphics.CopyFromScreen();
            filePath = string.Format("{0}{1:yyyyMMdd_HHmm}_Capture_{2}.jpg", this.ParentForm.ParentForm.PathDataBackupFolder, DateTime.Now, this.ParentForm.ParentForm.SystemConfig.UsbID);
            bitMap.Save(filePath, ImageFormat.Jpeg);

            SmartSplash splash = new SmartSplash();
            splash.CenterPosition = true;
            splash.AnimationInterval = 200;
            splash.LoadingImagePathname = "SmartLoading4";
            splash.Start();

            #region Line1 데이터백업
            filePath = string.Format("{0}{1:yyyyMMdd_HHmm}_Data_{2}_Line1.csv", this.ParentForm.ParentForm.PathDataBackupFolder, DateTime.Now, this.ParentForm.ParentForm.SystemConfig.UsbID);
            this.ParentForm.ParentForm.smartFileIO.FilePathName = filePath;
            if (File.Exists(filePath) == false)
            {
                byte[] dd = new byte[3] { 0xEF, 0xBB, 0xBF }; //byte-order mark : UTF-8
                FileStream stm = new FileStream(this.ParentForm.ParentForm.smartFileIO.FilePathName, FileMode.Create);
                stm.Write(dd, 0, 3);
                stm.Close();
            }

            this.ParentForm.ParentForm.smartFileIO.Open();
            this.ParentForm.ParentForm.smartFileIO.WriteString("##############################");
            this.ParentForm.ParentForm.smartFileIO.WriteString("      TOTAL  PRINT  LINE1     ");
            this.ParentForm.ParentForm.smartFileIO.WriteString("##############################");
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" PART    = {0}", this.SelectedProductItem1.Number));
            if (this.SelectedWeightData1.StartTime.Year == 1111 || this.SelectedWeightData1.StopTime.Year == 1111)
                this.SelectedWeightData1.StartTime = this.SelectedWeightData1.StopTime = DateTime.Now;
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" START   = {0}", this.SelectedWeightData1.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" END     = {0}", this.SelectedWeightData1.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n UNDER   = {0}g",
                Helper.StringToDecimalPlaces(this.SelectedProductItem1.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.UnderCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" TOTAL.W = {0}kg", this.SelectedWeightData1.UnderSumWeightKG));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" AVG     = {0}g",
                Helper.DoubleToString(this.SelectedWeightData1.UnderAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" RATIO   = {0}%", this.SelectedWeightData1.UnderRatio));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n PASS    = {0}g",
              Helper.StringToDecimalPlaces(this.SelectedProductItem1.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.PassCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" TOTAL.W = {0}kg", this.SelectedWeightData1.PassSumWeightKG));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" AVG     = {0}g",
                Helper.DoubleToString(this.SelectedWeightData1.PassAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" RATIO   = {0}%", this.SelectedWeightData1.PassRatio));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n OVER    = {0}g",
              Helper.StringToDecimalPlaces(this.SelectedProductItem1.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.OverCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" TOTAL.W = {0}kg", this.SelectedWeightData1.OverSumWeightKG));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" AVG     = {0}g",
                Helper.DoubleToString(this.SelectedWeightData1.OverAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" RATIO   = {0}%", this.SelectedWeightData1.OverRatio));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n TARE    = {0}g",
                Helper.StringToDecimalPlaces(this.SelectedProductItem1.TareRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n Faulty  = {0}", this.SelectedWeightData1.TotalUnderOverCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" Other.F = {0}", this.SelectedWeightData1.ETCExNGCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(" TOTAL");
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.TotalCount));

            this.ParentForm.ParentForm.smartFileIO.Close(); 
            #endregion

            #region Line2 데이터백업
            filePath = string.Format("{0}{1:yyyyMMdd_HHmm}_Data_{2}_Line2.csv", this.ParentForm.ParentForm.PathDataBackupFolder, DateTime.Now, this.ParentForm.ParentForm.SystemConfig.UsbID);
            this.ParentForm.ParentForm.smartFileIO.FilePathName = filePath;
            if (File.Exists(filePath) == false)
            {
                byte[] dd = new byte[3] { 0xEF, 0xBB, 0xBF }; //byte-order mark : UTF-8
                FileStream stm = new FileStream(this.ParentForm.ParentForm.smartFileIO.FilePathName, FileMode.Create);
                stm.Write(dd, 0, 3);
                stm.Close();
            }

            this.ParentForm.ParentForm.smartFileIO.Open();
            this.ParentForm.ParentForm.smartFileIO.WriteString("##############################");
            this.ParentForm.ParentForm.smartFileIO.WriteString("      TOTAL  PRINT  LINE2     ");
            this.ParentForm.ParentForm.smartFileIO.WriteString("##############################");
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" PART    = {0}", this.SelectedProductItem1.Number));
            if (this.SelectedWeightData1.StartTime.Year == 1111 || this.SelectedWeightData1.StopTime.Year == 1111)
                this.SelectedWeightData1.StartTime = this.SelectedWeightData1.StopTime = DateTime.Now;
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" START   = {0}", this.SelectedWeightData1.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" END     = {0}", this.SelectedWeightData1.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n UNDER   = {0}g",
                Helper.StringToDecimalPlaces(this.SelectedProductItem1.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.UnderCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" TOTAL.W = {0}kg", this.SelectedWeightData1.UnderSumWeightKG));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" AVG     = {0}g",
                Helper.DoubleToString(this.SelectedWeightData1.UnderAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" RATIO   = {0}%", this.SelectedWeightData1.UnderRatio));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n PASS    = {0}g",
              Helper.StringToDecimalPlaces(this.SelectedProductItem1.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.PassCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" TOTAL.W = {0}kg", this.SelectedWeightData1.PassSumWeightKG));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" AVG     = {0}g",
                Helper.DoubleToString(this.SelectedWeightData1.PassAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" RATIO   = {0}%", this.SelectedWeightData1.PassRatio));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n OVER    = {0}g",
              Helper.StringToDecimalPlaces(this.SelectedProductItem1.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.OverCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" TOTAL.W = {0}kg", this.SelectedWeightData1.OverSumWeightKG));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" AVG     = {0}g",
                Helper.DoubleToString(this.SelectedWeightData1.OverAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" RATIO   = {0}%", this.SelectedWeightData1.OverRatio));

            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n TARE    = {0}g",
                Helper.StringToDecimalPlaces(this.SelectedProductItem1.TareRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format("\n Faulty  = {0}", this.SelectedWeightData1.TotalUnderOverCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" Other.F = {0}", this.SelectedWeightData1.ETCExNGCount));
            this.ParentForm.ParentForm.smartFileIO.WriteString(" TOTAL");
            this.ParentForm.ParentForm.smartFileIO.WriteString(string.Format(" COUNT   = {0}", this.SelectedWeightData1.TotalCount));

            this.ParentForm.ParentForm.smartFileIO.Close(); 
            #endregion

            splash.Finish();
        }

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            this.buttonPrint.Enabled = false;
            this.buttonClear.Enabled = false;
            this.timerPrinting.Interval = 2700;
            this.timerPrinting.Enabled = true;

            this.ParentForm.ParentForm.PrintingWeight
                (this.ParentForm.ParentForm.CurrentWeightData1, this.ParentForm.ParentForm.CurrentWeightData2,
                this.ParentForm.ParentForm.CurrentProductItem1, this.ParentForm.ParentForm.CurrentProductItem2);

            //this.buttonPrint.Enabled = false;
            //this.buttonClear.Enabled = false;
            //this.timerPrinting.Interval = 10000;
            //this.timerPrinting.Enabled = true;

            //this.ParentForm.ParentForm.PrintingWeight(this.SelectedWeightData, this.SelectedProductItem);
        }

        private void buttonClear_Click(object sender, EventArgs e)
        {
            DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig.Language, 8);
            if (myDlg.ShowDialog() == DialogResult.Yes)
            {
                this.ParentForm.ParentForm.ChildFormMainDisplay.Clear();

                this.ParentForm.ParentForm.LoadCounterFile1(ref this.SelectedWeightData1, this.SelectedProductNo - 1);
                this.ParentForm.ParentForm.LoadProductFile1(ref this.SelectedProductItem1, this.SelectedProductNo - 1);
                this.UpdateDisplay1(this.SelectedWeightData1, this.SelectedProductItem1);

                this.ParentForm.ParentForm.LoadCounterFile2(ref this.SelectedWeightData2, this.SelectedProductNo - 1);
                this.ParentForm.ParentForm.LoadProductFile2(ref this.SelectedProductItem2, this.SelectedProductNo - 1);
                this.UpdateDisplay2(this.SelectedWeightData2, this.SelectedProductItem2);
            }
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.buttonPrint.Enabled = true;
            this.buttonClear.Enabled = true;
            this.timerPrinting.Enabled = false;
        }
        #endregion
    }
}
