Category Archives: RemObjects

tide.Northwind.Customers – Part 1

We’ll be breaking the work on the Customers plugin into one or more posts. This first post will net us a working plugin for browsing and editing customers, creating new customers, and deleting customers. This is pretty easy to do using tide – we only need to implement a few of the framework’s interfaces.

However, to keep these posts from getting too long or detailed, we’ll stop at editing our customers within the DevExpress GridControl. The application will be fully functional in this respect, but I’m not a huge fan of editing data directly in a grid – I think it’s handy at times, but for the most part is confusing for end users.

In a follow up post on our Customers plugin, we’ll implement a few more interfaces that allow us to get a details window that displays docked to the right of our browse window. We’ll be able to use that screen to edit our customers, with the rest of the flow working similarly to the way it does in this post.

So, let’s get started.

As with our previous plugins, we’ll add a new project to our existing Northwind solution, specifying a Hydra Plugin Module. To our new plugin module project (Northwind.Customers), we’ll add a new Hydra Visual Plugin. This gives us a Control with a visual design surface. To our visual design surface we’ll add a DevExpress RibbonControl and a DevExpress GridControl. We’ll add a tab, group, and button to our Ribbon control – the tab and group will have a “Customers” caption, and the button will display “Browse Customers”.

Then, we’ll use the Add New Datasource wizard in Visual Studio to add a data source for the Customers table in the Northwind database. This is outside of the scope of this post, but is fairly straight forward. Then, we’ll bind our GridControl to a binding source that is associated with a customers table adapter.

And that’s it for the form design – now we’ll write some code (don’t worry – not too much).

Switching to our source code, we’ll add the following to our using clause:

using tide.PluginInterfaces;
using tide.Utilities.Plugins;

The first namespace gives us access to the interfaces we’ll be implementing. The second namespace gives us access to a base Visual Plugin class from which we’ll inherit our current plugin. We’ll call our visual plugin BrowsePlugin, and adjust it’s declaration:

public partial class BrowsePlugin : MasterWindow, IRibbonProvider, IPrintableProvider

The MasterWindow class is declared in tide.Utilities.Plugins, and does some nice things for us, such as automatically saving and restoring DevExpress GridControl customizations, LayoutControl changes, and providing default implementations for IMasterWindow. IMasterWindow allows the controls in the host’s Quick Access Toolbar and Application Menu (items for saving changes, creating new items, deleting items) to interact with our plugin. Implmenting IRibbonProvider allows us to surface our Ribbon in the host. Finally, IPrintableProvider allows us to make controls within our plugin printable and exportable via the host’s Application Menu.

First, we’ll override several of the IMasterWindow methods that are implemented in the MasterWindow class:

public override string ItemName()
{
    return "Customer";
}

public override bool NewItemEnabled()
{
    return true;
}

public override void NewItem(object refId)
{
    customersBindingSource.AddNew();
}

public override bool SaveItemEnabled()
{
    return northwindDataSet.HasChanges();
}

public override bool SaveItem()
{
    customersTableAdapter.Update(northwindDataSet.Customers);
    return true;
}

public override void DeleteItem()
{
    customersBindingSource.RemoveCurrent();
}

public override bool DeleteItemEnabled()
{
    return customersBindingSource.Position = 0;
}

These very simple methods allow the Quick Access Toolbar and items in the host’s Application Menu to interact with our plugin.

Next, we’ll implement IRibbonProvider:

public DevExpress.XtraBars.Ribbon.RibbonControl RibbonControl()
{
    return ribbonControl1;
}

And now IPrintableProvider:

public DevExpress.XtraPrinting.IPrintable Printable()
{
    return gridControl1;
}

Now, we’ll add the meat of the code for this plugin. We need to add a couple of namespaces for access to our settings and encryption:

using tide.Utilities.Settings;
using tide.Utilities.Encryption;

Then, we’ll add a Click handler for the Browse Customers button on our RibbonControl, and handle it with the following code:

private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    BrowseNorthwindCustomers();
    ((IHostApplication)Host).DisplayPlugin(this);
}

private void BrowseNorthwindCustomers()
{
    string connectionString = GetConnectionString();
    customersTableAdapter.Connection.ConnectionString = connectionString;
    customersTableAdapter.Fill(northwindDataSet.Customers);
    customersView.BestFitColumns();
}

private string GetConnectionString()
{
    ApplicationSettings applicationSettings = new ApplicationSettings((IHostApplication)Host);
    SimpleSettings simpleSettings = new SimpleSettings(applicationSettings.SettingsFileName);
    SimpleEncryption.PassPhrase = "northwindpassphrase";

    string connectionString = simpleSettings.GetSetting("Northwind/ConnectionString", "");
    if (connectionString != "")
        connectionString = SimpleEncryption.SimpleDecrypt(connectionString);

    return connectionString;
}

And that’s it! No sweat broken, I hope. As with our previous examples, we are really just implementing some very simple methods and interfaces from the tide framework. Running the application now lets us browse customers, create new customers, make changes to existing customers (with the Save items in the host’s Quick Access Toolbar and Application Menu enabling as necessary), and save those changes. We can also print our customers, and export them to Excel, Acrobat, and several other formats.

tide.Northwind

In our next post, we’ll update this Customers plugin module, disallowing inline editing in the GridControl and creating a new Hydra Visual Plugin that implements IDetailWindow, allowing us to view the details of a selected customer and make changes within that dedicated screen.