Browse Source

优化ConfigTool重载命名,之前有过重载搞混的情况,优化Toast弹出框,提供点击事件,优化分类

yuzhengyang 7 years ago
parent
commit
52d61b5dd6

BIN
Fork.Net/.vs/Fork.Net/v15/Server/sqlite3/storage.ide


BIN
Fork.Net/.vs/Fork.Net/v15/sqlite3/storage.ide


+ 4 - 4
Fork.Net/Azylee.Utils/Azylee.Core/IOUtils/TxtUtils/ConfigTool.cs

@@ -23,7 +23,7 @@ namespace Azylee.Core.IOUtils.TxtUtils
             }
             catch { return defaultValue; }
         }
-        public static string Get(string exePath, string key, string defaultValue = "")
+        public static string GetExe(string exePath, string key, string defaultValue = "")
         {
             try
             {
@@ -38,9 +38,9 @@ namespace Azylee.Core.IOUtils.TxtUtils
             if (int.TryParse(s, out int value)) return value;
             return defaultValue;
         }
-        public static int GetInt(string exePath, string key, int defaultValue = 0)
+        public static int GetExeInt(string exePath, string key, int defaultValue = 0)
         {
-            string s = Get(exePath: exePath, key: key);
+            string s = GetExe(exePath: exePath, key: key);
             if (int.TryParse(s, out int value)) return value;
             return defaultValue;
         }
@@ -57,7 +57,7 @@ namespace Azylee.Core.IOUtils.TxtUtils
             }
             catch { return false; }
         }
-        public static bool Set(string exePath, string key, string value)
+        public static bool SetExe(string exePath, string key, string value)
         {
             try
             {

+ 19 - 23
Fork.Net/Azylee.Utils/Azylee.Core/IOUtils/TxtUtils/IniTool.cs

@@ -282,7 +282,7 @@ namespace Azylee.Core.IOUtils.TxtUtils
             string[] keys = GetAllItemKeys(file, "Menu");
 
             //获取指定KEY的值  
-            string value = GetStringValue(file, "Desktop", "color", null);
+            string value = GetValue(file, "Desktop", "color", null);
 
             //删除指定的KEY  
             DeleteKey(file, "desktop", "color");
@@ -344,7 +344,7 @@ namespace Azylee.Core.IOUtils.TxtUtils
         /// <param name="key">键名称</param>  
         /// <param name="defaultValue">如果没此KEY所使用的默认值</param>  
         /// <returns>读取到的值</returns>  
-        public static string GetStringValue(string iniFile, string section, string key, string defaultValue)
+        public static string GetValue(string iniFile, string section, string key, string defaultValue)
         {
             string value = defaultValue;
             const int SIZE = 1024 * 10;
@@ -370,33 +370,29 @@ namespace Azylee.Core.IOUtils.TxtUtils
 
             return value;
         }
-        [Obsolete]
-        public static bool GetBoolValue(string iniFile, string section, string key)
+        public static string GetString(string iniFile, string section, string key, string defaultValue)
         {
-            string flag = GetStringValue(iniFile, section, key, "");
-            return flag.ToLower() == "true" ? true : false;
+            return GetValue(iniFile, section, key, defaultValue);
         }
-        [Obsolete]
-        public static int GetIntValue(string iniFile, string section, string key)
+        public static bool GetBool(string iniFile, string section, string key, bool defaultValue)
         {
-            string flag = GetStringValue(iniFile, section, key, "0");
-            int result = 0;
-            int.TryParse(flag, out result);
-            return result;
+            string value = GetString(iniFile, section, key, "");
+            if (value.ToLower() == "true") return true;
+            if (value.ToLower() == "false") return false;
+            return defaultValue;
         }
-        [Obsolete]
-        public static long GetLongValue(string iniFile, string section, string key)
+        public static int GetInt(string iniFile, string section, string key, int defaultValue)
         {
-            string flag = GetStringValue(iniFile, section, key, "0");
-            long result = 0;
-            long.TryParse(flag, out result);
-            return result;
+            string value = GetString(iniFile, section, key, defaultValue.ToString());
+            if (int.TryParse(value, out int result)) return result;
+            return defaultValue;
+        }
+        public static long GetLong(string iniFile, string section, string key, long defaultValue)
+        {
+            string value = GetString(iniFile, section, key, defaultValue.ToString());
+            if (long.TryParse(value, out long result)) return result;
+            return defaultValue;
         }
-
-        public static string GetString(string iniFile, string section, string key, string defaultValue) { return GetStringValue(iniFile, section, key, defaultValue); }
-        public static bool GetBool(string iniFile, string section, string key) { return GetBoolValue(iniFile, section, key); }
-        public static int GetInt(string iniFile, string section, string key) { return GetIntValue(iniFile, section, key); }
-        public static long GetLong(string iniFile, string section, string key) { return GetLongValue(iniFile, section, key); }
         #endregion
     }
 }

