public MsgModel DeleteOrg(sys_org sys_org) { List <sys_org> myChilds = _baseSysOrgService.GetModels(a => a.org_pids.Contains("[" + sys_org.org_pid + "]")).ToList(); if (myChilds.Count > 0) { // "不能删除有下级组织的组织机构" throw new CustomException((int)HttpStatusCode.Status500InternalServerError, "不能删除有下级组织的组织机构"); } List <sys_org> myFatherChilds = _baseSysOrgService.GetModels(a => a.org_pids.Contains("[" + "]")).ToList(); //我的父节点只有我这一个子节点,而我还要被删除,更新父节点为叶子节点。 if (myFatherChilds.Count == 1) { sys_org parent = new sys_org { id = sys_org.org_pid, is_leaf = true// 更新父节点为叶子节点。 }; _baseSysOrgService.Update(parent); } // 删除节点 _baseSysOrgService.Remove(sys_org); return(MsgModel.Success("删除组织机构成功!")); }
/// <summary> /// 修改用户组 /// </summary> /// <param name="org"></param> /// <returns>执行结果</returns> public Result Update(sys_org org) { Result res = new Result(); OrganizationDAL orgDAL = new OrganizationDAL(); try { if (orgDAL.Update(org) == 0) { res.Code = RES.ERROR; res.Message = "修改失败!"; return(res); } else { res.Code = RES.OK; res.Message = "修改成功!"; return(res); } } catch { res.Code = RES.ERROR; res.Message = "修改失败!"; return(res); } }
/// <summary> /// 通过parent_id查询组织机构 /// </summary> /// <param name="pid"></param> /// <returns>List<sys_org></returns> public List <sys_org> SelectByparentid(int pid) { try { DataSet ds = new DataSet(); string sql = "Select * from sys_org where parent_id= '" + pid + "'"; List <sys_org> org = new List <sys_org>(); ds = SqlHelper.ExecuteDataset(ConStr, CommandType.Text, sql); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { sys_org org1 = new sys_org(); org1.id = (int)ds.Tables[0].Rows[i][nameof(sys_org.id)]; org1.org_name = (string)ds.Tables[0].Rows[i][nameof(sys_org.org_name)]; org1.create_time = (DateTime)ds.Tables[0].Rows[i][nameof(sys_org.create_time)]; org1.modify_time = (DateTime)ds.Tables[0].Rows[i][nameof(sys_org.modify_time)]; org.Add(org1); } new LogUserDAL().Add(LogOperations.LogUser("查询组织机构")); return(org); } catch (Exception e) { new LogSysDAL().Add(LogOperations.LogSys("查询组织机构" + e.Message)); return(null); } }
public MsgModel UpdateOrg(sys_org sys_org) { if (!_baseSysOrgService.Update(sys_org)) { return(MsgModel.Fail("更新组织机构失败!")); } return(MsgModel.Success("更新组织机构成功!")); }
/// <summary> /// 组织管理:更新组织的禁用状态 /// </summary> /// <param name="id"></param> /// <param name="status"></param> public MsgModel UpdateStatus(int id, bool status) { sys_org sys_org = _baseSysOrgService.GetModels(a => a.id == id).SingleOrDefault(); sys_org.status = status; bool result = _baseSysOrgService.Update(sys_org); return(result ? MsgModel.Success("更新组织机构状态成功!") : MsgModel.Fail("更新组织机构状态失败!")); }
public MsgModel AddOrg(sys_org sys_org) { SetOrgIdsAndLevel(sys_org); sys_org.is_leaf = true;//新增的组织节点都是子节点,没有下级 sys_org parent = _baseSysOrgService.GetModels(a => a.id == sys_org.org_pid).SingleOrDefault(); parent.id = sys_org.org_pid; parent.is_leaf = false; //更新父节点为非子节点。 _baseSysOrgService.Update(parent); sys_org.status = false;//设置是否禁用,新增节点默认可用 _baseSysOrgService.Add(sys_org); return(MsgModel.Success("新增组织机构成功!")); }
/// <summary> /// //设置某子节点的所有祖辈id /// </summary> /// <param name="child"></param> private void SetOrgIdsAndLevel(sys_org child) { List <sys_org> allOrgs = _baseSysOrgService.GetModels(null).ToList(); foreach (sys_org sys_org in allOrgs) { //从组织列表中找到自己的直接父亲 if (sys_org.id == child.org_pid) { //直接父亲的所有祖辈id + 直接父id = 当前子节点的所有祖辈id //爸爸的所有祖辈 + 爸爸 = 孩子的所有祖辈 child.org_pids = sys_org.org_pids + "[" + child.org_pid + "]"; child.level = sys_org.level + 1; } } }
private void btnAddUser_Click(object sender, EventArgs e) { sys_org org = new sys_org(); org.org_name = comboBox1.SelectedItem.ToString(); List <sys_org> orginfo = new List <sys_org>(); //orginfo =//查询组织机构Id方法 sys_user sys_User = new sys_user(); sys_User.name = textBoxX1.Text; sys_User.username = textBoxX2.Text; if (radioButton1.Checked) { sys_User.gender = "男"; } else { sys_User.gender = "女"; } sys_User.phone = textBoxX4.Text; sys_User.email = textBoxX5.Text; sys_User.job = textBoxX6.Text; foreach (var id in orginfo) { sys_User.org_id = id.id; } if (radioButton3.Checked) { sys_User.status = false; } else { sys_User.status = true; } SysUserBLL sysUserBLL = new SysUserBLL(); Result result = sysUserBLL.add(sys_User); if (result.Code == RES.OK) { MessageBoxCustom.Show("修改成功", "提示", MessageBoxButtons.OK, this); Close(); } else if (result.Code == RES.ERROR) { MessageBoxCustom.Show("修改失败", "提示", MessageBoxButtons.OK, this); } }
public IActionResult Delete(int id) { sys_org sysOrg = _sysOrgRpt.GetSingle(id); if (sysOrg == null) { return(new NotFoundResult()); } if (_sysStaffRpt.FindBy(f => f.OrgId == sysOrg.Id).Any()) { return(BadRequest(string.Concat(sysOrg.DeptName, "已经关联用户,不能删除。"))); } sysOrg.IsValid = false; _sysOrgRpt.Commit(); return(new NoContentResult()); }
public IActionResult Post([FromBody] sys_org value) { var oldSysOrg = _sysOrgRpt.FindBy(f => f.DeptName == value.DeptName); if (oldSysOrg.Any()) { return(BadRequest(string.Concat(value.DeptName, "已经存在。"))); } value.CreatedAt = DateTime.Now; value.UpdatedAt = DateTime.Now; if (User.Identity is ClaimsIdentity identity) { value.CreatedBy = identity.Name ?? "test"; } value.IsValid = true; _sysOrgRpt.Add(value); _sysOrgRpt.Commit(); return(new OkObjectResult(value)); }
/// <summary> /// 修改组织机构 /// </summary> /// <param name="org"></param> /// <returns>修改条数</returns> public int Update(sys_org org) { try { int res = 0; string sql = "upadate sys_menu SET parent_id = @p1,org_name = @p2,create_time = @p3,modify_time = @p4 where id = '" + org.id + "'"; SqlParameter sqlParameter1 = new SqlParameter("@p1", org.parent_id); SqlParameter sqlParameter2 = new SqlParameter("@p2", org.org_name); SqlParameter sqlParameter3 = new SqlParameter("@p3", org.create_time); SqlParameter sqlParameter4 = new SqlParameter("@p4", org.modify_time); res = SqlHelper.ExecuteNonQuery(ConStr, CommandType.Text, sql, sqlParameter1, sqlParameter2, sqlParameter3, sqlParameter4); new LogUserDAL().Add(LogOperations.LogUser("修改组织机构")); return(res); } catch (Exception e) { new LogSysDAL().Add(LogOperations.LogSys(e.Message)); return(0); } }
/// <summary> /// 添加组织机构 /// </summary> /// <param name="org"></param> /// <returns>添加条数</returns> public int Add(sys_org org) { try { int res = 0; string sql = "insert into sys_menu(parent_id,org_name,creat_time,modify_time) values(@p1,@p2,@p3,@p4) where parent_id = @id"; SqlParameter sqlParameter1 = new SqlParameter("@p1", org.parent_id); SqlParameter sqlParameter2 = new SqlParameter("@p2", org.org_name); SqlParameter sqlParameter3 = new SqlParameter("@p3", org.create_time); SqlParameter sqlParameter4 = new SqlParameter("@p4", org.modify_time); res = SqlHelper.ExecuteNonQuery(ConStr, CommandType.Text, sql, sqlParameter1, sqlParameter2, sqlParameter3, sqlParameter4); new LogUserDAL().Add(LogOperations.LogUser("添加组织机构")); return(res); } catch (Exception e) { new LogSysDAL().Add(LogOperations.LogSys(e.Message)); return(0); } }
private void BtnAddUser_Click(object sender, EventArgs e) { sys_org org = new sys_org(); org.org_name = CmbOrg.SelectedItem.ToString(); List <sys_org> orginfo = new List <sys_org>(); //orginfo =//查询组织机构Id方法 sys_user sys_User = new sys_user(); sys_User.name = TxtName.Text; sys_User.username = TxtUsername.Text; if (RdoSex1.Checked) { sys_User.gender = "男"; } else { sys_User.gender = "女"; } sys_User.password = TxtPassword.Text; sys_User.phone = TxtPhone.Text; sys_User.email = TxtEmail.Text; sys_User.job = TxtJob.Text; foreach (var id in orginfo) { sys_User.org_id = id.id; } SysUserBLL sysUserBLL = new SysUserBLL(); Result result = sysUserBLL.add(sys_User); if (result.Code == RES.OK) { MessageBoxCustom.Show("添加成功", "提示", MessageBoxButtons.OK, this); Close(); } else if (result.Code == RES.ERROR) { MessageBoxCustom.Show("添加失败", "提示", MessageBoxButtons.OK, this); } }