• 基于C#实现的在线聊天室的桌面系统软件


    资源下载地址:https://download.csdn.net/download/sheziqiong/86863237
    资源下载地址:https://download.csdn.net/download/sheziqiong/86863237
    目录
    个人聊天室软件 1
    需求分析与概要设计 1

    1. 项目说明 1
      1.1. 项目目标: 1
      1.2. 软硬件环境需求 1
      1.3. 使用的关键技术: 1
    2. 需求分析 2
      2.1. 系统用例 2
      2.2. 业务流程 3
    3. 概要设计 3
      3.1. 功能模块设计 3
      3.2. 核心类图 5
    4. 界面设计 5
      1.项目说明
      1.1.项目目标:
      本项目目标完成一个可以实现多个不同主题的在线聊天室的桌面应用,用户可以在不同的聊天室中交流不同的话题。用户在登录后可以选择聊天室、查看聊天室人数以及选择用户私聊等。
      1.2.软硬件环境需求
      软件是基于.net framework 4.7.2开发,数据库为Mysql8.0.24
      1.3.使用的关键技术:
      软件基于Socket编程,C/S架构风格开发。客户端通过发送指令得到服务器的返回信息。
      2.需求分析
      2.1.系统用例
      在这里插入图片描述

    图 1 系统用例图
    (1)登录
    参与者:普通用户、管理员
    基本事件流:用户或者管理员在登录的时候先选择登录身份。输入账号和密码后核验其账户是否存在以及密码是否匹配,若匹配则用户登录进入用户主界面,管理员登录进入管理主界面,否则提示用户不存在或者密码错误。
    (2) 创建聊天室
    参与者:普通用户、管理员
    基本事件流:用户和管理员在创建聊天室的时候需要标明此聊天室的主题以便于有不同兴趣爱好的用户进行交流。
    (3) 选择聊天室聊天
    参与者:普通用户
    基本事件流:用户登录后进入主界面可以浏览各个聊天室的主题以及在线人数,然后根据用户个人的兴趣爱好选择进入聊天室。本文转载自http://www.biyezuopin.vip/onews.asp?id=16975进入聊天室用户可以在公共聊天室发消息也可以选择用户私聊。
    (4) 禁言
    参与者:管理员
    基本事件流:管理员对个别发表引战、谩骂攻击、违法等言论的用户实施禁言以管理应用,具体禁言时间根据具体情况而定。
    (2) 删除聊天室
    参与者:管理员
    基本事件流:部分公共聊天室的主题可能存在违法乱纪的行为以及可能存在聊天室成员公开讨论违禁话题,需要管理员对此类聊天室进行查封删除。

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Threading;
    using System.Windows.Forms;
    
    namespace ChatWork.Forms
    {
        public partial class Chat : Form
        {
            private readonly int id;//房间Id
            private string MsgHis = null;
            private bool IsPrivate = false;
            private string PrivateRemote = null;//私聊对象的IP
            Thread thread;
            public Chat(string Id,string theme,string content)
            {
                id = Int32.Parse(Id);
                InitializeComponent();
                Tiltle.Text = "关于 "+theme + " 的聊天";
                ChatInfo_Box.Text += "\n简介:\n"+content;
                this.Member_List.Columns.Add("IP", 180, HorizontalAlignment.Left);
                this.Member_List.Columns.Add("账户", 68, HorizontalAlignment.Left);
            }
            private void Chat_Load(object sender, EventArgs e)
            {
                //加载历史信息
                List<Message> msgs = Program.clientService.GetMsg(id);
                foreach(var m in msgs)
                {
                    MsgHis += m.SendTime + "\n" + m.Sender + "说:" + m.Content + "\n";
                }
                Msg_Box.Text = MsgHis;
                Msg_Box.SelectionStart = Msg_Box.TextLength;
                Member_List.Items.Clear();
                //加载在线用户
                List<KeyValuePair<string, string>> users = Program.clientService.GetUser(id);
                Member_List.BeginUpdate();
                foreach (var user in users)
                {
                    ListViewItem i = new ListViewItem();
                    i.Text = user.Key;
                    i.SubItems.Add(user.Value);
                    Member_List.Items.Add(i);
                }
                Member_List.EndUpdate();
                //信息滑到最底部
                Msg_Box.ScrollToCaret();
                CheckForIllegalCrossThreadCalls = false;
                //开启更新信息的线程
                thread = new Thread(RefreshMsg);
                thread.IsBackground = true;
                thread.Start();
            }
            private void RefreshMsg()//更新信息
            {
                while (true)
                {
                    Msg_Box.Text = MsgHis + Program.clientService.Msg;
                }
            }
            private async void Send_button_Click(object sender, EventArgs e)
            {
                string Msg = MsgSend_Box.Text.Trim();
                MsgSend_Box.Text = null;
                //消息类型判断
                if (Msg == "") MessageBox.Show("发送信息不能为空");
                else if (Msg.StartsWith("文件"))//发送文件
                {
                    string[] ss = Msg.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    var re= await Program.clientService.SendFile(ss[1]);
                    if(!re)
                    MessageBox.Show("发送失败");
                }
                else//发送正常消息
                {
                    if (!IsPrivate)//公聊
                    {
                        if (!Program.clientService.SendMsg(Msg, id.ToString()))
                        {
                            MessageBox.Show("您已被禁言");
                            return;
                        }
                    }
                    else Program.clientService.SendMsg(Msg, PrivateRemote);       
                }
            }
            private async void Leave_button_Click(object sender, EventArgs e)
            {
                var re=await Program.clientService.LeaveChatRoom(id);
                if (re)
                {
                    thread.Abort();
                    this.Hide();
                    MainForm mainForm = new MainForm();
                    mainForm.Show();
                }
                else MessageBox.Show("请稍等");
            }
            private void File_Button_Click(object sender, EventArgs e)
            {
                string file=string.Empty;
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Multiselect = false;
                dialog.Title = "请选择文件夹";
                dialog.Filter = "所有文件(*.*)|*.*";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    file = dialog.FileName;
                }
                if (!string.IsNullOrEmpty(file))
                {
                    MsgSend_Box.Text = "文件:\n"+file;
                }
            }
            private void Member_List_SelectedIndexChanged(object sender, EventArgs e)
            {
                if(Member_List.SelectedItems.Count!=0)
                {
                    if (!IsPrivate)
                    {
                        DialogResult result =
                       MessageBox.Show("是否和该用户私聊?", "私聊确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            IsPrivate = true;
                        }
                        else IsPrivate = false;
                    }
                    else
                    {
                        DialogResult result =
                       MessageBox.Show("是否和该用户取消私聊?", "取消私聊", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            IsPrivate = false;
                        }
                        else IsPrivate = true;
                    }
                    PrivateRemote = Member_List.SelectedItems[0].Text;
                }
            }
            //点击文件超链接
            private void Msg_Box_LinkClicked(object sender, LinkClickedEventArgs e)
            {
                string path = string.Empty;
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    path = fbd.SelectedPath;
                }
                Program.clientService.RecvPath = path;
                string s = e.LinkText;
                Program.clientService.RequestFile(s.Substring(0,s.LastIndexOf('/'))+"D:/test/"
                    +s.Substring(s.LastIndexOf('/')+1));
            }
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    资源下载地址:https://download.csdn.net/download/sheziqiong/86863237
    资源下载地址:https://download.csdn.net/download/sheziqiong/86863237

  • 相关阅读:
    Android组件通信——ActivityGroup(二十五)
    操作系统实验二 进程管理
    hr竟主动给这位测试小姐姐涨工资,她是怎么做到的?
    深度学习 FairMOT多目标跟踪(PANDA)
    java面试应聘时的满分回答参考模板
    【工具】idea 设置自动渲染注释
    ubuntu bind9 主从配置
    突破性技术!开源多模态模型—MiniGPT-5
    【零基础学Java】第二十二篇 集合2(Set,Map,Collections工具类)
    驱动开发day4
  • 原文地址:https://blog.csdn.net/newlw/article/details/127583517