Custom Plug-Ins

Create a new Visual Studio "Class Library" using the ".NET Framework 4".

Add references to the project:

The Release version of these components need to be built using the latest source code.

Main.cs:

using System;

using System.Collections.Generic;

using System.Text;

using Hurkin.Shipper.Client.Interfaces;

using System.Windows.Forms;

namespace Hurkin.Shipper.Client.Forms

{

public class Main : Interfaces.IPlugIn

{

private IPlugInHost _host = null;

private Control _control = null;

public System.Windows.Forms.Control Initialize(IPlugInHost host)

{

_host = host;

if (_control == null || _control.IsDisposed)

_control = new Calaway.Fumigation.UserControl1(MenuItem);

return _control;

}

public MenuItemInfo MenuItem

{

get

{

return new MenuItemInfo(String.Empty, "Fumigation Tool", EditLevel.Write, true);

}

}

}

}

Add a User Control

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using Hurkin.Shipper.Client;

using Hurkin.Shipper.Client.Forms;

using Hurkin.Shipper.Data.EntityClasses;

using Hurkin.Shipper.Data.HelperClasses;

using Hurkin.Shipper.Data.TypedListClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace Calaway.Fumigation

{

public partial class UserControl1 : Hurkin.Shipper.Client.Forms.baseForm

{

public UserControl1(Hurkin.Shipper.Client.MenuItemInfo info)

{

InitializeComponent();

InitializeBaseForm(info);

colLocation.DataSource = Hurkin.Shipper.Client.Cache.GetItem(ItemType.LocationForCargo);

colLocation.ValueMember = LocationFields.LocationId.Name;

colLocation.DisplayMember = LocationFields.Description.Name;

}

}

Retrieving Data

private void ddlCargo_ValueChanged(object sender, EventArgs e)

{

// If the Cargo Number changes, get existing values

if (ddlCargo.Value.HasValue)

{

CargoEntity cargo = Program.Global.ShipperService.GetCargo(Program.Global.SessionId, ddlCargo.Value.Value) as CargoEntity;

Program.Global.StopWaiting();

ddlCargoLocation.Value = cargo.LocationId;

if (cargo.PlannedAvailableToShip.HasValue)

dtReadyToShip.DateTimeValue = cargo.PlannedAvailableToShip;

if (cargo.CargoContainer != null)

{

txtCuPlate.Text = cargo.CargoContainer.CuPlate;

if (cargo.CargoContainer.ActualFumigated.HasValue)

dtFumigated.DateTimeValue = cargo.CargoContainer.ActualFumigated;

if (cargo.CargoContainer.ActualOpened.HasValue)

dtOpened.DateTimeValue = cargo.CargoContainer.ActualOpened;

}

}

}

Saving Data

public override void SaveData()

{

// A collection for saved records

IEntityCollection2 toSave = new EntityCollection(new Hurkin.Shipper.Data.FactoryClasses.CargoEntityFactory());

// Loop through the grid, retrieve rows, and add to collection

foreach (DataGridViewRow row in grid.Rows)

{

int CargoId = (int)row.Cells[colCargoNumber.Index].Tag;

string CuPlate = row.Cells[colCuPlate.Index].Value.ToString();

int? LocationId = (int?)row.Cells[colLocation.Index].Tag;

DateTime? Fumigated = (DateTime?)row.Cells[colFumigated.Index].Tag;

DateTime? Opened = (DateTime?)row.Cells[colOpened.Index].Tag;

DateTime? ReadyToShip = (DateTime?)row.Cells[colReadyToShip.Index].Tag;

CargoEntity cargo = Program.Global.ShipperService.GetCargo(Program.Global.SessionId, CargoId) as CargoEntity;

if (cargo != null && cargo.CargoContainer != null)

{

cargo.CargoContainer.CuPlate = CuPlate;

cargo.CargoContainer.ActualFumigated = Fumigated;

cargo.CargoContainer.ActualOpened = Opened;

cargo.PlannedAvailableToShip = ReadyToShip;

cargo.LocationId = LocationId;

toSave.Add(cargo);

}

}

// Perform Save

Program.Global.ShipperService.SaveCollectionRecursive(Program.Global.SessionId, toSave, null);

Program.Global.StopWaiting();

grid.Rows.Clear();

base.SaveData();

}

Plugging It In

First, the Custom Forms (CFM) feature needs to be enabled for a role. This can easily be done in HAAL.

Second, the DLL you produce needs to be placed in the appropriate PlugIns folder. This will always be on the same server(s) that provide your web services (Shipper.svc).

Whatever plugins you add will automatically be checked, downloaded and added to clients as they log in. They will appear under “Custom Items”.