lu
2025-01-04 b437a00db77cee8b767d30486e7935b57242a236
DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
@@ -13,8 +13,6 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.RichEdit.Export;
using DevExpress.XtraBars.Customization;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid;
@@ -22,11 +20,11 @@
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTab;
using DevExpress.XtraTreeList;
using DevExpress.XtraWaitForm;
using Gs.DevApp.Entity;
using Gs.DevApp.UserControl;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UserControls.Data;
using static System.Windows.Forms.Control;
@@ -61,50 +59,7 @@
                }
            }
        }
        /// <summary>
        ///     httpPost访问服务
        /// </summary>
        /// <param name="url">服务地址</param>
        /// <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);
        //    }
        //    using (WebResponse response = await request.GetResponseAsync())
        //    {
        //        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
        //        {
        //            return await reader.ReadToEndAsync();
        //        }
        //    }
        //}
        /// <summary>
        ///     httpPost访问服务
        /// </summary>
        /// <param name="url">服务地址</param>
        /// <param name="meth">方法名称</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public static string HttpPost(string url, string meth, string param)
        {
            string _caption = "拼命加载中,请稍后...";
@@ -125,7 +80,7 @@
                request.ContentType = "application/json";
                request.Headers.Add("token", GetBasicAuthTicket());
                request.Accept = "*/*";
                request.Timeout = 15000;
                request.Timeout = 150000;
                request.AllowAutoRedirect = false;
                request.ServicePoint.Expect100Continue = false;
                wdf.SetCaption(_caption + "(10/100)" + meth);
@@ -314,21 +269,37 @@
        {
            isEdt = !isEdt;
            if (gridViews != null)
            {
                foreach (var gv in gridViews)
                {
                    foreach (GridColumn colmn in gv.Columns)
                    {
                        colmn.OptionsColumn.AllowEdit = true;
                        if (colmn.Name.ToString().Contains("gvBtnAlawys"))
                        {
                            colmn.Visible = true;
                            colmn.OptionsColumn.ReadOnly = false;
                        };
                        if (colmn.Name.ToString().Contains("gvMxDel") || colmn.Name.ToString().Contains("gvMxTui"))
                        {
                            //  colmn.Visible = !isEdt;
                            //  break;
                            colmn.OptionsColumn.AllowEdit = true;
                            colmn.Visible = !isEdt;
                        }
                        else
                            colmn.OptionsColumn.AllowEdit = !isEdt;
                        {
                            if (isEdt == false)
                            {
                                if (colmn.Tag != null && colmn.Tag.ToString().EndsWith("edit"))
                                    colmn.OptionsColumn.ReadOnly = isEdt;
                                else
                                    colmn.OptionsColumn.ReadOnly = !isEdt;
                            }
                            else
                                colmn.OptionsColumn.ReadOnly = isEdt;
                        }
                    }
                    //gv.OptionsBehavior.Editable = !isEdt;
                }
            }
            var _btnAry = controls.Find("btnSelect", false);
            if (_btnAry.Length > 0)
            {
@@ -359,7 +330,6 @@
                            txt.ReadOnly = isEdt;
                            continue;
                        }
                        if (colType is ImageComboBoxEdit)
                        {
                            var txt = colType as ImageComboBoxEdit;
@@ -374,32 +344,26 @@
                            }
                            continue;
                        }
                        if (colType is ComboBoxEdit)
                        {
                            var txt = colType as ComboBoxEdit;
                            if (txt.Properties.TextEditStyle ==
                                TextEditStyles.DisableTextEditor)
                                txt.SelectedIndex = int.Parse(strVal);
                                try
                                {
                                    txt.SelectedIndex = int.Parse(strVal);
                                }
                                catch (Exception)
                                {
                                    txt.Text = strVal;
                                }
                            else
                                txt.Text = strVal;
                            txt.ReadOnly = isEdt;
                            continue;
                        }
                        //下拉
                        if (colType is ComboBoxEdit)
                        {
                            var txt = colType as ComboBoxEdit;
                            if (txt.Properties.TextEditStyle ==
                                TextEditStyles.DisableTextEditor)
                                txt.SelectedIndex = int.Parse(strVal);
                            else
                                txt.Text = strVal;
                            txt.ReadOnly = isEdt;
                            continue;
                        }
                        //自定义下拉
                        if (colType is UcComBox)
                        {
@@ -408,14 +372,18 @@
                            txt.Enabled = !isEdt;
                            continue;
                        }
                        //文本
                        if (colType is TextEdit)
                        {
                            var txt = colType as TextEdit;
                            if (txt != null)
                                txt.Text = strVal;
                            txt.ReadOnly = isEdt;
                            if (_isRead(txt.Tag))
                            {
                                txt.ReadOnly = true;
                            }
                            else
                                txt.ReadOnly = isEdt;
                            continue;
                        }
                        if (colType is MemoEdit)
@@ -426,7 +394,6 @@
                            txt.ReadOnly = isEdt;
                            continue;
                        }
                        //数字卡
                        if (colType is NumericUpDown)
                        {
@@ -436,7 +403,6 @@
                            txt.ReadOnly = isEdt;
                            continue;
                        }
                        //单选
                        if (colType is CheckEdit)
                        {
@@ -461,7 +427,6 @@
                            txt.ReadOnly = isEdt;
                            continue;
                        }
                        //单选
                        if (colType is CheckBox)
                        {
@@ -487,7 +452,6 @@
                            txt.Enabled = !isEdt;
                            continue;
                        }
                        //Label
                        if (colType is Label)
                        {
@@ -570,7 +534,6 @@
                                txt.Enabled = false;
                            continue;
                        }
                        //自定客户
                        if (colType is UcLookCustomer)
                        {
@@ -637,6 +600,39 @@
                                txt.Enabled = false;
                            continue;
                        }
                        //自定部门
                        if (colType is UcLookDepartment)
                        {
                            var txt = colType as UcLookDepartment;
                            txt.SetIdOrCode(strVal);
                            if (txt.IsReadly == false)
                                txt.Enabled = !isEdt;
                            else
                                txt.Enabled = false;
                            continue;
                        }
                        //自定daa
                        if (colType is UcLookDaa)
                        {
                            var txt = colType as UcLookDaa;
                            txt.SetIdOrCode(strVal);
                            if (txt.IsReadly == false)
                                txt.Enabled = !isEdt;
                            else
                                txt.Enabled = false;
                            continue;
                        }
                        //自定委外
                        if (colType is UcLookWwgd)
                        {
                            var txt = colType as UcLookWwgd;
                            txt.SetIdOrCode(strVal);
                            if (txt.IsReadly == false)
                                txt.Enabled = !isEdt;
                            else
                                txt.Enabled = false;
                            continue;
                        }
                        if (colType is SimpleButton)
                        {
                            var txt = colType as SimpleButton;
@@ -648,6 +644,21 @@
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            foreach (Control ctrl in controls)
            {
                if (ctrl is TextEdit)
                {
                    var txt = ctrl as TextEdit;
                    if (_isRead(txt.Tag))
                    {
                        txt.ReadOnly = true;
                    }
                    else
                        txt.ReadOnly = isEdt;
                    continue;
                }
            }
        }
