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.UserFrame;
using Cosmos.BaseFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using Cosmos.UI;

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

        private ITableUs m_cTableSvr = null;                                        //테이블 서비스 관리
        private IMasterUs m_cMstService = null;                                     // 마스터 인터페이스

        private List<CsmPosEditBox> m_EditBoxList = new List<CsmPosEditBox>();		// 입력컨트롤 목록

        /// <summary>
        /// 리스트 데이터
        /// </summary>
        private DataTable m_dtGridList;

        /// <summary>
        /// 메모구분
        /// (PosConst.KPS_ORD_MSG_ID, 0:거래중지, 1:상품메모, 2:좌석메모, 3:테이블합석, 4:테이블이동, 5:상품이동, 9:FireKey)
        /// </summary>
        public string MsgId { get; set; }
        /// <summary>
        /// 상품등록행
        /// </summary>
        public int ItemRow { get; set; }
        /// <summary>
        /// 층코드 
        /// </summary>
        public string FloorCd { get; set; }
        /// <summary>
        /// 테이블번호
        /// </summary>
        public string TableNo { get; set; }
        /// <summary>
        /// 테이블 명
        /// </summary>
        public string TableNm { get; set; }

        public frmKtchMsg()
        {
            InitializeComponent();

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

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

            m_cTableSvr = (ITableUs)sManager.InitServiceInstance(ServiceLists.BSV_TABLE.DLL, ServiceLists.BSV_TABLE.TABLE_SERVICE);
            m_cMstService = (IMasterUs)sManager.InitServiceInstance(ServiceLists.ASV_MASTER.DLL, ServiceLists.ASV_MASTER.POS_MASTER);

            this.MsgId = string.Empty;
            this.ItemRow = -1;
            this.FloorCd = string.Empty;
            this.TableNo = string.Empty;
            this.TableNm = string.Empty;

            // 입력컨트롤 목록 추가 
            m_EditBoxList.Add(this.tbKtchMsg1);
            m_EditBoxList.Add(this.tbKtchMsg2);
            m_EditBoxList.Add(this.tbKtchMsg3);
        }

        private void Form_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 + "()", "");

                PosOLEDevice.SetEventHandle(null);

                this.InitControls();
                if (this.MsgId == PosConst.KPS_ORD_MSG_ID.FIRE_KEY) return;

                this.InitializeGrid();
                this.DisplayGrid();
            }
            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 Form_Closing(object sender, FormClosingEventArgs e)
        {
            try
            {
                PosOLEDevice.SetEventHandle(null);

                this.MsgId = string.Empty;
                this.ItemRow = -1;
                this.FloorCd = string.Empty;
                this.TableNo = string.Empty;
                this.TableNm = string.Empty;

                UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                          System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                          System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
            }
            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>
        private void InitControls()
        {
            try
            {
                this.picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);
                this.picBack.Location = new Point(0, 0);
                this.picBack.SendToBack();
                this.Size = this.picBack.Size = new Size(800, 600);

                FormManager.MovePopUpForm(this, false, m_cPosStatus.Sale.ScreenSizeUser);
                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);

                //테마색상 적용!
                btnEnter.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);
                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0009);
                btnSave.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0225);
                btnDel.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0021);

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

                btnUp.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP1_BASIC);
                btnDn.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN1_BASIC);
                if (btnUp.Image != null) btnUp.Text = string.Empty;
                if (btnDn.Image != null) btnDn.Text = string.Empty;

                if (MsgId == PosConst.KPS_ORD_MSG_ID.ITEM_MEMO)     
                {
                    // 1:상품메모
                    lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0180);
                    lblTarget1.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0178);
                    lblTarget2.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0015);

                    ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                    Column.TR_PLU.DATA cSaleItem = (Column.TR_PLU.DATA)alSaleItem[ItemRow];
                    lblFloorNm.Text = cSaleItem.ITEM_PLU_CD;
                    lblTableNo.Text = cSaleItem.ITEM_NAME;

                    lblMsg.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0177);
                }
                else if (MsgId == PosConst.KPS_ORD_MSG_ID.SEAT_MEMO) 
                {
                    // 2:좌석메모
                    lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0174);
                    lblTarget1.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0175);
                    lblTarget2.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0176);

                    lblFloorNm.Text = m_cTrnStatus.Head.FloorNm;
                    lblTableNo.Text = this.TableNm;

                    lblMsg.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0177);
                }
                else                    
                {
                    // 9:FIRE KEY
                    ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                    Column.TR_PLU.DATA cSaleItem = (Column.TR_PLU.DATA)alSaleItem[ItemRow];
                    //var msg = "  " + MessageManager.GetPrintMessage(POS_MESSAGE.PRINT.MSG_0103) + ":" + cSaleItem.SALE_QTY.ToString().PadLeft(5) + "FIRE".PadLeft(25);
                    var msg = cSaleItem.SALE_QTY.ToString();
                    var sReturn = m_cTableSvr.UpdateKtchOrderMessage(MsgId, ItemRow, msg, string.Empty, string.Empty);
                    if (sReturn != UserCom.RST_OK)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0157);
                    }

                    this.DialogResult = sReturn != UserCom.RST_OK ? DialogResult.Cancel : DialogResult.OK;
                    return;
                }
                tbKtchMsg1.Text = string.Empty;
                tbKtchMsg2.Text = string.Empty;
                tbKtchMsg3.Text = string.Empty;

                tbKtchMsg1.Select();
            }
            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 InitializeGrid()
        {
            try
            {
                gridList.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 12, gridList.CsmGridColumnHeadersFont.Style);

                //DataGridView 자체의 컬럼 헤더 Visible 여부
                gridList.CsmGridColumnHeadersVisible = false;
                gridList.CsmGridRowsHeight = 60;

                //그리드의 컬럼 수
                gridList.CsmGridColumnCount = 2;
                //그리드의 컬럼 헤더 높이 
                gridList.CsmGridRowsHeight = 60;
                //그리드의 한 화면에 보이는 로우수
                gridList.CsmGridShowPageRowsCount = 5;

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

                //각 컬럼별 이름 지정
                gridList.CsmGridColumnName(0, "");
                gridList.CsmGridColumnName(1, "");

                //컬럼넓이 지정(406)
                gridList.CsmGridSetColumnWidth(new int[] {  721, 0 });

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

                m_dtGridList = new DataTable("GRID_LIST");
                m_dtGridList.Columns.Add(new DataColumn("REASON_NM", typeof(string)));
                m_dtGridList.Columns.Add(new DataColumn("REASON_CD", typeof(string)));
                m_dtGridList.Clear();
            }
            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 DisplayGrid(bool isLastSelect = false)
        {
            try
            {
                m_dtGridList.Clear();
                gridList.SuspendLayout();

                string fmt = "SELECT * FROM POSMST..MST_POS_LOCAL WITH (NOLOCK) "
                           + " WHERE CMP_CD = '{0}' AND STOR_CD = '{1}' AND GRP_CD = '{2}' AND USE_YN = '{3}' "
                           + " ORDER BY ENTRY_NM ";
                string sql = string.Format(fmt, m_cPosStatus.Base.CmpCd
                                              , m_cPosStatus.Base.StoreNo
                                              , PosConst.COMMON_CODE_GROUP.Z0020
                                              , PosConst.MST_USE_YN.YES);
                DataTable dtData = m_cMstService.Select(new string[] { sql });
                if (dtData != null && dtData.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtData.Rows)
                    {
                        DataRow drNewRow = m_dtGridList.NewRow();
                        drNewRow["REASON_NM"] = CmUtil.GetDataRowStr(dr, "ENTRY_NM");
                        drNewRow["REASON_CD"] = CmUtil.GetDataRowStr(dr, "ENTRY_CD");
                        m_dtGridList.Rows.Add(drNewRow);
                    }
                }

                gridList.CsmGridDataSource = m_dtGridList;
                //gridList.CsmGridSelectRow(0);
                gridList.ResumeLayout();
            }
            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 btnExit_Click(object sender, EventArgs e)
        {
            this.EditBox_KeyDownEvent(null, PosKey.MENU_KEY.ESC_PREVIOUS);
        }

        private void Button_Click(object sender, EventArgs e)
        {
            if (sender == btnEnter)
            {
                this.EditBox_KeyDownEvent(tbKtchMsg3, PosKey.MENU_KEY.ENTER);
            }
            else if (sender == btnSave)
            {
                SaveText();
            }
            else if (sender == btnDel)
            {
                DeleteText();
            }
            else if (sender == btnUp)
            {
                gridList.CsmGridScroll("UP");
                tbKtchMsg1.Focus();
            }
            else if (sender == btnDn)
            {
                gridList.CsmGridScroll("DOWN");
                tbKtchMsg1.Focus();
            }
        }

        private void EditBox_KeyDownEvent(object sender, string sFuncValue)
        {
            try
            {
                int index = m_EditBoxList.IndexOf((CsmPosEditBox)sender);

                switch (sFuncValue)
                {
                    case PosKey.MENU_KEY.ENTER:
                        if (CheckInputValue(index) == false) return;
                        if (index >= m_EditBoxList.Count - 1)
                        {
                            // 수동출력시 장치코드 선택 => 후불 좌석메모 일때 만, 장치선택
                            if (MsgId == PosConst.KPS_ORD_MSG_ID.SEAT_MEMO && PosMstManager.GetPosOption(POS_OPTION.OPT425) == "1")
                            {
                                WinBasic.ShowForm(new string[] { FormManager.FORM_MENUAL_ORDER_KPS });
                            }

                            // 메모등록
                            string ret = m_cTableSvr.UpdateKtchOrderMessage(MsgId, ItemRow, tbKtchMsg1.Value.Trim(), tbKtchMsg2.Value.Trim(), tbKtchMsg3.Value.Trim());
                            if (ret != UserCom.RST_OK)
                            {
                                WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0157);
                                return;
                            }

                            // 상품메모 메모리 저장 
                            if (this.MsgId == PosConst.KPS_ORD_MSG_ID.ITEM_MEMO)
                            {
                                ArrayList alPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                                Column.TR_PLU.DATA cItem = (Column.TR_PLU.DATA)alPluItem[ItemRow];
                                cItem.ITEM_MEMO_1 = tbKtchMsg1.Value.Trim();
                                cItem.ITEM_MEMO_2 = tbKtchMsg2.Value.Trim();
                                cItem.ITEM_MEMO_3 = tbKtchMsg3.Value.Trim();
                            }

                            this.DialogResult = System.Windows.Forms.DialogResult.OK;
                            this.Close();
                            return;
                        }
                        if (index < m_EditBoxList.Count - 1)
                        {
                            m_EditBoxList[index + 1].Select();
                            m_EditBoxList[index + 1].SelectText();
                        }
                        break;
                    case PosKey.MENU_KEY.ESC_PREVIOUS:
                        this.DialogResult = DialogResult.Cancel;
                        this.Close();
                        break;
                }
            }
            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="index"></param>
        /// <returns></returns>
        private bool CheckInputValue(int index)
        {
            try
            {
                string value = string.Empty;

                if (index >= 0)
                {
                    value = tbKtchMsg1.Value.Trim();

                    //if (CmUtil.LenH(value) > 40)
                    if (value.Length > 40)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0405);
                        tbKtchMsg1.SelectText();
                        tbKtchMsg1.Select();
                        return false;
                    }
                }
                if (index >= 1)
                {
                    value = tbKtchMsg2.Value.Trim();

                    //if (CmUtil.LenH(value) > 40)
                    if (value.Length > 40)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0405);
                        tbKtchMsg2.SelectText();
                        tbKtchMsg2.Select();
                        return false;
                    }
                }
                if (index >= 2)
                {
                    value = tbKtchMsg3.Value.Trim();

                    //if (CmUtil.LenH(value) > 40)
                    if (value.Length > 40)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0405);
                        tbKtchMsg3.SelectText();
                        tbKtchMsg3.Select();
                        return false;
                    }
                    if (tbKtchMsg1.Text.Trim().Length == 0 && tbKtchMsg2.Text.Trim().Length == 0 && tbKtchMsg3.Text.Trim().Length == 0)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0129);
                        tbKtchMsg1.SelectText();
                        tbKtchMsg1.Select();
                        return false;
                    }
                }

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

        /// <summary>
        /// 메모 상용구 저장
        /// </summary>
        /// <returns></returns>
        private bool SaveText()
        {
            try
            {
                if (CheckInputValue(2) == false) return false; 

                List<string> memoList = new List<string>();
                if (string.IsNullOrWhiteSpace(tbKtchMsg1.Text) == false) memoList.Add(tbKtchMsg1.Text.Trim());
                if (string.IsNullOrWhiteSpace(tbKtchMsg2.Text) == false) memoList.Add(tbKtchMsg2.Text.Trim());
                if (string.IsNullOrWhiteSpace(tbKtchMsg3.Text) == false) memoList.Add(tbKtchMsg3.Text.Trim());
                if (memoList.Count == 0) return false;

                string memo = string.Join(Environment.NewLine,  memoList.ToArray());

                int maxEntryCode = 1;
                for (var i = 0; i < gridList.CsmGridRowsCount; i++)
                {
                    int code = CmUtil.IntParse(gridList.CsmGridGetCell(i, 1));
                    if (maxEntryCode < code) maxEntryCode = code + 1;

                    string name = gridList.CsmGridGetCell(i, 1);
                    if (memo == name) return false; 
                }

                string fmt = "INSERT INTO POSMST..MST_POS_LOCAL (CMP_CD, STOR_CD, GRP_CD, ENTRY_NM, DISP_SEQ, USE_YN, UPD_DT, REG_DT, ENTRY_CD) \n"
                           + " SELECT '{0}', '{1}', '{2}', '{3}', 0, '1', '{4}', '{4}' \n"
                           + "      , ISNULL(MAX(CONVERT(int, ENTRY_CD)), 0) + 1 \n"
                           + "   FROM POSMST..MST_POS_LOCAL \n"
                           + "  WHERE CMP_CD = '{0}' AND STOR_CD = '{1}' AND GRP_CD = '{2}' ";
                string sql = string.Format(fmt, m_cPosStatus.Base.CmpCd
                                              , m_cPosStatus.Base.StoreNo
                                              , PosConst.COMMON_CODE_GROUP.Z0020
                                              , ConvertDBStr(memo)
                                              , DateTime.Now.ToString("yyyyMMddHHmmss")
                                              );
                if (m_cMstService.Update(new string[] { sql }) != UserCom.OK)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0417);
                    return false; 
                }

                DisplayGrid();

                for (var i = gridList.CsmGridRowsCount - 1; i >= 0; i--)
                {
                    var temp = gridList.CsmGridGetCell(i, 0);
                    if (temp.Equals(memo))
                    {
                        gridList.CsmGridSelectRow(i);
                        break; 
                    }
                }
                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;
            }
        }

        /// <summary>
        /// 메모 상용구 삭제
        /// </summary>
        /// <returns></returns>
        private bool DeleteText()
        {
            try
            {
                // 반품 사유
                if (gridList.CsmGridRowsCount == 0) return false;
                int row = gridList.CsmGridSelectedRowIndex;
                if (row < 0) return false;
                if (row >= gridList.CsmGridRowsCount) return false; 

                string entryCode = gridList.CsmGridGetCell(row, 1);
                string fmt = "DELETE POSMST..MST_POS_LOCAL WHERE CMP_CD = '{0}' AND STOR_CD = '{1}' AND GRP_CD = '{2}' AND ENTRY_CD = '{3}' ";
                string sql = string.Format(fmt, m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, PosConst.COMMON_CODE_GROUP.Z0020, entryCode);

                if (m_cMstService.Update(new string[] { sql }) != UserCom.OK)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0417);
                    return false; 
                }
                //DisplayGrid();
                m_dtGridList.Rows[row].Delete();

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

        private void gridList_GridClickEvent(object sender, string rowIndex)
        {
            try
            {
                if (gridList.CsmGridRowsCount == 0) return;

                int row = gridList.CsmGridSelectedRowIndex;
                if (row < 0) return;

                string text = gridList.CsmGridGetCell(row, 0);
                string[] memo = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                if (memo.Length == 0) return;

                for (var i = 0; i < memo.Length; i++)
                {
                    switch (i)
                    {
                        case 0: tbKtchMsg1.Value = memo[0]; break;
                        case 1: tbKtchMsg2.Value = memo[1]; break;
                        case 2: tbKtchMsg3.Value = memo[2]; break; 

                    }
                }
                tbKtchMsg1.Focus();
            }
            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 string ConvertDBStr(string str)
        {
            return str.Replace("'", "''");
        }
    }
}
