I am new to C++ and .Net Framework, I am using it build a Windows Application that has a login feature. The login form then goes into a User Interface according to the type of the user. This form will have a logout button once pressed, it will close this form and opens the login form. The problem is that once opening the login form, my logic makes the application finishes and return 0 at the end. How can I make it that it will never end until user explicitly presses the close button ?
my main.cpp:
#include <iostream>
#include "AdminHomeForm.h"
#include "LoginForm.h"
#include "Constants.h"
#include "FileIO.h"
#include "Main.h"
#include "UserHomeForm.h"
using namespace std;
using namespace System;
using namespace System::Windows::Forms;
int main() {
json usersData;
json sessionData;
bool mustLogin = true;
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
if (FileIO::readFromJsonFile(USERS_PATH, usersData)) {
FileIO::loadUsersData(usersData);
if (FileIO::readFromJsonFile(SESSION_PATH, sessionData)) {
int session_result = FileIO::loadSession(sessionData);
if (session_result != 200)
{
switch (session_result)
{
case 304:
cout << "User Not Found";
break;
case 300:
cout << "Session File Found But With No Data";
break;
default:
break;
}
}
else
{
mustLogin = false;
}
}
}
if (mustLogin)
{
hotelreservationsystem::LoginForm loginform;
loginform.ShowDialog();
}
if (active_user.id != "")
{
FileIO::loadDatabase();
// begin app
if (active_user.user_type == 0)
{
hotelreservationsystem::AdminHomeForm adminHomeForm;
adminHomeForm.ShowDialog();
} else if (active_user.user_type == 1)
{
hotelreservationsystem::UserHomeForm userHomeForm;
userHomeForm.ShowDialog();
} else
{
cout << "Unknown User Type" << "n" << "Logging Out..." << endl;
}
// end app
if (!Main::saveChanges())
{
cout << "Saving Process Failed" << endl;
};
}
Main::cleanUp();
return 0;
}
logout:
System::Void logoutBtn_Click(System::Object^ sender, System::EventArgs^ e) {
Main::logout();
this->Close();
LoginForm^ loginForm = gcnew LoginForm();
loginForm->Show();
}