private void ctrl_TemplateEditParams_Click(object sender, EventArgs e) { if (p_SelectedTemplate != null) { e_EditTemplateParams?.Invoke(sender, new TreeViewEventArgs(p_SelectedTemplate)); } var tpl = Cl_App.m_DataContext.p_Templates.Where(t => t.p_TemplateID == p_SelectedTemplate.p_Template.p_TemplateID && !t.p_IsDelete).OrderByDescending(v => v.p_Version).FirstOrDefault(); if (tpl != null) { Dlg_EditorTemplate dlg = new Dlg_EditorTemplate(); dlg.ctrlPCategories.Enabled = tpl.p_Type == Cl_Template.E_TemplateType.Template; if (tpl.p_Type == Cl_Template.E_TemplateType.Template) { dlg.Text = "Редактирование параметров шаблона"; } else if (tpl.p_Type == Cl_Template.E_TemplateType.Block) { dlg.Text = "Редактирование параметров блока"; } else if (tpl.p_Type == Cl_Template.E_TemplateType.Table) { dlg.Text = "Редактирование параметров таблицы"; } dlg.ctrl_LGroupValue.Text = tpl.p_ParentGroup.p_Name; dlg.ctrl_TBName.Text = tpl.p_Name; dlg.ctrlTitle.Text = tpl.p_Title; dlg.ctrlCategoriesTotal.SelectedItem = tpl.p_CategoryTotal; dlg.ctrlCategoriesClinic.SelectedItem = tpl.p_CategoryClinic; if (dlg.ShowDialog() != DialogResult.OK) { return; } tpl.p_Name = dlg.ctrl_TBName.Text; tpl.p_Title = dlg.ctrlTitle.Text; if (tpl.p_Type == Cl_Template.E_TemplateType.Template) { var catTotal = (Cl_Category)dlg.ctrlCategoriesTotal.SelectedItem; tpl.p_CategoryTotalID = catTotal.p_ID; tpl.p_CategoryTotal = catTotal; var catClinic = (Cl_Category)dlg.ctrlCategoriesClinic.SelectedItem; tpl.p_CategoryClinicID = catClinic.p_ID; tpl.p_CategoryClinic = catClinic; } Cl_App.m_DataContext.SaveChanges(); SelectedNode.Text = tpl.p_Name; } }
private void f_TemplateNew(Cl_Template.E_TemplateType a_TemplateType) { using (var transaction = Cl_App.m_DataContext.Database.BeginTransaction()) { try { Cl_EntityLog eLog = new Cl_EntityLog(); Cl_Template newTemplate = (Cl_Template)Activator.CreateInstance(typeof(Cl_Template)); eLog.f_SetEntity(newTemplate); Cl_Group group = null; if (p_SelectedGroup != null && p_SelectedGroup.p_Group != null) { group = p_SelectedGroup.p_Group; } Dlg_EditorTemplate dlg = new Dlg_EditorTemplate(); dlg.ctrlPCategories.Enabled = a_TemplateType == Cl_Template.E_TemplateType.Template; if (a_TemplateType == Cl_Template.E_TemplateType.Template) { dlg.Text = "Новый шаблон"; } else if (a_TemplateType == Cl_Template.E_TemplateType.Block) { dlg.Text = "Новый блок"; } else if (a_TemplateType == Cl_Template.E_TemplateType.Table) { dlg.Text = "Новая таблица"; } if (group != null) { newTemplate.p_ParentGroup = p_SelectedGroup.p_Group; dlg.ctrl_LGroupValue.Text = p_SelectedGroup.p_Group.p_Name; } if (dlg.ShowDialog() != DialogResult.OK) { return; } newTemplate.p_Name = dlg.ctrl_TBName.Text; newTemplate.p_Title = dlg.ctrlTitle.Text; newTemplate.p_Type = a_TemplateType; if (a_TemplateType == Cl_Template.E_TemplateType.Template) { var catTotal = (Cl_Category)dlg.ctrlCategoriesTotal.SelectedItem; newTemplate.p_CategoryTotalID = catTotal.p_ID; newTemplate.p_CategoryTotal = catTotal; var catClinic = (Cl_Category)dlg.ctrlCategoriesClinic.SelectedItem; newTemplate.p_CategoryClinicID = catClinic.p_ID; newTemplate.p_CategoryClinic = catClinic; } Cl_App.m_DataContext.p_Templates.Add(newTemplate); Cl_App.m_DataContext.SaveChanges(); newTemplate.p_TemplateID = newTemplate.p_ID; Cl_App.m_DataContext.SaveChanges(); eLog.f_SaveEntity(newTemplate); transaction.Commit(); SelectedNode.Nodes.Add(new Ctrl_TreeNodeTemplate(group, newTemplate)); } catch (Exception ex) { transaction.Rollback(); MonitoringStub.Error("Error_Tree", "При создании нового шаблона произошла ошибка", ex, null, null); return; } } }