lg
2024-09-22 c115ac388af5a6928716f0146a75a2a42fb27d8e
DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
@@ -15,7 +15,6 @@
using DevExpress.XtraEditors;
using DevExpress.XtraTab;
using System.Text.RegularExpressions;
using System.Xml;
using System.Collections.Generic;
namespace Gs.DevApp.ToolBox
@@ -75,6 +74,17 @@
            }
            return responseStr;
        }
        /// <summary>
        /// 读取默认页大小
        /// </summary>
        /// <returns></returns>
        public static int GetPageSize()
        {
            return 50;
            // return int.Parse(System.Configuration.ConfigurationSettings.AppSettings.Get("PageSize").ToString());
        }
        /// <summary>
        /// 根据图片名读取资源文件,不带后缀名
        /// </summary>
@@ -114,11 +124,11 @@
            return token;
        }
        /// <summary>
        /// 标准json串返回ReturnModel-->table,
        /// 标准json返回ReturnModel-->包含TablePage分页,
        /// </summary>
        /// <param name="strReturn"></param>
        /// <returns></returns>
        public static ReturnModel<PageListModel> GetTableByJson(string strReturn)
        public static ReturnModel<PageListModel> ReturnToTablePage(string strReturn)
        {
            ReturnModel<PageListModel> rto = new ReturnModel<PageListModel>();
            JObject json = JObject.Parse(strReturn);
@@ -139,11 +149,11 @@
            return rto;
        }
        /// <summary>
        /// 标准json串返回ReturnModel->字符串,
        /// 标准json返回ReturnModel,
        /// </summary>
        /// <param name="strReturn"></param>
        /// <returns></returns>
        public static ReturnModel<dynamic> GetDataByJson(string strReturn)
        public static ReturnModel<dynamic> ReturnToDynamic(string strReturn)
        {
            ReturnModel<dynamic> rto = new ReturnModel<dynamic>();
            JObject json = JObject.Parse(strReturn);
@@ -154,11 +164,11 @@
        }
        /// <summary>
        /// 标准json串返回ReturnModel-->table,
        /// 标准json串返回ReturnModel-->仅仅有list,不分页,
        /// </summary>
        /// <param name="strReturn"></param>
        /// <returns></returns>
        public static ReturnModel<DataTable> GetNoPageTableByJson(string strReturn)
        public static ReturnModel<DataTable> ReturnToList(string strReturn)
        {
            ReturnModel<DataTable> rto = new ReturnModel<DataTable>();
            JObject json = JObject.Parse(strReturn);
@@ -174,17 +184,6 @@
            DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
            rto.rtnData = dt;
            return rto;
        }
        /// <summary>
        /// 读取默认页大小
        /// </summary>
        /// <returns></returns>
        public static int GetPageSize()
        {
            return 50;
            // return int.Parse(System.Configuration.ConfigurationSettings.AppSettings.Get("PageSize").ToString());
        }
        /// <summary>
