|
@@ -1,4 +1,5 @@
|
|
|
-using DevExpress.Utils;
|
|
|
+using DevExpress.Office.Crypto;
|
|
|
+using DevExpress.Utils;
|
|
|
using DevExpress.Utils.Menu;
|
|
|
using DevExpress.Utils.Svg;
|
|
|
using DevExpress.XtraBars;
|
|
@@ -22,6 +23,7 @@ using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Xml.Linq;
|
|
|
+using XdCxRhDW.Core;
|
|
|
|
|
|
public static class GridControlEx
|
|
|
{
|
|
@@ -38,8 +40,10 @@ public static class GridControlEx
|
|
|
/// </summary>
|
|
|
/// <param name="grid"></param>
|
|
|
/// <param name="rowHeight"></param>
|
|
|
+ /// <typeparam name="T">绑定的数据源模型类型</typeparam>
|
|
|
+ /// <param name="searchLookUpEdit">searchLookUpEditd控件</param>
|
|
|
/// <returns></returns>
|
|
|
- public static GridControl Init(this GridControl grid, int rowHeight = 24)
|
|
|
+ public static GridControl Init<T>(this GridControl grid, int rowHeight = 24, Control searchLookUpEdit = null)
|
|
|
{
|
|
|
grid.MainView.BorderStyle = BorderStyles.Flat;
|
|
|
var view = grid.MainView as GridView;
|
|
@@ -74,29 +78,67 @@ public static class GridControlEx
|
|
|
|
|
|
view.PopupMenuShowing += View_PopupMenuShowing;
|
|
|
view.OptionsSelection.EnableAppearanceFocusedCell = false;
|
|
|
+ string GetLayoutName()
|
|
|
+ {
|
|
|
+ Control ctrl;
|
|
|
+ if (searchLookUpEdit != null)
|
|
|
+ ctrl = searchLookUpEdit;
|
|
|
+ else
|
|
|
+ ctrl = grid;
|
|
|
+ while (ctrl.Parent != null)
|
|
|
+ {
|
|
|
+ ctrl = ctrl.Parent;
|
|
|
+ if (ctrl is UserControl) break;
|
|
|
+ }
|
|
|
+ var props = typeof(T).GetProperties();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ foreach (var item in props)
|
|
|
+ {
|
|
|
+ sb.Append(item.Name);
|
|
|
+ }
|
|
|
+ var md5 = MD5Helper.StrToMD5(sb.ToString());
|
|
|
+ if (searchLookUpEdit != null)
|
|
|
+ return $"{ctrl.Name}_{searchLookUpEdit.Name}_{md5}";
|
|
|
+ else
|
|
|
+ return $"{ctrl.Name}_{grid.Name}_{md5}";
|
|
|
+ }
|
|
|
+ string name = GetLayoutName();
|
|
|
grid.Load += (sender, e) =>
|
|
|
{
|
|
|
- var frm = grid.FindForm();
|
|
|
+ Form frm = null;
|
|
|
+ if (searchLookUpEdit == null)
|
|
|
+ frm = grid.FindForm();
|
|
|
+ else
|
|
|
+ frm = searchLookUpEdit.FindForm();
|
|
|
if (frm != null)
|
|
|
{
|
|
|
- frm.FormClosing += (sender2, e2) =>
|
|
|
+ //frm.FormClosing += (sender2, e2) =>
|
|
|
+ //{
|
|
|
+ // if (e2.CloseReason == CloseReason.UserClosing || e2.CloseReason == CloseReason.MdiFormClosing)
|
|
|
+ // {
|
|
|
+ // Directory.CreateDirectory("Layout");
|
|
|
+ // if (name == null) return;
|
|
|
+ // grid.MainView?.SaveLayoutToXml($"Layout\\{name}.xml", OptionsLayoutBase.FullLayout);
|
|
|
+ // }
|
|
|
+ //};
|
|
|
+ frm.VisibleChanged += (sender2, e2) =>
|
|
|
{
|
|
|
- if (e2.CloseReason == CloseReason.UserClosing||e2.CloseReason== CloseReason.MdiFormClosing)
|
|
|
- {
|
|
|
- Directory.CreateDirectory("Layout");
|
|
|
- grid.MainView?.SaveLayoutToXml($"Layout\\{grid.Name}.xml", OptionsLayoutBase.FullLayout);
|
|
|
- }
|
|
|
+ Directory.CreateDirectory("Layout");
|
|
|
+ if (name == null) return;
|
|
|
+ grid.MainView?.SaveLayoutToXml($"Layout\\{name}.xml", OptionsLayoutBase.FullLayout);
|
|
|
};
|
|
|
}
|
|
|
};
|
|
|
- string file = $"Layout\\{grid.Name}.xml";
|
|
|
- if (File.Exists(file))
|
|
|
- view.RestoreLayoutFromXml(file, OptionsLayoutBase.FullLayout);
|
|
|
+ if (name != null && File.Exists($"Layout\\{name}.xml"))
|
|
|
+ {
|
|
|
+ view.RestoreLayoutFromXml($"Layout\\{name}.xml", OptionsLayoutBase.FullLayout);
|
|
|
+ }
|
|
|
view.KeyUp += View_KeyUp;
|
|
|
grid.Tag = new GridTag();
|
|
|
return grid;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public static GridControl UseExportCsv(this GridControl grid)
|
|
|
{
|
|
|
GridTag tag = grid.Tag as GridTag;
|