#region Copyright © 2015 CLIPSOFT Co.,Ltd. All Rights Reserved.
//
// All rights are reserved. Reproduction or transmission in whole or in part, 
// in any form or by any means, electronic, mechanical or otherwise, is 
// prohibited without the prior written consent of the copyright owner.
//
// Filename:ConsentSelectTabPageAll.cs
//
#endregion
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Configuration;
using CLIP.eForm.Consent.UI.ConsentSvcRef;

namespace CLIP.eForm.Consent.UI {
  /// <summary>
  /// 동의서 미작성 탭 클래스
  /// </summary>
  /// <remarks>
  /// <p>[설계자]</p>
  /// <p>  클립소프트 연구소 홍지철 (jchong@clipsoft.co.kr)</p>
  /// <p>[원본 작성자]</p>
  /// <p>  클립소프트 기술부 4팀 이창훈 (chlee@clipsoft.co.kr)</p>
  /// <p>[수정 작성자]</p>
  /// <p>  클립소프트 기술부 이인희</p>
  /// <p>----------------------------------------------------------------------------------------</p>
  /// <p>[HISTORY]</p>
  /// <p> 2016-07-01 : 최초작성</p>
  /// <p>----------------------------------------------------------------------------------------</p>
  /// </remarks>  
  public partial class ConsentSelectTabPageUnfinished : UserControl {
    private ConsentSvcRef.ConsentSvcSoapClient consentWebService = null;
    private IConsentMain consentMain = null;
    private ConsentCommandCtrl commandControl = null;

    public ConsentSelectTabPageUnfinished() {
      InitializeComponent();
    }

    private void ConsentSelectTabPageUnfinished_Load(object sender, EventArgs e) {
      if(this.DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime) {
        return;
      }

      consentMain = ConsentMainControl.GetConsentMainInterface(this);
      commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
      consentWebService = WebMethodCommon.GetConsentWebService(consentMain.PluginExecuteInfo["consentSvcUrl"]);

      InitDataGrid();
    }

    public void SelectAllUnfinishedConsents(int consentMstRid) {
      InitDataGrid();
      BindDataGridRows(consentMstRid);
    }