@@ -663,21 +674,31 @@
        {
            isEdt = !isEdt;
            if (gridViews != null)
            {
                foreach (var gv in gridViews)
                {
                    foreach (GridColumn colmn in gv.Columns)
                    {
                        colmn.OptionsColumn.AllowEdit = true;
                        if (colmn.Name.ToString().Contains("gvMxDel") || colmn.Name.ToString().Contains("gvMxTui"))
                        {
                            //  colmn.Visible = !isEdt;
                            //  break;
                            colmn.OptionsColumn.AllowEdit = true;
                            colmn.Visible = !isEdt;
                        }
                        else
                            colmn.OptionsColumn.AllowEdit = !isEdt;
                        {
                            if (isEdt == false)
                            {
                                if (colmn.Tag != null && colmn.Tag.ToString().EndsWith("edit"))
                                    colmn.OptionsColumn.ReadOnly = isEdt;
                                else
                                    colmn.OptionsColumn.ReadOnly = !isEdt;
                            }
                            else
                                colmn.OptionsColumn.ReadOnly = isEdt;
                        }
                    }
                    //gv.OptionsBehavior.Editable = !isEdt;
                }
            }
            foreach (Control ctrl in controls)
            {
                //多行文本
@@ -688,7 +709,6 @@
                    txt.ReadOnly = isEdt;
                    continue;
                }
                //下拉
                if (ctrl is ComboBoxEdit)
                {
@@ -701,7 +721,6 @@
                    txt.ReadOnly = isEdt;
                    continue;
                }
                //自定义的下拉
                if (ctrl is UcComBox)
                {
@@ -710,7 +729,6 @@
                    txt.Enabled = !isEdt;
                    continue;
                }
                //文本
                if (ctrl is TextEdit)
                {
@@ -721,7 +739,12 @@
                    }
                    else
                        txt.Text = "";
                    txt.ReadOnly = isEdt;
                    if (_isRead(txt.Tag))
                    {
                        txt.ReadOnly = true;
                    }
                    else
                        txt.ReadOnly = isEdt;
                    continue;
                }
                if (ctrl is MemoEdit)
