using
System;
using
System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TEClientLib; //важно!!
using StockLibrary;
using StockLibraryAlor;
namespace WindowsFormsApplication1
{
public
partial class
frmTEClinetTest :
Form
{
public
frmTEClinetTest()
{
InitializeComponent();
}
private
SlotFace slot;
private
AlorDriver driver;
private
void slot_Error(int
OpenID, int SlotID,
int Code, String Description)
{
this.Invoke((MethodInvoker)delegate
{
lbState.Text =
"Error: " + Description;
}
);
}
private
void slot_Connected(int
OpenID, int SlotID,
int ResultCode, string ResultMsg)
{
this.Invoke((MethodInvoker)delegate
{
lbState.Text =
"Соединение со слотом " +
Convert.ToString(SlotID) +
" сообщение " + ResultMsg;
}
);
}
private
void slot_Disconnected(int
OpenID, int SlotID,
int ResultCode, string ResultMsg)
{
this.Invoke((MethodInvoker)delegate
{
lbState.Text =
"Отсоединение от слота " +
Convert.ToString(SlotID) +
" сообщение " + ResultMsg;
}
);
}
private
void sFace_Synchronized(int
OpenID, int SlotID)
{
this.Invoke((MethodInvoker)delegate
{
lbState.Text =
"Синхронизация со слотом " +
Convert.ToString(SlotID);
}
);
}
private
void items_loaded()
{
}
private
void btnConnect_Click(object
sender, EventArgs e)
{
slot = new
SlotFace();
driver = new
AlorDriver();
slot.Error +=
new _ISlotFaceEvents_ErrorEventHandler(slot_Error);
slot.Connected +=
new
_ISlotFaceEvents_ConnectedEventHandler(slot_Connected);
slot.Synchronized +=
new
_ISlotFaceEvents_SynchronizedEventHandler(sFace_Synchronized);
slot.Disconnected +=
new
_ISlotFaceEvents_DisconnectedEventHandler(slot_Disconnected);
driver.slot = slot;
driver.slotID = 5;
driver.server = tbServer.Text;
driver.password = tbPassword.Text;
driver.login = tbLogin.Text;
driver.onStockItemsLoaded +=
new
stock_items_loaded(items_loaded);
driver.connection();
lbRes.Text = driver.result;
}
private
void btnDisconnect_Click(object
sender, EventArgs e)
{
driver.disconnection();
}
private
void timer_Tick(object
sender, EventArgs e)
{
if (driver
== null) return;
lbOrdersCount.Text =
"Всего заявок " + driver.ordersCount().ToString();
if (driver.holdings
== null) return;
List<StockItemAlor>
ob = driver.items;
if (ob.Count
== 0) return;
dgvOrders.Rows.Clear();
dgvOrders.RowCount = ob.Count;
int j =
0;
foreach
(StockItemAlor item
in ob)
{
dgvOrders.Rows[j].Cells[0].Value =
item.ticker;
dgvOrders.Rows[j].Cells[1].Value =
item.name;
dgvOrders.Rows[j].Cells[2].Value =
item.price;
dgvOrders.Rows[j].Cells[3].Value =
item.count.ToString();
j++;
}
lbServerType.Text = slot.ServerType[driver.slotID];
lbPortolioPrice.Text =
driver.getPortfolioPrice().ToString();
lbItemsKindsCount.Text =
"Видов инструментов: " +
driver.itemsCount().ToString();
}
private
void dgvOrders_CellEnter(object
sender, DataGridViewCellEventArgs e)
{
if (driver
== null) return;
if (e.RowIndex
!= -1)
{
if (dgvOrders.Rows[e.RowIndex].Cells[1].Value
== null) return;
string
tiker=dgvOrders.Rows[e.RowIndex].Cells[0].Value.ToString();
lbCountItem.Text = tiker +
"; остаток: " + driver.itemCountOnAccount(tiker).ToString();
}
}
private
void rbUnit_CheckedChanged(object
sender, EventArgs e)
{
driver.measure =
Measures.unit;
}
private
void rbLot_CheckedChanged(object
sender, EventArgs e)
{
driver.measure = Measures.lot;
}
private void
lbStockItems_SelectedIndexChanged(object
sender, EventArgs e)
{
//int index=lbStockItems.SelectedIndex;
//driver.open_order_book(driver.items[index]);
}
}
} |