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

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

namespace Cosmos.Win
{
    public partial class frmSchHpLate : Form
    {
        #region 변수 선언
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private IDataProcessUs m_cDataService = null;
        private IDataServiceUs m_cSchHpLate = null;                                 // 해피포인트추후적립조회
        private IDataSearch m_cDataSearch = null;

        private ArrayList m_cSchData = null;                                        // 조회/출력 정보
        private DataTable m_dtItemInit;                                             // 조회 데이터 리스트

        private bool bNotDoubleClik = false;                                        // 더블 클릭 방지용
        #endregion 변수 선언

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

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

            m_cPosStatus = (PosStatus)StateObject.POS;             // POS 기본정보
            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);  
            m_cSchHpLate = (IDataServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.SCH_HP_LATE);  // 해피포인트추후적립조회
            m_cDataSearch = (IDataSearch)sManager.InitServiceInstance(ServiceLists.BSV_ADMIN.DLL, ServiceLists.BSV_ADMIN.DATASEARCH);
        }

        private void frmSchHpLate_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 frmSchHpLate_FormClosing(object sender, FormClosingEventArgs e)
        {
            vScrollbar.Attach(null);

            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            //  조회
            GetHpLateList();
        }
        #endregion 생성자 & 소멸자

        #region 폼 컨트롤 초기화
        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                if (m_cPosStatus.Sale.ScreenSizeUser == 1024)
                {
                    // 이미지 로딩 처리
                    picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_FULL_SIZE);
                    //this.Size = new Size(1024, 696);
                    //this.Location = new Point(0, 50);
                    FormManager.SetControlSize(picBack, 0, 0, 1024, 696);
                    FormManager.SetControlSize(this, 0, 50, picBack.Size.Width, picBack.Size.Height);

                    FormManager.SetControlSize(this.lblTitle, 16, 1, 950, 50, 16);
                    FormManager.SetControlSize(this.btnExit, 965, 1, 58, 50, 20);
                    FormManager.SetControlSize(this.txtPrtData, 686, 123, 322, 555);
                    FormManager.SetControlSize(this.vScrollbar, 981, 124, 30, 555);
                    FormManager.SetControlSize(this.label3, 686, 122, 325, 2);
                    FormManager.SetControlSize(this.label01, 16, 67, 337, 2);
                    FormManager.SetControlSize(this.lblSearchDate, 16, 68, 122, 40);
                    FormManager.SetControlSize(this.btnSearch, 806, 68, 100, 40);
                    FormManager.SetControlSize(this.btnPrint, 908, 68, 100, 40);
                    FormManager.SetControlSize(this.dgvData, 16, 123, 656, 508);
                    FormManager.SetControlSize(this.btnDw2, 508, 630, 164, 48);
                    FormManager.SetControlSize(this.btnDw, 344, 630, 164, 48);
                    FormManager.SetControlSize(this.btnUp, 180, 630, 164, 48);
                    FormManager.SetControlSize(this.btnUp2, 16, 630, 164, 48);
                    FormManager.SetControlSize(this.label5, 16, 122, 656, 2);
                    FormManager.SetControlSize(this.btnDate, 311, 74, 26, 26);
                    FormManager.SetControlSize(this.txtDate, 153, 74, 157, 26);
                    FormManager.SetControlSize(this.lblBox1, 137, 68, 216, 40);


                    btnUp.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP1_BASIC);
                    btnUp.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP1_PRESS);
                    btnUp2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP2_BASIC);
                    btnUp2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP2_PRESS);

                    btnDw.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN1_BASIC);
                    btnDw.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN1_PRESS);
                    btnDw2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN2_BASIC);
                    btnDw2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN2_PRESS);

                }
                else
                {
                    // 이미지 로딩 처리
                    picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);
                    FormManager.SetControlSize(picBack, 0, 0, 800, 600);
                    FormManager.SetControlSize(this, 0, 0, picBack.Size.Width, picBack.Size.Height);

                    FormManager.SetControlSize(this.lblTitle, 16, 1, 728, 50);
                    FormManager.SetControlSize(this.btnExit, 741, 1, 58, 50);
                    FormManager.SetControlSize(this.txtPrtData, 456, 123, 322, 453);
                    FormManager.SetControlSize(this.vScrollbar, 751, 124, 30, 453);
                    FormManager.SetControlSize(this.label3, 456, 122, 325, 2);
                    FormManager.SetControlSize(this.label01, 22, 67, 328, 2);
                    FormManager.SetControlSize(this.lblSearchDate, 22, 68, 122, 40);
                    FormManager.SetControlSize(this.btnSearch, 576, 68, 100, 40);
                    FormManager.SetControlSize(this.btnPrint, 678, 68, 100, 40);
                    FormManager.SetControlSize(this.dgvData, 22, 123, 420, 406);
                    FormManager.SetControlSize(this.btnDw2, 337, 528, 105, 48);
                    FormManager.SetControlSize(this.btnDw, 232, 528, 105, 48);
                    FormManager.SetControlSize(this.btnUp, 127, 528, 105, 48);
                    FormManager.SetControlSize(this.btnUp2, 22, 528, 105, 48);
                    FormManager.SetControlSize(this.label5, 22, 122, 420, 2);
                    FormManager.SetControlSize(this.btnDate, 308, 74, 26, 26);
                    FormManager.SetControlSize(this.txtDate, 159, 74, 148, 26);
                    FormManager.SetControlSize(this.lblBox1, 143, 68, 207, 40);

                    btnUp.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_UP1_BASIC);
                    btnUp.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_UP1_PRESS);
                    btnUp2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_UP2_BASIC);
                    btnUp2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_UP2_PRESS);

                    btnDw.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_DOWN1_BASIC);
                    btnDw.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_DOWN1_PRESS);
                    btnDw2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_DOWN2_BASIC);
                    btnDw2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_105X48_DOWN2_PRESS);
                }

                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_FULL_SIZE);

                btnExit.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BTN_CLOSE);
                if (btnExit.Image != null) btnExit.Text = "";
                btnDate.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.ICON_DATE_BASIC);
                if (btnDate.Image != null) btnDate.Text = "";

                txtPrtData.Font = new Font(m_cPosStatus.Base.FONT_FIX, txtPrtData.Font.Size, txtPrtData.Font.Style);
                vScrollbar.Attach(txtPrtData);

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0876).Replace("\n", "");

                lblSearchDate.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0354);

                btnSearch.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);
                btnPrint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0257);

                //btnUp.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP1_BASIC);
                //btnUp.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP1_PRESS);
                //btnUp2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP2_BASIC);
                //btnUp2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_UP2_PRESS);

                //btnDw.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN1_BASIC);
                //btnDw.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN1_PRESS);
                //btnDw2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN2_BASIC);
                //btnDw2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_164X48_DOWN2_PRESS);

                txtDate.InputTypeFormat = m_cPosStatus.Global.m_stCultureMaster.strDatePattern;
                txtDate.Text = m_cPosStatus.Global.DateToCulture(System.DateTime.Now.ToString("yyyyMMdd"));

                txtPrtData.Text = "";

                // 그리드 설정
                SetListColumn();
            }
            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
            {
                // 해피포인트 추후적립 내역 조회 정보
                dgvData.CsmGridColumnHeadersVisible = true;                                   //DataGridView 자체의 컬럼 헤더 Visible 여부
                dgvData.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 12, FontStyle.Bold);  //DataGridView 자체의 컬럼 헤더 폰트
                dgvData.CsmGridColumnCount = 4;                                               //그리드의 컬럼수
                dgvData.CsmGridSetHeaderBackColor(236, 238, 239);                             //그리드 헤더 배경색
                dgvData.CsmGridDefaultRowBackColor = Color.FromArgb(255, 255, 255);           //그리드 홀수(Default)행의 배경색 지정
                dgvData.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);         //그리드 짝수(Alternate)행의 배경색 지정
                dgvData.CsmGridBackGroundColor = Color.FromArgb(251, 253, 255);               //기본 백그라운드 컬러
                dgvData.CsmGridHighlightColor = Color.FromArgb(255, 251, 211);                //그리드 선택 백 컬러
                dgvData.CsmGridHighlightTextColor = Color.Black;                              //그리드 선택 글자 컬러
                dgvData.CsmGridAlignment(new int[] { 1, 1, 2, 2 });                              //컬럼 정렬 0:왼쪽, 1:가운데, 2:오른쪽

                if (m_cPosStatus.Sale.ScreenSizeUser == 1024)
                {
                    dgvData.CsmGridColumnHeadersHeight = 38;                                      //DataGridView 자체의 컬럼 헤더 높이
                    dgvData.CsmGridRowsHeight = 39;
                    dgvData.CsmGridShowPageRowsCount = 12;                                         //그리드의 한 화면에 보이는 로우수
                    dgvData.CsmGridSetColumnWidth(new int[] { 50, 130, 150, 326 });               //컬럼넓이 지정(656)
                }

                else
                {
                    dgvData.CsmGridColumnHeadersHeight = 34;                                      //DataGridView 자체의 컬럼 헤더 높이
                    dgvData.CsmGridRowsHeight = 37;
                    dgvData.CsmGridShowPageRowsCount = 10;                                         //그리드의 한 화면에 보이는 로우수
                    dgvData.CsmGridSetColumnWidth(new int[] { 50, 110, 120, 140 });               //컬럼넓이 지정(420)
                }

                // 서버에서 컬럼명을 받으므로 따로 지정하지 않음(2017.07.27)
                //각 컬럼별 이름 지정
                //dgvData.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));
                //dgvData.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0870));
                //dgvData.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0017));
                //dgvData.CsmGridColumnName(3, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0871));

                //그리드 초기화 테이블
                m_dtItemInit = new DataTable("INIT");
                m_dtItemInit.Columns.Add(new DataColumn("NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("SALE_DT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("ORG_SALE_DT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("HAPPY_POINT_AMOUNT", typeof(string)));

                m_dtItemInit.Clear();
            }
            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 폼 컨트롤 초기화

        /// <summary>
        /// 저널 데이터 컷팅
        /// </summary>
        /// <param name="sPrtData"></param>
        /// <returns></returns>
        private string PrintDispCuting(string sPrtData)
        {
            string sRecvData = string.Empty;
            int iDataLen = 0;

            try
            {
                while (iDataLen <= sPrtData.Length)
                {
                    sRecvData += CmUtil.MidH(sPrtData, iDataLen, 40) + Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString();
                    iDataLen += 40;
                }
            }
            catch (Exception ex)
            {

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

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

        /// <summary>
        /// 조회 그리드 업/다운 클릭 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSelProc_Click(object sender, EventArgs e)
        {
            try
            {
                if (bNotDoubleClik) return;
                bNotDoubleClik = true;

                if ((UI.CsmButton)sender == btnUp2)
                {
                    dgvData.CsmGridScroll("PAGE UP");
                }
                else if ((UI.CsmButton)sender == btnUp)
                {
                    dgvData.CsmGridScroll("UP");
                }
                else if ((UI.CsmButton)sender == btnDw)
                {
                    dgvData.CsmGridScroll("DOWN");
                }
                else if ((UI.CsmButton)sender == btnDw2)
                {
                    dgvData.CsmGridScroll("PAGE DOWN");
                }
            }

            catch (Exception ex)
            {

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

            bNotDoubleClik = false;
        }

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

            try
            {
                if (txtPrtData.Text == "")
                {
                    WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0302));
                    return;
                }

                ArrayList aPrintData = new ArrayList();

                // 상단 이미지 출력
                if (PosMstManager.GetPosOption(POS_OPTION.OPT409) != "0")
                    AddPrintData(PosConst.PRT_HDR.PRT_TBM, PosConst.PRT_FMT.F100, new string[] { "" }, ref aPrintData);

                // 상단 문구 출력
                AddPrintData(PosConst.PRT_HDR.PRT_NOR, PosConst.PRT_FMT.F101, new string[] { MessageManager.GetPrintMessage(POS_MESSAGE.PRINT.MSG_0160) + m_cPosStatus.Mst.StorName }, ref aPrintData);
                AddPrintData(PosConst.PRT_HDR.PRT_NOR, PosConst.PRT_FMT.F101, new string[] { MessageManager.GetPrintMessage(POS_MESSAGE.PRINT.MSG_0161) + m_cPosStatus.Mst.StorAddr }, ref aPrintData);
                AddPrintData(PosConst.PRT_HDR.PRT_NOR, PosConst.PRT_FMT.F101, new string[] { MessageManager.GetPrintMessage(POS_MESSAGE.PRINT.MSG_0162) + m_cPosStatus.Mst.StorOwnName }, ref aPrintData);
                AddPrintData(PosConst.PRT_HDR.PRT_NOR, PosConst.PRT_FMT.F101, new string[] { MessageManager.GetPrintMessage(POS_MESSAGE.PRINT.MSG_0163) + m_cPosStatus.Mst.StorBizPsnNo + "  (" + m_cPosStatus.Mst.StorTelNo + ")" }, ref aPrintData);
                AddPrintData(PosConst.PRT_HDR.PRT_NOR, PosConst.PRT_FMT.F101, new string[] { MessageManager.GetPrintMessage(POS_MESSAGE.PRINT.MSG_0164) + CmUtil.MidH(m_cPosStatus.Base.CashierName, 0, 12) + " POS NO :" + m_cPosStatus.Base.PosNo }, ref aPrintData);
                AddPrintData(PosConst.PRT_HDR.PRT_NOR, PosConst.PRT_FMT.F101, new string[] { MessageManager.GetPrintMessage(POS_MESSAGE.PRINT.MSG_0165) + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") }, ref aPrintData);
                AddPrintData(PosConst.PRT_HDR.PRT_NOR, PosConst.PRT_FMT.F101, new string[] { "-" }, ref aPrintData);

                // 공지사항 출력
                aPrintData.AddRange(m_cSchData);

                // 하단 이미지 출력
                if (PosMstManager.GetPosOption(POS_OPTION.OPT410) != "0")
                    AddPrintData(PosConst.PRT_HDR.PRT_BBM, PosConst.PRT_FMT.F100, new string[] { "" }, ref aPrintData);

                // cut
                AddPrintData(PosConst.PRT_HDR.PRT_CUT, PosConst.PRT_FMT.F100, new string[] { " " }, ref aPrintData);

                if (aPrintData.Count == 0) return;
                bool bReturn = m_cDataSearch.PosDataPrint(aPrintData);
                if (bReturn == true) sRet = UserCom.RST_OK;

                //string s = (string)m_cSchHpLate.SetData(m_cSchData);
            }
            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 btnSearch_Click(object sender, EventArgs e)
        {
            txtPrtData.Text = "";
            GetHpLateList();
        }

        #region User Method
        /// <summary>
        /// 계정선택 DataGridView와 Data 연결
        /// </summary>
        private void GetHpLateList()
        {
            string sRetData = null;

            string[] sCol = null;
            string[] sHeaderRow = null;
            string[] sDetailRow = null;

            try
            {
                string sDate = m_cPosStatus.Global.CultureToDate(txtDate.Text);

                // 해피포인트추후적립내역조회 리스트
                sRetData = (string)m_cSchHpLate.GetData(new string[] { "1", sDate });
                if (sRetData != UserCom.RST_ERR)
                {
                    if (sRetData != null && sRetData.Length > 0)
                    {
                        // 조회 시 그리드 초기화 추가(2017.07.27)
                        m_dtItemInit.Clear();

                        sCol = sRetData.Split(new string[] { "#~" }, StringSplitOptions.RemoveEmptyEntries);

                        sHeaderRow = sCol[0].Split('|');

                        //각 컬럼별 이름 지정
                        dgvData.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));
                        dgvData.CsmGridColumnName(1, sHeaderRow[0]);
                        dgvData.CsmGridColumnName(2, sHeaderRow[1]);
                        dgvData.CsmGridColumnName(3, sHeaderRow[2]);

                        // 조회 데이터 설정
                        // 헤더 이상의 값이 있을때 화면 설정
                        if (sCol.Count() > 1)
                        {
                            for (int i = 1; i < sCol.Count(); i++)
                            {
                                sDetailRow = sCol[i].Split('|');

                                DataRow drNewRow = m_dtItemInit.NewRow();
                                drNewRow["NO"] = Convert.ToString(i);
                                drNewRow["SALE_DT"] = m_cPosStatus.Global.DateToCulture(sDetailRow[0]);
                                drNewRow["ORG_SALE_DT"] = m_cPosStatus.Global.DateToCulture(sDetailRow[1]);
                                drNewRow["HAPPY_POINT_AMOUNT"] = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(sDetailRow[2]));

                                m_dtItemInit.Rows.Add(drNewRow);
                            }

                            dgvData.CsmGridDataSource = m_dtItemInit;

                            dgvData.CsmGridSelectRow(0);


                            // 상세조회 전문 요청 시 일자에 '-' 제거(2017.07.27)
                            // 상세조회
                            GetHpLateDetail(dgvData.CsmGridGetCell(dgvData.CsmGridSelectedRowIndex, 1).Replace("-", ""));
                        }
                    }
                    else
                    {
                        //데이터 없음!
                        dgvData.CsmGridDataSource = m_dtItemInit;
                    }
                }
                else
                {
                    //데이터 없음!
                    dgvData.CsmGridDataSource = m_dtItemInit;
                }
            }
            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와 Data 연결
        /// </summary>
        private void GetHpLateDetail(string sDateFrom)
        {
            try
            {
                if (dgvData.CsmGridRowsCount <= 0)
                {
                    return;
                }

                if (dgvData.CsmGridSelectedRowIndex < 0)
                {
                    return;
                }

                txtPrtData.Text = "";

                // 1> 상세조회 2> 화면표시, 출력 3> 조회일자
                m_cSchData = (ArrayList)m_cSchHpLate.GetData(new string[] { "2", sDateFrom });

                if (m_cSchData == null) return;

                for (int nLoop = 0; nLoop < m_cSchData.Count; nLoop++)
                {
                    txtPrtData.AppendText(CmUtil.MidH(m_cSchData[nLoop].ToString(), 5, CmUtil.LenH(m_cSchData[nLoop].ToString())).ToString() + PosConst.CRLF);
                }
                txtPrtData.Refresh();
            }
            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 User Method

        private void btnDate_Click(object sender, EventArgs e)
        {
            try
            {
                string sDate = WinBasic.ShowForm(new string[] { FormManager.FORM_CALENDAR });
                if (sDate != "") txtDate.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);
            }
        }

        #region 영수증 출력데이터 생성
        /// <summary>
        /// 영수증 출력데이터 생성
        /// </summary>
        /// <param name="sPrtHead">출력형태</param>
        /// <param name="sPrtFmt">출력포맷</param>
        /// <param name="sData">Data</param>
        private void AddPrintData(string sPrtHead, string sPrtFmt, string[] aData, ref ArrayList aPrintData)
        {
            try
            {
                string sPrtData = "";

                if (sPrtFmt == PosConst.PRT_FMT.F100)               // 선귿기
                {
                    for (int i = 1; i <= 42; i++) sPrtData += aData[0];
                }

                else if (sPrtFmt == PosConst.PRT_FMT.F101)          // 왼쪽정렬
                {
                    sPrtData = aData[0];
                }
                else if (sPrtFmt == PosConst.PRT_FMT.F102)          // 오른쪽 정렬
                {
                    sPrtData = CmUtil.LPadH(aData[0], 42);
                }
                else if (sPrtFmt == PosConst.PRT_FMT.F103)          // 중앙정렬
                {
                    if (sPrtHead == PosConst.PRT_HDR.PRT_HOR || sPrtHead == PosConst.PRT_HDR.PRT_BIG)
                    {
                        if (CmUtil.LenH(aData[0]) <= 21) sPrtData = CmUtil.LPadH("", 10 - (CmUtil.LenH(aData[0]) / 2)) + aData[0];
                    }
                    else
                    {
                        if (CmUtil.LenH(aData[0]) <= 42) sPrtData = CmUtil.LPadH("", 21 - (CmUtil.LenH(aData[0]) / 2)) + aData[0];
                    }
                }
                else
                {
                    switch (aData.Length)
                    {
                        case 5:
                            sPrtData = CmUtil.RPadH(aData[0].ToString(), 13) + CmUtil.LPadH(aData[1].ToString(), 5) + CmUtil.LPadH(aData[2].ToString(), 5) + CmUtil.RPadH(aData[3].ToString(), 5) + CmUtil.LPadH(aData[4].ToString(), 14);
                            break;
                        case 4:
                            sPrtData = CmUtil.RPadH(aData[0].ToString(), 19) + CmUtil.RPadH(aData[1].ToString(), 11) + CmUtil.LPadH(aData[2].ToString(), 6) + CmUtil.LPadH(aData[3].ToString(), 6);
                            break;
                        case 3:
                            sPrtData = CmUtil.RPadH(aData[0].ToString(), 23) + CmUtil.LPadH(aData[1].ToString(), 7) + CmUtil.LPadH(aData[2].ToString(), 11);
                            break;
                        default:
                            sPrtData = aData[0].ToString();
                            break;
                    }
                }
                aPrintData.Add(sPrtHead + sPrtData);
            }
            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 
    }
}