+ 5 - 2
Fork.Net/Azylee.Utils/Azylee.Core/WindowsUtils/InfoUtils/NetcardInfoTool.cs

@@ -35,11 +35,14 @@ namespace Azylee.Core.WindowsUtils.InfoUtils
                         string _name = item.Name.Trim();
                         string _desc = item.Description.Trim();
                         string _mac = item.GetPhysicalAddress().ToString();
+                        //测试获取数据
+                        var x = item.GetIPProperties().UnicastAddresses;
                         string _ip = item.GetIPProperties().UnicastAddresses.Count >= 1 ?
                             item.GetIPProperties().UnicastAddresses[0].Address.ToString() : null;
                         //更新IP为ipv4地址
-                        _ip = item.GetIPProperties().UnicastAddresses.Count >= 2 ?
-                          item.GetIPProperties().UnicastAddresses[1].Address.ToString() : null;
+                        if (item.GetIPProperties().UnicastAddresses.Count > 0)
+                            _ip = item.GetIPProperties().UnicastAddresses[item.GetIPProperties().
+                                UnicastAddresses.Count - 1].Address.ToString();
                         string _gateway = item.GetIPProperties().GatewayAddresses.Count >= 1 ?
                             item.GetIPProperties().GatewayAddresses[0].Address.ToString() : null;
                         result.Add(new Tuple<string, string, string, string, string>(_name, _desc, _mac, _ip, _gateway));

+ 65 - 23
Fork.Net/Azylee.Utils/Azylee.WinformSkin/FormUI/Toast/ToastForm.cs

