Click here to Skip to main content
15,991,071 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Im new at this. I am building a database. Form 1 is called Employees, with Employee AutoID and Employee ID Number, First name and so on. Form 2 is called, Employee Emergency Contacts. From the Employee Form I want to Open the Emergency Contacts Form and display the emergency contact that is associated with the employee, based on the Employee AutoID Number. If no data is associated the Emergency Contact Form should Open with Null values. Possible message of, no contact information associated. I have done this in Access but I am not sure how to do it with C++. I have researched and could not find any help. I would appreciate any and all help. Thanks in Advance. I hope I made since.

What I have tried:

I have researched this issue and could not find a solution.
Posted
Comments
Rick York 23-Jul-24 20:40pm    
You are not likely to just "find a solution" for your problem here. This site's members are not interested in doing people's homework for them so you have to put a bit of effort into it yourself.
Richard MacCutchan 24-Jul-24 3:30am    
If you are serious about using Windows Forms and database content, then .NET is a better choice. And it supports C++, C# and Visual Basic, but I would go for one of the latter twonot recomment C++.
Rick York 24-Jul-24 10:54am    
I would not recommend .Net's C++ either. It is a nauseating abomination.
Richard MacCutchan 24-Jul-24 11:05am    
Totally agree.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
The terms C++, form, Access and database suggest some assumptions that were not mentioned as requirements. However, there are actually countless possibilities of what could be meant and how something like this could be realized. Of course, if you don't specify it, you won't find anything specific with Google.

To create a database application in C++ under Windows, you could proceed as follows.

1. create a Win32 C++ desktop project with Visual Studio or another development environment. In Visual Studio, the wizard usually creates a GUI based on the Windows API.

2. define the GUI controls, for example for input fields:
C++
struct EmployeeControls {
    HWND hEmployeeID, hFirstName, hLastName, hOpenEmergencyContactsButton;
} controls;

3. define further data structures, such as
C++
class Employee {
public:
    Employee() : autoID(0) {}  // Constructor
    int manageAutoID(int value = 0); // Function to set or get AutoID
    std::wstring manageEmployeeID(const std::wstring& value = L"");
    std::wstring manageFirstName(const std::wstring& value = L"");
    std::wstring manageLastName(const std::wstring& value = L"");
    bool LoadFromDatabase(sqlite3* db, int autoID);
    // ...
private:
    int autoID;
    std::wstring employeeID;
    std::wstring firstName;
    std::wstring lastName;
};

4. display the employee form in the main window and offer the possibility to open the emergency contact form.

5. download the SQL database engine www.sqlite.org and add it to the project
Usually enter paths and libraries in the project settings and integrate them with include headers.

6. create/open the SQLite database with C++.

7. create tables for employees and employee emergency contacts in the database using C++.

To make something visible right at the beginning of step 4, you could use the following, for example:
C++
void AddControls(HWND hWnd) {
    CreateWindowW(L"static", L"Employee ID:", WS_VISIBLE | WS_CHILD, 50, 50, 100, 25, hWnd, NULL, NULL, NULL);
    controls.hEmployeeID = CreateWindowW(L"edit", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 150, 50, 200, 25, hWnd, NULL, NULL, NULL);

    CreateWindowW(L"static", L"First Name:", WS_VISIBLE | WS_CHILD, 50, 100, 100, 25, hWnd, NULL, NULL, NULL);
    controls.hFirstName = CreateWindowW(L"edit", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 150, 100, 200, 25, hWnd, NULL, NULL, NULL);

    CreateWindowW(L"static", L"Last Name:", WS_VISIBLE | WS_CHILD, 50, 150, 100, 25, hWnd, NULL, NULL, NULL);
    controls.hLastName = CreateWindowW(L"edit", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 150, 150, 200, 25, hWnd, NULL, NULL, NULL);

    controls.hOpenEmergencyContactsButton = CreateWindowW(L"button", L"Open Emergency Contacts", WS_VISIBLE | WS_CHILD, 50, 200, 200, 25, hWnd, (HMENU)1, NULL, NULL);
}


The function can then be used in WindowProcedure (WinProc):
C++
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
  switch (msg) {
    WM_CREATE: 
    AddControls(hWnd);
    // LoadEmployeeData(hWnd, 1);  // Example AutoID=1
    break;
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900