簡體   English   中英

為什么當我單擊消息框確定按鈕時關閉代碼不執行?

[英]Why when I click messagebox OK button the close code not execute?

我有 windows 表格申請,我想防止為同一患者重復訂單

我檢查病人今天是否有訂單,如果我嘗試下一個訂單,它會顯示消息

患者今天有訂單,然后當單擊確定按鈕時,我需要關閉 window,但當單擊確定按鈕時,它不會關閉 window,

這是我使用的代碼:

var patientNumber = order.GetPatientNumber(Convert.ToInt32(textPatientID.Text),Program.branch_id); // int?
            bool patientExists = patientNumber.HasValue;
            if (patientExists == true)
            {
                DialogResult dialogResult = MessageBox.Show("PATIENT HAS ORDER TODAY ", "DUPLICATE ORDER ", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                if (dialogResult == DialogResult.OK)
                {
                    this.Close();
                }

            }

我也嘗試在沒有 if 但也沒有關閉的情況下關閉表單:

var patientNumber = order.GetPatientNumber(Convert.ToInt32(textPatientID.Text),Program.branch_id); // int?
            bool patientExists = patientNumber.HasValue;
            if (patientExists == true)
            {
                DialogResult dialogResult = MessageBox.Show("PATIENT HAS ORDER TODAY ", "DUPLICATE ORDER ", MessageBoxButtons.OK, MessageBoxIcon.Stop);
               
                    this.Close();
               

            }

為什么它不關閉有什么問題請您幫忙?

我看不出有什么理由

if (dialogResult == DialogResult.OK)

檢查,因為對話框有唯一OK按鈕:

if (order
    .GetPatientNumber(int.Parse(textPatientID.Text), Program.branch_id)
    .HasValue) {
  MessageBox.Show(
    "PATIENT HAS ORDER TODAY", 
    "DUPLICATE ORDER", 
     MessageBoxButtons.OK, 
     MessageBoxIcon.Stop);

  Close();
}
  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM