Browse Source

添加无标题UI控件控制

yuzhengyang 8 years ago
parent
commit
54b94ba8a0

+ 31 - 0
Fork.Net/Test/Y.Test/Models/WebAPIMessageModel.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Y.Test.Models
+{
+    public class WebAPIMessageModel
+    {
+        /// <summary>
+        /// 操作成功
+        /// </summary>
+        public bool IsSucc { get; set; }
+        /// <summary>
+        /// 错误码
+        /// </summary>
+        public int ErrorCode { get; set; }
+        /// <summary>
+        /// 错误信息
+        /// </summary>
+        public string ErrorMsg { get; set; }
+        /// <summary>
+        /// 返回信息类型
+        /// </summary>
+        public string Type { get; set; }
+        /// <summary>
+        /// 信息
+        /// </summary>
+        public string Text { get; set; }
+    }
+}

+ 6 - 0
Fork.Net/Test/Y.Test/Program.cs

@@ -4,9 +4,11 @@ using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using Y.Test.Commons;
+using Y.Test.Models;
 using Y.Test.Views;
 using Y.Utils.IOUtils.FileUtils;
 using Y.Utils.IOUtils.PathUtils;
+using Y.Utils.NetUtils.HttpUtils;
 
 namespace Y.Test
 {
@@ -18,6 +20,10 @@ namespace Y.Test
         [STAThread]
         static void Main()
         {
+            string param = string.Format("id={0}&text={1}", "123123123", "123123123");
+            //string rs = HttpTool.Post("http://localhost:20001/Data/Post", param);
+            WebAPIMessageModel rs = HttpTool.Post<WebAPIMessageModel>("http://localhost:20001/Data/Post", param);
+
             //var a = DirTool.Parent(@"D:\Temp\流量测试\");
             //var b = DirTool.Parent(@"D:\Temp");
             //var c = DirTool.Parent(@"D:\");

+ 1 - 0
Fork.Net/Test/Y.Test/Y.Test.csproj

@@ -85,6 +85,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Commons\R.cs" />
+    <Compile Include="Models\WebAPIMessageModel.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Views\ChineseCalendarForm.cs">

+ 38 - 1
Fork.Net/Y.Skin/YoForm/NoTitle/NoTitleForm.cs

@@ -146,6 +146,43 @@ namespace Y.Skin.YoForm.NoTitle
             //Graphics g = CreateGraphics();
             //g.DrawRectangle(new Pen(Color.Red, 1), new Rectangle(0, 0, Width, Height));
         }
-
+        /// <summary>
+        /// 设置控件是否可用
+        /// </summary>
+        /// <param name="ctrl"></param>
+        /// <param name="enable"></param>
+        public void UIEnable(Control ctrl, bool enable = true)
+        {
+            try
+            {
+                BeginInvoke(new Action(() =>
+                {
+                    ctrl.Enabled = enable;
+                }));
+            }
+            catch (Exception e) { }
+        }
+        public void UIVisible(Control ctrl, bool enable = true)
+        {
+            try
+            {
+                BeginInvoke(new Action(() =>
+                {
+                    ctrl.Visible = enable;
+                }));
+            }
+            catch (Exception e) { }
+        }
+        public void UIClose()
+        {
+            try
+            {
+                BeginInvoke(new Action(() =>
+                {
+                    Close();
+                }));
+            }
+            catch (Exception e) { }
+        }
     }
 }

+ 31 - 0
Fork.Net/Y.Utils/NetUtils/HttpUtils/HttpTool.cs

@@ -78,6 +78,37 @@ namespace Y.Utils.NetUtils.HttpUtils
             { }
             return result;
         }
+        public static T Post<T>(string url, string param, string encoding = "utf-8")
+        {
+            try
+            {
+                Encoding myEncoding = Encoding.GetEncoding(encoding);
+                byte[] byteArray = myEncoding.GetBytes(param); //转化
+                HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
+                webReq.Method = "POST";
+                webReq.ContentType = "application/x-www-form-urlencoded";
+                webReq.ContentLength = byteArray.Length;
+                using (Stream newStream = webReq.GetRequestStream())
+                {
+                    newStream.Write(byteArray, 0, byteArray.Length);//写入参数
+                    newStream.Close();
+                    using (HttpWebResponse response = (HttpWebResponse)webReq.GetResponse())
+                    {
+                        using (StreamReader sr = new StreamReader(response.GetResponseStream(), myEncoding))
+                        {
+                            string txt = sr.ReadToEnd();
+                            if (!string.IsNullOrWhiteSpace(txt))
+                            {
+                                T result = JsonConvert.DeserializeObject<T>(txt);
+                                return result;
+                            }
+                        }
+                    }
+                }
+            }
+            catch (Exception ex) { }
+            return default(T);
+        }
         //public static string PostJson(string url, string param)
         //{
         //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);