/// <summary>Установка элементов шаблона</summary> public void f_SetTemplatesElements(Cl_TemplateElement[] a_TemplatesElements) { if (a_TemplatesElements == null) { return; } Items.Clear(); foreach (var te in a_TemplatesElements) { if (te.p_ChildElement != null) { var ctrl = new Ctrl_Element(); ctrl.p_Element = te.p_ChildElement; Items.Add(ctrl); } else if (te.p_ChildTemplate != null) { var ctrl = new Ctrl_Template(); ctrl.p_Template = te.p_ChildTemplate; Items.Add(ctrl); } } ctrlMenuDel.Visible = Items.Count > 0; this.Invalidate(); }
private void f_DragNewElement(Ctrl_TreeNodeElement a_NodeElement, int a_PosX, int a_PosY) { if (a_NodeElement == null) { return; } if (a_NodeElement.p_Element == null) { return; } Ctrl_Element ctrlEl = new Ctrl_Element(); ctrlEl.p_Element = a_NodeElement.p_Element; ctrlEl.Name = f_CreateName(ctrlEl.p_Name); this.InsertionIndex = Items.Count - 1; Items.Add(ctrlEl); this.Invalidate(this.InsertionIndex); this.InsertionIndex = InvalidIndex; ctrlMenuDel.Visible = Items.Count > 0; }
protected override void OnDrawItem(DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); if (e.Index != -1 && Items.Count > e.Index) { if (Items[e.Index] is I_Element) { var el = (I_Element)Items[e.Index]; Color foreColor = ForeColor; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { foreColor = Color.White; } if (el is Ctrl_Element) { Ctrl_Element elm = (Ctrl_Element)el; if (Cl_TemplatesFacade.f_GetInstance().f_IsActualElement(elm.p_Element) == false) { foreColor = Color.Red; } } else if (el is Ctrl_Template) { Ctrl_Template tmpl = (Ctrl_Template)el; if (Cl_TemplatesFacade.f_GetInstance().f_IsActualElementsOnTemplate(tmpl.p_Template) == false) { foreColor = Color.Red; } } el.f_Draw(e.Graphics, e.Bounds, Font, foreColor); } } }
/// <summary> /// Сохранение шаблона /// </summary> /// <param name="curTemplate">Сохраняемый шаблон</param> /// <param name="items">Новый список элементов в сохраняемом шаблоне</param> /// <param name="m_Log">Объект логгера</param> /// <returns></returns> public Cl_Template f_SaveTemplate(Cl_Template curTemplate, I_Element[] elements, Cl_EntityLog m_Log = null) { using (var transaction = m_DataContextMegaTemplate.Database.BeginTransaction()) { try { Cl_Template newTemplate = null; if (curTemplate.p_Version == 0) { newTemplate = curTemplate; newTemplate.p_Version = 1; } else { newTemplate = new Cl_Template(); newTemplate.p_TemplateID = curTemplate.p_TemplateID; newTemplate.p_Title = curTemplate.p_Title; newTemplate.p_CategoryTotalID = curTemplate.p_CategoryTotalID; newTemplate.p_CategoryTotal = curTemplate.p_CategoryTotal; newTemplate.p_CategoryClinicID = curTemplate.p_CategoryClinicID; newTemplate.p_CategoryClinic = curTemplate.p_CategoryClinic; newTemplate.p_Type = curTemplate.p_Type; newTemplate.p_Name = curTemplate.p_Name; newTemplate.p_Version = curTemplate.p_Version + 1; newTemplate.p_ParentGroupID = curTemplate.p_ParentGroupID; newTemplate.p_ParentGroup = curTemplate.p_ParentGroup; newTemplate.p_Description = curTemplate.p_Description; m_DataContextMegaTemplate.p_Templates.Add(newTemplate); } m_DataContextMegaTemplate.SaveChanges(); foreach (I_Element item in elements) { Cl_TemplateElement tplEl = new Cl_TemplateElement(); tplEl.p_TemplateID = newTemplate.p_ID; tplEl.p_Template = newTemplate; if (item is Ctrl_Element) { Ctrl_Element block = (Ctrl_Element)item; tplEl.p_ChildElementID = block.p_ID; tplEl.p_ChildElement = block.p_Element; } else if (item is Ctrl_Template) { Ctrl_Template block = (Ctrl_Template)item; tplEl.p_ChildTemplateID = block.p_ID; tplEl.p_ChildTemplate = block.p_Template; } tplEl.p_Index = Array.IndexOf(elements, item) + 1; m_DataContextMegaTemplate.p_TemplatesElements.Add(tplEl); } m_DataContextMegaTemplate.SaveChanges(); if (m_Log != null && m_Log.f_IsChanged(newTemplate) == false) { if (newTemplate.Equals(curTemplate) && newTemplate.p_Version == 1) { newTemplate.p_Version = 0; } MonitoringStub.Message("Шаблон не изменялся!"); transaction.Rollback(); } else { m_Log.f_SaveEntity(newTemplate); transaction.Commit(); return(newTemplate); } } catch (Exception ex) { transaction.Rollback(); MonitoringStub.Error("Error_Editor", "При сохранении изменений произошла ошибка", ex, null, null); } return(curTemplate); } }