Esempio n. 1
0
 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("}");
         }
     }
 }
        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("}");
        }
Esempio n. 3
0
 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");
 }
Esempio n. 4
0
        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(")");
        }
Esempio n. 5
0
        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
        }
Esempio n. 6
0
        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()));
        }
Esempio n. 7
0
        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 override void Generate(CSourceWriter sw)
 {
     sw.WriteLn(this.Text);
 }
 public void Generate(CSourceWriter sw)
 {
     sw.WriteLn($"using {this.Text};");
 }