//#15746 해피오더 '쇼킹박스' 관련 POS 시스템 개발 요청 start


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text; 
using System.Windows.Forms; 
using Cosmos.BaseFrame;
using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;

namespace Cosmos.Win
{
    public partial class frmHappyOrderBarcode : Form
    {
        private SManager sManager = new SManager();                                 //이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   //StateObject : StateServer Object(객체)
        private PosStatus m_cPosStatus;
        //private TranStatus m_cTrnStatus;                                            //거래정보 참조
        //private DeviceStatus m_cDevStatus = null;

        private IHoldDeal m_cHoldDeal = null;
        private IHappyOrderList m_cHappyOrder = null;
        private IFormHappyOrderMainUs m_cHappyOrderList = null;
        private IDataCommonUs m_cDataCommon = null;


        /// <summary>
        /// 주문번호 
        /// </summary>
        private string mHPOrderNo = "";
        public string sHPOrderNo { set { this.mHPOrderNo = value; } }


        /// <summary>
        /// 상품코드 
        /// </summary>
        private string mItemCode = "";
        public string sItemCode { set { this.mItemCode = value; } }

        /// <summary>
        /// 등록할 바코드 번호 부가정보 
        /// </summary>
        private Hashtable htLandomBoxInfo = null;
         
         
        public frmHappyOrderBarcode()
        {
            try
            {
                InitializeComponent();
                base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
                m_cPosStatus = (PosStatus)StateObject.POS;      //POS 기본정보
                //m_cTrnStatus = (TranStatus)StateObject.TRAN;    //거래정보
                //m_cDevStatus = (DeviceStatus)StateObject.DEVICE;

                m_cHoldDeal = (IHoldDeal)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.HOLD_DEAL);
                m_cHappyOrder = (IHappyOrderList)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.HAPPY_ORDER_LIST);
                m_cHappyOrderList = (IFormHappyOrderMainUs)FormManager.GetForm(FormManager.FORM_SAL_HPORD);
                m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
            }
            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 frmHappyOrderBarcode_Load(object sender, EventArgs e)
        {
            try
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS, 
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + 
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");

                InitControls();
                
                ReadyToBarcode();

                htLandomBoxInfo = new Hashtable();
                htLandomBoxInfo.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);
            }
        }

        private void frmHappyOrderBarcode_FormClosed(object sender, FormClosedEventArgs e)
        {
            UserLog.WriteLogFile(UserCom.LOG_IOS, 
                                 System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + 
                                 System.Reflection.MethodBase.GetCurrentMethod().Name + "()", 
                                 lblTitle.Text);
        }

        private void InitControls()
        {
            try
            {
                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);
                FormManager.SetTextBoxGlobalInfo(this, 
                                                 m_cPosStatus.Global.m_stCultureMaster.nGroupingDigits, 
                                                 m_cPosStatus.Global.m_stCultureMaster.strGroupingSymbol, 
                                                 m_cPosStatus.Global.m_stCultureMaster.nDecimalDigits, 
                                                 m_cPosStatus.Global.m_stCultureMaster.strDecimalSymbol);

                picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_S);

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0483);
              
                btnReg.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0126);

                tbBarcodeNum.Text = string.Empty;
            }
            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>
        /// 텍스트박스에 포커스를 고정
        /// </summary>
        private void ReadyToBarcode()
        {
            try
            {
                tbBarcodeNum.Select();
            }
            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 ControlOnFormClick(object sender, EventArgs e)
        {
            try
            {
                ReadyToBarcode();
            }
            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 btnProc_Click(object sender, EventArgs e)
        {
            try
            {
                if ((Cosmos.UI.CsmButton)sender == btnReg)      // 등록
                {
                    if (htLandomBoxInfo == null || htLandomBoxInfo.Count <= 0)
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0795));
                        ReadyToBarcode();
                        return;
                    }

                    if (WinManager.QuestionMessage("[" + htLandomBoxInfo["BARCODE_NO"].ToString() + "] " + MessageManager.GetGuideMessage(POS_MESSAGE.GUIDE.MSG_0017)) == true)
                    {
                        m_cHappyOrderList.Receive_BarCodeInfo(htLandomBoxInfo);

                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        htLandomBoxInfo.Clear();
                        ReadyToBarcode();
                    }
                }                
            }
            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 btnExit_Click(object sender, EventArgs e)
        {
            try
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            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 tbBarcodeNum_KeyDown(object sender, KeyEventArgs e)
        {
            string sInputData = string.Empty;
            try
            {
                if(e.KeyCode == Keys.Enter)
                {
                    sInputData = tbBarcodeNum.Text;
                    tbBarcodeNum.Text = string.Empty;

                    if (htLandomBoxInfo == null) { htLandomBoxInfo = new Hashtable(); }
                    htLandomBoxInfo.Clear();

                    string sSale_dt = "";
                    string sPos_no = "";
                    string sReg_no = "";                                       

                    DataTable dt = m_cHoldDeal.SearchShockingBoxDealList(sInputData, ItemConst.TRAN_KIND.HPO_LOG.LANDOM_BOX, "0");
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0269));
                        ReadyToBarcode();
                        return;
                    }
                    else
                    {
                        DataRow dr = dt.Rows[0];
                        sSale_dt = dr["SALE_DT"].ToString();
                        sPos_no = dr["POS_NO"].ToString();
                        sReg_no = dr["REG_NO"].ToString();
                    }

                    htLandomBoxInfo.Add("HPORDER_NO", mHPOrderNo);
                    htLandomBoxInfo.Add("ITEM_CD", mItemCode);
                    htLandomBoxInfo.Add("BARCODE_NO", sInputData);
                    htLandomBoxInfo.Add("SALE_DT", sSale_dt);
                    htLandomBoxInfo.Add("POS_NO", sPos_no);
                    htLandomBoxInfo.Add("REG_NO", sReg_no);

                    btnProc_Click(btnReg,null);

                    ReadyToBarcode();
                }
            }
            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);
            }
        }
    }
}

//#15746 해피오더 '쇼킹박스' 관련 POS 시스템 개발 요청 end