/// <summary> /// Handles a change to the WorkingOrder row. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="workingOrderRowChangeEventArgs">The event arguments.</param> protected virtual void OnWorkingOrderRowChanged(Object sender, DataModel.WorkingOrderRowChangeEventArgs workingOrderRowChangeEventArgs) { // Validate the parameters. if (sender == null) { throw new ArgumentNullException("sender"); } if (workingOrderRowChangeEventArgs == null) { throw new ArgumentNullException("workingOrderRowChangeEventArgs"); } // If the new working order belongs to this blotter or one of its descendants, then add it in the proper place. if (workingOrderRowChangeEventArgs.Action == DataRowAction.Add) { DataModel.WorkingOrderRow workingOrderRow = workingOrderRowChangeEventArgs.Row; if (this.blotterIdSet.Contains(workingOrderRow.BlotterId)) { Int32 index = this.BinarySearch(order => order.WorkingOrderId, workingOrderRow.WorkingOrderId); this.Insert(~index, this.CreateInstanceCore(workingOrderRowChangeEventArgs.Row)); } } // This will copy the modified elements from the data model into the collection and commit the changes. if (workingOrderRowChangeEventArgs.Action == DataRowAction.Change) { DataModel.WorkingOrderRow workingOrderRow = workingOrderRowChangeEventArgs.Row; if (this.blotterIdSet.Contains(workingOrderRow.BlotterId)) { Int32 index = this.BinarySearch(order => order.WorkingOrderId, workingOrderRow.WorkingOrderId); WorkingOrder workingOrder = this[index]; this.workingOrderCollectionView.EditItem(workingOrder); workingOrder.IsActive = workingOrderRow.StatusRow.StatusCode != StatusCode.Filled; workingOrder.BlotterName = workingOrderRow.BlotterRow.EntityRow.Name; workingOrder.CreatedBy = workingOrderRow.UserRowByFK_User_WorkingOrder_CreatedUserId.EntityRow.Name; workingOrder.CreatedTime = workingOrderRow.CreatedTime; workingOrder.ModifiedBy = workingOrderRow.UserRowByFK_User_WorkingOrder_ModifiedUserId.EntityRow.Name; workingOrder.ModifiedTime = workingOrderRow.ModifiedTime; workingOrder.RowVersion = workingOrderRow.RowVersion; workingOrder.SecurityName = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.EntityRow.Name; workingOrder.SettlementDate = workingOrderRow.SettlementDate; workingOrder.SideCode = workingOrderRow.SideRow.SideCode; workingOrder.SideMnemonic = workingOrderRow.SideRow.Mnemonic; workingOrder.StatusCode = workingOrderRow.StatusRow.StatusCode; workingOrder.Symbol = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.Symbol; workingOrder.TradeDate = workingOrderRow.TradeDate; workingOrder.WorkingOrderId = workingOrderRow.WorkingOrderId; this.workingOrderCollectionView.CommitEdit(); } } }
/// <summary> /// Updates the aggregates associated with a SourceOrder. /// </summary> /// <param name="workingOrderRow">The working order to which the SourceOrder belongs.</param> void UpdateSourceOrderQuantity(WorkingOrder workingOrder, DataModel.WorkingOrderRow workingOrderRow) { // These factors are used display the quantities and prices in industry standard notations. Decimal quantityFactor = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.QuantityFactor; Decimal priceFactor = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.PriceFactor; // Aggregate the execution and source order quantities. Decimal sourceOrderQuantity = 0.0m; foreach (DataModel.SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows()) { sourceOrderQuantity += sourceOrderRow.OrderedQuantity; } // Update and commit the changes to the WorkingOrder record. this.workingOrderCollectionView.EditItem(workingOrder); workingOrder.SourceOrderQuantity = sourceOrderQuantity; workingOrder.MarketValue = sourceOrderQuantity * quantityFactor * workingOrder.LastPrice.Price * priceFactor; this.workingOrderCollectionView.CommitEdit(); }
/// <summary> /// Updates the aggregates associated with an Execution. /// </summary> /// <param name="workingOrderRow">The working order to which the Execution belongs.</param> void UpdateExecutionQuantity(WorkingOrder workingOrder, DataModel.WorkingOrderRow workingOrderRow) { // Aggregate the execution and destination order quantities. Decimal executionQuantity = 0.0m; Decimal destinationOrderQuantity = 0.0m; foreach (DataModel.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows()) { destinationOrderQuantity += (destinationOrderRow.OrderedQuantity - destinationOrderRow.CanceledQuantity); foreach (DataModel.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows()) { executionQuantity += executionRow.ExecutionQuantity; } } // Update and commit the changes to the WorkingOrder record. this.workingOrderCollectionView.EditItem(workingOrder); workingOrder.ExecutionQuantity = executionQuantity; workingOrder.LeavesQuantity = destinationOrderQuantity - executionQuantity; this.workingOrderCollectionView.CommitEdit(); }
/// <summary> /// Raises the CollectionChanged event. /// </summary> /// <param name="args">The NotifyCollectionChangedEventArgs object to pass to the event handler.</param> protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs args) { // The base class has significant processing to do on this event. base.OnCollectionChanged(args); // This class will update the odd/even property of the workingOrders in the collection. This is the only place that knows about the final order of the // records, so this is the only place a function like this can be placed. if (this.MoveCurrentToFirst()) { do { WorkingOrder workingOrder = this.CurrentItem as WorkingOrder; if (workingOrder != null) { this.EditItem(workingOrder); workingOrder.IsEven = this.CurrentPosition % 2 == 0 ? true : false; this.CommitEdit(); } } while (this.MoveCurrentToNext()); } }