public static Tuple <int, int, string> get_ItemJsonByWhere(Func <m_kh_nhom, bool> where, int page_number, int page_size) { var ls = list.Where(where).ToList(); //int startRowIndex = page_size * (page_number - 1); //var dt = ls.Skip(startRowIndex).Take(page_size).ToList(); List <m_kh_nhom> dt = new List <m_kh_nhom>() { }; if (ls.Count > page_size) { int startRowIndex = page_size * (page_number - 1); dt = ls.Skip(startRowIndex).Take(page_size).ToList(); } else { dt = ls; } for (int k = 0; k < dt.Count; k++) { m_kh_nhom m = dt[k]; List <long> lsi = new List <long>() { }; dic_Nhom_Item.TryGetValue(m.id, out lsi); if (lsi != null && lsi.Count > 0) { m.item_count = lsi.Count; } dt[k] = m; } string json = JsonConvert.SerializeObject(dt); //return json; return(new Tuple <int, int, string>(list.Count, ls.Count, json)); }
// update các thông tin của nhóm public static string edit_ItemJsonString(string item_json, string msg_default = "") { string json = msg_default; try { m_kh_nhom m = JsonConvert.DeserializeObject <m_kh_nhom>(item_json); int index = list.FindIndex(o => o.id == m.id); if (index != -1) { m_kh_nhom o = list[index]; o.name = m.name; o.type = m.type; long id_parent_new = m.id_parent, id_parent_old = o.id_parent; if (id_parent_new != id_parent_old) { string array_subID_new = "", array_subID_old = ""; dic_Nhom_Index.TryGetValue(id_parent_new, out array_subID_new); dic_Nhom_Index.TryGetValue(id_parent_old, out array_subID_old); //join new id parent if (string.IsNullOrEmpty(array_subID_new)) { array_subID_new = ";" + o.id.ToString() + ";"; } else { array_subID_new += o.id.ToString() + ";"; } //remove id parent old if (!string.IsNullOrEmpty(array_subID_old)) { array_subID_old = array_subID_old.Replace(";" + o.id.ToString() + ";", ";"); } try { lock (lock_index) { update_index(id_parent_new, array_subID_new); update_index(id_parent_old, array_subID_old); } } catch { } } lock (lock_list) list[index] = o; update(); json = JsonConvert.SerializeObject(o); } } catch { } return(json); }
// them 1 nhom moi public static string add_ItemJson(string item_json, string msg_default = "") { string json = msg_default; var json_obj = JsonConvert.DeserializeObject <m_kh_nhom>(item_json); try { m_kh_nhom m = JsonConvert.DeserializeObject <m_kh_nhom>(item_json); int index = list.FindIndex(o => o.code == m.code); if (index == -1) { bool c = false; int id_new = 0; while (c == false) { Random rnd = new Random(); id_new = rnd.Next(1, int.MaxValue); int idx = list.FindIndex(o => id_new == m.id); if (idx == -1) { c = true; } ; } int phase_type = json_obj.id_group; long id_parent = json_obj.id_parent; m.id = id_new; m.id_group = phase_type; m.id_parent = id_parent; m.level = json_obj.level; m.name = json_obj.name; m.code = json_obj.code; m.status = true; string array_subID = ""; dic_Nhom_Index.TryGetValue(id_parent, out array_subID); if (array_subID == null) { array_subID = ";" + id_new.ToString() + ";"; } else { array_subID = array_subID + id_new.ToString() + ";"; } lock (lock_list) { list.Add(m); } lock (lock_index) { if (dic_Nhom_Index.ContainsKey(id_parent)) { dic_Nhom_Index[id_parent] = array_subID; } update_index(id_parent, array_subID); } update(); json = JsonConvert.SerializeObject(m); } else { json = "Trùng mã"; } } catch { } return(json); }
public static Tuple <bool, string, dynamic> add(string s_key, string s_item) { try { string json = ""; var json_obj = JsonConvert.DeserializeObject <m_kh_nhom>(s_item); m_kh_nhom m = JsonConvert.DeserializeObject <m_kh_nhom>(s_item); int index = list.FindIndex(o => o.code == m.code); if (index == -1) { bool c = false; int id_new = 0; while (c == false) { Random rnd = new Random(); id_new = rnd.Next(1, int.MaxValue); int idx = list.FindIndex(o => id_new == m.id); if (idx == -1) { c = true; } ; } int phase_type = json_obj.id_group; long id_parent = json_obj.id_parent; m.id = id_new; m.id_group = phase_type; m.id_parent = id_parent; m.level = json_obj.level; m.name = json_obj.name; m.code = json_obj.code; m.status = true; string array_subID = ""; dic_Nhom_Index.TryGetValue(id_parent, out array_subID); if (array_subID == null) { array_subID = ";" + id_new.ToString() + ";"; } else { array_subID = array_subID + id_new.ToString() + ";"; } lock (lock_list) { list.Add(m); } lock (lock_index) { if (dic_Nhom_Index.ContainsKey(id_parent)) { dic_Nhom_Index[id_parent] = array_subID; } update_index(id_parent, array_subID); } update(); json = JsonConvert.SerializeObject(m); } else { json = "trung_ma"; } return(new Tuple <bool, string, dynamic>(true, json, m)); } catch { } return(new Tuple <bool, string, dynamic>(false, "", null)); }
public static Tuple <bool, string, dynamic> edit(string s_key, string s_item) { try { string json = ""; m_kh_nhom m = JsonConvert.DeserializeObject <m_kh_nhom>(s_item); int index = list.FindIndex(o => o.id == m.id); if (index != -1) { m_kh_nhom o = list[index]; o.name = m.name; o.type = m.type; long id_parent_new = m.id_parent, id_parent_old = o.id_parent; if (id_parent_new != id_parent_old) { string array_subID_new = "", array_subID_old = ""; dic_Nhom_Index.TryGetValue(id_parent_new, out array_subID_new); dic_Nhom_Index.TryGetValue(id_parent_old, out array_subID_old); //join new id parent if (string.IsNullOrEmpty(array_subID_new)) { array_subID_new = ";" + o.id.ToString() + ";"; } else { array_subID_new += o.id.ToString() + ";"; } //remove id parent old if (!string.IsNullOrEmpty(array_subID_old)) { array_subID_old = array_subID_old.Replace(";" + o.id.ToString() + ";", ";"); } try { lock (lock_index) { update_index(id_parent_new, array_subID_new); update_index(id_parent_old, array_subID_old); } } catch { } } lock (lock_list) list[index] = o; update(); json = JsonConvert.SerializeObject(o); } return(new Tuple <bool, string, dynamic>(true, json, m)); } catch { } return(new Tuple <bool, string, dynamic>(false, "", null)); }