Socket Realization QQ Chat (can be deployed in wide area network) with source code (4)-Join the database system Setup completed

Source: Internet
Author: User

1. Preface

This is the fourth article in this series, the previous article we talked about the client to the client's chattering screen and send and receive various types of files, this article we join SQL Server database to achieve login and friends add functions, and the interface has been beautified. As usual I will deploy the chat server to the WAN server, then you can open the source inside the client to chat with me! (This is just a starter version of the feature is simply not supported offline messages, so the premise of chatting is I am online (user ID is 19931221, that's me.) )...... ), you can also open two client tests, the deployment documentation of the program is placed in the root directory of my source code.

2. This article realizes the function

0. Simple database design.

1. Service-side management optimization and interface beautification.

2. Client login, register, retrieve password.

3. The client's welcome interface is built.

4. The client's chat interface is built (CORE).

5. Client's personal information floating display.

6. Add a friend to the client.

7. The client's avatar is modified.

8. Personal details operation.

9. Accurate search for friends.

3. Concrete implementation

(0) Simple database design.

Database tables are divided into user tables, as well as several other detail tables, as well as friends tables. The structure is as follows

Based on this, a three-tier architecture is built. To realize the data deletion and modification.

(1) service-side management optimization and interface beautification.

On the basis of the original added, data management, data submission function. To implement the management of the client (general database operations, there is no code here, interested in the following source).

(2) Client login, registration, retrieve password.

A. Login-Verify the user name, password, and verification code. Here is a code to write using GDI + (can be collected, Web, WinForm Universal), click PictureBox to verify the image switch. The code is as follows:

1 Private voidPicturebox3_click (Objectsender, EventArgs e)2      {3Random x =NewRandom ();4s=NULL;5           for(inti =0; I <5; i++)6          {7              intnum = X.next (0,Ten);8s + =num;9          }Ten          //MessageBox.Show (s); OneBitmap Bmap =NewBitmap ( the, -); AGraphics g =graphics.fromimage (BMAP); -           for(inti =0; I <5; i++) -          { thePoint P =NewPoint (I * -,0); -              string[] fonts = {"Microsoft Ya-Black","Song Body","blackbody","Official Script","Imitation" }; -color[] Colors ={color.black, Color.Blue, Color.Red, Color.green, color.orange}; -g.DrawString (S[i]. ToString (),NewFont (Fonts[x.next (0,5)], -, FontStyle.Bold),NewSolidBrush (Colors[x.next (0,5) ], p); +  -          } +           for(inti =0; I <Ten; i++) A          { atPen pen =NewPen (brushes.gray); -Point P2 =NewPoint (X.next (0, Bmap. Width), X.next (0, Bmap. Height)); -Point P3 =NewPoint (X.next (0, Bmap. Width), X.next (0, Bmap. Height)); - G.drawline (pen, p2, p3); -          } -           for(inti =0; I < $; i++) in          { -Point P1 =NewPoint (X.next (0, Bmap. Width), X.next (0, Bmap. Height)); to Bmap. SetPixel (P1. X, p1. Y, Color.green); +          } -Picturebox3.image =Bmap; the}
View Code

Effect:


B. Registration, note: The inside to fill the card ID, is when I did when the student's card as the user's primary key ID, test when you can fill in a random.

C. Recover Password:

(3) The client's welcome interface is built.

(4) The client's chat interface is built (CORE).

Realize the normal chat with friends, send chatter screen, sending and receiving files, (if the current received message is not the current chat form will appear in the main interface chat alert three,).

Note The Friends online list 45 seconds to refresh, the graph interface will appear slightly lag. The Friend list will be refreshed after 45 seconds of testing.

The core principle of chat has been explained in the third chapter, here mainly to do some of the interface beautification. The effect is as follows:

(5) The client's personal information floating display.

The implementation principle is based on the size and position of the current main form, to determine whether the floating display is now left or right. Then add the Mouseenter,mouseleave event, the code is as follows

1 Private voidPicturebox1_mouseenter (Objectsender, EventArgs e)2     {3         intUsertop = Top + -;4         intUserleft = left- -;5         //screen does not include the height of the taskbar6         intPH = Screen.getworkingarea ( This). Height;7         //determine if the screen height is exceeded8         if(Usertop +181>PH)9         {TenUsertop = PH-181-5; One         } A         //Determine if the screen is smaller than the left -         if(Userleft <0) -         { theUserleft = right +5; -         } -         //form is not a null pass value -         if(Myhead! =NULL) +         { -             if(myhead.isdisposed) +             { AMyhead =NewMyhead (); atMyhead.nowuser =Nowuser; - myhead.show (); -             } -             Else -             { -Myhead.location =NewPoint (Userleft, usertop); inMyhead.nowuser =Nowuser; - myhead.show (); to             } +           -         } the         Else //form is empty new one *         { $Myhead =NewMyhead ();Panax NotoginsengMyhead.nowuser =Nowuser; - myhead.show (); the         } +     } A  the Private voidPicturebox1_mouseleave (Objectsender, EventArgs e) +        { -Thread.Sleep ( -); $            if(Myhead! =NULL&&!myHead.Bounds.Contains (cursor.position)) $            { - myhead.hide (); -            } the}
View Code

(6) Add friends to the client.

Add friends by entering ID, or go to detailed search

(7) The user picture of the client is modified.

Show your avatar through a ListView control and update your avatar

(8) Personal detailed information operation.

A. Personal data

B. Security settings

(9) Accurate search for friends.

(4) Summary

This time we implemented the addition of SQL Server database login and friends added and other functions, and the interface has been beautified. Up to now a basic chat software is basically built and finished. This article has a lot of, the amount of code is not much, if the specific implementation of interest can be the next source to see. Finally you can open the source code of the client, register an account, find the user ID 19931221 is me, can chat with me, I will deploy the server to the WAN. or open two clients themselves chat (do not need to run the service side, the default is my server IP, theoretically have a network can chat), quickly try it!!! (There is a configuration document in the root directory must see OH)

This series to the current basic has been completed, follow-up friends have what functional requirements can give me a message, I add. This is only a small example (in my C # course design work on the basis of a perfect), I hope you have a lot of advice.

Cond..................... , looking forward to your attention

MyChatV2.0 Source Address: http://pan.baidu.com/s/1eRENjDg

Socket Realization QQ Chat (can be deployed in wide area network) with source code (4)-Join the database system Setup completed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.