    /// <summary>
    /// 그리드 초기화
    /// </summary>
    private void InitDataGrid() {

      this.dataGridViewConsentSelectResult.DataSource = null;
      this.dataGridViewConsentSelectResult.Columns.Clear();

      if(rdoUser.Checked) {

        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "등록번호", "PatientCode", true, 60, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "성명", "PatientName", true, 60, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료형태", "VisitTypeName", true, 40, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료/\n입원일", "ClnDate", true, 80, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "동의서명", "ConsentName", true, 180);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "상태", "ConsentStateDisp", true, 60, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "작성자", "CreateUserName", true, 70, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "작성일시", "CreateDateTime", true, 120, DataGridViewContentAlignment.MiddleCenter);

      }
      else {

        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "동의서명", "ConsentName", true, 180);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "상태", "ConsentStateDisp", true, 60, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "작성자", "CreateUserName", true, 70, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "작성일시", "CreateDateTime", true, 120, DataGridViewContentAlignment.MiddleCenter);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "등록번호", "PatientCode", false);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "성명", "PatientName", false);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료형태", "VisitTypeName", false);
        CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료/\n입원일", "ClnDate", false);
      }

      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "기관코드", "HosType", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "생성번호", "Cretno", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료형태코드", "VisitType", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료과코드", "ClnDeptCd", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료과", "ClnDeptNm", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "진료의", "Doctor", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "병동", "Ward", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "병실", "RoomCd", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "처방번호", "OrderNo", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "처방코드", "OrderCd", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "처방", "OrderNm", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "수술진단명", "OpDiagName", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "수술명", "OpName", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "수술예약번호", "OpRsrvNo", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "동의서고유ID", "FormGuid", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "동의서ID", "FormRid", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "동의서코드", "FormCd", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "동의서생성ID", "ConsentMstRid", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "상태코드", "ConsentState", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "OCR태그", "OcrNumber", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "작성자ID", "CreateUserId", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "코사인의사ID", "CosignDcId", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "코사인의사", "CosignDcName", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "출력매수", "PrntCnt", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "OCR생성여부", "OcrTagYN", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "출력제목", "FormPrintName", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "작성자변경여부", "UserDrFlag", false);
      CommonUtil.AddNewColumnToDataGridView(this.dataGridViewConsentSelectResult, "출력전용", "PrntOnly", false);
    }

    /// <summary>
    /// 미작성, 임시저장 동의서 조회
    /// </summary>
    /// <param name="consentMstRid">The consent MST rid.</param>
    public void BindDataGridRows(int consentMstRid) {
      if(this.consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
      if(this.commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
      if(this.consentWebService == null) this.consentWebService = WebMethodCommon.GetConsentWebService(consentMain.PluginExecuteInfo["consentSvcUrl"]);

      try {

        string patientCode = string.Empty;
        if(commandControl.CurrentTargetPatient != null && !string.IsNullOrEmpty(commandControl.CurrentTargetPatient.PatientCode)) {
          patientCode = commandControl.CurrentTargetPatient.PatientCode;
        }

        string userId = string.Empty;
        if(rdoUser.Checked) {
          userId = consentMain.ConsentExecuteInfo["loginUserNo"];
        }

        if(!patientCode.Equals(string.Empty) || !userId.Equals(string.Empty)) {

          string sDate = consentMain.PluginExecuteInfo["ConsentSearchStartDate"].Replace("-", "");
          string eDate = DateTime.Now.ToShortDateString().Replace("-", "");
          // 검색할 조건을 미작성, 임시저장, 출력
          string consentState = "'UNFINISHED','TEMP','PAPER_OUT'";
          // 동의서 조회
          // TODO
          //ConsentFormListVO[] resultData = consentWebService.GetConsentList(patientCode
          //                                                        , sDate
          //                                                        , eDate
          //                                                        , consentState
          //                                                        , string.Empty
          //                                                        , consentMain.ConsentExecuteInfo["dutinstcd"]
          //                                                        , userId);

          /*if (resultData == null) */
          {
            return;
          }

          // 진료일 표시 형식 변경
          //foreach(ConsentVO v in resultData) {
          //    if (v.ClnDate.Length == 8) {
          //        v.ClnDate = v.ClnDate.Substring(0, 4) + "-" + v.ClnDate.Substring(4, 2) + "-" + v.ClnDate.Substring(6, 2);
          //    }
          //}

          //this.dataGridViewConsentSelectResult.DataSource = new SortableBindingList<ConsentVO>(resultData);

          // 목록 조회 시 자동 선택 기능 제외
          consentMain.ClearPreviewConsent(true);
          /*
          //초기 전달받은 startFormCd 값이 있는 경우, 폼을 보여준다.
          if (!string.IsNullOrEmpty(consentMain.ConsentExecuteInfo["startFormCd"])) {
              for (int i = 0; i < resultData.Length; i++) {
                  if (((ConsentVO)resultData[i]).FormCd == consentMain.ConsentExecuteInfo["startFormCd"].ToString()) {
                      ConsentVO vo = GetCurrentConsentVO(i);

                      if (vo != null) {
                          ExecutePreviewWithSelectedConsent(vo);
                          RunConsentDualView();
                      }
                      break;
                  }
              }
          }
          // 조회할 MST_RID 가 있을 경우
          else if (consentMstRid > 0) {
              for (int i = 0; i < resultData.Length; i++) {
                  if (((ConsentVO)resultData[i]).ConsentMstRid == consentMstRid) {
                      ConsentVO vo = GetCurrentConsentVO(i);

                      if (vo != null) {
                          ExecutePreviewWithSelectedConsent(vo);
                          RunConsentDualView();
                      }
                      break;
                  }
              }
          }
          // 조회할 MST_RID 가 없을 경우 0번째 동의서를 미리보기 한다
          else {
              ConsentVO vo = GetCurrentConsentVO(0);

              if (vo != null) {
                  ExecutePreviewWithSelectedConsent(vo);
              }
          }
          */
        }
      }
      catch(Exception ex) {
        throw ex;
      }
    }

    #region 동의서 미리보기
    //선택된 Row의 ConsentVO 객체를 반환한다.
    private ConsentVO GetCurrentConsentVO(int rowIndex) {
      ConsentVO vo = null;

      if(rowIndex < 0) {
        return vo;
      }

      if(dataGridViewConsentSelectResult != null && dataGridViewConsentSelectResult.Rows.Count > 0) {
        this.dataGridViewConsentSelectResult.Rows[rowIndex].Selected = true;
        //this.dataGridViewConsentSelectResult.CurrentCell = this.dataGridViewConsentSelectResult.Rows[rowIndex].Cells[0];

        vo = this.dataGridViewConsentSelectResult.Rows[rowIndex].DataBoundItem as ConsentVO;
      }

      return vo;
    }

    /// <summary>
    /// 선택된 ConsentVO 객체를 미리보기 실행한다.
    /// </summary>
    /// <param name="vo">The vo.</param>
    private void ExecutePreviewWithSelectedConsent(ConsentVO vo) {
      if(consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
      if(commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;

      Cursor currentCursor = this.Cursor;
      this.Cursor = Cursors.WaitCursor;

      if(rdoUser.Checked) {

        consentMain.ConsentExecuteInfo["patientNo"] = vo.PatientCode;
        consentMain.ConsentExecuteInfo["clnDate"] = vo.ClnDate.Replace("-", "");
        consentMain.ConsentExecuteInfo["visitType"] = vo.VisitType;
        consentMain.ConsentExecuteInfo["clnDept"] = vo.ClnDeptCd;
        consentMain.ConsentExecuteInfo["cretno"] = vo.Cretno.ToString();
        consentMain.ConsentExecuteInfo["opRsrvNo"] = vo.OpRsrvNo;

        consentMain.SetPatientInfo();
      }

      commandControl.CurrentPreviewConsent = new PreviewConsent {
        formRid = vo.FormRid.ToString(),
        formGuid = vo.FormGuid,
        formCd = vo.FormCd.ToString(),
        FormName = vo.ConsentName,
        formPrintName = vo.FormPrintName,
        prntCnt = vo.PrntCnt,
        consentMstRid = vo.ConsentMstRid.ToString(),
        consentStateEngnm = vo.ConsentState,
        orderNo = vo.OrderNo,
        ocrCode = vo.OcrNumber,
        inputId = vo.CreateUserId,
        inputNm = vo.CreateUserName,
        ReissueConsentMstRid = 0,
        RewriteConsentMstRid = 0,
        ordType = vo.VisitType,
        ocrtagPrntyn = vo.OcrTagYN,
        userDrFlag = vo.UserDrFlag,
        printOnly = vo.PrntOnly,
        opDiagName = vo.OpDiagName,
        opName = vo.OpName
      };

      consentMain.PatientInfoCtrl.SetConsentDocumentName(vo.ConsentName);

      switch(vo.ConsentState.ToUpper()) {
        // 임시저장
        case "TEMP":
          commandControl.ShowTempSaveConsent(consentMain);
          break;
        // 출력, 미작성
        case "PAPER_OUT":
        case "UNFINISHED":
          //CheckClnDateInfo(vo);
          commandControl.PreviewConsent(consentMain);
          break;
        default:
          break;
      }

      //if (vo.ConsentState.ToUpper().Equals("TEMP")) {

      //    commandControl.ShowTempSaveConsent(consentMain);

      //} else if (vo.ConsentState.ToUpper().Equals("PAPER_OUT")) {
      //    CheckClnDateInfo(vo);
      //    commandControl.PreviewConsent(consentMain);

      //} else if (vo.ConsentState.ToUpper().Equals("UNFINISHED")) {
      //    CheckClnDateInfo(vo);
      //    commandControl.PreviewConsent(consentMain);
      //}

      if (commandControl.CurrentTargetPatient.VisitType.Equals("O"))
      {
        commandControl.setCompleteSaveButton(true);
      }
      else
      {
        if (ConsentMainControl.SETTING_DATA["ELECTR_CMP"].Equals("Y") && commandControl.CurrentEndUser.JobKindCd.Substring(0, 2).Equals("03"))
        {
          commandControl.setCompleteSaveButton(true);
        }
        else
        {
          commandControl.setCompleteSaveButton(false);
        }
      }

      this.Cursor = currentCursor;
    }

    /// <summary>
    /// 동의서의 처방일자와 생성번호 등의 정보가 현재 정보와 일치하지 않은 경우
    /// 미리보기를 위해서 데이터를 재조회한다.
    /// </summary>
    /// <param name="vo">조회할 ConsentVO 인스턴스</param>
    private void CheckClnDateInfo(ConsentVO vo) {
      if(consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
      if(commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;
      if(commandControl.CurrentTargetPatient == null) return;

      bool bSame = true;

      if(!string.IsNullOrEmpty(vo.ClnDate) && !vo.ClnDate.Replace("-", "").Equals(commandControl.CurrentTargetPatient.clnDate.Replace("-", "")))
        bSame = false;

      if(!vo.Cretno.ToString().Equals(commandControl.CurrentTargetPatient.cretno))
        bSame = false;

      if(!string.IsNullOrEmpty(vo.ClnDeptCd) && !vo.ClnDeptCd.Equals(commandControl.CurrentTargetPatient.clnDeptCode))
        bSame = false;

      if(!string.IsNullOrEmpty(vo.VisitType) && !vo.VisitType.Equals(commandControl.CurrentTargetPatient.VisitType))
        bSame = false;

      if(bSame == false) {
        //동의서 맵핑 정보를 상단의 선택된 진료일과 작성자 정보로 한다.
        consentMain.PatientInfoCtrl.SetPatientByConsentInfo(vo.ClnDate.Replace("-", ""),
                                                            vo.VisitType,
                                                            vo.ClnDeptCd,
                                                            vo.Cretno.ToString());
      }
    }
    #endregion

    #region 그리드 이벤트        
    /// <summary>
    /// dataGridViewConsentSelectResult 그리드 컨트롤 셀 더블클릭 이벤트
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="DataGridViewCellEventArgs"/> instance containing the event data.</param>
    private void dataGridViewConsentSelectResult_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {

      if(commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;

      // dbs227, 셀 클릭 시 더블클릭 인식되어 작동되는 경우 오류
      if(e.RowIndex < 0) {
        return;
      }
      ConsentVO vo = GetCurrentConsentVO(e.RowIndex);

      // dbs227, 출력된 동의서는 미리보기를 하지 않는다
      if(vo.ConsentState.Equals("PAPER_OUT")) {
        MessageBox.Show(String.Format(Properties.Resources.msg_printed_consent),
            String.Format(Properties.Resources.title_printed_consent));
        return;
      }

      if(vo != null) {
        // 선택된 동의서가 현재 보여지고 있는 동의서와 다른 경우, 임시 저장 여부 확인
        if(!consentMain.ConsentExecuteInfo["readOnly"].Equals("Y") &&
            !string.IsNullOrEmpty(commandControl.CurrentTargetPatient.PatientCode) &&
            commandControl.CurrentPreviewConsent != null && !commandControl.CurrentPreviewConsent.formRid.Equals(vo.FormRid.ToString()) &&
            (commandControl.CurrentPreviewConsent.consentState == string.Empty || commandControl.CurrentPreviewConsent.consentState == "TEMP")) {
          // dbs227, 임시저장 팝업 사용 안함
          //DialogResult result = MessageBox.Show(string.Format(Properties.Resources.msg_confirm_tempsave)
          //                            , string.Format(Properties.Resources.msg_caption_confirm),
          //                            MessageBoxButtons.YesNo, MessageBoxIcon.Information);

          //if (result == DialogResult.Yes) {
          //    // 임시저장 실행
          //    consentMain.TempSave();
          //}
        }

        consentMain.preParamClean();

        ExecutePreviewWithSelectedConsent(vo);
        RunConsentDualView();
      }
    }

    /// <summary>
    /// dataGridViewConsentSelectResult 그리드 컨트롤 마우스 우클릭 이벤트
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="DataGridViewCellContextMenuStripNeededEventArgs"/> instance containing the event data.</param>
    private void dataGridViewConsentSelectResult_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e) {
      // read only 로 실행 한 경우 우클릭 이벤트를 실행하지 않는다
      if(consentMain.ConsentExecuteInfo["readOnly"].Equals("Y")) {
        return;
      }

      if(e.RowIndex >= 0 && this.dataGridViewConsentSelectResult.Rows[e.RowIndex].Selected == true) {

        ConsentVO vo = GetCurrentConsentVO(e.RowIndex);

        if(commandControl.CurrentPreviewConsent != null && commandControl.CurrentEndUser.UserNo.Equals(vo.CreateUserId)) {
          // 임시저장의 경우 삭제의 메뉴와 이벤트를 할당한다
          if(vo.ConsentState.Equals("TEMP") || vo.ConsentState.Equals("ELECTR_CMP")) {
            ContextMenuStrip strip = new ContextMenuStrip();

            ToolStripMenuItem deleteRecord = new ToolStripMenuItem();
            deleteRecord.Text = "삭제";
            strip.Items.Add(deleteRecord);
            deleteRecord.Click += new EventHandler(deleteRecord_Click);

            e.ContextMenuStrip = strip;
          }
        }
      }
    }

    private void RunConsentDualView() {
      if(this.consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
      if(this.commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;

      commandControl.RunConsentDualView();
    }

    /// <summary>
    /// dataGridViewConsentSelectResult 그리드 컨트롤의 data binding 이 끝난 후 이벤트
    /// 미작성인 경우, 배경색과 글씨색을 RED 로 변경.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="DataGridViewBindingCompleteEventArgs"/> instance containing the event data.</param>
    private void dataGridViewConsentSelectResult_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) {
      foreach(DataGridViewRow row in dataGridViewConsentSelectResult.Rows) {
        if(!string.IsNullOrEmpty(row.Cells["consentStateEngnm"].Value.ToString())) {
          if(row.Cells["consentStateEngnm"].Value.ToString().ToUpper() == "UNFINISHED") {
            row.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
          }
        }
      }
    }

    /// <summary>
    /// 동의서 삭제
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    private void deleteRecord_Click(object sender, EventArgs e) {
      if(consentMain == null) consentMain = ConsentMainControl.GetConsentMainInterface(this);
      if(commandControl == null) commandControl = consentMain.ConsentCommandCtrl as ConsentCommandCtrl;

      bool bDel = true;
      ReasonForUseN reasonForUseN = new ReasonForUseN(bDel);
      if(reasonForUseN.ShowDialog() == DialogResult.OK) {
        string reason = reasonForUseN.GetReasonForUseN();
        reasonForUseN.Close();

        if(this.dataGridViewConsentSelectResult.SelectedRows.Count != 0) {
          Cursor currentCursor = this.Cursor;
          try {
            this.Cursor = Cursors.WaitCursor;

            ConsentVO vo = GetCurrentConsentVO(this.dataGridViewConsentSelectResult.SelectedRows[0].Index);
            commandControl.CurrentPreviewConsent.ReissueConsentMstRid = vo.ConsentMstRid;
            //consentMain.ConsentCommandCtrl.DeleteRecordOfDeleteConsent(reason);

            consentMain.ConsentListCtrl.InquiryConsentData(-1);
          }
          catch(Exception ex) {
            throw ex;
          }
          finally {
            this.Cursor = currentCursor;
          }
          MessageBox.Show(string.Format(Properties.Resources.msg_consent_record_deleted)
              , string.Format(Properties.Resources.msg_caption_confirm), MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
      }
    }
    #endregion

    private void btnSearch_Click(object sender, EventArgs e) {
      btnSearch.Enabled = false;
      Application.DoEvents();

      InitDataGrid();

      BindDataGridRows(0);

      btnSearch.Enabled = true;
    }
  }
}
