private void btnLogin_Click(object sender, EventArgs e) { mysqlDB = new MysqlDB(); //FrmChat frmChat = new FrmChat("调试"); //frmChat.Show(); //sql语句(谨慎使用drop,delete!!!) string sql = "SELECT name,pwd FROM qqUser"; if (TxtUser.Text.Equals("")) { MessageBox.Show("用户名不能为空"); } else { var reader = mysqlDB.Get(sql); Dictionary <string, string> qqDict = new Dictionary <string, string>();//qq用户密码字典 if (reader != null) { while (reader.Read()) { string name = reader.GetString("name"); string pwd = reader.GetString("pwd"); qqDict.Add(name, pwd); } if (TxtPas.Text.Equals("")) { MessageBox.Show("密码不能为空"); } else { loginName = TxtUser.Text; User.Name = TxtUser.Text;//将登陆名的text创给类的静态字段 if (qqDict.ContainsKey(loginName)) { if (TxtPas.Text.Equals(qqDict[TxtUser.Text])) { //MessageBox.Show("密码正确"); FrmMain frmMain = new FrmMain(); frmMain.Show(); this.Hide(); } else { MessageBox.Show("密码错误"); } } else { MessageBox.Show("无此用户名"); } } } else { MessageBox.Show("出现网络连接问题"); } } }
private void FrmAddUser_Load(object sender, EventArgs e) { //初始化 mysqlDB = new MysqlDB(); string sql = "select * from qquser where name!='" + FrmLogin.loginName + "'"; var reader = mysqlDB.Get(sql); while (reader.Read()) { UserList userList = new UserList(); userList.UserName = reader.GetString("name"); //用户名 userList.UserEmail = reader.GetString("email"); //邮箱 flowLayoutPanel1.Controls.Add(userList); } }
private void FrmMain_Load(object sender, EventArgs e) { //初始化全局变量 mysqlDB = new MysqlDB(); dicChatLists = new Dictionary <string, MessageList>(); dicChats = new Dictionary <string, List <OneWord> >(); frmChats = new Dictionary <string, FrmChat>(); labName.Text = User.Name;//从类的静态字段中取值 //从服务器拉取所有与本用户相关的聊天记录,存储到聊天记录字典 //sql语句(谨慎使用drop,delete!!!) string sql = "SELECT * FROM qqchatView WHERE rname='" + loginName + "' OR sname='" + loginName + "' ORDER BY time ASC"; //接口sql=SELECT * FROM qqchatView WHERE rname='yiki' OR sname='yiki' ORDER BY time ASC res = mysqlDB.Get(sql); while (res.Read()) { string _sender = res.GetString("sname");; //发送者 string _receiver = res.GetString("rname"); //接收者 DateTime _time = res.GetDateTime("time"); //发送时间 //_time = _time.AddHours(-8); //加时间(时区转换) string _text = res.GetString("text"); //发送内容 string _friend; //该条记录的好友昵称 OneWord word = new OneWord(); word.Time = _time; word.Text = _text; if (_sender.Equals(loginName)) { word.Sender = true; _friend = _receiver; } else { word.Sender = false; _friend = _sender; } if (DicChats.ContainsKey(_friend)) { DicChats[_friend].Add(word);//该好友目录下增加一条聊天记录 } else {//增加一条好友目录 List <OneWord> words = new List <OneWord>(); words.Add(word); DicChats.Add(_friend, words); } } //将最新一条聊天记录显示到聊天记录列表控件中 //反向遍历数组 for (int i = DicChats.Count() - 1; i >= 0; i--) { var data = DicChats.ToArray()[i]; MessageList messageList = new MessageList(); messageList.ContactsName = data.Key.ToString(); messageList.LastMsg = data.Value.Last().Text; messageList.LastMsgSendTime = data.Value.Last().Time.TimeOfDay.ToString(); flowLayoutPanelMessage.Controls.Add(messageList); dicChatLists.Add(messageList.ContactsName, messageList); } //创建TCP套接字,发起连接请求 try { tcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ipaddress = IPAddress.Parse(serverAdress); EndPoint point = new IPEndPoint(ipaddress, serverPoint); tcpClient.Connect(point); //通过IP和端口号,定位一个要连接到的服务端 //向服务端发送初始化消息以表明自己身份 DataPack dataPack = new DataPack(loginName, "server", "server", "server"); tcpClient.Send(FrmChat.DataPackToBytes(dataPack)); //创建线程,一直接收服务端发来的数据 ThreadStart _receiveThread = new ThreadStart(receiveThread); Thread _childThread = new Thread(_receiveThread); _childThread.Start(); } catch (Exception) { MessageBox.Show("服务器无响应,请稍后再试"); System.Environment.Exit(0); } }
private void FrmChat_Load(object sender, EventArgs e) { mysqlDB = new MysqlDB(); }
private void FrmSign_Load(object sender, EventArgs e) { jsonServer = new JsonServer(); mysqlDB = new MysqlDB(); }