/// <summary> /// 根据菜单Id获取菜单编辑信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public MenuInfoEditModel GetMenuInfoById(string id) { try { if (string.IsNullOrWhiteSpace(id)) { throw new Exception("菜单Id不能为空!"); } MenuInfoEditModel result = new MenuInfoEditModel(); DataTable dt = _sql.Query(@"SELECT m.MenuName, m.MenuCode, m.MenuPath, m.MenuSeq, m.MenuInfoId, m.PMenuId, pm.MenuName AS PMenuIdName FROM MenuInfo m LEFT JOIN MenuInfo pm ON m.PMenuId = pm.MenuInfoId WHERE m.MenuInfoId = @id ", new Dictionary <string, object> { { "@id", id } }); if (dt != null && dt.Rows.Count > 0) { result = dt.ToModelList <MenuInfoEditModel>()[0]; } return(result); } catch (Exception ex) { _log.Error(ex); throw ex; } }
/// <summary> /// 创建或更新菜单信息 /// </summary> /// <param name="info">菜单编辑信息</param> /// <returns></returns> public string CreateOrUpdateMenuInfo(MenuInfoEditModel info) { try { if (string.IsNullOrWhiteSpace(info.MenuName)) { throw new Exception("菜单名称不能为空!"); } if (string.IsNullOrWhiteSpace(info.MenuCode)) { throw new Exception("菜单编码不能为空!"); } if (string.IsNullOrWhiteSpace(info.MenuPath)) { throw new Exception("菜单路径不能为空!"); } if (Cast.ConToInt(info.MenuSeq) == 0) { throw new Exception("菜单排序不能为空!"); } _sql.OpenDb(); string result = string.Empty; MenuInfo main = new MenuInfo(); info.FillTableWithModel <MenuInfo>(main); if (!string.IsNullOrEmpty(info.MenuInfoId)) { if (main.MenuInfoId == main.PMenuId) { throw new Exception("上级菜单不能为当前菜单!"); } _sql.Update(main); result = Constants.UpdateSuccessMssg; } else { DataTable dt = _sql.Query("SELECT MenuName FROM MenuInfo WHERE IsDeleted = 0 AND MenuCode = @code", new Dictionary <string, object> { { "@code", info.MenuCode } }); if (dt != null && dt.Rows.Count > 0) { throw new Exception(string.Format("当前菜单【{0}:{1}】已存在!", info.MenuCode, Cast.ConToString(dt.Rows[0]["MenuName"]))); } _sql.Create(main); result = Constants.CreateSuccessMssg; } return(result); } catch (Exception ex) { _log.Error(ex); throw ex; } finally { _sql.CloseDb(); } }