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

using Cosmos.UserFrame;
using Cosmos.BaseFrame;
using Cosmos.Common;
using Cosmos.CommonManager;
using Cosmos.ServiceProvider;

namespace Cosmos.Win
{
    public partial class frmStoreEquipCheckList : Form
    {
        #region 변수 선언
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private IStoreEquipCheck m_cStoreEquipCheck = null;                         // 일일점검리스트 조회

        private string sCheckState = null;
        #endregion 변수 선언

        #region 생성자 & 소멸자
        public frmStoreEquipCheckList()
        {
            InitializeComponent();

            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
            //this.UpdateStyles();

            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cStoreEquipCheck = (IStoreEquipCheck)sManager.InitServiceInstance(ServiceLists.BSV_OPEN_CLOSE.DLL, ServiceLists.BSV_OPEN_CLOSE.STORE_EQUIP_CHECK);  // 일일점검리스트조회
        }

        private void frmStoreEquipCheckList_Load(object sender, EventArgs e)
        {
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");
            InitControl();
        }

        private void frmStoreEquipCheckList_FormClosing(object sender, FormClosingEventArgs e)
        {
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
        }
        #endregion 생성자 & 소멸자

        #region 폼 컨트롤 초기화
        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);
                FormManager.SetTextBoxGlobalInfo(this, m_cPosStatus.Global.m_stCultureMaster.nGroupingDigits, m_cPosStatus.Global.m_stCultureMaster.strGroupingSymbol
                    , m_cPosStatus.Global.m_stCultureMaster.nDecimalDigits, m_cPosStatus.Global.m_stCultureMaster.strDecimalSymbol);
                FormManager.MovePopUpForm(this, false, m_cPosStatus.Sale.ScreenSizeUser);
                picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);
                btnExit.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BTN_CLOSE);
                if (btnExit.Image != null) btnExit.Text = "";

                btnUp.DefaultImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_UP1_BASIC);
                btnUp.ClickImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_UP1_PRESS);
                btnUp2.DefaultImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_UP1_BASIC);
                btnUp2.ClickImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_UP1_PRESS);

                btnDn.DefaultImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_DOWN1_BASIC);
                btnDn.ClickImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_DOWN1_PRESS);
                btnDn2.DefaultImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_DOWN1_BASIC);
                btnDn2.ClickImage = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_105X48_DOWN1_PRESS);

                //테마색상 적용!
                btnSearch.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);

                // 라벨 이름 설정
                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0965);
                lblSearchDate.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0354);

                // 버튼 이름 설정
                btnSearch.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);
                btnAsFin.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0966);
                btnStoreFin.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0967);

                // 일자설정
                txtDateFrom.InputTypeFormat = m_cPosStatus.Global.m_stCultureMaster.strDatePattern;
                txtDateFrom.Text = m_cPosStatus.Global.DateToCulture(m_cPosStatus.Base.SaleDate);

                txtDateTo.InputTypeFormat = m_cPosStatus.Global.m_stCultureMaster.strDatePattern;
                txtDateTo.Text = m_cPosStatus.Global.DateToCulture(m_cPosStatus.Base.SaleDate);

                // 일일점검 리스트 그리드 초기화
                SetListColumn();

                // 일일점검 상세 그리드 초기화
                SetDetailColumn();

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 일일점검 리스트 DataGridView 초기화
        /// </summary>
        private void SetListColumn()
        {
            try
            {
                int[] arColumnsWidth = { 100, 150, 0 };
                int[] arColumnsAlignment = { 0, 1, 2 };

                dgvData1.Columns.Clear();
                dgvData1.Rows.Clear();

                dgvData1.Columns.Add("DATE", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0530));
                dgvData1.Columns.Add("STATE_NAME", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0421));
                dgvData1.Columns.Add("STATE_CODE", "상태코드");

                dgvData1.ColumnHeadersHeight = 40;
                dgvData1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                dgvData1.RowHeadersVisible = false;
                dgvData1.AllowUserToAddRows = false;
                dgvData1.Font = new Font(m_cPosStatus.Base.FONT, 12);
                dgvData1.RowTemplate.Height = 40;

                for (int nLoop = 0; nLoop < dgvData1.Columns.Count; nLoop++)
                {
                    dgvData1.Columns[nLoop].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    dgvData1.Columns[nLoop].Width = arColumnsWidth[nLoop];
                    dgvData1.Columns[nLoop].Resizable = DataGridViewTriState.False;

                    if (nLoop == 0 || nLoop == 1)
                    {
                        dgvData1.Columns[nLoop].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                        dgvData1.Columns[nLoop].ReadOnly = true;
                    }
                    else if (nLoop >= 2)
                    {
                        dgvData1.Columns[nLoop].Visible = false;
                    }

                    switch (arColumnsAlignment[nLoop])
                    {
                        case 0:
                            dgvData1.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                            break;
                        case 1:
                            dgvData1.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                            break;
                        default:
                            dgvData1.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                            break;
                    }

                    dgvData1.Columns[nLoop].SortMode = DataGridViewColumnSortMode.NotSortable;
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }
        }

        /// <summary>
        /// 일일점검 상세 DataGridView 초기화
        /// </summary>
        private void SetDetailColumn()
        {
            try
            {
                int[] arColumnsWidth = { 100, 100, 200, 50, 50, 0, 0 };
                int[] arColumnsAlignment = { 0, 0, 0, 0, 0, 0, 0 };

                dgvData2.Columns.Clear();
                dgvData2.Rows.Clear();

                dgvData2.Columns.Add("TYPE", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0532));
                dgvData2.Columns.Add("DEVICENAME", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0968));
                dgvData2.Columns.Add("CHECKINFO", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0969));
                dgvData2.Columns.Add("AS_RESULT", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0970));
                dgvData2.Columns.Add("STOR_RESULT", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0970));

                dgvData2.Columns.Add("CHECK_DIV_CD", "점포점검구분");
                dgvData2.Columns.Add("CHECK_EQU_CD", "점포점검항목");

                dgvData2.ColumnHeadersHeight = 40;
                dgvData2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                dgvData2.RowHeadersVisible = false;
                dgvData2.AllowUserToAddRows = false;
                dgvData2.Font = new Font(m_cPosStatus.Base.FONT, 12);
                dgvData2.RowTemplate.Height = 40;

                for (int nLoop = 0; nLoop < dgvData2.Columns.Count; nLoop++)
                {
                    dgvData2.Columns[nLoop].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    dgvData2.Columns[nLoop].Width = arColumnsWidth[nLoop];
                    dgvData2.Columns[nLoop].Resizable = DataGridViewTriState.False;

                    if (nLoop == 0 || nLoop == 1)
                    {
                        dgvData2.Columns[nLoop].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                        dgvData2.Columns[nLoop].ReadOnly = true;
                    }
                    else if (nLoop >= 5)
                    {
                        dgvData2.Columns[nLoop].Visible = false;
                    }

                    switch (arColumnsAlignment[nLoop])
                    {
                        case 0:
                            dgvData2.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                            break;
                        case 1:
                            dgvData2.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                            break;
                        default:
                            dgvData2.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                            break;
                    }

                    dgvData2.Columns[nLoop].SortMode = DataGridViewColumnSortMode.NotSortable;
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }
        }
        #endregion 폼 컨트롤 초기화

        #region Control Event
        /// <summary>
        /// 조회 그리드 업/다운 클릭 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSelProc_Click(object sender, EventArgs e)
        {
            int nRow1 = 0;
            int nRow2 = 0;

            try
            {
                if ((UI.CsmButton)sender == btnUp)                               // 좌측 그리드 Up
                {
                    if (nRow1 > 0)
                    {
                        nRow1--;
                        dgvData1.Rows[nRow1].Selected = true;
                        dgvData1.Rows[nRow1].Cells[dgvData1.CurrentCell.ColumnIndex].Selected = true;
                    }
                }
                else if ((UI.CsmButton)sender == btnDn)                          // 좌측 그리드 Down
                {
                    if (nRow1 < dgvData1.Rows.Count - 1)
                    {
                        nRow1++;
                        dgvData1.Rows[nRow1].Selected = true;
                        dgvData1.Rows[nRow1].Cells[dgvData1.CurrentCell.ColumnIndex].Selected = true;
                    }
                }
                else if ((UI.CsmButton)sender == btnUp2)                               // 우측 그리드 Up
                {
                    if (nRow2 > 0)
                    {
                        nRow2--;
                        dgvData2.Rows[nRow2].Selected = true;
                        dgvData2.Rows[nRow2].Cells[dgvData1.CurrentCell.ColumnIndex].Selected = true;
                    }
                }
                else if ((UI.CsmButton)sender == btnDn2)                          // 우측 그리드 Down
                {
                    if (nRow2 < dgvData2.Rows.Count - 1)
                    {
                        nRow2++;
                        dgvData2.Rows[nRow2].Selected = true;
                        dgvData2.Rows[nRow2].Cells[dgvData1.CurrentCell.ColumnIndex].Selected = true;
                    }
                }

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string sRetData = null;
            string[] sCol = null;
            string[] sDetailRow = null;

            int iRow = 0;

            try
            {
                dgvData1.Rows.Clear();

                string sFromDate = m_cPosStatus.Global.CultureToDate(txtDateFrom.Text);
                string sToDate = m_cPosStatus.Global.CultureToDate(txtDateTo.Text);

                // 일일점검리스트 일자별 상태 조회
                sRetData = (string)m_cStoreEquipCheck.SearchStoreEquipCheckList( "0", sFromDate, sToDate );
                if (sRetData != UserCom.RST_ERR)
                {
                    if (sRetData != null && sRetData.Length > 0)
                    {
                        sCol = sRetData.Split(new string[] { "#~" }, StringSplitOptions.RemoveEmptyEntries);

                        // 조회 데이터 설정
                        if (sCol.Count() > 0)
                        {
                            for (int i = 0; i < sCol.Count(); i++)
                            {
                                sDetailRow = sCol[i].Split('|');

                                iRow = dgvData1.Rows.Add();
                                dgvData1.Rows[iRow].Cells[0].Value = m_cPosStatus.Global.DateToCulture(sDetailRow[0]);
                                dgvData1.Rows[iRow].Cells[1].Value = DateCheckState(sDetailRow[1]);
                                dgvData1.Rows[iRow].Cells[2].Value = sDetailRow[1];
                            }
                        }
                    }
                    else
                    {
                        //데이터 없음!
                        //dgvData.CsmGridDataSource = m_dtInit;
                    }
                }
                else
                {
                    //데이터 없음!
                    //dgvData.CsmGridDataSource = m_dtInit;
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }
        }

        private void btnAsFin_Click(object sender, EventArgs e)
        {
            string sRet = UserCom.RST_ERR;

            try
            {
                if (dgvData2.RowCount <= 0) return;

                dgvData2.SelectedRows[0].Cells[3].Value = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0248);

                sHeaderState();

                string sRegUserId = m_cPosStatus.Base.CashierNo;

                // 점포 점검 리스트(헤더)
                DataTable dtData1 = new DataTable();
                dtData1.Columns.Add(new DataColumn("SALE_DT", typeof(string)));
                dtData1.Columns.Add(new DataColumn("CHECK_STATE", typeof(string)));
                dtData1.Columns.Add(new DataColumn("REG_USER_ID", typeof(string)));

                // 점포 점검 리스트(디테일)
                DataTable dtData2 = new DataTable();
                dtData2.Columns.Add(new DataColumn("SALE_DT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("CHECK_DIV_CD", typeof(string)));
                dtData2.Columns.Add(new DataColumn("CHECK_EQU_CD", typeof(string)));
                dtData2.Columns.Add(new DataColumn("CHECK_RESULT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("AS_RESULT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("STOR_RESULT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("REG_USER_ID", typeof(string)));


                // 점포점검 마스터 헤더 값 설정
                DataRow dr1 = dtData1.NewRow();
                dr1["SALE_DT"] = dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", "");
                dr1["CHECK_STATE"] = sCheckState;
                dr1["REG_USER_ID"] = sRegUserId;   //cbCashierName.ValueMember;

                dtData1.Rows.Add(dr1);

                for (int i = 0; i < dgvData2.RowCount; i++)
                {
                    DataRow dr2 = dtData2.NewRow();
                    dr2["SALE_DT"] = dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", "");

                    dr2["AS_RESULT"] = DetailState((string)dgvData2.Rows[i].Cells[3].Value);
                    dr2["STOR_RESULT"] = DetailState((string)dgvData2.Rows[i].Cells[4].Value);
                    dr2["CHECK_RESULT"] = "2";
                    dr2["CHECK_DIV_CD"] = ((string)dgvData2.Rows[i].Cells[5].Value);
                    dr2["CHECK_EQU_CD"] = ((string)dgvData2.Rows[i].Cells[6].Value);

                    dr2["REG_USER_ID"] = sRegUserId;   //cbCashierName.ValueMember;


                    dtData2.Rows.Add(dr2);
                }

                sRet = m_cStoreEquipCheck.StoreCheckSave(dtData1, dtData2);
                if (sRet == UserCom.RST_OK)
                {
                    //this.DialogResult = DialogResult.OK;
                    //this.Close();
                }

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void btnStoreFin_Click(object sender, EventArgs e)
        {
            string sRet = UserCom.RST_ERR;

            try
            {
                if (dgvData2.RowCount <= 0) return;

                dgvData2.SelectedRows[0].Cells[4].Value = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0248);

                sHeaderState();

                string sRegUserId = m_cPosStatus.Base.CashierNo;

                // 점포 점검 리스트(헤더)
                DataTable dtData1 = new DataTable();
                dtData1.Columns.Add(new DataColumn("SALE_DT", typeof(string)));
                dtData1.Columns.Add(new DataColumn("CHECK_STATE", typeof(string)));
                dtData1.Columns.Add(new DataColumn("REG_USER_ID", typeof(string)));

                // 점포 점검 리스트(디테일)
                DataTable dtData2 = new DataTable();
                dtData2.Columns.Add(new DataColumn("SALE_DT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("CHECK_DIV_CD", typeof(string)));
                dtData2.Columns.Add(new DataColumn("CHECK_EQU_CD", typeof(string)));
                dtData2.Columns.Add(new DataColumn("CHECK_RESULT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("AS_RESULT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("STOR_RESULT", typeof(string)));
                dtData2.Columns.Add(new DataColumn("REG_USER_ID", typeof(string)));


                // 점포점검 마스터 헤더 값 설정
                DataRow dr1 = dtData1.NewRow();
                dr1["SALE_DT"] = dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", "");
                dr1["CHECK_STATE"] = sCheckState;
                dr1["REG_USER_ID"] = sRegUserId;   //cbCashierName.ValueMember;

                dtData1.Rows.Add(dr1);

                for (int i = 0; i < dgvData2.RowCount; i++)
                {
                    DataRow dr2 = dtData2.NewRow();
                    dr2["SALE_DT"] = dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", "");

                    dr2["AS_RESULT"] = DetailState((string)dgvData2.Rows[i].Cells[3].Value);
                    dr2["STOR_RESULT"] = DetailState((string)dgvData2.Rows[i].Cells[4].Value);
                    dr2["CHECK_RESULT"] = "2";
                    dr2["CHECK_DIV_CD"] = ((string)dgvData2.Rows[i].Cells[5].Value);
                    dr2["CHECK_EQU_CD"] = ((string)dgvData2.Rows[i].Cells[6].Value);

                    dr2["REG_USER_ID"] = sRegUserId;   //cbCashierName.ValueMember;


                    dtData2.Rows.Add(dr2);
                }

                sRet = m_cStoreEquipCheck.StoreCheckSave(dtData1, dtData2);
                if (sRet == UserCom.RST_OK)
                {
                    //this.DialogResult = DialogResult.OK;
                    //this.Close();
                }

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void dgvData1_Click(object sender, EventArgs e)
        {
            string sRet = UserCom.RST_ERR;

            try
            {
                dgvData2.Rows.Clear();

                if (dgvData1.RowCount <= 0) return;

                if (dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", "") == "" || dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", "") == null) return;

                if (dgvData1.SelectedRows[0].Cells[2].Value.ToString() == PosConst.EquipCheckCode.NO_CHECK)
                {
                    if (dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", "") != m_cPosStatus.Base.SaleDate)
                    {
                        WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0435));
                        return;
                    }

                    // 미점검
                    // 일일점검리스트 항목 표시
                    if (m_cPosStatus.Base.SaleDate != "")
                    {
                        sRet = WinOpenClose.ShowForm(new string[] { FormManager.FORM_STORE_EQUIP_CHECK, PosKey.MENU_KEY.STORE_EQUIP_CHECK });
                        if (sRet == UserCom.RST_OK)
                        {

                        }
                    }
                }
                else if (dgvData1.SelectedRows[0].Cells[2].Value.ToString() == PosConst.EquipCheckCode.ING_CHECK 
                    || dgvData1.SelectedRows[0].Cells[2].Value.ToString() == PosConst.EquipCheckCode.FIN_CHECK)
                {
                    // 점검완료, 점검중일 경우에는 좌측에 전문통신 한 것으로 목록을 보여준다. (오류로 표시한것만 보여준다.)
                    StoreEquipError(dgvData1.SelectedRows[0].Cells[0].Value.ToString().Replace("-", ""));

                }
                else if (dgvData1.SelectedRows[0].Cells[2].Value.ToString() == PosConst.EquipCheckCode.OK_CHECK)
                {
                    // 이상무일 경우에는 "특이사항 없음" 이라는 팝업창을 표시해 준다.
                    WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0605));
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void btnDateFrom_Click(object sender, EventArgs e)
        {
            try
            {
                string sDate = WinBasic.ShowForm(new string[] { FormManager.FORM_CALENDAR });
                if (sDate == "" || sDate.Length != 8) return;

                // 체크일자가 영업일자보다 큰지 확인 필요함
                if (CmUtil.LongParse(sDate) > CmUtil.LongParse(System.DateTime.Now.ToString(m_cPosStatus.Base.SaleDate)))
                {
                    WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0607));
                    return;
                }
                if (sDate != "") txtDateFrom.Text = m_cPosStatus.Global.DateToCulture(sDate);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void btnDateTo_Click(object sender, EventArgs e)
        {
            try
            {
                string sDate = WinBasic.ShowForm(new string[] { FormManager.FORM_CALENDAR });
                if (sDate == "" || sDate.Length != 8) return;

                // 체크일자가 영업일자보다 큰지 확인 필요함
                if (CmUtil.LongParse(sDate) > CmUtil.LongParse(System.DateTime.Now.ToString(m_cPosStatus.Base.SaleDate)))
                {
                    WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0607));
                    return;
                }
                if (sDate != "") txtDateTo.Text = m_cPosStatus.Global.DateToCulture(sDate);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion Control Event

        #region User Method
        private string DateCheckState(string sCode)
        {
            string sResultMsg = "";

            try
            {
                if (sCode == PosConst.EquipCheckCode.NO_CHECK)
                {
                    // 미점검
                    sResultMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0994);
                }
                else if (sCode == PosConst.EquipCheckCode.OK_CHECK)
                {
                    // 이상무
                    sResultMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0995);
                }
                else if (sCode == PosConst.EquipCheckCode.ING_CHECK)
                {
                    // 점검중
                    sResultMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0996);
                }
                else if (sCode == PosConst.EquipCheckCode.FIN_CHECK)
                {
                    // 점검완료
                    sResultMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0997);
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }

            return sResultMsg;
        }

        private string DateCheckEquState(string sCode)
        {
            string sResultMsg = "";

            try
            {
                if (sCode == "0")
                {
                    sResultMsg = "";
                }
                else if (sCode == "1")
                {
                    sResultMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0248);
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }

            return sResultMsg;
        }

        private void StoreEquipError(string sDate)
        {
            string sRetData = null;
            string[] sCol = null;
            string[] sDetailRow = null;

            int iRow = 0;

            try
            {
                // 일일점검리스트 일자별 상태 조회
                sRetData = (string)m_cStoreEquipCheck.SearchStoreEquipCheckList("1", sDate, sDate);
                if (sRetData != UserCom.RST_ERR)
                {
                    if (sRetData != null && sRetData.Length > 0)
                    {
                        sCol = sRetData.Split(new string[] { "#~" }, StringSplitOptions.RemoveEmptyEntries);

                        // 조회 데이터 설정
                        if (sCol.Count() > 0)
                        {
                            for (int i = 0; i < sCol.Count(); i++)
                            {
                                sDetailRow = sCol[i].Split('|');

                                iRow = dgvData2.Rows.Add();
                                dgvData2.Rows[iRow].Cells[0].Value = sDetailRow[1];
                                dgvData2.Rows[iRow].Cells[1].Value = sDetailRow[3];
                                dgvData2.Rows[iRow].Cells[2].Value = sDetailRow[6];
                                dgvData2.Rows[iRow].Cells[3].Value = DateCheckEquState(sDetailRow[4]);
                                dgvData2.Rows[iRow].Cells[4].Value = DateCheckEquState(sDetailRow[5]);
                                dgvData2.Rows[iRow].Cells[5].Value = sDetailRow[0];
                                dgvData2.Rows[iRow].Cells[6].Value = sDetailRow[2];
                            }
                        }
                    }
                    else
                    {
                        //데이터 없음!
                        //dgvData.CsmGridDataSource = m_dtInit;
                    }
                }
                else
                {
                    //데이터 없음!
                    //dgvData.CsmGridDataSource = m_dtInit;
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }
        }

        private string sHeaderState()
        {
            sCheckState = PosConst.EquipCheckCode.FIN_CHECK;

            try
            {
                for (int i = 0; i < dgvData2.RowCount; i++)
                {
                    // AS
                    if (dgvData2.Rows[i].Cells[3].Value.ToString() != MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0248))
                    {
                        sCheckState = PosConst.EquipCheckCode.ING_CHECK;
                    }

                    // 점포확인
                    if (dgvData2.Rows[i].Cells[4].Value.ToString() != MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0248))
                    {
                        sCheckState = PosConst.EquipCheckCode.ING_CHECK;
                    }
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }

            return "";
        }

        private string DetailState(string sFlag)
        {
            string sDetailState = "0";

            try
            {
                if (sFlag == MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0248))
                {
                    sDetailState = "1";
                    return sDetailState;
                }
                else
                {
                    sDetailState = "0";
                    return sDetailState;
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }

            return sDetailState;
        }
        #endregion User Method

    }
}
