using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using Cosmos.Common;
using Cosmos.ServiceProvider;
using Cosmos.CommonManager;
using Cosmos.UserFrame;

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 결제 배경
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
    public partial class frmPayBackGround : Form
    {
        #region Variable
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private PosStatus m_cPosStatus = new PosStatus();                           //기본정보 참조
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   //StateObject : StateServer Object(객체)
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스

        private const int WM_SETREDRAW = 0x000B;
        private const int WM_USER = 0x400;
        private const int EM_GETEVENTMASK = (WM_USER + 59);
        private const int EM_SETEVENTMASK = (WM_USER + 69);

        #endregion

        #region 생성자 & 소멸자 & 폼초기화
        public frmPayBackGround()
        {
            try
            {
                InitializeComponent();

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

                m_cPosStatus = (PosStatus)StateObject.POS;      //POS 기본정보
                m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);

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

        private void frmPayBackGround_Load(object sender, EventArgs e)
        {
            try
            {
                InitControl();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void frmPayBackGround_Activated(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                // 이미지 로딩 처리
                this.Size = new Size(1024, 768);
                this.Location = new Point(0, 0);
                this.Opacity = .5;
            }
            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 리치박스 MOT 텍스트 설정
        /// <summary>
        /// 리치박스 MOT 텍스트 설정
        /// </summary>
        /// <returns></returns>
        public bool SetrtbMotMainMotMsg(string sMsgTp, string sMsgFlag)
        {
            try
            {
                //최초 1회만 실행!
                if (rtbMotMain.Tag == null)
                {
                    FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);
                    rtbMotMain.Tag = "1";
                }
                
                rtbMotMain.Text = "";

                DataTable dt = m_cDataCommon.SelectMOT(PosMst.MST_MOT_MSG_DTL.TABLE_NAME, sMsgTp, sMsgFlag, "");
                if (dt == null || dt.Rows.Count <= 0)
                {
                    return false;
                }

                int iStrtNum = 0;

                foreach (DataRow dr in dt.Rows)
                {

                    string tmpStr = string.Empty;

                    tmpStr = CmUtil.GetDataRowStr(dr, PosMst.MST_MOT_MSG_DTL.DATA.MSG);

                    rtbMotMain.AppendText(tmpStr.Trim());
                    rtbMotMain.Select(iStrtNum, tmpStr.Trim().Length);
                    rtbMotMain.SelectionColor = CmUtil.GetColorToString(CmUtil.GetDataRowStr(dr, PosMst.MST_MOT_MSG_DTL.DATA.FONT_COLOR));  // 백 컬러

                    int iFontSize = CmUtil.GetDataRowInt(dr, PosMst.MST_MOT_MSG_DTL.DATA.FONT_SIZE);
                    if (iFontSize <= 0)
                        iFontSize = 1;

                    rtbMotMain.SelectionFont = new Font(m_cPosStatus.Base.FONT, iFontSize);

                    //rtbMotMain.SelectionFont = new Font(m_cPosStatus.Base.FONT, CmUtil.GetDataRowInt(dr, PosMst.MST_MOT_MSG_DTL.DATA.FONT_SIZE));

                    if (CmUtil.GetDataRowStr(dr, PosMst.MST_MOT_MSG_DTL.DATA.NEW_LINE_YN) == "1")
                    {
                        rtbMotMain.AppendText("\n");
                        iStrtNum += 1;
                    }

                    iStrtNum += tmpStr.Trim().Length; // +1; 
                }

                rtbMotMain.Select(0, 0);
                rtbMotMain.Refresh();

                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;
            }
        }
        #endregion

    }

}
