Example Object Event Script: Custom Document Type

Documents can be added to trains, truck despatches, service trips, shipments, organisations, internal companies, sales contracts, purchase contracts, freight contracts, service contracts and despatch orders.

In the List Editor, the Document Types list includes three preconfigured document types: URLs, comments and network files. Additional document types require an object event script to enable the file search and hyperlink.

The following script can be set up for the Document Link object:

Copy
using System;
using System.Collections;
using Mincom.MineMarket.DAL;
using Mincom.MineMarket;
using System.Windows.Forms;

public class DocumentLinkEvents : IObjectEvents
{
    public DocumentLinkEvents() { }

    public void ObjectPropertyChange(IEventsObject obj, 
        ObjectPropertyChangeEventArgs e)
    {
        DocumentLink Doc = (DocumentLink)obj;
        if (e.PropertyName == "OpenLink" && Doc.TypeOfDocument.Alias1 == 
            "Custom")
        {
            System.Diagnostics.Process.Start(Doc.Link);
        }
        else if (e.PropertyName == "OpenDialog" && Doc.TypeOfDocument.Alias1 
            == "Custom")
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.CheckFileExists = true;
            dialog.CheckPathExists = true;
            dialog.Multiselect = false;
            dialog.DefaultExt = "dll";
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                string dirName = 
                    System.IO.Path.GetDirectoryName(dialog.FileName);
                Doc.Link = dialog.FileName;
            }
        }
    }

    public void ObjectBeforeSave(IEventsObject obj,
        ObjectBeforeSaveEventArgs e)
    {
    }

    public void ObjectBeforeDelete(IEventsObject obj, 
        ObjectBeforeDeleteEventArgs e)
    {
    }
}

Note: The Alias1 indicated in bold text must match what is set as the Alias1 value of the custom document type in the List Editor. The Alias1 value can be edited via the Property Window.