
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTRA_TEMPLATE',NULL,'Primary SQL Server','Шаблон пользовательских списков',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Шаблон пользовательских списков',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES') WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXTRA_TEMPLATE" Description="Шаблон пользовательских списков" Inherits="VCLib.FILES"><Fields><Attribute Name="ReportFileParameters" Index="980003" Type="text" Description="Параметры шаблона"></Attribute><Attribute Name="OutputName" Index="980004" Type="string" Description="Имя выходного файла" CharacterMaximumLength="1000"></Attribute><Parent Name="ReportFileFormat" Index="980001" Type="VCLib.ReportFileFormat" Description="Формат отчета" Required="1"></Parent><Parent Name="ExtraUiCommand" Index="980002" Type="VCLib.EXTRA_UI_COMMAND" Description="Дополнительная команда пользовательского интерфейса" Required="1"></Parent><Parent Name="ReportFormType" Index="980007" Type="VCLib.ENUMS" Description="Вид отчета" EnumType="ReportFormType" Required="1"></Parent><Child Name="ExtraTemplateParams" Index="980008" Type="VCLib.EXTRA_TEMPLATE_PARAM" Description="Параметры для формирования наименования шаблона" ChildAttribute="ExtraTemplate"></Child><Choice Name="ReportProcessingWay" Index="980005" Description="Способ обработки отчета" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice><Choice Name="OutputFormat" Index="980006" Description="Выходной формат"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_EXTRA_TEMPLATE"><Map Name="ReportFileFormat" Column="ReportFileFormat"></Map><Map Name="ExtraUiCommand" Column="ExtraUiCommand"></Map><Map Name="ReportFileParameters" Column="ReportFileParameters"></Map><Map Name="ReportProcessingWay" Column="ReportProcessingWay"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map><Map Name="OutputName" Column="OutputName"></Map><Map Name="ReportFormType" Column="ReportFormType"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE'
        GO
      
	  
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE_PARAM')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTRA_TEMPLATE_PARAM',NULL,'Primary SQL Server','Параметр для формирования наименования шаблона',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'LEXEM_PARAMETER'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр для формирования наименования шаблона',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'LEXEM_PARAMETER') WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE_PARAM'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXTRA_TEMPLATE_PARAM" Description="Параметр для формирования наименования шаблона" Inherits="VCLib.LEXEM_PARAMETER"><Fields><Parent Name="ExtraTemplate" Index="450001" Type="VCLib.EXTRA_TEMPLATE" Description="Шаблон пользовательских списков" Required="1"></Parent></Fields><DbMapping><Table name="T_LEXEM_PARAMETER"><Map Name="ExtraTemplate" Column="ExtraTemplate"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXTRA_TEMPLATE_PARAM'
        GO
      
	  
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='EXTRA_UI_ACTION_PARAMS')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'EXTRA_UI_ACTION_PARAMS',NULL,'Primary SQL Server','Параметр дополнительной команды',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр дополнительной команды',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='EXTRA_UI_ACTION_PARAMS'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="EXTRA_UI_ACTION_PARAMS" Description="Параметр дополнительной команды" PrimaryKey="ExtraUiActionParamsID" DNAttributes="{Name};{ParamDescription}" DisplayName="{0} - {1}"><Fields><Attribute Name="ExtraUiActionParamsID" Index="1020001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="Name" Index="1020003" Description="Наименование" Required="1"></Attribute><Attribute Name="ParamDescription" Index="1020004" Description="Описание" Required="1"></Attribute><Attribute Name="IsOutput" Index="1020005" Type="bool" Description="Выходной параметр" Required="1"></Attribute><Attribute Name="ParamValue" Index="1020006" Type="text" Description="Значение"></Attribute><Attribute Name="OutputOrder" Index="1020008" Type="int" Description="Порядок отображения"></Attribute><Attribute Name="FileName" Index="1020009" Type="string" Description="Наименование файла результата" CharacterMaximumLength="255"></Attribute><Attribute Name="Verb" Index="1020010" Type="string" Description="Verb"></Attribute><Parent Name="ExtraUiCommand" Index="1020002" Type="VCLib.EXTRA_UI_COMMAND" Description="Дополнительная команда пользовательского интерфейса" Required="1"></Parent><Choice Name="ResultType" Index="1020007" Description="Тип результата"><Item Name="Предпросмотр" Index="0"></Item><Item Name="Файл" Index="1"></Item></Choice></Fields><DbMapping><Table name="T_EXTRA_UI_ACTION_PARAMS"><Map Name="ExtraUiActionParamsID" Column="ExtraUiActionParamsID"></Map><Map Name="ExtraUiCommand" Column="ExtraUiCommand"></Map><Map Name="Name" Column="Name"></Map><Map Name="ParamDescription" Column="ParamDescription"></Map><Map Name="IsOutput" Column="IsOutput"></Map><Map Name="ParamValue" Column="ParamValue"></Map><Map Name="ResultType" Column="ResultType"></Map><Map Name="OutputOrder" Column="OutputOrder"></Map><Map Name="FileName" Column="FileName"></Map><Map Name="Verb" Column="Verb"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='EXTRA_UI_ACTION_PARAMS'
        GO
      
	  
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='LEXEM_PARAMETER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'LEXEM_PARAMETER',NULL,'Primary SQL Server','Лексемный параметр',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Лексемный параметр',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='LEXEM_PARAMETER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="LEXEM_PARAMETER" Description="Лексемный параметр" PrimaryKey="LexemParameterID"><Fields><Attribute Name="LexemParameterID" Index="410001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="ParamName" Index="410002" Type="string" Description="Наименование" Required="1"></Attribute><Attribute Name="ParamValue" Index="410003" Type="text" Description="Лексема" Required="1"></Attribute></Fields><DbMapping><Table name="T_LEXEM_PARAMETER"><Map Name="LexemParameterID" Column="LexemParameterID"></Map><Map Name="ParamName" Column="ParamName"></Map><Map Name="ParamValue" Column="ParamValue"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='LEXEM_PARAMETER'
        GO
      
	  
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='ReportFile')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'ReportFile',NULL,'Primary SQL Server','Шаблон документа отчета',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Шаблон документа отчета',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'FILES') WHERE [Schema]='VCLib' and EntName='ReportFile'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="ReportFile" Description="Шаблон документа отчета" version="2" UnrestrictedAccess="1" Inherits="VCLib.FILES"><Fields><Attribute Name="IsSecondary" Index="110003" Type="bool" Description="Не обрабатывать"></Attribute><Attribute Name="OutputName" Index="110006" Type="string" Description="Имя выходного файла"></Attribute><Attribute Name="PreparedOutputName" Index="380012" Type="string" Description="Подготовленная лексема для получения наименования файла"></Attribute><Parent Name="GroupID" Index="110001" Type="VCLib.ReportFileGroup" Description="Комплект шаблонов"></Parent><Parent Name="RepFmtID" Index="110002" Type="VCLib.ReportFileFormat" Description="Формат" Required="1"></Parent><Child Name="Parameters" Index="110004" Type="VCLib.ReportFileParameter" Description="Пераметры, используемые в шаблоне" ChildAttribute="FileID" RemoveAction="0"></Child><Choice Name="OutputFormat" Index="110005" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice><Choice Name="ProcessingWay" Index="8570006" Description="Способ обработки" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_ReportFile"><Map Name="GroupID" Column="GroupID"></Map><Map Name="RepFmtID" Column="RepFmtID"></Map><Map Name="IsSecondary" Column="IsSecondary"></Map><Map Name="ProcessingWay" Column="ProcessingWay"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map><Map Name="OutputName" Column="OutputName"></Map></Table></DbMapping><Customs><Custom Name="NotDisplayedInFilter" Value="PreparedOutputName"></Custom><Custom Name="NotDisplayedColumns" Value="PreparedOutputName"></Custom><Custom Name="NotTrackedAttributes" Value="PreparedOutputName"></Custom></Customs></Entity>' WHERE [Schema]='VCLib' and EntName='ReportFile'
        GO
      

	  
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='REPORTS_CONFIG')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'REPORTS_CONFIG',NULL,'Primary SQL Server','Настройка шаблонов печатных форм',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Настройка шаблонов печатных форм',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='REPORTS_CONFIG'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="REPORTS_CONFIG" Description="Настройка шаблонов печатных форм" PrimaryKey="TemplateName"><Fields><Attribute Name="TemplateName" Index="380002" Type="string" Description="Наименование шаблона" Required="1"></Attribute><Attribute Name="TemplatePath" Index="380003" Type="string" Description="Путь до файла шаблона" CharacterMaximumLength="1000" Required="1"></Attribute><Attribute Name="Printer" Index="380008" Type="string" Description="Принтер"></Attribute><Attribute Name="FileName" Index="380009" Type="string" Description="Наименование файла" Required="1"></Attribute><Attribute Name="OutputName" Index="380010" Type="string" Description="Имя выходного файла"></Attribute><Attribute Name="PreparedOutputName" Index="380012" Type="string" Description="Подготовленная лексема для получения наименования файла"></Attribute><Parent Name="ReportFileFormat" Index="380004" Type="VCLib.ReportFileFormat" Description="Формат шаблона" Required="1"></Parent><Child Name="TemplateOverrides" Index="380007" Type="VCLib.TEMPLATE_OVERRIDE" Description="Переопределения шаблона печатной формы" ChildAttribute="ReportsConfig" SortingAttr="OverrideOrder"></Child><Choice Name="ReportProcessingWay" Index="380006" Description="Способ обработки отчета" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice><Choice Name="OutputFormat" Index="380011" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_REPORTS_CONFIG"><Map Name="TemplateName" Column="TemplateName" IsStored="0"></Map><Map Name="TemplatePath" Column="TemplatePath" IsStored="0"></Map><Map Name="ReportFileFormat" Column="ReportFileFormat" IsStored="0"></Map><Map Name="ReportProcessingWay" Column="ReportProcessingWay" IsStored="0"></Map><Map Name="FileName" Column="FileName" IsStored="0"></Map><Map Name="OutputName" Column="OutputName" IsStored="0"></Map><Map Name="OutputFormat" Column="OutputFormat" IsStored="0"></Map></Table></DbMapping><Customs><Custom Name="NotDisplayedInFilter" Value="Printer;PreparedOutputName"></Custom><Custom Name="NotDisplayedColumns" Value="Printer;PreparedOutputName"></Custom><Custom Name="NotTrackedAttributes" Value="Printer;PreparedOutputName"></Custom></Customs></Entity>' WHERE [Schema]='VCLib' and EntName='REPORTS_CONFIG'
        GO
      
	  
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='TEMPLATE_OVERRIDE')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TEMPLATE_OVERRIDE',NULL,'Primary SQL Server','Переопределение шаблона печатной формы',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = ''), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Переопределение шаблона печатной формы',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='' and EntName = '') WHERE [Schema]='VCLib' and EntName='TEMPLATE_OVERRIDE'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="TEMPLATE_OVERRIDE" Description="Переопределение шаблона печатной формы" PrimaryKey="TemplateOverrideID"><Fields><Attribute Name="TemplateOverrideID" Index="390001" Type="guid" Description="Идентификатор"></Attribute><Attribute Name="TemplatePath" Index="390004" Type="string" Description="Путь до файла шаблона" CharacterMaximumLength="1000" Required="1"></Attribute><Attribute Name="Printer" Index="390005" Type="string" Description="Принтер"></Attribute><Attribute Name="OverrideOrder" Index="390008" Type="int" Description="Порядковый номер перегрузки" Required="1"></Attribute><Attribute Name="FileName" Index="390010" Type="string" Description="Наименование файла" Required="1"></Attribute><Attribute Name="OutputName" Index="390011" Type="string" Description="Имя выходного файла"></Attribute><Parent Name="ReportsConfig" Index="390002" Type="VCLib.REPORTS_CONFIG" Description="Настройка шаблонов печатных форм" Required="1"></Parent><Parent Name="UsersGroup" Index="390003" Type="VCLib.USERS_GROUP" Description="Группы пользователей" Required="1"></Parent><Parent Name="ReportFileFormat" Index="390007" Type="VCLib.ReportFileFormat" Description="Формат шаблона" Required="1"></Parent><Parent Name="Entities" Index="390014" Type="VCLib.ENTITIES" Description="Сущность шаблона"></Parent><Child Name="TemplateParameters" Index="390013" Type="VCLib.TEMPLATE_PARAMETER" Description="Параметры шаблона" ChildAttribute="TemplateOverride"></Child><Choice Name="ReportProcessingWay" Index="390006" Description="Способ обработки отчета" Required="1"><Item Name="По умолчанию" Index="0"></Item><Item Name="MS OLE Automation" Index="1"></Item><Item Name="Быстрая обработка" Index="2"></Item></Choice><Choice Name="ConfigType" Index="390009" Description="Тип настройки" Required="1"><Item Name="Переопределение" Index="0"></Item><Item Name="Дополнительный шаблон" Index="1"></Item></Choice><Choice Name="OutputFormat" Index="390012" Description="Выходной формат" Required="1"><Item Name="Формат шаблона" Index="0"></Item><Item Name="Pdf" Index="1"></Item><Item Name="Html" Index="2"></Item></Choice></Fields><DbMapping><Table name="T_TEMPLATE_OVERRIDE"><Map Name="TemplateOverrideID" Column="TemplateOverrideID"></Map><Map Name="ReportsConfig" Column="ReportsConfig"></Map><Map Name="UsersGroup" Column="UsersGroup"></Map><Map Name="TemplatePath" Column="TemplatePath"></Map><Map Name="Printer" Column="Printer"></Map><Map Name="ReportProcessingWay" Column="ReportProcessingWay"></Map><Map Name="ReportFileFormat" Column="ReportFileFormat"></Map><Map Name="OverrideOrder" Column="OverrideOrder"></Map><Map Name="ConfigType" Column="ConfigType"></Map><Map Name="FileName" Column="FileName"></Map><Map Name="OutputName" Column="OutputName"></Map><Map Name="OutputFormat" Column="OutputFormat"></Map><Map Name="Entities" Column="Entities"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='TEMPLATE_OVERRIDE'
        GO
      
	  
        IF NOT EXISTS(SELECT * FROM VCLib.T_ENTITIES WHERE [Schema]='VCLib' and EntName='TEMPLATE_PARAMETER')
        BEGIN
        INSERT INTO VCLib.T_ENTITIES (EntityID, EntName, XML, ServerName, EntDesc, NeedHistory, BaseEntity, [Schema])
        VALUES ((isnull((select top 1 EntityID from VCLib.T_ENTITIES order by EntityID desc), 0) + 1),'TEMPLATE_PARAMETER',NULL,'Primary SQL Server','Параметр шаблона',0, (select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'LEXEM_PARAMETER'), 'VCLib')
        END
        ELSE BEGIN
        UPDATE VCLib.T_ENTITIES SET EntDesc='Параметр шаблона',BaseEntity=(select top 1 EntityID from VCLib.T_ENTITIES where [Schema]='VCLib' and EntName = 'LEXEM_PARAMETER') WHERE [Schema]='VCLib' and EntName='TEMPLATE_PARAMETER'
        END
        GO
        UPDATE VCLib.T_ENTITIES SET XML='<?xml version="1.0" encoding="utf-8" standalone="yes"?><Entity Schema="VCLib" Name="TEMPLATE_PARAMETER" Description="Параметр шаблона" Inherits="VCLib.LEXEM_PARAMETER"><Fields><Parent Name="TemplateOverride" Index="400002" Type="VCLib.TEMPLATE_OVERRIDE" Description="Переопределение шаблона печатной формы" Required="1"></Parent></Fields><DbMapping><Table name="T_LEXEM_PARAMETER"><Map Name="TemplateOverride" Column="TemplateOverride"></Map></Table></DbMapping></Entity>' WHERE [Schema]='VCLib' and EntName='TEMPLATE_PARAMETER'
        GO
      
	  exec sp_UpdateEntities

