private
void BindRecords(){
try
{
//Call method for get records
dstOrderRecords = objOrderMonitor.GetRecord();
if (dstOrderRecords.Tables.Count != 0)
{
this.MonitorRowCount = dstOrderRecords.Tables[0].Rows.Count;
dstOrderRecords.Tables[0].Merge(dstOrderRecords.Tables[1]);
DataView dvwOrderRecords = new DataView(dstOrderRecords.Tables[0]);
if (IsOnlyViewHitOrders) // Check whether to view only Hit Orders or all Orders
{
dvwOrderRecords.RowFilter = "OOB_ORDER_STATUS = " + ApplicationBase.ORDERSTATUS_AWAITING_EXECUTION.ToString();
}
dgvOrderMonitor.DataSource = dvwOrderRecords;
}
}
catch (System.Exception ex)
{
base.MsgWindow.AppendText(MessageConstants.EXCEPTION_UNKNOWN_MSG, this.Text, ex);
timerOrderMonitor.Stop();
}
}
and my DataSourceChange Event Code is
private
void dgvOrderMonitor_DataSourceChanged(object sender, EventArgs e){
try
{
//Set boolen value for Alertbell.If any HitOrderExist then start belling else stop belling
//and aslo use for Enable and disable View AllOrders/View HitOrders button
bool blnisHitOrderExist = false;
//Use for Enable and disable ResetAll button
//If Order with OrderType New,Stop or Limit and OrderStatus is Awaiting Execution
//exist then n then ResetAll button enable
bool blnIsResetAllEnable = false;
//Loop for each rows of dgvOrderMonitor and set backcolor and forecolor of respective row(s), and cell(s)
foreach (DataGridViewRow rowObj in dgvOrderMonitor.Rows)
{
//If OrderId != null means if any data exist in datagridview then start
//process of changing color of hitorder rows and pending order rows
if (rowObj.Cells["OrderID"].Value != null)
{
if (Convert.ToInt32(rowObj.Cells["Status"].Value).CompareTo(ApplicationBase.ORDERSTATUS_PENDING) == 0)
{
//Call method for set style on current row
this.SetRowStyle(rowObj, this.MonitorForeColor, this.MonitorBackColor);
rowObj.Cells["Amend_Reset"].Value = "Amend";
}
else if (Convert.ToInt32(rowObj.Cells["Status"].Value).CompareTo(ApplicationBase.ORDERSTATUS_AWAITING_EXECUTION) == 0)
{
if (!blnisHitOrderExist)
blnisHitOrderExist = true;
//Call method for set style on current row
this.SetRowStyle(rowObj, this.HitOrderForeColor, this.HitOrderBackColor);
rowObj.Cells["Amend_Reset"].Value = "Reset";
//Check whether any HitOder exist with Order type is New,Stop or Limit
//if any order exist then enable ResetAll button
if ((string.Compare(rowObj.Cells["OrderType"].Value.ToString().ToUpper(), ApplicationBase.OrderType.New.ToString().ToUpper(), true) == 0) && !blnIsResetAllEnable ||
(string.Compare(rowObj.Cells["OrderType"].Value.ToString().ToUpper(), ApplicationBase.OrderType.Stop.ToString().ToUpper(), true) == 0) && !blnIsResetAllEnable ||
(string.Compare(rowObj.Cells["OrderType"].Value.ToString().ToUpper(), ApplicationBase.OrderType.Limit.ToString().ToUpper(), true) == 0) && !blnIsResetAllEnable
)
{
blnIsResetAllEnable = true;
}
}
//If Margin > Available Resources then change backcolor and forecolor of that two cells.
if (Convert.ToDecimal(rowObj.Cells["MarginRequired"].Value) > Convert.ToDecimal(rowObj.Cells["AvailableResource"].Value))
{
//Call method for set style on current cell
this.SetCellStyle(rowObj.Cells["MarginRequired"], this.MarginBreachForeColor, this.MarginBreachBackColor);
this.SetCellStyle(rowObj.Cells["AvailableResource"], this.MarginBreachForeColor, this.MarginBreachBackColor);
}
//If OrderType is Rollover or Market/Trade or Close then change backcolor and forecolor of OrderType cells.
//and disable reset button for this type of order(s)
if ((string.Compare(rowObj.Cells["OrderType"].Value.ToString().ToUpper(), ApplicationBase.OrderType.Rollover.ToString().ToUpper(), true) == 0) ||
(string.Compare(rowObj.Cells["OrderType"].Value.ToString().ToUpper(), ApplicationBase.OrderType.Close.ToString().ToUpper(), true) == 0) ||
(string.Compare(rowObj.Cells["OrderType"].Value.ToString().ToUpper(), ApplicationBase.OrderType.Trade.ToString().ToUpper(), true) == 0)
)
{
//Call method for set style on current cell
this.SetCellStyle(rowObj.Cells["OrderType"], this.OrderTypeForeColor, this.OrderTypeBackColor);
//disable reset button
DataGridViewDisableButtonCell buttonReset = (DataGridViewDisableButtonCell)rowObj.Cells["Amend_Reset"];
buttonReset.Enabled = false;
buttonReset.TextForeColor = Color.Black;
dgvOrderMonitor.InvalidateCell(buttonReset);
}
}
}
//Check whether HitOrder(Red Zone) Exist.
//If exist then start Alert bell till all hit order not execute.
//and if not Exist then stop Alert bell till new Hit order not come.
if (blnisHitOrderExist && objSoundPlayer.SoundLocation.Length > 0)
objSoundPlayer.PlayLooping();
else if (!blnisHitOrderExist)
objSoundPlayer.Stop();
//Enable or Disable ResetAll button
if (blnIsResetAllEnable)
btnResetAll.Enabled = true;
else
btnResetAll.Enabled = false;
}
catch (System.Exception ex)
{
base.MsgWindow.AppendText(MessageConstants.EXCEPTION_UNKNOWN_MSG, this.Text, ex);
}
}