Ejemplo n.º 1
0
        /// <summary>
        /// Genera código de parámetros de llamado a un método.
        /// </summary>
        /// <param name="MethodActionType">información sobre el método a generar.</param>
        /// <param name="pTable">tabla.</param>
        /// <returns>Código que representa los parámetros para ejecutar el método.</returns>
        /// <author>Marcelo Oviedo</author>
        static string GenMethodParameters(MethodActionType pMethodActionType, Table pTable)
        {
            String wBuilder = string.Empty;

            switch (pMethodActionType)
            {
            case MethodActionType.Insert:
            case MethodActionType.Update:
            case MethodActionType.GetByParam:
            case MethodActionType.SearchByParam:

                wBuilder = string.Concat(pTable.Name, " p", pTable.Name);
                break;

            case MethodActionType.Delete:
                Column pPK = FwkGeneratorHelper.GetPrimaryKey(pTable);
                if (pPK != null)
                {
                    FwkGeneratorHelper.GetCSharpType(pPK);
                    wBuilder = String.Concat(FwkGeneratorHelper.GetCSharpType(pPK), " p", pPK.Name);
                }
                else
                {
                    wBuilder = String.Concat("int pId");
                }

                break;
            }
            return(wBuilder);
        }
Ejemplo n.º 2
0
        static string GenSPParameters_Batch(Table pTable, MethodActionType pMethodActionType)
        {
            StringBuilder wParams        = new StringBuilder();
            int           i              = 0;
            bool          appendProperty = true;
            Column        primaryKey     = FwkGeneratorHelper.GetPrimaryKey(pTable);

            foreach (Column c in pTable.Columns)
            {
                i++;

                if (pMethodActionType == MethodActionType.Insert ||
                    pMethodActionType == MethodActionType.Update)
                {
                    if (primaryKey != null)
                    {
                        appendProperty = !(primaryKey == c && pMethodActionType == MethodActionType.Insert);
                    }

                    if (appendProperty)
                    {
                        //i == pTable.Columns.Count --> Fin de la coleccion
                        wParams.Append(Get_Property_Batch(c, (i == pTable.Columns.Count)));
                    }
                }
            }
            return(wParams.ToString());
        }
