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

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

namespace Cosmos.Win
{
    public partial class frmShopPayType : Form
    {
        #region 변수 선언
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private IAccEtc m_cAccEtcInout = null;                                      // 고객 클레임 처리 인터페이스

        private string m_sPosMenuKeyOut;
        public string PosMenuKeyOut { set { m_sPosMenuKeyOut = value; } get { return m_sPosMenuKeyOut; } }
        private DataTable m_dtItemInit;                                             // 조회 데이터 리스트

        #endregion 변수 선언

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

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

            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
            m_cAccEtcInout = (IAccEtc)sManager.InitServiceInstance(ServiceLists.BSV_OPEN_CLOSE.DLL, ServiceLists.BSV_OPEN_CLOSE.ACC_ETC_INOUT);
        }

        private void frmShopPayType_Load(object sender, EventArgs e)
        {
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");

            // 폼 컨트롤 초기화
            InitControl();

            // 컬럼 설정
            SetListColumn();

            // 컬럼 설정
            GetAccInfo();
        }

        private void frmShopPayType_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 폼 컨트롤 초기화
        private void InitControl()
        {
            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);

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

            btnUp.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP2_BASIC);
            btnDw.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN2_BASIC);

            if (btnUp.Image != null) btnUp.Text = "";
            if (btnDw.Image != null) btnDw.Text = "";

            //2017.12.19;label 명 다국어 처리;girak.kim;start
            if (!string.IsNullOrEmpty(MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1083)))
            {
                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1083);
            }

            if (!string.IsNullOrEmpty(MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0009)))
            {
                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0009);
            }
            //2017.12.19;label 명 다국어 처리;girak.kim;End

        }
        #endregion 폼 컨트롤 초기화

        #region Control Event
        #region 업/다운 클릭 이벤트
        /// <summary>
        /// 조회 그리드 업/다운 클릭 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSelProc_Click(object sender, EventArgs e)
        {
            if ((UI.CsmButton)sender == btnUp)
            {
                dgvData.CsmGridScroll("UP");
            }
            else if ((UI.CsmButton)sender == btnDw)
            {
                dgvData.CsmGridScroll("DOWN");
            }
        }
        #endregion 업/다운 클릭 이벤트

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

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvData.CsmGridRowsCount <= 0) return;

                m_sPosMenuKeyOut = dgvData.CsmGridGetCell(dgvData.CsmGridSelectedRowIndex, 2);
                this.DialogResult = DialogResult.OK;
                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);
                this.DialogResult = DialogResult.Cancel;
            }
            return;
        }
        #endregion Control Event

        #region User Method
        /// <summary>
        /// 계정선택 관련 DataGridView 초기화
        /// </summary>
        private void SetListColumn()
        {
            try
            {
                // 준비금 입력 정보
                dgvData.CsmGridColumnHeadersVisible = true;                                   //DataGridView 자체의 컬럼 헤더 Visible 여부
                dgvData.CsmGridColumnHeadersHeight = 56;                                      //DataGridView 자체의 컬럼 헤더 높이 54
                dgvData.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 12, FontStyle.Bold);  //DataGridView 자체의 컬럼 헤더 폰트
                dgvData.CsmGridRowsHeight = 40;
                dgvData.CsmGridColumnCount = 3;                                               //그리드의 컬럼수
                dgvData.CsmGridShowPageRowsCount = 5;                                         //그리드의 한 화면에 보이는 로우수
                dgvData.CsmGridSetHeaderBackColor(236, 238, 239);                             //그리드 헤더 배경색
                dgvData.CsmGridDefaultRowBackColor = Color.FromArgb(255, 255, 255);           //그리드 홀수(Default)행의 배경색 지정
                dgvData.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);         //그리드 짝수(Alternate)행의 배경색 지정
                dgvData.CsmGridBackGroundColor = Color.FromArgb(251, 253, 255);               //기본 백그라운드 컬러
                dgvData.CsmGridHighlightColor = Color.FromArgb(255, 251, 211);                //그리드 선택 백 컬러
                dgvData.CsmGridHighlightTextColor = Color.Black;                              //그리드 선택 글자 컬러
                dgvData.CsmGridSetColumnWidth(new int[] { 714, 0, 0 });                       //컬럼넓이 지정(714)
                dgvData.CsmGridAlignment(new int[] { 1, 1, 1 });                              //컬럼 정렬 0:왼쪽, 1:가운데, 2:오른쪽

                //각 컬럼별 이름 지정
                dgvData.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0907));
                dgvData.CsmGridColumnName(1, "GRP_CODE");
                dgvData.CsmGridColumnName(2, "DTL_CODE");

                //그리드 초기화 테이블
                m_dtItemInit = new DataTable("INIT");
                m_dtItemInit.Columns.Add(new DataColumn("CODE_NM", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("GRP_CODE", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("DTL_CODE", typeof(string)));

                m_dtItemInit.Clear();
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }
        }

        /// <summary>
        /// 계정선택 DataGridView와 Data 연결
        /// </summary>
        public void GetAccInfo()
        {
            try
            {
                DataTable dtData = new DataTable();
                m_dtItemInit.Clear();

                dtData = m_cDataCommon.SeletCommonCode(PosConst.COMMON_CODE_GROUP.B0001, "");

                if (dtData != null && dtData.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtData.Rows)
                    {
                        DataRow drNewRow = m_dtItemInit.NewRow();
                        drNewRow["CODE_NM"] = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CD_NM);
                        drNewRow["GRP_CODE"] = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CMM_GRP_CD);
                        drNewRow["DTL_CODE"] = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CMM_CD);

                        m_dtItemInit.Rows.Add(drNewRow);
                    }

                    //그리드 적용!
                    dgvData.CsmGridDataSource = m_dtItemInit;

                    dgvData.CsmGridSelectRow(0);
                }
                else
                {
                    //데이터 없음!
                    dgvData.CsmGridDataSource = m_dtItemInit;
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     ex.Message);
            }
        }
        #endregion User Method
    }
}
