using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;

using SHDocVw;

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

namespace Cosmos.Win
{
    public class WinBasic
    {
        /// <summary>
        /// 현재 실행중인 윈도우의 상태를 보여준다.
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="nCmdShow"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

        /// <summary>
        /// 선택한 윈도우를 뒤에 숨어있었으면 앞으로, 최소화상태였으면 원래상태로 되돌려놓으며 활성화시킨다.
        /// </summary>
        /// <param name="hWnd"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        /// <summary>
        /// FORM 화면 표시
        /// </summary>
        /// <param name="aPara"></param>
        /// <returns></returns>
        public static string ShowForm(string[] aPara)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                // WEB POS 화면 호출
                switch (aPara[0])
                {
                    case FormManager.FORM_WEB_POS_PLU_MGR:
                    case FormManager.FORM_WEB_POS_SETTING:
                    case FormManager.FORM_WEB_POS_OPTION:
                    case FormManager.FORM_WEB_POS_REG_FLOVOR:
                    case FormManager.FORM_WEB_POS_TABLE_MANAGEMENT:
                    case FormManager.FORM_WEB_EMGNCY_LIST:
                    case FormManager.FORM_WEB_LINK:
                    case FormManager.FORM_WEB_TMPRT:
                    case FormManager.FORM_WEB_SHOPPING_MALL:
                    case FormManager.FORM_WEB_SEVERANCE:
                    case FormManager.FORM_WEB_MAKE_MENUAL:
                    case FormManager.FORM_WEB_MONTH_EVENT:
                    case FormManager.FORM_WEB_ORDER_LIST:
                    case FormManager.FORM_WEB_EZWELW:
                    case FormManager.FORM_WEB_HAPPY_ORDER:
                    case FormManager.FORM_WEB_BIZEUN:
                    case FormManager.FORM_WEB_SCH_APPROVAL:
                    case FormManager.FORM_WEB_MGR_BGM:
                        // WEBPOS,WEBLINK 호출
                        return ShowWebPos(aPara[1], aPara[0], "");
                }

                if (aPara[0] == FormManager.FORM_MENU_SUB)
                {
                    // 메뉴(팝업)
                    frmMenuSub fForm = (frmMenuSub)FormManager.GetForm(FormManager.FORM_MENU_SUB);
                    if (fForm == null)
                    {
                        fForm = new frmMenuSub();
                        FormManager.AddForm(FormManager.FORM_MENU_SUB, fForm);
                    }

                    fForm.PosMenuKeyIn = aPara[1];      // 메뉴화면 기능키값
                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fForm.PosMenuKeyOut;     // 메뉴선택 기능키값
                    }
                }

                //#15525 고객구매이력 수정 요청 start, 20180704
                //VIP 여부 안내 표시
                else if (aPara[0] == FormManager.FORM_VIP)
                {
                    frmScreenVip fForm = (frmScreenVip)FormManager.GetForm(FormManager.FORM_VIP);

                    if (fForm == null)
                    {
                        fForm = new frmScreenVip();
                        FormManager.AddForm(FormManager.FORM_VIP, fForm);
                    }
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                //#15525 고객구매이력 수정 요청 end, 20180704

                else if (aPara[0] == FormManager.FORM_BIZ_MAIN)
                {
                    //#20181026 #17412 PAS 대왕암공원 - 매출자료조회 frmADMT 오류창 팝업 start
                    UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + 
                                         System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                         "frmBizMain ShowForm");
                    //#20181026 #17412 PAS 대왕암공원 - 매출자료조회 frmADMT 오류창 팝업 end

                    // 메뉴(팝업)
                    frmBizMain fForm = (frmBizMain)FormManager.GetForm(FormManager.FORM_BIZ_MAIN);
                    if (fForm == null)
                    {
                        fForm = new frmBizMain();
                        FormManager.AddForm(FormManager.FORM_BIZ_MAIN, fForm);
                    }

                    fForm.PosMenuKeyIn = aPara[1];      // 메뉴화면 기능키값


                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        //#20181026 #17412 PAS 대왕암공원 - 매출자료조회 frmADMT 오류창 팝업 start
                        UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                             System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                             System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                             "frmBizMain ShowDialog  In : [" + fForm.PosMenuKeyIn + "] , Out : [ " + fForm.PosMenuKeyOut + "]");
                        //#20181026 #17412 PAS 대왕암공원 - 매출자료조회 frmADMT 오류창 팝업 end

