/// <summary> /// 取得仅更新的SQL语句 /// </summary> internal string GetModifiedSqlCode(DataDictionaryData data) { if (data.__EntityStatusNull || !data.__EntityStatus.IsModified) { return(";"); } StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE [ST_Dictionary] SET"); //名称 if (data.__EntityStatus.ModifiedProperties[DataDictionaryData.Real_Name] > 0) { sql.AppendLine(" [Name] = @Name"); } //状态 if (data.__EntityStatus.ModifiedProperties[DataDictionaryData.Real_State] > 0) { sql.AppendLine(" [State] = @State"); } //特性 if (data.__EntityStatus.ModifiedProperties[DataDictionaryData.Real_Feature] > 0) { sql.AppendLine(" [Feature] = @Feature"); } //备注 if (data.__EntityStatus.ModifiedProperties[DataDictionaryData.Real_Memo] > 0) { sql.AppendLine(" [Memo] = @Memo"); } //值 if (data.__EntityStatus.ModifiedProperties[DataDictionaryData.Real_Value] > 0) { sql.AppendLine(" [Value] = @Value"); } sql.Append(" WHERE [Id] = @Id;"); return(sql.ToString()); }
/// <summary> /// 载入数据 /// </summary> /// <param name="reader">数据读取器</param> /// <param name="entity">读取数据的实体</param> protected sealed override void LoadEntity(MySqlDataReader reader, DataDictionaryData entity) { using (new EditScope(entity.__EntityStatus, EditArrestMode.All, false)) { entity._id = (int)reader.GetInt32(0); if (!reader.IsDBNull(1)) { entity._name = reader.GetString(1); } entity._state = (long)reader.GetInt64(2); if (!reader.IsDBNull(3)) { entity._feature = reader.GetString(3); } if (!reader.IsDBNull(4)) { entity._memo = reader.GetString(4); } if (!reader.IsDBNull(5)) { entity._value = reader.GetString(5); } } }
/// <summary> /// 设置插入数据的命令 /// </summary> /// <param name="entity">实体对象</param> /// <param name="cmd">命令</param> /// <returns>返回真说明要取主键</returns> protected sealed override bool SetInsertCommand(DataDictionaryData entity, MySqlCommand cmd) { cmd.CommandText = InsertSqlCode; CreateFullSqlParameter(entity, cmd); return(true); }
/// <summary> /// 设置更新数据的命令 /// </summary> /// <param name="entity">实体对象</param> /// <param name="cmd">命令</param> protected sealed override void SetUpdateCommand(DataDictionaryData entity, MySqlCommand cmd) { cmd.CommandText = UpdateSqlCode; CreateFullSqlParameter(entity, cmd); }
/// <summary> /// 设置插入数据的命令 /// </summary> /// <param name="entity">实体对象</param> /// <param name="cmd">命令</param> /// <returns>返回真说明要取主键</returns> private void CreateFullSqlParameter(DataDictionaryData entity, MySqlCommand cmd) { //01:标识(Id) cmd.Parameters.Add(new MySqlParameter("Id", MySqlDbType.Int32) { Value = entity.Id }); //02:名称(Name) var isNull = string.IsNullOrWhiteSpace(entity.Name); var parameter = new MySqlParameter("Name", MySqlDbType.VarChar, isNull ? 10 : (entity.Name).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Name; } cmd.Parameters.Add(parameter); //03:状态(State) cmd.Parameters.Add(new MySqlParameter("State", MySqlDbType.Int64) { Value = entity.State }); //04:特性(Feature) isNull = string.IsNullOrWhiteSpace(entity.Feature); parameter = new MySqlParameter("Feature", MySqlDbType.VarChar, isNull ? 10 : (entity.Feature).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Feature; } cmd.Parameters.Add(parameter); //05:备注(Memo) isNull = string.IsNullOrWhiteSpace(entity.Memo); parameter = new MySqlParameter("Memo", MySqlDbType.VarChar, isNull ? 10 : (entity.Memo).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Memo; } cmd.Parameters.Add(parameter); //06:值(Value) isNull = string.IsNullOrWhiteSpace(entity.Value); parameter = new MySqlParameter("Value", MySqlDbType.VarChar, isNull ? 10 : (entity.Value).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Value; } cmd.Parameters.Add(parameter); }