CapicuaGenGaspar 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/CapicuaGenGaspar.gemspec +60 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +33 -0
- data/LICENSE +165 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/CapicuaGenGaspar/Business/CSSqlEntitityInterface/Source/cs_sql_entity_interface_feature.rb +96 -0
- data/lib/CapicuaGenGaspar/Business/CSSqlEntitityInterface/Template/table_interface.erb +49 -0
- data/lib/CapicuaGenGaspar/Business/CSSqlEntity/Source/cs_sql_entity_feature.rb +103 -0
- data/lib/CapicuaGenGaspar/Business/CSSqlEntity/Template/table_entity.erb +51 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb +148 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Template/footer.erb +37 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Template/header.erb +43 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Bin/EnvDTE.dll +0 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Bin/EnvDTE80.dll +0 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Bin/RunCodeMaidCleaner.exe +0 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Bin/RunCodeMaidCleaner.exe.config +52 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Bin/stdole.dll +0 -0
- data/lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Source/code_maid_cleaner_feature.rb +162 -0
- data/lib/CapicuaGenGaspar/DataAccess/CSConnectionProvider/Source/cs_db_connection_provider_feature.rb +90 -0
- data/lib/CapicuaGenGaspar/DataAccess/CSSqlDataAccess/Source/cs_sql_data_access_feature.rb +106 -0
- data/lib/CapicuaGenGaspar/DataAccess/CSSqlDataAccess/Template/data_access.erb +154 -0
- data/lib/CapicuaGenGaspar/DataAccess/CSSqlDataAccess/Template/data_access_exception.erb +36 -0
- data/lib/CapicuaGenGaspar/DataAccess/CSSqlDataAccess/Template/data_access_table.erb +298 -0
- data/lib/CapicuaGenGaspar/Entities/CSEntity/Source/entity_field_schema.rb +100 -0
- data/lib/CapicuaGenGaspar/GUI/CSAboutWindowsForm/Source/cs_about_windows_form_feature.rb +85 -0
- data/lib/CapicuaGenGaspar/GUI/CSAboutWindowsForm/Template/AboutForm.designer.erb +211 -0
- data/lib/CapicuaGenGaspar/GUI/CSAboutWindowsForm/Template/AboutForm.erb +127 -0
- data/lib/CapicuaGenGaspar/GUI/CSAboutWindowsForm/Template/AboutForm.resx.erb +535 -0
- data/lib/CapicuaGenGaspar/GUI/CSCatalogWindowsForm/Source/cs_catalog_windows_form_feature.rb +146 -0
- data/lib/CapicuaGenGaspar/GUI/CSCatalogWindowsForm/Template/CatalogForm.Designer.erb +363 -0
- data/lib/CapicuaGenGaspar/GUI/CSCatalogWindowsForm/Template/CatalogForm.erb +320 -0
- data/lib/CapicuaGenGaspar/GUI/CSCatalogWindowsForm/Template/CatalogForm.resx.erb +2407 -0
- data/lib/CapicuaGenGaspar/GUI/CSCatalogWindowsForm/Template/CatalogState.erb +51 -0
- data/lib/CapicuaGenGaspar/GUI/CSMDIWindowsForm/Source/cs_mdi_windows_form_feature.rb +93 -0
- data/lib/CapicuaGenGaspar/GUI/CSMDIWindowsForm/Template/MainForm.Designer.erb +316 -0
- data/lib/CapicuaGenGaspar/GUI/CSMDIWindowsForm/Template/MainForm.erb +161 -0
- data/lib/CapicuaGenGaspar/GUI/CSMDIWindowsForm/Template/MainForm.resx.erb +2504 -0
- data/lib/CapicuaGenGaspar/GUI/CSMDIWindowsForm/Template/MsgboxConsts.erb +31 -0
- data/lib/CapicuaGenGaspar/GUI/CSSplashWindowsForm/Source/cs_splash_windows_feature.rb +87 -0
- data/lib/CapicuaGenGaspar/GUI/CSSplashWindowsForm/Template/SplashForm.designer.erb +141 -0
- data/lib/CapicuaGenGaspar/GUI/CSSplashWindowsForm/Template/SplashForm.erb +160 -0
- data/lib/CapicuaGenGaspar/GUI/CSSplashWindowsForm/Template/SplashForm.resx.erb +535 -0
- data/lib/CapicuaGenGaspar/Mixins/about_mixin.rb +55 -0
- data/lib/CapicuaGenGaspar/Mixins/catalog_mixin.rb +65 -0
- data/lib/CapicuaGenGaspar/Mixins/cs_app_config_mixin.rb +41 -0
- data/lib/CapicuaGenGaspar/Mixins/cs_db_connection_provider_mixin.rb +67 -0
- data/lib/CapicuaGenGaspar/Mixins/cs_namespace_mixin.rb +53 -0
- data/lib/CapicuaGenGaspar/Mixins/entity_interface_mixin.rb +57 -0
- data/lib/CapicuaGenGaspar/Mixins/entity_mixin.rb +58 -0
- data/lib/CapicuaGenGaspar/Mixins/entity_sql_table_mixin.rb +58 -0
- data/lib/CapicuaGenGaspar/Mixins/main_form_mixin.rb +55 -0
- data/lib/CapicuaGenGaspar/Mixins/splash_mixin.rb +54 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyect/Source/cs_proyect_feature.rb +140 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectRESTFul/Source/cs_proyect_rest_ful_feature.rb +82 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectRESTFul/Template/AssemblyInfo.erb +59 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectRESTFul/Template/ExcepcionControlada.erb +38 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectRESTFul/Template/Proyect.erb +114 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectRESTFul/Template/Soluction.erb +54 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectRESTFul/Template/Web.erb +66 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Source/cs_proyect_windows_form_feature.rb +85 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Template/App.erb +32 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Template/AssemblyInfo.erb +59 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Template/ControlExcepciones.erb +49 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Template/ExcepcionControlada.erb +40 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Template/Program.erb +46 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Template/Proyect.erb +138 -0
- data/lib/CapicuaGenGaspar/Proyect/CSProyectWindowsForm/Template/Soluction.erb +55 -0
- data/lib/CapicuaGenGaspar/Tools/message_helper.rb +43 -0
- data/lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb +176 -0
- data/lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Template/CatalogState.erb +51 -0
- data/lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Template/Catalogs.erb +58 -0
- data/lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Template/Catalogs.svc.erb +24 -0
- data/lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Template/ICatalogs.erb +58 -0
- data/lib/CapicuaGenGaspar/gaspar.rb +44 -0
- data/lib/CapicuaGenGaspar/version.rb +3 -0
- metadata +216 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
CapicuaGen
|
|
4
|
+
|
|
5
|
+
CapicuaGen es un software que ayuda a la creación automática de
|
|
6
|
+
sistemas empresariales a través de la definición y ensamblado de
|
|
7
|
+
diversos generadores de características.
|
|
8
|
+
|
|
9
|
+
El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
|
|
10
|
+
del 2016.
|
|
11
|
+
|
|
12
|
+
Puede modificar y distribuir este software, según le plazca, y usarlo
|
|
13
|
+
para cualquier fin ya sea comercial, personal, educativo, o de cualquier
|
|
14
|
+
índole, siempre y cuando incluya este mensaje, y se permita acceso el
|
|
15
|
+
código fuente.
|
|
16
|
+
|
|
17
|
+
Este software es código libre, y se licencia bajo LGPL.
|
|
18
|
+
|
|
19
|
+
Para más información consultar http://www.gnu.org/licenses/lgpl.html
|
|
20
|
+
=end
|
|
21
|
+
|
|
22
|
+
require 'active_support/core_ext/object/blank'
|
|
23
|
+
|
|
24
|
+
require_relative '../../../gaspar'
|
|
25
|
+
require_relative '../../../Mixins/cs_db_connection_provider_mixin'
|
|
26
|
+
require_relative '../../../Mixins/cs_namespace_mixin'
|
|
27
|
+
require_relative '../../../Mixins/entity_interface_mixin'
|
|
28
|
+
require_relative '../../../Mixins/entity_sql_table_mixin'
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
module CapicuaGen::Gaspar
|
|
32
|
+
|
|
33
|
+
# Caracteristica generadora para la capa de persistencia
|
|
34
|
+
# en case a las entidades obtenidas en un archivo .SQL
|
|
35
|
+
class CSSqlDataAccessFeature < CapicuaGen::TemplateFeature
|
|
36
|
+
include CapicuaGen
|
|
37
|
+
include CapicuaGen::Gaspar
|
|
38
|
+
include CapicuaGen::Melchior
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
public
|
|
42
|
+
|
|
43
|
+
# Inicializa la caracteristica
|
|
44
|
+
def initialize(values= {})
|
|
45
|
+
super(values)
|
|
46
|
+
|
|
47
|
+
# Configuro los tipos si estos no han sido configurados previamente
|
|
48
|
+
self.types= [:data_access] if self.types.blank?
|
|
49
|
+
|
|
50
|
+
# Configuro los templates
|
|
51
|
+
set_template("data_access_exception", Template.new(:file => 'data_access_exception.erb'))
|
|
52
|
+
set_template("data_access", Template.new(:file => 'data_access.erb'))
|
|
53
|
+
set_template("data_access_table", Template.new(:file => 'data_access_table.erb'))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Configura los objetivos de las platillas (despues de establecer el generador)
|
|
59
|
+
def configure_template_targets
|
|
60
|
+
|
|
61
|
+
# Configuro los templates
|
|
62
|
+
set_template_target('data_access_exception', TemplateTarget.new(:out_file => "DataAccessException.cs", :types => :proyect_file, :class_name => 'DataAccessException'))
|
|
63
|
+
set_template_target('data_access', TemplateTarget.new(:out_file => "DataAccess.cs", :types => :proyect_file, :class_name => 'DataAccess'))
|
|
64
|
+
|
|
65
|
+
# Busco las caracteristicas que contiene entidades de SQL para una table
|
|
66
|
+
get_tables do |e|
|
|
67
|
+
set_template_target("data_access_table/#{get_entity_data_access_name(e.name)}",
|
|
68
|
+
TemplateTarget.new(
|
|
69
|
+
:out_file => "#{get_entity_data_access_name(e.name)}.cs",
|
|
70
|
+
:types => :proyect_file,
|
|
71
|
+
:class_name => get_entity_data_access_name(e.name),
|
|
72
|
+
:entity_schema => e,
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Resetea los atributos personalizados de la caracteristica (antes de establecer el generador)
|
|
81
|
+
def reset_attributes
|
|
82
|
+
self.generation_attributes[:out_dir] = nil
|
|
83
|
+
self.generation_attributes[:namespace]= nil
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Configura los atributos personalizados de la caracteristica (antes de establecer el generador)
|
|
87
|
+
def configure_attributes()
|
|
88
|
+
self.generation_attributes[:out_dir] = "#{self.generation_attributes[:out_dir]}/#{self.generation_attributes[:namespace]}/Data.Access" unless self.generation_attributes.has_in_self?(:out_dir)
|
|
89
|
+
self.generation_attributes[:namespace]= "#{self.generation_attributes[:namespace]}.Data.Access" unless self.generation_attributes.has_in_self?(:namespace)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Obtiene el nombre de la clase de persistencia asociada a una entidad
|
|
94
|
+
def get_entity_data_access_name(entity_name)
|
|
95
|
+
return "#{entity_name}DataAccess"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Obtiene el nombre completo de la clase de persistencia asociada a una entidad
|
|
99
|
+
def get_entity_data_access_full_name(entity_name)
|
|
100
|
+
return "#{self.generation_attributes[:namespace]}.#{get_entity_data_access_name(entity_name)}"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<%
|
|
2
|
+
#encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
=begin
|
|
5
|
+
|
|
6
|
+
CapicuaGen
|
|
7
|
+
|
|
8
|
+
CapicuaGen es un software que ayuda a la creación automática de
|
|
9
|
+
sistemas empresariales a través de la definición y ensamblado de
|
|
10
|
+
diversos generadores de características.
|
|
11
|
+
|
|
12
|
+
El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
|
|
13
|
+
del 2016.
|
|
14
|
+
|
|
15
|
+
Puede modificar y distribuir este software, según le plazca, y usarlo
|
|
16
|
+
para cualquier fin ya sea comercial, personal, educativo, o de cualquier
|
|
17
|
+
índole, siempre y cuando incluya este mensaje, y se permita acceso el
|
|
18
|
+
código fuente.
|
|
19
|
+
|
|
20
|
+
Este software es código libre, y se licencia bajo LGPL.
|
|
21
|
+
|
|
22
|
+
Para más información consultar http://www.gnu.org/licenses/lgpl.html
|
|
23
|
+
=end
|
|
24
|
+
%>using System;
|
|
25
|
+
using System.Configuration;
|
|
26
|
+
using System.Data;
|
|
27
|
+
using System.Data.Common;
|
|
28
|
+
using System.Text;
|
|
29
|
+
using System.Collections.Generic;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
namespace <%=self.generation_attributes[:namespace]%>
|
|
34
|
+
{
|
|
35
|
+
/// <summary>
|
|
36
|
+
/// Clase base de acceso a datos
|
|
37
|
+
/// </summary>
|
|
38
|
+
abstract partial class AccesoDatos<T>
|
|
39
|
+
{
|
|
40
|
+
#region Propiedades
|
|
41
|
+
|
|
42
|
+
/// <summary>
|
|
43
|
+
/// Nombre de la conexión
|
|
44
|
+
/// </summary>
|
|
45
|
+
protected const string nombreConexion= <%=get_db_connection_name_method%>;
|
|
46
|
+
|
|
47
|
+
/// <summary>
|
|
48
|
+
/// Fabrica que crea los objetos de acceso a datos
|
|
49
|
+
/// </summary>
|
|
50
|
+
protected DbProviderFactory dbProviderFactory;
|
|
51
|
+
|
|
52
|
+
#endregion Propiedades
|
|
53
|
+
|
|
54
|
+
#region Constructor
|
|
55
|
+
|
|
56
|
+
/// <summary>
|
|
57
|
+
/// Constructor
|
|
58
|
+
/// </summary>
|
|
59
|
+
public AccesoDatos()
|
|
60
|
+
{
|
|
61
|
+
dbProviderFactory = <%=get_db_connection_provider_method%>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#endregion Constructor
|
|
65
|
+
|
|
66
|
+
#region Sentencias SQL
|
|
67
|
+
|
|
68
|
+
/// <summary>
|
|
69
|
+
/// Listado completo de los registros
|
|
70
|
+
/// </summary>
|
|
71
|
+
/// <returns>Listado completo de los registros</returns>
|
|
72
|
+
public abstract IEnumerable<T> Listar();
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/// <summary>
|
|
76
|
+
/// Consulta
|
|
77
|
+
/// </summary>
|
|
78
|
+
/// <param name="registro">Registro a consultar</param>
|
|
79
|
+
/// <returns>Registro consultado</returns>
|
|
80
|
+
public abstract T Consultar(T registro);
|
|
81
|
+
|
|
82
|
+
/// <summary>
|
|
83
|
+
/// Consulta si un registro existe
|
|
84
|
+
/// </summary>
|
|
85
|
+
/// <param name="registro">Registro a consultar</param>
|
|
86
|
+
/// <returns>Devuelve el registro o nulo</returns>
|
|
87
|
+
public abstract T ConsultarExiste(T registro);
|
|
88
|
+
|
|
89
|
+
/// <summary>
|
|
90
|
+
/// Actualización
|
|
91
|
+
/// </summary>
|
|
92
|
+
/// <param name="registro">Registro a actualizar</param>
|
|
93
|
+
public abstract void Actualizar(T registro);
|
|
94
|
+
|
|
95
|
+
/// <summary>
|
|
96
|
+
/// Inserta un registro
|
|
97
|
+
/// </summary>
|
|
98
|
+
/// <param name="registro">Registro para insertar</param>
|
|
99
|
+
public abstract void Insertar(T registro);
|
|
100
|
+
|
|
101
|
+
/// <summary>
|
|
102
|
+
/// Borrado de registros
|
|
103
|
+
/// </summary>
|
|
104
|
+
/// <param name="registro">Registro a eliminar</param>
|
|
105
|
+
public abstract void Eliminar(T registro);
|
|
106
|
+
|
|
107
|
+
#endregion Sentencias SQL
|
|
108
|
+
|
|
109
|
+
#region funciones para crear comandos
|
|
110
|
+
|
|
111
|
+
/// <summary>
|
|
112
|
+
/// Devuelve una conexión abierta a base de datos
|
|
113
|
+
/// </summary>
|
|
114
|
+
/// <returns>Conexión abierta</returns>
|
|
115
|
+
protected virtual DbConnection CrearConexionAbierta()
|
|
116
|
+
{
|
|
117
|
+
DbConnection dbConnection = dbProviderFactory.CreateConnection();
|
|
118
|
+
dbConnection.ConnectionString = <%=get_db_connection_string_method%>;
|
|
119
|
+
dbConnection.Open();
|
|
120
|
+
return dbConnection;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// <summary>
|
|
124
|
+
/// Crea un comando de texto
|
|
125
|
+
/// </summary>
|
|
126
|
+
/// <param name="textoComando">Texto a crear</param>
|
|
127
|
+
/// <returns>comando</returns>
|
|
128
|
+
protected virtual DbCommand CrearComando(string textoComando)
|
|
129
|
+
{
|
|
130
|
+
DbCommand comando = dbProviderFactory.CreateCommand();
|
|
131
|
+
comando.CommandType = CommandType.Text;
|
|
132
|
+
comando.CommandText = textoComando;
|
|
133
|
+
return comando;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// <summary>
|
|
137
|
+
/// Agregado un parámetro a un comando
|
|
138
|
+
/// </summary>
|
|
139
|
+
/// <param name="comando">Comando</param>
|
|
140
|
+
/// <param name="nombre">Nombre del parámetro</param>
|
|
141
|
+
/// <param name="tipoSql">Tipo del parámetro</param>
|
|
142
|
+
/// <param name="valor">Valor del parámetro</param>
|
|
143
|
+
protected virtual void AgregarParametro(DbCommand comando, string nombre, DbType tipoSql, object valor)
|
|
144
|
+
{
|
|
145
|
+
DbParameter parametro = dbProviderFactory.CreateParameter();
|
|
146
|
+
parametro.ParameterName = nombre;
|
|
147
|
+
parametro.DbType = tipoSql;
|
|
148
|
+
parametro.Value = valor;
|
|
149
|
+
comando.Parameters.Add(parametro);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#endregion funciones para crear comandos
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<%
|
|
2
|
+
#encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
=begin
|
|
5
|
+
|
|
6
|
+
CapicuaGen
|
|
7
|
+
|
|
8
|
+
CapicuaGen es un software que ayuda a la creación automática de
|
|
9
|
+
sistemas empresariales a través de la definición y ensamblado de
|
|
10
|
+
diversos generadores de características.
|
|
11
|
+
|
|
12
|
+
El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
|
|
13
|
+
del 2016.
|
|
14
|
+
|
|
15
|
+
Puede modificar y distribuir este software, según le plazca, y usarlo
|
|
16
|
+
para cualquier fin ya sea comercial, personal, educativo, o de cualquier
|
|
17
|
+
índole, siempre y cuando incluya este mensaje, y se permita acceso el
|
|
18
|
+
código fuente.
|
|
19
|
+
|
|
20
|
+
Este software es código libre, y se licencia bajo LGPL.
|
|
21
|
+
|
|
22
|
+
Para más información consultar http://www.gnu.org/licenses/lgpl.html
|
|
23
|
+
=end
|
|
24
|
+
%>namespace <%=self.generation_attributes[:namespace]%>
|
|
25
|
+
{
|
|
26
|
+
/// <summary>
|
|
27
|
+
/// Excepción relativa a un error en acceso a datos
|
|
28
|
+
/// </summary>
|
|
29
|
+
partial class AccesoDatosException : ExcepcionControlada
|
|
30
|
+
{
|
|
31
|
+
public AccesoDatosException(string mensaje)
|
|
32
|
+
: base(mensaje)
|
|
33
|
+
{
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
<%
|
|
2
|
+
#encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
=begin
|
|
5
|
+
|
|
6
|
+
CapicuaGen
|
|
7
|
+
|
|
8
|
+
CapicuaGen es un software que ayuda a la creación automática de
|
|
9
|
+
sistemas empresariales a través de la definición y ensamblado de
|
|
10
|
+
diversos generadores de características.
|
|
11
|
+
|
|
12
|
+
El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
|
|
13
|
+
del 2016.
|
|
14
|
+
|
|
15
|
+
Puede modificar y distribuir este software, según le plazca, y usarlo
|
|
16
|
+
para cualquier fin ya sea comercial, personal, educativo, o de cualquier
|
|
17
|
+
índole, siempre y cuando incluya este mensaje, y se permita acceso el
|
|
18
|
+
código fuente.
|
|
19
|
+
|
|
20
|
+
Este software es código libre, y se licencia bajo LGPL.
|
|
21
|
+
|
|
22
|
+
Para más información consultar http://www.gnu.org/licenses/lgpl.html
|
|
23
|
+
=end
|
|
24
|
+
%>using System;
|
|
25
|
+
using System.Configuration;
|
|
26
|
+
using System.Data;
|
|
27
|
+
using System.Data.Common;
|
|
28
|
+
using System.Text;
|
|
29
|
+
using System.Collections.Generic;
|
|
30
|
+
<%=get_namespaces_text(:business_interfaces) %>
|
|
31
|
+
|
|
32
|
+
namespace <%=generation_attributes[:namespace]%>
|
|
33
|
+
{
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Capa de acceso a datos de una<%=template_target.class_name%>
|
|
36
|
+
/// </summary>
|
|
37
|
+
partial class <%=template_target.class_name%><T> : AccesoDatos<T> where T : class, <%=get_entity_interface_name(template_target.entity_schema.name)%>, new()
|
|
38
|
+
{
|
|
39
|
+
|
|
40
|
+
#region Sentencias SQL
|
|
41
|
+
|
|
42
|
+
/// <summary>
|
|
43
|
+
/// Consulta
|
|
44
|
+
/// </summary>
|
|
45
|
+
/// <param name="<%=template_target.entity_schema.name.downcase%>">Registro a consultar</param>
|
|
46
|
+
/// <returns>Registro consultado</returns>
|
|
47
|
+
public override T Consultar(T <%=template_target.entity_schema.name.downcase%>)
|
|
48
|
+
{
|
|
49
|
+
T resultado = ConsultarExiste(<%=template_target.entity_schema.name.downcase%>);
|
|
50
|
+
|
|
51
|
+
if (resultado == null)
|
|
52
|
+
{
|
|
53
|
+
throw new AccesoDatosException("No existe el registro");
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
return resultado;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// <summary>
|
|
62
|
+
/// Lista todos los registros
|
|
63
|
+
/// </summary>
|
|
64
|
+
/// <returns>Registros</returns>
|
|
65
|
+
public override IEnumerable<T> Listar()
|
|
66
|
+
{
|
|
67
|
+
List<T> listaResultado = new List<T>();
|
|
68
|
+
|
|
69
|
+
StringBuilder query = new StringBuilder();
|
|
70
|
+
|
|
71
|
+
query.AppendLine("SELECT");
|
|
72
|
+
<%
|
|
73
|
+
total=template_target.entity_schema.fields.count
|
|
74
|
+
indice=0
|
|
75
|
+
template_target.entity_schema.fields.each { |field|
|
|
76
|
+
indice=indice+1
|
|
77
|
+
%>query.AppendLine(" <%=field.name%><%="," if indice!=total%>");
|
|
78
|
+
<%}%>query.AppendLine("FROM");
|
|
79
|
+
query.AppendLine(" <%=template_target.entity_schema.sql_name.downcase%>");
|
|
80
|
+
|
|
81
|
+
DbCommand comando = CrearComando(query.ToString());
|
|
82
|
+
|
|
83
|
+
using (DbConnection conexion = CrearConexionAbierta())
|
|
84
|
+
{
|
|
85
|
+
comando.Connection = conexion;
|
|
86
|
+
DbDataReader reader = comando.ExecuteReader();
|
|
87
|
+
|
|
88
|
+
if (reader.HasRows)
|
|
89
|
+
{
|
|
90
|
+
while (reader.Read())
|
|
91
|
+
{
|
|
92
|
+
T resultado = new T();
|
|
93
|
+
<%
|
|
94
|
+
template_target.entity_schema.fields.each { |field|
|
|
95
|
+
%> if (reader["<%=field.name%>"] != DBNull.Value) resultado.<%=field.name%> = (<%=field.net_type%>)reader["<%=field.name%>"];
|
|
96
|
+
<%}%>
|
|
97
|
+
listaResultado.Add(resultado);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return listaResultado;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// <summary>
|
|
107
|
+
/// Consulta si un registro existe
|
|
108
|
+
/// </summary>
|
|
109
|
+
/// <param name="<%=template_target.entity_schema.name.downcase%>">Registro a consultar</param>
|
|
110
|
+
/// <returns>Devuelve el registro o nulo</returns>
|
|
111
|
+
public override T ConsultarExiste(T <%=template_target.entity_schema.name.downcase%>)
|
|
112
|
+
{
|
|
113
|
+
StringBuilder query = new StringBuilder();
|
|
114
|
+
|
|
115
|
+
query.AppendLine("SELECT");
|
|
116
|
+
<%
|
|
117
|
+
total=template_target.entity_schema.fields.count
|
|
118
|
+
indice=0
|
|
119
|
+
template_target.entity_schema.fields.each { |field|
|
|
120
|
+
indice=indice+1
|
|
121
|
+
%>query.AppendLine(" <%=field.name%><%="," if indice!=total%>");
|
|
122
|
+
<%}%>query.AppendLine("FROM");
|
|
123
|
+
query.AppendLine(" <%=template_target.entity_schema.sql_name.downcase%>");
|
|
124
|
+
query.AppendLine("WHERE");
|
|
125
|
+
<%
|
|
126
|
+
total=template_target.entity_schema.primary_fields.count
|
|
127
|
+
indice=0
|
|
128
|
+
template_target.entity_schema.primary_fields.each { |field|
|
|
129
|
+
indice=indice+1
|
|
130
|
+
%>query.AppendLine("<%=field.name%>=@p<%=indice%><%=" AND" if indice!=total%>");
|
|
131
|
+
<%}%>
|
|
132
|
+
|
|
133
|
+
DbCommand comando = CrearComando(query.ToString());
|
|
134
|
+
<%
|
|
135
|
+
indice=0
|
|
136
|
+
template_target.entity_schema.primary_fields.each { |field|
|
|
137
|
+
indice=indice+1
|
|
138
|
+
%>AgregarParametro(comando, "@p<%=indice%>",<%=field.sql_net_type%>, <%=template_target.entity_schema.name.downcase%>.<%=field.name%>);
|
|
139
|
+
<%}%>
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
using (DbConnection conexion = CrearConexionAbierta())
|
|
143
|
+
{
|
|
144
|
+
comando.Connection = conexion;
|
|
145
|
+
DbDataReader reader = comando.ExecuteReader();
|
|
146
|
+
|
|
147
|
+
if (reader.HasRows)
|
|
148
|
+
{
|
|
149
|
+
while (reader.Read())
|
|
150
|
+
{
|
|
151
|
+
T resultado = new T();
|
|
152
|
+
<%
|
|
153
|
+
template_target.entity_schema.fields.each { |field|
|
|
154
|
+
%> if (reader["<%=field.name%>"] != DBNull.Value) resultado.<%=field.name%> = (<%=field.net_type%>)reader["<%=field.name%>"];
|
|
155
|
+
<%}%>
|
|
156
|
+
|
|
157
|
+
return resultado;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/// <summary>
|
|
166
|
+
/// Actualización
|
|
167
|
+
/// </summary>
|
|
168
|
+
/// <param name="<%=template_target.entity_schema.name.downcase%>">Registro a actualizar</param>
|
|
169
|
+
public override void Actualizar(T <%=template_target.entity_schema.name.downcase%>)
|
|
170
|
+
{
|
|
171
|
+
Consultar(<%=template_target.entity_schema.name.downcase%>);
|
|
172
|
+
|
|
173
|
+
StringBuilder query = new StringBuilder();
|
|
174
|
+
query.AppendLine("UPDATE <%=template_target.entity_schema.sql_name.downcase%>");
|
|
175
|
+
query.AppendLine("SET");
|
|
176
|
+
<%
|
|
177
|
+
total=template_target.entity_schema.non_primary_fields.count
|
|
178
|
+
indice=0
|
|
179
|
+
template_target.entity_schema.non_primary_fields.each { |field|
|
|
180
|
+
indice=indice+1
|
|
181
|
+
%>query.AppendLine(" <%=field.name%>=@p<%=indice%><%="," if indice!=total%>");
|
|
182
|
+
<%}%>query.AppendLine("WHERE");
|
|
183
|
+
<%
|
|
184
|
+
total=indice + template_target.entity_schema.primary_fields.count
|
|
185
|
+
template_target.entity_schema.primary_fields.each { |field|
|
|
186
|
+
indice=indice+1
|
|
187
|
+
%>query.AppendLine(" <%=field.name%>=@p<%=indice%><%=" AND" if indice!=total%>");
|
|
188
|
+
<%}%>
|
|
189
|
+
DbCommand comando = CrearComando(query.ToString());
|
|
190
|
+
<%
|
|
191
|
+
indice=0
|
|
192
|
+
template_target.entity_schema.non_primary_fields.each { |field|
|
|
193
|
+
indice=indice+1
|
|
194
|
+
%>AgregarParametro(comando, "@p<%=indice%>",<%=field.sql_net_type%>, <%=template_target.entity_schema.name.downcase%>.<%=field.name%>);
|
|
195
|
+
<%}
|
|
196
|
+
template_target.entity_schema.primary_fields.each { |field|
|
|
197
|
+
indice=indice+1
|
|
198
|
+
%>AgregarParametro(comando, "@p<%=indice%>",<%=field.sql_net_type%>, <%=template_target.entity_schema.name.downcase%>.<%=field.name%>);
|
|
199
|
+
<%}%>
|
|
200
|
+
|
|
201
|
+
using (DbConnection conexion = CrearConexionAbierta())
|
|
202
|
+
{
|
|
203
|
+
comando.Connection = conexion;
|
|
204
|
+
comando.ExecuteNonQuery();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/// <summary>
|
|
211
|
+
/// Inserta un registro
|
|
212
|
+
/// </summary>
|
|
213
|
+
/// <param name="<%=template_target.entity_schema.name.downcase%>">Registro para insertar</param>
|
|
214
|
+
public override void Insertar(T <%=template_target.entity_schema.name.downcase%>)
|
|
215
|
+
{
|
|
216
|
+
T registroExistente = ConsultarExiste(<%=template_target.entity_schema.name.downcase%>);
|
|
217
|
+
|
|
218
|
+
if (registroExistente != null)
|
|
219
|
+
{
|
|
220
|
+
throw new AccesoDatosException("El registro ya existe");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
StringBuilder query = new StringBuilder();
|
|
224
|
+
query.AppendLine("INSERT INTO <%=template_target.entity_schema.sql_name.downcase%>");
|
|
225
|
+
query.AppendLine("(");
|
|
226
|
+
<%
|
|
227
|
+
total=template_target.entity_schema.fields.count
|
|
228
|
+
indice=0
|
|
229
|
+
template_target.entity_schema.fields.each { |field|
|
|
230
|
+
indice=indice+1
|
|
231
|
+
next if field.identity
|
|
232
|
+
%>query.AppendLine(" <%=field.name%><%="," if indice!=total%>");
|
|
233
|
+
<%}%>query.AppendLine(")");
|
|
234
|
+
query.AppendLine("VALUES");
|
|
235
|
+
query.AppendLine("(");
|
|
236
|
+
<%
|
|
237
|
+
total=template_target.entity_schema.fields.count
|
|
238
|
+
indice=0
|
|
239
|
+
template_target.entity_schema.fields.each { |field|
|
|
240
|
+
indice=indice+1
|
|
241
|
+
next if field.identity
|
|
242
|
+
%>query.AppendLine(" @p<%=indice%><%="," if indice!=total%>");
|
|
243
|
+
<%}%>query.AppendLine(")");
|
|
244
|
+
|
|
245
|
+
DbCommand comando = CrearComando(query.ToString());
|
|
246
|
+
<%
|
|
247
|
+
indice=0
|
|
248
|
+
template_target.entity_schema.fields.each { |field|
|
|
249
|
+
indice=indice+1
|
|
250
|
+
next if field.identity
|
|
251
|
+
%>AgregarParametro(comando, "@p<%=indice%>",<%=field.sql_net_type%>, <%=template_target.entity_schema.name.downcase%>.<%=field.name%>);
|
|
252
|
+
<%}%>
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
using (DbConnection conexion = CrearConexionAbierta())
|
|
256
|
+
{
|
|
257
|
+
comando.Connection = conexion;
|
|
258
|
+
comando.ExecuteNonQuery();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/// <summary>
|
|
263
|
+
/// Borrado de registros
|
|
264
|
+
/// </summary>
|
|
265
|
+
/// <param name="<%=template_target.entity_schema.name.downcase%>">Registro a eliminar</param>
|
|
266
|
+
public override void Eliminar(T <%=template_target.entity_schema.name.downcase%>)
|
|
267
|
+
{
|
|
268
|
+
Consultar(<%=template_target.entity_schema.name.downcase%>);
|
|
269
|
+
|
|
270
|
+
StringBuilder query = new StringBuilder();
|
|
271
|
+
query.AppendLine("DELETE <%=template_target.entity_schema.sql_name.downcase%>");
|
|
272
|
+
query.AppendLine("WHERE");
|
|
273
|
+
<%
|
|
274
|
+
total=template_target.entity_schema.primary_fields.count
|
|
275
|
+
indice=0
|
|
276
|
+
template_target.entity_schema.primary_fields.each { |field|
|
|
277
|
+
indice=indice+1
|
|
278
|
+
%>query.AppendLine("<%=field.name%>=@p<%=indice%><%=" AND" if indice!=total%>");
|
|
279
|
+
<%}%>
|
|
280
|
+
|
|
281
|
+
DbCommand comando = CrearComando(query.ToString());
|
|
282
|
+
<%
|
|
283
|
+
indice=0
|
|
284
|
+
template_target.entity_schema.primary_fields.each { |field|
|
|
285
|
+
indice=indice+1
|
|
286
|
+
%>AgregarParametro(comando, "@p<%=indice%>",<%=field.sql_net_type%>, <%=template_target.entity_schema.name.downcase%>.<%=field.name%>);
|
|
287
|
+
<%}%>
|
|
288
|
+
|
|
289
|
+
using (DbConnection conexion = CrearConexionAbierta())
|
|
290
|
+
{
|
|
291
|
+
comando.Connection = conexion;
|
|
292
|
+
comando.ExecuteNonQuery();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
#endregion
|
|
297
|
+
}
|
|
298
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
CapicuaGen
|
|
4
|
+
|
|
5
|
+
CapicuaGen es un software que ayuda a la creación automática de
|
|
6
|
+
sistemas empresariales a través de la definición y ensamblado de
|
|
7
|
+
diversos generadores de características.
|
|
8
|
+
|
|
9
|
+
El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
|
|
10
|
+
del 2016.
|
|
11
|
+
|
|
12
|
+
Puede modificar y distribuir este software, según le plazca, y usarlo
|
|
13
|
+
para cualquier fin ya sea comercial, personal, educativo, o de cualquier
|
|
14
|
+
índole, siempre y cuando incluya este mensaje, y se permita acceso el
|
|
15
|
+
código fuente.
|
|
16
|
+
|
|
17
|
+
Este software es código libre, y se licencia bajo LGPL.
|
|
18
|
+
|
|
19
|
+
Para más información consultar http://www.gnu.org/licenses/lgpl.html
|
|
20
|
+
=end
|
|
21
|
+
|
|
22
|
+
require 'active_support/core_ext/object/blank'
|
|
23
|
+
|
|
24
|
+
require_relative '../../../gaspar'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
module CapicuaGen::Melchior
|
|
28
|
+
|
|
29
|
+
# Modifica la case Entity Field Schema, para agregar
|
|
30
|
+
# referencias a componentes de .NET
|
|
31
|
+
class EntityFieldSchema
|
|
32
|
+
|
|
33
|
+
# Convierte el tipo de un campo o un tipo de .NET
|
|
34
|
+
def net_type
|
|
35
|
+
|
|
36
|
+
case @type.upcase
|
|
37
|
+
when "SMALLINT"
|
|
38
|
+
return "Int16"
|
|
39
|
+
when "INTEGER", "INT"
|
|
40
|
+
return "int"
|
|
41
|
+
when "DECIMAL", "REAL", "MONEY"
|
|
42
|
+
return "decimal"
|
|
43
|
+
when "CHAR", "VARCHAR", "NCHAR", "NVARCHAR"
|
|
44
|
+
return "string"
|
|
45
|
+
when "DATE", "DATETIME"
|
|
46
|
+
return "DateTime"
|
|
47
|
+
when "BIT"
|
|
48
|
+
return "bool"
|
|
49
|
+
else
|
|
50
|
+
return "object"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Convierte el tipo de un campo o un tipo SQL de .NET
|
|
56
|
+
def sql_net_type
|
|
57
|
+
|
|
58
|
+
case @type.upcase
|
|
59
|
+
when "SMALLINT"
|
|
60
|
+
return "DbType.Int16"
|
|
61
|
+
when "INTEGER", "INT"
|
|
62
|
+
return "DbType.Int32"
|
|
63
|
+
when "DECIMAL", "REAL", "MONEY"
|
|
64
|
+
return "DbType.Decimal"
|
|
65
|
+
when "CHAR", "VARCHAR", "NCHAR", "NVARCHAR"
|
|
66
|
+
return "DbType.String"
|
|
67
|
+
when "DATE", "DATETIME"
|
|
68
|
+
return "DbType.DateTime"
|
|
69
|
+
when "BIT"
|
|
70
|
+
return "DbType.Boolean"
|
|
71
|
+
else
|
|
72
|
+
return "DbType.String"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# Convierte el tipo de un campo desde un texto, a un objeto .NET
|
|
79
|
+
def convert_from_text
|
|
80
|
+
case @type.upcase
|
|
81
|
+
when "SMALLINT"
|
|
82
|
+
return "Convert.ToInt16("
|
|
83
|
+
when "INTEGER", "INT"
|
|
84
|
+
return "Convert.ToInt32("
|
|
85
|
+
when "DECIMAL", "REAL", "MONEY"
|
|
86
|
+
return "Convert.ToDecimal("
|
|
87
|
+
when "CHAR", "VARCHAR", "NCHAR", "NVARCHAR"
|
|
88
|
+
return "("
|
|
89
|
+
when "DATE", "DATETIME"
|
|
90
|
+
return "Convert.ToDateTime("
|
|
91
|
+
when "BIT"
|
|
92
|
+
return "Convert.ToBoolean("
|
|
93
|
+
else
|
|
94
|
+
return "("
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|