private void f_DrawTemplate(Graphics a_Graphics, Rectangle a_Bounds, Cl_Template a_Template, Font a_Font, Color a_ForeColor) { if (a_Template != null) { if (a_Template.p_TemplateElements != null && a_Template.p_TemplateElements.Count > 0) { int top = a_Bounds.Top + 20; for (int i = 0; i < a_Template.p_TemplateElements.Count; i++) { var te = a_Template.p_TemplateElements.ElementAt(i); if (te.p_ChildTemplate != null) { f_DrawTemplate(a_Graphics, a_Bounds, te.p_ChildTemplate, a_Font, a_ForeColor); } else if (te.p_ChildElement != null) { var ctrlEl = new Ctrl_Element() { p_Element = te.p_ChildElement }; ctrlEl.f_Draw(a_Graphics, new Rectangle(a_Bounds.Left + 4, top, a_Bounds.Width, Ctrl_Element.m_ElementHeight), a_Font, a_ForeColor); if (p_Template.p_Type == Cl_Template.E_TemplateType.Table && i < a_Template.p_TemplateElements.Count - 1) { a_Graphics.DrawLine(new Pen(this.p_BorderColor, 1) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash }, a_Bounds.Left + 3, top + Ctrl_Element.m_ElementHeight, a_Bounds.Width - 5, top + Ctrl_Element.m_ElementHeight); } top += Ctrl_Element.m_ElementHeight; } } } } }
/// <summary>Инициализация пользовательских контролов</summary> private void f_AddControlsTemplate(Cl_Template a_Template, ControlCollection a_Controls = null) { if (m_Record != null && a_Template != null) { if (a_Template.p_TemplateElements == null) { var cTe = Cl_App.m_DataContext.Entry(a_Template).Collection(g => g.p_TemplateElements).Query().Include(te => te.p_ChildElement).Include(te => te.p_ChildElement.p_Default).Include(te => te.p_ChildElement.p_ParamsValues).Include(te => te.p_ChildElement.p_PartAgeNorms).Include(te => te.p_ChildTemplate); cTe.Load(); } if (a_Template.p_TemplateElements != null && a_Template.p_TemplateElements.Count > 0) { int top = 0; ControlCollection controls = null; if (a_Controls != null) { controls = a_Controls; } else { controls = ctrlContent.Controls; } foreach (var te in a_Template.p_TemplateElements) { if (te.p_ChildElement != null) { var ctrlEl = new Ctrl_Element(); ctrlEl.p_Element = te.p_ChildElement; ctrlEl.e_ValueChanged += CtrlEl_e_ValueChanged; Cl_RecordValue recval = m_Record.p_Values.FirstOrDefault(v => v.p_ElementID == te.p_ChildElement.p_ID); if (recval == null) { recval = new Cl_RecordValue(); recval.p_ElementID = ctrlEl.p_Element.p_ID; recval.p_Element = ctrlEl.p_Element; recval.p_RecordID = m_Record.p_ID; recval.p_Record = m_Record; } if (controls is TableLayoutControlCollection && controls.Owner is TableLayoutPanel) { var table = (TableLayoutPanel)controls.Owner; table.RowCount++; table.RowStyles.Add(new RowStyle(SizeType.AutoSize)); ctrlEl.f_SetRecordElementValues(recval, table, table.RowCount - 1); } else { ctrlEl.f_SetRecordElementValues(recval); controls.Add(ctrlEl); } ctrlEl.Top = top; ctrlEl.Left = m_PaddingX; top += ctrlEl.Height + m_PaddingY; m_Elements.Add(ctrlEl); } else if (te.p_ChildTemplate != null) { if (te.p_ChildTemplate.p_Type == Cl_Template.E_TemplateType.Block) { var ctrlGroup = new GroupBox(); ctrlGroup.Text = te.p_ChildTemplate.p_Name; ctrlGroup.AutoSize = true; ctrlGroup.Top = top; FlowLayoutPanel panel = new FlowLayoutPanel(); panel.Top = 20; panel.Left = 3; panel.WrapContents = false; panel.AutoSize = true; panel.FlowDirection = FlowDirection.TopDown; ctrlGroup.Controls.Add(panel); controls.Add(ctrlGroup); f_AddControlsTemplate(te.p_ChildTemplate, panel.Controls); top += ctrlGroup.Height + m_PaddingY; } else if (te.p_ChildTemplate.p_Type == Cl_Template.E_TemplateType.Table) { var ctrlTable = f_GetControlTable(); ctrlTable.AutoSize = true; top += 10; ctrlTable.Top = top; ctrlTable.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble; ctrlTable.RowCount = 1; ctrlTable.Controls.Add(new Label() { Text = "Показатель", TextAlign = System.Drawing.ContentAlignment.MiddleLeft }, 0, 0); //ctrlTable.Controls.Add(new Label() { Text = "Локация", TextAlign = System.Drawing.ContentAlignment.MiddleLeft }, 1, 0); ctrlTable.Controls.Add(new Label() { Text = "Значение", TextAlign = System.Drawing.ContentAlignment.MiddleLeft }, 1, 0); ctrlTable.Controls.Add(new Label() { Text = "Ед. изм.", TextAlign = System.Drawing.ContentAlignment.MiddleLeft }, 2, 0); ctrlTable.Controls.Add(new Label() { Text = "Нормa", TextAlign = System.Drawing.ContentAlignment.MiddleLeft }, 3, 0); controls.Add(ctrlTable); f_AddControlsTemplate(te.p_ChildTemplate, ctrlTable.Controls); top += ctrlTable.Height + m_PaddingY; } } } } } }