                        sRet = fForm.PosMenuKeyOut;     // 메뉴선택 기능키값
                    }
                }
                else if (aPara[0] == FormManager.FORM_SAL_AGE)
                {
                    // 메뉴(팝업)
                    frmRegGuest fForm = (frmRegGuest)FormManager.GetForm(FormManager.FORM_SAL_AGE);
                    if (fForm == null)
                    {
                        fForm = new frmRegGuest();
                        FormManager.AddForm(FormManager.FORM_SAL_AGE, fForm);
                    }
                    fForm.PosMenuKeyIn = aPara[1];      // 메뉴화면 기능키값
                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fForm.PosMenuKeyOut;     // 메뉴선택 기능키값
                    }
                }
                else if (aPara[0] == FormManager.FORM_USER_INPUT_DATA)
                {
                    // 사용자 입력화면(팝업)
                    frmInputData fForm = (frmInputData)FormManager.GetForm(FormManager.FORM_USER_INPUT_DATA);
                    if (fForm == null)
                    {
                        fForm = new frmInputData();
                        FormManager.AddForm(FormManager.FORM_USER_INPUT_DATA, fForm);
                    }
                    fForm.PosMenuKeyIn = aPara[1];      // 입력종류
                    fForm.PosMenuKeyOut = string.Empty;
                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fForm.PosMenuKeyOut;     // 입력값
                    }
                }
                //else if (aPara[0] == FormManager.FORM_ETC_SERVER_REG)
                //{
                //    frmRegServer fForm = (frmRegServer)FormManager.GetForm(FormManager.FORM_ETC_SERVER_REG);
                //    if (fForm == null)
                //    {
                //        fForm = new frmRegServer();
                //        FormManager.AddForm(FormManager.FORM_ETC_SERVER_REG, fForm);
                //    }
                //    DialogResult dReturn = fForm.ShowDialog();
                //    sRet = (dReturn == DialogResult.OK ? UserCom.RST_OK : UserCom.RST_ERR);
                //}
                else if (aPara[0] == FormManager.FORM_SEL_SALE_PLU)
                {
                    // 등록 상품 조회 화면
                    frmSelSalePlu fForm = (frmSelSalePlu)FormManager.GetForm(FormManager.FORM_SEL_SALE_PLU);
                    if (fForm == null)
                    {
                        fForm = new frmSelSalePlu();
                        FormManager.AddForm(FormManager.FORM_SEL_SALE_PLU, fForm);
                    }
                    //#20171116 온라인 쿠폰 제품군코드,상품코드 존재 시 할인 대상이 변경되도록 추가 start, phj
                    //20171229 요건변경(할인대상 상품 중 제일 단가가 작은제품적용, 동일 판매가 일 경우 판매코드 제일 작은 상품) start, phj
                    //#20180502 온라인쿠폰 제품군, 상품코드 할인 적용 기능 적용 start
                    //적용시 주석 해제
                    
                    if (aPara.Length == 2)
                    {
                        fForm.CpnItemDcCode = aPara[1];
                    }
                    
                    //#20180502 온라인쿠폰 제품군, 상품코드 할인 적용 기능 적용 end
                    //20171229 요건변경(할인대상 상품 중 제일 단가가 작은제품적용, 동일 판매가 일 경우 판매코드 제일 작은 상품) end, phj
                    //#20171116 온라인 쿠폰 제품군코드,상품코드 존재 시 할인 대상이 변경되도록 추가 end, phj
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = fForm.SelectRow;
                }
                else if (aPara[0] == FormManager.FORM_SAL_ITEM_SEARCH)
                {
                    frmItemSearch fForm = (frmItemSearch)FormManager.GetForm(FormManager.FORM_SAL_ITEM_SEARCH);
                    if (fForm == null)
                    {
                        fForm = new frmItemSearch();
                        FormManager.AddForm(FormManager.FORM_SAL_ITEM_SEARCH, fForm);
                    }
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = fForm.PosMenuKeyOut;
                }
                else if (aPara[0] == FormManager.FORM_SAL_HOLD)
                {
                    frmHoldDeal fForm = (frmHoldDeal)FormManager.GetForm(FormManager.FORM_SAL_HOLD);
                    if (fForm == null)
                    {
                        fForm = new frmHoldDeal();
                        FormManager.AddForm(FormManager.FORM_SAL_HOLD, fForm);
                    }
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_SAL_CAL)
                {
                    // 임시_PSS
                    frmSalCalc fForm = (frmSalCalc)FormManager.GetForm(FormManager.FORM_SAL_CAL);
                    if (fForm == null)
                    {
                        fForm = new frmSalCalc();
                        FormManager.AddForm(FormManager.FORM_SAL_CAL, fForm);
                    }
                    // 수정을 위한 상세값 전달
                    //fForm.SearchInfo = aPara[2];

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_SAL_TAKE_IN_OUT)
                {
                    frmTakeInOut fForm = (frmTakeInOut)FormManager.GetForm(FormManager.FORM_SAL_TAKE_IN_OUT);
                    if (fForm == null)
                    {
                        fForm = new frmTakeInOut();
                        FormManager.AddForm(FormManager.FORM_SAL_TAKE_IN_OUT, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }

                //#16232 환경부 1회용컵 사용줄이기 관련 테이크인아웃 설정 start
                else if (aPara[0] == FormManager.FORM_SAL_TAKE_IN_OUT_PROD)
                {
                    frmTakeInOutProd fForm = (frmTakeInOutProd)FormManager.GetForm(FormManager.FORM_SAL_TAKE_IN_OUT_PROD);
                    if (fForm == null)
                    {
                        fForm = new frmTakeInOutProd();
                        FormManager.AddForm(FormManager.FORM_SAL_TAKE_IN_OUT_PROD, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                //#16232 환경부 1회용컵 사용줄이기 관련 테이크인아웃 설정 end

                //#16577 결제창 내부 봉투 추가 기능 도입 start
                else if (aPara[0] == FormManager.FORM_ADD_BAG)
                {
                    frmAddBag fForm = (frmAddBag)FormManager.GetForm(FormManager.FORM_ADD_BAG);
                    if (fForm == null)
                    {
                        fForm = new frmAddBag();
                        FormManager.AddForm(FormManager.FORM_ADD_BAG, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fForm.PosMenuKeyOut;     // 메뉴선택 기능키값
                    }
                }
                //#16577 결제창 내부 봉투 추가 기능 도입 end

                else if (aPara[0] == FormManager.FORM_SAL_PREPAID_CUST)
                {
                    frmPrepaidCust fForm = (frmPrepaidCust)FormManager.GetForm(FormManager.FORM_SAL_PREPAID_CUST);
                    if (fForm == null)
                    {
                        fForm = new frmPrepaidCust();
                        FormManager.AddForm(FormManager.FORM_SAL_PREPAID_CUST, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                //else if (aPara[0] == FormManager.FORM_SAL_HP_GIFT_CHARGED)
                //{
                //    frmHPGiftReChange fForm = (frmHPGiftReChange)FormManager.GetForm(FormManager.FORM_SAL_HP_GIFT_CHARGED);
                //    if (fForm == null)
                //    {
                //        fForm = new frmHPGiftReChange();
                //        FormManager.AddForm(FormManager.FORM_SAL_HP_GIFT_CHARGED, fForm);
                //    }

                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //}
                else if (aPara[0] == FormManager.FORM_SCH_EVT)
                {
                    frmSchEvt fForm = (frmSchEvt)FormManager.GetForm(FormManager.FORM_SCH_EVT);
                    if (fForm == null)
                    {
                        fForm = new frmSchEvt();
                        FormManager.AddForm(FormManager.FORM_SCH_EVT, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_REASON_CODE)
                {
                    frmSelReasonCode fForm = (frmSelReasonCode)FormManager.GetForm(FormManager.FORM_REASON_CODE);
                    if (fForm == null)
                    {
                        fForm = new frmSelReasonCode();
                        FormManager.AddForm(FormManager.FORM_REASON_CODE, fForm);
                    }

                    fForm.ReasonGroup = aPara[1];       // 사유 그룹코드
                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fForm.ReasonCode;        // 선택된 사유코드
                    }
                }
                else if (aPara[0] == FormManager.FORM_CAMPAIGN_INFO)
                {
                    frmCampaignInfo fForm = (frmCampaignInfo)FormManager.GetForm(FormManager.FORM_CAMPAIGN_INFO);
                    if (fForm == null)
                    {
                        fForm = new frmCampaignInfo();
                        FormManager.AddForm(FormManager.FORM_CAMPAIGN_INFO, fForm);
                    }

                    fForm.PosMenuKeyIn = aPara[1];
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_NOTICE_SEARCH)
                {
                    frmNoticeInfo fForm = (frmNoticeInfo)FormManager.GetForm(FormManager.FORM_NOTICE_SEARCH);
                    if (fForm == null)
                    {
                        fForm = new frmNoticeInfo();
                        FormManager.AddForm(FormManager.FORM_NOTICE_SEARCH, fForm);
                    }

                    fForm.PosMenuKeyIn = aPara[1];
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }

                //else if (aPara[0] == FormManager.FORM_WEB_STOR_ARRV_INFO)
                //{
                //    WebLink(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_STOR_ARRV_DETAIL)
                //{
                //    WebLink(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_TMPRT)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_SHOPPING_MALL)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_SEVERANCE)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_MAKE_MENUAL)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_MONTH_EVENT)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_ORDER_LIST)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_EZWELW)
                //{
                //    WebStart(aPara[1]);

                //}
                //else if (aPara[0] == FormManager.FORM_WEB_HAPPY_ORDER)
                //{
                //    WebStart(aPara[1]);

                //}
                //else if (aPara[0] == FormManager.FORM_WEB_BIZEUN)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_SCH_APPROVAL)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_MGR_BGM)
                //{
                //    WebStart(aPara[1]);
                //}
                //else if (aPara[0] == FormManager.FORM_SOD_CHECK)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_SOD_CHECK);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_SOD_CHECK, fForm);
                //    }
                //    // 수정을 위한 상세값 전달
                //    fForm.SearchInfo = aPara[1];
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.Show();
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_POS_PLU_MGR)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_WEB_POS_PLU_MGR);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_WEB_POS_PLU_MGR, fForm);
                //        // WEB 업무 화면을 띄워주기 위한 파라메터값
                //        fForm.SearchInfo = aPara[1];
                //    }
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.Show();
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_POS_SETTING)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_WEB_POS_SETTING);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_WEB_POS_SETTING, fForm);
                //        // WEB 업무 화면을 띄워주기 위한 파라메터값
                //        fForm.SearchInfo = aPara[1];
                //    }
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.Show();
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_POS_OPTION)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_WEB_POS_OPTION);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_WEB_POS_OPTION, fForm);
                //        // WEB 업무 화면을 띄워주기 위한 파라메터값
                //        fForm.SearchInfo = aPara[1];
                //    }
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.Show();
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_POS_REG_FLOVOR)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_WEB_POS_REG_FLOVOR);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_WEB_POS_REG_FLOVOR, fForm);
                //        // WEB 업무 화면을 띄워주기 위한 파라메터값
                //        fForm.SearchInfo = aPara[1];
                //    }
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.SearchInfo = aPara[1];
                //    //fForm.Show();
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_POS_TABLE_MANAGEMENT)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_WEB_POS_TABLE_MANAGEMENT);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_WEB_POS_TABLE_MANAGEMENT, fForm);
                //        // WEB 업무 화면을 띄워주기 위한 파라메터값
                //        fForm.SearchInfo = aPara[1];
                //    }
                //    //fForm.Show();
                //    fForm.SearchInfo = aPara[1];
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.SearchInfo = aPara[1];
                //    //fForm.Show();
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_EMGNCY_LIST)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_WEB_EMGNCY_LIST);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_WEB_EMGNCY_LIST, fForm);
                //        // WEB 업무 화면을 띄워주기 위한 파라메터값
                //        fForm.SearchInfo = aPara[1];
                //    }
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.Show();
                //}
                //else if (aPara[0] == FormManager.FORM_WEB_LINK)
                //{
                //    frmWebBiz fForm = (frmWebBiz)FormManager.GetForm(FormManager.FORM_WEB_LINK);
                //    if (fForm == null)
                //    {
                //        fForm = new frmWebBiz();
                //        FormManager.AddForm(FormManager.FORM_WEB_LINK, fForm);
                //        // WEB 업무 화면을 띄워주기 위한 파라메터값
                //        fForm.SearchInfo = aPara[1];
                //    }
                //    fForm.SearchInfo = aPara[1];
                //    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    //fForm.Show();
                //}

		        else if (aPara[0] == FormManager.FORM_SCH_RETURN_COMPAY)
                {
                    frmSchReturnCompany fForm = (frmSchReturnCompany)FormManager.GetForm(FormManager.FORM_SCH_RETURN_COMPAY);
                    if (fForm == null)
                    {
                        fForm = new frmSchReturnCompany();
                        FormManager.AddForm(FormManager.FORM_SCH_RETURN_COMPAY, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_TRANLOG_DOWNLOAD)
                {
                    frmSvr2Tran fForm = (frmSvr2Tran)FormManager.GetForm(FormManager.FORM_TRANLOG_DOWNLOAD);
                    if (fForm == null)
                    {
                        fForm = new frmSvr2Tran();
                        FormManager.AddForm(FormManager.FORM_TRANLOG_DOWNLOAD, fForm); 
                    }
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_PGM_DOWNLOAD)
                {
                    frmPGMDownLoad fForm = (frmPGMDownLoad)FormManager.GetForm(FormManager.FORM_PGM_DOWNLOAD);
                    if (fForm == null)
                    {
                        fForm = new frmPGMDownLoad();
                        FormManager.AddForm(FormManager.FORM_PGM_DOWNLOAD, fForm); 
                    }
                    fForm.PosMenuKeyIn = aPara[1];
                    fForm.ManualMode = aPara[2];
                    
                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = UserCom.RST_ERR;
                    }
                    else
                    {
                        sRet = UserCom.RST_OK;
                    }
                }
		        else if (aPara[0] == FormManager.FORM_SCH_SHIPEMNT)
                {
                    frmSchShipment fForm = (frmSchShipment)FormManager.GetForm(FormManager.FORM_SCH_SHIPEMNT);
                    if (fForm == null)
                    {
                        fForm = new frmSchShipment();
                        FormManager.AddForm(FormManager.FORM_SCH_SHIPEMNT, fForm);
                    }
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_WEB_STOR_ARRV_INFO)
                {
                    frmSchStorArrvInfo fForm = (frmSchStorArrvInfo)FormManager.GetForm(FormManager.FORM_WEB_STOR_ARRV_INFO);
                    if (fForm == null)
                    {
                        fForm = new frmSchStorArrvInfo();
                        FormManager.AddForm(FormManager.FORM_WEB_STOR_ARRV_INFO, fForm);
                    }
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                
                //else if (aPara[0] == FormManager.FORM_CASHIER_INPUT)
                //{
                //    // 판매원(캐셔) 등록 화면
                //    frmRegCashier fFormCsh = (frmRegCashier)FormManager.GetForm(FormManager.FORM_CASHIER_INPUT);
                //    if (fFormCsh == null)
                //    {
                //        fFormCsh = new frmRegCashier();
                //        FormManager.AddForm(FormManager.FORM_CASHIER_INPUT, fFormCsh);
                //    }
                //    if (aPara.Length == 1)
                //    {
                //        fFormCsh.Mode = "0";
                //        if (fFormCsh.ShowDialog() != DialogResult.OK) return sRet;

                //        sRet = fFormCsh.CashierNo + "|" + fFormCsh.CashierName;
                //    }
                //    else
                //    {
                //        fFormCsh.Mode = "1";
                //        if (fFormCsh.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                //    }
                //}
                else if (aPara[0] == FormManager.FORM_SCH_HPLATE)
                {
                    //  해피포인트 추후 적립 조회
                    frmSchHpLate fFormCsh = (frmSchHpLate)FormManager.GetForm(FormManager.FORM_SCH_HPLATE);
                    if (fFormCsh == null)
                    {
                        fFormCsh = new frmSchHpLate();
                        FormManager.AddForm(FormManager.FORM_SCH_HPLATE, fFormCsh);
                    }
                    if (fFormCsh.ShowDialog() != DialogResult.OK) return sRet;

                    //sRet = fFormCsh.CashierNo + "|" + fFormCsh.CashierName;
                }
		        else if (aPara[0] == FormManager.FORM_SCH_KTCH_ORDER)
                {
                    // 주방주문내역조회
                    frmSchKtchOrder fFormCsh = (frmSchKtchOrder)FormManager.GetForm(FormManager.FORM_SCH_KTCH_ORDER);
                    if (fFormCsh == null)
                    {
                        fFormCsh = new frmSchKtchOrder();
                        FormManager.AddForm(FormManager.FORM_SCH_KTCH_ORDER, fFormCsh);
                    }
                    if (fFormCsh.ShowDialog() != DialogResult.OK) return sRet;

                    //sRet = fFormCsh.CashierNo + "|" + fFormCsh.CashierName;
                }
                else if (aPara[0] == FormManager.FORM_PROGRAM_START)
                {
                     //프로그램 시작 화면
                    frmSaleOpen fForm = (frmSaleOpen)FormManager.GetForm(FormManager.FORM_PROGRAM_START);
                    if (fForm == null)
                    {
                        fForm = new frmSaleOpen();
                        FormManager.AddForm(FormManager.FORM_PROGRAM_START, fForm);
                    }

                    fForm.MstDownOp = aPara[1];
                    fForm.PeripheralChk = aPara[2];
                    if (aPara.Length >= 4)
                        fForm.ManualMode = aPara[3];
                    else
                        fForm.ManualMode = "A";
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_EXE_VACCINE)
                {
                    sRet = UserCom.RST_ERR;
                    // 백신 실행
                    sRet = VaccineExe();
                    if (sRet == UserCom.RST_ERR)
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0650));
                    }
                }
                else if (aPara[0] == FormManager.FORM_BARCODE_PRINT)
                {
                    // 스캐너 입력을 위한 메세지 박스
                    frmLabelBarcodePrint fForm = (frmLabelBarcodePrint)FormManager.GetForm(FormManager.FORM_BARCODE_PRINT);
                    if (fForm == null)
                    {
                        fForm = new frmLabelBarcodePrint();
                        FormManager.AddForm(FormManager.FORM_BARCODE_PRINT, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_SIGNPAD_UPDATE)
                {
                    // 서명패드 업데이트
                    frmSignPadUpdate fForm = (frmSignPadUpdate)FormManager.GetForm(FormManager.FORM_SIGNPAD_UPDATE);
                    if (fForm == null)
                    {
                        fForm = new frmSignPadUpdate();
                        FormManager.AddForm(FormManager.FORM_SIGNPAD_UPDATE, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_ETC_CHECK_EMP)    // 출퇴근 등록
                {

                    frmEmpCommute fForm = (frmEmpCommute)FormManager.GetForm(FormManager.FORM_ETC_CHECK_EMP);
                    if (fForm == null)
                    {
                        fForm = new frmEmpCommute();
                        FormManager.AddForm(FormManager.FORM_BARCODE_PRINT, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_SCH_POS_LOG)    // POS LOG 조회
                {

                    frmSchPosLog fForm = (frmSchPosLog)FormManager.GetForm(FormManager.FORM_SCH_POS_LOG);
                    if (fForm == null)
                    {
                        fForm = new frmSchPosLog();
                        FormManager.AddForm(FormManager.FORM_SCH_POS_LOG, fForm);
                    }

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_LOG_ON)
                {
                    // 로그온 및 판매원 등록 처리
                    frmLogOnCashier fForm = (frmLogOnCashier)FormManager.GetForm(FormManager.FORM_LOG_ON);
                    if (fForm == null)
                    {
                        fForm = new frmLogOnCashier();
                        FormManager.AddForm(FormManager.FORM_LOG_ON, fForm);
                    }

                    fForm.PosMenuKey = aPara[1];
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = fForm.CashierInfo;                    
                }
                else if (aPara[0] == FormManager.FORM_REMB_ORDER_PRINT)
                {
                    // 기념일배송 주문정보 출력
                    frmRembOrderPrint fForm = (frmRembOrderPrint)FormManager.GetForm(FormManager.FORM_REMB_ORDER_PRINT);
                    if (fForm == null)
                    {
                        fForm = new frmRembOrderPrint();
                        FormManager.AddForm(FormManager.FORM_REMB_ORDER_PRINT, fForm);
                    }

                    //fForm.PosMenuKey = aPara[1];
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;

                }
                else if (aPara[0] == FormManager.FORM_ETC_EXCHANGE_REG)
                {
                    // 환율등록
                    frmExchageRate fForm = (frmExchageRate)FormManager.GetForm(FormManager.FORM_ETC_EXCHANGE_REG);
                    if (fForm == null)
                    {
                        fForm = new frmExchageRate();
                        FormManager.AddForm(FormManager.FORM_ETC_EXCHANGE_REG, fForm);
                    }
                    fForm.SetPosMenuKey = aPara[1];

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }

                else if (aPara[0] == FormManager.FORM_CALENDAR)
                {
                    // 달력
                    frmCalendar fForm = (frmCalendar)FormManager.GetForm(FormManager.FORM_CALENDAR);
                    if (fForm == null)
                    {
                        fForm = new frmCalendar();
                        FormManager.AddForm(FormManager.FORM_CALENDAR, fForm);
                    }
                    sRet = "";
                    fForm.TopMost = true;
                    if (fForm.ShowDialog() == DialogResult.OK) sRet = fForm.ChoiceDate;
                }
                else if (aPara[0] == FormManager.FORM_HAPPY_BUZZ)
                {
                    // 메뉴(팝업)
                    frmHappyBuzz fForm = (frmHappyBuzz)FormManager.GetForm(FormManager.FORM_HAPPY_BUZZ);
                    if (fForm == null)
                    {
                        fForm = new frmHappyBuzz();
                        FormManager.AddForm(FormManager.FORM_HAPPY_BUZZ, fForm);
                    }

                    fForm.PosMenuKeyIn = aPara[1];      // 메뉴화면 기능키값
                    fForm.CardNoIn = CmUtil.MidH(aPara[2], 0, 16);          // 카드번호
                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fForm.PosMenuKeyOut;     // 메뉴선택 기능키값
                    }
                }
                else if (aPara[0] == FormManager.FORM_DISCOUNT_LIST)
                {
                    // 할인내역리스트 조회
                    frmDiscountList fForm = (frmDiscountList)FormManager.GetForm(FormManager.FORM_DISCOUNT_LIST);
                    if (fForm == null)
                    {
                        fForm = new frmDiscountList();
                        FormManager.AddForm(FormManager.FORM_DISCOUNT_LIST, fForm);
                    }

                    fForm.ShowDialog();
                }
                else if (aPara[0] == FormManager.FORM_SAL_FOREIGNERS_RESPONSE)
                {
                    // 외국인 응대 (영어/일본어/중국어) 팝업창
                    frmForeignersResponse fForm = (frmForeignersResponse)FormManager.GetForm(FormManager.FORM_SAL_FOREIGNERS_RESPONSE);
                    if (fForm == null)
                    {
                        fForm = new frmForeignersResponse();
                        FormManager.AddForm(FormManager.FORM_SAL_FOREIGNERS_RESPONSE, fForm);
                    }

                    fForm.ForeignersInfo = aPara[1];

                    if (fForm.ShowDialog() == DialogResult.OK) sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_POPUP_COM)
                {
                    frmPopupCom fForm = (frmPopupCom)FormManager.GetForm(FormManager.FORM_POPUP_COM);
                    if (fForm == null)
                    {
                        fForm = new frmPopupCom();
                        FormManager.AddForm(FormManager.FORM_POPUP_COM, fForm);
                    }

                    fForm.BizComCode = aPara[1];
                    fForm.BizMsg1 = aPara[2];
                    fForm.BizMsg2 = aPara[3];
                    fForm.BizMsg3 = aPara[4];
                    fForm.SetOnLine = aPara[5] == "T" ? true : false;
                    fForm.SetCountDown = CmUtil.IntParse(aPara[6]);
                    fForm.SetYesMsg = aPara[7];
                    fForm.SetTitle = aPara[8];

                    if (fForm.ShowDialog() != DialogResult.No)
                    {
                        sRet = UserCom.RST_OK;
                    }
                }
                else if (aPara[0] == FormManager.FORM_SAL_EMERGENCY_NOTICE)
                {
                    frmCountdownMessageBox fForm = (frmCountdownMessageBox)FormManager.GetForm(FormManager.FORM_SAL_EMERGENCY_NOTICE);
                    if (fForm == null)
                    {
                        fForm = new frmCountdownMessageBox();
                        FormManager.AddForm(FormManager.FORM_SAL_EMERGENCY_NOTICE, fForm);
                    }
                    fForm.PosMessageType = aPara[1];
                    fForm.PosMessageTitle = aPara[2];
                    fForm.PosMessageStr = aPara[3];
                    
                    if (fForm.ShowDialog() != DialogResult.No)
                    {
                        sRet = UserCom.RST_OK;
                    }
                }
                else if (aPara[0] == FormManager.FORM_MENUAL_ORDER_KPS)
                { 
                    // 주방프린터 수동출력 (장치선택)
                    frmMenualOrderKps f = (frmMenualOrderKps)FormManager.GetForm(FormManager.FORM_MENUAL_ORDER_KPS);
                    if (f == null)
                    {
                        f = new frmMenualOrderKps();
                        FormManager.AddForm(FormManager.FORM_MENUAL_ORDER_KPS, f);
                    }
                    f.HappyOrderList = null; 
                    f.ShowDialog();
                    sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_MENUAL_ORDER_ITEM)
                { 
                    // 주방프린터 수동출력 (메뉴선택) 
                    frmMenualOrderItem f = (frmMenualOrderItem)FormManager.GetForm(FormManager.FORM_MENUAL_ORDER_ITEM);
                    if (f == null)
                    {
                        f = new frmMenualOrderItem();
                        FormManager.AddForm(FormManager.FORM_MENUAL_ORDER_ITEM, f);
                    }
                    f.HappyOrderList = null; 
                    f.ShowDialog();
                    sRet = UserCom.RST_OK;
                }
                else if (aPara[0] == FormManager.FORM_CHOICE_BOX)
                {
                    // 할인/통합결제 선택 
                    frmChoiceBox fForm = (frmChoiceBox)FormManager.GetForm(FormManager.FORM_CHOICE_BOX);
                    if (fForm == null)
                    {
                        fForm = new frmChoiceBox();
                        FormManager.AddForm(FormManager.FORM_CHOICE_BOX, fForm);
                    }

                    fForm.TitleText = aPara[1];
                    fForm.MessageText = aPara[2];
                    fForm.ChoiceButtonText01 = aPara[3];
                    fForm.ChoiceButtonText02 = aPara[4];
                    fForm.SetLocation(CmUtil.IntParse(aPara[5]), CmUtil.IntParse(aPara[6]));
                    fForm.ExitBtnUse = aPara[7];

                    if (fForm.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fForm.ChoiceButtonNo;
                    }
                }
                else if (aPara[0] == FormManager.FORM_KPS_CHECK)
                {
                    frmCheckKtchPrinter fFrom = (frmCheckKtchPrinter)FormManager.GetForm(FormManager.FORM_KPS_CHECK);
                    if (fFrom == null)
                    {
                        fFrom = new frmCheckKtchPrinter();
                        FormManager.AddForm(FormManager.FORM_KPS_CHECK, fFrom);
                    }
                    FormManager.ShowForm(FormManager.FORM_KPS_CHECK);
                }
                else if (aPara[0] == FormManager.FORM_ETC_SELECT_BTN)
                {
                    frmSelectBtnMsgCom fFrom = (frmSelectBtnMsgCom)FormManager.GetForm(FormManager.FORM_ETC_SELECT_BTN);
                    if (fFrom == null)
                    {
                        fFrom = new frmSelectBtnMsgCom();
                        FormManager.AddForm(FormManager.FORM_ETC_SELECT_BTN, fFrom);
                    }
                    fFrom.SetPosMenuKey = aPara[1];
                    fFrom.SetPosMsg = aPara[2];
                    if (fFrom.ShowDialog() == DialogResult.OK)
                    {
                        sRet = fFrom.PosMenuKeyOut;    
                    }
                }
                else if (aPara[0] == FormManager.FORM_SALEPLU_LIST)
                {
                    // 상품내역리스트 조회
                    frmSalePluList fForm = (frmSalePluList)FormManager.GetForm(FormManager.FORM_SALEPLU_LIST);
                    if (fForm == null)
                    {
                        fForm = new frmSalePluList();
                        FormManager.AddForm(FormManager.FORM_SALEPLU_LIST, fForm);
                    }

                    fForm.ShowDialog();
                }
                else if (aPara[0] == FormManager.FORM_BRITHDAY_CANDLE)
                {
                    // 생일초계산
                    frmBirthdayCandle fForm = (frmBirthdayCandle)FormManager.GetForm(FormManager.FORM_BRITHDAY_CANDLE);
                    if (fForm == null)
                    {
                        fForm = new frmBirthdayCandle();
                        FormManager.AddForm(FormManager.FORM_BRITHDAY_CANDLE, fForm);
                    }

                    fForm.ShowDialog();
                }


                
            }
            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 sRet;
        }

        ///// <summary>
        ///// 웹브라우저 띄우기
        ///// </summary>
        ///// <param name="sFuncKey"></param>
        ///// <returns></returns>
        //private static string WebStart(string sFuncKey)
        //{
        //    string sRet = UserCom.RST_ERR;
        //    try
        //    {
        //        IDataServiceUs m_cWebBiz = null;                                    // 웹업무 서비스
        //        SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출

        //        m_cWebBiz = (IDataServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.WEB_BIZ);

        //        string sUrl = string.Empty;

        //        sUrl = (string)m_cWebBiz.GetData(new string[] { sFuncKey });

        //        if (sUrl != UserCom.ERROR && sUrl != null)
        //        {
        //            System.Diagnostics.Process.Start("iexplore.exe", sUrl);
        //            sRet = UserCom.RST_OK;
        //            return sRet;
        //        }

        //        return sRet;
        //    }
        //    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 sRet;
        //}

        /// <summary>
        /// 기능키별 해당 캐셔의 사용 권한 체크
        /// </summary>
        /// <returns></returns>
        public static bool CheckMenuKeyAuth(string sMenuKey)
        {
            try
            { 
                PosStatus m_cPosStatus = (PosStatus)((StateServer)StateServer.GetInstance()).POS;

                string sMngAuth = PosMstManager.GetMstPicAuth(m_cPosStatus.Base.CashierNo + sMenuKey);
                switch(sMngAuth)
                {
                    case PosConst.MNG_AUTH_DIV.NON_PERMISSION:
                        //#20171107 통제관리 start, phj
                        //기존
                        /*
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0308), MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0505), false);
                        return false;
                        */


                        //#20171107 통제관리 start, phj - 20171113
                        //변경
                        //if (WinBasic.ShowForm(new string[] { FormManager.FORM_LOG_ON, PosKey.MENU_KEY.AUTHORITY_CNTL }) == UserCom.RST_ERR) return false;
                        //break;
                        
                        //수정
                        string sRtn_Pwd = string.Empty;
                        sRtn_Pwd = m_cPosStatus.Base.CashierRtnPwd;

                        if (sRtn_Pwd == "")
                        {
                            WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0308), MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0505), false);
                            return false;
                        }
                        else
                        {
                            if (WinBasic.ShowForm(new string[] { FormManager.FORM_LOG_ON, PosKey.MENU_KEY.AUTHORITY_CNTL }) == UserCom.RST_ERR) return false;
                            break;
                        }
                        //#20171107 통제관리 end, phj - 20171113

                        //#20171107 통제관리 end, phj
                    case PosConst.MNG_AUTH_DIV.PERMISSION:
                        break;
                    case PosConst.MNG_AUTH_DIV.SUPERVISOR:
                        if (WinBasic.ShowForm(new string[] { FormManager.FORM_LOG_ON, PosKey.MENU_KEY.REGISTER_ADMIN }) == UserCom.RST_ERR) return false;
                        //sRet = WinBasic.ShowForm(new string[] { FormManager.FORM_CASHIER_INPUT, "Supervisor" });
                        //if (sRet != UserCom.RST_OK)
                        //{
                        //    return UserCom.RST_ERR;
                        //}
                        break;
                }
                return 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);
                return false;
            }
        }

        [DllImport("Ole32.dll", SetLastError = true)]
        private static extern void CoFreeUnusedLibraries();  
        /// <summary>
        /// 웹 화면 표시
        /// </summary>
        /// <param name="sFuncKey"></param>
        /// <returns></returns>
        public static string ShowWebPos(string sFuncKey)
        {
            return ShowWebPos(sFuncKey, "", "", false);
        }
        public static string ShowWebPos(string sFuncKey, string sParam)
        {
            return ShowWebPos(sFuncKey, "", sParam, false);
        }

        //#20170918 기념일 배송 출력 start  
        #region 기념일 배송 출력을 위한 PBILL.EXE 기동  및 중지
        public static string PBillDemonRun(bool bRun)
        {
            string sRet = UserCom.RST_ERR;
            Process[] arPgm = null;
            Process[] arPgm2 = null;
            PosStatus m_cPosStatus = (PosStatus)((StateServer)StateServer.GetInstance()).POS;
            try
            {
                if (bRun == true)
                {
                    // PBILL 데몬 조회
                    arPgm = Process.GetProcessesByName("PBILL");
                    foreach (Process pPgm in arPgm)
                    {
                        // 현재 PBILL 구동 중이면 나감.
                        return UserCom.RST_OK;
                    }

                    // 구포스 EXE 경로에 있으면 그곳에 것 실행.
                    // 없으면 차세대 BIN 폴더 안에 것 실행.

                    //#20180511 기념일배송시 구포스 PBILL 실행되는 증상 수정 start
                    //기존 주석 처리
                    
                    if ((File.Exists("C:\\SPCPOS\\EXE\\PBILL.exe") == true) && ((m_cPosStatus.Base.CmpCd == "PCKR")))
                    {
                        // PBILL 데몬 실행
                        ProcessStartInfo startInfo = new ProcessStartInfo("C:\\SPCPOS\\EXE\\PBILL.exe");
                        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        startInfo.CreateNoWindow = false;
                        Process.Start(startInfo);
                    }
                    else if ((File.Exists("C:\\SLPOS\\EXE\\PBILL.exe") == true) && ((m_cPosStatus.Base.CmpCd == "SLKR")))
                    {
                        // PBILL 데몬 실행
                        ProcessStartInfo startInfo = new ProcessStartInfo("C:\\SLPOS\\EXE\\PBILL.exe");
                        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        startInfo.CreateNoWindow = false;
                        Process.Start(startInfo);
                    }
                    else
                    {
                        ProcessStartInfo startInfo = new ProcessStartInfo(Directory.GetCurrentDirectory().ToString() + @"\PBILL.exe");
                        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        startInfo.CreateNoWindow = false;
                        Process.Start(startInfo);
                    }
                    
                    //변경
                    /*
                    ProcessStartInfo startInfo = new ProcessStartInfo(Directory.GetCurrentDirectory().ToString() + @"\PBILL.exe");
                    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    startInfo.CreateNoWindow = false;
                    Process.Start(startInfo);
                    */
                    //#20180511 기념일배송시 구포스 PBILL 실행되는 증상 수정 end
                }
                else
                {
                    // PBILL 종료 시 
                    // WBP 실행 중이면 종료하지 않고
                    // 구포스 EXE 폴더에 PBILL 파일이 존재하지 않으면
                    // 종료한다.

                    //#20180511 기념일배송시 구포스 PBILL 실행되는 증상 수정 start
                    //기존 주석 처리
                    
                    arPgm2 = Process.GetProcessesByName("WBP");
                    foreach (Process pPgm in arPgm2)
                    {
                        return UserCom.RST_OK;
                    }
                    
                    //#20180511 기념일배송시 구포스 PBILL 실행되는 증상 수정 end

                    /*
                    if ((File.Exists("C:\\SPCPOS\\EXE\\PBILL.exe") == true) && ((m_cPosStatus.Base.CmpCd == "PCKR")))
                    {
                        return UserCom.RST_OK;
                    }
                    else if ((File.Exists("C:\\SLPOS\\EXE\\PBILL.exe") == true) && ((m_cPosStatus.Base.CmpCd == "SLKR")))
                    {
                        return UserCom.RST_OK;
                    }
                    */

                    // PBILL 데몬 종료
                    arPgm = Process.GetProcessesByName("PBILL");
                    foreach (Process pPgm in arPgm)
                    {
                        pPgm.Kill();
                    }
                }

                return UserCom.RST_OK;
            }
            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 sRet;
        }
        #endregion
        //#20170918 기념일 배송 출력 end

        /// <summary>
        /// 웹 화면 표시
        /// </summary>
        /// <param name="sFuncKey">기능키</param>
        /// <param name="bIsBizeunEncoded">빚은몰Encoded여부</param>
        /// <returns></returns>
        public static string ShowWebPos(string sFuncKey, bool bIsBizeunEncoded)
        {
            return ShowWebPos(sFuncKey, "", "", bIsBizeunEncoded);
        }
        public static string ShowWebPos(string sFuncKey, string sFormKey, string sParam, bool bIsBizeunEncoded = false)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                //#20170918 기념일 배송 출력 start  
                //파리, 삼립만 가능하도록 수정 
                if ((sFuncKey== "00176") || (sFuncKey== "00111"))
                {
                    PBillDemonRun(true);
                }
                //#20170918 기념일 배송 출력 end


                SManager sManager = new SManager();     // 이 객체를 통해 업무 Service 호출
                PosStatus m_cPosStatus = (PosStatus)((StateServer)StateServer.GetInstance()).POS;

                IDataServiceUs cWebBiz = (IDataServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.WEB_POS);
 
                // 링크구분(1) + 메뉴명(30) + 메뉴ID(100) + 파라미터(100) + 캡션(50)
                string sUrl = "";

                if (bIsBizeunEncoded == false)
                    sUrl = (string)cWebBiz.GetData(new string[] { sFuncKey });
                else
                    sUrl = (string)cWebBiz.GetData(new string[] { sFuncKey, "1" });
               
                if (sUrl == null || sUrl == "") return sRet;

                if (sUrl.StartsWith("1") == true)           // 1: WEB POS, 2:WEB LINK, 4: 전용프로그램
                {
                    Process[] arPosPgm = Process.GetProcessesByName("WebPos");
                    foreach (Process pPosPgm in arPosPgm)
                    {
                        UserLog.WriteLogFile(UserCom.ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "WebPos.Exe Kill");
                        pPosPgm.Kill();
                        Thread.Sleep(1000);
                    }

                    // 메뉴키(0),메뉴명(1),URL(2),메뉴ID(3),파라메터(4),폰트(5),브랜드구분(6),브랜드코드(7),캐셔번호(8),브라우져키(9)
                    string sPara = "\"" + sFuncKey + "|" + CmUtil.MidH(sUrl, 1, 30).Trim() + "|" + CmUtil.MidH(sUrl, 31, 100).Trim() + "|" + CmUtil.MidH(sUrl, 131, 100).Trim() + "|" + sParam + "|"
                        + m_cPosStatus.Base.FONT + "|" + m_cPosStatus.Mst.CorpDiv + "|" + m_cPosStatus.Base.BrandCd + "|" + m_cPosStatus.Base.CashierNo + "|" + m_cPosStatus.Mst.BrowserKey + "\"";
                   

                    string sFilePath = BaseCom.NxBinPath + "WebPos.exe";
                    if (CmUtil.Exists(sFilePath) == true)
                    {
                        CmUtil.ExecuteProcess(sFilePath, sPara);
                        Thread.Sleep(1000);
                        //CmUtil.ExecuteWaitProcess(sFilePath, sPara);
                        sRet = UserCom.RST_OK;
                    }

                    //CoFreeUnusedLibraries();
                    //System.Threading.Thread.Sleep(500);

                    //// WEBPOS 모달리스 화면으로 로딩
                    //frmWebBiz2 fForm = new frmWebBiz2();
                    //fForm.PosMenuKey = sFuncKey;
                    //fForm.PosMenuName = CmUtil.MidH(sUrl, 1, 30).Trim();
                    //fForm.PosWebMenuURL = CmUtil.MidH(sUrl, 31, 100).Trim();
                    //fForm.PosWebMenuId = CmUtil.MidH(sUrl, 131, 100).Trim();
                    //fForm.PosWebParam = sParam;
                    //fForm.ShowDialog();
                    //sRet = UserCom.RST_OK;
                }
                else if (sUrl.StartsWith("2") == true)           // 1: WEB POS, 2:WEB LINK, 4: 전용프로그램
                {
                    bool bActive = false;                       // 기존에 띄워져 있는 브라우저를 활성화 여부 확인

                    string sCaption = CmUtil.MidH(sUrl, 231, 50).Trim();

                    if (sCaption != null && sCaption != "")
                    {
                        SHDocVw.ShellWindowsClass shWindowsInfo = new SHDocVw.ShellWindowsClass();

                        foreach (SHDocVw.InternetExplorer ielnst in shWindowsInfo)
                        {
                            if (ielnst.Name.Contains("Internet Explorer"))
                            {
                                string url = ielnst.LocationURL;

                                //mshtml.HTMLDocument doc = (HTMLDocument)ielnst.Document;

                                if (url.Contains(sCaption))
                                {
                                    int val = ielnst.HWND;
                                    IntPtr handle = new IntPtr(val);

                                    // 3 -> 최대화
                                    ShowWindowAsync(handle, 3);
                                    bActive = SetForegroundWindow(handle);
                                }
                            }
                        }
                    }

                    // 활성화 시키지 못했을 경우 새로 띄워준다.
                    if (bActive != true)
                    {
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("IExplore.exe");
                        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                        startInfo.Arguments = CmUtil.MidH(sUrl, 31, 100).Trim() + CmUtil.MidH(sUrl, 131, 100).Trim();

                        System.Diagnostics.Process.Start(startInfo);
                    }

                    sRet = UserCom.RST_OK;
                }
                else if (sUrl.StartsWith("4") == true)           // 1: WEB POS, 2:WEB LINK, 4: 전용프로그램
                { 

                    if (CmUtil.FindProcess("nexacro") == true)
                    {
                        CmUtil.SetForceFocus("nexacro");
                    }
                    else
                    {
                        System.Diagnostics.ProcessStartInfo startInfo = null;

                        if (File.Exists(@"C:\Program Files\nexacro\14\nexacro.exe") == true)
                            startInfo = new System.Diagnostics.ProcessStartInfo(@"C:\Program Files\nexacro\14\nexacro.exe");
                        else if (File.Exists(@"C:\Program Files (x86)\nexacro\14\nexacro.exe") == true)
                            startInfo = new System.Diagnostics.ProcessStartInfo(@"C:\Program Files (x86)\nexacro\14\nexacro.exe");

                        if (startInfo == null)
                        {
                            WinManager.ErrorMessage("FILE NOT FIND NEXACRO.EXE"); 
                            return UserCom.RST_ERR;
                        }

                        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;

                        // 브라우저 키값 설정
                        //PosStatus m_cPosStatus = (PosStatus)((StateServer)StateServer.GetInstance()).POS;
                        string sBrowerKey = m_cPosStatus.Mst.BrowserKey;
                        //if (m_cPosStatus.Base.CmpCd == ItemConst.COMPANY_CODE.BRKR) sBrowerKey += m_cPosStatus.Base.BrandCd;

                        if (m_cPosStatus.Mst.CorpDiv == ItemConst.CORP_DIV.BR) sBrowerKey += m_cPosStatus.Base.BrandCd;
                        

                        // "C:\Program Files (x86)\nexacro\14\nexacro.exe" -K 'SPCPosPb' -S 'http://10.0.40.99:7001/spcwps/start.json' -V 'gv_posUsrId=Z1BodGWrqF4z1EX5x5oOkw=='

                        //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 start, phj
                        //기존
                        /*
                         startInfo.Arguments = " -K '" + sBrowerKey + "' -S '" + CmUtil.MidH(sUrl, 31, 100).Trim() +
                                              "' -V 'gv_posUsrId=" + UserLog.UserAES.StaticKeyEncrypt(m_cPosStatus.Base.CashierNo) + "'";
                        */
                        //변경
                        
                        if (m_cPosStatus.Mst.ComplexShopType == "2")
                        {
                            //스퀘어일경우, 실점포코드 + 000으로 수정함.
                            //000인 경우는, 000을 제외하고 다른 아이디로 로그인 시 
                            //실점포에는 그 다른 아이디가 없을 수 도 있기 때문에.
                            string Real_CashierNo = string.Empty;
                            Real_CashierNo = m_cPosStatus.Base.SubShopNo.Trim() + "000";

                            startInfo.Arguments = " -K '" + sBrowerKey + "' -S '" + CmUtil.MidH(sUrl, 31, 100).Trim() +
                                                  "' -V 'gv_posUsrId=" + UserLog.UserAES.StaticKeyEncrypt(Real_CashierNo.Trim()) + "'";
                        }
                        else
                        {
                            startInfo.Arguments = " -K '" + sBrowerKey + "' -S '" + CmUtil.MidH(sUrl, 31, 100).Trim() +
                                                  "' -V 'gv_posUsrId=" + UserLog.UserAES.StaticKeyEncrypt(m_cPosStatus.Base.CashierNo) + "'";
                        }
                        
                        //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 end, phj
                        
                        System.Diagnostics.Process.Start(startInfo);
                    }
                    sRet = UserCom.RST_OK;
                }
                return sRet;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);

                //#20170918 기념일 배송 출력 start  
                //파리, 삼립만 가능하도록 수정 
                if ((sFuncKey == "00176") || (sFuncKey == "00111"))
                {
                    PBillDemonRun(false);
                }
                //#20170918 기념일 배송 출력 end
            }
            return sRet;
        }

        /// <summary>
        /// 백신실행
        /// </summary>
        /// <returns></returns>
        public static string VaccineExe()
        {
            string sVaccineExeNm = null;
            string sRet = UserCom.RST_ERR;

            try
            {
                SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
                IDataCommonUs m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);    // POS 공통함수 인터페이스

                DataTable dtData = new DataTable();

                dtData = m_cDataCommon.SeletCommonCode(PosConst.COMMON_CODE_GROUP.Z0026, "");
                if (dtData != null && dtData.Rows.Count != 0)
                {
                    sVaccineExeNm = dtData.Rows[0].ToString();
                }

                if (sVaccineExeNm != null && sVaccineExeNm != "")
                {
                    System.Diagnostics.Process.Start(BaseCom.NxBinPath + PosConst.VACCINE_EXE_INFO);
                    sRet = UserCom.RST_OK;
                    return sRet;
                }

                return sRet;
            }
            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 sRet;
        }

        public const string ClientPOSVersion = "1.0.0.35"; 
        //##2017.10.19  : 33 > 34 
        // 중국 샤오청쉬 위쳇페이, 기프트 카드 추가됨
    }
}
