protected void WriteTableDefinitionRow(String entityName, EntityField currField) { String str = ""; switch (currField.FieldType) { case EntityFieldType.String: str = GenerateRowForStringFieldType(currField); break; case EntityFieldType.SLong: str = GenerateRowForSLongFieldType(currField); break; case EntityFieldType.Float: str = GenerateRowForFloatFieldType(currField); break; case EntityFieldType.DateTime: str = GenerateRowForDateTimeFieldType(currField); break; case EntityFieldType.Boolean: str = GenerateRowForBooleanFieldType(currField); break; case EntityFieldType.DecimalOrMoney: str = GenerateRowForDecimalOrMoneyFieldType(currField); break; case EntityFieldType.DirectoryItem: // indexes generated in Indexes4TableCreator str = GenerateRowForDirectoryItemFieldType(currField); break; case EntityFieldType.Link2TableOrVirtaulPart: switch (currField.LinkType) { case LinkType.One2OneTablePartOfObject: // indexes generated in Indexes4TableCreator str = GenerateRowForLinkOne2OneTable(currField); break; case LinkType.N2OneTableOtherObject: // indexes generated in Indexes4TableCreator str = GenerateRowForLinkN2OneTable(currField); break; case LinkType.N2MTableOtherObject: // link table and indexes generated here str = GenerateLinkTableForN2MLink(entityName, currField); break; default: throw new Exception("Error: LinkType has unsupported value !!!"); } break; default: throw new Exception("Error: FieldType has unsupported value !!!"); } FileWriter.WriteString(str); }
private void FillOneTblTranslatedString(TranslatedString transStr, StringFileWriter fileWriter) { fileWriter.WriteString(""); fileWriter.WriteString("IF NOT EXISTS( SELECT * FROM tblTranslatedString"); fileWriter.WriteString(" WHERE Language=" + transStr.Language.ToString() + " AND Type=" + ((int)transStr.Type).ToString() + " AND "); fileWriter.WriteString(" ReferencedItemId=" + transStr.ReferencedItemId.ToString() + " AND Value=\'" + transStr.Value.ToString() + "\' )"); fileWriter.WriteString("BEGIN"); fileWriter.WriteString(" INSERT INTO tblTranslatedString "); fileWriter.WriteString(" ( Language, Type, ReferencedItemId, Value )"); fileWriter.WriteString(" VALUES"); fileWriter.WriteString(" ( " + transStr.Language.ToString() + ", " + ((int)transStr.Type).ToString() + ", " + transStr.ReferencedItemId.ToString() + ", \'" + transStr.Value.ToString() + "\' );"); fileWriter.WriteString("END"); }
public void Generate() { StringFileWriter FileWriter = new StringFileWriter(DataConfiguration.OutputPath, "fill_tblLanguage", OutputFileType.SqlScript); FileWriter.WriteString("SET IDENTITY_INSERT tblLanguage ON;"); foreach (var currLanguage in DataConfiguration.Languages.Values) { FillOneTableRow(currLanguage, FileWriter); } FileWriter.WriteString("SET IDENTITY_INSERT tblLanguage OFF;"); FileWriter.WriteString("GO"); FileWriter.Close(); }
protected String GenerateLinkTableForN2MLink(String entityName, EntityField currField) { String tableName = "n2m" + entityName + currField.LinkedEntityName; StringFileWriter FileWriter = new StringFileWriter(DataConfiguration.OutputPath, tableName, OutputFileType.SqlScript); FileWriter.WriteString("CREATE TABLE " + tableName + "("); FileWriter.WriteString(EmptyPrefix4 + "Id BIGINT IDENTITY(1,1) NOT NULL PRIMARY KEY,"); FileWriter.WriteString(EmptyPrefix4 + "[" + entityName + "]" + " BIGINT FOREIGN KEY REFERENCES tbl" + entityName + "(Id),"); FileWriter.WriteString(EmptyPrefix4 + "[" + currField.LinkedEntityName + "]" + " BIGINT FOREIGN KEY REFERENCES tbl" + currField.LinkedEntityName + "(Id),"); FileWriter.WriteString(");"); FileWriter.WriteString("GO"); FileWriter.Close(); String indexFileName = "idx" + entityName + currField.LinkedEntityName; FileWriter = new StringFileWriter(DataConfiguration.OutputPath, indexFileName, OutputFileType.SqlScript); FileWriter.WriteString("CREATE INDEX " + indexFileName + "_" + entityName + " "); FileWriter.WriteString(EmptyPrefix4 + "ON [" + tableName + "]([" + entityName + "]); "); FileWriter.WriteString("GO"); FileWriter.WriteString(""); FileWriter.WriteString("CREATE INDEX " + indexFileName + "_" + currField.LinkedEntityName + " "); FileWriter.WriteString(EmptyPrefix4 + "ON [" + tableName + "]([" + currField.LinkedEntityName + "]); "); FileWriter.WriteString("GO"); FileWriter.Close(); String result = EmptyPrefix4 + "-- see N2M link table n2m" + entityName + currField.LinkedEntityName; return(result); }
private void FillOneTableRow(LanguageItem currLangItem, StringFileWriter fileWriter) { fileWriter.WriteString(""); fileWriter.WriteString("IF NOT EXISTS( SELECT * FROM tblLanguage WHERE Id=" + currLangItem.Id.ToString() + " )"); fileWriter.WriteString("BEGIN"); fileWriter.WriteString(" INSERT INTO tblLanguage "); fileWriter.WriteString(" ( Id, EnumName, UIName )"); fileWriter.WriteString(" VALUES"); fileWriter.WriteString(" ( " + currLangItem.Id.ToString() + ", \'" + currLangItem.EnumName + "\', \'" + currLangItem.UIName + "\' );"); fileWriter.WriteString("END"); }
public void GenerateFile(String entityName, List <EntityField> fields) { List <EntityField> fieldsWithIndexes = new List <EntityField>(); foreach (var currField in fields) { if (currField.FieldType == EntityFieldType.DirectoryItem || ( currField.FieldType == EntityFieldType.Link2TableOrVirtaulPart && currField.LinkType != LinkType.N2MTableOtherObject && currField.LinkType != LinkType.One2OneVirtualPartOfObject ) || currField.GridColumnIsSortingAllowed == true || currField.FieldFilterIsRequired == true ) { fieldsWithIndexes.Add(currField); } } foreach (var currField in fieldsWithIndexes) { String idxEntityName, idxFieldName; if (currField.IsFieldOfVirtualNestedEntity == true || currField.FieldType == EntityFieldType.DirectoryItem || currField.FieldType == EntityFieldType.Link2TableOrVirtaulPart) { idxEntityName = _rootEntityName; idxFieldName = currField.Name; } else { idxEntityName = currField.LinkedEntityName; idxFieldName = currField.LinkedFieldName; } _fileWriter.WriteString("CREATE INDEX " + _indexFileName + "_" + currField.Name + " "); _fileWriter.WriteString(EmptyPrefix4 + "ON [tbl" + idxEntityName + "]([" + idxFieldName + "]); "); _fileWriter.WriteString("GO"); _fileWriter.WriteString(""); } _fileWriter.Close(); }
public void Generate() { // заполняем словарными данными tblDirectory ------------------------------------------------------------------------------------------------ StringFileWriter FileWriter_tblDirectory = new StringFileWriter(DataConfiguration.OutputPath, "fill_tblDirectory", OutputFileType.SqlScript); FileWriter_tblDirectory.WriteString(""); FileWriter_tblDirectory.WriteString("SET IDENTITY_INSERT tblDirectory ON;"); FileWriter_tblDirectory.WriteString(""); foreach (var currDirectory in DataConfiguration.DirectoryConfigurations.Values) { FillOneTblDirectoryRow(currDirectory, FileWriter_tblDirectory); } FileWriter_tblDirectory.WriteString(""); FileWriter_tblDirectory.WriteString("SET IDENTITY_INSERT tblDirectory OFF;"); FileWriter_tblDirectory.WriteString("GO"); FileWriter_tblDirectory.Close(); // заполняем словарными данными tblDirectoryValue ------------------------------------------------------------------------------------------- StringFileWriter FileWriter_tblDirectoryValue = new StringFileWriter(DataConfiguration.OutputPath, "fill_tblDirectoryValue", OutputFileType.SqlScript); FileWriter_tblDirectoryValue.WriteString(""); FileWriter_tblDirectoryValue.WriteString("SET IDENTITY_INSERT tblDirectoryValue ON;"); FileWriter_tblDirectoryValue.WriteString(""); foreach (var currDirectory in DataConfiguration.DirectoryConfigurations.Values) { foreach (var currDirectoryValue in currDirectory.Items.Values) { FillOneTblDirectoryValue(currDirectoryValue, FileWriter_tblDirectoryValue); } } FileWriter_tblDirectoryValue.WriteString(""); FileWriter_tblDirectoryValue.WriteString("SET IDENTITY_INSERT tblDirectoryValue OFF;"); FileWriter_tblDirectoryValue.WriteString("GO"); FileWriter_tblDirectoryValue.Close(); // заполняем словарными данными tblTranslatedString ----------------------------------------------------------------------------------------- StringFileWriter FileWriter_tblTranslatedString = new StringFileWriter(DataConfiguration.OutputPath, "fill_tblTranslatedString", OutputFileType.SqlScript); foreach (var currDirectory in DataConfiguration.DirectoryConfigurations.Values) { foreach (var currTranslatedString in currDirectory.TranslatedUINames) { FillOneTblTranslatedString(currTranslatedString, FileWriter_tblTranslatedString); } foreach (var currDirectoryValue in currDirectory.Items.Values) { foreach (var currTranslatedUIName in currDirectoryValue.TranslatedUINames) { FillOneTblTranslatedString(currTranslatedUIName, FileWriter_tblTranslatedString); } foreach (var currTranslatedUIComment in currDirectoryValue.TranslatedUIComments) { FillOneTblTranslatedString(currTranslatedUIComment, FileWriter_tblTranslatedString); } } } FileWriter_tblTranslatedString.Close(); }
private void FillOneTblDirectoryRow(Directory dirItem, StringFileWriter fileWriter) { fileWriter.WriteString(""); fileWriter.WriteString("IF NOT EXISTS( SELECT * FROM tblDirectory WHERE Id=" + dirItem.Id.ToString() + " )"); fileWriter.WriteString("BEGIN"); fileWriter.WriteString(" INSERT INTO tblDirectory "); fileWriter.WriteString(" ( Id, EnumName, IsReadOnly )"); fileWriter.WriteString(" VALUES"); String IsReadOnlyStr = dirItem.IsReadOnly == true ? "1" : "0"; fileWriter.WriteString(" ( " + dirItem.Id.ToString() + ", \'" + dirItem.EnumName + "\', " + IsReadOnlyStr + " );"); fileWriter.WriteString("END"); }
private void CreateOneViewForComplexEntity(ComplexEntity complexEntity) { String viewName = "vw" + complexEntity.Name; StringFileWriter FileWriter = new StringFileWriter(DataConfiguration.OutputPath, viewName, OutputFileType.SqlScript); FileWriter.WriteString("CREATE VIEW " + viewName); FileWriter.WriteString("AS"); FileWriter.WriteString("SELECT "); List <String> allFields = new List <string>(); // получим все поля из основной сущности if (complexEntity.IsMainTableLink == false) { allFields.AddRange(GenerateEntityFields(complexEntity.MainEntityTableName, complexEntity.MainEntityShortName)); } // получим все поля из связанных сущностей allFields.AddRange(ProcessLinkFields(complexEntity)); // сегенрируем поля в скрипте с учетом отсутствия запятой после последнего for (int i = 0; i < allFields.Count; i++) { var currFieldStr = allFields[i]; FileWriter.Write(" " + currFieldStr); if (i < allFields.Count - 1) { FileWriter.WriteString(","); } else { FileWriter.WriteString(""); } } FileWriter.WriteString("FROM [" + complexEntity.MainEntityTableName + "] [" + complexEntity.MainEntityShortName + "] "); foreach (var currLink in complexEntity.Links) { GenerateJoinClause(currLink, FileWriter); } FileWriter.WriteString("GO"); FileWriter.Close(); }
private void FillOneFile(List <EnumItem> items, String itemName) { String enName = itemName; StringFileWriter FileWriter = new StringFileWriter( DataTransferObjectsConfiguration.OutputPath, enName, OutputFileType.CSharpSource); FileWriter.WriteString("namespace Common.DataTransferObjects.AppIdAndAuth.ApplicationId "); FileWriter.WriteString("{ "); FileWriter.WriteString(" using System;"); FileWriter.WriteString(""); FileWriter.WriteString(" public enum " + enName); FileWriter.WriteString(" { "); FillOneFileItems(items, FileWriter); FileWriter.WriteString(" } "); FileWriter.WriteString("} "); FileWriter.Close(); }
private void GenerateJoinClause(ComplexEntityLink link, StringFileWriter FileWriter) { String joinStr = ""; switch (link.Type) { case ComplexEntityLinkType.Inner: joinStr = "INNER JOIN"; break; case ComplexEntityLinkType.Left: joinStr = "LEFT JOIN"; break; case ComplexEntityLinkType.Right: joinStr = "RIGHT JOIN"; break; } FileWriter.WriteString(joinStr + " [" + link.RightTableName + "] [" + link.RightShortTableName + "] ON [" + link.LeftShortTableName + "].[" + link.LeftFieldName + "]=[" + link.RightShortTableName + "].[" + link.RightFieldName + "]"); }
private void FillOneString(EnumItem currEnumItem, StringFileWriter fileWriter) { fileWriter.WriteString(currEnumItem.GetEnumRow()); }