/// <summary> /// 保存完成后期处理(Insert或Update) /// </summary> /// <param name="entity"></param> protected sealed override void OnDataSaved(UserJobData entity) { using (var proxy = new RedisProxy(RedisProxy.DbComboCache)) { proxy.RemoveKey(treeKey); proxy.RemoveKey(comboKey); } }
/// <summary> /// 载入数据 /// </summary> /// <param name="reader">数据读取器</param> /// <param name="entity">读取数据的实体</param> protected sealed override void LoadEntity(MySqlDataReader reader, UserJobData entity) { using (new EditScope(entity.__EntityStatus, EditArrestMode.All, false)) { entity._id = (int)reader.GetInt32(0); if (!reader.IsDBNull(1)) { entity._title = reader.GetString(1).ToString(); } if (!reader.IsDBNull(2)) { try{ entity._date = reader.GetMySqlDateTime(2).Value; }catch {} } if (!reader.IsDBNull(3)) { entity._message = reader.GetString(3).ToString(); } if (!reader.IsDBNull(4)) { entity._jobtype = (UserJobType)reader.GetInt32(4); } if (!reader.IsDBNull(5)) { entity._jobstatus = (JobStatusType)reader.GetInt32(5); } if (!reader.IsDBNull(6)) { entity._commandtype = (JobCommandType)reader.GetInt32(6); } entity._linkid = (int)reader.GetInt32(7); entity._entitytype = (int)reader.GetInt32(8); entity._touserid = (int)reader.GetInt32(9); if (!reader.IsDBNull(10)) { entity._tousername = reader.GetString(10).ToString(); } entity._fromuserid = (int)reader.GetInt32(11); if (!reader.IsDBNull(12)) { entity._fromusername = reader.GetString(12).ToString(); } if (!reader.IsDBNull(13)) { entity._argument = /*(LONGTEXT)*/ reader.GetValue(13).ToString(); } if (!reader.IsDBNull(14)) { entity._datastate = (DataStateType)reader.GetInt32(14); } if (!reader.IsDBNull(15)) { entity._isfreeze = (bool)reader.GetBoolean(15); } entity._departmentid = (int)reader.GetInt32(16); } }
/// <summary> /// 读取Form传过来的数据 /// </summary> /// <param name="data">数据</param> /// <param name="convert">转化器</param> protected void DefaultReadFormData(UserJobData data, FormConvert convert) { //数据 data.Title = convert.ToString("Title"); data.Date = convert.ToDateTime("Date"); data.Message = convert.ToString("Message"); data.JobType = (UserJobType)convert.ToInteger("JobType"); data.JobStatus = (JobStatusType)convert.ToInteger("JobStatus"); data.CommandType = (JobCommandType)convert.ToInteger("CommandType"); data.LinkId = convert.ToInteger("LinkId"); data.EntityType = convert.ToInteger("EntityType"); data.ToUserId = convert.ToInteger("ToUserId"); data.ToUserName = convert.ToString("ToUserName"); data.FromUserId = convert.ToInteger("FromUserId"); data.FromUserName = convert.ToString("FromUserName"); }
/// <summary> /// 载入数据 /// </summary> /// <param name="reader">数据读取器</param> /// <param name="entity">读取数据的实体</param> public override void SimpleLoad(MySqlDataReader reader, UserJobData entity) { using (new EditScope(entity.__EntityStatus, EditArrestMode.All, false)) { entity._id = (int)reader.GetInt32(0); if (!reader.IsDBNull(1)) { entity._title = reader.GetString(1).ToString(); } if (!reader.IsDBNull(2)) { try{ entity._date = reader.GetMySqlDateTime(2).Value; }catch {} } if (!reader.IsDBNull(3)) { entity._message = reader.GetString(3).ToString(); } if (!reader.IsDBNull(4)) { entity._jobtype = (UserJobType)reader.GetInt32(4); } if (!reader.IsDBNull(5)) { entity._jobstatus = (JobStatusType)reader.GetInt32(5); } if (!reader.IsDBNull(6)) { entity._commandtype = (JobCommandType)reader.GetInt32(6); } if (!reader.IsDBNull(7)) { entity._tousername = reader.GetString(7).ToString(); } if (!reader.IsDBNull(8)) { entity._fromusername = reader.GetString(8).ToString(); } if (!reader.IsDBNull(9)) { entity._datastate = (DataStateType)reader.GetInt32(9); } if (!reader.IsDBNull(10)) { entity._isfreeze = (bool)reader.GetBoolean(10); } } }
/// <summary> /// 设置插入数据的命令 /// </summary> /// <param name="entity">实体对象</param> /// <param name="cmd">命令</param> /// <returns>返回真说明要取主键</returns> protected sealed override bool SetInsertCommand(UserJobData 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(UserJobData entity, MySqlCommand cmd) { cmd.CommandText = UpdateSqlCode; CreateFullSqlParameter(entity, cmd); }
/// <summary> /// 设置插入数据的命令 /// </summary> /// <param name="entity">实体对象</param> /// <param name="cmd">命令</param> /// <returns>返回真说明要取主键</returns> private void CreateFullSqlParameter(UserJobData entity, MySqlCommand cmd) { //02:标识(Id) cmd.Parameters.Add(new MySqlParameter("Id", MySqlDbType.Int32) { Value = entity.Id }); //04:标题(Title) var isNull = string.IsNullOrWhiteSpace(entity.Title); var parameter = new MySqlParameter("Title", MySqlDbType.VarString, isNull ? 10 : (entity.Title).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Title; } cmd.Parameters.Add(parameter); //05:发生日期(Date) isNull = entity.Date.Year < 1900; parameter = new MySqlParameter("Date", MySqlDbType.DateTime); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Date; } cmd.Parameters.Add(parameter); //06:工作消息(Message) isNull = string.IsNullOrWhiteSpace(entity.Message); parameter = new MySqlParameter("Message", MySqlDbType.VarString, isNull ? 10 : (entity.Message).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Message; } cmd.Parameters.Add(parameter); //07:任务分类(JobType) cmd.Parameters.Add(new MySqlParameter("JobType", MySqlDbType.Int32) { Value = (int)entity.JobType }); //08:工作状态(JobStatus) cmd.Parameters.Add(new MySqlParameter("JobStatus", MySqlDbType.Int32) { Value = (int)entity.JobStatus }); //09:命令类型(CommandType) cmd.Parameters.Add(new MySqlParameter("CommandType", MySqlDbType.Int32) { Value = (int)entity.CommandType }); //10:关联标识(LinkId) cmd.Parameters.Add(new MySqlParameter("LinkId", MySqlDbType.Int32) { Value = entity.LinkId }); //11:连接类型(EntityType) cmd.Parameters.Add(new MySqlParameter("EntityType", MySqlDbType.Int32) { Value = entity.EntityType }); //12:目标用户标识(ToUserId) cmd.Parameters.Add(new MySqlParameter("ToUserId", MySqlDbType.Int32) { Value = entity.ToUserId }); //13:目标用户名字(ToUserName) isNull = string.IsNullOrWhiteSpace(entity.ToUserName); parameter = new MySqlParameter("ToUserName", MySqlDbType.VarString, isNull ? 10 : (entity.ToUserName).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.ToUserName; } cmd.Parameters.Add(parameter); //14:来源用户标识(FromUserId) cmd.Parameters.Add(new MySqlParameter("FromUserId", MySqlDbType.Int32) { Value = entity.FromUserId }); //15:来源用户名字(FromUserName) isNull = string.IsNullOrWhiteSpace(entity.FromUserName); parameter = new MySqlParameter("FromUserName", MySqlDbType.VarString, isNull ? 10 : (entity.FromUserName).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.FromUserName; } cmd.Parameters.Add(parameter); //16:其它参数(Argument) isNull = string.IsNullOrWhiteSpace(entity.Argument); parameter = new MySqlParameter("Argument", MySqlDbType.LongText, isNull ? 10 : (entity.Argument).Length); if (isNull) { parameter.Value = DBNull.Value; } else { parameter.Value = entity.Argument; } cmd.Parameters.Add(parameter); //17:数据状态(DataState) cmd.Parameters.Add(new MySqlParameter("DataState", MySqlDbType.Int32) { Value = (int)entity.DataState }); //18:数据是否已冻结(IsFreeze) cmd.Parameters.Add(new MySqlParameter("IsFreeze", MySqlDbType.Byte) { Value = entity.IsFreeze ? (byte)1 : (byte)0 }); //19:接收者部门(DepartmentId) cmd.Parameters.Add(new MySqlParameter("DepartmentId", MySqlDbType.Int32) { Value = entity.DepartmentId }); }
/// <summary> /// 取得仅更新的SQL语句 /// </summary> internal string GetModifiedSqlCode(UserJobData data) { if (data.__EntityStatusNull || !data.__EntityStatus.IsModified) { return(";"); } StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE `tb_wf_user_job` SET"); //标题 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_Title] > 0) { sql.AppendLine(" `_title` = ?Title"); } //发生日期 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_Date] > 0) { sql.AppendLine(" `_date` = ?Date"); } //工作消息 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_Message] > 0) { sql.AppendLine(" `_message` = ?Message"); } //工作状态 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_JobStatus] > 0) { sql.AppendLine(" `_job_status` = ?JobStatus"); } //目标用户标识 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_ToUserId] > 0) { sql.AppendLine(" `_to_user_id` = ?ToUserId"); } //目标用户名字 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_ToUserName] > 0) { sql.AppendLine(" `_to_user_name` = ?ToUserName"); } //来源用户标识 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_FromUserId] > 0) { sql.AppendLine(" `_from_user_id` = ?FromUserId"); } //来源用户名字 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_FromUserName] > 0) { sql.AppendLine(" `_from_user_name` = ?FromUserName"); } //其它参数 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_Argument] > 0) { sql.AppendLine(" `_argument` = ?Argument"); } //数据状态 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_DataState] > 0) { sql.AppendLine(" `_data_state` = ?DataState"); } //数据是否已冻结 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_IsFreeze] > 0) { sql.AppendLine(" `_is_freeze` = ?IsFreeze"); } //接收者部门 if (data.__EntityStatus.ModifiedProperties[UserJobData.Real_DepartmentId] > 0) { sql.AppendLine(" `_department_id` = ?DepartmentId"); } sql.Append(" WHERE `_user_work_id` = ?Id;"); return(sql.ToString()); }