using System.Collections.Generic;
using System.IO;
using System.Text;
using Codes;
using CodeUtility;
using Model;
namespace CodeFactory
{
public class CodeAccess
{
#region BLL
public static void CreateBLLFile(Database.DatabaseType dbType, List<Table> tables, CodeStyle style, string path)
{
try
{
foreach (Table table in tables)
{
List<Field> fields = table.Fields;
CodeHelper.WriteUTF8File(path + @"\" + style.AfterNamespaceDot + table.Name + ".cs", BLLCode.GetBLLCode(dbType, table, style));
}
if (style.CacheFrame != CodeStyle.CacheFrames.None)
{
CodeHelper.WriteUTF8File(path + @"\Caches.cs", BLLCode.GetCachesCode(style));
}
}
catch (Exception e)
{
throw e;
}
}
public static void CreateBLLCodeAssemblyInfoFile(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", BLLCodeAssemblyInfo.GetBLLCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateBLLCodecsproj(Database.DatabaseType dbType, CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\BLL.csproj", BLLCodecsproj.GetBLLCodecsproj(dbType,style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region DBUtility
public static void CreateDBUtilityFile(Database.DatabaseType dbType, CodeStyle style, string path)
{
try
{
if (dbType == Database.DatabaseType.Access)
{
CodeHelper.WriteUTF8File(path + @"\AccessHelper.cs", DBUtilityCode.GetDBUtilityCode(dbType, style));
}
else {
CodeHelper.WriteUTF8File(path + @"\SqlHelper.cs", DBUtilityCode.GetDBUtilityCode(dbType, style));
}
}
catch (Exception e)
{
throw e;
}
}
public static void CreateDBUtilityAssemblyInfoFile(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", DBUtilityCodeAssemblyInfo.GetDBUtilityCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateDBUtilityCodecsproj(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\DBUtility.csproj", DBUtilityCodecsproj.GetDBUtilityCodecsproj(style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region CacheDependencyFactory
public static void CreateCacheDependencyFactoryFile(List<Table> tables, CodeStyle style, string path)
{
try{
CodeHelper.WriteUTF8File(path + @"\DependencyAccess.cs", CacheDependencyFactoryCode.GetDependencyAccessCode(tables, style));
CodeHelper.WriteUTF8File(path + @"\DependencyFacade.cs", CacheDependencyFactoryCode.GetDependencyFacadeCode(tables, style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateCacheDependencyFactoryCodeAssemblyInfo(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", CacheDependencyFactoryCodeAssemblyInfo.GetCacheDependencyFactoryCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateCacheDependencyFactoryCodecsproj(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\CacheDependencyFactory.csproj", CacheDependencyFactoryCodecsproj.GetCacheDependencyFactoryCodecsproj(style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region DALFactory
public static void CreateDALFactoryFile(List<Table> tables, CodeStyle style, string path)
{
try{
string str = path + @"\DataAccess.cs";
string dALFactoryCode = DALFactoryCode.GetDALFactoryCode(tables, style);
CodeHelper.WriteUTF8File(str, dALFactoryCode);
}
catch (Exception e)
{
throw e;
}
}
public static void CreateDALFactoryCodeAssemblyInfoFile(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", DALFactoryCodeAssemblyInfo.GetDALFactoryCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateDALFactoryCodecsproj(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\DALFactory.csproj", DALFactoryCodecsproj.GetDALFactoryCodecsproj(style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region DAL SqlServerDAL
public static void CreateDALFile(Database.DatabaseType dbType, List<Table> tables, CodeStyle style, string path)
{
try{
foreach (Table table in tables)
{
string str = path + @"\" + style.AfterNamespaceDot + table.Name + ".cs";
if (dbType == Database.DatabaseType.Access)
{
CodeHelper.WriteUTF8File(str, DALCode.GetAccessDALCode(table, style));
}
else
{
CodeHelper.WriteUTF8File(str, DALCode.GetSQLServerDALCode(table, style));
}
}
}
catch (Exception e)
{
throw e;
}
}
public static void CreateDALCodeAssemblyInfoFile(Database.DatabaseType dbType, CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", DALCodeAssemblyInfo.GetDALCodeAssemblyInfo(dbType,style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateDALCodecsproj(Database.DatabaseType dbType, CodeStyle style, string path)
{
try
{
if (dbType == Database.DatabaseType.Access)
{
CodeHelper.WriteUTF8File(path + @"\AccessDAL.csproj", DALCodecsproj.GetDALCodecsproj(style, path));
}
else
{
CodeHelper.WriteUTF8File(path + @"\SQLServerDAL.csproj", DALCodecsproj.GetDALCodecsproj(style, path));
}
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region ICacheDependency
public static void CreateICacheDependencyFile(CodeStyle style, string path)
{
try{
CodeHelper.WriteUTF8File(path + @"\ICacheDependency.cs", ICacheDependencyCode.GetICacheDependencyCode(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateICacheDependencyCodeAssemblyInfo(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", ICacheDependencyCodeAssemblyInfo.GetICacheDependencyCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateICacheDependencyCodecsproj(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\ICacheDependency.csproj", ICacheDependencyCodecsproj.GetICacheDependencyCodecsproj(style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region IDAL
public static void CreateIDALFile(List<Table> tables, CodeStyle style, string path)
{
try{
foreach (Table table in tables)
{
CodeHelper.WriteUTF8File(path + @"\" + style.AfterNamespaceDot + "I" + table.Name + ".cs", IDALCode.GetIDALCode(table, style));
}
}
catch (Exception e)
{
throw e;
}
}
public static void CreateIDALCodeAssemblyInfoFile(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", IDALCodeAssemblyInfo.GetIDALCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateIDALCodecsproj(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\IDAL.csproj", IDALCodecsproj.GetIDALCodecsproj(style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region Model
public static void CreateModelFile(List<Table> tables, CodeStyle style, string path)
{
try{
foreach (Table table in tables)
{
CodeHelper.WriteUTF8File(path + @"\" + style.AfterNamespaceDot + table.Name + ".cs", ModelCode.GetModelCode(table, style));
}
if (style.CacheFrame != CodeStyle.CacheFrames.None)
{
CodeHelper.WriteUTF8File(path + @"\PageData.cs", ModelCode.GetPageDataCode(style));
}
}
catch (Exception e)
{
throw e;
}
}
public static void CreateModelCodeAssemblyInfoFile(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", ModelCodeAssemblyInfo.GetModelCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateModelCodecsproj(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\Model.csproj", ModelCodecsproj.GetModelCodecsproj(style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region Sp
public static void CreateSpFile(List<Table> tables, string path)
{
try{
StringBuilder builder = new StringBuilder();
foreach (Table table in tables)
{
builder.Append(Sp.GetSpCode(table));
}
CodeHelper.WriteUTF8File(path + @"\StoreProcedures.sql", builder.ToString());
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region TableCacheDependency
public static void CreateTableCacheDependencyFile(string dbName, List<Table> tables, CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\TableDependency.cs", TableCacheDependencyCode.GetTableDependencyCode(dbName, style));
foreach (Table table in tables)
{
CodeHelper.WriteUTF8File(path + @"\" + style.AfterNamespaceDot + table.Name + ".cs", TableCacheDependencyCode.GetTableCacheDependencyCode(dbName, table, style));
}
}
catch (Exception e)
{
throw e;
}
}
public static void CreateTableCacheDependencyCodeAssemblyInfo(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\AssemblyInfo.cs", TableCacheDependencyCodeAssemblyInfo.GetTableCacheDependencyCodeAssemblyInfo(style));
}
catch (Exception e)
{
throw e;
}
}
public static void CreateTableCacheDependencyCodecsproj(CodeStyle style, string path)
{
try
{
CodeHelper.WriteUTF8File(path + @"\TableCacheDependency.csproj", TableCacheDependencyCodecsproj.GetTableCacheDependencyCodecsproj(style, path));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region UserControl
public static void CreateUserControl(List<Table> tables, CodeStyle style, string path)
{
try{
Directory.CreateDirectory(path);
foreach (Table table in tables)
{
CodeHelper.WriteUTF8File(path + @"\" + style.DotAfterNamespace.Replace(".", "") + table.Name + "ListControl.ascx", UserControlCode.GetUserControlCode(table, style));
CodeHelper.WriteUTF8File(path + @"\" + style.DotAfterNamespace.Replace(".", "") + table.Name + "ListControl.ascx.cs", UserControlCode.GetWebUserControlCsCode(table, style));
}
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region webconfig
public static void CreateWebConfigFile(Database.DatabaseType dbType, CodeStyle style, string path, Database dbName)
{
try
{
CodeHelper.WriteUTF8File(path + @"\Web.config", WebConfigFile.GetWebConfigFile(dbType,style, path, dbName));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region word
public static void CreatewordFile(List<Table> tables, CodeStyle style, string path)
{
try
{
StringBuilder builder = new StringBuilder();
foreach (Table table in tables)
{
builder.Append(wordhtml.GetwordCode(table, style));
}
CodeHelper.WriteUTF8File(path + @"\myword.doc", builder.ToString());
}
catch (Exception e)
{
throw e;
}
}
#endregion
}
}

浙公网安备 33010602011771号