using ManualSoftwareSystem.lib;
using ManualSoftwareSystem.Operation_Manual;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Mime;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ManualSoftwareSystem
{
    public partial class FrmOperationManual : Form
    {

        private bool viewer = false;
        private List<List<string>> Master = new List<List<string>>();
        private Int32 rowCount = 0;
        private Int32 rowCurrent = -1;
        private List<Int32> rowsNo = new List<Int32>();
        private Int32 intRowSelect = 0;
        private Int32 intRowStart = 0;
        private Int32 intColPicSelect = 0;
        private string csvPartFile = string.Empty;
        private string type = string.Empty;
        private string loginUser = string.Empty;
        private string machineName = string.Empty;
        public static bool startClick = false;
        public static bool stopClick = false;
        public static bool ENDClick = false;
        public static bool RestartClick = false;
        public static string strWorkHistory = string.Empty;
        public static string strWorkHistoryStopError = string.Empty;
        public static string strStartDate = string.Empty;
        public static string strStartTime = string.Empty;
        public static string strPathSave = string.Empty;
        public static string strPathSaveComplete = string.Empty;
        public static string strWorkComplete = string.Empty;
        public static string strStartDate001 = string.Empty;
        public static string strStartTime001 = string.Empty;
        public static string strContinueTime001 = string.Empty;

        public static List<string> listS = new List<string>();
        public static List<string> listSBNEF = new List<string>();
        public static string strAll = string.Empty;
        public static string strType = string.Empty;

        private double dblAll = 0;
        private Int32 intAll = 0;
        public dynamic objLanguage;
        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 Int32 intHHstart = 0;
        private Int32 intMMstart = 0;
        private Int32 intSSstart = 0;
        private string strHHstart = "00";
        private string strMMstart = "00";
        private string strSSstart = "00";
        private string[] arrayCondition;
        private string condition = string.Empty;
        private string commentType = string.Empty;
        private string strTitle = string.Empty;
        private string strMessage = string.Empty;
        private string strComment = string.Empty;
        private string strTextType = string.Empty;
        private string strWordCount = string.Empty;
        private string strMin = string.Empty;
        private string strMax = string.Empty;
        private string strUnit = string.Empty;
        private Int32 intPageAll = 0;
        private Int32 intDiffAll = 0;
        private string strDiffAll = string.Empty;
        private string strDateStop = string.Empty;
        private string strTimeStop = string.Empty;

        private Int32 intHHContinue = 0;
        private Int32 intMMContinue = 0;
        private Int32 intSSContinue = 0;
        private string strHHContinue = "00";
        private string strMMContinue = "00";
        private string strSSContinue = "00";

        public static Int32 intHHstartError = 0;
        public static Int32 intMMstartError = 0;
        public static Int32 intSSstartError = 0;
        public static string strHHstartError = "00";
        public static string strMMstartError = "00";
        public static string strSSstartError = "00";

        public FrmOperationManual(bool viewer, DataGridView dgView1, string pathFile, string type, string loginUser)
        {
            InitializeComponent();
            this.objLanguage = FrmOperationManualOperator.objLanguage;
            this.viewer = viewer;
            this.csvPartFile = pathFile;
            strWorkHistory = Path.GetFileName(this.csvPartFile).Substring(0, Path.GetFileName(this.csvPartFile).Length - 4);
            strWorkHistoryStopError = Path.GetFileName(this.csvPartFile).Substring(0, Path.GetFileName(this.csvPartFile).Length - 4);
            FrmOperationManualOperator.strFileMaster = Path.GetFileName(this.csvPartFile).Substring(0, Path.GetFileName(this.csvPartFile).Length - 4);
            machineName = System.Environment.MachineName;
            strPathSave = Path.GetDirectoryName(this.csvPartFile) + "\\" + machineName + "_visual_teacher_pro_"
                + DateTime.Now.ToString("yyyy_MM") + ".csv";
            strPathSaveComplete = csvPartFile.Substring(0, csvPartFile.Length - 3) + "001.nck";
            this.type = type;
            this.loginUser = loginUser;
            FrmOperationManualOperator.strLoginError = loginUser;
            //dataGridView1 = dgView1;
            //dataGridView1.SelectAll();
            if (FrmOperationManualOperator.isViewer == true)
            {
                if (dgView1.CurrentRow.Index != null)
                {
                    rowCurrent = dgView1.CurrentRow.Index;

                }
                else if (dgView1.CurrentCell.RowIndex != null)
                {
                    rowCurrent = dgView1.CurrentCell.RowIndex;
                }
                else
                {
                    rowCurrent = -1;
                }
            }
            dgView1.SelectAll();
            rowCount = dgView1.SelectedRows.Count;
            DataObject dataObj = dgView1.GetClipboardContent();
            if (dataObj != null)
                Clipboard.SetDataObject(dataObj);
        }

        private void FrmOperationManual_Load(object sender, EventArgs e)
        {
            string strComment = "Comment";
            string strOKNext = "OK\r\nNEXT";
            string strStop = "STOP";
            string strData = string.Empty;
            string[] listContinueTime;

            listS = new List<string>();
            listSBNEF = new List<string>();

            FrmOperationManualOperator.CancelClickShare = false;

            FrmOperationManual.stopClick = false;

            FrmOperationManualOperator.startClickShare = false;

            FrmOperationManualOperator.blClickBlack = false;


            lblComment.Text = objLanguage.Translate(strComment);
            btnOKNext.Text = objLanguage.Translate(strOKNext);
            btnStop.Text = objLanguage.Translate(strStop);

            if (type == "Operation Manual")
            {
                this.Text = objLanguage.Translate("Operation Manual");
            }
            else
            {
                this.Text = objLanguage.Translate("Inspection Work");
            }



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


            strContinueTime001 = "00:00:00";


            if (viewer == true)
            {


                if (FrmOperationManualOperator.isViewer == true)
                {
                    if (rowCurrent == -1)
                    {
                        //MessageBox.Show(objLanguage.Translate("Please select a row"), objLanguage.Translate("Viewer"),
                        MessageBox.Show(objLanguage.Translate("Please select a row"), objLanguage.Translate("Preview"),
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Close();
                    }
                }
                else
                {
                    if (rowCount == 0)
                    {
                        //MessageBox.Show(objLanguage.Translate("Please select a row"), objLanguage.Translate("Viewer"),
                        MessageBox.Show(objLanguage.Translate("Please select a row"), objLanguage.Translate("Preview"),
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Close();
                    }
                }


                ViewClipboardValue();
                PasteClipboardValue();


                if (!File.Exists(strPathSaveComplete))
                {

                    using (StreamWriter sw = File.CreateText(strPathSaveComplete))
                    {
                        if (dataGridView1.Rows.Count == 0)
                        {
                            return;
                        }

                        sw.WriteLine(objLanguage.Translate("形式") + "," + objLanguage.Translate("図番") + "," + objLanguage.Translate("版数") + ","
                        + objLanguage.Translate("インデックス") + "," + objLanguage.Translate("情報1") + "," + objLanguage.Translate("情報2") + "," +
                        objLanguage.Translate("情報3") + "," + objLanguage.Translate("情報4") + "," + objLanguage.Translate("情報5") + "," +
                        objLanguage.Translate("1検査-1") + "," + objLanguage.Translate("1検査-2") + "," + objLanguage.Translate("1検査-3")
                            + "," + dataGridView1[15, 0].Value.ToString().Replace("\r", "").Replace("\n", ""));
                        //sw.WriteLine("sample,,,,,,,,," + DateTime.Now.ToString("yyyy/MM/dd") + ",,"
                        //    + FrmOperationManualOperator.WeatherShare);
                        //sw.WriteLine("総台数,この番号,認識名称(シリアルNo),認識番号(製造番号),他１,他２,他３,他４,他５,"
                        //    + DateTime.Now.ToString("HH:mm:ss") + ",," + FrmOperationManualOperator.TemperatureShare);
                        sw.WriteLine(FrmOperationManualOperator.strFormatName + ",,,,,,,,," + "" + ",,"
                            + FrmOperationManualOperator.WeatherShare);
                        sw.WriteLine(objLanguage.Translate("総台数") + "," + objLanguage.Translate("この番号") + "," +
                        objLanguage.Translate("認識名称(シリアルNo)") + "," + objLanguage.Translate("認識番号(製造番号)") + "," +
                        objLanguage.Translate("他１") + "," + objLanguage.Translate("他２") + "," + objLanguage.Translate("他３") + "," +
                        objLanguage.Translate("他４") + "," + objLanguage.Translate("他５") + ","
                            + "" + ",," + FrmOperationManualOperator.TemperatureShare + ",00:00:00");
                        sw.WriteLine("1,1,,,,,,,," + loginUser + "," + FrmOperationManualOperator.RemarksShare + ","
                            + FrmOperationManualOperator.HumidityShare);

                        strStartDate001 = DateTime.Now.ToString("yyyy/MM/dd");
                        strStartTime001 = DateTime.Now.ToString("HH:mm:ss");
                        strContinueTime001 = "00:00:00";

                        for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            condition = dataGridView1[7, i].Value.ToString().Replace("\r", "").Replace("\n", "");
                            strTitle = dataGridView1[4, i].Value.ToString().Replace("\r", "").Replace("\n", "");
                            strMessage = dataGridView1[5, i].Value.ToString().Replace("\r", "").Replace("\n", "");
                            strComment = dataGridView1[3, i].Value.ToString().Replace("\r", "").Replace("\n", "");


                            if (condition == string.Empty)
                            {
                                //strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,,,,,," + "✔" + ","
                                //    + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ",";

                                strWorkComplete = strTitle + "," + strMessage + "," + strComment + ",,,,,,," + "" + ","
                                    + "" + ",";

                                sw.WriteLine(strWorkComplete);

                            }
                            else
                            {

                                if (condition.Split("|").Length == 8)
                                {
                                    arrayCondition = condition.Split("|");
                                    commentType = arrayCondition[0].Trim();
                                    strTextType = arrayCondition[1].Trim();
                                    strWordCount = arrayCondition[3].Trim();
                                    strMin = arrayCondition[2].Trim();
                                    strMax = arrayCondition[5].Trim();
                                    strUnit = arrayCondition[6].Trim();


                                    if (commentType == "Character input")
                                    {
                                        //strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,文字-強制,"
                                        //    + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                                        //    + ",,," + "✔" + ","
                                        //    + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                                        string strText = string.Empty;
                                        if (strTextType.Substring(strTextType.Length - 1, 1) == "]")
                                        {
                                            strText = "1";
                                        }

                                        strWorkComplete = strTitle + "," + strMessage + "," + strComment + ",," + objLanguage.Translate("文字 -強制") + ","
                                            + strTextType + "," + strWordCount
                                            + "," + strText + ",," + "" + ","
                                            + "" + "," + "";

                                        sw.WriteLine(strWorkComplete);

                                    }
                                    else if ((commentType == "Integer input") ||
                                            (commentType == "Decimal input"))
                                    {
                                        //strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,小数点±,"
                                        //    + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                                        //    + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + "✔" + ","
                                        //    + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                                        strWorkComplete = strTitle + "," + strMessage + "," + strComment + ",," + objLanguage.Translate("小数点±") + ","
                                            + strTextType + "," + strMin
                                            + "," + strMax + "," + strUnit + "," + "" + ","
                                            + "" + "," + "";

                                        sw.WriteLine(strWorkComplete);

                                    }
                                }
                            }
                        }

                        sw.WriteLine(objLanguage.Translate("管理者記入欄") + ",1-2-3-4,1-2-3,1,2,3,4," + FrmOperationManualOperator.DateStartShare + ",1," + "" + "," + "" + ","
                            + "");

                    }

                }
                else
                {

                    string strLine;
                    string[] strArray;
                    Int32 rowID = 0;
                    StreamReader srCheck = new StreamReader(strPathSaveComplete);
                    strLine = string.Empty;

                    while (srCheck.Peek() >= 0)
                    {
                        strLine = srCheck.ReadLine();
                        if (strLine != null)
                        {
                            strArray = strLine.Split(',');
                            if (strArray.Length > 11)
                            {
                                if (rowID == 1)
                                {
                                    FrmOperationManualOperator.strFormatName = strArray[0];
                                    strStartDate001 = strArray[9];
                                }
                                if (rowID == 2)
                                {
                                    strStartTime001 = strArray[9];
                                    if (strArray.Length > 12)
                                    {
                                        strContinueTime001 = strArray[12];
                                        if (strContinueTime001 == string.Empty)
                                        {
                                            strContinueTime001 = "00:00:00";
                                        }
                                    }

                                }
                            }

                        }
                        rowID = rowID + 1;

                    }

                    srCheck.Close();

                }


            }



            //if (dataGridView1.Rows.Count == 0)
            //{
            //    MessageBox.Show("Please check Manual Column", "Viewer",
            //    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    Close();
            //}

            //lblPage.Text = "1/" + dataGridView1.Rows.Count.ToString();

            btnBackStart.Enabled = false;
            btnBack.Enabled = false;

            listContinueTime = strContinueTime001.Split(":");

            intHH = Convert.ToInt32(listContinueTime[0]); // 0;
            strHH = listContinueTime[0]; // "00";
            intMM = Convert.ToInt32(listContinueTime[1]); // 0;
            strMM = listContinueTime[1]; // "00";
            intSS = Convert.ToInt32(listContinueTime[2]); // 0;
            strSS = listContinueTime[2]; // "00";
            intHHstart = 0;
            strHHstart = "00";
            intMMstart = 0;
            strMMstart = "00";
            intSSstart = 0;
            strSSstart = "00";

            intHHContinue = Convert.ToInt32(listContinueTime[0]); // 0;
            strHHContinue = listContinueTime[0]; // "00";
            intMMContinue = Convert.ToInt32(listContinueTime[1]); // 0;
            strMMContinue = listContinueTime[1]; // "00";
            intSSContinue = Convert.ToInt32(listContinueTime[2]); // 0;
            strSSContinue = listContinueTime[2]; // "00";

            //lblValueDetail.Text = "T00:00:00";

            //lblValueDetail.Text = "T" + strHH + ":" + strMM + ":" + strSS;

            lblValueDetail.Text = "T" + strHH + ":" + strMM + ":" + strSS + " S" + strHHstart + ":" + strMMstart + ":" + strSSstart;

            timer1.Enabled = true;
            timer2.Enabled = true;

            if (FrmOperationManualOperator.isViewer == true)
            {
                intRowSelect = rowCurrent;
            }
            else
            {
                intRowSelect = 0;
            }


            intColPicSelect = 12;

            //if (intRowSelect == 0)
            //{
            //    strWorkHistory = strWorkHistory + "," + "S";
            //}

            strStartDate = DateTime.Now.ToString("yyyy/M/dd");
            strStartTime = DateTime.Now.ToString("HH:mm:ss");

            if (FrmOperationManualOperator.isViewer == false)
            {

                if ((FrmOperationManualOperator.strPage == "PreviousPage") && (type == "Inspection Work"))
                {
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        if (dataGridView1[16, i].Value.ToString().Replace("\r", "").Replace("\n", "") == "1")
                        {
                            intRowSelect = i;
                            intRowStart = 0;
                            if (intRowSelect == 0)
                            {
                                strWorkHistory = strWorkHistory + "," + "S";
                                strWorkHistoryStopError = strWorkHistoryStopError + "," + "S";
                            }
                            else
                            {
                                strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString();
                                strWorkHistoryStopError = strWorkHistoryStopError + "," + (intRowSelect + 1).ToString();
                            }

                            if (intRowSelect == 0)
                            {
                                btnBack.Enabled = false;
                                btnBackStart.Enabled = false;
                            }
                            else if (intRowSelect > 0)
                            {
                                btnBack.Enabled = true;
                                btnBackStart.Enabled = true;
                            }

                        }
                    }
                }
                else if ((FrmOperationManualOperator.strPage == "FirstPage") && (type == "Inspection Work"))
                {
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        //strData = dataGridView1[0, i].Value.ToString() + "," +
                        //dataGridView1[1, i].Value.ToString() + "," +
                        //dataGridView1[2, i].Value.ToString() + "," +
                        strData = dataGridView1[3, i].Value.ToString() + "," +
                        dataGridView1[4, i].Value.ToString() + "," +
                        dataGridView1[5, i].Value.ToString() + "," +
                        dataGridView1[6, i].Value.ToString() + "," +
                        dataGridView1[7, i].Value.ToString() + "," +
                        dataGridView1[8, i].Value.ToString() + "," +
                        dataGridView1[9, i].Value.ToString() + "," +
                        dataGridView1[10, i].Value.ToString() + "," +
                        dataGridView1[11, i].Value.ToString() + "," +
                        dataGridView1[12, i].Value.ToString() + "," +
                        dataGridView1[13, i].Value.ToString() + "," +
                        dataGridView1[14, i].Value.ToString() + "," +
                        dataGridView1[15, i].Value.ToString() + ",";
                        if (i == 0)
                        {
                            strData = strData.Replace("\r", "").Replace("\n", "") + "1";
                        }
                        else
                        {
                            strData = strData.Replace("\r", "").Replace("\n", "") + "0";
                        }

                        lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, i + 1);
                    }
                    if (intRowSelect == 0)
                    {
                        strWorkHistory = strWorkHistory + "," + "S";
                    }
                }
                else
                {
                    if (intRowSelect == 0)
                    {
                        strWorkHistory = strWorkHistory + "," + "S";
                    }
                }
            }

            ShowData(intRowSelect, intColPicSelect, sender, e);


            if (FrmOperationManual.stopClick == true)
            {
                //btnStop_Click(sender, e);
                return;
            }

            if (FrmOperationManualOperator.startClickShare == true)
            {
                btnOKNext_Click(sender, e);
            }

        }



        private void ShowData(Int32 intRow, Int32 intColPic, object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count == 0)
            {
                return;
            }

            lblPage.Text = (intRow + 1).ToString() + "/" + dataGridView1.Rows.Count.ToString();

            progressBar1.Value = ((intRow + 1) * 100) / dataGridView1.Rows.Count;

            intPageAll = dataGridView1.Rows.Count + 1;

            if (dataGridView1[4, intRow].Value != null)
            {
                lblTitle.Text = dataGridView1[4, intRow].Value.ToString();
            }
            else
            {
                lblTitle.Text = string.Empty;
            }

            if (dataGridView1[5, intRow].Value != null)
            {
                lblMessage.Text = dataGridView1[5, intRow].Value.ToString();
            }
            else
            {
                lblMessage.Text = string.Empty;
            }

            if (dataGridView1[3, intRow].Value != null)
            {
                txtComment.Text = dataGridView1[3, intRow].Value.ToString();
            }
            else
            {
                txtComment.Text = string.Empty;
            }

            FrmOperationManualOperator.TitleShare = lblTitle.Text;
            FrmOperationManualOperator.MessageShare = lblMessage.Text;
            FrmOperationManualOperator.CommentShare = txtComment.Text;

            if (dataGridView1[14, intRow].Value != null)
            {
                if (dataGridView1[14, intRow].Value != string.Empty)
                {
                    picMain3.Image = null;
                    byte[] data;
                    //using (MemoryStream ms = new MemoryStream())
                    //{
                    data = Convert.FromBase64String(dataGridView1[14, intRow].Value.ToString());
                    picMain3.Image = byteArrayToImage((byte[])data);

                    //}

                }
                else
                {
                    picMain3.Image = null;
                }
            }
            else
            {
                picMain3.Image = null;
            }

            if (dataGridView1[intColPic, intRow].Value != null)
            {
                if (dataGridView1[intColPic, intRow].Value != string.Empty)
                {
                    picMain1_2.Image = null;
                    byte[] data;
                    //using (MemoryStream ms = new MemoryStream())
                    //{
                    data = Convert.FromBase64String(dataGridView1[intColPic, intRow].Value.ToString());
                    picMain1_2.Image = byteArrayToImage((byte[])data);

                    //}
                }
                else
                {
                    picMain1_2.Image = null;
                }
            }
            else
            {
                picMain1_2.Image = null;
            }


            if ((dataGridView1[7, intRow].Value != null) && (type == "Inspection Work"))
            {
                //timer1.Enabled = false;
                if (dataGridView1[7, intRow].Value.ToString() != string.Empty)
                {
                    FrmOperationManualOperator.ErrorCloseShare = false;
                    FrmComment frmComment = new FrmComment(dataGridView1[7, intRow].Value.ToString(), csvPartFile, intRow);
                    frmComment.ShowDialog();

                    //if (startClick == true)
                    //{

                    //    btnOKNext_Click(sender, e);
                    //}


                    //if (FrmOperationManualOperator.startClickShare == true)
                    //{
                    //    btnOKNext_Click(sender, e);
                    //}

                    if (FrmOperationManualOperator.ErrorCloseShare == true)
                    {
                        this.Close();
                        return;
                    }

                    if (stopClick == true)
                    {

                        btnStop_Click(sender, e);
                    }

                    //timer1.Enabled = true;

                }
                else
                {
                    FrmOperationManualOperator.SerialNumberShare = string.Empty;
                    FrmOperationManualOperator.commentTypeShare = string.Empty;
                }

            }
            else
            {
                FrmOperationManualOperator.SerialNumberShare = string.Empty;
                FrmOperationManualOperator.commentTypeShare = string.Empty;
            }

        }

        public bool ThumbnailCallback()
        {
            return false;
        }

        public Image byteArrayToImage(byte[] byteArrayIn)
        {
            //System.Drawing.Bitmap bitmap = null;
            //ImageConverter converter = new ImageConverter();
            //System.Drawing.Image img =
            //(System.Drawing.Image)converter.ConvertFrom(byteArrayIn);
            //bitmap = (System.Drawing.Bitmap)img;         
            //return bitmap;

            //byte[] bytes = Convert.FromBase64String(pictureTxt);

            using (MemoryStream ms = new MemoryStream(byteArrayIn))
            {
                try
                {
                    Image image = Image.FromStream(ms);
                    ms.Close();
                    ms.Dispose();
                    ExifRotate(image);
                    return image;
                }
                catch (Exception)
                {
                    ms.Close();
                    ms.Dispose();
                    return null;
                }




            }

        }

        private const int exifOrientationID = 0x112; //274

        public static void ExifRotate(Image img)
        {
            if (!img.PropertyIdList.Contains(exifOrientationID))
                return;

            var prop = img.GetPropertyItem(exifOrientationID);
            int val = BitConverter.ToUInt16(prop.Value, 0);
            var rot = RotateFlipType.RotateNoneFlipNone;

            if (val == 3 || val == 4)
                rot = RotateFlipType.Rotate180FlipNone;
            else if (val == 5 || val == 6)
                rot = RotateFlipType.Rotate90FlipNone;
            else if (val == 7 || val == 8)
                rot = RotateFlipType.Rotate270FlipNone;

            if (val == 2 || val == 4 || val == 5 || val == 7)
                rot |= RotateFlipType.RotateNoneFlipX;

            if (rot != RotateFlipType.RotateNoneFlipNone)
            {
                img.RotateFlip(rot);
                img.RemovePropertyItem(exifOrientationID);
            }
        }

        private void PasteClipboardValue()
        {

            for (int i = 0; i < rowCount; i++)
            {

                dataGridView1.Rows.Add();
            }

            //Get the starting Cell
            //DataGridViewCell startCell = GetStartCell(dataGridView1);
            //Get the clipboard value in a dictionary
            Dictionary<int, Dictionary<int, string>> cbValue =
                    ClipBoardValues(Clipboard.GetText());

            dataGridView1.Rows.Clear();

            //int rowCheck = -1;
            bool rowCheck = false;
            int iRowIndex = 0; // startCell.RowIndex;
            foreach (int rowKey in cbValue.Keys)
            {
                rowCheck = false;
                foreach (var item in rowsNo)
                {
                    if (rowKey == item)
                    {
                        rowCheck = true;
                        break;
                    }
                }

                if (rowCheck == true)
                {
                    continue;
                }

                dataGridView1.Rows.Add();

                int iColIndex = 3; // startCell.ColumnIndex;
                foreach (int cellKey in cbValue[rowKey].Keys)
                {
                    if ((cellKey == 0) || (cellKey == 1) || (cellKey == 2) || (cellKey == 3))
                    {
                        continue;
                    }

                    //Check if the index is within the limit
                    if (iColIndex <= dataGridView1.Columns.Count - 1
                    && iRowIndex <= dataGridView1.Rows.Count - 1)
                    {
                        DataGridViewCell cell = dataGridView1[iColIndex, iRowIndex];

                        //Copy to selected cells if 'chkPasteToSelectedCells' is checked
                        //if ((chkPasteToSelectedCells.Checked && cell.Selected) ||
                        //    (!chkPasteToSelectedCells.Checked))

                        cell.Value = cbValue[rowKey][cellKey];



                    }
                    iColIndex++;
                }
                iRowIndex++;
            }
        }

        private DataGridViewCell GetStartCell(DataGridView dgView)
        {
            ////get the smallest row,column index
            //if (dgView.SelectedCells.Count == 0)
            //    return null;

            //int rowIndex = dgView.Rows.Count - 1;
            //int colIndex = dgView.Columns.Count - 1;

            //foreach (DataGridViewCell dgvCell in dgView.SelectedCells)
            //{
            //    if (dgvCell.RowIndex < rowIndex)
            //        rowIndex = dgvCell.RowIndex;
            //    if (dgvCell.ColumnIndex < colIndex)
            //        colIndex = dgvCell.ColumnIndex;
            //}

            //return dgView[colIndex, rowIndex];
            if (FrmOperationManualOperator.isViewer == true)
            {
                return dgView[0, rowCurrent];
            }
            else
            {
                return dgView[0, 0];
            }


        }

        private void ViewClipboardValue()
        {
            Master = new List<List<string>>();

            //Get the clipboard value in a dictionary
            Dictionary<int, Dictionary<int, string>> cbValue =
                    ClipBoardValues(Clipboard.GetText());

            foreach (int rowKey in cbValue.Keys)
            {
                foreach (int cellKey in cbValue[rowKey].Keys)
                {
                    if (cellKey == 0)
                    {
                        continue;
                    }

                    if (cellKey == 7)
                    {
                        if (cbValue[rowKey][cellKey].ToString() == "False")
                        {
                            rowsNo.Add(rowKey);
                            break;
                        }
                    }

                }
            }
        }

        private Dictionary<int, Dictionary<int, string>> ClipBoardValues(string clipboardValue)
        {
            Dictionary<int, Dictionary<int, string>>
            copyValues = new Dictionary<int, Dictionary<int, string>>();

            String[] lines = clipboardValue.Split('\n');

            for (int i = 0; i <= lines.Length - 1; i++)
            {
                copyValues[i] = new Dictionary<int, string>();
                String[] lineContent = lines[i].Split('\t');

                //if an empty cell value copied, then set the dictionary with an empty string
                //else Set value to dictionary
                if (lineContent.Length == 0)
                    copyValues[i][0] = string.Empty;
                else
                {
                    for (int j = 0; j <= lineContent.Length - 1; j++)
                        copyValues[i][j] = lineContent[j];
                }
            }
            return copyValues;
        }

        static void lineChanger(string newText, string fileName, int line_to_edit)
        {
            string[] arrLine = File.ReadAllLines(fileName);
            if (arrLine.Length == 0)
            {
                return;
            }
            arrLine[line_to_edit - 1] = newText;
            File.WriteAllLines(fileName, arrLine);
        }


        public static void DeleteLastLine(string filepath)
        {
            List<string> lines = File.ReadAllLines(filepath).ToList();

            File.WriteAllLines(filepath, lines.GetRange(0, lines.Count - 1).ToArray());

        }

        public static void DeleteLineStart(string filepath)
        {
            List<string> lines = File.ReadAllLines(filepath).ToList();

            File.WriteAllLines(filepath, lines.GetRange(0, 4).ToArray());

        }

        private void btnOKNext_Click(object sender, EventArgs e)
        {
            string strData = String.Empty;
            //lblValueDetail.Text = "T" + strHH + ":" + strMM + ":" + strSS;

            Int32 intPage = intRowSelect;
            Int32 intSecond = (Convert.ToInt32(strHHstart) * 60 * 60) + (Convert.ToInt32(strMMstart) * 60) + Convert.ToInt32(strSSstart);
            string strSeond = intSecond.ToString();

            if ((FrmOperationManualOperator.CancelClickShare == true) || (FrmOperationManual.stopClick == true))
            {
                ShowData(intRowSelect, intColPicSelect, sender, e);


                if (FrmOperationManual.stopClick == true)
                {
                    //btnStop_Click(sender, e);
                    return;
                }

                if ((FrmOperationManualOperator.SerialNumberShare == string.Empty) && (FrmOperationManualOperator.commentTypeShare != string.Empty))
                {
                    return;
                }


                if (FrmOperationManualOperator.startClickShare == true)
                {
                    btnOKNext_Click(sender, e);
                }

                return;
            }


            if (FrmOperationManualOperator.blClickBlack == false)
            {

                if (intPage == 0)
                {
                    listS.Insert(intPage, strSeond);
                    listSBNEF.Insert(intPage, "N");
                }
                else
                {
                    if (intPage > listS.Count)
                    {
                        for (int i = 0; i < intPage; i++)
                        {
                            if (i == 0)
                            {
                                listS.Insert(i, "0");
                                listSBNEF.Insert(i, "J");
                            }
                            else
                            {
                                listS.Insert(i, "");
                                listSBNEF.Insert(i, "");
                            }

                        }

                        listS.Insert(intPage, strSeond);
                        listSBNEF.Insert(intPage, "N");
                    }
                    else
                    {
                        listS.Insert(intPage, strSeond);
                        listSBNEF.Insert(intPage, "N");
                    }

                }
            }

            intRowStart = 1;

            //listS.Insert(intPage, strSeond);
            //listSBNEF.Insert(intPage, "N");

            intHHstart = 0;
            strHHstart = "00";
            intMMstart = 0;
            strMMstart = "00";
            intSSstart = 0;
            strSSstart = "00";

            lblValueDetail.Text = "T" + strHH + ":" + strMM + ":" + strSS + " S" + strHHstart + ":" + strMMstart + ":" + strSSstart;



            timer1.Enabled = true;
            timer2.Enabled = true;


            intRowSelect = intRowSelect + 1;

            if (intRowSelect < dataGridView1.Rows.Count)
            {
                intColPicSelect = 12;

                if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))
                {
                    // strData = dataGridView1[0, intRowSelect - 1].Value.ToString() + "," +
                    //dataGridView1[1, intRowSelect - 1].Value.ToString() + "," +
                    //dataGridView1[2, intRowSelect - 1].Value.ToString() + "," +
                    strData = dataGridView1[3, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[4, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[5, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[6, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[7, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[8, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[9, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[10, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[11, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[12, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[13, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[14, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[15, intRowSelect - 1].Value.ToString() + "," +
                    "0";
                    lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, intRowSelect);

                    //strData = dataGridView1[0, intRowSelect].Value.ToString() + "," +
                    //    dataGridView1[1, intRowSelect].Value.ToString() + "," +
                    //    dataGridView1[2, intRowSelect].Value.ToString() + "," +
                    strData = dataGridView1[3, intRowSelect].Value.ToString() + "," +
                    dataGridView1[4, intRowSelect].Value.ToString() + "," +
                    dataGridView1[5, intRowSelect].Value.ToString() + "," +
                    dataGridView1[6, intRowSelect].Value.ToString() + "," +
                    dataGridView1[7, intRowSelect].Value.ToString() + "," +
                    dataGridView1[8, intRowSelect].Value.ToString() + "," +
                    dataGridView1[9, intRowSelect].Value.ToString() + "," +
                    dataGridView1[10, intRowSelect].Value.ToString() + "," +
                    dataGridView1[11, intRowSelect].Value.ToString() + "," +
                    dataGridView1[12, intRowSelect].Value.ToString() + "," +
                   dataGridView1[13, intRowSelect].Value.ToString() + "," +
                   dataGridView1[14, intRowSelect].Value.ToString() + "," +
                   dataGridView1[15, intRowSelect].Value.ToString() + "," +
                        "1";
                    lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, intRowSelect + 1);
                }

                FrmOperationManualOperator.startClickShare = false;

                string strTitle = lblTitle.Text;
                string strMessage = lblMessage.Text;
                string strComment = txtComment.Text;



                //if (FrmOperationManualOperator.isViewer == false)
                if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

                {
                    if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,,,,,," + "✔" + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ",";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 4);

                    }
                    else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                    {
                        string strText = string.Empty;
                        if (FrmOperationManualOperator.TextTypeShare.Substring(FrmOperationManualOperator.TextTypeShare.Length - 1, 1) == "]")
                        {
                            strText = "1";
                        }

                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("文字 -強制") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                            + "," + strText + ",," + "✔" + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 4);

                    }
                    else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                            (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("小数点±") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                            + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + "✔" + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 4);

                    }


                    strWorkComplete = objLanguage.Translate("形式") + "," + objLanguage.Translate("図番") + "," + objLanguage.Translate("版数") + ","
                        + objLanguage.Translate("インデックス") + "," + objLanguage.Translate("情報1") + "," + objLanguage.Translate("情報2") + "," +
                        objLanguage.Translate("情報3") + "," + objLanguage.Translate("情報4") + "," + objLanguage.Translate("情報5") + "," +
                        objLanguage.Translate("1検査-1") + "," + objLanguage.Translate("1検査-2") + "," + objLanguage.Translate("1検査-3")
                        + "," + dataGridView1[15, 0].Value.ToString().Replace("\r", "").Replace("\n", "");

                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 1);

                    strWorkComplete = FrmOperationManualOperator.strFormatName + ",,,,,,,,," + strStartDate001 + ",,"
                        + FrmOperationManualOperator.WeatherShare;

                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 2);

                    strWorkComplete = objLanguage.Translate("総台数") + "," + objLanguage.Translate("この番号") + "," +
                        objLanguage.Translate("認識名称(シリアルNo)") + "," + objLanguage.Translate("認識番号(製造番号)") + "," +
                        objLanguage.Translate("他１") + "," + objLanguage.Translate("他２") + "," + objLanguage.Translate("他３") + "," +
                        objLanguage.Translate("他４") + "," + objLanguage.Translate("他５") + ","
                        + strStartTime001 + ",," + FrmOperationManualOperator.TemperatureShare;

                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 3);


                    strWorkComplete = "1,1,,,,,,,," + FrmOperationManualOperator.loginShare + "," + FrmOperationManualOperator.RemarksShare + ","
                        + FrmOperationManualOperator.HumidityShare;

                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 4);



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

                    //System.IO.StreamWriter sr =
                    //    new System.IO.StreamWriter(strPathSaveComplete, true, enc);

                    //sr.WriteLine(strWorkComplete);

                    //sr.Close();
                }


                ShowData(intRowSelect, intColPicSelect, sender, e);

                if (FrmOperationManual.stopClick == true)
                {
                    //btnStop_Click(sender, e);
                    return;
                }

                btnBack.Enabled = true;
                btnBackStart.Enabled = true;


                if (FrmOperationManualOperator.startClickShare == true)
                {
                    btnOKNext_Click(sender, e);
                }

            }
            else
            {
                intRowSelect = intRowSelect - 1;

                DialogResult dialogResult = MessageBox.Show(objLanguage.Translate("Finished to the end. Repeat Work?"), objLanguage.Translate("Confirmation"),
               MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0);
                if (dialogResult == DialogResult.Yes)
                {
                    CheckSerialUSB.SerialUSB = CheckSerialUSB.CheckSerialUSBLicense();

                    CheckSerialUSBWarning();

                    timer1.Enabled = false;
                    timer2.Enabled = false;

                    if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))
                    {
                        for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            //strData = dataGridView1[0, i].Value.ToString() + "," +
                            //dataGridView1[1, i].Value.ToString() + "," +
                            //dataGridView1[2, i].Value.ToString() + "," +
                            strData = dataGridView1[3, i].Value.ToString() + "," +
                            dataGridView1[4, i].Value.ToString() + "," +
                            dataGridView1[5, i].Value.ToString() + "," +
                            dataGridView1[6, i].Value.ToString() + "," +
                            dataGridView1[7, i].Value.ToString() + "," +
                            dataGridView1[8, i].Value.ToString() + "," +
                            dataGridView1[9, i].Value.ToString() + "," +
                            dataGridView1[10, i].Value.ToString() + "," +
                            dataGridView1[11, i].Value.ToString() + "," +
                            dataGridView1[12, i].Value.ToString() + "," +
                            dataGridView1[13, i].Value.ToString() + "," +
                            dataGridView1[14, i].Value.ToString() + "," +
                            dataGridView1[15, i].Value.ToString() + ",";
                            if (i == 0)
                            {
                                strData = strData.Replace("\r", "").Replace("\n", "") + "1";
                            }
                            else
                            {
                                strData = strData.Replace("\r", "").Replace("\n", "") + "0";
                            }

                            lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, i + 1);
                        }


                        if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                        {
                            strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,,,,,," + "✔" + ","
                                + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ",";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                        {
                            strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text
                                + ",," + objLanguage.Translate("文字 -強制") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                                + ",,," + "✔" + ","
                                + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                                (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                        {
                            strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text
                                + ",," + objLanguage.Translate("小数点±") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                                + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + "✔" + ","
                                + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }


                        //File 001
                        string path = strPathSaveComplete.Substring(0, strPathSaveComplete.Length - 4);
                        using (FileStream fs = File.Create(path)) ;
                        try
                        {
                            File.Copy(strPathSaveComplete, path, true);
                        }
                        catch (IOException iox)
                        {
                            //Console.WriteLine(iox.Message);
                            MessageBox.Show(this, iox.Message,
                                                   objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                                   MessageBoxIcon.Exclamation,
                                                   MessageBoxDefaultButton.Button1, 0);

                            return;

                        }
                    }


                    SumAll();

                    //Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    //string strSeondAll = intSecondAll.ToString();

                    Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    intSecondAll = intSecondAll - ((Convert.ToInt32(strHHContinue) * 60 * 60)
                        + (Convert.ToInt32(strMMContinue) * 60) + Convert.ToInt32(strSSContinue));
                    string strSeondAll = intSecondAll.ToString();

                    //strWorkHistory = strWorkHistory + "," + "E" + "," + loginUser + ",,," + strStartDate + "," + strStartTime
                    //   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                    //   + "," + strAll;

                    //strWorkHistory = strWorkHistory + "," + "E" + "," + loginUser + ",,," + strStartDate + "," + strStartTime
                    //   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                    //   + "," + strSeondAll;

                    if (this.type == "Operation Manual")
                    {
                        strWorkHistory = strWorkHistory + "," + "E" + "," + "" + "," + "" + "," + "" + "," + strStartDate + "," + strStartTime
                     + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                     + "," + strSeondAll;
                    }
                    else
                    {
                        strWorkHistory = strWorkHistory + "," + "E" + "," + objLanguage.Translate("1/1目の検査") + "," + loginUser + "," + FrmOperationManualOperator.RemarksShare + "," + strStartDate + "," + strStartTime
                      + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                      + "," + strSeondAll;
                    }


                    SumAll();

                    intDiffAll = intSecondAll - intAll;
                    strDiffAll = intDiffAll.ToString();

                    for (int j = listS.Count; j <= rowCount; j++)
                    {
                        if (j == rowCount)
                        {
                            listS.Insert(j, strDiffAll);
                            listSBNEF.Insert(j, "");
                        }
                        else
                        {
                            listS.Insert(j, "");
                            listSBNEF.Insert(j, "");
                        }

                    }


                    Int32 i1 = 0;
                    foreach (var s in listS)
                    {
                        if (s != null)
                        {
                            strWorkHistory = strWorkHistory + "," + s.ToString() + "," + listSBNEF[i1].ToString();
                        }
                        else if (s == null)
                        {
                            strWorkHistory = strWorkHistory + "," + string.Empty + "," + string.Empty;
                        }
                        i1++;
                    }

                    //strWorkHistory = strWorkHistory + "," + "E" + ",,,," + strStartDate + "," + strStartTime
                    //   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                    //   + "," + strAll + "," + strS1 + "," + strS1BNEF + "," + strS2 + "," + strS2BNEF
                    //    + "," + strS3 + "," + strS3BNEF + "," + strS4 + "," + strS4BNEF
                    //    + "," + strS5 + "," + strS5BNEF + "," + strS6 + "," + strS6BNEF
                    //    + "," + strS7 + "," + strS7BNEF + "," + strS8 + "," + strS8BNEF
                    //    + "," + strS9 + "," + strS9BNEF + "," + strS10 + "," + strS10BNEF
                    //    + "," + strS11 + "," + strS11BNEF;

                    if (FrmOperationManualOperator.isViewer == false)
                    {
                        //CSV Encoding
                        System.Text.Encoding enc =
                            System.Text.Encoding.UTF8;

                        System.IO.StreamWriter sr =
                            new System.IO.StreamWriter(strPathSave, true, enc);

                        sr.WriteLine(strWorkHistory);

                        sr.Close();


                    }


                    listS = new List<string>();
                    listSBNEF = new List<string>();

                    FrmOperationManualOperator frmOperationManualOperator = new FrmOperationManualOperator(csvPartFile, "");

                    this.Dispose();

                    frmOperationManualOperator.ShowDialog();


                }
                else if (dialogResult == DialogResult.No)
                {
                    timer1.Enabled = false;
                    timer2.Enabled = false;

                    SumAll();

                    //strWorkHistory = strWorkHistory + "," + "E" + "," + loginUser + ",,," + strStartDate + "," + strStartTime
                    //  + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                    //  + "," + strAll;

                    //Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    //string strSeondAll = intSecondAll.ToString();

                    Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    intSecondAll = intSecondAll - ((Convert.ToInt32(strHHContinue) * 60 * 60)
                        + (Convert.ToInt32(strMMContinue) * 60) + Convert.ToInt32(strSSContinue));
                    string strSeondAll = intSecondAll.ToString();

                    if (this.type == "Operation Manual")
                    {
                        strWorkHistory = strWorkHistory + "," + "E" + "," + "" + "," + "" + "," + "" + "," + strStartDate + "," + strStartTime
                      + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                      + "," + strSeondAll;
                    }
                    else
                    {
                        strWorkHistory = strWorkHistory + "," + "E" + "," + objLanguage.Translate("1/1目の検査") + "," + loginUser + "," + FrmOperationManualOperator.RemarksShare + "," + strStartDate + "," + strStartTime
                       + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                       + "," + strSeondAll;
                    }


                    SumAll();

                    intDiffAll = intSecondAll - intAll;
                    strDiffAll = intDiffAll.ToString();

                    for (int j = listS.Count; j <= rowCount; j++)
                    {
                        if (j == rowCount)
                        {
                            listS.Insert(j, strDiffAll);
                            listSBNEF.Insert(j, "");
                        }
                        else
                        {
                            listS.Insert(j, "");
                            listSBNEF.Insert(j, "");
                        }

                    }


                    Int32 i = 0;
                    foreach (var s in listS)
                    {
                        if (s != null)
                        {
                            strWorkHistory = strWorkHistory + "," + s.ToString() + "," + listSBNEF[i].ToString();
                        }
                        else if (s == null)
                        {
                            strWorkHistory = strWorkHistory + "," + string.Empty + "," + string.Empty;
                        }
                        i++;
                    }

                    //strWorkHistory = strWorkHistory + "," + "E" + ",,,," + strStartDate + "," + strStartTime 
                    //    + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                    //    + "," + strAll + "," + strS1 + "," + strS1BNEF + "," + strS2 + "," + strS2BNEF 
                    //    + "," + strS3 + "," + strS3BNEF + "," + strS4 + "," + strS4BNEF
                    //    + "," + strS5 + "," + strS5BNEF + "," + strS6 + "," + strS6BNEF
                    //    + "," + strS7 + "," + strS7BNEF + "," + strS8 + "," + strS8BNEF
                    //    + "," + strS9 + "," + strS9BNEF + "," + strS10 + "," + strS10BNEF
                    //    + "," + strS11 + "," + strS11BNEF;

                    if (FrmOperationManualOperator.isViewer == false)
                    {
                        strWorkComplete = FrmOperationManualOperator.strFormatName + ",,,,,,,,," + strStartDate001 + "," + DateTime.Now.ToString("yyyy/MM/dd") + ","
                            + FrmOperationManualOperator.WeatherShare;
                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 2);

                        strWorkComplete = objLanguage.Translate("総台数") + "," + objLanguage.Translate("この番号") + "," +
                        objLanguage.Translate("認識名称(シリアルNo)") + "," + objLanguage.Translate("認識番号(製造番号)") + "," +
                        objLanguage.Translate("他１") + "," + objLanguage.Translate("他２") + "," + objLanguage.Translate("他３") + "," +
                        objLanguage.Translate("他４") + "," + objLanguage.Translate("他５") + ","
                        + strStartTime001 + "," + DateTime.Now.ToString("HH:mm:ss") + "," + FrmOperationManualOperator.TemperatureShare;
                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 3);


                        if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                        {
                            strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,,,,,," + "✔" + ","
                                + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ",";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                        {
                            strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text
                                + ",," + objLanguage.Translate("文字 -強制") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                                + ",,," + "✔" + ","
                                + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                                (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                        {
                            strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text
                                + ",," + objLanguage.Translate("小数点±") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                                + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + "✔" + ","
                                + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + FrmOperationManualOperator.SerialNumberShare;

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }

                        //File 001
                        string path = strPathSaveComplete.Substring(0, strPathSaveComplete.Length - 4);
                        using (FileStream fs = File.Create(path)) ;
                        try
                        {
                            File.Copy(strPathSaveComplete, path, true);
                        }
                        catch (IOException iox)
                        {
                            //Console.WriteLine(iox.Message);
                            MessageBox.Show(this, iox.Message,
                                                   objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                                   MessageBoxIcon.Exclamation,
                                                   MessageBoxDefaultButton.Button1, 0);

                            return;

                        }


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

                        System.IO.StreamWriter sr =
                            new System.IO.StreamWriter(strPathSave, true, enc);

                        sr.WriteLine(strWorkHistory);

                        sr.Close();
                    }

                    listS = new List<string>();
                    listSBNEF = new List<string>();

                    this.Close();
                    return;
                }


            }
        }

        public bool IsNumeric(string input)
        {
            return Regex.IsMatch(input, @"^[0-9]\d+$");

        }

        bool IsDecimalFormat(string input)
        {
            Decimal dummy;
            return Decimal.TryParse(input, out dummy);
        }

        public void SumAll()
        {
            intAll = 0;
            foreach (var s in listS)
            {
                if (s != null)
                {
                    if (s.ToString() != string.Empty)
                    {
                        //if (IsDecimalFormat(s.ToString()) == true)
                        //{
                        //    dblAll = dblAll + Convert.ToDouble(s.ToString());
                        //}

                        intAll = intAll + Convert.ToInt32(s.ToString());

                    }

                }
            }

            strAll = Convert.ToString(intAll);

            //if (strType == "Integer input")
            //{
            //    //strAll = Convert.ToString(dblAll).Substring(0, Convert.ToString(dblAll).Length - 3);
            //    strAll = Convert.ToString(Convert.ToInt32(dblAll));
            //}
            //else if (strType == "Decimal input")
            //{
            //    strAll = Convert.ToString(dblAll);
            //}


        }

        public void CheckSerialUSBWarning()
        {
            if (CheckSerialUSB.SerialUSB == string.Empty)
            {
                MessageBox.Show(this, objLanguage.Translate("Please insert the USB key."),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);

                Application.Exit();
            }
            else if (CheckSerialUSB.SerialUSB == "Get")
            {
                MessageBox.Show(this, objLanguage.Translate("Not correct"),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                Application.Exit();
            }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            string strData = String.Empty;
            Int32 intPage = intRowSelect;

            FrmOperationManualOperator.blClickBlack = true;

            if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))
            {
                // strData = dataGridView1[0, intRowSelect - 1].Value.ToString() + "," +
                //dataGridView1[1, intRowSelect - 1].Value.ToString() + "," +
                //dataGridView1[2, intRowSelect - 1].Value.ToString() + "," +
                strData = dataGridView1[3, intRowSelect].Value.ToString() + "," +
                dataGridView1[4, intRowSelect].Value.ToString() + "," +
                dataGridView1[5, intRowSelect].Value.ToString() + "," +
                dataGridView1[6, intRowSelect].Value.ToString() + "," +
                dataGridView1[7, intRowSelect].Value.ToString() + "," +
                dataGridView1[8, intRowSelect].Value.ToString() + "," +
                dataGridView1[9, intRowSelect].Value.ToString() + "," +
                dataGridView1[10, intRowSelect].Value.ToString() + "," +
                dataGridView1[11, intRowSelect].Value.ToString() + "," +
                dataGridView1[12, intRowSelect].Value.ToString() + "," +
                dataGridView1[13, intRowSelect].Value.ToString() + "," +
                dataGridView1[14, intRowSelect].Value.ToString() + "," +
                dataGridView1[15, intRowSelect].Value.ToString() + "," +
                "0";
                lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, intRowSelect + 1);

                //strData = dataGridView1[0, intRowSelect].Value.ToString() + "," +
                //    dataGridView1[1, intRowSelect].Value.ToString() + "," +
                //    dataGridView1[2, intRowSelect].Value.ToString() + "," +
                strData = dataGridView1[3, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[4, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[5, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[6, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[7, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[8, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[9, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[10, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[11, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[12, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[13, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[14, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[15, intRowSelect - 1].Value.ToString() + "," +
                    "1";
                lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, intRowSelect);

                //DeleteLastLine(strPathSaveComplete);

            }

            intRowSelect = intRowSelect - 1;


            if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

            {
                if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                {
                    strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                        + FrmOperationManualOperator.CommentShare + ",,,,,,," + "" + ","
                        + "" + ",";

                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 6);

                }
                else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                {

                    string strText = string.Empty;
                    if (FrmOperationManualOperator.TextTypeShare.Substring(FrmOperationManualOperator.TextTypeShare.Length - 1, 1) == "]")
                    {
                        strText = "1";
                    }

                    strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                        + FrmOperationManualOperator.CommentShare + ",," + objLanguage.Translate("文字 -強制") + ","
                        + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                        + "," + strText + ",," + "" + ","
                        + "" + "," + "";

                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 6);

                }
                else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                        (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                {
                    strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                        + FrmOperationManualOperator.CommentShare + ",," + objLanguage.Translate("小数点±") + ","
                        + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                        + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + "" + ","
                        + "" + "," + "";

                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 6);

                }

            }

            if (intPage == 0)
            {
                listS.Insert(intPage, "");
                listSBNEF.Insert(intPage, "B");
            }
            else
            {
                if (intPage > listS.Count)
                {
                    for (int i = 0; i < intPage; i++)
                    {
                        if (i == 0)
                        {
                            listS.Insert(i, "0");
                            listSBNEF.Insert(i, "J");
                        }
                        else
                        {
                            listS.Insert(i, "");
                            listSBNEF.Insert(i, "");
                        }

                    }

                    listS.Insert(intPage, "");
                    listSBNEF.Insert(intPage, "B");
                }
                else
                {
                    listS.Insert(intPage, "");
                    listSBNEF.Insert(intPage, "B");
                }

            }

            intRowStart = 1;

            FrmOperationManual.stopClick = false;
            FrmOperationManualOperator.startClickShare = false;
            FrmOperationManualOperator.ErrorClickShare = false;


            ShowData(intRowSelect, intColPicSelect, sender, e);

            //if (FrmOperationManual.stopClick == true)
            //{
            //    //btnStop_Click(sender, e);              

            //    return;
            //}

            if (FrmOperationManual.stopClick == true)
            {
                //btnStop_Click(sender, e);              

                return;
            }

            btnBack.Enabled = true;
            btnBackStart.Enabled = true;


            if (FrmOperationManualOperator.startClickShare == true)
            {

                btnOKNext_Click(sender, e);
                return;
            }


            if (FrmOperationManualOperator.ErrorClickShare == true)
            {
                if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

                {
                    if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,,,,,," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ",";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }
                    else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                    {

                        string strText = string.Empty;
                        if (FrmOperationManualOperator.TextTypeShare.Substring(FrmOperationManualOperator.TextTypeShare.Length - 1, 1) == "]")
                        {
                            strText = "1";
                        }

                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("文字 -強制") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                            + "," + strText + ",," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + "";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }
                    else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                            (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("小数点±") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                            + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + "";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }

                    Int32 intSecond = (Convert.ToInt32(strHHstart) * 60 * 60) + (Convert.ToInt32(strMMstart) * 60) + Convert.ToInt32(strSSstart);
                    string strSeond = intSecond.ToString();


                    //Click Black no record error F
                    //if (intPage == 0)
                    //{
                    //    listS.Insert(intPage, strSeond);
                    //    listSBNEF.Insert(intPage, "F");
                    //}
                    //else
                    //{
                    //    if (intPage > listS.Count)
                    //    {
                    //        for (int i = 0; i < intPage; i++)
                    //        {
                    //            if (i == 0)
                    //            {
                    //                listS.Insert(i, "0");
                    //                listSBNEF.Insert(i, "J");
                    //            }
                    //            else
                    //            {
                    //                listS.Insert(i, "");
                    //                listSBNEF.Insert(i, "");
                    //            }

                    //        }

                    //        listS.Insert(intPage, strSeond);
                    //        listSBNEF.Insert(intPage, "F");
                    //    }
                    //    else
                    //    {
                    //        listS.Insert(intPage, strSeond);
                    //        listSBNEF.Insert(intPage, "F");
                    //    }

                    //}



                    //Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    //string strSeondAll = intSecondAll.ToString();

                    Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    intSecondAll = intSecondAll - ((Convert.ToInt32(strHHContinue) * 60 * 60)
                        + (Convert.ToInt32(strMMContinue) * 60) + Convert.ToInt32(strSSContinue));
                    string strSeondAll = intSecondAll.ToString();

                    if (this.type == "Operation Manual")
                    {
                        strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + "" + "," + "" + "," + "" + "," + strStartDate + "," + strStartTime
                   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                   + "," + strSeondAll;
                    }
                    else
                    {
                        strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + objLanguage.Translate("1/1目の検査") + "," + loginUser + "," + FrmOperationManualOperator.RemarksShare + "," + strStartDate + "," + strStartTime
                   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                   + "," + strSeondAll;
                    }

                    SumAll();

                    intDiffAll = intSecondAll - intAll;
                    strDiffAll = intDiffAll.ToString();

                    for (int j = listS.Count; j <= rowCount; j++)
                    {
                        if (j == rowCount)
                        {
                            listS.Insert(j, strDiffAll);
                            listSBNEF.Insert(j, "");
                        }
                        else
                        {
                            listS.Insert(j, "");
                            listSBNEF.Insert(j, "");
                        }

                    }

                    Int32 i1 = 0;
                    foreach (var s in listS)
                    {
                        if (s != null)
                        {
                            strWorkHistory = strWorkHistory + "," + s.ToString() + "," + listSBNEF[i1].ToString();
                        }
                        else if (s == null)
                        {
                            strWorkHistory = strWorkHistory + "," + string.Empty + "," + string.Empty;
                        }
                        i1++;
                    }

                    if (FrmOperationManualOperator.isViewer == false)
                    {
                        //CSV Encoding
                        System.Text.Encoding enc =
                        System.Text.Encoding.UTF8;

                        System.IO.StreamWriter sr =
                            new System.IO.StreamWriter(strPathSave, true, enc);

                        sr.WriteLine(strWorkHistory);

                        sr.Close();
                    }


                }
            }
            else
            {


                if (intRowSelect == 0)
                {
                    intColPicSelect = 12;

                    if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

                    {
                        if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                        {
                            strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                                + FrmOperationManualOperator.CommentShare + ",,,,,,," + "" + ","
                                + "" + ",";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                        {

                            string strText = string.Empty;
                            if (FrmOperationManualOperator.TextTypeShare.Substring(FrmOperationManualOperator.TextTypeShare.Length - 1, 1) == "]")
                            {
                                strText = "1";
                            }

                            strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                                + FrmOperationManualOperator.CommentShare + ",," + objLanguage.Translate("文字 -強制") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                                + "," + strText + ",," + "" + ","
                                + "" + "," + "";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                                (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                        {
                            strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                                + FrmOperationManualOperator.CommentShare + ",," + objLanguage.Translate("小数点±") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                                + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + "" + ","
                                + "" + "," + "";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }

                    }


                    btnBack.Enabled = false;
                    btnBackStart.Enabled = false;



                }
                else if (intRowSelect > 0)
                {
                    intColPicSelect = 12;


                    if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

                    {
                        if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                        {
                            strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                                + FrmOperationManualOperator.CommentShare + ",,,,,,," + "" + ","
                                + "" + ",";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                        {

                            string strText = string.Empty;
                            if (FrmOperationManualOperator.TextTypeShare.Substring(FrmOperationManualOperator.TextTypeShare.Length - 1, 1) == "]")
                            {
                                strText = "1";
                            }

                            strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                                + FrmOperationManualOperator.CommentShare + ",," + objLanguage.Translate("文字 -強制") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                                + "," + strText + ",," + "" + ","
                                + "" + "," + "";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }
                        else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                                (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                        {
                            strWorkComplete = FrmOperationManualOperator.TitleShare + "," + FrmOperationManualOperator.MessageShare + ","
                                + FrmOperationManualOperator.CommentShare + ",," + objLanguage.Translate("小数点±") + ","
                                + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                                + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + "" + ","
                                + "" + "," + "";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                        }

                    }


                }
            }

            if (FrmOperationManualOperator.startClickShare == true)
            {
                btnOKNext_Click(sender, e);
            }

        }

        private void btnBackStart_Click(object sender, EventArgs e)
        {
            string strData = String.Empty;
            Int32 intPageBB = intRowSelect;

            if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))
            {
                // strData = dataGridView1[0, intRowSelect - 1].Value.ToString() + "," +
                //dataGridView1[1, intRowSelect - 1].Value.ToString() + "," +
                //dataGridView1[2, intRowSelect - 1].Value.ToString() + "," +
                strData = dataGridView1[3, intRowSelect].Value.ToString() + "," +
                dataGridView1[4, intRowSelect].Value.ToString() + "," +
                dataGridView1[5, intRowSelect].Value.ToString() + "," +
                dataGridView1[6, intRowSelect].Value.ToString() + "," +
                dataGridView1[7, intRowSelect].Value.ToString() + "," +
                dataGridView1[8, intRowSelect].Value.ToString() + "," +
                dataGridView1[9, intRowSelect].Value.ToString() + "," +
                dataGridView1[10, intRowSelect].Value.ToString() + "," +
                dataGridView1[11, intRowSelect].Value.ToString() + "," +
                dataGridView1[12, intRowSelect].Value.ToString() + "," +
                dataGridView1[13, intRowSelect].Value.ToString() + "," +
                dataGridView1[14, intRowSelect].Value.ToString() + "," +
                dataGridView1[15, intRowSelect].Value.ToString() + "," +
                "0";
                lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, intRowSelect + 1);

                //strData = dataGridView1[0, intRowSelect].Value.ToString() + "," +
                //    dataGridView1[1, intRowSelect].Value.ToString() + "," +
                //    dataGridView1[2, intRowSelect].Value.ToString() + "," +

                Int32 intRowKeep = intRowSelect;

                for (int i = 0; i <= intRowKeep; i++)
                {
                    //intRowSelect = intRowSelect - 1;

                    if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

                        condition = dataGridView1[7, i].Value.ToString().Replace("\r", "").Replace("\n", "");
                    strTitle = dataGridView1[4, i].Value.ToString().Replace("\r", "").Replace("\n", "");
                    strMessage = dataGridView1[5, i].Value.ToString().Replace("\r", "").Replace("\n", "");
                    strComment = dataGridView1[3, i].Value.ToString().Replace("\r", "").Replace("\n", "");


                    if (condition == string.Empty)
                    {
                        commentType = string.Empty;
                        strTextType = string.Empty;
                        strWordCount = string.Empty;
                        strMin = string.Empty;
                        strMax = string.Empty;
                        strUnit = string.Empty;
                    }
                    else
                    {

                        if (condition.Split("|").Length == 8)
                        {
                            arrayCondition = condition.Split("|");
                            commentType = arrayCondition[0].Trim();
                            strTextType = arrayCondition[1].Trim();
                            strWordCount = arrayCondition[3].Trim();
                            strMin = arrayCondition[2].Trim();
                            strMax = arrayCondition[5].Trim();
                            strUnit = arrayCondition[6].Trim();

                        }
                    }


                    {
                        if (commentType == string.Empty)
                        {
                            strWorkComplete = strTitle + "," + strMessage + "," + strComment + ",,,,,,," + "" + ","
                                + "" + ",";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, i + 5);

                        }
                        else if (commentType == "Character input")
                        {
                            string strText = string.Empty;
                            if (strTextType.Substring(strTextType.Length - 1, 1) == "]")
                            {
                                strText = "1";
                            }

                            strWorkComplete = strTitle + "," + strMessage + "," + strComment + ",," + objLanguage.Translate("文字 -強制") + ","
                                + strTextType + "," + strWordCount
                                + "," + strText + ",," + "" + ","
                                + "" + "," + "";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, i + 5);

                        }
                        else if ((commentType == "Integer input") ||
                                (commentType == "Decimal input"))
                        {
                            strWorkComplete = strTitle + "," + strMessage + "," + strComment + ",," + objLanguage.Translate("小数点±") + ","
                                + strTextType + "," + strMin
                                + "," + strMax + "," + strUnit + "," + "" + ","
                                + "" + "," + "";

                            lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, i + 5);

                        }

                    }


                }


                intRowSelect = 1;

                strData = dataGridView1[3, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[4, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[5, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[6, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[7, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[8, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[9, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[10, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[11, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[12, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[13, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[14, intRowSelect - 1].Value.ToString() + "," +
                    dataGridView1[15, intRowSelect - 1].Value.ToString() + "," +
                    "1";
                lineChanger(strData.Replace("\r", "").Replace("\n", ""), csvPartFile, intRowSelect);

                //DeleteLineStart(strPathSaveComplete);

            }

            if (intPageBB == 0)
            {
                listS.Insert(intPageBB, "");
                listSBNEF.Insert(intPageBB, "BB");
            }
            else
            {
                if (intPageBB > listS.Count)
                {
                    for (int i = 0; i < intPageBB; i++)
                    {
                        if (i == 0)
                        {
                            listS.Insert(i, "0");
                            listSBNEF.Insert(i, "J");
                        }
                        else
                        {
                            listS.Insert(i, "");
                            listSBNEF.Insert(i, "");
                        }

                    }

                    listS.Insert(intPageBB, "");
                    listSBNEF.Insert(intPageBB, "BB");
                }
                else
                {
                    listS.Insert(intPageBB, "");
                    listSBNEF.Insert(intPageBB, "BB");
                }

            }

            intRowStart = 1;


            intRowSelect = 0;

            intColPicSelect = 12;

            ShowData(intRowSelect, intColPicSelect, sender, e);

            Int32 intPage = intRowSelect;

            if (FrmOperationManual.stopClick == true)
            {
                //btnStop_Click(sender, e);
                return;
            }

            btnBack.Enabled = true;
            btnBackStart.Enabled = true;


            if (FrmOperationManualOperator.startClickShare == true)
            {
                btnOKNext_Click(sender, e);
                return;
            }

            if (FrmOperationManualOperator.ErrorClickShare == true)
            {
                if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

                {
                    if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,,,,,," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ",";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }
                    else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                    {
                        string strText = string.Empty;
                        if (FrmOperationManualOperator.TextTypeShare.Substring(FrmOperationManualOperator.TextTypeShare.Length - 1, 1) == "]")
                        {
                            strText = "1";
                        }

                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("文字 -強制") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                            + "," + strText + ",," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + "";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }
                    else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                            (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("小数点±") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                            + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + "";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }

                    Int32 intSecond = (Convert.ToInt32(strHHstart) * 60 * 60) + (Convert.ToInt32(strMMstart) * 60) + Convert.ToInt32(strSSstart);
                    string strSecond = intSecond.ToString();

                    //for (int i = listS.Count; i < intPage; i++)
                    //{
                    //    listS.Insert(i, "");
                    //    listSBNEF.Insert(i, "");
                    //}

                    //listS.Insert(intPage, strSeond);
                    //listSBNEF.Insert(intPage, "F");


                    if (intPage == 0)
                    {
                        listS.Insert(intPage, strSecond);
                        listSBNEF.Insert(intPage, "F");
                    }
                    else
                    {
                        if (intPage > listS.Count)
                        {
                            for (int i = 0; i < intPage; i++)
                            {
                                if (i == 0)
                                {
                                    listS.Insert(i, "0");
                                    listSBNEF.Insert(i, "J");
                                }
                                else
                                {
                                    listS.Insert(i, "");
                                    listSBNEF.Insert(i, "");
                                }

                            }

                            listS.Insert(intPage, strSecond);
                            listSBNEF.Insert(intPage, "F");
                        }
                        else
                        {
                            listS.Insert(intPage, strSecond);
                            listSBNEF.Insert(intPage, "F");
                        }

                    }


                    //Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    //string strSeondAll = intSecondAll.ToString();

                    Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    intSecondAll = intSecondAll - ((Convert.ToInt32(strHHContinue) * 60 * 60)
                        + (Convert.ToInt32(strMMContinue) * 60) + Convert.ToInt32(strSSContinue));
                    string strSeondAll = intSecondAll.ToString();

                    if (this.type == "Operation Manual")
                    {
                        strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + "" + "," + "" + "," + "" + "," + strStartDate + "," + strStartTime
                   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                   + "," + strSeondAll;
                    }
                    else
                    {
                        strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + objLanguage.Translate("1/1目の検査") + "," + loginUser + "," + FrmOperationManualOperator.RemarksShare + "," + strStartDate + "," + strStartTime
                   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                   + "," + strSeondAll;
                    }

                    SumAll();

                    intDiffAll = intSecondAll - intAll;
                    strDiffAll = intDiffAll.ToString();

                    for (int j = listS.Count; j <= rowCount; j++)
                    {
                        if (j == rowCount)
                        {
                            listS.Insert(j, strDiffAll);
                            listSBNEF.Insert(j, "");
                        }
                        else
                        {
                            listS.Insert(j, "");
                            listSBNEF.Insert(j, "");
                        }

                    }

                    Int32 i1 = 0;
                    foreach (var s in listS)
                    {
                        if (s != null)
                        {
                            strWorkHistory = strWorkHistory + "," + s.ToString() + "," + listSBNEF[i1].ToString();
                        }
                        else if (s == null)
                        {
                            strWorkHistory = strWorkHistory + "," + string.Empty + "," + string.Empty;
                        }
                        i1++;
                    }

                    if (FrmOperationManualOperator.isViewer == false)
                    {
                        //CSV Encoding
                        System.Text.Encoding enc =
                        System.Text.Encoding.UTF8;

                        System.IO.StreamWriter sr =
                            new System.IO.StreamWriter(strPathSave, true, enc);

                        sr.WriteLine(strWorkHistory);

                        sr.Close();
                    }

                }
            }

            btnBack.Enabled = false;
            btnBackStart.Enabled = false;

            if (FrmOperationManualOperator.startClickShare == true)
            {
                btnOKNext_Click(sender, e);
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            if (backgroundWorker1.IsBusy == false)
            {
                backgroundWorker1.RunWorkerAsync();
            }


        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            ENDClick = false;
            RestartClick = false;
            timer1.Enabled = false;
            timer2.Enabled = false;
            Int32 intPage = intRowSelect;


            lblValueDetail.Text = "T" + strHH + ":" + strMM + ":" + strSS + " S" + strHHstart + ":" + strMMstart + ":" + strSSstart;

            strDateStop = DateTime.Now.ToString("yyyy/M/dd");

            strTimeStop = DateTime.Now.ToString("HH:mm:ss");

            dataGridView1.SelectAll();

            FrmOperationManualOperator.strPageError = intPage.ToString();

            FrmOperationConfirmation frmOperationConfirmation = new FrmOperationConfirmation(dataGridView1, csvPartFile, loginUser);

            frmOperationConfirmation.ShowDialog();

            if (ENDClick == true)
            {
                if (FrmOperationManualOperator.isViewer == false)
                {
                    strWorkComplete = FrmOperationManualOperator.strFormatName + ",,,,,,,,," + strStartDate001 + "," + DateTime.Now.ToString("yyyy/MM/dd") + ","
                        + FrmOperationManualOperator.WeatherShare;
                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 2);

                    strWorkComplete = objLanguage.Translate("総台数") + "," + objLanguage.Translate("この番号") + "," +
                        objLanguage.Translate("認識名称(シリアルNo)") + "," + objLanguage.Translate("認識番号(製造番号)") + "," +
                        objLanguage.Translate("他１") + "," + objLanguage.Translate("他２") + "," + objLanguage.Translate("他３") + "," +
                        objLanguage.Translate("他４") + "," + objLanguage.Translate("他５") + ","
                    + strStartTime001 + "," + DateTime.Now.ToString("HH:mm:ss") + ","
                    + FrmOperationManualOperator.TemperatureShare + "," + strHH + ":" + strMM + ":" + strSS;
                    lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, 3);
                }

                SumAll();

                //Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);

                //string strSeondAll = intSecondAll.ToString();

                Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                intSecondAll = intSecondAll - ((Convert.ToInt32(strHHContinue) * 60 * 60)
                    + (Convert.ToInt32(strMMContinue) * 60) + Convert.ToInt32(strSSContinue));
                string strSeondAll = intSecondAll.ToString();

                //strWorkHistory = strWorkHistory + "," + (intRowSelect+1).ToString() + "," + loginUser + ",,," + strStartDate + "," + strStartTime
                //   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                //   + "," + strAll;

                if (this.type == "Operation Manual")
                {
                    strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + "" + "," + "" + "," + "" + "," + strStartDate + "," + strStartTime
                   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                   + "," + strSeondAll;
                }
                else
                {
                    strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + objLanguage.Translate("1/1目の検査") + "," + loginUser + "," + FrmOperationManualOperator.RemarksShare + "," + strStartDate + "," + strStartTime
                   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                   + "," + strSeondAll;
                }




                //Int32 intPage = intRowSelect;
                //Int32 intSecond = (Convert.ToInt32(strHHstart) * 60 * 60) + (Convert.ToInt32(strMMstart) * 60) + Convert.ToInt32(strSSstart);
                //string strSeond = intSecond.ToString();

                //listS.Insert(intPage, strSeond);
                //listSBNEF.Insert(intPage, "N");

                SumAll();

                intDiffAll = intSecondAll - intAll;
                strDiffAll = intDiffAll.ToString();

                for (int j = listS.Count; j <= rowCount; j++)
                {
                    if (j == rowCount)
                    {
                        listS.Insert(j, strDiffAll);
                        listSBNEF.Insert(j, "");
                    }
                    else
                    {
                        listS.Insert(j, "");
                        listSBNEF.Insert(j, "");
                    }

                }

                Int32 i1 = 0;
                foreach (var s in listS)
                {
                    if (s != null)
                    {
                        strWorkHistory = strWorkHistory + "," + s.ToString() + "," + listSBNEF[i1].ToString();
                    }
                    else if (s == null)
                    {
                        strWorkHistory = strWorkHistory + "," + string.Empty + "," + string.Empty;
                    }
                    i1++;
                }

                if ((FrmOperationManualOperator.isViewer == false) && (intRowStart == 1))
                {
                    //CSV Encoding
                    System.Text.Encoding enc =
                    System.Text.Encoding.UTF8;

                    System.IO.StreamWriter sr =
                        new System.IO.StreamWriter(strPathSave, true, enc);

                    sr.WriteLine(strWorkHistory);

                    sr.Close();
                }

                listS = new List<string>();
                listSBNEF = new List<string>();

                this.Dispose();

            }
            else if ((RestartClick == true) || (FrmOperationManualOperator.HandingOverShare == true))
            {
                timer1.Enabled = true;
                timer2.Enabled = true;
                return;
            }
            else if (FrmOperationManualOperator.ErrorClickShare = true)
            {
                if ((type == "Inspection Work") && (FrmOperationManualOperator.isViewer == false))

                {
                    if (FrmOperationManualOperator.commentTypeShare == string.Empty)
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",,,,,,," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + ",";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }
                    else if (FrmOperationManualOperator.commentTypeShare == "Character input")
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("文字 -強制") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.WordCountShare
                            + ",,," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + "";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }
                    else if ((FrmOperationManualOperator.commentTypeShare == "Integer input") ||
                            (FrmOperationManualOperator.commentTypeShare == "Decimal input"))
                    {
                        strWorkComplete = lblTitle.Text + "," + lblMessage.Text + "," + txtComment.Text + ",," + objLanguage.Translate("小数点±") + ","
                            + FrmOperationManualOperator.TextTypeShare + "," + FrmOperationManualOperator.MinShare
                            + "," + FrmOperationManualOperator.MaxShare + "," + FrmOperationManualOperator.UnitShare + "," + objLanguage.Translate("否") + ","
                            + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "," + "";

                        lineChanger(strWorkComplete.Replace("\r", "").Replace("\n", ""), strPathSaveComplete, intRowSelect + 5);

                    }

                    Int32 intSecond = (Convert.ToInt32(strHHstart) * 60 * 60) + (Convert.ToInt32(strMMstart) * 60) + Convert.ToInt32(strSSstart);
                    string strSecond = intSecond.ToString();

                    //for (int i = listS.Count; i < intPage; i++)
                    //{
                    //    listS.Insert(i, "");
                    //    listSBNEF.Insert(i, "");
                    //}

                    //listS.Insert(intPage, strSecond);
                    //listSBNEF.Insert(intPage, "F");

                    if (FrmOperationManualOperator.blClickBlack == false)
                    {


                        if (intPage == 0)
                        {
                            listS.Insert(intPage, strSecond);
                            listSBNEF.Insert(intPage, "F");
                        }
                        else
                        {
                            if (intPage > listS.Count)
                            {
                                for (int i = 0; i < intPage; i++)
                                {
                                    if (i == 0)
                                    {
                                        listS.Insert(i, "0");
                                        listSBNEF.Insert(i, "J");
                                    }
                                    else
                                    {
                                        listS.Insert(i, "");
                                        listSBNEF.Insert(i, "");
                                    }

                                }

                                listS.Insert(intPage, strSecond);
                                listSBNEF.Insert(intPage, "F");
                            }
                            else
                            {
                                listS.Insert(intPage, strSecond);
                                listSBNEF.Insert(intPage, "F");
                            }

                        }
                    }



                    SumAll();

                    Int32 intSecondAll = (Convert.ToInt32(strHH) * 60 * 60) + (Convert.ToInt32(strMM) * 60) + Convert.ToInt32(strSS);
                    intSecondAll = intSecondAll - ((Convert.ToInt32(strHHContinue) * 60 * 60)
                        + (Convert.ToInt32(strMMContinue) * 60) + Convert.ToInt32(strSSContinue));
                    string strSecondAll = intSecondAll.ToString();


                    if (this.type == "Operation Manual")
                    {
                        strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + "" + "," + "" + "," + "" + "," + strStartDate + "," + strStartTime
                   + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                   + "," + strSecondAll;

                    }
                    else
                    {
                        strWorkHistory = strWorkHistory + "," + (intRowSelect + 1).ToString() + "," + objLanguage.Translate("1/1目の検査") + "," + loginUser + "," + FrmOperationManualOperator.RemarksShare + "," + strStartDate + "," + strStartTime
                  + "," + DateTime.Now.ToString("yyyy/M/dd") + "," + DateTime.Now.ToString("HH:mm:ss")
                  + "," + strSecondAll;

                        strWorkHistoryStopError = strWorkHistoryStopError + "," + (intRowSelect + 1).ToString() + "," + objLanguage.Translate("1/1目の検査") + "," + loginUser + "," + FrmOperationManualOperator.RemarksShare + "," + strStartDate + "," + strStartTime
                  + "," + strDateStop + "," + strTimeStop
                  + "," + strSecondAll;
                    }


                    //SumAll();

                    if (FrmOperationManualOperator.blClickBlack == false)
                    {
                        intDiffAll = (Convert.ToInt32(strHHstartError) * 60 * 60) + (Convert.ToInt32(strMMstartError) * 60) + Convert.ToInt32(strSSstartError);//intSecondAll - intAll;
                        strDiffAll = intDiffAll.ToString();

                    }
                    else
                    {
                        strDiffAll = strSecondAll;
                    }



                    for (int j = listS.Count; j <= rowCount; j++)
                    {
                        if (j == rowCount)
                        {
                            listS.Insert(j, strDiffAll);
                            listSBNEF.Insert(j, "");
                        }
                        else
                        {
                            listS.Insert(j, "");
                            listSBNEF.Insert(j, "");
                        }

                    }


                    Int32 i1 = 0;
                    foreach (var s in listS)
                    {
                        if (s != null)
                        {
                            strWorkHistory = strWorkHistory + "," + s.ToString() + "," + listSBNEF[i1].ToString();
                            strWorkHistoryStopError = strWorkHistoryStopError + "," + s.ToString() + "," + listSBNEF[i1].ToString();
                        }
                        else if (s == null)
                        {
                            strWorkHistory = strWorkHistory + "," + string.Empty + "," + string.Empty;
                            strWorkHistoryStopError = strWorkHistoryStopError + "," + string.Empty + "," + string.Empty;
                        }
                        i1++;
                    }

                    if (FrmOperationManualOperator.isViewer == false)
                    {
                        //CSV Encoding
                        System.Text.Encoding enc =
                        System.Text.Encoding.UTF8;

                        System.IO.StreamWriter sr =
                            new System.IO.StreamWriter(strPathSave, true, enc);

                        if (this.type != "Operation Manual")
                        {
                            sr.WriteLine(strWorkHistoryStopError);
                        }
                        sr.WriteLine(strWorkHistory);

                        sr.Close();
                    }


                }



                listS = new List<string>();
                listSBNEF = new List<string>();

                this.Dispose();

            }
            else
            {
                this.Dispose();
            }



        }

        private void picMain3_Click(object sender, EventArgs e)
        {

        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (intRowSelect < dataGridView1.Rows.Count)
            {
                if (intColPicSelect == 12)
                {
                    intColPicSelect = 13;
                    //ShowData(intRowSelect, intColPicSelect);

                    if (dataGridView1[intColPicSelect, intRowSelect].Value != null)
                    {
                        if (dataGridView1[intColPicSelect, intRowSelect].Value != string.Empty)
                        {
                            //picMain1_2.Image = null;
                            byte[] data;
                            //using (MemoryStream ms = new MemoryStream())
                            //{
                            data = Convert.FromBase64String(dataGridView1[intColPicSelect, intRowSelect].Value.ToString());
                            picMain1_2.Image = byteArrayToImage((byte[])data);



                            //}



                        }
                    }



                }
                else if (intColPicSelect == 13)
                {
                    intColPicSelect = 12;
                    //ShowData(intRowSelect, intColPicSelect);

                    if (dataGridView1[intColPicSelect, intRowSelect].Value != null)
                    {
                        if (dataGridView1[intColPicSelect, intRowSelect].Value != string.Empty)
                        {
                            //picMain1_2.Image = null;
                            byte[] data;
                            //using (MemoryStream ms = new MemoryStream())
                            //{
                            data = Convert.FromBase64String(dataGridView1[intColPicSelect, intRowSelect].Value.ToString());
                            picMain1_2.Image = byteArrayToImage((byte[])data);



                            //}


                        }
                    }

                }
            }
        }

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


                lblValueDetail.Text = "T" + strHH + ":" + strMM + ":" + strSS + " S" + strHHstart + ":" + strMMstart + ":" + strSSstart;


            }
        }

        private void backgroundWorker2_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 (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();
            }


            intSSstart = intSSstart + 1;

            if (intSSstart > 59)
            {
                intSSstart = 0;
                intMMstart = intMMstart + 1;
            }

            if (intMMstart > 59)
            {
                intMMstart = 0;
                intHHstart = intHHstart + 1;
            }

            if (intSSstart.ToString().Length == 1)
            {
                strSSstart = "0" + intSSstart.ToString();
            }
            else
            {
                strSSstart = intSSstart.ToString();
            }

            if (intMMstart.ToString().Length == 1)
            {
                strMMstart = "0" + intMMstart.ToString();
            }
            else
            {
                strMMstart = intMMstart.ToString();
            }

            if (intHHstart.ToString().Length == 1)
            {
                strHHstart = "0" + intHHstart.ToString();
            }
            else
            {
                strHHstart = intHHstart.ToString();
            }

        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            var grid = sender as DataGridView;
            var rowIdx = (e.RowIndex + 1).ToString();

            var centerFormat = new StringFormat()
            {
                // right alignment might actually make more sense for numbers
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
            e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
        }
    }
}
