/// <summary> /// 从服务器获取所有群组的基本信息,并更新本地数据库 /// </summary> /// <returns></returns> public SimpleGroupsModel2[] getAllGroups() { //1.从服务器获取所有群组的基本信息,“owner”、“groupid”、“affiliations”、“groupname” HXService hxService = new HXService(); string strJson = hxService.GetAllGroups(); //2.更新本地数据库 if (!string.IsNullOrEmpty(strJson)) { //解析json字符串 //List<SimpleGroupsModel1> groupList = fastJSON.JSON.ToObject<List<SimpleGroupsModel1>>(strJson); SimpleGroupsModel1 simpleGroupsModel = fastJSON.JSON.ToObject<SimpleGroupsModel1>(strJson); //foreach (SimpleGroupsModel2 model in simpleGroupsModel.data) //{ // string groupId = model.groupid; // string groupName = model.groupname; // //string groupOwner = model.owner;//这个一般不会被修改的 // int currentUsers = model.affiliations; // string strSql = "UPDATE [dbo].[Tb_Group] SET [groupName] = '" + groupName + "',currentUsers=" + currentUsers + " WHERE [groupId] = '" + groupId + "'"; // sqlHelper.RunSQL(strSql); //} return simpleGroupsModel.data; } return null; }
public string getGroupTree() { HXService hxService = new HXService(); string strJson = hxService.GetAllGroups(); SimpleGroupsModel1 group = fastJSON.JSON.ToObject<SimpleGroupsModel1>(strJson); //反序列化 SimpleGroupsModel2[] groups = group.data; StringBuilder builder = new StringBuilder(); builder.Append("["); foreach (SimpleGroupsModel2 g in groups) { builder.Append("{\"groupid\":\"" + g.groupid + "\","); builder.Append("\"icon\":\"../../Content/Themes/Images/16/users.png\","); builder.Append("\"leaf\":true,"); builder.Append("\"groupname\":\"" + g.groupname + "\"},"); } builder.Remove(builder.Length - 1, 1); builder.Append("]"); return builder.ToString(); }