Loading Data

The first step is to retrieve some data from the Relativity Server. You will start by getting the data from the Tasks table and displaying it to the user.

The Main Form

Before we write the code to get the data, we are going build a very basic UI. First open MainForm.cs in designer mode, and delete the Powered by REMOBJECTS Data Abstract button. Next add a 'Button' which will be used to load the data from the server and a 'DataGridView' which will display the retrieved data.

Rename the the button to loadButton and set the button's label to Load Data. Next change the DataGridView's name to tasksDataGridView.

Adding a button to retrieve the data

Now we add some code. Double click on the Load Data button to add the click event handler to MainForm.cs. Before we add the code to that method, add a new private field _isLoggedIn which we'll use to track if the user is logged in, and also rename all instances of fDataModule to _dataModule (The later simply so that any private fields we add/use consistently start with an underscore)

#region Private fields
private DataModule _dataModule;
private bool _isLoggedIn;
#endregion

Then in the event handler loadButton_Click we add the following code to handle logging in. In the code we take advantage of the LogOnForm supplied with the project template and display it when the user clicks the Load Data button. We retrieve the values the user enters and pass them to the server via the data module. If the user successfully logs in we store the result in the private _isLoggedIn field.

private void loadButton_Click(object sender, EventArgs e)
{
    if (!this._isLoggedIn)
    {
         // Attempt to log in to the Relativity Server
        Boolean loginResult = false;

        using (LogOnForm logonForm = new LogOnForm())
        {
            if (logonForm.ShowDialog() == DialogResult.OK)
            {
                loginResult = this._dataModule.LogOn(logonForm.UserId, logonForm.Password);
            }
        }

        if (!loginResult)
        {
            MessageBox.Show("User was not logged in");
            return;
        }

        this._isLoggedIn = true;
    }

    // Retreive and display the ToDo List
    this.tasksDataGridView.DataSource = (from x in this._dataModule.DataAdapter.GetTable<Tasks.Tasks>() select x).ToList();
}

The last line of the event handler retrieves the tasks from the Tasks table and displays them in the DataGridView.

First Run

Now run the app, when the UI appears press the Load Data button, enter Alex for the username and 111 for the password and then press OK on the login form. (the form should be pre-populated with the user & password you supplied during the creation of this project).

App displaying login dialog

If Relativity Server is running you'll be greeted by the data from the database.

App displaying the retrieved data

The DataAbstract components have handled all the complexity behind retrieving the remote data and left you the simple task of opening the table, just as if it were connected to a local database.

In the next page we will improve the UI to hide columns that shouldn't be visible to the user like User and Id.