ShowMessageBox.cs 3.5 KB
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace App
{
    public static class ShowMessageBox
    {
        /// <summary>
        /// 获得对应语言的消息文本
        /// </summary>
        /// <param name="textId">消息ID</param>
        /// <returns>对应语言的消息文本</returns>
        private static String GetMsgText(string str_Text)
        {

            FrmBase frmBase = new FrmBase();
            frmBase.GetCurrLanguage();
            return frmBase.getMsg("msg-" + str_Text);
        }
        /// <summary>
        /// 获得对应语言的消息文本
        /// </summary>
        /// <param name="textId">消息ID</param>
        /// <returns>对应语言的消息文本</returns>
        private static String GetMsgTextWithoutAppGlobal(string str_TextID, string str_Language)
        {

            FrmBase frmBase = new FrmBase();
            frmBase.GetCurrLanguageWithoutAppGlobal(str_Language);
            return frmBase.getMsg("msg-" + str_TextID);
        }



        /// <summary>
        /// 提示消息框
        /// </summary>
        public static void ShowInfo(string captionStr, int textId)
        {
            string caption = GetMsgText(captionStr);
            string text = GetMsgText(textId.ToString());

            MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary>
        /// 询问消息框
        /// </summary>
        public static bool ShowQuestion(string captionStr, int textId)
        {
            string caption = GetMsgText(captionStr);
            string text = GetMsgText(textId.ToString());

            return MessageBox.Show(text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes;
        }

        public static bool ShowQuestionForDeleteProduce(string captionStr, string info)
        {
            string caption = GetMsgText(captionStr);
            FrmBase frmBase = new FrmBase();
            frmBase.GetCurrLanguage();
            string text = frmBase.getMsg("ConfirmDelete") + info + "?";
            return MessageBox.Show(text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Yes;;
        }

        /// <summary>
        /// 警告消息框
        /// </summary>
        public static bool ShowWarning(string captionStr, int textId)
        {
            string caption = GetMsgText(captionStr);
            string text = GetMsgText(textId.ToString());

            return MessageBox.Show(text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Yes;
        }

        /// <summary>
        /// 错误消息框
        /// </summary>
        public static void ShowError(string captionStr,string name, int textId)
        {
            string caption = GetMsgText(captionStr);
            string text = GetMsgText(textId.ToString());

            MessageBox.Show(name+text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        /// <summary>
        /// 错误消息框,用于还未登录时,因为Appglobel为空
        /// </summary>
        public static void ShowErrorWithoutAppGlobal(string captionStr,string name ,int textId,string str_Language)
        {

            string caption = GetMsgTextWithoutAppGlobal(captionStr, str_Language);
            string text = GetMsgTextWithoutAppGlobal(textId.ToString(), str_Language);

            MessageBox.Show(name+text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}