public JsonResult UpdateSort_Nav(string ids, string sorts) { bool res = true; if (string.IsNullOrEmpty(ids) || string.IsNullOrEmpty(sorts)) { res = false; } else { string[] arrId = ids.Split(','); string[] arrSort = sorts.Split(','); for (int i = 0; i < arrId.Length; i++) { NcNavigation model = dblEf.Find <NcNavigation>(Utils.StrToInt(arrId[i])); if (model != null && Utils.StrToInt(arrSort[i]) != model.SortId)//减少数据库访问次数 { model.SortId = Utils.StrToInt(arrSort[i]); res = dblEf.SaveChanges() > 0; //res = dblEf.Update<NcNavigation>(model); } } } return(Json(new { status = (res ? 1 : 0), message = "保存成功!" })); }
public JsonResult nav_validate() { string navname = Request.Form["param"].ToString(); string old_name = Request.Query["old_name"].ToString(); string strStatus = "y"; string strMsg = "该导航菜单ID可使用!"; if (string.IsNullOrEmpty(navname)) { strStatus = "n"; strMsg = "该导航菜单ID不可为空!"; } else if (navname.ToLower() == old_name.ToLower())//未改 { //strMsg = "该导航菜单ID可使用!"; } //检查保留的名称开头 else if (navname.ToLower().StartsWith("channel_")) { strStatus = "n"; strMsg = "该导航菜单ID系统保留,请更换!"; } else { NcNavigation model = dblEf.NcNavigation.Where(n => n.Name == navname).FirstOrDefault(); if (model != null) { strStatus = "n"; strMsg = "该导航菜单ID已被占用,请更换!"; } } return(Json(new { status = strStatus, info = strMsg })); }
private NcNavigation NavSetModel(NcNavigation model) { model.NavType = JHEnums.NavigationEnum.System.ToString(); model.Name = Request.Form["txtName"]; model.Title = Request.Form["txtTitle"]; model.SubTitle = Request.Form["txtSubTitle"]; model.LinkUrl = Request.Form["txtLinkUrl"]; model.SortId = Utils.StrToInt(Request.Form["SortId"]); model.IsLock = 0; if (Request.Form["is_lock"] == "on") { model.IsLock = 1; } model.Remark = Request.Form["remark"]; int parentId = Utils.StrToInt(Request.Form["parent_id"]); //如果选择的父ID不是自己,则更改 if (parentId != model.Id || model.Id == 0) { model.ParentId = parentId; } //添加操作权限类型 model.ActionType = Request.Form["cblActionType"]; return(model); }
public JsonResult NavSave() { NcNavigation model = new NcNavigation(); action = Request.Form["act"]; if (action.ToLower() == JHEnums.ActionEnum.Edit.ToString().ToLower())//修改 { int id = Utils.StrToInt(Request.Form["id"]); model = dblEf.Find <NcNavigation>(id); model = NavSetModel(model); if (NavUpdate(model)) { CacheHelper.Remove("NC_nav"); strStatus = "1"; strMsg = "保存成功"; } } else//新增 { model = NavSetModel(model); model.ChannelId = 0; model.IsSys = 0; if (NavAdd(model) > 0) { CacheHelper.Remove("NC_nav"); strStatus = "1"; strMsg = "保存成功"; } } return(Json(new { status = strStatus, msg = strMsg })); }
public bool NavUpdate(NcNavigation model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update nc_Navigation set "); strSql.Append("nav_type=@nav_type,"); strSql.Append("name=@name,"); strSql.Append("title=@title,"); strSql.Append("sub_title=@sub_title,"); strSql.Append("link_url=@link_url,"); strSql.Append("Sort_Id=@SortId,"); strSql.Append("is_lock=@is_lock,"); strSql.Append("remark=@remark,"); strSql.Append("Parent_Id=@ParentId,"); strSql.Append("channel_id=@channel_id,"); strSql.Append("action_type=@action_type,"); strSql.Append("is_sys=@is_sys"); strSql.Append(" where id=@id;"); strSql.Append(@"if @@error<>0 begin rollback tran select N'fail' as result return end"); // StringBuilder strChild = new StringBuilder(); StringBuilder strN = new StringBuilder(); //string sC = UpdateChilds(strChild, model.ParentId); //string sn = UpdateChilds(strN, model.id); //先判断选中的父节点是否被包含 //查找旧父节点数据 //" + sC + @" //" + sn + @" string sql = @" Begin Tran declare @ReturnValue as int " + strSql.ToString() + @" select N'success' as result Commit Tran "; DbParameters p = new DbParameters(); p.Add("@id", model.Id); p.Add("@ParentId", model.ParentId); p.Add("@channel_id", model.ChannelId); p.Add("@action_type", model.ActionType); p.Add("@is_sys", model.IsSys); p.Add("@nav_type", model.NavType); p.Add("@name", model.Name); p.Add("@title", model.Title); p.Add("@sub_title", model.SubTitle); p.Add("@link_url", model.LinkUrl); p.Add("@SortId", model.SortId); p.Add("@is_lock", model.IsLock); p.Add("@remark", model.Remark); string result = Utils.ObjectToStr(Dbl.ZZCMS.CreateSqlScalar(sql, p)); return(result == "success"); }
public ActionResult DelNav(string ids) { bool res = true; if (string.IsNullOrEmpty(ids)) { res = false; strMsg = "删除参数异常!";// } else { string[] arrId = ids.Split(','); try { for (int i = 0; i < arrId.Length; i++) { string id = arrId[i]; //dblEf.NcNavigation.Remove(nv => nv.Id.Contains("," + id + ","));// //1、创建要删除的对象 NcNavigation modelDel = new NcNavigation() { Id = Utils.StrToInt(id) }; //2、将对象添加到EF管理容器中 dblEf.NcNavigation.Attach(modelDel); //3、将对象包装类的状态标识为删除状态 dblEf.NcNavigation.Remove(modelDel); //4、更新到数据库 dblEf.SaveChanges(); } res = true; strMsg = "删除成功!"; } catch (Exception ex)//循环删除,异常才报删除错误 { res = false; strMsg = "删除过程中出现异常!";//调试过程中+ex.ToString(); } } return(Json(new { status = (res ? 1 : 0), message = strMsg })); }
public ActionResult Nav_Edit() { action = Request.Query["act"]; int id = Utils.StrToInt(Request.Query["id"]); NcNavigation model = new NcNavigation(); if (action.ToLower() == JHEnums.ActionEnum.Edit.ToString().ToLower() && id != 0) //修改 { model = BindNav(id); } else { model.SortId = 99; if (id != 0) { model.ParentId = id; } } ViewBag.action = action; ViewBag.id = id; return(View(model)); }
public int NavAdd(NcNavigation model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into nc_Navigation("); strSql.Append("nav_type,name,title,sub_title,link_url,Sort_Id,is_lock,remark,Parent_Id,channel_id,action_type,is_sys)"); strSql.Append(" values ("); strSql.Append("@nav_type,@name,@title,@sub_title,@link_url,@SortId,@is_lock,@remark,@ParentId,@channel_id,@action_type,@is_sys)"); strSql.Append(";select @ReturnValue= @@IDENTITY "); strSql.Append(@"if @@error<>0 begin rollback tran select N'fail' as result return end"); string sql = @" Begin Tran declare @ReturnValue as int " + strSql.ToString() + @" select N'success' as result Commit Tran "; DbParameters p = new DbParameters(); p.Add("@ParentId", model.ParentId); p.Add("@channel_id", model.ChannelId); p.Add("@action_type", model.ActionType); p.Add("@is_sys", model.IsSys); p.Add("@nav_type", model.NavType); p.Add("@name", model.Name); p.Add("@title", model.Title); p.Add("@sub_title", model.SubTitle); p.Add("@link_url", model.LinkUrl); p.Add("@SortId", model.SortId); p.Add("@is_lock", model.IsLock); p.Add("@remark", model.Remark); string result = Utils.ObjectToStr(Dbl.ZZCMS.CreateSqlScalar(sql, p)); return(result == "success" ? 1 : 0); }
/// <summary> /// 绑定菜单 /// </summary> private NcNavigation BindNav(int id) { NcNavigation model = dblEf.Find <NcNavigation>(id); return(model); }