PiecesProgram Pieces Tutorial: Hello, User!

Chapter 3: How to connect a program piece to the database

Program pieces access the database through the MM3Data and MM3State objects they are passed when the program instantiates them.

This tutorial demonstrates using those objects to read the display name of the current user and say hello to them

Open your Hello world project

Recall the steps you took making the HelloWorld project:

  1. Make a new project, named HelloWorld
  2. Add a reference to MM3Common.dll
  3. Add a class named HelloWorldProgramPiece
  4. Make HelloWorldProgramPiece inherit from ProgramPieceBase
  5. Add the using MM3Common; statement at the top of the code for the class HelloUserProgramPiece:

{short description of image}

Give it something to do

The beauty of program pieces is that they have access to the database and to the program state information through the objects MM3Data and MM3State. For example, we access the name of the current user through MM3State. To do this we will override OnCallBeforeShow() as in HelloWorld, but this time we use MM3State. Type the following code:

System.Windows.Forms.MessageBox.Show( "Hello, " + MM3State.CurrentUser.DisplayName);

Notice Visual Studio's Intellisense feature lets you see what members are available to you in classes such as MM3State and MM3Data.

That should do it

Hello World with Display name

Plug in the piece

The administrator's console can then plug in the piece, adding its information to the database table. This is done in the Administrator's console, described elsewhere, but it adds a row the the ProgramPieceInfos table in the database.

{short description of image}

Run the program

When you run the program now, look under menu item Tools, Windows, HelloWorld (or whatever you told it to use for a label when you added it via the Administrator's console). Now you will get a personalized Hello message box.

Next tutorial: Making a display to show in the main form: PPHelloUserDisplay.html