lu
2025-03-20 3a6e552259847fee78104ebda0a18dbf889df1d5
DevApp/Gs.DevApp/UserControl/UcToolBarMenu.cs
@@ -2,17 +2,22 @@
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Commands;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraLayout;
using Gs.DevApp.DevFrm.Rpt;
using Gs.DevApp.DevFrm.Sys;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Gs.DevApp.UserControl
{
@@ -54,7 +59,7 @@
            var lst = new List<string>();
            foreach (BarItem item in barManager1.Items)
                if (item is BarLargeButtonItem largeButtonItem)
                    if (!string.IsNullOrEmpty(item.Caption) && item.Caption != "保存" && item.Caption != "刷新")
                    if (!string.IsNullOrEmpty(item.Caption) && item.Caption != "保存" && item.Caption != "刷新" && item.Caption != "帮助" && item.Caption != "保存版面" && item.Caption != "取消")
                        lst.Add(item.Caption);
            actions = lst;
        }
@@ -652,9 +657,19 @@
            Gs.DevApp.ToolBox.MsgHelper.ShowInformation(_rtnJson.rtnMsg);
        }
        private void BtnLayout_ItemClick(object sender, ItemClickEventArgs e)
        private void BtnLayout_ItemClick(object sender, ItemClickEventArgs ee)
        {
            if (btnLayoutClick != null) btnLayoutClick(this, e);
            Form parentForm = this.Parent as Form;
            string _formNamespace = parentForm.GetType().FullName;
            if (parentForm != null)
            {
                List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = getGvList();
                List<DevExpress.XtraLayout.LayoutControl> layList = getLayList();
                List<DevExpress.XtraEditors.SplitContainerControl> spcList = getSpcList();
                Gs.DevApp.UserControl.showLayOut DevFrm = new showLayOut(_formNamespace, gvList, layList, spcList);
                DevFrm.ShowDialog();
            }
            //if (btnLayoutClick != null) btnLayoutClick(this, ee);
        }
        private void _enabledBtn(List<string> lstBtn)
        {
@@ -699,6 +714,19 @@
                    JsonConvert.SerializeObject(_obj));
                var dd = UtilityHelper.ReturnToList(strReturn);
                var dt = dd.rtnData;
                if (!string.IsNullOrEmpty(defaultActions) && defaultActions.Contains("查询")) {
                    if (dt == null || dt.Rows.Count <= 0)
                    {
                        dt.Columns.Add("guid", typeof(string));
                        dt.Columns.Add("name", typeof(string));
                    }
                    DataRow newRow = dt.NewRow();
                    newRow["guid"] = Guid.NewGuid().ToString();
                    newRow["name"] = "查询";
                    dt.Rows.Add(newRow);
                }
                var _enabledList = new List<string>();
                foreach (BarItem item in barManager1.Items)
                {
@@ -781,6 +809,7 @@
                //默认启用的按钮
                _enabledList.Add(btnLoad.Name);
                _enabledList.Add(btnHelp.Name);
                _enabledList.Add(btnLayout.Name);
                _enabledBtn(_enabledList);
            }
            catch (Exception ex)
@@ -823,7 +852,7 @@
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
                return true;
                return false;
            }
            return false;
        }
@@ -974,7 +1003,7 @@
        public event EventHandler btnWgClick;
        public event EventHandler btnLayoutClick;
        //public event EventHandler btnLayoutClick;
        #endregion
