public void GeneraParametersCSharp(CSourceWriter sw) { foreach (var f in this.lFieldData) { if (f.IsNullable) { sw.Write("com.Parameters.AddWithValue(UtilBD.Param(\""); sw.Write(f.Name); sw.Write("\"), "); sw.Write(f.Name); sw.WriteLn(");"); } else { sw.Write("if ("); sw.Write(f.Name); sw.Write(" == null){"); sw.Write("com.Parameters.AddWithValue(UtilBD.Param(\""); sw.Write(f.Name); sw.Write("\"), "); sw.Write("DBNull.Value"); sw.WriteLn(");"); sw.WriteLn("} else {"); sw.Write("com.Parameters.AddWithValue(UtilBD.Param(\""); sw.Write(f.Name); sw.Write("\"), "); sw.Write(f.Name); sw.WriteLn(");"); sw.WriteLn("}"); } } }
internal void GenerateSql(CSourceWriter sw) { sw.WriteLn("create table dbo." + this.Name + "("); bool primero = true; sw.AddTab(); foreach (CFieldM f in this.lFieldAll) { f.GeneraSql(sw, ref primero); } if (this.lFieldPk.Count > 0) { sw.WriteLn(",CONSTRAINT PK_" + this.Name + " PRIMARY KEY ("); primero = true; sw.AddTab(); foreach (CFieldM f in this.lFieldPk) { sw.Write(""); sw.WriteComma(ref primero); sw.WriteLn(f.Name); } sw.DelTab(); sw.WriteLn(")"); } foreach (CUniqueConstraintM u in this.LUniqueConstraint) { u.GeneraSql(sw); } sw.DelTab(); sw.WriteLn(")"); sw.EndLine(); sw.WriteLn("GO"); //Genera las unique constraints }
public override void Generate(CSourceWriter sw) { CSharpProject.WriteVisibility(sw, this.Visibility); sw.Space(); if (this.Class == null) { throw new NullReferenceException("El constructor ha de tener una clase."); } sw.Write(this.Class.Name); sw.Write("("); bool Primero = true; foreach (CParam p in this.lParam) { sw.WriteComma(ref Primero); p.Generate(sw); } sw.Write(")"); sw.OpenBracesLn(); sw.AddTab(); foreach (CSentence sen in lSentence) { sen.Generate(sw); } sw.DelTab(); sw.CloseBracesLn(); }
public override void Generate(CSourceWriter sw) { CSharpProject.WriteVisibility(sw, this.Visibility); sw.Space(); if (this.IsStatic) { sw.Write("static"); sw.Space(); } if (this.IsOverride) { sw.Write("override"); sw.Space(); } this.Type.Generate(sw); sw.Space(); sw.Write(this.Name); sw.Write("("); bool Primero = true; foreach (CParam p in this.lParam) { sw.WriteComma(ref Primero); p.Generate(sw); } sw.Write(")"); sw.WriteLn("{"); sw.AddTab(); foreach (CSentence sen in lSentence) { sen.Generate(sw); } sw.DelTab(); sw.WriteLn("}"); }
public override void Generate(CSourceWriter sw) { CSharpProject.WriteVisibility(sw, this.CSharpVisibility); sw.Space(); if (this.IsStatic) { sw.Write("static"); sw.Space(); } if (this.IsPartial) { sw.Write("partial"); sw.Space(); } sw.Write("class"); sw.Space(); sw.Write(this.Name); if (!string.IsNullOrWhiteSpace(this.ParentClassName)) { sw.Write(" : "); sw.Write(this.ParentClassName); } //*** Interfaces sw.OpenBracesLn(); sw.AddTab(); foreach (CClassElement item in this.lElement) { item.Generate(sw); } sw.DelTab(); sw.CloseBracesLn(); }
private void GenerateNamespace(CSourceWriter sw) { sw.Write("namespace"); sw.Space(); sw.Write(this.Namespace); sw.OpenBracesLn(); sw.AddTab(); }
public string GeneraSelectByPk() { MemoryStream ms = new MemoryStream(); CSourceWriter sw = new CSourceWriter(ms); this.GeneraSelectByPk(sw); sw.Close(); return(Encoding.UTF8.GetString(ms.ToArray())); }
private void GeneraSelectAll(CSourceWriter sw) { sw.Write("select"); sw.Space(); this.CamposPorComas(sw); sw.Space(); sw.Write("from"); sw.Space(); sw.Write(this.Name); }
private void CamposPorComas(CSourceWriter sw) { bool Primero = true; foreach (CFieldM f in this.lFieldAll) { sw.WriteComma(ref Primero); sw.Write(f.Name); } }
private void ParametrosCamposNoClavePorComas(CSourceWriter sw) { bool Primero = true; foreach (CFieldM f in this.lFieldData) { sw.WriteComma(ref Primero); sw.Write(SUtilBD.Param(f.Name)); } }
public void GeneraInsert(CSourceWriter sw) { sw.Write("insert into "); sw.Write(this.Name); sw.Write("("); this.CamposNoIdPorComas(sw); sw.Write(")"); sw.Write("values"); sw.Write("("); this.ParametrosCamposNoIdPorComas(sw); sw.Write(")"); }
internal void GeneraSql(CSourceWriter sw) { sw.WriteLn(string.Format("alter table dbo.{0} add constraint {1} foreign key(", this.tableSource.Name, this.Name)); sw.AddTab(); sw.WriteCommaStringList(this.lFieldSource); sw.DelTab(); sw.WriteLn(") references dbo." + this.tableDestination + " ("); sw.AddTab(); sw.WriteCommaStringList(this.lFieldDestination); sw.DelTab(); sw.WriteLn(")"); sw.WriteLn("GO"); }
private void ParametrosCamposNoIdPorComas(CSourceWriter sw) { bool Primero = true; foreach (CFieldM f in this.lFieldAll) { if (!f.IsIdentity) { sw.WriteComma(ref Primero); sw.Write(SUtilBD.Param(f.Name)); } } }
internal void GeneraSql(CSourceWriter sw) { bool primero = true; //CONSTRAINT AK_TransactionID UNIQUE(TransactionID) sw.WriteLn(",constraint " + this.Nombre + " unique ("); sw.AddTab(); foreach (CFieldM f in this.LFields) { sw.WriteComma(ref primero); sw.WriteLn("" + f.Name); } sw.DelTab(); sw.WriteLn(")"); }
private void GeneraDelete(CSourceWriter sw) { sw.Write("delete from "); sw.Write(this.Name); sw.Write(" where "); bool Primero = true; foreach (CFieldM f in this.lFieldPk) { sw.WriteAnd(ref Primero); sw.Write(f.Name); sw.Write(" = "); sw.Write(SUtilBD.Param(f.Name)); } }
public override void Generate(TextWriter lMensaje) { CSourceWriter sw = new CSourceWriter(this.ParentDirectory.FullName, this.Name); try { GenerateUsings(sw); GenerateNamespace(sw); foreach (CSharpElement item in this.lElement) { item.Generate(sw); } GenerateEndNamespace(sw); } finally { sw.Close(); lMensaje.WriteLine("Generado: " + sw.FullFileName); } }
private void GeneraSelectByPk(CSourceWriter sw) { sw.Write("select"); sw.Space(); this.CamposPorComas(sw); sw.Space(); sw.Write("from"); sw.Space(); sw.Write(this.Name); bool Primero = true; var sb = new StringBuilder(); foreach (CFieldM f in this.lFieldPk) { SUtilBD.AddCondicion(ref Primero, sb, f.Name + " = @" + SUtilBD.ParamName(f.Name)); } sw.Space(); sw.Write(sb.ToString()); }
public override void Generate(CSourceWriter sw) { CSharpProject.WriteVisibility(sw, this.CSharpVisibility); sw.Space(); if (this.IsStatic) { sw.Write("static"); sw.Space(); } this.Type.Generate(sw); sw.Space(); sw.Write(this.Name); if (!string.IsNullOrWhiteSpace(this.InitialValue)) { sw.Write(" = "); sw.Write(this.InitialValue); } sw.SemicolonLn(); }
private void GenerateUsings(CSourceWriter sw) { bool escribioUsings = false; LUsing l = new LUsing(); foreach (var item in this.lElement) { l.AddLUsing(item.lUsing); } foreach (CUsing u in l) { u.Generate(sw); escribioUsings = true; } if (escribioUsings) { sw.EndLine(); } }
internal static void WriteVisibility(CSourceWriter sw, CSharpVisibility cSharpVisibility) { switch (cSharpVisibility) { case CSharpVisibility.cvPublic: sw.Write("public"); break; case CSharpVisibility.cvPrivate: sw.Write("private"); break; case CSharpVisibility.cvProtected: sw.Write("protected"); break; case CSharpVisibility.cvInternal: sw.Write("internal"); break; } }
public string GenerateSql(bool withDrops) { MemoryStream ms = new MemoryStream(); CSourceWriter sw = new CSourceWriter(ms); if (withDrops) { //Primero se borran todas las relaciones para evitar errores de eliminaciĆ³n de tablas con otras relacionadas.(Si existen) foreach (CTableM t in this.lTable) { foreach (CRelationM r in t.lRelation) { sw.WriteLn(string.Format("IF OBJECT_ID('dbo.{0}', 'F') IS NOT NULL ALTER TABLE dbo.{1} DROP CONSTRAINT {0};", r.Name, r.tableSource.Name)); sw.WriteLn("GO"); } } //Se elinan las tablas si existen foreach (CTableM t in this.lTable) { sw.WriteLn(string.Format("IF OBJECT_ID('dbo.{0}', 'U') IS NOT NULL DROP TABLE dbo.{0};", t.Name)); sw.WriteLn("GO"); } } foreach (CTableM t in this.lTable) { t.GenerateSql(sw); sw.EndLine(); } foreach (CTableM t in this.lTable) { foreach (CRelationM r in t.lRelation) { r.GeneraSql(sw); } } sw.Close(); return(Encoding.UTF8.GetString(ms.ToArray())); }
public void GeneraInsertMethod(CSourceWriter sw) { sw.Write("public static int Insert"); sw.Write(this.Name); sw.Write("("); bool primero = true; foreach (CFieldM f in this.lFieldAll) { if (!f.IsIdentity) { sw.WriteComma(ref primero); sw.Write(f.csDataTypeName()); sw.Write(" "); sw.Write(f.Name); } } sw.WriteComma(ref primero); sw.Write("SqlConnection con"); sw.Write(")"); sw.WriteLn("{"); }
public void GeneraSql(CSourceWriter sw, ref bool primero) { sw.WriteComma(ref primero); sw.Write(this.Name); sw.Write(" "); sw.Write(this.CadenaTDSqlServer); if ((this.Td == SqlDbType.VarChar) || (this.Td == SqlDbType.VarBinary)) { sw.Write("("); sw.Write(this.Lenght.ToString()); sw.Write(")"); } if (this.IsIdentity) { sw.Write(" identity "); } if (!this.IsNullable) { sw.Write(" not null "); } sw.EndLine(); }
private void GeneraUpdate(CSourceWriter sw) { sw.Write("update "); sw.Write(this.Name); sw.Write(" set "); bool Primero = true; foreach (CFieldM f in this.lFieldData) { sw.WriteComma(ref Primero); sw.Write(f.Name); sw.Write(" = "); sw.Write(SUtilBD.Param(f.Name)); } sw.Write(" where "); Primero = true; foreach (CFieldM f in this.lFieldPk) { sw.WriteComma(ref Primero); sw.Write(f.Name); sw.Write(" = "); sw.Write(SUtilBD.Param(f.Name)); } }
public override void Generate(CSourceWriter sw) { sw.Write("bool?"); }
public override void Generate(CSourceWriter sw) { sw.Write("float?"); }
public override void Generate(CSourceWriter sw) { sw.Write("double?"); }
public override void Generate(CSourceWriter sw) { sw.Write("DateTime ?"); }
public override void Generate(CSourceWriter sw) { sw.Write("string"); }
public override void Generate(CSourceWriter sw) { sw.Write("byte[]"); }