using DevExpress.Data.Helpers;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Navigation;

using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.IO;
using System.Diagnostics;

using SystemX.Net;
using SystemX.Common;
using SystemX.Net.BaseProtocol;
using SystemX.Net.Comm;
using SystemX.Net.Schedule;
using SystemX.Net.DB;
using SystemX.Common.Serialization;
using SystemX.Common.Archive;
using System.Threading.Tasks;

using SystemX.Common.Protocol.SIA;

using static SystemX.Net.Platform.Common.Util.LogMessage;
using SystemX.Net.Platform.Common.ExtensionMethods;

namespace SystemX.Net.MiddlewareUI
{
    public partial class MainForm : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm
    {
        static internal class CpLogProcessInfo
        {
            static public string strProcessDebugInfo = string.Empty;
            static public string strGetFileName = string.Empty;

            //Summary 삽입 정보 생성
            static public string strHostID = string.Empty;
            static public string strSection = string.Empty;
            static public string strStationID = string.Empty;
            static public string strIdent = string.Empty;
            static public string strStationName = string.Empty;
            static public string strProdNo_P = string.Empty;
            static public string strProdNo_C = string.Empty;
            static public string strTestType = string.Empty;
            static public string strTestCode = string.Empty;
            static public string strVersion = string.Empty;
            static public string strProdCode = string.Empty;
            static public string strTestListCntID = string.Empty;

            static public int nTestListFileNo = int.MaxValue;
            static public int nTestListVariantNo = int.MaxValue;
            static public int nTestListReleaseNo = int.MaxValue;

            static public string strCpLogFileComment = string.Empty;

            static public Dictionary<string, string> dicCpLogHeader = new Dictionary<string, string>();

            static public int nGetReadStepVersion = int.MaxValue;

            /*
             * CpLog Header 상 검사 시작 시간 획득 및 맨앞 공백 제거
             */
            static public string strStTime = string.Empty;

            static public long lMainMeasTime = 0;
            static public long lLongTermMeasTime = 0;
        }

        private string GetFileName(int iPos, HEADER_PACKET getHeader, string strCreateName, string strSubName)
        {
            Random randNumber = new Random();

            string strFileName = strCreateName;

            if (getHeader.objOptionName[0].Data.CompareTo("-") == 0)
                strFileName += @strSubName + @randNumber.Next().ToString() + @thisConnInfo[iPos].strRecvFileExtension;
            else
                strFileName += @thisConnInfo[iPos].strRecvFileName + @thisConnInfo[iPos].strRecvFileExtension;

            if (File.Exists(strFileName) == true)
            {
                while (true)
                {
                    strFileName = strCreateName;

                    if (getHeader.objOptionName[0].Data.CompareTo("-") == 0)
                        strFileName += @strSubName + @randNumber.Next().ToString() + @thisConnInfo[iPos].strRecvFileExtension;
                    else
                        strFileName += @thisConnInfo[iPos].strRecvFileName + "_" + @randNumber.Next().ToString() + @thisConnInfo[iPos].strRecvFileExtension;

                    if (File.Exists(strFileName) == false)
                        break;
                }
            }

            return strFileName;
        }
    }
}
