From 2ce5f9b653e0a9a125e0e2b5ce9ecd5cce97365e Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Fri, 2 Apr 2021 09:29:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20=D0=B8=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DesktopTools/Interfaces/IControl.cs | 12 +++++ .../Interfaces/IControlViewEntityElement.cs | 12 +++++ .../Interfaces/IControlViewEntityList.cs | 12 +++++ .../GenericControlEntityElement.cs | 36 +++++++++++-- .../MainControls/GenericControlEntityList.cs | 52 +++++++++++++++---- .../MainControlViewEntityElement.cs | 4 ++ .../MainControls/MainControlViewEntityList.cs | 4 ++ .../FormMain.Designer.cs | 32 ++++-------- .../DepartmentPortalDesctop/FormMain.cs | 8 +-- .../DepartmentPortalDesctop/Program.cs | 2 +- 10 files changed, 135 insertions(+), 39 deletions(-) diff --git a/DepartmentPortal/Common/DesktopTools/Interfaces/IControl.cs b/DepartmentPortal/Common/DesktopTools/Interfaces/IControl.cs index 8488cf7..c4da828 100644 --- a/DepartmentPortal/Common/DesktopTools/Interfaces/IControl.cs +++ b/DepartmentPortal/Common/DesktopTools/Interfaces/IControl.cs @@ -35,5 +35,17 @@ namespace DesktopTools.Interfaces /// /// void Open(ControlOpenModel model); + + /// + /// Сохранение настроек в xml-строку + /// + /// + string SaveToXml(); + + /// + /// Загрузка настроек из xml-строки + /// + /// + void LoadFromXml(string xml); } } \ No newline at end of file diff --git a/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityElement.cs b/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityElement.cs index 7aaecfd..69bcdbf 100644 --- a/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityElement.cs +++ b/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityElement.cs @@ -18,5 +18,17 @@ namespace DesktopTools.Interfaces /// /// IControl GetInstanceControl(); + + /// + /// Сохранение настроек в xml-строку + /// + /// + string SaveControlToXml(); + + /// + /// Загрузка настроек из xml-строки + /// + /// + void LoadControlFromXml(string xml); } } \ No newline at end of file diff --git a/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityList.cs b/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityList.cs index 0720e52..80f5ba2 100644 --- a/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityList.cs +++ b/DepartmentPortal/Common/DesktopTools/Interfaces/IControlViewEntityList.cs @@ -25,5 +25,17 @@ namespace DesktopTools.Interfaces /// /// string GetTitleFromIdControl(Guid id); + + /// + /// Сохранение настроек в xml-строку + /// + /// + string SaveControlToXml(); + + /// + /// Загрузка настроек из xml-строки + /// + /// + void LoadControlFromXml(string xml); } } \ No newline at end of file diff --git a/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityElement.cs b/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityElement.cs index ac5534d..81f8d9c 100644 --- a/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityElement.cs +++ b/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityElement.cs @@ -13,6 +13,7 @@ using System; using System.Linq; using System.Reflection; using System.Windows.Forms; +using System.Xml.Linq; namespace DesktopTools.Controls { @@ -50,14 +51,29 @@ namespace DesktopTools.Controls /// private event Action CloseElementEvent; + /// + /// События установки одинаковой ширины для заголовков контролов + /// private event Action SetTitleWidth; + /// + /// Событие установки значения + /// private event Action SetValues; + /// + /// Событие сброса значения в исходное состояние + /// private event Action DropValues; + /// + /// Событие проверки заполненности контрола + /// private event Func CheckValues; + /// + /// Событие получения значения из контрола + /// private event Action GetValues; private E Element @@ -79,7 +95,7 @@ namespace DesktopTools.Controls } if (page.Controls[0] is IControlChildEntity cntrl) { - cntrl.ParentObject = _element; + cntrl.ParentId = _element.Id; cntrl.Open(new ControlOpenModel { OpenMode = ControlOpenMode.Child }); } } @@ -129,6 +145,20 @@ namespace DesktopTools.Controls Dock = DockStyle.Fill; } + public IControl GetInstanceControl() => _genericControlViewEntityElement?.GetInstanceGenericControl(); + + public string SaveControlToXml() => new XElement("Control", + new XAttribute("Type", GetType().FullName), + new XAttribute("ControlId", ControlId), + new XAttribute("Title", Title)).ToString(); + + public void LoadControlFromXml(string xml) + { + var control = XElement.Parse(xml).Element("Control"); + ControlId = new Guid(control.Attribute("ControlId").Value.ToString()); + Title = control.Attribute("Title").Value.ToString(); + } + private void InitEvents() { toolStripButtonSave.Click += (object sender, EventArgs e) => { Save(); }; @@ -295,7 +325,7 @@ namespace DesktopTools.Controls } } - public bool Save() + private bool Save() { if (CheckValues.GetInvocationList().Select(x => (bool)x.DynamicInvoke()).ToList().Any(x => !x)) { @@ -334,7 +364,5 @@ namespace DesktopTools.Controls return false; } - - public IControl GetInstanceControl() => _genericControlViewEntityElement?.GetInstanceGenericControl(); } } diff --git a/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityList.cs b/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityList.cs index b0bf6c4..016a3b8 100644 --- a/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityList.cs +++ b/DepartmentPortal/Common/DesktopTools/MainControls/GenericControlEntityList.cs @@ -5,6 +5,7 @@ using DesktopTools.Models; using ModuleTools.Attributes; using ModuleTools.BindingModels; using ModuleTools.BusinessLogics; +using ModuleTools.Enums; using ModuleTools.Extensions; using ModuleTools.ViewModels; using System; @@ -13,6 +14,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml.Linq; namespace DesktopTools.Controls { @@ -94,6 +96,43 @@ namespace DesktopTools.Controls public IControl GetInstanceControl() => _genericControlViewEntityList?.GetInstanceGenericControl(); public string GetTitleFromIdControl(Guid id) => _businessLogic.GetElement(new G { Id = id })?.ToString(); + + public string SaveControlToXml() => new XElement("Control", + new XAttribute("Type", GetType().FullName), + new XAttribute("ControlId", ControlId), + new XAttribute("Title", Title), + new XAttribute("AccessOperation", AccessOperation), + new XElement("Configurate", + new XElement("Page", toolStripTextBoxPage.Text), + new XElement("CountElementsOnPage", toolStripTextBoxCountRecords.Text), + new XElement("PageName", + new XElement("Key", ((toolStripComboBoxPageNames.SelectedItem as PageNamesForPaginationModel)?.Key ?? "-")), + new XElement("Value", ((toolStripComboBoxPageNames.SelectedItem as PageNamesForPaginationModel)?.Value ?? "-"))), + new XElement("ParentId", ParentId?.ToString() ?? "-"))).ToString(); + + public void LoadControlFromXml(string xml) + { + var control = XElement.Parse(xml).Element("Control"); + ControlId = new Guid(control.Attribute("ControlId").Value.ToString()); + Title = control.Attribute("Title").Value.ToString(); + AccessOperation = (AccessOperation)Enum.Parse(typeof(AccessOperation), control.Attribute("AccessOperation").Value.ToString()); + var config = control.Element("Configurate"); + toolStripTextBoxPage.Text = config.Element("Page").Value.ToString(); + toolStripTextBoxCountRecords.Text = config.Element("CountElementsOnPage").Value.ToString(); + if (config.Element("PageName").Element("Key").Value.ToString() != "-") + { + var pageName = new PageNamesForPaginationModel + { + Key = config.Element("PageName").Element("Key").Value.ToString(), + Value = config.Element("PageName").Element("Value").Value.ToString() + }; + toolStripComboBoxPageNames.SelectedItem = pageName; + } + if (config.Element("ParentId").Value.ToString() != "-") + { + ParentId = new Guid(config.Element("ParentId").Value.ToString()); + } + } #endregion /// @@ -330,13 +369,9 @@ namespace DesktopTools.Controls if (ParentPropertyName.IsNotEmpty()) { - if (ParentObject != null) + if (ParentId.HasValue) { - var property = ParentObject.GetType().GetProperty("Id"); - if (property != null) - { - await Task.Run(() => data = GetDataFromParent(new Guid(property.GetValue(ParentObject).ToString()))); - } + await Task.Run(() => data = GetDataFromParent(ParentId.Value)); Visible = true; } else @@ -495,10 +530,9 @@ namespace DesktopTools.Controls try { var control = ControlViewEntityElement.GetInstance() as IControlChildEntity; - var property = ParentObject?.GetType()?.GetProperty("Id"); - if (property != null) + if (ParentId.HasValue) { - control.ParentId = new Guid(property.GetValue(ParentObject).ToString()); + control.ParentId = ParentId; control.ParentPropertyName = ParentPropertyName; } if (toolStripFooter.Visible && toolStripComboBoxPageNames.Visible) diff --git a/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityElement.cs b/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityElement.cs index d571721..1f2934b 100644 --- a/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityElement.cs +++ b/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityElement.cs @@ -24,6 +24,10 @@ namespace DesktopTools.Controls public IControl GetInstance() => _controlViewEntityElement?.GetInstanceControl(); + public string SaveToXml() => _controlViewEntityElement?.SaveControlToXml(); + + public void LoadFromXml(string xml) => _controlViewEntityElement?.LoadControlFromXml(xml); + #endregion #region IControlChildEntity diff --git a/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityList.cs b/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityList.cs index ebac13d..7527b78 100644 --- a/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityList.cs +++ b/DepartmentPortal/Common/DesktopTools/MainControls/MainControlViewEntityList.cs @@ -23,6 +23,10 @@ namespace DesktopTools.Controls public void Open(ControlOpenModel model) => _controlViewEntityList?.OpenControl(model); public IControl GetInstance() => _controlViewEntityList?.GetInstanceControl(); + + public string SaveToXml() => _controlViewEntityList?.SaveControlToXml(); + + public void LoadFromXml(string xml) => _controlViewEntityList?.LoadControlFromXml(xml); #endregion #region IControlEntityList diff --git a/DepartmentPortal/DepartmentPortalDesctop/FormMain.Designer.cs b/DepartmentPortal/DepartmentPortalDesctop/FormMain.Designer.cs index 8b58a4d..18b6b38 100644 --- a/DepartmentPortal/DepartmentPortalDesctop/FormMain.Designer.cs +++ b/DepartmentPortal/DepartmentPortalDesctop/FormMain.Designer.cs @@ -34,12 +34,10 @@ namespace DepartmentPortalDesctop this.dataGridViewControls = new System.Windows.Forms.DataGridView(); this.ColumnControlId = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnControlName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.splitContainerMain = new System.Windows.Forms.SplitContainer(); this.ButtonShowHideControlList = new System.Windows.Forms.Button(); + this.panelControl = new System.Windows.Forms.Panel(); this.panelControls.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewControls)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainerMain)).BeginInit(); - this.splitContainerMain.SuspendLayout(); this.SuspendLayout(); // // menuMain @@ -97,20 +95,6 @@ namespace DepartmentPortalDesctop this.ColumnControlName.Name = "ColumnControlName"; this.ColumnControlName.ReadOnly = true; // - // splitContainerMain - // - this.splitContainerMain.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainerMain.Location = new System.Drawing.Point(216, 24); - this.splitContainerMain.Name = "splitContainerMain"; - this.splitContainerMain.Panel1MinSize = 100; - // - // splitContainerMain.Panel2 - // - this.splitContainerMain.Panel2.AutoScroll = true; - this.splitContainerMain.Size = new System.Drawing.Size(584, 426); - this.splitContainerMain.SplitterDistance = 295; - this.splitContainerMain.TabIndex = 2; - // // ButtonShowHideControlList // this.ButtonShowHideControlList.Dock = System.Windows.Forms.DockStyle.Left; @@ -122,12 +106,20 @@ namespace DepartmentPortalDesctop this.ButtonShowHideControlList.UseVisualStyleBackColor = true; this.ButtonShowHideControlList.Click += new System.EventHandler(this.ButtonShowHideControlList_Click); // + // panelControl + // + this.panelControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.panelControl.Location = new System.Drawing.Point(216, 24); + this.panelControl.Name = "panelControl"; + this.panelControl.Size = new System.Drawing.Size(584, 426); + this.panelControl.TabIndex = 4; + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.splitContainerMain); + this.Controls.Add(this.panelControl); this.Controls.Add(this.ButtonShowHideControlList); this.Controls.Add(this.panelControls); this.Controls.Add(this.menuMain); @@ -138,8 +130,6 @@ namespace DepartmentPortalDesctop this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.panelControls.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewControls)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainerMain)).EndInit(); - this.splitContainerMain.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -149,11 +139,11 @@ namespace DepartmentPortalDesctop private System.Windows.Forms.MenuStrip menuMain; private System.Windows.Forms.Panel panelControls; - private System.Windows.Forms.SplitContainer splitContainerMain; private System.Windows.Forms.Button ButtonShowHideControlList; private System.Windows.Forms.DataGridView dataGridViewControls; private System.Windows.Forms.DataGridViewTextBoxColumn ColumnControlId; private System.Windows.Forms.DataGridViewTextBoxColumn ColumnControlName; + private System.Windows.Forms.Panel panelControl; } } diff --git a/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs b/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs index 6b46bf4..bc107e1 100644 --- a/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs +++ b/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs @@ -74,8 +74,8 @@ namespace DepartmentPortalDesctop ctrl.Open(new ControlOpenModel { OpenMode = ControlOpenMode.List, CloseList = CloseControl }); _controls.Add(ctrl.ControlId, ctrl); - splitContainerMain.Panel1.Controls.Clear(); - splitContainerMain.Panel1.Controls.Add(ctrl as UserControl); + panelControl.Controls.Clear(); + panelControl.Controls.Add(ctrl as UserControl); dataGridViewControls.Rows.Add(new object[] { ctrl.ControlId, ctrl.Title }); dataGridViewControls.Rows[^1].Selected = true; } @@ -132,8 +132,8 @@ namespace DepartmentPortalDesctop { return; } - splitContainerMain.Panel1.Controls.Clear(); - splitContainerMain.Panel1.Controls.Add(ctrl as UserControl); + panelControl.Controls.Clear(); + panelControl.Controls.Add(ctrl as UserControl); } private void ButtonShowHideControlList_Click(object sender, EventArgs e) diff --git a/DepartmentPortal/DepartmentPortalDesctop/Program.cs b/DepartmentPortal/DepartmentPortalDesctop/Program.cs index 86e377a..1bc9463 100644 --- a/DepartmentPortal/DepartmentPortalDesctop/Program.cs +++ b/DepartmentPortal/DepartmentPortalDesctop/Program.cs @@ -28,7 +28,7 @@ namespace DepartmentPortalDesctop if (form.ShowDialog() == DialogResult.OK && securityManager.IsAuth) { - Application.Run(DependencyManager.Instance.Resolve()); + Application.Run(new FormMain()); } } }