Original tutorial folder for VC ++/mfc Window Programming
C ++ course design. However, if you have not learned the data or understood the layer-3 architecture, you can simply deepen this job. Although the personnel management system seems simple, it is nothing more than processing employee information. But that's the case. You only know what reality is.
At the beginning, I didn't want to use a three-tier architecture. If our team members have different abilities, they can only start from the console (black form. Later, when I wanted to build a three-tier architecture, I found this was correct. Materials learned from the Internet: three layers are available: the presentation layer (UI), the business logic layer (BLL), and the data presentation layer (DAL ). It is best to start from the logic layer, and the code we make suitable for the console should be the code at the logic layer. Now I want to call Dal data in Bll, and then call BLL data in Ui to implement a three-tier architecture.
(Now It's, and the logic layer data is almost the same. The subsequent understandings are added here: 11-07. After writing the Dal code, the code can be saved and other software can be directly applied after slight changes, directly added to the BLL layer to add a plug-in to the software; you need to change the database type, you only need to change the Dal layer ;)
The first step is to design the attributes of employee information. An employee information table contains the following information: ID, name, gender, age, education, phone number, department, position, start time, salary, and email address. (When I started the UI Layer on November 8, I found that some data still needs to be processed. For example, the Administrator account password, employee image, in-service or out-of-office or internship, after the employee changes the information, record the backup file to view the transfer information. Consider the information later. put it first );
Then I want to write some functions to process this information: add, delete, query, modify, and sort.
The next step is the class design. Is it necessary to create MFC at the beginning or create a console for debugging? I don't know, but when I wrote this article, I designed and implemented the class, and all the team members had done well. After I understood it, I used it directly. Therefore, this tutorial directly creates a single MFC Document (project name staff )!
I originally wanted to do The bll layer first, but the team members provided the data operations of the text type of the Q & A, which were directly changed to the method of database Q & A and felt messy. So I should write the Dal layer first. The Dal layer is a function dedicated to writing and processing database data. I now understand the Dal layer, just put all the simple data operation functions, and then call the Dal function for different functions in the BLL layer. The upper layer does not directly operate the database, which is very helpful for adding or maintaining functions of later programs.
Connecting to the database is also very troublesome. From the beginning, self-learning always takes many detours. After several days, I found a simple connection method than the connector [Ado Database Connector question] (the simplest is to generate a database class directly through the MFC Creation wizard, but that is not easy to understand ).
Start!
1. Download and install Microsoft Office Access 2003.
2. Use Microsoft Office Access 2003 to create a database (named staffmessage. mdb) and save it in D: \ data. Double-click the designer to create a table. Enter the following information:
(I later found that the design is less age. Make up it)
Note: Id --- the data type is Numeric-the optical calibration is in the number. You can select an integer as follows. Phone and worktime are long integers, salary is single-precision, and others are the default text types.
When you close the table, you will be prompted to save it. Save the name as staffmessage. If no primary key is defined, select YES.
3. Add the database file to the data source of your computer.
Control Panel -- Administrative Tools -- data source -- User DSN -- join -- Microsoft Access Driver (*. mdb) -- complete: Data Source Name staffmessage, database select D: \ data \ staffmessage. MDB. (Microsoft Office Access 2003 is disabled when you join the service. Otherwise, the Service may fail to be added)
4. Add the header file (staffdal. h) and paste the image. After the program is completed, send the source code.
5. The class of the header file includes something that can be thought of temporarily. The reason why the Dal layer has been doing well for a day is that I have practiced and understood it before, and now I just turn it around. I also wrote step by step to make it easier to make changes later. The following is the class implementation code written in staffdal. cpp.
After writing this, you can try it out first. Staffdal sdal is added to the View class. A button is added to the menu bar and a button processing function is added. Write
Sdal. Connect ();
Sdal. addnew (); // you can try sdal. Close () to change the m_id equivalent token in this function ();
// An error occurs when I click. At first, the data source name was written but could not connect to the database. After modification, click the button to prompt whether the memory error persists. Click continue to continue the execution. The error is not displayed when you add the record for the second time. Therefore, it is expected that the original table is empty. I have written the program here. The first section is over. It is still unknown whether other parts can be implemented. First, and then go to dinner (the tutorials I wrote are all in the draft box for a while ...).