Problem:
Customer is developing a Windows Forms application and would like it to display a LoginForm to do user authentication and then to exit the application if it fails or continue on and display the main form if successful.
How can this be done?
Resolution:
Change the main.cbl program to display the loginform first and then start the application with the main form depending on the results of the login.
Example:
main.cbl
class-id winformlogin.Main.
method-id Main static
attribute System.STAThread.
local-storage section.
01 mainForm type winformlogin.Form1.
01 loginForm type winformlogin.LoginForm1.
01 myresult type DialogResult.
procedure division.
set loginForm to new winformlogin.LoginForm1
set myresult to loginForm::ShowDialog
if myresult = type DialogResult::OK
set mainForm to new winformlogin.Form1()
invoke type System.Windows.Forms.Application::EnableVisualStyles()
invoke type System.Windows.Forms.Application::Run(mainForm)
else
invoke type System.Windows.Forms.Application::Exit
end-if
goback.
end method.
end class.
LoginForm1.cbl
class-id winformlogin.LoginForm1 is partial
inherits type System.Windows.Forms.Form.
working-storage section.
method-id NEW.
procedure division.
invoke self::InitializeComponent()
goback.
end method.
method-id btnOK_Click final private.
procedure division using by value sender as object
e as type System.EventArgs.
set self::DialogResult to type DialogResult::OK
invoke self::Close()
goback.
end method.
method-id btnCancel_Click final private.
procedure division using by value sender as object
e as type System.EventArgs.
set self::DialogResult to type DialogResult::Cancel
invoke self::Close()
goback.
end method.
end class.