Example #1
0
        /// <summary>
        /// 实体修改记录
        /// </summary>
        /// <param name="newEntity">修改前的实体对象</param>
        /// <param name="oldEntity">修改后的实体对象</param>
        /// <param name="tableName">表名称</param>
        public void UpdateEntityLog(BaseAreaProvinceMarkEntity newEntity, BaseAreaProvinceMarkEntity oldEntity, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                tableName = this.CurrentTableName + "_LOG";
            }
            BaseModifyRecordManager manager = new BaseModifyRecordManager(this.UserInfo, tableName);

            foreach (var property in typeof(BaseAreaProvinceMarkEntity).GetProperties())
            {
                var oldValue = Convert.ToString(property.GetValue(oldEntity, null));
                var newValue = Convert.ToString(property.GetValue(newEntity, null));
                //不记录创建人、修改人、没有修改的记录
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var record = new BaseModifyRecordEntity();
                record.ColumnCode        = property.Name.ToUpper();
                record.ColumnDescription = fieldDescription.Text;
                record.NewValue          = newValue;
                record.OldValue          = oldValue;
                record.TableCode         = this.CurrentTableName.ToUpper();
                record.TableDescription  = FieldExtensions.ToDescription(typeof(BaseAreaProvinceMarkEntity), "TableName");
                record.RecordKey         = oldEntity.Id.ToString();
                record.IPAddress         = Utilities.GetIPAddress(true);
                manager.Add(record, true, false);
            }
        }
Example #2
0
        public int Update(BaseAreaProvinceMarkEntity entity)
        {
            // 获取原始实体信息
            var entityOld = this.GetObject(entity.Id);

            // 保存修改记录
            this.UpdateEntityLog(entity, entityOld);

            return(this.UpdateObject(entity));
        }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseAreaProvinceMarkEntity entity)
 {
     sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldArea, entity.Area);
     sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldAreaId, entity.AreaId);
     sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldProvince, entity.Province);
     sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldProvinceId, entity.ProvinceId);
     sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldMark, entity.Mark);
     sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldEnabled, entity.Enabled);
     sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldDescription, entity.Description);
     SetObjectExpand(sqlBuilder, entity);
 }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(BaseAreaProvinceMarkEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedBy, UserInfo.RealName);
            }
            // 若有修改时间标示,那就按修改时间来,不是按最新的时间来
            if (entity.ModifiedOn.HasValue)
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedOn, entity.ModifiedOn.Value);
            }
            else
            {
                sqlBuilder.SetDBNow(BaseAreaProvinceMarkEntity.FieldModifiedOn);
            }
            sqlBuilder.SetWhere(BaseAreaProvinceMarkEntity.FieldId, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseAreaProvinceMarkEntity entity)
 {
     return(this.AddObject(entity));
 }
 partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseAreaProvinceMarkEntity entity);
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(BaseAreaProvinceMarkEntity entity)
        {
            string sequence = string.Empty;

            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseAreaProvinceMarkEntity.FieldId);
            if (!string.IsNullOrEmpty(entity.Id) || !this.Identity)
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldId, entity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(BaseAreaProvinceMarkEntity.FieldId, "SEQ_" + BaseAreaEntity.TableName + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(BaseAreaProvinceMarkEntity.FieldId, "NEXT VALUE FOR SEQ_" + BaseAreaEntity.TableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (entity.Id == null)
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.Increment(this.CurrentTableName);
                            }
                            entity.Id = sequence;
                        }
                        sqlBuilder.SetValue(BaseAreaEntity.FieldId, entity.Id);
                    }
                }
            }
            this.SetObject(sqlBuilder, entity);

            // 创建人信息
            if (!string.IsNullOrEmpty(entity.CreateUserId))
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldCreateUserId, entity.CreateUserId);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldCreateUserId, UserInfo.Id);
                }
            }
            if (!string.IsNullOrEmpty(entity.CreateBy))
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldCreateBy, entity.CreateBy);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldCreateBy, UserInfo.RealName);
                }
            }
            if (entity.CreateOn.HasValue)
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldCreateOn, entity.CreateOn);
            }
            else
            {
                sqlBuilder.SetDBNow(BaseAreaProvinceMarkEntity.FieldCreateOn);
            }

            // 修改人信息
            if (!string.IsNullOrEmpty(entity.ModifiedUserId))
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedUserId, entity.ModifiedUserId);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedUserId, UserInfo.Id);
                }
            }
            if (!string.IsNullOrEmpty(entity.ModifiedBy))
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedBy, entity.ModifiedBy);
            }
            else
            {
                if (UserInfo != null)
                {
                    sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedBy, UserInfo.RealName);
                }
            }
            if (entity.ModifiedOn.HasValue)
            {
                sqlBuilder.SetValue(BaseAreaProvinceMarkEntity.FieldModifiedOn, entity.ModifiedOn);
            }
            else
            {
                sqlBuilder.SetDBNow(BaseAreaEntity.FieldModifiedOn);
            }

            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(BaseAreaProvinceMarkEntity entity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddObject(entity));
 }