@@ -14,22 +14,52 @@ namespace Azylee.WinformSkin.FormUI.Toast
 {
     public partial class ToastForm : NoTitleForm
     {
+        public enum ToastType { warn, error, info }
         private static ToastForm form = new ToastForm();
+        private Action ClickAction = null;
+
         /// <summary>
         /// 弹出提示框
         /// </summary>
         /// <param name="title">标题</param>
         /// <param name="text">内容</param>
         /// <param name="type">类型:w,e,i</param>
-        /// <param name="time">显示时间:ms</param>
-        public static void Display(string title, string text, char type, int time)
+        /// <param name="time">显示时间:毫秒</param>
+        /// <param name="clickAction">点击触发动作反馈</param>
+        public static void Display(string title, string text, char type, int time, Action clickAction = null)
         {
             try
             {
                 if (form == null || form.IsDisposed)
                     form = new ToastForm();
 
-                form.SetContent(title, text, type, time);
+                ToastType tt = ToastType.info;
+                if (type == 'w' || type == 'W') tt = ToastType.warn;
+                if (type == 'e' || type == 'E') tt = ToastType.error;
+
+                form.SetContent(title, text, tt, time);//设置提示框:标题、文本、类型、时间
+                form.ClickAction = clickAction;//设置单击触发事件
+                form.Toast();
+            }
+            catch { }
+        }
+        /// <summary>
+        /// 弹出提示框
+        /// </summary>
+        /// <param name="title">标题</param>
+        /// <param name="text">内容</param>
+        /// <param name="type">类型</param>
+        /// <param name="clickAction">点击动作</param>
+        /// <param name="time">显示时间:秒</param>
+        public static void Display(string title, string text, ToastType type = ToastType.info, Action clickAction = null, short time = 5)
+        {
+            try
+            {
+                if (form == null || form.IsDisposed)
+                    form = new ToastForm();
+
+                form.SetContent(title, text, type, time * 1000);//设置提示框:标题、文本、类型、时间
+                form.ClickAction = clickAction;//设置单击触发事件
                 form.Toast();
             }
             catch { }
@@ -56,6 +86,7 @@ namespace Azylee.WinformSkin.FormUI.Toast
             TMShowAnim.Enabled = true;//启动显示动画
             TMHide.Enabled = true;//开始隐藏倒计时
         }
+
         #region 初始化设置
         /// <summary>
         /// 初始化设置,设置要显示的内容
@@ -64,7 +95,7 @@ namespace Azylee.WinformSkin.FormUI.Toast
         /// <param name="text">内容</param>
         /// <param name="type">类型:w,e,i</param>
         /// <param name="time">显示时间:ms</param>
-        private void SetContent(string title, string text, char type, int time)
+        private void SetContent(string title, string text, ToastType type, int time)
         {
             TimeSpend = 0;//初始化运行时间,每次执行动画++
             SetPosition();//设置初始位置
@@ -80,20 +111,19 @@ namespace Azylee.WinformSkin.FormUI.Toast
         /// 设置消息类型
         /// </summary>
         /// <param name="type"></param>
-        private void SetType(char type)
+        private void SetType(ToastType type)
         {
             switch (type)
             {
-                case 'w':
-                case 'W':
+                case ToastType.warn:
                     PBIcon.Image = Resources.toast_warning;
                     break;
-                case 'e':
-                case 'E':
+                case ToastType.error:
                     PBIcon.Image = Resources.toast_error;
                     break;
-                case 'i':
-                case 'I':
+                case ToastType.info:
+                    PBIcon.Image = Resources.toast_info;
+                    break;
                 default:
                     PBIcon.Image = Resources.toast_info;
                     break;
@@ -109,6 +139,30 @@ namespace Azylee.WinformSkin.FormUI.Toast
         }
         #endregion
 
+        #region 事件动作
+        private void PBIcon_Click(object sender, EventArgs e)
+        {
+            ClickAction?.Invoke();
+            ClickAction = null;
+
+            HideForm();
+        }
+        private void LBTitle_Click(object sender, EventArgs e)
+        {
+            ClickAction?.Invoke();
+            ClickAction = null;
+
+            HideForm();
+        }
+        private void LBText_Click(object sender, EventArgs e)
+        {
+            ClickAction?.Invoke();
+            ClickAction = null;
+
+            HideForm();
+        }
+        #endregion
+
         #region 显示提示框
         private void TMShowAnim_Tick(object sender, EventArgs e)
         {
@@ -135,18 +189,6 @@ namespace Azylee.WinformSkin.FormUI.Toast
             TMHideAnim.Enabled = true;//执行隐藏窗口动画
             TMHideAnim.Interval = 10;
         }
-        private void PBIcon_Click(object sender, EventArgs e)
-        {
-            HideForm();
-        }
-        private void LBTitle_Click(object sender, EventArgs e)
-        {
-            HideForm();
-        }
-        private void LBText_Click(object sender, EventArgs e)
-        {
-            HideForm();
-        }
         private void TMHide_Tick(object sender, EventArgs e)
         {
             HideForm();

+ 26 - 0
Fork.Net/Test/Test.BlackBox/Form1.Designer.cs

@@ -34,6 +34,8 @@
             this.BTStopBB = new System.Windows.Forms.Button();
             this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
             this.BTWriteLog = new System.Windows.Forms.Button();
+            this.button1 = new System.Windows.Forms.Button();
+            this.button2 = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // BTStartBB
@@ -74,11 +76,33 @@
             this.BTWriteLog.UseVisualStyleBackColor = true;
             this.BTWriteLog.Click += new System.EventHandler(this.BTWriteLog_Click);
             // 
+            // button1
+            // 
+            this.button1.Location = new System.Drawing.Point(339, 295);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(75, 23);
+            this.button1.TabIndex = 4;
+            this.button1.Text = "button1";
+            this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.button1_Click);
+            // 
+            // button2
+            // 
+            this.button2.Location = new System.Drawing.Point(444, 295);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(75, 23);
+            this.button2.TabIndex = 5;
+            this.button2.Text = "button2";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.button2_Click);
+            // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(553, 365);
+            this.Controls.Add(this.button2);
+            this.Controls.Add(this.button1);
             this.Controls.Add(this.BTWriteLog);
             this.Controls.Add(this.BTStopBB);
             this.Controls.Add(this.textBox1);
@@ -98,6 +122,8 @@
         private System.Windows.Forms.Button BTStopBB;
         private System.Windows.Forms.ToolTip toolTip1;
         private System.Windows.Forms.Button BTWriteLog;
+        private System.Windows.Forms.Button button1;
+        private System.Windows.Forms.Button button2;
     }
 }
 

+ 14 - 0
Fork.Net/Test/Test.BlackBox/Form1.cs

@@ -1,6 +1,7 @@
 using Azylee.Core.LogUtils.SimpleLogUtils;
 using Azylee.Core.LogUtils.StatusLogUtils;
 using Azylee.Core.WindowsUtils.InfoUtils;
+using Azylee.WinformSkin.FormUI.Toast;
 using System;
 using System.Threading.Tasks;
 using System.Windows.Forms;
@@ -49,5 +50,18 @@ namespace Test.BlackBox
                 }
             });
         }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            ToastForm.Display("标题", "内容", ToastForm.ToastType.error, new Action(() =>
+            {
+                new Form2().Show();
+            }), 2);
+        }
+
+        private void button2_Click(object sender, EventArgs e)
+        {
+            ToastForm.Display("标题222", "内容222", ToastForm.ToastType.error, null, 10);
+        }
     }
 }