@@ -1016,8 +1045,196 @@
        /// 当前状态
        /// </summary>
        public string currentAction { get; set; }
        public string defaultActions { get; set; }
        #endregion
        /// <summary>
        /// 查找gridView
        /// </summary>
        /// <returns></returns>
        private List<DevExpress.XtraGrid.Views.Grid.GridView> getGvList()
        {
            Form parentForm;
            if (this.Parent is Form)
                parentForm = this.Parent as Form;
            else
                parentForm = this.Parent.Parent as Form;
            List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
            //查找gridview,主页面
            GridControl gcMain = parentForm.Controls.Find("gcMain1", true).OfType<GridControl>().FirstOrDefault();
            if (gcMain != null)
            {
                GridView gv1 = gcMain.MainView as GridView;
                if (gv1 != null)
                {
                    gvList.Add(gv1);
                }
            }
            GridControl mx = parentForm.Controls.Find("gcMx1", true).OfType<GridControl>().FirstOrDefault();
            if (mx != null)
            {
                GridView gv1 = mx.MainView as GridView;
                if (gv1 != null)
                {
                    gvList.Add(gv1);
                }
            }
            GridControl mx2 = parentForm.Controls.Find("gcMx2", true).OfType<GridControl>().FirstOrDefault();
            if (mx2 != null)
            {
                GridView gv1 = mx2.MainView as GridView;
                if (gv1 != null)
                {
                    gvList.Add(gv1);
                }
            }
            return gvList;
        }
        /// <summary>
        /// 查找LayoutControl
        /// </summary>
        /// <returns></returns>
        private List<DevExpress.XtraLayout.LayoutControl> getLayList()
        {
            Form parentForm;
            if (this.Parent is Form)
                parentForm = this.Parent as Form;
            else
                parentForm = this.Parent.Parent as Form;
            List<DevExpress.XtraLayout.LayoutControl> layList = new List<DevExpress.XtraLayout.LayoutControl>();
            DevExpress.XtraLayout.LayoutControl lay2 = parentForm.Controls.Find("layoutMx1", true).OfType<DevExpress.XtraLayout.LayoutControl>().FirstOrDefault();
            if (lay2 != null)
            {
                layList.Add(lay2);
            }
            return layList;
        }
        /// <summary>
        /// 查找SplitContainerControl
        /// </summary>
        /// <returns></returns>
        private List<DevExpress.XtraEditors.SplitContainerControl> getSpcList()
        {
            Form parentForm;
            if (this.Parent is Form)
                parentForm = this.Parent as Form;
            else
                parentForm = this.Parent.Parent as Form;
            List<DevExpress.XtraEditors.SplitContainerControl> spcList = new List<DevExpress.XtraEditors.SplitContainerControl>();
            DevExpress.XtraEditors.SplitContainerControl spc1 = parentForm.Controls.Find("split1", true).OfType<DevExpress.XtraEditors.SplitContainerControl>().FirstOrDefault();
            DevExpress.XtraEditors.SplitContainerControl spc2 = parentForm.Controls.Find("splitMx1", true).OfType<DevExpress.XtraEditors.SplitContainerControl>().FirstOrDefault();
            if (spc1 != null)
            {
                spcList.Add(spc1);
            }
            if (spc2 != null)
            {
                spcList.Add(spc2);
            }
            return spcList;
        }
        /// <summary>
        /// 读取xml配置,目前配置gcMain1,layoutMx1
        /// </summary>
        public void getXmlConfig()
        {
            Form parentForm;
            if (this.Parent is Form)
                parentForm = this.Parent as Form;
            else
                parentForm = this.Parent.Parent as Form;
            string _formNamespace = parentForm.GetType().FullName;
            List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = getGvList();
            List<DevExpress.XtraLayout.LayoutControl> layList = getLayList();
            List<DevExpress.XtraEditors.SplitContainerControl> spcList = getSpcList();
            JArray array = new JArray();
            var _obj = new
            {
                formPath = _formNamespace,
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", "Fm/GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    JObject _job = JObject.Parse(strJson);
                    foreach (var a in _job["rtnData"]["list"])
                    {
                        //string _id = a["controlId"].ToString();
                        //string _controlType = a["controlType"].ToString();
                        //string _controlXml = a["controlXml"].ToString();
                        //string _splitterPosition = a["splitterPosition"].ToString();
                        array.Add(a);
                    }
                    foreach (GridView gv in gvList)
                    {
                        JToken john = array.FirstOrDefault(t => t["controlId"].ToString().ToUpper() == gv.Name.ToString().Trim().ToUpper());
                        if (john != null)
                        {
                            string controlId = john["controlId"].ToString();
                            string controlXml = john["controlXml"].ToString();
                            byte[] byteArray = Encoding.UTF8.GetBytes(controlXml);
                            using (var stream = new MemoryStream(byteArray))
                            {
                                gv.RestoreLayoutFromStream(stream);
                            }
                        }
                    }
                    foreach (LayoutControl lay in layList)
                    {
                        JToken john = array.FirstOrDefault(t => t["controlId"].ToString().ToUpper() == lay.Name.ToString().Trim().ToUpper());
                        if (john != null)
                        {
                            string controlId = john["controlId"].ToString();
                            string controlXml = john["controlXml"].ToString();
                            byte[] byteArray = Encoding.UTF8.GetBytes(controlXml);
                            using (var stream = new MemoryStream(byteArray))
                            {
                                lay.RestoreLayoutFromStream(stream);
                            }
                        }
                    }
                    foreach (SplitContainerControl spt in spcList)
                    {
                        JToken john = array.FirstOrDefault(t => t["controlId"].ToString().ToUpper() == spt.Name.ToString().Trim().ToUpper());
                        if (john != null)
                        {
                            string controlId = john["controlId"].ToString();
                            string controlXml = john["controlXml"].ToString();
                            // string splitterPosition = john["splitterPosition"].ToString();
                            byte[] byteArray = Encoding.UTF8.GetBytes(controlXml);
                            using (var stream = new MemoryStream(byteArray))
                            {
                                spt.RestoreLayoutFromStream(stream);
                            }
                            spt.Horizontal = false;
                            spt.Panel1.AutoScroll = false;
                            spt.Panel2.AutoScroll = false;
                            //spt.Panel1.MaximumSize = new System.Drawing.Size(spt.Panel1.Width, 100);
                            // spt.SplitterPosition = int.Parse( splitterPosition);
                            spt.ShowSplitGlyph = DevExpress.Utils.DefaultBoolean.True;
                            if (spt.Name.Contains("Mx"))
                                spt.FixedPanel = DevExpress.XtraEditors.SplitFixedPanel.Panel1;
                            else
                                spt.FixedPanel = DevExpress.XtraEditors.SplitFixedPanel.Panel2;
                        }
                    }
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}