//ham tra ve day cac menu item cung 1 level //vi du nhu : New, Open, Save, Save As cung 1 cap : 1 myStruct[] getOneLevelMenu(string dieukien, string group_id) { DataRow[] rows = dt.Select(dieukien, "pos"); int count = 0; myStruct[] _myStruct = new myStruct[rows.Length]; foreach (DataRow row in rows) { string[] g = ((string)(row["group_list"])).Split(','); //neu trong group list co chua group_id thi moi tra ve menu_id if (isContain(g, group_id)) { try { _myStruct[count] = new myStruct(); _myStruct[count].key = (string)row["menu_id"]; _myStruct[count].val = (string)row["menu_title"]; _myStruct[count].id = (int)row["pos"]; //_myStruct[count].name = (string)row["menu_name"]; count++; } catch { } //ht.Add((string)row["menu_id"],(string)row["menu_title"]); //int i=(int)row["pos"]; //ht.uu_tien.Add(i); } } return(_myStruct); }
void HopTapHop(ref myStruct[] ketqua, myStruct[] struct1, myStruct[] struct2) { if (struct1 != null) { myStruct[] _myStruct = new myStruct[struct1.Length + struct2.Length]; int count = 0; //lay cac phan tu tu tap hop A for (int i = 0; i < struct1.Length; i++) { if (struct1[i].key != null && struct1[i].val != null) { _myStruct[count] = struct1[i]; count++; } } for (int j = 0; j < struct2.Length; j++) { string key = struct2[j].key; string val = struct2[j].val; //neu key trong struct 2 khong chua trong struct1 if (!isContain(struct1, struct2[j].key)) { if (key != null && val != null) { _myStruct[count++] = struct2[j]; } } } //sort lai theo vi tri tren menu for (int i = 0; i < _myStruct.Length - 1; i++) { for (int j = i + 1; j < _myStruct.Length; j++) { if (_myStruct[i].val != null && _myStruct[i].key != null && _myStruct[j].val != null && _myStruct[j].key != null) { if (_myStruct[i].id > _myStruct[j].id) { myStruct temp = new myStruct(); temp = _myStruct[i]; _myStruct[i] = _myStruct[j]; _myStruct[j] = temp; } } } } ketqua = _myStruct; } else { ketqua = struct2; } }
myStruct[] hopTapHop(ref myHashtable ketqua, myHashtable h1, myHashtable h2) { IDictionaryEnumerator ide1 = h1.GetEnumerator(); IDictionaryEnumerator ide2 = h2.GetEnumerator(); //do khi tra ve getEnumerator se theo thu tu tu duoi len //nen cho i =h1.Count-1 int i = h1.Count - 1; int count = h1.Count + h2.Count - 1; myStruct[] _myStruct = new myStruct[count + 1]; while (ide1.MoveNext()) { //neu nhu key do chua co thi moi add vao // if(!ketqua.ContainsKey(ide1.Key)) // { _myStruct[count] = new myStruct(); _myStruct[count].key = (string)ide1.Key; _myStruct[count].val = (string)ide1.Value; _myStruct[count].id = (int)h1.uu_tien[i]; count--; // ketqua.Add(ide1.Key,ide1.Value); // //them vao do uu tien de sort menu // ketqua.uu_tien.Add(h1.uu_tien[i]); // } i--; } i = h2.Count - 1; while (ide2.MoveNext()) { //neu tap hop 1 khong chua 1 phan tu cua tap hop 2 thi add vao hop if (!h1.ContainsValue(ide2.Value)) { _myStruct[count] = new myStruct(); _myStruct[count].key = (string)ide2.Key; _myStruct[count].val = (string)ide2.Value; _myStruct[count].id = (int)h2.uu_tien[i]; count--; // ketqua.Add(ide2.Key,ide2.Value); // ketqua.uu_tien.Add(h2.uu_tien[i]); } i--; } //bay gio moi sort lai roi dua vao ketqua for (i = 0; i < _myStruct.Length - 1; i++) { for (int j = i + 1; j < _myStruct.Length; j++) { if (_myStruct[i].id > _myStruct[j].id && _myStruct[i].key != null) { myStruct temp = new myStruct(); temp = _myStruct[i]; _myStruct[i] = _myStruct[j]; _myStruct[j] = temp; } } } myHashtable myhash = new myHashtable(); //bat dau gan vao hashtable for (i = 0; i < _myStruct.Length; i++) { if (_myStruct[i].key != null && _myStruct[i].val != null) { myhash.Add(_myStruct[i].key, _myStruct[i].val); myhash.uu_tien.Add(_myStruct[i].id); } } ketqua = myhash; return(_myStruct); }