+ 38 - 0
Fork.Net/Test/Test.BlackBox/Form2.Designer.cs

@@ -0,0 +1,38 @@
+namespace Test.BlackBox
+{
+    partial class Form2
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.Text = "Form2";
+        }
+
+        #endregion
+    }
+}

+ 19 - 0
Fork.Net/Test/Test.BlackBox/Form2.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Test.BlackBox
+{
+    public partial class Form2 : Form
+    {
+        public Form2()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 10 - 0
Fork.Net/Test/Test.BlackBox/Test.BlackBox.csproj

@@ -49,6 +49,12 @@
     <Compile Include="Form1.Designer.cs">
       <DependentUpon>Form1.cs</DependentUpon>
     </Compile>
+    <Compile Include="Form2.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Form2.Designer.cs">
+      <DependentUpon>Form2.cs</DependentUpon>
+    </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Form1.resx">
@@ -78,6 +84,10 @@
       <Project>{88dc61fa-95f0-41b7-9d7d-ab0f3cbd169c}</Project>
       <Name>Azylee.Core</Name>
     </ProjectReference>
+    <ProjectReference Include="..\..\Azylee.Utils\Azylee.WinformSkin\Azylee.WinformSkin.csproj">
+      <Project>{d280c16f-fde2-4647-bd76-3514f673426d}</Project>
+      <Name>Azylee.WinformSkin</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>