using System;
using System.Collections;
using System.Windows.Forms;

using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using System.Drawing;

namespace Cosmos.Service
{
    public partial class frmInputPrc : Form
    {
        #region Variable

        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조
        private DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리
        private IDataProcessUs m_cDataService = null;                               // 거래데이터 합계금액 계산 및 관리


        private string m_sPosMenuKeyIn;
        public string PosMenuKeyIn { set { m_sPosMenuKeyIn = value; } get { return m_sPosMenuKeyIn; } }
        private string m_sPosMenuKeyOut;
        public string PosMenuKeyOut { set { m_sPosMenuKeyOut = value; } get { return m_sPosMenuKeyOut; } }

        //#16577 결제창 내부 봉투 추가 기능 도입 start
        private string m_sPosMenuNm;
        public string PosMenuNm { set { m_sPosMenuNm = value; } get { return m_sPosMenuNm; } }
        //#16577 결제창 내부 봉투 추가 기능 도입 end

        #endregion

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

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

            m_cPosStatus = (PosStatus)StateObject.POS;      
            m_cTrnStatus = (TranStatus)StateObject.TRAN;

            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;
        }
        /// <summary>
        /// 폼로드
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmInputPrc_Load(object sender, EventArgs e)
        {

            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);

            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");
            InitControl();
            txtInPutData.Select();
        }
        /// <summary>
        /// 폼 클로즈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmInputPrc_FormClosing(object sender, FormClosingEventArgs e)
        {
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
        }
        #endregion

        #region 폼 컨트롤 초기화        
        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {

                //this.Size = new Size(788, 402);
                //this.Location = new Point(216, 173);

                picBack.Image = ImageManager.GetImage(Cosmos.BaseFrame.BaseCom.NxImgPath, ImageManager.POP_SIZE_S);
                btnExit.Image = ImageManager.GetImage(Cosmos.BaseFrame.BaseCom.NxImgPath, ImageManager.BTN_CLOSE);

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

                btnExit.Image = ImageManager.GetImage(Cosmos.BaseFrame.BaseCom.NxImgPath, ImageManager.BTN_CLOSE);
                if (btnExit.Image != null) btnExit.Text = "";
                
                FormManager.MovePopUpForm(this, false, m_cPosStatus.Sale.ScreenSizeUser);
                
                //테마색상 적용!
                padInPut.ThemeColor = m_cPosStatus.ScnMst.ThemeColor;
                padInPut.ClearBtnText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0817);
                padInPut.SearchBtnText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1018);

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

                padInPut.BtnDotEnable = true;

                lblMsgDesc.Text = "";
                lblMsgDesc.Visible = false;

                //#16577 결제창 내부 봉투 추가 기능 도입 start
                if (m_sPosMenuNm != "")
                {
                    lblTitle.Text = m_sPosMenuNm;
                    lblMsgDesc.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1188);
                    lblMsgDesc.Visible = true;
                }
                //#16577 결제창 내부 봉투 추가 기능 도입 end

                btnExit.Visible = true;
                //btnExit.Text = "X";
                txtInPutData.InputType = UI.InputType.Digit;
                                
                lblMsg.Text = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0233);
                txtInPutData.InputType = UI.InputType.Money;
                txtInPutData.MaxLength = 10;
                
                // 기능 버튼 설정 체크
                FormManager.SetbtnMenu(null, m_cDevStatus.ICReader.UseYn, btnMenu1, btnMenu2, btnMenu3, btnMenu4);

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

        #region Control Event

        /// <summary>
        /// 입력박스 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sFuncValue"></param>
        private void txtEditBox_EditBoxKeyDownEvent(object sender, string sFuncValue)
        {
            try
            {
                if (sFuncValue == PosKey.MENU_KEY.ENTER)
                {
                    if (txtInPutData.Value == "") return;

                    // 로스면 원단위 입력가능!
                    if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.ETC.LOSS)
                    {
                        if (CmUtil.AmountCut(m_cDataService.DoubleParse(txtInPutData.Value), CmUtil.IntParse(m_cPosStatus.Mst.PayRudDwLoc)) != m_cDataService.DoubleParse(txtInPutData.Value))
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);    // 입력한 금액은 입력 불가 단위 입니다.
                            return;
                        }
                    }
                    m_sPosMenuKeyOut = txtInPutData.Value;
                    this.DialogResult = DialogResult.OK;
                    this.Close();

                }
                else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender).ReadOnly == false) ((Cosmos.UI.CsmPosEditBox)sender).Text = "";
                }
                else if (sFuncValue == PosKey.MENU_KEY.ESC_PREVIOUS)
                {

                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        /// <summary>
        /// 입력박스 엔터 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtEditBox_EnterEvent(object sender, EventArgs e)
        {
            try
            {
                padInPut.SetActiveControl = (Control)sender;
                
            }
            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>
        /// 종료
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 소수점 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditBoxTextChangedEvnet(object sender, EventArgs e)
        {

            try
            {
                //if (padInPut.BtnDotEnable == true)
                //{
                //    string stmp = ((Cosmos.UI.CsmPosEditBox)sender).Value;

                //    if (stmp.IndexOf(".") != -1)
                //        ((Cosmos.UI.CsmPosEditBox)sender).Value = Math.Truncate(m_cDataService.DoubleParse(stmp)).ToString();
                //}

            }
            catch (Exception ex)
            {

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


        }
        #endregion
        
        #region User Method
        
        #endregion

    }
}
