/// <summary> /// 获取所有的字典目录树t_itemcode第一级目录 /// </summary> /// <returns></returns> public string GetItemTreeJson(List <T_ItemCode> listItemCode) { T_ItemCodeMenumBLL codeMenuBll = new T_ItemCodeMenumBLL(); List <T_ItemCodeMenum> listMenu = codeMenuBll.GetItemCodeMenu(); sbJson.Append("["); T_ItemCode itemCode = new T_ItemCode(); for (int i = 0; i < listItemCode.Count; i++) { if (i != 0) { sbJson.Append(" , "); } itemCode = listItemCode[i]; sbJson.Append(AddModleItem(itemCode)); var data = listMenu.Where(o => o.item_id == itemCode.item_id && o.code_pid == 0); if (data.Count() > 0) { sbJson.Append(" ,nodes: "); sbJson.Append(GetItemCodeMenuTreeJson(data.ToList())); sbChild = new StringBuilder(); sbJson.Append(" } "); } else { sbJson.Append(" } "); } } sbJson.Append("]"); return(sbJson.ToString()); }
/// <summary> /// 编辑数据字典 /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool EditItemCode(object obj) { bool isAccess = false; FormCollection param = (FormCollection)obj; int code_id = int.Parse(param["code_id"]); int item_id = int.Parse(param["item_id"]); string item_type = param["item_type"]; string input_item_name = param["input_name"]; string input_item_code = param["input_code"]; string input_item_note = param["input_note"]; string code_type = param["code_type"]; if (item_type == "M") { T_ItemCode itemcode = new T_ItemCode(); itemcode.item_name = input_item_name; itemcode.item_code = input_item_code; itemcode.item_note = input_item_note; isAccess = base.Modify(itemcode, o => o.item_id == item_id, "item_name", "item_code", "item_note") > 0; } else if (item_type == "N") { T_ItemCodeMenumBLL menu_bll = new T_ItemCodeMenumBLL(); T_ItemCodeMenum menu = new T_ItemCodeMenum(); menu.code_name = input_item_name; menu.code_value = input_item_code; menu.code_note = input_item_note; menu.code_type = code_type; isAccess = menu_bll.Modify(menu, o => o.code_id == code_id, "code_name", "code_value", "code_note", "code_type") > 0; } return(isAccess); }
/// <summary> /// 需要添加的itemcode表的数据 /// </summary> /// <param name="itemCode"></param> /// <returns></returns> private string AddModleItem(T_ItemCode itemCode) { StringBuilder sb = new StringBuilder(); sb.Append("{ \"item_name\" :\"" + itemCode.item_name + "\" "); sb.Append(", \"item_id\" :\"" + itemCode.item_id + "\" "); sb.Append(", \"item_code\" :\"" + itemCode.item_code + "\" "); sb.Append(", \"text\" :\"" + itemCode.item_name + "\" "); return(sb.ToString()); }
/// <summary> /// 首页显示数据源JSON /// </summary> /// <param name="obj"></param> /// <returns></returns> public string ReturnPageJson(object obj) { FormCollection param = (FormCollection)obj; T_ItemCodeBLL itemCodeBll = new T_ItemCodeBLL(); T_ItemCode item_code = itemCodeBll.GetByItemCode("food_type"); List <T_ItemCodeMenum> list = GetByItemId(item_code.item_id); int page = int.Parse(param["page"]); int rows = int.Parse(param["rows"]); if (!string.IsNullOrEmpty(param["txtSearchName"])) { list = list.Where(o => o.code_name.Contains(param["txtSearchName"])).ToList(); } var data = list.Skip((page * rows) - rows).Take(rows).OrderByDescending(o => o.code_order); return("{\"total\":" + list.Count() + ",\"rows\":" + HCQ2_Common.JsonHelper.ObjectToJson(data) + "}"); }
public List <T_ItemCodeMenum> GetItemByCode(string fieldCode) { if (string.IsNullOrEmpty(fieldCode)) { return(null); } T_ItemCode item = Select(s => s.item_code == fieldCode).FirstOrDefault(); if (item == null) { return(null); } List <T_ItemCodeMenum> list = DBSession.IT_ItemCodeMenumDAL.Select(s => s.item_id == item.item_id); return(list); }
/// <summary> /// 添加商品分类 /// </summary> /// <param name="code_name"></param> /// <param name="code_value"></param> /// <param name="code_note"></param> /// <returns></returns> public bool AddGoodsType(string code_name, string code_value, string code_note) { T_ItemCodeBLL itemCodeBll = new T_ItemCodeBLL(); T_ItemCode item_code = itemCodeBll.GetByItemCode("food_type"); if (item_code != null) { List <T_ItemCodeMenum> list = GetByItemId(item_code.item_id); T_ItemCodeMenum Menu = new T_ItemCodeMenum(); Menu.item_id = item_code.item_id; Menu.code_name = code_name; Menu.code_value = code_value; Menu.code_note = code_note; Menu.code_pid = 0; Menu.if_system = 0; Menu.if_child = 0; Menu.code_order = list == null ? 1 : list[list.Count() - 1].code_order + 1; return(base.Add(Menu) > 0); } else { return(false); } }
/// <summary> /// 新增数据字典 /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool AddItemCode(object obj) { bool isAccess = false; FormCollection param = (FormCollection)obj; string code_id = param["code_id"]; string item_id = param["item_id"]; string input_item_name = param["input_name"]; string input_item_code = param["input_code"]; string input_item_note = param["input_note"]; string input_code_type = param["input_code_type"]; if (string.IsNullOrEmpty(item_id) && string.IsNullOrEmpty(code_id)) { //如果有相同的code,则不能添加。 if (base.Select(o => o.item_code == input_item_code).Count() > 0) { return(isAccess); } //添加字典说明表 T_ItemCode itemCode = new T_ItemCode(); itemCode.item_name = input_item_name; itemCode.item_code = input_item_code; itemCode.item_note = input_item_note; itemCode.creator_date = DateTime.Now; itemCode.creator_id = HCQ2UI_Helper.OperateContext.Current.Usr.user_id; itemCode.creator_name = HCQ2UI_Helper.OperateContext.Current.Usr.user_name; isAccess = base.Add(itemCode) > 0; } else if (!string.IsNullOrEmpty(item_id) && string.IsNullOrEmpty(code_id)) { //添加第一层字典表 T_ItemCodeMenumBLL codeBll = new T_ItemCodeMenumBLL(); //如果有相同的code,则不能添加。 if (codeBll.GetByItemId(int.Parse(item_id)).Where(o => o.code_value == input_item_code).Count() > 0) { return(isAccess); } T_ItemCodeMenum codeMenu = codeBll.GetByItemId(int.Parse(item_id)).Where(o => o.code_pid == 0).LastOrDefault(); int? maxOrder = codeMenu != null ? codeMenu.code_order + 1 : 1; codeMenu = new T_ItemCodeMenum(); codeMenu.item_id = int.Parse(item_id); codeMenu.code_name = input_item_name; codeMenu.code_value = input_item_code; codeMenu.code_note = input_item_note; codeMenu.if_system = 0; codeMenu.if_child = 0; codeMenu.code_pid = 0; codeMenu.code_order = maxOrder; if (!string.IsNullOrEmpty(input_code_type)) { codeMenu.code_type = input_code_type; } isAccess = codeBll.Add(codeMenu) > 0; } else if (!string.IsNullOrEmpty(item_id) && !string.IsNullOrEmpty(code_id)) { //添加字典表字典的子节点 T_ItemCodeMenumBLL codeBll = new T_ItemCodeMenumBLL(); //如果有相同的code,则不能添加。 if (codeBll.GetByItemId(int.Parse(item_id)).Where(o => o.code_value == input_item_code).Count() > 0) { return(isAccess); } T_ItemCodeMenum codeMenu = codeBll.GetByItemId(int.Parse(item_id)).Where(o => o.code_pid == int.Parse(code_id)).Max(); int? maxOrder = codeMenu != null ? codeMenu.code_order + 1 : 1; codeMenu = new T_ItemCodeMenum(); codeMenu.item_id = int.Parse(item_id); codeMenu.code_name = input_item_name; codeMenu.code_value = input_item_code; codeMenu.code_note = input_item_note; codeMenu.if_system = 0; codeMenu.if_child = 0; codeMenu.code_pid = int.Parse(code_id); codeMenu.code_order = maxOrder; if (!string.IsNullOrEmpty(input_code_type)) { codeMenu.code_type = input_code_type; } isAccess = codeBll.Add(codeMenu) > 0; } return(isAccess); }