public Card(Friendlist friendlist) { this.friendlist = friendlist; InitializeComponent(); string connString = "Server=cdb-9lgx1peo.bj.tencentcdb.com;Database=SDChatRoom;uid=root;pwd=rjgzjc666;port=10096;Charset=utf8"; MySqlConnection connection1 = new MySqlConnection(connString); string sqlstr = "SELECT * FROM users WHERE U_Login=\"" + MainWindow.ID + "\";"; MySqlCommand Mycommand = new MySqlCommand(sqlstr, connection1); connection1.Open(); MySqlDataReader MyReader = Mycommand.ExecuteReader(); while (MyReader.Read()) { thetouxiang.Source = new BitmapImage(new Uri("pack://application:,,,/Images/head" + MyReader["P_ID"] + ".jpg")); zhanghaoshow.Text = MyReader["U_Login"].ToString(); nicknameshow.Text = MyReader["Nickname"].ToString(); sexresult.Text = MyReader["Sex"].ToString(); phoneshow.Text = MyReader["Telephone"].ToString(); emailshow.Text = MyReader["Email"].ToString(); occupationshow.Text = MyReader["Occupation"].ToString(); kongjianshow.Text = nicknameshow.Text + "的空间"; //you may ask why not "sexshow",because it is used! } MyReader.Close(); connection1.Close(); }
private void initLogin() { string strRecvMsg = recvMsg(); //theAccount.Content = "接受成功!"; string[] strArray = strRecvMsg.Split('|'); switch (strArray[0]) { case "login": if (strArray[1].Equals("succeed")) //登录成功! { Friendlist friendlist = new Friendlist(clientSocket, txtName.Text); //string user = userTXB.Text; //启动客户端与服务器的连接服务 new ClientService(clientSocket, friendlist.Chat); //将此socket传给chat string strSendMsg = "Init|online"; sendMsg(strSendMsg); MessageBox.Show("登录成功!"); friendlist.Show(); friendlist.Myname.Text = txtName.Text; this.Close(); } break; case "warning": string warningMsg = this.recvMsg(); MessageBox.Show(warningMsg.Split('|')[1]); clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); clientSocket = null; MessageBox.Show("登录失败!用户名或密码错误"); break; } }
public CardEdit(Friendlist friendlist, Card card1) { InitializeComponent(); //touxiang.Source = new BitmapImage(new Uri("pack://application:,,,/Images/head" + MyReader["P_ID"] + ".jpg")); string connString = "Server=cdb-9lgx1peo.bj.tencentcdb.com;Database=SDChatRoom;uid=root;pwd=rjgzjc666;port=10096;Charset=utf8"; MySqlConnection connection1 = new MySqlConnection(connString); string sqlstr = "SELECT * FROM users WHERE U_Login=\"" + MainWindow.ID + "\";"; MySqlCommand Mycommand = new MySqlCommand(sqlstr, connection1); connection1.Open(); MySqlDataReader MyReader = Mycommand.ExecuteReader(); while (MyReader.Read()) { nicknamein.Text = MyReader["NickName"].ToString(); phonein.Text = MyReader["Telephone"].ToString(); emailin.Text = MyReader["Email"].ToString(); occupationin.Text = MyReader["Occupation"].ToString(); addressin.Text = MyReader["Address"].ToString(); touxiang.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/head" + MyReader["P_ID"] + ".jpg")) }; } MyReader.Close(); connection1.Close(); this.friendlist = friendlist; this.card1 = card1; zhanghaoshowinedit.Text = MainWindow.ID; }
public ClientService(Socket socket, Friendlist friendlist) { this.socket = socket; this.friendlist = friendlist; talkThread = new Thread(watchMsg); talkThread.IsBackground = true; talkThread.Start(); }
public FriendlistViewModel(Friendlist frdlst, string user) { //friends = new ObservableCollection<Friend>(); //friends.Add(new Friend() { Nickname = "Mark", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head1.jpg")) }); //friends.Add(new Friend() { Nickname = "Mary", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head2.jpg")) }); //friends.Add(new Friend() { Nickname = "静香", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head3.jpg")) }); //friends.Add(new Friend() { Nickname = "小夫", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head4.jpg")) }); //friends.Add(new Friend() { Nickname = "饼藏", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head5.jpg")) }); //friends.Add(new Friend() { Nickname = "玉子", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head6.jpg")) }); //friends = new ObservableCollection<Friend>(); //friends.Add(new Friend() { Nickname = "albery", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head1.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FF1C93EC") }); //friends.Add(new Friend() { Nickname = "wangwu", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head2.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FFFFFFFF") }); //friends.Add(new Friend() { Nickname = "静香", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head3.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FFFFFFFF") }); //friends.Add(new Friend() { Nickname = "wangwu2", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head4.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FF1C93EC") }); //friends.Add(new Friend() { Nickname = "饼藏", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head5.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FF1C93EC") }); ////friends.Add(new Friend() { Nickname = "玉子", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head6.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FF1C93EC") }); //friends.Add(new Friend() { Nickname = "All", Head = new BitmapImage(new Uri("pack://application:,,,/Images/head6.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FF1C93EC") }); friendlist = frdlst; usr = user; string connString = "Server=cdb-9lgx1peo.bj.tencentcdb.com;Database=SDChatRoom;uid=root;pwd=rjgzjc666;port=10096;Charset=utf8"; MySqlConnection connection1 = new MySqlConnection(connString); string sqlstr = "SELECT * FROM users ;"; MySqlCommand Mycommand = new MySqlCommand(sqlstr, connection1); connection1.Open(); MySqlDataReader MyReader = Mycommand.ExecuteReader(); friends = new ObservableCollection <Friend>(); friends.Add(new Friend() { Nickname = "All", Head = new BitmapImage(new Uri("pack://application:,,,/Images/headqun.jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FF1C93EC") }); while (MyReader.Read()) { friends.Add(new Friend() { Nickname = MyReader["NickName"].ToString(), Head = new BitmapImage(new Uri("pack://application:,,,/Images/head" + MyReader["P_ID"] + ".jpg")), BackGroundColor = ColorTranslater.ColorFromHex("#FF1C93EC") }); } MyReader.Close(); connection1.Close(); Console.Read(); CloseCommand = new DelegateCommand(() => { //friendlist.Quit(); Application.Current.Shutdown(); }); MouseRightButtonDownCommand = new DelegateCommand <object>((p) => { //MessageBox.Show("MouseRightButtonDownCommand"); ListView lv = p as ListView; Friend friend = lv.SelectedItem as Friend; Head = friend.Head; Nickname = friend.Nickname; Chat chat = friendlist.Chat; friendlist.BindChatSocket(chat); chat.Show(); }); }