/// <summary> /// 获取指定记录 /// <param name="id">Id值</param> /// </summary> public SysUserTimemachine Get(int userid, int entid) { SysUserTimemachine returnValue = null; MySqlConnection oc = ConnectManager.Create(); MySqlCommand _cmdGetSysUserTimemachine = cmdGetSysUserTimemachine.Clone() as MySqlCommand; _cmdGetSysUserTimemachine.Connection = oc; try { _cmdGetSysUserTimemachine.Parameters["@UserId"].Value = userid; _cmdGetSysUserTimemachine.Parameters["@EntId"].Value = entid; if (oc.State == ConnectionState.Closed) { oc.Open(); } MySqlDataReader reader = _cmdGetSysUserTimemachine.ExecuteReader(); if (reader.HasRows) { reader.Read(); returnValue = new SysUserTimemachine().BuildSampleEntity(reader); } } finally { oc.Close(); oc.Dispose(); oc = null; _cmdGetSysUserTimemachine.Dispose(); _cmdGetSysUserTimemachine = null; GC.Collect(); } return(returnValue); }
/// <summary> /// 添加数据 /// <param name="es">数据实体对象数组</param> /// <returns></returns> /// </summary> public int Insert(SysUserTimemachine e) { MySqlConnection oc = ConnectManager.Create(); MySqlCommand _cmdInsertSysUserTimemachine = cmdInsertSysUserTimemachine.Clone() as MySqlCommand; int returnValue = 0; _cmdInsertSysUserTimemachine.Connection = oc; try { if (oc.State == ConnectionState.Closed) { oc.Open(); } _cmdInsertSysUserTimemachine.Parameters["@UserId"].Value = e.UserId; _cmdInsertSysUserTimemachine.Parameters["@UserName"].Value = e.UserName; _cmdInsertSysUserTimemachine.Parameters["@RoleName"].Value = e.RoleName; _cmdInsertSysUserTimemachine.Parameters["@EntName"].Value = e.EntName; _cmdInsertSysUserTimemachine.Parameters["@EntId"].Value = e.EntId; _cmdInsertSysUserTimemachine.Parameters["@StartTime"].Value = e.StartTime; _cmdInsertSysUserTimemachine.ExecuteNonQuery(); returnValue = Convert.ToInt32(_cmdInsertSysUserTimemachine.LastInsertedId); return(returnValue); } finally { oc.Close(); oc.Dispose(); oc = null; _cmdInsertSysUserTimemachine.Dispose(); _cmdInsertSysUserTimemachine = null; } }
/// <summary> /// 修改指定的数据 /// <param name="e">修改后的数据实体对象</param> /// <para>数据对应的主键必须在实例中设置</para> /// </summary> public void Update(SysUserTimemachine e) { MySqlConnection oc = ConnectManager.Create(); MySqlCommand _cmdUpdateSysUserTimemachine = cmdUpdateSysUserTimemachine.Clone() as MySqlCommand; _cmdUpdateSysUserTimemachine.Connection = oc; try { if (oc.State == ConnectionState.Closed) { oc.Open(); } _cmdUpdateSysUserTimemachine.Parameters["@IdsysUserTimemachine"].Value = e.IdsysUserTimemachine; _cmdUpdateSysUserTimemachine.Parameters["@UserId"].Value = e.UserId; _cmdUpdateSysUserTimemachine.Parameters["@UserName"].Value = e.UserName; _cmdUpdateSysUserTimemachine.Parameters["@RoleName"].Value = e.RoleName; _cmdUpdateSysUserTimemachine.Parameters["@EntName"].Value = e.EntName; _cmdUpdateSysUserTimemachine.Parameters["@EntId"].Value = e.EntId; _cmdUpdateSysUserTimemachine.Parameters["@StartTime"].Value = e.StartTime; _cmdUpdateSysUserTimemachine.Parameters["@EndTime"].Value = e.EndTime; _cmdUpdateSysUserTimemachine.ExecuteNonQuery(); } finally { oc.Close(); oc.Dispose(); oc = null; _cmdUpdateSysUserTimemachine.Dispose(); _cmdUpdateSysUserTimemachine = null; GC.Collect(); } }
//添加用户入职记录 private void AddUTM(int userId, int changeType, int roleId) { /* * changeType * 1用户注册 * 2企业注册 * 3用户绑定企业code 或者是有权限变没权限 * 4未审核修改为有权限时 * */ SysUserTimemachine ut = new SysUserTimemachine(); SysUser user = new SysUser(); user = SysUserAccessor.Instance.Get(userId); switch (changeType) { case 1: if (!string.IsNullOrEmpty(user.EntCode)) { ut.EntId = user.EntId; ut.EntName = SysUserAccessor.Instance.Get(user.EntId).UserName; ut.RoleName = "未审核"; } ut.UserId = userId; ut.UserName = user.UserName; ut.StartTime = DateTime.Now; SysUserTimemachineAccessor.Instance.Insert(ut); break; case 2: ut.EntId = user.EntId; ut.EntName = user.UserName; ut.RoleName = "管理员"; ut.StartTime = DateTime.Now; ut.UserId = userId; ut.UserName = user.UserName; SysUserTimemachineAccessor.Instance.Insert(ut); break; case 3: ut.EntId = user.EntId; ut.EntName = SysUserAccessor.Instance.Get(user.EntId).UserName; ut.RoleName = "未审核"; ut.StartTime = DateTime.Now; ut.UserId = userId; ut.UserName = user.UserName; SysUserTimemachineAccessor.Instance.Insert(ut); break; case 4: ut.EntId = user.EntId; ut.EntName = SysUserAccessor.Instance.Get(user.EntId).UserName; ut.RoleName = SysRoleAccessor.Instance.Get(roleId).RoleName; ut.StartTime = DateTime.Now; ut.UserId = user.UserId; ut.UserName = user.UserName; SysUserTimemachineAccessor.Instance.Insert(ut); break; default: break; } List <SysUserTimemachine> utlist = new List <SysUserTimemachine>(); utlist = SysUserTimemachineAccessor.Instance.Search(userId); SysUserTimemachine oldut = new SysUserTimemachine(); if (utlist.Count > 1) { oldut = utlist[1]; oldut.EndTime = DateTime.Now; SysUserTimemachineAccessor.Instance.Update(oldut); } }