黄学彪
2020-09-18 c7df85937f73fb347ee0b19e9c052d2d00a6df6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// 消息的逻辑
    /// </summary>
    public class HdlMessageLogic
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 消息的逻辑
        /// </summary>
        private static HdlMessageLogic m_Current = null;
        /// <summary>
        /// 消息的逻辑
        /// </summary>
        public static HdlMessageLogic Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new HdlMessageLogic();
                }
                return m_Current;
            }
        }
 
        #endregion
 
        #region ■ 一般的方法_________________________
 
        /// <summary>
        /// 显示信息框
        /// </summary>
        /// <param name="msgType">信息类型</param>
        /// <param name="msg">信息</param>
        /// <param name="action">单击确认后执行的回调函数</param>
        /// <param name="buttonText">按钮的文本</param>
        /// <param name="i_waitTime">等待时间,单位为秒,设置确认按钮在多长时间后才能够点击</param>
        public void ShowMassage(ShowMsgType msgType, string msg, Action action = null, string buttonText = null, int i_waitTime = -1)
        {
            //空对象时,不显示
            if (string.IsNullOrEmpty(msg))
            {
                return;
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                var alert = new ShowMsgControl(msgType, msg, buttonText, null, i_waitTime);
                if (action != null)
                {
                    alert.ConfirmClickEvent += () =>
                    {
                        try
                        {
                            //回调函数
                            action?.Invoke();
                        }
                        catch (Exception ex)
                        {
                            //出现未知错误,数据丢失
                            this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
 
                            //Log出力
                            HdlLogLogic.Current.WriteLog(ex);
                        }
                        action = null;
                    };
                }
                alert.Show();
            });
        }
 
        #endregion
    }
 
    /// <summary>
    /// 信息显示的类型
    /// </summary>
    public enum ShowMsgType
    {
        /// <summary>
        /// 普通提示类型
        /// </summary>
        Normal = 1,
        /// <summary>
        /// 确认类型
        /// </summary>
        Confirm = 2,
        /// <summary>
        /// 错误类型
        /// </summary>
        Error = 3,
        /// <summary>
        /// Tip类型
        /// </summary>
        Tip = 4,
        /// <summary>
        /// 提醒类型
        /// </summary>
        Remind = 5
    }
}