@@ -743,13 +766,14 @@
                if (ctrl is CheckBox)
                {
                    var txt = ctrl as CheckBox;
                    //txt.Checked = false;
                    txt.Enabled = !isEdt;
                    txt.Checked = false;
                }
                if (ctrl is CheckEdit)
                {
                    var txt = ctrl as CheckEdit;
                    txt.ReadOnly = isEdt;
                    txt.Checked = false;
                    continue;
                }
@@ -849,16 +873,39 @@
                    txt.Enabled = !isEdt;
                    continue;
                }
                //自定部门
                if (ctrl is UcLookDepartment)
                {
                    var txt = ctrl as UcLookDepartment;
                    txt.SetIdOrCode("-1");
                    txt.Enabled = !isEdt;
                    continue;
                }
                //自定daa
                if (ctrl is UcLookDaa)
                {
                    var txt = ctrl as UcLookDaa;
                    txt.SetIdOrCode("-1");
                    txt.Enabled = !isEdt;
                    continue;
                }
                //自定委外
                if (ctrl is UcLookWwgd)
                {
                    var txt = ctrl as UcLookWwgd;
                    txt.SetIdOrCode("-1");
                    txt.Enabled = !isEdt;
                    continue;
                }
                if (ctrl is SimpleButton)
                {
                    var txt = ctrl as SimpleButton;
                    txt.Enabled = !isEdt;
                    continue;
                }
            }
        }
        /// <summary>
        ///     禁用或启用容器里面的控件
        /// </summary>
