private void OpenChatForm() { if (nf != null) { nf.Close(); } string info = friendsTree.SelectedNode.Text; int startindex = info.IndexOf('('); int endindex = info.IndexOf(')'); string param = info.Substring(startindex + 1, endindex - startindex - 1); string result = HTTPUtil.SendGetRequest(Util.GetHttpUrl() + "/getuserbyaccount/" + param); User DestUser = User.GetUserByStr(result); if (Id_Chat.TryGetValue(DestUser.Id, out Chat chat)) { chat.Activate(); } else { Chat newchat = new Chat(); newchat.DestUser = DestUser; Id_Chat.TryAdd(DestUser.Id, newchat); newchat.Init(); Id_Messages.TryRemove(DestUser.Id, out List <MessageType> list); if (list != null) { newchat.InitChatText(list); } newchat.Show(); } }
public void Init() { Tuple <List <int>, List <DateTime>, List <int> > list = UserChatRecordManager.GetUserIdList(GlobalClass.CurrentUser.Id, Ids, contentTB.Text); if (list.Item1.Count > 0) { string ids = string.Join(",", list.Item1); string Users = HTTPUtil.SendGetRequest(Util.GetHttpUrl() + "/getUsersByUserid/" + ids); JArray usersArray = JArray.Parse(Users); userList = new List <User>(); for (int i = 0; i < usersArray.Count; i++) { User user = new User() { Id = int.Parse((string)usersArray[i]["id"]), Name = (string)usersArray[i]["name"], Account = (string)usersArray[i]["account"], Headimage = (string)usersArray[i]["headimage"] }; userList.Add(user); Image image = string.IsNullOrEmpty(user.Headimage) ? Properties.Resources.defalut : Util.GetImageByBase64Str(user.Headimage); imageList.Images.Add(i.ToString(), image); } for (int i = 0; i < userList.Count; i++) { ListViewItem lvi = new ListViewItem(); lvi.ImageIndex = i; //通过与imageList绑定,显示imageList中第i项图标 lvi.Text = userList[i].Name + "(" + userList[i].Account + ")"; lvi.SubItems.Add(list.Item2[i].ToString("yyyy-MM-dd HH:mm:ss")); lvi.SubItems.Add(list.Item3[i].ToString()); this.listView.Items.Add(lvi); } this.listView.Items[0].Selected = true; } }
public void Init(List <FriendsReq> list) { if (list.Count == 0) { tip.Visible = true; return; } int[] array = new int[list.Count]; for (int i = 0; i < list.Count; i++) { if (list[i].destid == GlobalClass.CurrentUser.Id) { array[i] = list[i].userid; } else { array[i] = list[i].destid; } } string str = string.Join(",", array); string usersStr = HTTPUtil.SendGetRequest(Util.GetHttpUrl() + "/getUsersByUserid/" + str); JArray usersArray = JArray.Parse(usersStr); for (int k = 0; k < list.Count; k++) { for (int i = 0; i < usersArray.Count; i++) { int id = int.Parse((string)usersArray[i]["id"]); if (array[k] == id) { User destUser = new User() { Id = id, Name = (string)usersArray[i]["name"], Account = (string)usersArray[i]["account"], Sex = char.Parse((string)usersArray[i]["sex"]), Birthday = DateTime.Parse((string)usersArray[i]["birthday"]), Headimage = (string)usersArray[i]["headimage"] }; FriendsReq fr = list[k]; fr.DestUser = destUser; GroupList g = new GroupList(); g.fr = fr; g.Init(); g.Dock = DockStyle.Top; this.Controls.Add(g); break; } } } }
private void loginBtn_Click(object sender, EventArgs e) { string accountStr = account.Text; string pwd = password.Text; if (string.IsNullOrEmpty(accountStr)) { MessageBox.Show("请输入账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(pwd)) { MessageBox.Show("请输入密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string url = Util.GetHttpUrl() + "/login/" + accountStr + "/" + pwd; string result = HTTPUtil.SendGetRequest(url); if (result != "登录失败!") { JObject userObj = JObject.Parse(result); int id = int.Parse(userObj["id"].ToString()); Message msg = new Message(id, 0, "", 0); this.Hide(); User user = User.GetUserByStr(result); GlobalClass.CurrentUser = user; GlobalClass.Groups = Util.GetGroups(user.Friends); MainForm mainForm = new MainForm(); mainForm.Init(); GlobalClass.mf = mainForm; mainForm.Show(); try { TCPUtil.socketSend.Send(msg.ToJsonBytes()); } catch (Exception) { MessageBox.Show("请检查网络!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } } else { MessageBox.Show(result, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void FRBtn_Click(object sender, EventArgs e) { if (nf != null) { nf.Close(); } Id_Messages.TryRemove(0, out List <MessageType> list); string frStr = HTTPUtil.SendGetRequest(Util.GetHttpUrl() + "/friendsreq/getall/" + GlobalClass.CurrentUser.Id); List <FriendsReq> frList = FriendsReq.GetListByStr(frStr); CheckFriendsReqForm fr = new CheckFriendsReqForm(); fr.Init(frList); fr.ShowDialog(); string result = HTTPUtil.SendGetRequest(Util.GetHttpUrl() + "/getfriendsbyid/" + user.Id); if (result != "获取失败!") { GlobalClass.CurrentUser.Friends = result; GlobalClass.Groups = Util.GetGroups(user.Friends); InitTree(); } }
public void InitTree() { if (string.IsNullOrEmpty(user.Friends)) { return; } friendsTree.Nodes.Clear(); Group_Users.Clear(); JArray array = JArray.Parse(user.Friends); for (int i = 0; i < array.Count; i++) { string groupname = (string)array[i]["name"]; friendsTree.Nodes.Add(groupname); string membersStr = (string)array[i]["members"]; List <User> list = new List <User>(); if (string.IsNullOrEmpty(membersStr)) { Group_Users.Add(groupname, list); continue; } string Users = HTTPUtil.SendGetRequest(Util.GetHttpUrl() + "/getUsersByUserid/" + membersStr); JArray usersArray = JArray.Parse(Users); for (int k = 0; k < usersArray.Count; k++) { User user = new User() { Id = int.Parse((string)usersArray[k]["id"]), Name = (string)usersArray[k]["name"], Account = (string)usersArray[k]["account"], Headimage = (string)usersArray[k]["headimage"] }; friendsTree.Nodes[i].Nodes.Add(user.Name + "(" + user.Account + ")"); list.Add(user); } Group_Users.Add(groupname, list); } }