lu
2025-04-14 ecb7a60de1639f520712ce95f99414b0dd2c9713
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraLayout;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
 
namespace Gs.DevApp.UserControl
{
    public partial class showLayOut : DevExpress.XtraEditors.XtraForm
    {
        string formNamespace = "";
        List<GridView> gridViews = new List<GridView>();
        List<DevExpress.XtraLayout.LayoutControl> layList = new List<DevExpress.XtraLayout.LayoutControl>();
        List<DevExpress.XtraEditors.SplitContainerControl> spcList = new List<DevExpress.XtraEditors.SplitContainerControl>();
        public showLayOut(string _formNamespace, List<GridView> _gridViews, List<DevExpress.XtraLayout.LayoutControl> _layList, List<DevExpress.XtraEditors.SplitContainerControl> _spcList)
        {
            formNamespace = _formNamespace;
            gridViews = _gridViews;
            layList = _layList;
            spcList = _spcList;
            InitializeComponent();
            this.btnCancel.Click += BtnCancel_Click;
            this.btnSave.Click += BtnSave_Click;
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            _setLyout();
        }
 
        private void BtnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
 
        private void _setLyout()
        {
            if (txt_layOut.SelectedIndex <= 0)
            {
                MsgHelper.Warning("请选择适用范围!");
                return;
            }
            List<dynamic> xmlList = new List<dynamic>();
            foreach (GridView gridView1 in gridViews)
            {
                System.IO.Stream stream = new System.IO.MemoryStream();
                gridView1.SaveLayoutToStream(stream);
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                StringBuilder sb = new StringBuilder();
                using (StreamReader reader = new StreamReader(stream))
                {
                    char[] buffer = new char[4096]; // 缓冲区大小根据需要调整
                    int numCharsRead;
                    while ((numCharsRead = reader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        sb.Append(buffer, 0, numCharsRead);
                    }
                }
                xmlList.Add(
                       new { idType = "gridview", idName = gridView1.Name, idXml = sb.ToString(), splitterPosition = "" }
                 );
            }
            foreach (LayoutControl lay1 in layList)
            {
                System.IO.Stream stream = new System.IO.MemoryStream();
                lay1.SaveLayoutToStream(stream);
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                StringBuilder sb = new StringBuilder();
                using (StreamReader reader = new StreamReader(stream))
                {
                    char[] buffer = new char[4096]; // 缓冲区大小根据需要调整
                    int numCharsRead;
                    while ((numCharsRead = reader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        sb.Append(buffer, 0, numCharsRead);
                    }
                }
                xmlList.Add(
                       new { idType = "layoutcontrol ", idName = lay1.Name, idXml = sb.ToString(), splitterPosition = "" }
                 );
            }
            foreach (SplitContainerControl splt in spcList)
            {
                System.IO.Stream stream = new System.IO.MemoryStream();
                splt.SaveLayoutToStream(stream);
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                StringBuilder sb = new StringBuilder();
                using (StreamReader reader = new StreamReader(stream))
                {
                    char[] buffer = new char[4096]; // 缓冲区大小根据需要调整
                    int numCharsRead;
                    while ((numCharsRead = reader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        sb.Append(buffer, 0, numCharsRead);
                    }
                }
                xmlList.Add(
                       new { idType = "splitcontainercontrol ", idName = splt.Name, idXml = sb.ToString(), splitterPosition = splt.SplitterPosition }
                 );
            }
            var _obj = new
            {
                xmlList = xmlList,
                formPath = formNamespace,
                intType = txt_layOut.SelectedIndex,
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("", "Fm/EditModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnData.outMsg);
                if (_rtn.rtnCode > 0)
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    DialogResult = DialogResult.None;
                }
            }
            catch (Exception ex)
            {
                DialogResult = DialogResult.Cancel;
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}