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;
using System.Globalization;

namespace Cosmos.Win
{
    public partial class frmHappyOrderWeightPrint : 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 PosOLEDevice.DelegateOlePos delegatePos;

        /// <summary>
        /// Grid 연동 DataTable
        /// </summary>
        private DataTable m_dtGrid;

        /// <summary>
        /// 출력 Data Array
        /// </summary>
        private ArrayList m_sPrintData;

        /// <summary>
        /// 해피오더 Header 정보
        /// </summary>
        private Column.TR_HPORD.HPORD_HEADER m_cHappyOrderHeader;
        public Column.TR_HPORD.HPORD_HEADER HappyOrderHeader { set { m_cHappyOrderHeader = value; } }
        /// <summary>
        /// 해피오더 Item 정보
        /// </summary>
        private ArrayList m_cHappyOrderItem;
        public ArrayList HappyOrderItem { set { m_cHappyOrderItem = value; } }

        private string m_sReceiverHp;
        private string m_sFlavour1;
        private string m_sFlavour2;
        private string m_sOrderDT;

        public frmHappyOrderWeightPrint()
        {
            InitializeComponent();

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

            m_cPosStatus = (PosStatus)StateObject.POS;      //POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    //거래정보
            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;

            //delegatePos = new PosOLEDevice.DelegateOlePos(OnDeviceEvent);

            //PosOLEDevice.SetEventHandle(delegatePos);

            m_sPrintData = new ArrayList();
        }

