using System.Windows;
using System.Windows.Input;

namespace XHPZ.Desktop
{
    /// <summary>
    /// MessageWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MessageWindow : Window
    {
        /// <summary>
        /// 提示框
        /// </summary>
        /// <param name="MessageType">取消按钮  1不显示2显示</param>
        /// <param name="Title">标题</param>
        /// <param name="content">消息内容</param>
        public MessageWindow(int MessageType, string Title, string Content)
        {
            InitializeComponent();
            switch (MessageType)
            {
                case 1:
                    borCancel.Visibility = Visibility.Hidden;
                    break;
                case 2:
                    borCancel.Visibility = Visibility.Visible;
                    break;
                default:
                    break;
            }
            lblTitle.Content = Title;
            if (!string.IsNullOrWhiteSpace(Content))
            {
                if (Content.Length > 143)
                {
                    Content = Content.Substring(0, 140) + "...";
                }
                tbkContent.Text = Content;
            }
            else
            {
                tbkContent.Text = "错误！";
            }
        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }
        /// <summary>
        /// 消息提示框
        /// </summary>
        /// <param name="Message">消息</param>
        /// <returns></returns>
        public static MessageBoxResult Show(string Message)
        {
            string Title = "消息提示";
            return Show(Message, Title);
        }
        /// <summary>
        /// 消息提示框
        /// </summary>
        /// <param name="Message">消息</param>
        /// <returns></returns>
        public static MessageBoxResult Show(string Message, string Title)
        {
            MessageWindow message = new MessageWindow(1, Title, Message);
            message.ShowDialog();
            return MessageBoxResult.Cancel;
        }
        /// <summary>
        /// 消息提示框
        /// </summary>
        /// <param name="Title">标题</param>
        /// <param name="Message">消息</param>
        /// <returns></returns>
        public static MessageBoxResult Show(string Message, string Title, MessageBoxButton messageBox)
        {
            if (string.IsNullOrWhiteSpace(Title))
            {
                Title = "消息提示";
            }
            MessageWindow message = new MessageWindow(2, Title, Message);
            bool? res = message.ShowDialog();
            if ((bool)res)
            {
                if (messageBox == MessageBoxButton.OKCancel)
                {
                    return MessageBoxResult.OK;
                }
                else
                {
                    return MessageBoxResult.Yes;
                }
            }
            else
            {
                if (messageBox == MessageBoxButton.OKCancel)
                {
                    return MessageBoxResult.Cancel;
                }
                else
                {
                    return MessageBoxResult.No;
                }
            }
        }
        private static MessageBoxResult Win32ToMessageBoxResult(int value)
        {
            switch (value)
            {
                case 1:
                    return MessageBoxResult.OK;
                case 2:
                    return MessageBoxResult.Cancel;
                case 6:
                    return MessageBoxResult.Yes;
                case 7:
                    return MessageBoxResult.No;
                default:
                    return MessageBoxResult.No;
            }
        }

        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                //this.DragMove();              
                DragMove();
            }
        }
    }
}