@@ -870,28 +917,38 @@
        {
            isEdt = !isEdt;
            if (gridViews != null)
            {
                foreach (var gv in gridViews)
                {
                    foreach (GridColumn colmn in gv.Columns)
                    {
                        colmn.OptionsColumn.AllowEdit = true;
                        if (colmn.Name.ToString().Contains("gvMxDel") || colmn.Name.ToString().Contains("gvMxTui"))
                        {
                            //  colmn.Visible = !isEdt;
                            //  break;
                            colmn.OptionsColumn.AllowEdit = true;
                            colmn.Visible = !isEdt;
                        }
                        else
                            colmn.OptionsColumn.AllowEdit = !isEdt;
                        {
                            if (colmn.Tag != null && colmn.Tag.ToString().EndsWith("edit"))
                                colmn.OptionsColumn.ReadOnly = isEdt;
                            else
                                colmn.OptionsColumn.ReadOnly = isEdt;
                        }
                    }
                    //gv.OptionsBehavior.Editable = !isEdt;
                }
            }
            foreach (Control ctrl in controls)
            {
                //文本
                if (ctrl is TextEdit)
                {
                    var txt = ctrl as TextEdit;
                    txt.ReadOnly = isEdt;
                    if (_isRead(txt.Tag))
                    {
                        txt.ReadOnly = true;
                    }
                    else
                        txt.ReadOnly = isEdt;
                    continue;
                }
                if (ctrl is MemoEdit)
@@ -1056,9 +1113,53 @@
                        txt.Enabled = false;
                    continue;
                }
                //自定部门
                if (ctrl is UcLookDepartment)
                {
                    var txt = ctrl as UcLookDepartment;
                    if (txt.IsReadly == false)
                        txt.Enabled = !isEdt;
                    else
                        txt.Enabled = false;
                    continue;
                }
                //自定daa
                if (ctrl is UcLookDaa)
                {
                    var txt = ctrl as UcLookDaa;
                    if (txt.IsReadly == false)
                        txt.Enabled = !isEdt;
                    else
                        txt.Enabled = false;
                    continue;
                }
                //自定委外
                if (ctrl is UcLookWwgd)
                {
                    var txt = ctrl as UcLookWwgd;
                    if (txt.IsReadly == false)
                        txt.Enabled = !isEdt;
                    else
                        txt.Enabled = false;
                    continue;
                }
                if (ctrl is SimpleButton)
                {
                    var txt = ctrl as SimpleButton;
                    txt.Enabled = !isEdt;
                    continue;
                }
            }
        }
        private static bool _isRead(object obj)
        {
            if (obj != null && obj.ToString().ToUpper().Contains("readOnly".ToUpper()))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        ///     切换选项卡
        /// </summary>
@@ -1078,6 +1179,59 @@
                tabControl.TabPages[i].PageEnabled = false;
            tabControl.TabPages[idx].PageEnabled = true;
            tabControl.SelectedTabPageIndex = idx;
        }
        /// <summary>
        /// tab跳转:0查看,1退出,2删除,3修改,4新增加
        /// </summary>
        /// <param name="tabControl"></param>
        /// <param name="idx">0查看,1退出,2删除,3修改,4新增加</param>
        public static void JumpTab(XtraTabControl tabControl, int action)
        {
            if (action == 0)
            {
                tabControl.TabPages[0].PageEnabled = true;
                tabControl.TabPages[1].PageEnabled = true;
                tabControl.SelectedTabPageIndex = 1;
                return;
            }
            if (action == 1)
            {
                tabControl.TabPages[0].PageEnabled = true;
                tabControl.TabPages[1].PageEnabled = true;
                tabControl.SelectedTabPageIndex = 0;
                return;
            }
            if (action == 2)
            {
                tabControl.TabPages[0].PageEnabled = true;
                tabControl.TabPages[1].PageEnabled = true;
                tabControl.SelectedTabPageIndex = 0;
                return;
            }
            if (action == 3)
            {
                tabControl.TabPages[0].PageEnabled = false;
                tabControl.TabPages[1].PageEnabled = true;
                tabControl.SelectedTabPageIndex = 1;
                return;
            }
            if (action == 4)
            {
                tabControl.TabPages[0].PageEnabled = false;
                tabControl.TabPages[1].PageEnabled = true;
                tabControl.SelectedTabPageIndex = 1;
                return;
            }
            if (action == 5)
            {
                tabControl.TabPages[0].PageEnabled = true;
                tabControl.TabPages[1].PageEnabled = true;
                tabControl.SelectedTabPageIndex = 1;
                return;
            }
        }
        /// <summary>
@@ -1188,6 +1342,18 @@
            if (str.ToUpper() == "true".ToUpper())
                return 1;
            return 0;
        }
        public static bool ToBoole(string str)
        {
            if (str.ToUpper() == "true".ToUpper())
                return true;
            return false;
        }
        public string GetIsNullOrEmpty(string str)
        {
            if (string.IsNullOrEmpty(str.Trim()))
                return "{>";
            return str.Trim();
        }
        /// <summary>
@@ -1329,7 +1495,6 @@
                    }
                }
            }
            return "";
        }
@@ -1382,9 +1547,15 @@
                        btnChkIco.Text = checkStatus;
                        btnChkIco.Visible = true;
                        if (checkStatus == "1" || checkStatus.ToUpper() == true.ToString().ToUpper())
                        {
                            btnChkIco.Image = global::Gs.DevApp.Properties.Resources.ico_check;
                            btnChkIco.Tag = "已审核";
                        }
                        else
                        {
                            btnChkIco.Image = global::Gs.DevApp.Properties.Resources.ico_noCheck;
                            btnChkIco.Tag = "未审核";
                        }
                        btnChkIco.Anchor = AnchorStyles.Top | AnchorStyles.Right; // 靠右
                        btnChkIco.Location = new Point(fm.ClientSize.Width - btnChkIco.Width - 20, 80); // 距离顶部10像素
                    }
