using ManualSoftwareSystem.lib;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.AxHost;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace ManualSoftwareSystem.Operation_Manual
{
    public partial class FrmOperationManualOperator : Form
    {
        private string csvPartFile = string.Empty;
        private List<List<string>> Operator = new List<List<string>>();
        private List<List<string>> Language = new List<List<string>>();
        private List<List<string>> SoftwareSystem = new List<List<string>>();
        private string csvPartFileOperator = System.IO.Directory.GetCurrentDirectory() + "\\Operator.sys";
        private string csvPartFileLanguage = System.IO.Directory.GetCurrentDirectory() + "\\Language.sys";
        private string csvSoftwareSystem = "C:\\ProgramData\\SoftwareSystem\\SoftwareSystem.sys";
        private string loginUser = string.Empty;
        private string type = string.Empty;
        public static string strLanguage = string.Empty;
        private object objLanguageThai;
        private object objLanguageEnglish;
        public static dynamic objLanguage;
        public static string strPage = string.Empty;
        public static bool isViewer = false;
        //public static string Regname = "Registryname";
        //public static string Regname = @"Software\RegistrySoftware\";
        public static string Regname = @"RegistrySoftware";
        public static bool isTrial = false;
        Microsoft.Win32.RegistryKey key;
        public static string commentTypeShare = string.Empty;
        public static string TextTypeShare = string.Empty;
        public static string WordCountShare = string.Empty;
        public static string SerialNumberShare = string.Empty;
        public static string MinShare = string.Empty;
        public static string MaxShare = string.Empty;
        public static string UnitShare = string.Empty;
        public static bool startClickShare = false;
        public static string excelPathShare = string.Empty;
        public static string TitleShare = string.Empty;
        public static string MessageShare = string.Empty;
        public static string CommentShare = string.Empty;
        public static bool HandingOverShare = false;
        public static string loginShare = string.Empty;
        public static bool ErrorClickShare = false;
        public static string WeatherShare = string.Empty;
        public static string TemperatureShare = string.Empty;
        public static string HumidityShare = string.Empty;
        public static string RemarksShare = string.Empty;
        public static bool CancelClickShare = false;
        public static bool ErrorCloseShare = false;
        public static string DateStartShare = string.Empty;
        private DateTime dateTimeCount;
        private string strDateTimeCount = string.Empty;
        private Int32 intHH = 0;
        private Int32 intMM = 0;
        private Int32 intSS = 0;
        private string strHH = "00";
        private string strMM = "00";
        private string strSS = "00";
        private string strDateTimeCountNow = string.Empty;
        private DateTime DateTimeCountNow;
        private string strDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        private string[] strData;
        private Int32 intCount;
        private string strCount;
        private Int32 intDiffDate;
        private Int32 intDiffDateCount;
        private Int32 intDiffDateTimeCount;
        private string strDateStart;
        private string strSoftwareSystemPath = "C:\\ProgramData\\SoftwareSystem";
        public static bool blClickBlack = false;
        public static string strType = string.Empty;
        public static string strFileMaster = string.Empty;
        public static string strPageError = string.Empty;
        public static string strLoginError = string.Empty;
        public static string strFormatName = string.Empty;

        public FrmOperationManualOperator(string pathFile, string type)
        {
            InitializeComponent();
            this.csvPartFile = pathFile;
            this.type = type;
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);

        }

        private void FrmOperationManualOperator_Load(object sender, EventArgs e)
        {
            //string strDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //string[] strData;
            //Int32 intCount;
            //string strCount;
            //Int32 intDiffDate;
            //Int32 intDiffDateCount;
            //Int32 intDiffDateTimeCount;
            //string strDateStart;
            //string strSoftwareSystemPath = "C:\\ProgramData\\SoftwareSystem";

            bool exists = System.IO.Directory.Exists(strSoftwareSystemPath);

            if (!exists)
                System.IO.Directory.CreateDirectory(strSoftwareSystemPath);

            if (!File.Exists(csvSoftwareSystem))
            {
                using (StreamWriter sw = File.CreateText(csvSoftwareSystem))
                {
                    strDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    strDateStart = strDate;
                    strCount = "1";
                    sw.WriteLine("0,1|" + strDate + "|" + strDate + "|" + strDate);
                }
            }

            List<string> tmp1 = null;
            SoftwareSystem = new List<List<string>>();
            tmp1 = null;
            using (var csv = new CsvReader(csvSoftwareSystem))
            {
                while ((tmp1 = csv.ReadRow()) != null)
                {
                    SoftwareSystem.Add(tmp1);

                }

            }//using end

            if (SoftwareSystem[0][1].Split("|").Length == 4)
            {
                strData = SoftwareSystem[0][1].Split("|");
                DateStartShare = strData[1];
                strDateTimeCount = strData[3];
                strDateTimeCountNow = strData[3];
                dateTimeCount = Convert.ToDateTime(strDateTimeCount);
                DateTimeCountNow = Convert.ToDateTime(strDateTimeCountNow);
                if (DateTimeCountNow < DateTime.Now)
                {
                    DateTimeCountNow = DateTime.Now;
                    intHH = DateTimeCountNow.Hour;
                    intMM = DateTimeCountNow.Minute;
                    intSS = DateTimeCountNow.Second;

                    if ((Convert.ToDateTime(strData[2]) < Convert.ToDateTime(strDate)) && (Convert.ToDateTime(strData[1]) < Convert.ToDateTime(strDate)))
                    {
                        intDiffDate = (Convert.ToDateTime(strDate).Date - Convert.ToDateTime(strData[1]).Date).Days + 1;
                        intDiffDateCount = (Convert.ToDateTime(strDate).Date - Convert.ToDateTime(strData[2]).Date).Days;
                        //intDiffDateTimeCount = (Convert.ToDateTime(strDate).Date - Convert.ToDateTime(strData[3]).Date).Days;
                        intCount = Convert.ToInt32(strData[0]);
                        strDateStart = strData[1];
                        if ((intDiffDate <= 30) && (intCount <= 30))
                        {
                            intCount = Convert.ToInt32(strData[0]) + intDiffDateCount;
                            strCount = Convert.ToString(intCount);
                            //writeRegistryKey("0", strCount + "|" + strDateStart + "|" + strDate);
                            writeSoftwareSystem(csvSoftwareSystem, "0," + strCount + "|" + strDateStart + "|" + strDate + "|" + DateTimeCountNow);
                            isTrial = true;
                        }
                        else
                        {
                            intCount = Convert.ToInt32(strData[0]) + intDiffDateCount;
                            strCount = Convert.ToString(intCount);
                            writeSoftwareSystem(csvSoftwareSystem, "0," + strCount + "|" + strDateStart + "|" + strDate + "|" + DateTimeCountNow);
                            isTrial = false;
                        }

                    }
                    else if ((Convert.ToDateTime(strData[2]) == Convert.ToDateTime(strDate)) && (Convert.ToDateTime(strData[1]) <= Convert.ToDateTime(strDate)))
                    {
                        intDiffDate = (Convert.ToDateTime(strDate).Date - Convert.ToDateTime(strData[1]).Date).Days;
                        intCount = Convert.ToInt32(strData[0]);
                        if ((intDiffDate <= 30) && (intCount <= 30))
                        {
                            isTrial = true;
                        }
                        else
                        {
                            isTrial = false;
                        }

                    }
                    else
                    {
                        isTrial = false;
                    }
                }
                else
                {
                    isTrial = false;
                }
                timer1.Enabled = true;
            }

            lblTrial.Text = "Trial : " + (31 - intCount) + " day";

            //lblTrial.Text = "Trial : 30 day";

            if (!File.Exists(csvPartFileLanguage))
            {
                using (StreamWriter sw = File.CreateText(csvPartFileLanguage))
                {
                    sw.WriteLine("English");
                }
            }

            List<string> tmpLanguage = null;
            Language = new List<List<string>>();
            tmpLanguage = null;
            using (var csv = new CsvReader(csvPartFileLanguage))
            {
                while ((tmpLanguage = csv.ReadRow()) != null)
                {
                    Language.Add(tmpLanguage);
                }

            }//using end

            strLanguage = this.Language[0][0];

            switch (strLanguage)
            {
                case "English":

                    clsLanguageEnglish objLanguageEnglish = new clsLanguageEnglish();

                    objLanguage = objLanguageEnglish;

                    break;
                case "Thai":
                    clsLanguageThai objLanguageThai = new clsLanguageThai();

                    objLanguage = objLanguageThai;
                    break;
                case "Japanese":
                    clsLanguageJapan objLanguageJapan = new clsLanguageJapan();

                    objLanguage = objLanguageJapan;
                    break;
                case "Vietnamese":
                    clsLanguageVietnamese objLanguageVietnamese = new clsLanguageVietnamese();

                    objLanguage = objLanguageVietnamese;
                    break;
                default:
                    clsLanguageEnglish objLanguageEnglishDefault = new clsLanguageEnglish();

                    objLanguage = objLanguageEnglishDefault;
                    break;
            }


            //isTrial = true; //For Test no License


            CheckSerialUSB.SerialUSB = CheckSerialUSB.CheckSerialUSBLicense();

            CheckSerialUSBWarning();


            if (!File.Exists(csvPartFileOperator))
            {
                using (StreamWriter sw = File.CreateText(csvPartFileOperator))
                {
                    //sw.WriteLine("");
                }
            }

            if (!File.Exists(csvPartFileLanguage))
            {
                using (StreamWriter sw = File.CreateText(csvPartFileLanguage))
                {
                    sw.WriteLine("English");
                }
            }

            cmbOperator.Items.Clear();

            //List<string> tmpLanguage = null;
            //Language = new List<List<string>>();
            //tmpLanguage = null;
            //using (var csv = new CsvReader(csvPartFileLanguage))
            //{
            //    while ((tmpLanguage = csv.ReadRow()) != null)
            //    {
            //        Language.Add(tmpLanguage);
            //    }

            //}//using end

            //strLanguage = this.Language[0][0];

            cmbLanguage.Items.Add("English");
            cmbLanguage.Items.Add("Thai");
            cmbLanguage.Items.Add("Japanese");
            cmbLanguage.Items.Add("Vietnamese");

            cmbLanguage.Text = strLanguage;

            switch (strLanguage)
            {
                case "English":

                    clsLanguageEnglish objLanguageEnglish = new clsLanguageEnglish();

                    objLanguage = objLanguageEnglish;

                    break;
                case "Thai":
                    clsLanguageThai objLanguageThai = new clsLanguageThai();

                    objLanguage = objLanguageThai;
                    break;
                case "Japanese":
                    clsLanguageJapan objLanguageJapan = new clsLanguageJapan();

                    objLanguage = objLanguageJapan;
                    break;
                case "Vietnamese":
                    clsLanguageVietnamese objLanguageVietnamese = new clsLanguageVietnamese();

                    objLanguage = objLanguageVietnamese;
                    break;
                default:
                    clsLanguageEnglish objLanguageEnglishDefault = new clsLanguageEnglish();

                    objLanguage = objLanguageEnglishDefault;
                    break;
            }

            string strOperator = "Operator";
            string strOperatorRequired = "Operator (*Required)";
            string strAddOperator = "Add";
            string strDelOperator = "Del";
            string strYes = "Yes";
            string strCancel = "Cancel";


            lblOperator.Text = objLanguage.Translate(strOperator);
            lblOperatorRequired.Text = objLanguage.Translate(strOperatorRequired);
            btnAddOperator.Text = objLanguage.Translate(strAddOperator);
            btnDelOperator.Text = objLanguage.Translate(strDelOperator);
            btnYes.Text = objLanguage.Translate(strYes);
            btnCancel.Text = objLanguage.Translate(strCancel);


            List<string> tmp = null;
            Operator = new List<List<string>>();
            tmp = null;
            Int32 i = 0;
            using (var csv = new CsvReader(csvPartFileOperator))
            {
                while ((tmp = csv.ReadRow()) != null)
                {
                    Operator.Add(tmp);

                    cmbOperator.Items.Add(this.Operator[i][0]);

                    i = i + 1;
                }

            }//using end

            isViewer = false;

        }

        public void writeSoftwareSystem(string path, string writeData)
        {
            //CSV Encoding
            System.Text.Encoding enc =
                System.Text.Encoding.UTF8;

            System.IO.StreamWriter sr =
                new System.IO.StreamWriter(path, false, enc);

            sr.WriteLine(writeData);

            sr.Close();
        }

        public bool writeRegistryKey(string Key, string value)
        {
            try
            {
                Microsoft.Win32.RegistryKey key;

                System.Security.Permissions.RegistryPermission permissions = new System.Security.Permissions.RegistryPermission
                    (System.Security.Permissions.RegistryPermissionAccess.AllAccess, @"HKEY_CLASSES_ROOT\" + Regname);

                bool regPermissions = System.Security.SecurityManager.IsGranted(permissions);

                key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(Regname);

                key.SetValue(Key, value);
                key.Close();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public string readRegistryKey(string Key)
        {
            try
            {


                string keyValue = null;
                Microsoft.Win32.RegistryKey key;
                RegistryKey registryKey;
                if (Environment.Is64BitOperatingSystem == true)
                {
                    registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
                }
                else
                {
                    registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
                }

                registryKey = registryKey.OpenSubKey(@"SOFTWARE\");



                //registryKey = registryKey.CreateSubKey(Regname);

                RegistrySecurity userSecurity = new RegistrySecurity();
                RegistryAccessRule userRule = new RegistryAccessRule("SYSTEM", RegistryRights.FullControl, AccessControlType.Allow);
                userSecurity.AddAccessRule(userRule);


                registryKey.SetAccessControl(userSecurity);

                registryKey = registryKey.CreateSubKey(Regname);

                //registryKey = registryKey.CreateSubKey(Regname, RegistryKeyPermissionCheck.ReadWriteSubTree, userSecurity);





                //registryKey = registryKey.CreateSubKey(Regname, RegistryKeyPermissionCheck.ReadWriteSubTree, userSecurity);

                key = registryKey.CreateSubKey(Regname);

                if (key == null)
                {
                    key = registryKey.CreateSubKey(Regname);
                }

                keyValue = key.GetValue(Key).ToString();
                key.Close();
                return keyValue;

                //System.Security.Permissions.RegistryPermission permissions = new System.Security.Permissions.RegistryPermission
                //    (System.Security.Permissions.RegistryPermissionAccess.AllAccess, @"HKEY_LOCAL_MACHINE\" + Regname);

                //bool regPermissions = System.Security.SecurityManager.IsGranted(permissions);


                //RegistryKey regKey;//= this.key.OpenSubKey(@"HKEY_LOCAL_MACHINE\" + Regname, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions | RegistryRights.ReadKey);
                //if (this.key.OpenSubKey(@"HKEY_LOCAL_MACHINE\" + Regname, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ChangePermissions | RegistryRights.ReadKey) == null)

                //if (regKey == null)
                //{
                //RegistrySecurity userSecurity = new RegistrySecurity();
                //    RegistryAccessRule userRule = new RegistryAccessRule("Administrator", RegistryRights.FullControl, AccessControlType.Allow);
                //    userSecurity.AddAccessRule(userRule);

                //    //regKey = this.key.CreateSubKey(@"HKEY_LOCAL_MACHINE\" + Regname, RegistryKeyPermissionCheck.ReadWriteSubTree, userSecurity);
                //key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(Regname, RegistryKeyPermissionCheck.ReadWriteSubTree, userSecurity);

                //}
                //key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(Regname);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return null;
            }
        }

        public void CheckSerialUSBWarning()
        {
            if (CheckSerialUSB.SerialUSB == string.Empty)
            {
                //MessageBoxManager.OK = objLanguage.Translate("OK");
                //MessageBoxManager.Register();
                MessageBox.Show(this, objLanguage.Translate("Please insert the USB key."),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                //MessageBoxManager.Unregister();
                Application.Exit();
            }
            else if (CheckSerialUSB.SerialUSB == "Get")
            {
                //MessageBoxManager.OK = objLanguage.Translate("OK");
                //MessageBoxManager.Register();
                MessageBox.Show(this, objLanguage.Translate("Not correct"),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                //MessageBoxManager.Unregister();
                Application.Exit();
            }
            else if (CheckSerialUSB.SerialUSB == "OK")
            {
                //lblTrial.Text = string.Empty;
            }
            else
            {
                lblTrial.Text = string.Empty;
            }
        }

        private void btnAddOperator_Click(object sender, EventArgs e)
        {
            if (cmbOperator.Text.Trim() == string.Empty)
            {
                //MessageBoxManager.OK = objLanguage.Translate("OK");
                //MessageBoxManager.Register();
                MessageBox.Show(this, objLanguage.Translate("Operator is Blanks"),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                //MessageBoxManager.Unregister();
                return;
            }


            //int index = cmbOperator.FindString(cmbOperator.Text.Trim());

            int index = cmbOperator.FindStringExact(cmbOperator.Text.Trim());

            if (index == -1)
            {
                cmbOperator.Items.Add(cmbOperator.Text.Trim());

                //CSV Encoding
                System.Text.Encoding enc =
                    System.Text.Encoding.UTF8;

                System.IO.StreamWriter sr =
                    new System.IO.StreamWriter(csvPartFileOperator, false, enc);

                for (int i = 0; i < cmbOperator.Items.Count; i++)
                {
                    sr.WriteLine(cmbOperator.Items[i]);
                }

                sr.Close();
            }
        }

        private void btnDelOperator_Click(object sender, EventArgs e)
        {
            if (cmbOperator.Text.Trim() == string.Empty)
            {
                //MessageBoxManager.OK = objLanguage.Translate("OK");
                //MessageBoxManager.Register();
                MessageBox.Show(this, objLanguage.Translate("Operator is Blanks"),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                //MessageBoxManager.Unregister();
                return;
            }

            int index = cmbOperator.FindStringExact(cmbOperator.Text.Trim());

            if (index > -1)
            {
                cmbOperator.Items.RemoveAt(index);

                //CSV Encoding
                System.Text.Encoding enc =
                    System.Text.Encoding.UTF8;

                System.IO.StreamWriter sr =
                    new System.IO.StreamWriter(csvPartFileOperator, false, enc);

                for (int i = 0; i < cmbOperator.Items.Count; i++)
                {
                    sr.WriteLine(cmbOperator.Items[i]);
                }

                sr.Close();

                cmbOperator.Text = string.Empty;

            }

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnYes_Click(object sender, EventArgs e)
        {
            if (cmbOperator.Text.Trim() == string.Empty)
            {

                //MessageBoxManager.OK = objLanguage.Translate("OK");
                //MessageBoxManager.Register();
                MessageBox.Show(this, objLanguage.Translate("Operator is Blanks"),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                //MessageBoxManager.Unregister();
                return;
            }

            //btnAddOperator_Click(sender, e);
            loginUser = cmbOperator.Text.Trim();

            FrmOperationManualOperator.loginShare = cmbOperator.Text.Trim();

            if (FrmOperationManualOperator.strType == "Operation Manual")
            {
                FrmOperationManualInput frmOperationManualInput = new FrmOperationManualInput(csvPartFile, loginUser, FrmOperationManualOperator.strType);

                if (csvPartFile == string.Empty)
                {
                    this.Hide();
                }
                else
                {
                    this.Dispose();
                }


                frmOperationManualInput.ShowDialog();
            }
            else
            {
                FrmInspectionInformation frmInspectionInformation = new FrmInspectionInformation(csvPartFile, loginUser, FrmOperationManualOperator.strType);

                if (csvPartFile == string.Empty)
                {
                    this.Hide();
                }
                else
                {
                    this.Dispose();
                }


                frmInspectionInformation.ShowDialog();
            }




        }

        private void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {

            strLanguage = cmbLanguage.Text;

            //CSV Encoding
            System.Text.Encoding enc =
                System.Text.Encoding.UTF8;

            System.IO.StreamWriter sr =
                new System.IO.StreamWriter(csvPartFileLanguage, false, enc);

            sr.WriteLine(strLanguage);

            sr.Close();

            switch (strLanguage)
            {
                case "English":

                    clsLanguageEnglish objLanguageEnglish = new clsLanguageEnglish();

                    objLanguage = objLanguageEnglish;

                    break;
                case "Thai":
                    clsLanguageThai objLanguageThai = new clsLanguageThai();

                    objLanguage = objLanguageThai;
                    break;
                case "Japanese":
                    clsLanguageJapan objLanguageJapan = new clsLanguageJapan();

                    objLanguage = objLanguageJapan;
                    break;
                case "Vietnamese":
                    clsLanguageVietnamese objLanguageVietnamese = new clsLanguageVietnamese();

                    objLanguage = objLanguageVietnamese;
                    break;
                default:
                    clsLanguageEnglish objLanguageEnglishDefault = new clsLanguageEnglish();

                    objLanguage = objLanguageEnglishDefault;
                    break;
            }

            string strOperator = "Operator";
            string strOperatorRequired = "Operator (*Required)";
            string strAddOperator = "Add";
            string strDelOperator = "Del";
            string strYes = "Yes";
            string strCancel = "Cancel";


            lblOperator.Text = objLanguage.Translate(strOperator);
            lblOperatorRequired.Text = objLanguage.Translate(strOperatorRequired);
            btnAddOperator.Text = objLanguage.Translate(strAddOperator);
            btnDelOperator.Text = objLanguage.Translate(strDelOperator);
            btnYes.Text = objLanguage.Translate(strYes);
            btnCancel.Text = objLanguage.Translate(strCancel);

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (backgroundWorker1.IsBusy == false)
            {
                backgroundWorker1.RunWorkerAsync();


                strDateTimeCountNow = DateTimeCountNow.Date.ToString("yyyy-MM-dd") + " " + strHH + ":" + strMM + ":" + strSS;


            }
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            intSS = intSS + 1;

            if (intSS > 59)
            {
                intSS = 0;
                intMM = intMM + 1;
            }

            if (intMM > 59)
            {
                intMM = 0;
                intHH = intHH + 1;
            }

            if (intHH > 23)
            {
                intHH = 0;
                DateTimeCountNow = Convert.ToDateTime(strDateTimeCountNow).AddDays(1);
            }

            if (intSS.ToString().Length == 1)
            {
                strSS = "0" + intSS.ToString();
            }
            else
            {
                strSS = intSS.ToString();
            }

            if (intMM.ToString().Length == 1)
            {
                strMM = "0" + intMM.ToString();
            }
            else
            {
                strMM = intMM.ToString();
            }

            if (intHH.ToString().Length == 1)
            {
                strHH = "0" + intHH.ToString();
            }
            else
            {
                strHH = intHH.ToString();
            }
        }

        private void FrmOperationManualOperator_FormClosing(object sender, FormClosingEventArgs e)
        {
            writeSoftwareSystem(csvSoftwareSystem, "0," + strCount + "|" + strDateStart + "|" + strDate + "|" + strDateTimeCountNow);
        }
    }
}