@@ -297,7 +296,7 @@
        /// </summary>
        /// <param name="controls">controls:为groupBox1.Controls/panel1.Controls</param>
        /// <param name="isEdt">是否可编辑</param>
        public static void CleanValue(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null)
        public static void CleanValueByControl(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null)
        {
            if (gridViews != null)
            {
@@ -342,7 +341,7 @@
        /// </summary>
        /// <param name="controls">controls:为groupBox1.Controls/panel1.Controls</param>
        /// <param name="isEdt">是否可编辑</param>
        public static void ChangeEnable(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null)
        public static void ChangeEnableByControl(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null)
        {
            if (gridViews != null)
            {
@@ -351,8 +350,10 @@
                    gv.OptionsBehavior.Editable = isEdt;
                }
            }
            foreach (Control ctrl in controls)
            {
                ctrl.Enabled = isEdt;
                //文本
                if (ctrl is TextEdit)
                {
@@ -379,7 +380,7 @@
        /// </summary>
        /// <param name="tabControl">选项卡容器</param>
        /// <param name="idx">从0开始,如果是999,则全部可用</param>
        public static void ChangeTab(XtraTabControl tabControl, int idx)
        public static void JumpToTab(XtraTabControl tabControl, int idx)
        {
            if (idx == 999)
            {
@@ -397,7 +398,6 @@
            tabControl.TabPages[idx].PageEnabled = true;
            tabControl.SelectedTabPageIndex = idx;
        }
        public static void TreeViewCheck(TreeViewEventArgs e)
        {
@@ -459,45 +459,114 @@
            string dd = Regex.Replace(propertyName, @"_([a-z])", m => m.Groups[1].Value.ToUpper());
            return dd;
        }
        public static void UpdateAppConfig(string key, string newValue)
        {
            string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(configFile);
            XmlNode node = xmlDoc.SelectSingleNode($"//appSettings//add[@key='{key}']");
            if (node != null)
        /// <summary>
        ///
        /// </summary>
        /// <param name="xtraTabControl1"></param>
        /// <param name="lbGuid">编辑框中的主键名</param>
        /// <param name="txtName">编辑框中的文本框名</param>
        /// <param name="gridView1"></param>
        /// <param name="gridRowName">列表中的文本列名</param>
        /// <param name="SelectedTabPageIndex"></param>
        /// <returns></returns>
        public static (string, string) GetCurrentRow(XtraTabControl xtraTabControl1
            , System.Windows.Forms.Label lbGuid
            , DevExpress.XtraEditors.TextEdit txtName
            , DevExpress.XtraGrid.Views.Grid.GridView gridView1
            , int SelectedTabPageIndex = 1)
        {
            string _strGuid = "";
            string _strName = "";
            if (xtraTabControl1.SelectedTabPageIndex == SelectedTabPageIndex && lbGuid.Text.Length > 10)
            {
                XmlAttribute attribute = node as XmlAttribute;
                attribute.Value = newValue;
                xmlDoc.Save(configFile);
                _strGuid = lbGuid.Text.Trim();
                _strName = txtName.Text.Trim();
            }
            else
            {
                DataRow dr = gridView1.GetFocusedDataRow();
                if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString()))
                {
                }
                else {
                    _strGuid = dr["guid"].ToString();
                    _strName = dr[1].ToString();
                }
            }
            return (_strGuid, _strName);
        }
        public class CboItemEntity
        public static (string, string) GetCurrentRow(XtraTabControl xtraTabControl1
            , System.Windows.Forms.Label lbGuid
            , DevExpress.XtraEditors.TextEdit txtName
            , System.Windows.Forms.TreeView tlMenu
            , int SelectedTabPageIndex = 1)
        {
            private object _text = 0;
            private object _Value = "";
            /// <summary>
            /// 显示值
            /// </summary>
            public object Text
            string _strGuid = "";
            string _strName = "";
            if (xtraTabControl1.SelectedTabPageIndex == SelectedTabPageIndex && lbGuid.Text.Length > 10)
            {
                get { return this._text; }
                set { this._text = value; }
                _strGuid = lbGuid.Text.Trim();
                _strName = txtName.Text.Trim();
            }
            /// <summary>
            /// 对象值
            /// </summary>
            public object Value
            else
            {
                get { return this._Value; }
                set { this._Value = value; }
                TreeNode clickedNode = tlMenu.SelectedNode;
                if (clickedNode != null)
                {
                    _strGuid = clickedNode.Name.ToString();
                    _strName = clickedNode.Text.Trim();
                }
            }
            return (_strGuid, _strName);
        }
        public static (string, string) GetCurrentRow(XtraTabControl xtraTabControl1
            , System.Windows.Forms.Label lbGuid
             , DevExpress.XtraEditors.TextEdit txtName
            , DevExpress.XtraTreeList.TreeList tlMenu
            , int SelectedTabPageIndex = 1)
        {
            string _strGuid = "";
            string _strName = "";
            if (xtraTabControl1.SelectedTabPageIndex == SelectedTabPageIndex && lbGuid.Text.Length > 10)
            {
                _strGuid = lbGuid.Text.Trim();
                _strName = txtName.Text.Trim();
            }
            else
            {
                _strGuid = tlMenu.FocusedNode.GetValue("guid").ToString();
                _strName = tlMenu.FocusedNode.GetValue(0).ToString();
            }
            return (_strGuid, _strName);
        }
    }
            public override string ToString()
            {
                return this.Text.ToString();
            }
    public class CboItemEntity
    {
        private object _text = 0;
        private object _Value = "";
        /// <summary>
        /// 显示值
        /// </summary>
        public object Text
        {
            get { return this._text; }
            set { this._text = value; }
        }
        /// <summary>
        /// 对象值
        /// </summary>
        public object Value
        {
            get { return this._Value; }
            set { this._Value = value; }
        }
        public override string ToString()
        {
            return this.Text.ToString();
        }
    }
}