1-BLMa白龙马C#代码生成器-概述
2-BLMa白龙马C#代码生成器-参数设置详解1
3-BLMa白龙马C#代码生成器-参数设置详解2
4-BLMa白龙马C#代码生成器-核心要点
生成代码的逻辑是这样,
-1取出要生成代码的表集合,循环逐个生成代码
-2代码生成成功工保存到磁盘上指定目录。
-3窗口上反馈显示生成进度情况。
5.1EM实体模型代码示例
using System;
using System.ComponentModel;
namespace EM
{
public class SysUserEM
{
[Description("用户ID"), Category("系统-用户表"), DisplayName("用户ID")]
public string UserId { get; set; }
[Description("名称"), Category("系统-用户表"), DisplayName("名称")]
public string UserName { get; set; }
[Description("密码"), Category("系统-用户表"), DisplayName("密码")]
public string SPwd { get; set; }
[Description("手机号"), Category("系统-用户表"), DisplayName("手机号")]
public string SMobile { get; set; }
[Description("Email"), Category("系统-用户表"), DisplayName("Email")]
public string SEmail { get; set; }
[Description("状态"), Category("系统-用户表"), DisplayName("状态")]
public string UserStatus { get; set; }
[Description("创建日期"), Category("系统-用户表"), DisplayName("创建日期")]
public DateTime DTime { get; set; }
[Description("备注"), Category("系统-用户表"), DisplayName("备注")]
public string SNote { get; set; }
}
}
关于字段属性的分组还是需要根据业务需要修改Category()、固定显示顺序可以在DisplayName()加序列字符,比如1,2,3,A,B,C等等。
5.2BLL业务逻辑层代码示例
using System.Data;
#region 用到的别名,复制代码时修改这里即可
using EM = EM.SysUserEM;
using DAL = DAL.SysUserDAL;
#endregion
namespace BLL
{
public class SysUserBLL
{
///
/// 全部查询
///
///
public static DataTable Select()
{
return DAL.Select(DAL.SQL_Select);
}
///
/// 模糊查询
///
///
///
public static DataTable Query(string find)
{
return DAL.Query(find);
}
///
/// 保存
///
///
///
public static int Save(EM em, bool insert_or_update)
{
if (insert_or_update)
{
return DAL.Update(em);
}
else
{
return DAL.Insert(em);
}
}
///
/// 删除
///
///
///
public static int Delete(string pk)
{
return DAL.Delete(pk);
}
}
}
5.1DAL数据访问层代码示例
using System.Data;
using DBUtility;
#region 用到的别名,复制代码时修改这里即可
using EM = EM.SysUserEM;
#endregion
namespace DAL
{
public class SysUserDAL
{
#region 数据库表名
public const string TABLE_NAME = "SYS_USER";
#endregion
#region All主键ID及列
public const string PKEY = "USER_ID";//PK_USER
public const string ALLCOLUMNS = "USER_ID,USER_NAME,S_PWD,S_MOBILE,S_EMAIL,USER_STATUS,D_TIME,S_NOTE";
#endregion
#region SQL_Select 语句
public static string SQL_Select = "Select * from SYS_USER order by USER_ID";
#endregion
#region Select 方法
public static DataTable Select(string sql_select)
{
return OracleDML.GetDataTable(sql_select);
}
#endregion
#region SQL_Delete 语句
public static string SQL_Delete = "Delete from SYS_USER where USER_ID={0} ";
#endregion
#region SQL_Insert 语句
public static string SQL_Insert = @"Insert into SYS_USER (USER_ID,USER_NAME,S_PWD,S_MOBILE,S_EMAIL,USER_STATUS,D_TIME,S_NOTE)
values ('{0}','{1}','{2}','{3}','{4}','{5}',to_date('{6}','yyyy-mm-dd hh24:mi:ss'),'{7}')";
#endregion
#region SQL_Update 语句
public static string SQL_Update = @"Update SYS_USER
set USER_NAME='{1}',S_PWD='{2}',S_MOBILE='{3}',S_EMAIL='{4}',USER_STATUS='{5}',D_TIME=to_date('{6}','yyyy-mm-dd hh24:mi:ss'),S_NOTE='{7}'
where USER_ID={0} ";
#endregion
#region Query 方法
public static DataTable Query(string find)
{
string sql_query = string.Format(@"Select USER_ID,USER_NAME,S_PWD,S_MOBILE,S_EMAIL,USER_STATUS,D_TIME,S_NOTE
from SYS_USER
where USER_ID||USER_NAME||S_PWD||S_MOBILE||S_EMAIL||USER_STATUS||S_NOTE| like '%{0}%'
order by USER_ID", find);
return OracleDML.GetDataTable(sql_query);
}
#endregion
#region Delete 方法
public static int Delete(string PK_UserId)
{
string sql_del = string.Format(SQL_Delete, PK_UserId);
return OracleDML.ExecuteNonQuery(sql_del);
}
#endregion
#region Insert 方法
public static int Insert(EM em)
{
string sql_insert = string.Format(SQL_Insert, EM.UserId,EM.UserName,EM.SPwd,EM.SMobile,EM.SEmail,EM.UserStatus,EM.DTime,EM.SNote);
return OracleDML.ExecuteNonQuery(sql_insert);
}
#endregion
#region Update 方法
public static int Update(EM em)
{
string sql_update = string.Format(SQL_Update, EM.UserName,EM.SPwd,EM.SMobile,EM.SEmail,EM.UserStatus,EM.DTime,EM.SNote,EM.UserId,);
return OracleDML.ExecuteNonQuery(sql_update);
}
#endregion
}
}