/// <summary> /// 获取材料类别列表 /// </summary> /// <param name="context"></param> private void isExit(HttpContext context) { string json = string.Empty; string sql = " "; string categoryname = context.Request["categoryname"]; string parentcategoryid = context.Request["parentcategoryid"]; string id = context.Request["id"]; if (!string.IsNullOrEmpty(categoryname)) { sql += " and categoryname = '" + categoryname + "'"; } if (!string.IsNullOrEmpty(parentcategoryid)) { sql += " and parentcategoryid ='" + parentcategoryid + "'"; } try { List <TBL_MATERIALCATEGORY> lists = Bll.GetList(sql) as List <TBL_MATERIALCATEGORY>; if (lists.Count > 0) { if (lists.Count == 1) { TBL_MATERIALCATEGORY model = lists[0]; if (model.materialcategoryid == id) { json = JsonConvert.SerializeObject("{IsSuccess:'false',Message:'不存在该材料类型!'}"); } else { json = JsonConvert.SerializeObject("{IsSuccess:'true',Message:'存在该材料类型!'}"); } } else { json = JsonConvert.SerializeObject("{IsSuccess:'true',Message:'存在该材料类型!'}"); } } else { json = JsonConvert.SerializeObject("{IsSuccess:'false',Message:'不存在该材料类型!'}"); } } catch { json = JsonConvert.SerializeObject("{IsSuccess:'false',Message:'服务器交互失败!'}"); } context.Response.ContentType = "application/json"; //返回JSON结果 context.Response.Write(json); context.Response.End(); }
/// <summary> /// 获取材料类别的树型结构 /// </summary> /// <param name="toList">材料类别列表</param> /// <param name="to">材料类别</param> public void getTree(List <TBL_MATERIALCATEGORY> toList, TBL_MATERIALCATEGORY category) { //获取子集节点 List <TBL_MATERIALCATEGORY> coList = toList.Where(o => o.parentcategoryid == category.materialcategoryid).ToList <TBL_MATERIALCATEGORY>(); if (coList.Count > 0) { category.children = coList; foreach (TBL_MATERIALCATEGORY toc in coList) { getTree(toList, toc); } } }
/// <summary> /// 新增材料类别 /// </summary> /// <param name="context"></param> private void add(HttpContext context) { string json = ""; TBL_MATERIALCATEGORY model = new TBL_MATERIALCATEGORY(); model.materialcategoryid = System.Guid.NewGuid().ToString().ToUpper(); model.parentcategoryid = context.Request["parentcategoryid"]; model.categoryname = context.Request["categoryname"]; model.matlevel = context.Request["level"]; try { Bll.Add(model); json = "{IsSuccess:'true',Message:'保存成功!',id:'" + model.materialcategoryid + "'}"; } catch { json = "{IsSuccess:'false',Message:'保存失败!'}"; } context.Response.Write(json); context.Response.End(); }
/// <summary> /// 修改材料类别 /// </summary> /// <param name="context"></param> private void update(HttpContext context) { string json = ""; TBL_MATERIALCATEGORY model = new TBL_MATERIALCATEGORY(); model.materialcategoryid = context.Request["materialcategoryid"]; model.parentcategoryid = context.Request["parentcategoryid"]; model.categoryname = context.Request["categoryname"]; model.matlevel = context.Request["level"]; try { Bll.Update(model); json = "{IsSuccess:'true',Message:'保存成功!'}"; } catch { json = "{IsSuccess:'false',Message:'保存失败!'}"; } // context.Response.ContentType = "application/json"; //返回JSON结果 context.Response.Write(json); context.Response.End(); }