Example #1
0
 string check; //当前选中项
 //构造函数
 public setUI(Font f, chat c)
 {
     InitializeComponent();
     this.f = f;
     this.c = c;
 }
Example #2
0
 public static void setChat(chat s)
 {
     myChat = s;
 }
Example #3
0
        //==========按钮点击事件==========
        //注册、登录或修改按钮
        private void Bt_login_Click(object sender, EventArgs e)
        {
            //修改服务器信息,并调用函数重新连接服务器
            if (Bt_login.Text == "修改")
            {
                dataProcessing.address(textBox1.Text.Trim(), int.Parse(textBox2.Text.Trim()));
                label7.Text = "正在重新连接服务器......";
                isConnect   = false;
                dataProcessing.beginWork("login");
                La_return_Click(sender, e);
                MessageBox.Show("修改成功,请登录");
                return;
            }
            //判断是否连接上服务器,如果没有,则取消后面操作
            if (!isConnect)
            {
                MessageBox.Show("未连接到服务器,无法进行操作");
                return;
            }
            //用户名及密码不能为空
            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
            {
                label8.Text = "请输入用户名及密码!";
                return;
            }
            //用户名及密码不能包含“$”,方便解析数据时的操作
            if (textBox1.Text.Contains('$') || textBox1.Text.Contains('$'))
            {
                MessageBox.Show("用户名或密码不能包含'$'");
                return;
            }
            //data[0]:用户名  data[1]:已加密的密码
            List <string> data = new List <string>();

            data.Add(textBox1.Text);                                  //用户名
            //==============调用系统自带MD5函数进行加密====================
            byte[] result = Encoding.Default.GetBytes(textBox2.Text); //textBox2为输入的密码
            MD5    md5    = new MD5CryptoServiceProvider();

            byte[] output = md5.ComputeHash(result);
            data.Add(BitConverter.ToString(output).Replace("-", ""));//输出加密文本赋给data[1]

            //登录账号时发送的消息
            if (!dataProcessing.sendData(0, data))//登录情况
            {
                MessageBox.Show("发送数据时出现错误,发送失败.");
                return;
            }
            //==========接收服务器反馈信息==========
            string[] receiveData = dataProcessing.receiveData();
            if (receiveData == null)
            {
                MessageBox.Show("接收数据时出现错误.");
                return;
            }
            //登录时接收到的代码
            if (receiveData[1] == "WRONGPASSWORD")
            {
                MessageBox.Show("账号或密码错误,请重新输入");
                dataProcessing.beginWork("login");
                return;
            }
            else if (receiveData[1] == "NAMEONLINE")
            {
                MessageBox.Show("该账号已登录,登录失败");
                return;
            }
            //登录成功
            else if (receiveData[1] == "SUCCESS")
            {
                dataProcessing.loginName = textBox1.Text.Trim();//设置登录的用户名字
                this.Visible             = false;
                try
                {
                    GlobalUtil.SetMaxLengthOfUserID(50);
                    this.multimediaManager.Initialize(textBox1.Text, textBox2.Text, ConfigurationManager.AppSettings["OMCSServerIP"], int.Parse(ConfigurationManager.AppSettings["OMCSServerPort"]));
                }
                catch (Exception ee)
                {
                    MessageBox.Show("初始化多媒体设备管理器失败!" + ee.Message);
                    return;
                }
                beginChat = new chat(textBox1.Text.Trim());
                beginChat.Initialize(multimediaManager);
                beginChat.Visible = true;
            }
        }
Example #4
0
File: login.cs Project: one966/chat
        //==========按钮点击事件==========
        //注册、登录或修改按钮
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            //修改服务器信息,并调用函数重新连接服务器
            if (label3.Text == "修改")
            {
                dataProcessing.address(textBox1.Text.Trim(), int.Parse(textBox2.Text.Trim()));
                label7.Text = "正在重新连接服务器......";
                isConnect   = false;
                dataProcessing.beginWork("login");
                label5_Click(sender, e);
                MessageBox.Show("修改成功,请登录");
                return;
            }
            //判断是否连接上服务器,如果没有,则取消后面操作
            if (!isConnect)
            {
                MessageBox.Show("未连接到服务器,无法进行操作");
                return;
            }
            //用户名及密码不能为空
            if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
            {
                label8.Text = "请输入用户名及密码!";
                return;
            }
            //用户名及密码不能包含“$”,方便解析数据时的操作
            if (textBox1.Text.Contains('$') || textBox1.Text.Contains('$'))
            {
                MessageBox.Show("用户名或密码不能包含'$'");
                return;
            }
            //data[0]:用户名  data[1]:已加密的密码
            string[] data = new string[2];
            data[0] = textBox1.Text;                                  //用户名
            //==============调用系统自带MD5函数进行加密====================
            byte[] result = Encoding.Default.GetBytes(textBox2.Text); //textBox2为输入的密码
            MD5    md5    = new MD5CryptoServiceProvider();

            byte[] output = md5.ComputeHash(result);
            data[1] = BitConverter.ToString(output).Replace("-", ""); //输出加密文本赋给data[1]
            //注册账号时发送的消息
            if (label3.Text == "注册")                                  //注册情况
            {
                if (!dataProcessing.sendData(4, data))
                {
                    MessageBox.Show("发送数据时出现错误,发送失败.");
                    return;
                }
            }
            //登录账号时发送的消息
            else if (!dataProcessing.sendData(0, data))//登录情况
            {
                MessageBox.Show("发送数据时出现错误,发送失败.");
                return;
            }
            //==========接收服务器反馈信息==========
            string[] receiveData = dataProcessing.receiveData();
            if (receiveData == null)
            {
                MessageBox.Show("接收数据时出现错误.");
                return;
            }
            //登录时接收到的代码
            if (receiveData[1] == "NOTEXISTNAME")
            {
                MessageBox.Show("不存在该用户名,请先注册");
                dataProcessing.beginWork("login");
                return;
            }
            else if (receiveData[1] == "WRONGPASSWORD")
            {
                MessageBox.Show("密码错误,请重新输入");
                dataProcessing.beginWork("login");
                return;
            }
            else if (receiveData[1] == "NAMEONLINE")
            {
                MessageBox.Show("该账号已登录,登录失败");
                return;
            }
            //登录成功
            else if (receiveData[1] == "SUCCESS")
            {
                this.Visible      = false;
                beginChat         = new chat(textBox1.Text.Trim());
                beginChat.Visible = true;
            }
            //注册时接收到的消息
            else if (receiveData[1] == "SAMENAME")
            {
                MessageBox.Show("该账号已存在,请输入其他账号进行注册");
                dataProcessing.beginWork("login");
                return;
            }
            else if (receiveData[1] == "REGISTERSUCCESS")
            {
                MessageBox.Show("账号注册成功,请登录");
                label3.Text     = "Login";
                label6.Text     = "注册";
                label5.Visible  = true;
                label3.Location = new Point(pictureBox2.Width / 2 - label3.Width / 2, pictureBox2.Height / 2 - label3.Height / 2);
                dataProcessing.beginWork("login");
                return;
            }
        }