Ejemplo n.º 3
0
        static string GetInParameter(Table pTable, Column c)
        {
            StringBuilder wParamBuilder = new StringBuilder(FwkGeneratorHelper.TemplateDocument.GetTemplate("ParameterInput").Content);

            //Si es un tipo de dato string y hacepta nulos se agrega la condicion para decidir si pasar o no el parametros al SP
            if (c.Nullable && FwkGeneratorHelper.GetDBType(c).Contains("string"))
            {
                wParamBuilder.Replace("[ConditionalString]", FwkGeneratorHelper.TemplateDocument.GetTemplate("ConditionalString").Content);
            }
            else
            {
                wParamBuilder.Replace("[ConditionalString]", String.Empty);
            }

            //quito si esxiste la cadena .Value de [Property_Name].Value.ToString("yy
            if (!c.Nullable)
            {
                wParamBuilder.Replace("Value.", string.Empty);
            }

            wParamBuilder.Replace("[ParameterName]", c.Name);
            wParamBuilder.Replace("[ParameterType]", FwkGeneratorHelper.GetDBType(c));
            wParamBuilder.Replace("[ParameterValue]", string.Concat("p", pTable.Name, ".", c.Name));



            return(wParamBuilder.ToString());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Obtiene el seteo de parametro que se envia a un store procedure  para Aplication Block,
        /// en forma de batch.-
        ///
        /// </summary>
        /// <param name="pTableName">Nombre de tabla</param>
        /// <param name="pColumnName">Nombre de columna</param>
        /// <param name="pType">Tipo de SQL Server</param>
        ///<example>
        /// <code>
        ///
        ///   #region [[Property_Name]]
        ///   public [TYPENAME] [Property_Name]
        ///     {
        ///      get { return _[Property_Name]; }
        ///      set { _[Property_Name] = value;  }
        ///     }
        ///   #endregion
        ///
        /// </code>
        /// </example>
        /// <returns>string</returns>
        internal static string GetCsharpProperty(Column pColumn)
        {
            string wTypeName = pColumn.DataType.Name.ToUpper();

            if (pColumn.DataType.SqlDataType.ToString().Equals("UserDefinedDataType"))
            {
                wTypeName = UserDefinedTypes.GetUserDefinedType(pColumn.DataType.Name).SystemType.ToUpper();
            }

            System.Text.StringBuilder str = new System.Text.StringBuilder(_Entity_Property_tt);



            switch (wTypeName)
            {
            case "IMAGE":
            case "VARBINARY":
            case "BINARY":

                str = new System.Text.StringBuilder(_Entity_Property_TemplateBinary_tt);
                //str.Replace(CommonConstants.CONST_TYPENAME, "Byte[]");
                break;
            }



            str.Replace(CommonConstants.CONST_TYPENAME, FwkGeneratorHelper.GetCSharpType(pColumn));
            str.Replace("[NullToken]", GetNullableToken(pColumn));
            str.Replace(CommonConstants.CONST_ENTITY_PROPERTY_NAME, pColumn.Name);
            str.AppendLine(Environment.NewLine);

            return(str.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Genera comentarios sobre los parámetros de un método.
        /// </summary>
        /// <param name="pMethodInfo">información sobre el método a generar.</param>
        /// <returns>Comentarios sobre los parámetros.</returns>
        /// <author>Marcelo Oviedo</author>
        static string GenParametersSummary(MethodActionType pMethodActionType, Table pTable)
        {
            StringBuilder wBuilder = new StringBuilder(FwkGeneratorHelper.TemplateDocument.GetTemplate("ParameterSummary").Content);



            switch (pMethodActionType)
            {
            case MethodActionType.Insert:
            case MethodActionType.Update:
            case MethodActionType.GetByParam:
            case MethodActionType.SearchByParam:

                wBuilder.Replace("[MethodParameterName]", pTable.Name);
                wBuilder.Replace("[ParameterName]", pTable.Name);
                break;

            case MethodActionType.Delete:
                Column pPK = FwkGeneratorHelper.GetPrimaryKey(pTable);
                if (pPK != null)
                {
                    wBuilder.Replace("[MethodParameterName]", pPK.Name);
                }
                else
                {
                    wBuilder.Replace("[MethodParameterName]", "pId");
                }
                wBuilder.Replace("[ParameterName]", string.Concat("Id por el cual realizar la busqueda de registros a eliminar de tabla ", pTable.Name));
                break;
            }
            return(wBuilder.ToString());
        }
Ejemplo n.º 6
0
        static string GetOutParameter(Table pTable, Column c)
        {
            StringBuilder wParamBuilder = new StringBuilder(FwkGeneratorHelper.TemplateDocument.GetTemplate("ParameterOutput").Content);

            wParamBuilder.Replace("[ParameterName]", c.Name);
            wParamBuilder.Replace("[ParameterType]", FwkGeneratorHelper.GetDBType(c));
            wParamBuilder.Replace("[ParameterLength]", c.DataType.MaximumLength.ToString());


            return(wParamBuilder.ToString());
        }
Ejemplo n.º 7
0
        static FwkGeneratorHelper()
        {
            //roottemplate = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates"); //Path.Combine(HelperFunctions.ProgramFilesx86(), @"Allus Global BPO\FwkTemplates\tt\");
            roottemplate      = Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Templates");
            _TemplateDocument = (TemplateDocument)HelperFunctions.DeserializeFromXml(typeof(TemplateDocument), GetFileTemplate("Templates.xml"));
            _MappingTypes     = (MappingTypes)HelperFunctions.DeserializeFromXml(typeof(MappingTypes), GetFileTemplate("MappingType.xml"));

            NotSupportTypes_ToIncludeInBackEnd = "xml,timestamp,sql_variant";

            NotSupportTypes_ToSearchInStoreProcedure = "xml,timestamp,sql_variant,varbinary,binary,image";
            NotSupportTypes_ToInsertStoreProcedure   = "xml,timestamp,sql_variant";


            _Entity_Envelope_tt = FwkGeneratorHelper.GetFileTemplate("Entity.txt");
            _Entity_Property_TemplateBinary_tt = _TemplateDocument.GetTemplate("Property_Binary").Content;

            _Entity_Property_tt = _TemplateDocument.GetTemplate("Property").Content;

            _Entity_Member_tt = "           private [TYPENAME][NullToken] _[Property_Name];";
        }
Ejemplo n.º 8
0
        static FwkGeneratorHelper()
        {
            roottemplate = Path.Combine(HelperFunctions.ProgramFilesx86(), @"Fwk Software Factory\5.0\FwkTemplates\tt\");

            _TemplateDocument = (TemplateDocument)HelperFunctions.DeserializeFromXml(typeof(TemplateDocument), GetFileTemplate("Templates.xml"));
            _MappingTypes     = (MappingTypes)HelperFunctions.DeserializeFromXml(typeof(MappingTypes), GetFileTemplate("MappingType.xml"));

            NotSupportTypes_ToIncludeInBackEnd = "xml,timestamp,sql_variant";

            NotSupportTypes_ToSearchInStoreProcedure = "xml,timestamp,sql_variant,varbinary,binary,image";
            NotSupportTypes_ToInsertStoreProcedure   = "xml,timestamp,sql_variant";


            _Entity_Envelope_tt = FwkGeneratorHelper.GetFileTemplate("Entity.txt");
            _Entity_Property_TemplateBinary_tt = _TemplateDocument.GetTemplate("Property_Binary").Content;

            _Entity_Property_tt = _TemplateDocument.GetTemplate("Property").Content;

            _Entity_Member_tt = "           private [TYPENAME][NullToken] _[Property_Name];";

            UserDefinedTypes = new UserDefinedTypes();
        }
Ejemplo n.º 9
0
        private static string GenMethodReturn(TableViewBase pTable, CodeGeneratorCommon.MethodActionType t)
        {
            StringBuilder wBuilderReturn = null;

            switch (t)
            {
            case CodeGeneratorCommon.MethodActionType.Insert:
            {
                Column pPK = FwkGeneratorHelper.GetPrimaryKey(pTable);
                if (pPK != null)
                {
                    wBuilderReturn = new StringBuilder("  cmd.ExecuteNonQuery();");
                    wBuilderReturn.AppendLine(FwkGeneratorHelper.TemplateDocument.GetTemplate("InsertReturn").Content);
                    wBuilderReturn.Replace(CodeGeneratorCommon.CommonConstants.CONST_ENTITY_PROPERTY_NAME, pPK.Name);
                    wBuilderReturn.Replace(CodeGeneratorCommon.CommonConstants.CONST_TYPENAME, FwkGeneratorHelper.GetCSharpType(pPK));

                    return(wBuilderReturn.ToString());
                }
                else
                {
                    return("  cmd.ExecuteNonQuery();");
                }
            }

            case CodeGeneratorCommon.MethodActionType.Update:
                return("  cmd.ExecuteNonQuery();");

            case CodeGeneratorCommon.MethodActionType.SearchByParam:

                wBuilderReturn = new StringBuilder(FwkGeneratorHelper.TemplateDocument.GetTemplate("SearchReturn").Content);

                return(wBuilderReturn.ToString());

            case CodeGeneratorCommon.MethodActionType.Delete:
                return("  cmd.ExecuteNonQuery();");
            }

            return(string.Empty);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Retorna codigo de miembros privados + los atributos publicos.-
        /// </summary>
        /// <param name="pTable">tabla</param>
        /// <param name="pPublicProperty_Body">atributos publicos</param>
        /// <param name="pPrivateMembers_Body">miembros privados</param>
        static void GenerateDataBaseProperttyBody(Table pTable, out String pPublicProperty_Body, out String pPrivateMembers_Body)
        {
            StringBuilder wPrivateMembers_BODY = new StringBuilder();
            StringBuilder wPublicProperty_BODY = new StringBuilder();

            foreach (Column wColumn in pTable.Columns)
            {
                //Si es una columna no permitida
                if (!FwkGeneratorHelper.NotSupportTypes_ToIncludeInBackEnd.Contains(wColumn.DataType.Name.ToLower()))
                {
                    //if (wColumn.Selected)
                    //{
                    //Privados
                    wPrivateMembers_BODY.Append(FwkGeneratorHelper.GetCsharpMember(wColumn));
                    //Publicos (con Get y Set)
                    wPublicProperty_BODY.Append(FwkGeneratorHelper.GetCsharpProperty(wColumn));
                    //}
                }
            }
            pPrivateMembers_Body = wPrivateMembers_BODY.ToString();
            pPublicProperty_Body = wPublicProperty_BODY.ToString();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Retorno del metodo
        /// </summary>
        /// <param name="pTable"></param>
        /// <param name="pMethodActionType"></param>
        /// <returns></returns>
        static string GetRetType(Table pTable, MethodActionType pMethodActionType)
        {
            String wBuilder = string.Empty;
            Column c        = FwkGeneratorHelper.GetPrimaryKey(pTable);

            switch (pMethodActionType)
            {
            case MethodActionType.Insert:

            case MethodActionType.Update:
            case MethodActionType.Delete:
                wBuilder = "void";
                break;

            case MethodActionType.SearchByParam:
                wBuilder = string.Concat(pTable.Name, "List");
                break;

            case MethodActionType.GetByParam:
                wBuilder = pTable.Name;
                break;
            }
            return(wBuilder);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Obtiene el seteo de parametro que se envia a un store procedure  para Aplication Block,
        /// en forma de batch.-
        ///
        /// </summary>
        /// <param name="pTableName">Nombre de tabla</param>
        /// <param name="pColumnName">Nombre de columna</param>
        /// <param name="pType">Tipo de SQL Server</param>
        /// <param name="pLastField">indica si es el ultimo parametro</param>
        ///<example>
        /// <code>
        ///
        ///   BatchCommandText.Append("@[Property_Name] = ");
        ///   if (w[NamePattern].[Property_Name] != null)
        ///    {
        ///         BatchCommandText.Append(w[NamePattern].[Property_Name]  == true ? "1":"0");
        ///     }
        ///     else { BatchCommandText.Append("NULL"); }
        ///     BatchCommandText.Append( ",");
        ///
        /// </code>
        /// </example>
        /// <returns>string</returns>
        static string Get_Property_Batch(Column c, bool pLastField)
        {
            System.Text.StringBuilder str = new System.Text.StringBuilder();

            switch (c.DataType.ToString().ToUpper())
            {
            case "BIT":
                str.Append(FwkGeneratorHelper.TemplateDocument.GetTemplate("SPParameterBatchBit").Content);
                break;

            case "REAL":
            case "NUMERIC":
            case "BIGINT":
            case "SMALLINT":
            case "INT":
            case "TINYINT":
                str.Append(FwkGeneratorHelper.TemplateDocument.GetTemplate("SPParameterBatchInteger").Content);
                break;

            case "MONEY":
            case "SMALLMONEY":
            case "DECIMAL":
            case "FLOAT":
                str.Append(FwkGeneratorHelper.TemplateDocument.GetTemplate("SPParameterBatchDecimal").Content);
                break;

            case "SMALLDATETIME":
            case "DATETIME":
                str.Append(FwkGeneratorHelper.TemplateDocument.GetTemplate("SPParameterBatchDateTime").Content);
                break;

            case "TEXT":
            case "CHAR":
            case "NCHAR":
            case "VARCHAR":
            case "NVARCHAR":
                str.Append(FwkGeneratorHelper.TemplateDocument.GetTemplate("SPParameterBatchString").Content);
                break;

            ///TODO:Ver paso de binarios por batch
            case "IMAGE":
            case "VARBINARY":
            case "BINARY":
                str.Append(FwkGeneratorHelper.TemplateDocument.GetTemplate("SPParameterBatchString").Content);
                break;
            }
            if (!c.Nullable)
            {
                str.Replace("[Batch_NULL_Question]", String.Empty);
            }

            else
            {
                if (FwkGeneratorHelper.GetCSharpType(c).Contains("string"))
                {
                    str.Replace("[Batch_NULL_Question_string]", FwkGeneratorHelper.TemplateDocument.GetTemplate("Batch_NULL_Question").Content);
                }
                else
                {
                    str.Replace("[Batch_NULL_Question]", FwkGeneratorHelper.TemplateDocument.GetTemplate("Batch_NULL_Question").Content);
                }
            }



            str.Replace(CommonConstants.CONST_ENTITY_PROPERTY_NAME, c.Name);

            if (pLastField)
            {
                str.Replace("wBatchCommandText.Append( \",\");", "wBatchCommandText.Append( \";\");");
            }

            return(str.ToString());
        }
Ejemplo n.º 13
0
        static string GenSPParameters(Table pTable, MethodActionType pMethodActionType)
        {
            StringBuilder wParams = new StringBuilder();



            switch (pMethodActionType)
            {
            case MethodActionType.Insert:
                foreach (Column c in pTable.Columns)
                {
                    if (!FwkGeneratorHelper.NotSupportTypes_ToIncludeInBackEnd.Contains(c.DataType.SqlDataType.ToString().ToLower()))
                    {
                        if (c.InPrimaryKey)
                        {
                            wParams.Append(GetOutParameter(pTable, c));
                        }
                        else
                        {
                            wParams.Append(GetInParameter(pTable, c));
                        }
                    }
                }
                break;

            case MethodActionType.Update:
                foreach (Column c in pTable.Columns)
                {
                    if (!FwkGeneratorHelper.NotSupportTypes_ToIncludeInBackEnd.Contains(c.DataType.SqlDataType.ToString().ToLower()))
                    {
                        wParams.Append(GetInParameter(pTable, c));
                    }
                }
                break;

            case MethodActionType.Delete:

                Column cPK = FwkGeneratorHelper.GetPrimaryKey(pTable);
                if (cPK != null)
                {
                    wParams.Append(GetInParameter(cPK.Name, FwkGeneratorHelper.GetDBType(cPK)));
                }
                else
                {
                    wParams.Append(GetInParameter("Id", "System.Data.DbType.Int32"));
                }

                break;

            case MethodActionType.SearchByParam:

                foreach (Column c in pTable.Columns)
                {
                    if (FwkGeneratorHelper.GeColumnFindeable(c))
                    {
                        wParams.Append(GetInParameter(pTable, c));
                    }
                }
                break;

            case MethodActionType.Get:
                wParams.Append(string.Empty);
                break;
            }
            return(wParams.ToString());
        }
Ejemplo n.º 14
0
 static GenDAC()
 {
     _DAC_tt    = FwkGeneratorHelper.GetFileTemplate("DAC.txt");
     _Method_tt = FwkGeneratorHelper.TemplateDocument.GetTemplate("Method").Content; //FwkGeneratorHelper.GetFileTemplate("Method.txt");
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Genera código fuente de un parámetro del procedimiento almacenado a partir de un campo de la tabla.
        /// </summary>
        /// <param name="pTableFieldInfo">información sobre el parámetro a generar.</param>
        /// <param name="pActionType">Tipo de Acción a realizar por el procedimiento almacenado.</param>
        /// <param name="pSetDirection">Dirección del parámetro.</param>
        /// <param name="pSetDefaultNull">Indica si se pasa NULL como valor por defecto.</param>
        /// <returns>Código fuente del parámetro.</returns>
        /// <date>2007-5-25T00:00:00</date>
        /// <author>Marcelo Oviedo</author>
        static StringBuilder BuildParameter(Column pColumn,
                                            CodeGeneratorCommon.MethodActionType pActionType, bool pSetDirection, bool pSetDefaultNull)
        {
            string        wDirection = string.Empty;
            StringBuilder wBuilder   = new StringBuilder();

            wBuilder.Append("\t");
            wBuilder.Append(FwkGeneratorHelper.GetParameterPattern(pColumn));
            //@Nombre
            wBuilder.Replace("[Name]", "@" + pColumn.Name);
            if (pColumn.DataType.ToString().ToLower().Contains("image"))
            {
                wBuilder.Replace("[Type]", "varbinary");
            }
            else
            {
                wBuilder.Replace("[Type]", pColumn.DataType.ToString());
            }

            if (pColumn.DataType.MaximumLength != -1 && pColumn.DataType.MaximumLength != 0)
            {
                wBuilder.Replace("[Length]", pColumn.DataType.MaximumLength.ToString());
            }
            else
            {
                wBuilder.Replace("[Length]", "max");
            }

            wBuilder.Replace("[Precision]", pColumn.DataType.NumericPrecision.ToString());
            wBuilder.Replace("[Scale]", pColumn.DataType.NumericScale.ToString());

            if (pSetDirection)
            {
                ParameterDirection wParamDirection = ((pColumn.InPrimaryKey) && (pActionType == CodeGeneratorCommon.MethodActionType.Insert)) ? ParameterDirection.Output : ParameterDirection.Input;

                switch (wParamDirection)
                {
                case System.Data.ParameterDirection.Input:
                {
                    wDirection = String.Empty;
                    break;
                }

                case System.Data.ParameterDirection.Output:
                {
                    wDirection = "OUTPUT";
                    break;
                }

                case System.Data.ParameterDirection.InputOutput:
                {
                    wDirection = String.Empty;
                    break;
                }

                default:
                {
                    wDirection = string.Empty;
                    break;
                }
                }
            }

            wBuilder.Replace("[Direction]", wDirection);

            if (pSetDefaultNull && pColumn.Nullable)
            {
                wBuilder.Append(" = NULL");
            }

            wBuilder.Append(",\r\n");

            return(wBuilder);
        }
Ejemplo n.º 16
0
 static GenSVC()
 {
     _ISVC_tt = FwkGeneratorHelper.GetFileTemplate("Isvc.txt");
     _SVC_tt  = FwkGeneratorHelper.GetFileTemplate("Svc.txt");
 }