init lserp cs 5.0

This commit is contained in:
cyf
2026-07-10 15:25:05 +08:00
commit 90f3fda86a
3799 changed files with 976868 additions and 0 deletions
@@ -0,0 +1,25 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// count »º´æÅú×¢
/// </summary>
[Serializable]
public class CacheCountAttribute : Attribute, ICacheAttribute {
private String _targetPropertyName;
public CacheCountAttribute( String targetPropertyName ) {
_targetPropertyName = targetPropertyName;
}
public String TargetPropertyName {
get {
return _targetPropertyName;
}
}
}
}
@@ -0,0 +1,51 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 数据列批注,用于标识属性在数据库中对应的列名称和长度
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class ColumnAttribute : Attribute {
private String _columnName;
private String _label;
private int _length;
public ColumnAttribute() {
_length = 250;
}
public String Name {
get {
return _columnName;
}
set {
_columnName = value;
}
}
public String Label {
get {
return _label;
}
set {
_label = value;
}
}
public int Length {
get {
return _length;
}
set {
_length = value;
}
}
public Boolean LengthSetted() {
return _length > 0 && _length != 250;
}
}
}
@@ -0,0 +1,28 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// Êý¾Ý¿âÅú×¢
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Class )]
public class DatabaseAttribute : Attribute {
private String _dbName;
public DatabaseAttribute( String dbName ) {
_dbName = dbName;
}
public String Database {
get {
return _dbName;
}
set {
_dbName = value;
}
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 用于自定义精度数据,也可以存储自定义精度的货币数值。
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class DecimalAttribute : Attribute {
/// <summary>
/// 数值的精度,即小数点左右的总共位数,但不包括小数点。
/// </summary>
public int Precision { get; set; }
/// <summary>
/// 小数点右侧的位数
/// </summary>
public int Scale { get; set; }
}
}
@@ -0,0 +1,25 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 默认值批注,当属性没有被赋值的时候,系统使用此默认值存入数据库
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class DefaultAttribute : Attribute {
private Object _value;
public DefaultAttribute( Object val ) {
_value = val;
}
public Object Value {
get { return _value; }
set { _value = value; }
}
}
}
@@ -0,0 +1,13 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// html 文本批注,表明此属性允许接受 html 风格的文本
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class HtmlTextAttribute : Attribute {
}
}
@@ -0,0 +1,13 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 缓存批注的接口
/// </summary>
public interface ICacheAttribute {
String TargetPropertyName { get; }
}
}
@@ -0,0 +1,26 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// label 批注,用于表单代码的自动生成
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Class )]
public class LabelAttribute : Attribute {
private String _label;
public LabelAttribute( String lbl ) {
_label = lbl;
}
public String Label {
get {
return _label;
}
set {
_label = value;
}
}
}
}
@@ -0,0 +1,12 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 长文本批注,标识此属性对应的数据列允许接受长文本字符串
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class LongTextAttribute : Attribute {
}
}
@@ -0,0 +1,20 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 货币批注,可以保存货币类型数据。
/// 此批注只能用在dotnet的decimal数据类型上。数据库存储的时候,使用的精度为:总位数19, 小数点后4位
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class MoneyAttribute : Attribute {
}
}
@@ -0,0 +1,13 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// ORM在保存数据的时候,会忽略打上 NotSave 批注的属性
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property | AttributeTargets.Class )]
public class NotSaveAttribute : Attribute {
}
}
@@ -0,0 +1,12 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 在 json 序列化的时候,打上 NotSerialize 批注的属性会被忽略
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class NotSerializeAttribute : Attribute {
}
}
@@ -0,0 +1,27 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 表名称批注,用于标识对象在数据库中对应的表名称
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Class )]
public class TableAttribute : Attribute {
private String _tableName;
public TableAttribute( String tableName ) {
_tableName = tableName;
}
public String TableName {
get {
return _tableName;
}
set {
_tableName = value;
}
}
}
}
@@ -0,0 +1,12 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 小型整数批注,标识此属性对应的数据列为小型整数
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public class TinyIntAttribute : Attribute {
}
}
@@ -0,0 +1,25 @@
using System;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// email 批注,验证对象的属性是否是合法的 email
/// </summary>
[Serializable]
public class EmailAttribute : PatternAttribute {
public EmailAttribute() {
Regexp = RegPattern.Email;
}
public EmailAttribute( String msg ) {
Regexp = RegPattern.Email;
Message = msg;
}
}
}
@@ -0,0 +1,49 @@
using System;
using System.Reflection;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 检查对象属性是否已经赋值,如果是字符串类型,empty的字符串也是不合法的
/// </summary>
[Serializable]
public class NotNullAttribute : ValidationAttribute {
public NotNullAttribute() {
}
public NotNullAttribute( String msg ) {
base.Message = msg;
}
public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ) {
Object obj = target.get( info.Name );
Boolean isNull = false;
if (info.Type == typeof( String )) {
if (obj == null) {
isNull = true;
}
else if (strUtil.IsNullOrEmpty( obj.ToString() )) {
isNull = true;
}
}
else if (obj == null) {
isNull = true;
}
if (isNull) {
if (strUtil.HasText( this.Message )) {
result.Add( this.Message );
}
else {
EntityInfo ei = Entity.GetInfo( target );
String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
result.Add( str + "can not be null" );
}
}
}
}
}
@@ -0,0 +1,59 @@
using System;
using System.Reflection;
namespace Zhaizj.Framework.ORM
{
/// <summary>
/// 检查对象属性是否已经赋值,如果是字符串类型,empty的字符串也是不合法的
/// </summary>
[Serializable]
public class NotZeroAttribute : ValidationAttribute
{
public NotZeroAttribute()
{
}
public NotZeroAttribute(String msg)
{
base.Message = msg;
}
public override void Validate(String action, IEntity target, EntityPropertyInfo info, Result result)
{
Object obj = target.get(info.Name);
Boolean isInt = false;
if (info.Type == typeof(int))
{
if (obj == null)
{
isInt = true;
}
else if (Convert.ToInt32(obj) == 0)
{
isInt = true;
}
}
else if (Convert.ToInt32(obj) == 0)
{
isInt = true;
}
if (isInt)
{
if (strUtil.HasText(this.Message))
{
result.Add(this.Message);
}
else
{
EntityInfo ei = Entity.GetInfo(target);
String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
result.Add(str + "can not be null");
}
}
}
}
}
@@ -0,0 +1,51 @@
using System;
using System.Text.RegularExpressions;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 正则表达式批注,验证属性的对象是否符合指定的正则表达式
/// </summary>
[Serializable]
public class PatternAttribute : ValidationAttribute {
private String _regexp;
public PatternAttribute() {
}
public PatternAttribute( String regexp ) {
_regexp = regexp;
}
public PatternAttribute( String regexp, String msg ) {
_regexp = regexp;
base.Message = msg;
}
public String Regexp {
get { return _regexp; }
set { _regexp = value; }
}
public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ) {
if (!Regex.IsMatch( cvt.ToNotNull( target.get( info.Name ) ), this.Regexp, RegexOptions.Singleline )) {
if (strUtil.HasText( this.Message )) {
result.Add( this.Message );
}
else {
EntityInfo ei = Entity.GetInfo( target );
String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
result.Add( str + " is not match the format pattern : " + this.Regexp );
}
}
}
}
}
@@ -0,0 +1,64 @@
using System;
using Zhaizj.Framework.Data;
using System.Data;
using Zhaizj.Framework.Log;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 唯一性验证批注,验证对象的属性值是否在所有对象中是唯一的
/// </summary>
[Serializable]
public class UniqueAttribute : ValidationAttribute {
private static readonly ILog logger = LogManager.GetLogger( typeof( UniqueAttribute ) );
public UniqueAttribute() {
}
public UniqueAttribute( String msg ) {
base.Message = msg;
}
public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ) {
Object obj = target.get( info.Name );
EntityInfo ei = Entity.GetInfo( target );
int count = getCount( action, target, ei, info, obj );
if (count > 0) {
if (strUtil.HasText( this.Message )) {
result.Add( this.Message );
}
else {
String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
result.Add( str + " should be unique, but it has been in database" );
}
}
}
private static int getCount( String action, IEntity target, EntityInfo entityInfo, EntityPropertyInfo info, Object obj ) {
if (obj == null) return 1;
String usql;
IDatabaseDialect dialect = entityInfo.Dialect;
if (action.Equals( "update" )) {
usql = String.Format( "select count(Id) from {0} where Id<>{3} and {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter( info.Name ), target.Id );
}
else {
usql = String.Format( "select count(Id) from {0} where {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter( info.Name ) );
}
logger.Info( LoggerUtil.SqlPrefix + " validate unique sql : " + usql );
IDbCommand cmd = DataFactory.GetCommand( usql, DbContext.getConnection( entityInfo ) );
DataFactory.SetParameter( cmd, info.ColumnName, obj );
return cvt.ToInt( cmd.ExecuteScalar() );
}
}
}
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace Zhaizj.Framework.ORM {
/// <summary>
/// 验证批注的抽象基类。如果要自定义验证批注,请通过继承此基类扩展
/// </summary>
[Serializable, AttributeUsage( AttributeTargets.Property )]
public abstract class ValidationAttribute : Attribute {
private String _message;
/// <summary>
/// 错误提示信息
/// </summary>
public String Message {
get { return _message; }
set { _message = value; }
}
/// <summary>
/// 多国语言化的错误提示信息
/// </summary>
public String Lang {
set {
_message = lang.get( value );
}
get { return _message; }
}
/// <summary>
/// 可以扩展的验证方法
/// </summary>
/// <param name="action">当前操作:update或insert</param>
/// <param name="target">需要验证的实体对象</param>
/// <param name="info">当前属性信息</param>
/// <param name="result">验证结果</param>
public abstract void Validate( String action, IEntity target, EntityPropertyInfo info, Result result );
public virtual void Validate( String action, Object target, String propertyName, Result result ) {
if (target == null) return;
IEntity entity = target as IEntity;
if (entity == null) throw new NotImplementedException( "NotNullAttribute can only implement to IEntity. Currenty object's type:" + target.GetType().FullName );
EntityPropertyInfo ep = Entity.GetInfo( entity ).GetProperty( propertyName );
Validate( action, entity, ep, result );
}
}
}