lu
2024-12-06 e6a9b817b0fd82dd89bf58107388edd1ab89bf11
DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
@@ -13,6 +13,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.RichEdit.Export;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid;
@@ -25,6 +26,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static System.Windows.Forms.Control;
namespace Gs.DevApp.ToolBox
{
@@ -64,35 +66,35 @@
        /// <param name="meth">方法名称</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public static async Task<string> HttpPostAsync(string url, string meth, string param)
        {
            if (string.IsNullOrEmpty(url))
                url = WebApiUrl;
            url += meth;
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/json";
            request.Headers.Add("token", GetBasicAuthTicket());
            request.Accept = "*/*";
            request.Timeout = 15000;
            request.AllowAutoRedirect = false;
            request.ServicePoint.Expect100Continue = false;
            HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            request.CachePolicy = noCachePolicy;
            using (Stream requestStream = await request.GetRequestStreamAsync())
            {
                byte[] dataBytes = Encoding.UTF8.GetBytes(param);
                await requestStream.WriteAsync(dataBytes, 0, dataBytes.Length);
            }
        //public static async Task<string> HttpPostAsync(string url, string meth, string param)
        //{
        //    if (string.IsNullOrEmpty(url))
        //        url = WebApiUrl;
        //    url += meth;
        //    var request = (HttpWebRequest)WebRequest.Create(url);
        //    request.Method = "POST";
        //    request.ContentType = "application/json";
        //    request.Headers.Add("token", GetBasicAuthTicket());
        //    request.Accept = "*/*";
        //    request.Timeout = 15000;
        //    request.AllowAutoRedirect = false;
        //    request.ServicePoint.Expect100Continue = false;
        //    HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
        //    request.CachePolicy = noCachePolicy;
        //    using (Stream requestStream = await request.GetRequestStreamAsync())
        //    {
        //        byte[] dataBytes = Encoding.UTF8.GetBytes(param);
        //        await requestStream.WriteAsync(dataBytes, 0, dataBytes.Length);
        //    }
            using (WebResponse response = await request.GetResponseAsync())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    return await reader.ReadToEndAsync();
                }
            }
        }
        //    using (WebResponse response = await request.GetResponseAsync())
        //    {
        //        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
        //        {
        //            return await reader.ReadToEndAsync();
        //        }
        //    }
        //}
        /// <summary>
        ///     httpPost访问服务
@@ -103,24 +105,28 @@
        /// <returns></returns>
        public static string HttpPost(string url, string meth, string param)
        {
            if (string.IsNullOrEmpty(url))
                url = WebApiUrl;
            url += meth;
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/json";
            request.Headers.Add("token", GetBasicAuthTicket());
            request.Accept = "*/*";
            request.Timeout = 15000;
            request.AllowAutoRedirect = false;
            request.ServicePoint.Expect100Continue = false;
            HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            request.CachePolicy = noCachePolicy;
            DevExpress.Utils.WaitDialogForm wdf = new DevExpress.Utils.WaitDialogForm("拼命加载中,请稍后..." + meth, "友情提示");
            HttpWebRequest request = null;
            StreamWriter requestStream = null;
            WebResponse response = null;
            string responseStr = null;
            try
            {
                if (string.IsNullOrEmpty(url))
                    url = WebApiUrl;
                url += meth;
                request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "POST";
                request.ContentType = "application/json";
                request.Headers.Add("token", GetBasicAuthTicket());
                request.Accept = "*/*";
                request.Timeout = 15000;
                request.AllowAutoRedirect = false;
                request.ServicePoint.Expect100Continue = false;
                wdf.SetCaption("加载进度(10/100)");
                HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                request.CachePolicy = noCachePolicy;
                wdf.SetCaption("加载进度(20/100)");
                requestStream = new StreamWriter(request.GetRequestStream());
                requestStream.Write(param);
                requestStream.Close();
@@ -133,9 +139,11 @@
                    //File.WriteAllText(Server.MapPath("~/") + @"\test.txt", responseStr); 
                    reader.Close();
                }
                wdf.SetCaption("加载进度(80/100)");
            }
            catch (Exception ex)
            {
                wdf.Close();
                LogHelper.Debug(url, param + ":" + ex.Message);
                throw ex;
            }
@@ -145,7 +153,8 @@
                requestStream = null;
                response = null;
            }
            wdf.SetCaption("加载进度(90/100)");
            wdf.Close();
            return responseStr;
        }
@@ -304,10 +313,10 @@
                        {
                            //  colmn.Visible = !isEdt;
                            //  break;
                            colmn.OptionsColumn.AllowEdit =true;
                            colmn.OptionsColumn.AllowEdit = true;
                        }
                        else
                        colmn.OptionsColumn.AllowEdit = !isEdt;
                            colmn.OptionsColumn.AllowEdit = !isEdt;
                    }
                    //gv.OptionsBehavior.Editable = !isEdt;
                }
@@ -1073,6 +1082,14 @@
                return 0;
            }
        }
        public static int ToBit(string str)
        {
            if (str.ToUpper() == "true".ToUpper())
                return 1;
            return 0;
        }
        /// <summary>
        /// 读取grid的当前行
        /// </summary>
@@ -1327,16 +1344,20 @@
            return _sbSqlWhere.ToString();
        }
        /// <summary>
        /// 初始化gridview
        ///
        /// </summary>
        /// <param name="gridView1"></param>
        public static void SetGridSear(GridView gridView1)
        /// <param name="gridView1">gridview</param>
        /// <param name="btnChkIco">图标按钮</param>
        /// <param name="fm">当前窗体</param>
        /// <param name="fileName">字段</param>
        /// <param name="icoName">图标路径</param>
        public static void SetGridSear(GridView gridView1, PictureBox btnChkIco = null, Form fm = null, string fileName = "checkStatus", string icoName = "")
        {
            foreach (GridColumn column in gridView1.Columns)
            {
                column.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                column.OptionsFilter.ImmediateUpdateAutoFilter = false;
                column.OptionsColumn.AllowEdit = false;
                // column.OptionsColumn.AllowEdit = false;
                if (column.Tag == null || column.Tag.ToString().Length <= 0)
                    column.OptionsFilter.AllowAutoFilter = false;
            }
@@ -1361,10 +1382,15 @@
                    e.Bounds.Top + 45, e.Bounds.Right - 5, e.Bounds.Height - 5);
                e.Graphics.DrawString(str, f, Brushes.Gray, r);
            };
            if (btnChkIco != null)
            {
                gridView1.FocusedRowChanged += (s, e) =>
                {
                    UtilityHelper.SetCheckIco(s, btnChkIco, fm, fileName, icoName);
                };
            }
        }
        #endregion
        public static bool IsNumeric(string str)
        {