Monday 2 July 2012

Integrating crucial hierarchical binding feature to the trading applications

Hierarchical binding present in the trading and financial applications offer a variety of features to its users. Most of the .Net grid or MFC grid based applications implement Hierarchical binding. The benefits of using Hierarchical binding are many. For example an application implementing the Hierarchical binding techniques can easily sort and filter data compared to ones that do not. Thus the use of Hierarchical binding techniques is becoming more and more popular. Most of the developers working on the .Net platform and designing trading applications make use of Hierarchical binding benefits. The Hierarchical binding techniques also allow better data integration techniques in case of real time data update. Since most of the modern day trading and financial applications need real time voluminous updates therefore hierarchical binding is necessary to implement performance and security. Most of the hierarchical binding modules can be designed in secured manner to ensure data and application integrity.
public class Order
{
    private readonly string _instrument;
    private readonly double _price;
    private readonly long _quantity;

    public Order(string instrument, double price, long quantity)
    {
        _instrument = instrument;
        _price = price;
        _quantity = quantity;
    }

    public string Instrument
    {
        get { return _instrument; }
    }

    public double Price
    {
        get { return _price; }
    }

    public long Quantity
    {
        get { return _quantity; }
    }
}

public void PopulateGrid(Grid grid)
{
    BindingList<Order> orders = new BindingList<Order>();

    orders.Add(new Order("Instrument1", 10.55, 34));
    orders.Add(new Order("Instrument2", 12.26, 154));
    orders.Add(new Order("Instrument1", 13.16, 14));
    orders.Add(new Order("Instrument5", 9.85, 52));
    orders.Add(new Order("Instrument1", 16.47, 11));

    grid.DataSource = orders;
}
The above code implements the hierarchical binding features. Most of the hierarchical binding modules enable better data integration customizability along with data safety. The hierarchical binding modules also allow the developer to make the application more robust and scalable for regular use.
public void PopulateGrid(Grid grid)
{
    Strategy strategy = new Strategy("Strategy 1");
    strategy.Orders.Add(new Order("SubOrder1", 10.15, 34));
    strategy.Orders.Add(new Order("SubOrder2", 30.51, 43));
    grid.Rows.Add(strategy);

    Strategy strategy = new Strategy("Strategy 2");
    strategy.Orders.Add(new Order("SubOrder1", 10.15, 34));
    strategy.Orders.Add(new Order("SubOrder2", 30.51, 43));
    grid.Rows.Add(strategy);
}

public class Order : INotifyPropertyChanged
{
    ...

    public double Price
    {
        get { return _price; }
        set
        {
            _price = value;
            if(PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Price"));
            }
        }
    }

    public long Quantity
    {
        get { return _quantity; }
        set
        {
            _quantity = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Quantity"));
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}
In the above code the hierarchical binding modules implement two known features of Data binding with multi threading features and the INotifyPropertyChanged feature. The hierarchical binding modules are applied in such a way that these features are used effectively in designing the applications for regular usage. Since most of the applications are financial and trading in such cases therefore the use of these features are crucial for development.

Sunday 1 July 2012

Datagridview: The best thing about Dapfor’s Datagridview

The best thing about using Dapfor’s application is its capability to offers lots of feature and that too with good performance. One of the most important features of Dapfor application is its Datagridview. Datagridview is not only stable but also supports various version of CLR such as 2.0, 3.0, 3.5 and 4.0. This is the main reason that Datagridview is used in many applications of Dapfor. Users can find many others Datagridview from many organizations but they lack the capability to handle event-based model efficiently as Dapfor applications do. Others organizations Datagridview doesn’t face any kind of problem while handling non-event based model but when it comes to event based model there is no better than the Dapfor’s Datagridview. Dapfor’s Datagridview also consumes less system and memory resources which make them among the best in the business. 
For example, take the sorting mechanism on the Datagridview. In such kind of scenario all the relevant information’s are stored in grid headers. Look at the code below which states the sort direction using simple inbuilt methods provided by the Dapfor’s Datagridview.
//Get top-level header
Header header = grid.Headers [0];

header["Product"].SortDirection = SortDirection.Ascending;
header["Price"].SortDirection = SortDirection.Descending;
If the users want to restrict the sorting property from the GUI, they can use the Column.Sortable property. Datagridview implements the IComparable interface for applying sorting on the view. During sorting objects generally returns simple data types such as int, float, string pr Timespan. IComparable interface uses these data types for sorting purposes on the Datagridview. Dapfor’s Datagridview also has the capability to handle sorting for different rows as well for complex type of data types. The task of the IComparable interface is to compare between the simple data types and the complex data types. This interface doesn’t take into account about the stocks which is present on the grid cells. The code below gives you the insight about the Datagridview sorting using the DateTime value.
class AnotherDateSortingExample
{
    private readonly DateTime _date;

    public DateExample(DateTime date)
    {
        _date = date;
    }

    public DateTime Date
    {
        get { return _date; }
    }
}

//Create header and column
grid.Headers.Add(new Header());
grid.Headers[0].Add(new Column("Date"));

//Configure the header
grid.Headers[0].StretchMode = ColumnStretchMode.All;
grid.Headers[0][0].SortDirection = SortDirection.Ascending;
grid.Headers[0]["Date"].Format = new StringFormat("d", new CultureInfo("fr-FR"));

//Populate grid with random data
Random random = new Random();
BindingList<DateExample> source = new BindingList<DateExample>();
for (int i = 0; i < 6; ++i)
{
    source.Add(new DateExample(DateTime.Now + TimeSpan.FromDays(random.Next(1000))));
}
grid.DataSource = source;
Dapfor’s Datagridview provides provision to do user defined sorting technique. This can be achieved using the ICustomSort interface which helps is setting the sorting rules.
//An implementation ICustomSort that sorts values by day of week
class MonthOfYearCustomSort : ICustomSort
{
    public int Compare(Row row1, Row row2, string fieldId, object value1, object value2, int defaultResult)
    {
        if(fieldId == "Date")
        {
            DateTime d1 = (DateTime) value1;
            DateTime d2 = (DateTime) value2;

            if (d1. MonthOfYear != d2. MonthOfYear)
            {
                return d1. MonthOfYear > d2.MonthOfYear? 1 : -1;   
            }
        }
        return defaultResult;
    }
}

//Setup custom sorting
grid.CustomSort = new MonthOfYearCustomSort();