@@ -1443,22 +1614,31 @@
            }
            return _sbSqlWhere.ToString();
        }
        public delegate void DelegateGetModel(string guid);
        public delegate void DelegateGetList(int currentPage);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gridView1">gridview</param>
        /// <param name="btnChkIco">图标按钮</param>
        /// <param name="fm">当前窗体</param>
        /// <param name="picCheckBox">图标按钮</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 = "")
        /// <param name="action"></param>
        public static void SetGridViewParameter(GridView gridView1, PictureBox picCheckBox = null, Form fm = null, string fileName = "checkStatus", string icoName = "", DelegateGetModel action = null)
        {
            //   gridView1.OptionsView.ColumnAutoWidth = false;自动调整列宽
            gridView1.OptionsView.ColumnAutoWidth = false;//自动调整列宽
            foreach (GridColumn column in gridView1.Columns)
            {
                column.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                column.OptionsFilter.ImmediateUpdateAutoFilter = false;
                // column.OptionsColumn.AllowEdit = false;
                column.OptionsColumn.AllowEdit = true;
                if (column.Tag == null || column.Tag.ToString().EndsWith("edit"))
                    column.OptionsColumn.ReadOnly = false;
                else
                    column.OptionsColumn.ReadOnly = true;
                if (column.Tag == null || column.Tag.ToString().Length <= 0)
                    column.OptionsFilter.AllowAutoFilter = false;
            }
@@ -1483,13 +1663,66 @@
                    e.Bounds.Top + 45, e.Bounds.Right - 5, e.Bounds.Height - 5);
                e.Graphics.DrawString(str, f, Brushes.Gray, r);
            };
            if (btnChkIco != null)
            if (picCheckBox != null)
            {
                gridView1.FocusedRowChanged += (s, e) =>
                {
                    UtilityHelper.SetCheckIco(s, btnChkIco, fm, fileName, icoName);
                    UtilityHelper.SetCheckIco(s, picCheckBox, fm, fileName, icoName);
                };
            }
            if (action != null)
            {
                gridView1.ShownEditor += (sender, e) =>
                {
                    DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
                    view.ActiveEditor.DoubleClick += (ssssss, eeeeeee) =>
                    {
                        int _handle = gridView1.FocusedRowHandle;
                        if (_handle == -1)
                            return;
                        DataRow row = gridView1.GetDataRow(_handle);
                        if (row == null)
                            return;
                        string _guid = row["guid"].ToString();
                        if (string.IsNullOrEmpty(_guid))
                            return;
                        action(_guid);
                    };
                    if (view.ActiveEditor is TextEdit)
                        view.ActiveEditor.MouseUp += ActiveEditor_MouseUp;
                };
            }
        }
        private static void ActiveEditor_MouseUp(object sender, MouseEventArgs e)
        {
            BaseEdit edit = sender as BaseEdit;
            edit.MouseUp -= ActiveEditor_MouseUp;
            edit.SelectAll();
        }
        public static void SetTabParameter(GridView gridView1, DevExpress.XtraTab.XtraTabControl xtraTabControl1, UcPageBar pageBar1, DelegateGetModel action = null, DelegateGetList page = null)
        {
            xtraTabControl1.SelectedPageChanged += (s, e) =>
            {
                if (xtraTabControl1.SelectedTabPageIndex == 1)
                {
                    int _handle = gridView1.FocusedRowHandle;
                    if (_handle == -1)
                        return;
                    DataRow row = gridView1.GetDataRow(_handle);
                    if (row == null)
                        return;
                    string _guid = row["guid"].ToString();
                    if (string.IsNullOrEmpty(_guid))
                        return;
                    action(_guid);
                }
                if (xtraTabControl1.SelectedTabPageIndex == 0)
                {
                    page(pageBar1.CurrentPage);
                }
            };
        }
        /// <summary>
@@ -1500,8 +1733,9 @@
        /// <param name="fm"></param>
        /// <param name="fileName"></param>
        /// <param name="icoName"></param>
        public static void SetGridSearMx(GridView gridView1)
        public static void SetGridViewParameterMx(GridView gridView1)
        {
            gridView1.OptionsView.ColumnAutoWidth = false;//自动调整列宽
            gridView1.OptionsFilter.AllowFilterEditor = false;
            gridView1.OptionsFilter.ShowCustomFunctions = DevExpress.Utils.DefaultBoolean.False;
            gridView1.OptionsCustomization.AllowFilter = false;
@@ -1549,8 +1783,6 @@
            Regex regex = new Regex("^[0-9]+$");
            return regex.IsMatch(str);
        }
    }