Пример #1
0
        /// <summary>
        /// Retourne la ligne d'insert.
        /// </summary>
        /// <param name="modelClass">Modele de la classe.</param>
        /// <param name="initItem">Item a insérer.</param>
        /// <param name="siPrimaryKeyIncluded">True si le script d'insert doit comporter la clef primaire.</param>
        /// <returns>Requête.</returns>
        private static string GetInsertLine(ModelClass modelClass, ItemInit initItem, bool siPrimaryKeyIncluded)
        {
            // Remplissage d'un dictionnaire nom de colonne => valeur.
            BeanDefinition definition = BeanDescriptor.GetDefinition(initItem.Bean);
            Dictionary <string, string> nameValueDict = new Dictionary <string, string>();

            foreach (ModelProperty property in modelClass.PersistentPropertyList)
            {
                if (!property.DataDescription.IsPrimaryKey || siPrimaryKeyIncluded || property.DataDescription.Domain.Code == "DO_CD")
                {
                    BeanPropertyDescriptor propertyDescriptor = definition.Properties[property.Name];
                    object propertyValue    = propertyDescriptor.GetValue(initItem.Bean);
                    string propertyValueStr = propertyValue == null ? "NULL" : propertyValue.ToString();
                    if (property.DataType == "byte[]")
                    {
                        nameValueDict[property.DataMember.Name] = propertyValueStr;
                    }
                    else if (propertyDescriptor.PrimitiveType == typeof(string))
                    {
                        nameValueDict[property.DataMember.Name] = propertyValue == null ? "NULL" : "N'" + ScriptUtils.PrepareDataToSqlDisplay(propertyValueStr) + "'";
                    }
                    else
                    {
                        nameValueDict[property.DataMember.Name] = propertyValue == null ? "NULL" : propertyValueStr;
                    }
                }
            }

            // Création de la requête.
            StringBuilder sb = new StringBuilder();

            sb.Append("\tINSERT INTO " + modelClass.DataContract.Name + "(");
            bool isFirst = true;

            foreach (string columnName in nameValueDict.Keys)
            {
                if (!isFirst)
                {
                    sb.Append(", ");
                }

                isFirst = false;
                sb.Append(columnName);
            }

            sb.Append(") VALUES(");

            isFirst = true;
            foreach (string value in nameValueDict.Values)
            {
                if (!isFirst)
                {
                    sb.Append(", ");
                }

                isFirst = false;
                sb.Append(value);
            }

            sb.Append(");");
            return(sb.ToString());
        }
Пример #2
0
 /// <summary>
 /// Ecrit la création de la propriété de description de la table.
 /// </summary>
 /// <param name="writer">Writer.</param>
 /// <param name="classe">Classe de la table.</param>
 private static void WriteTableDescriptionProperty(TextWriter writer, ModelClass classe)
 {
     writer.WriteLine("/* Description property. */");
     writer.WriteLine("EXECUTE sp_addextendedproperty 'Description', '" + ScriptUtils.PrepareDataToSqlDisplay(classe.Label) + "', 'SCHEMA', 'dbo', 'TABLE', '" + classe.GetTableName() + "';");
 }