        private void frmHappyOrderWeightPrint_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 + "()", "");
                this.Location = new Point(0, 50);

                InitControls();
                SetDataOnGrid();
            }
            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 frmHappyOrderWeightPrint_FormClosing(object sender, FormClosingEventArgs e)
        {
            vScrollbar.Attach(null);

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

                txtPrtData.Font = new Font(m_cPosStatus.Base.FONT_FIX, txtPrtData.Font.Size, txtPrtData.Font.Style);

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

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

                InitializeGrid();

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

                btnIceCream.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0560);

                btnGridUp.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_GRID_UP_ARROW);
                btnGridUp.ImageAlign = ContentAlignment.MiddleCenter;
                btnGridUp.BorderStyle = BorderStyle.None;

                btnGridDown.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_GRID_DOWN_ARROW);
                btnGridDown.ImageAlign = ContentAlignment.MiddleCenter;
                btnGridDown.BorderStyle = BorderStyle.None;

                InitOrderDetail();

                vScrollbar.Attach(txtPrtData);
            }
            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>
        /// Grid 초기화
        /// </summary>
        private void InitializeGrid()
        {
            try
            {
                //DataGridView 자체의 컬럼 헤더 Visible 여부
                gridHappyOrderList.CsmGridColumnHeadersVisible = true;
                //DataGridView 자체의 컬럼 헤더 높이
                gridHappyOrderList.CsmGridColumnHeadersHeight = 38;
                //DataGridView 컬럼 폰트 설정
                gridHappyOrderList.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 11, FontStyle.Bold);

                //DataGridView 컬럼 수
                gridHappyOrderList.CsmGridColumnCount = 6;
                gridHappyOrderList.CsmGridSetHeaderBackColor(236, 238, 239);                             //그리드 헤더 배경색
                gridHappyOrderList.CsmGridDefaultRowBackColor = Color.FromArgb(255, 255, 255);           //그리드 홀수(Default)행의 배경색 지정
                gridHappyOrderList.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);         //그리드 짝수(Alternate)행의 배경색 지정
                gridHappyOrderList.CsmGridBackGroundColor = Color.FromArgb(251, 253, 255);               //기본 백그라운드 컬러
                gridHappyOrderList.CsmGridHighlightColor = Color.FromArgb(255, 251, 211);                //그리드 선택 백 컬러
                gridHappyOrderList.CsmGridHighlightTextColor = Color.Black;                              //그리드 선택 글자 컬러

                //각 컬럼별 이름 설정
                gridHappyOrderList.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));    // NO
                gridHappyOrderList.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0015));    // 상품명
                gridHappyOrderList.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0436));    // 주문일자
                gridHappyOrderList.CsmGridColumnName(3, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0192));    // 연락처
                gridHappyOrderList.CsmGridColumnName(4, string.Empty);  // Idx
                gridHappyOrderList.CsmGridColumnName(5, string.Empty);  // Blank

                //컬럼별 정렬 기준 설정(0:왼쪽, 1:가운데, 2:오른쪽)
                gridHappyOrderList.CsmGridAlignment(new int[] { 0, 1, 1, 1, 1 });

                //DataGridView 한 화면에 보이는 Row 수
                gridHappyOrderList.CsmGridShowPageRowsCount = 14;
                //DataGridView Row의 헤더 높이
                gridHappyOrderList.CsmGridRowsHeight = 37;
                //컬럼 넓이 지정
                gridHappyOrderList.CsmGridSetColumnWidth(new int[] { 60, 220, 170, 138, 0, 32 });
                //특정컬럼 Visible 여부 설정
                gridHappyOrderList.CsmGridColumnShowHide(4, false);

                m_dtGrid = new DataTable();
                m_dtGrid.Columns.Add(new DataColumn("NO", typeof(string)));
                m_dtGrid.Columns.Add(new DataColumn("ITEM_NM", typeof(string)));
                m_dtGrid.Columns.Add(new DataColumn("ORDER_DT", typeof(string)));
                m_dtGrid.Columns.Add(new DataColumn("TEL", typeof(string)));
                m_dtGrid.Columns.Add(new DataColumn("INDEX", typeof(string)));
                m_dtGrid.Columns.Add(new DataColumn("BLANK", typeof(string)));
                m_dtGrid.Clear();

                m_dtGrid.Clear();
                gridHappyOrderList.CsmGridDataSource = m_dtGrid;
            }
            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 InitOrderDetail()
        {
            try
            {
                txtPrtData.Text = string.Empty;
                if (m_sPrintData != null)
                {
                    m_sPrintData.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 SetDataOnGrid()
        {
            try
            {
                m_dtGrid.Clear();

                Column.TR_HPORD.HPORD_HEADER header = m_cHappyOrderHeader;

                for (int nLoop = 0; nLoop < m_cHappyOrderItem.Count;nLoop++ )
                {
                    DataRow drNew = m_dtGrid.NewRow();
                    
                    Column.TR_HPORD.HPORD_ITEM item = (Column.TR_HPORD.HPORD_ITEM)m_cHappyOrderItem[nLoop];

                    if(item.FlavourFlag == "N")
                    {
                        drNew["NO"] = (m_dtGrid.Rows.Count + 1).ToString();
                        drNew["ITEM_NM"] = item.GoodsName;
                        drNew["ORDER_DT"] = header.OrderDate;
                        drNew["TEL"] = header.ReceiverHp.Substring(header.ReceiverHp.Length - 4, 4);
                        drNew["INDEX"] = nLoop.ToString();
                        drNew["BLANK"] = string.Empty;
                        m_dtGrid.Rows.Add(drNew);
                    }
                }
                
                gridHappyOrderList.CsmGridDataSource = m_dtGrid;
                gridHappyOrderList.CsmGridSelectRow(0);
                //gridHappyOrderList.Refresh();
            }
            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 SetFlavourDataOnTextBox()
        {
            try
            {
                int iSelectedIndex = gridHappyOrderList.CsmGridSelectedRowIndex;
                int iMainItemIndex = int.Parse(m_dtGrid.Rows[iSelectedIndex]["INDEX"].ToString());

                InitOrderDetail();

                AddPrintData(PosConst.PRT_FMT.F103, "[플레이버 내역]");
                AddPrintData(PosConst.PRT_FMT.F100, " ");

                if(m_cHappyOrderItem.Count >= iMainItemIndex + 1 + 1)
                {
                    for(int nLoop = iMainItemIndex + 1;nLoop < m_cHappyOrderItem.Count;nLoop++)
                    {
                        Column.TR_HPORD.HPORD_ITEM item = (Column.TR_HPORD.HPORD_ITEM)m_cHappyOrderItem[nLoop];
                        if (item.FlavourFlag == "Y")
                        {
                            int iIdx = (item.GoodsName).IndexOf(']');
                            AddPrintData(PosConst.PRT_FMT.F101, " >" + item.GoodsName.Substring(iIdx + 1));
                        }
                    }
                }

                for (int nLoop = 0; nLoop < m_sPrintData.Count; nLoop++)
                {
                    txtPrtData.AppendText(m_sPrintData[nLoop].ToString() + "\r\n");
                }
                txtPrtData.Refresh();
            }
            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>
        /// <param name="sPrtHead">출력형태</param>
        /// <param name="sPrtFmt">출력포맷</param>
        /// <param name="sData">Data</param>
        private void AddPrintData(string sPrtFmt, string sData)
        {
            try
            {
                string sPrtData = "";
                if (sPrtFmt == PosConst.PRT_FMT.F100)               // 선귿기
                {
                    for (int i = 1; i <= 42; i++) sPrtData += sData;
                }
                else if (sPrtFmt == PosConst.PRT_FMT.F101)          // 왼쪽정렬
                {
                    sPrtData = sData;
                }
                else if (sPrtFmt == PosConst.PRT_FMT.F102)          // 오른쪽 정렬
                {
                    sPrtData = CmUtil.LPadH(sData, 42);
                }
                else if (sPrtFmt == PosConst.PRT_FMT.F103)          // 중앙정렬
                {
                    if (CmUtil.LenH(sData) <= 42) sPrtData = CmUtil.LPadH("", 21 - (CmUtil.LenH(sData) / 2)) + sData;
                }
                else
                {
                    sPrtData = sData;
                }

                m_sPrintData.Add(sPrtData);
            }
            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 WeightPrintProc()
        {
            int iSelectedIdx = -1;
            ArrayList alHeader = null;

            try
            {
                m_sReceiverHp = m_cHappyOrderHeader.ReceiverHp;
                m_sOrderDT = m_cHappyOrderHeader.OrderDate;

                m_sFlavour1 = string.Empty;
                m_sFlavour2 = string.Empty;
                int iFlavourCnt = 0;

                int iSelectedIndex = gridHappyOrderList.CsmGridSelectedRowIndex;
                int iMainItemindex = int.Parse(m_dtGrid.Rows[iSelectedIndex]["INDEX"].ToString());

                if(m_cHappyOrderItem.Count >= iMainItemindex + 1 + 1)
                {
                    for(int nLoop = iMainItemindex + 1;nLoop < m_cHappyOrderItem.Count;nLoop++)
                    {
                        Column.TR_HPORD.HPORD_ITEM item = (Column.TR_HPORD.HPORD_ITEM)m_cHappyOrderItem[nLoop];

                        if(item.FlavourFlag == "Y")
                        {
                            if (iFlavourCnt == 0)
                            {
                                m_sFlavour1 = item.FlavourName;
                            }
                            else if (iFlavourCnt <= 2)
                            {
                                m_sFlavour1 = m_sFlavour1 + "/" + item.FlavourName;
                            }
                            else if (iFlavourCnt == 3)
                            {
                                m_sFlavour2 = item.FlavourName;
                            }
                            else if (iFlavourCnt >= 4)
                            {
                                m_sFlavour2 = m_sFlavour2 + "/" + item.FlavourName;
                            }
                            iFlavourCnt++;
                        }
                    }
                }

                IMeasuring cMeasuringAgt = (IMeasuring)sManager.InitServiceInstance(ServiceLists.AGENT_MEASURING.DLL, ServiceLists.AGENT_MEASURING.MEASURING_MAIN);
                // 라벨프린터 출력 모드 설정
                cMeasuringAgt.SetPrintMode(PosConst.MEASURING_AGENT_PRINT_MODE.HAPPY_ORDER);
                // 출력용 해피오더 데이터 설정
                cMeasuringAgt.SetHappyOrderData(new string[] { m_sReceiverHp.Substring(m_sReceiverHp.Length - 4), m_sFlavour1, m_sFlavour2, m_sOrderDT });

                WinManager.ConfirmMessage(MessageManager.GetGuideMessage(POS_MESSAGE.GUIDE.MSG_0003), MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0543));

                // 라벨프린터 출력 모드 설정
                cMeasuringAgt.SetPrintMode(PosConst.MEASURING_AGENT_PRINT_MODE.NORMAL);

                //IWirelessScaleUs m_cWirelessScaleUs = (IWirelessScaleUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_WIRELESSSCALE);
                //m_cWirelessScaleUs.OpenDevice(m_cPosStatus.Base.OlePosWirelessScaleSerialPortNumber, m_cPosStatus.Base.OlePosWirelessScaleSerialBaudRate);

                //WinManager.ConfirmMessage(MessageManager.GetGuideMessage(POS_MESSAGE.GUIDE.MSG_0003), MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0543));

                //m_cWirelessScaleUs.CloseDevice();
            }
            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 bool CheckOverWeightValue(int iWeight, ref string sItemNm)
        {
            bool bIsNormal = false;
            sItemNm = string.Empty;
            try
            {
                if (iWeight >= 236 && iWeight <= 335)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0545);
                    bIsNormal = false;
                }
         
                //else if (iWeight >= 336 && iWeight <= 434)
                //{
                //    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0545);
                //    bIsNormal = true;
                //}
                //else if (iWeight >= 435 && iWeight <= 534)
                //{
                //    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0546);
                //    bIsNormal = true;
                //}
                //#10856] (신규) [BR] 저울 중량 라벨프린터 양식 변경
                //스타워즈 파인트 제외
                else if (iWeight >= 336 && iWeight <= 534)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0545);
                    bIsNormal = true;
                }

                else if (iWeight >= 545 && iWeight <= 642)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0547);
                    bIsNormal = false;
                }
                else if (iWeight >= 643 && iWeight <= 742)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0547);
                    bIsNormal = true;
                }
                else if (iWeight >= 889 && iWeight <= 988)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0548);
                    bIsNormal = false;
                }
                else if (iWeight >= 989 && iWeight <= 1088)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0548);
                    bIsNormal = true;
                }
                else if (iWeight >= 1137 && iWeight <= 1236)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0549);
                    bIsNormal = false;
                }
                else if (iWeight >= 1237 && iWeight <= 1536)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0549);
                    bIsNormal = true;
                }
                else if (iWeight >= 1700 && iWeight <= 1999)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0550);
                    bIsNormal = false;
                }
                else if (iWeight >= 2000 && iWeight <= 2300)
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0550);
                    bIsNormal = true;
                }
                else
                {
                    sItemNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0551);
                    bIsNormal = false;
                }
            }
            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);
            }

            return bIsNormal;
        }

        public void OnDeviceEvent(string sDevice, string sData1, string sData2, string sData3)
        {
            try
            {
                switch (sDevice)
                {
                    case PosConst.OPOS_DEVICE.WIRELESSSCALE:
                        this.Invoke(new EventHandler(OnScaleEvent));
                        break;
                }
            }
            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 OnScaleEvent(object source, EventArgs e)
        {
            try
            {
                //ILabelPrinterUs m_cLabelPrinterUs = (ILabelPrinterUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_LABELPRINTER);

                //string sItemNm = string.Empty;
                //if (CheckOverWeightValue(Convert.ToInt32(m_cDevStatus.WirelessScale.Data), ref sItemNm) == true)
                //{
                //    bool bConnection = m_cLabelPrinterUs.OpenDevice(m_cPosStatus.Base.OlePosLabelPrinterSerialPortNumber, (int)m_cPosStatus.Base.OlePosLabelPrinterSerialBaudRate);

                //    if (bConnection == true)
                //    {
                //        m_cLabelPrinterUs.PrintO2OProductInfo(sItemNm,
                //                                              m_sReceiverHp.Substring(m_sReceiverHp.Length - 4),
                //                                              (Convert.ToInt32(m_cDevStatus.WirelessScale.Data)).ToString() + "g",
                //                                              m_sFlavour1,
                //                                              m_sFlavour2,
                //                                              (PosMstManager.GetMstStore())[PosMst.MST_STORE.DATA.STORNM].ToString(),
                //                                              m_sOrderDT,
                //                                              DateTime.Now.ToString("yyyy-MM-dd HH시mm분"));
                //    }

                //    m_cLabelPrinterUs.CloseDevice();
                //}

            }
            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 btnGrid_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                ((Cosmos.UI.CsmButton)sender).BorderStyle = BorderStyle.FixedSingle;
            }
            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 btnGrid_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                ((Cosmos.UI.CsmButton)sender).BorderStyle = BorderStyle.None;
            }
            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)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);

            }
        }

        private void gridHappyOrderList_GridClickEvent(object sender, string rowIndex)
        {
            try
            {
                SetFlavourDataOnTextBox();
            }
            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 btnIceCream_Click(object sender, EventArgs e)
        {
            try
            {
                if(m_dtGrid == null || m_dtGrid.Rows.Count == 0)
                {
                    return;
                }

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