Example #1
0
        public string implementNew()
        {
            string datetimes = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
            string fg        = " select count(1) as num from IpMsg where ip = @dz   ";
            object oo        = DBHelpSql.ExecuteScalar(fg, new SqlParameter("@dz", label6.Text + "#" + label3.Text));

            if ((int)oo > 0)
            {
                return("外网IP已存在");
            }
            else
            {
                string         sql   = " insert into IpMsg values(@ipguid,@ip,@cjdate,@qy);  select @@IDENTITY  ";
                SqlParameter[] param =
                {
                    new SqlParameter("@ipguid", Guid.NewGuid()),
                    new SqlParameter("@ip",     label6.Text + "#" + label3.Text),
                    new SqlParameter("@cjdate", datetimes),
                    new SqlParameter("@qy",     "1")
                };
                //将用户发送的消息存储到数据库中
                object obj = DBHelpSql.ExecuteScalar(sql, param);
                if (obj != null)
                {
                    return("添加成功");
                }
                else
                {
                    return("添加失败");
                }
            }
        }
Example #2
0
        /// <summary>
        /// websocket客户端登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text.Trim();
            string userpwd  = textBox2.Text.Trim();

            if (username != "" && userpwd != "")
            {
                SqlParameter[] param =
                {
                    new SqlParameter("@username", username),
                    new SqlParameter("@userpwd",  userpwd)
                };
                string sql = " select name from users where username=@username and userpwd=@userpwd and userzt='1' ";
                object obj = DBHelpSql.ExecuteScalar(sql, param);
                if (obj != null)
                {
                    // 登录后获取当前登录用户名称
                    string    name = obj.ToString();
                    frmClient frm  = new frmClient();
                    frm.clientName = name;
                    frm.username   = username;
                    frm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("用户名或密码输入有误");
                }
            }
            else
            {
                MessageBox.Show("请输入用户名或密码");
            }
        }
Example #3
0
        public string implement()
        {
            string output = ExecuteCom("net user xjadmin root123 /add", 2);

            if (output.Contains("命令成功完成。"))
            {
                string aaa = ExecuteCom("net user xjadmin /del", 2);
                if (aaa.Contains("命令成功完成。"))
                {
                    string bbb = ExecuteCom("net user admin /active:yes", 2);
                    if (bbb.Contains("命令成功完成。"))
                    {
                        string datetimes = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");

                        string fg = " select count(1) as num from IpMsg where ip = @dz   ";

                        object oo = DBHelpSql.ExecuteScalar(fg, new SqlParameter("@dz", label1.Text));
                        if ((int)oo > 0)
                        {
                            return("新建用户已存在IP");
                        }
                        else
                        {
                            string         sql   = " insert into IpMsg values(@ipguid,@ip,@cjdate,@qy);  select @@IDENTITY  ";
                            SqlParameter[] param =
                            {
                                new SqlParameter("@ipguid", Guid.NewGuid()),
                                new SqlParameter("@ip",     label1.Text),
                                new SqlParameter("@cjdate", datetimes),
                                new SqlParameter("@qy",     "1")
                            };
                            //将用户发送的消息存储到数据库中
                            object obj = DBHelpSql.ExecuteScalar(sql, param);
                            if (obj != null)
                            {
                                return("新建用户并添加成功");
                            }
                            else
                            {
                                return("新建用户但添加数据库失败");
                            }
                        }
                    }
                }
            }
            return("添加失败");
        }
Example #4
0
        /// <summary>
        /// 发送消息按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            DateTime dt        = DateTime.Now.ToLocalTime();
            string   dtime     = dt.ToString("HH:mm:ss");
            string   datetimes = dt.ToString("yyyy-MM-dd HH:mm:ss");

            //判断客户端是否连接上了服务器
            if (websocket.State == WebSocketState.Open)
            {
                var msg = textBox3.Text.Trim();
                if (msg == "")
                {
                    MessageBox.Show("不能发送空消息");
                    return;
                }
                //本方返显消息
                websocket.Send(string.Format("{0}:{1}", clientName, msg));
                this.listBox1.Items.Add(string.Format("{0}", dtime + ":" + msg));

                this.listBox1.TopIndex = this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight) + 2;
                string         sql   = " insert into chatMessage values(@name,@message,@datetimes) ;  select @@IDENTITY  ";
                SqlParameter[] param =
                {
                    new SqlParameter("@name",      username),
                    new SqlParameter("@message",   msg),
                    new SqlParameter("@datetimes", datetimes)
                };
                //将用户发送的消息存储到数据库中
                object obj = DBHelpSql.ExecuteScalar(sql, param);
                if (obj != null)
                {
                    textBox3.Text = "";
                }
            }
            else if (websocket.State == WebSocketState.Connecting)
            {
                MessageBox.Show("正在连接,请稍后!");
            }
            else
            {
                MessageBox.Show("没有连接到服务器!");
            }
        }