#include "MainFrame.h"
|
#include <list>
|
#include "../common_nopch/WidgetsRenderUtil.h"
|
#include "../common_nopch/JsonUtil.h"
|
#include "MyNetworkApi.h"
|
#include <thread>
|
#include "../common_nopch/Win32Util.h"
|
#include "../common_nopch/TimeUtil.h"
|
#include "MyConfigUtil.h"
|
#include <wx/graphics.h>
|
|
#define ROW_WIDTH_DELEGATE_INFO (FRAME_WIDTH - 30)*DPI/100
|
|
#define TEXT_LINE_HEIGHT 20*DPI/100
|
|
#define ROW_HEIGHT (20*3 + 22 + 32 )*DPI/100
|
|
#define DEFAULT_FONT_SIZE 10
|
|
|
using namespace std;
|
|
|
std::map<wxString, DelegateInfo> MainFrame::delegateMap;
|
|
enum BtnClickType
|
{
|
CLICK_TYPE_UNKNOWN,
|
CLICK_TYPE_CANCEL_BUY,
|
CLICK_TYPE_VIEW_DETAIL,
|
CLICK_TYPE_QUEUE,
|
};
|
|
struct ViewDetailData {
|
string code;
|
};
|
|
|
// ίÍÐÐÅÏ¢Êý¾Ý
|
class DelegateInfoRenderer : public wxDataViewCustomRenderer
|
{
|
|
private:
|
DelegateInfo delegateInfo;
|
wxString delegateInfoStr;
|
list<ColorIndexInfo> delegateColors;
|
map<wxString, wxRect> viewBtnRectMap;
|
map<wxString, wxRect> cancelBtnRectMap;
|
map<wxString, wxRect> queueRectMap;
|
map<wxString, wxRect> gridPostionMap;
|
|
public:
|
/*static void addDelegateInfo(DelegateInfo info) {
|
delegateMap[info.id] = info;
|
}*/
|
|
|
private:
|
|
wxString floatToString(float value) {
|
std::ostringstream ss;
|
ss << std::fixed << std::setprecision(2) << std::round(value * 100) / 100;
|
return ss.str();
|
}
|
|
void loadContent() {
|
delegateColors.clear();
|
delegateInfoStr.Clear();
|
delegateInfoStr.Append("Ê£");
|
|
ColorIndexInfo colorInfo0;
|
colorInfo0.start_index = delegateInfoStr.Length();
|
delegateInfoStr.Append(to_string(delegateInfo.left_count));
|
colorInfo0.end_index = delegateInfoStr.Length() - 1;
|
if (delegateInfo.left_count <= 10) {
|
colorInfo0.color = *wxRED;
|
delegateColors.push_back(colorInfo0);
|
}
|
|
|
delegateInfoStr.Append("±Ê ");
|
|
ColorIndexInfo colorInfo1;
|
colorInfo1.start_index = delegateInfoStr.Length();
|
delegateInfoStr.Append(delegateInfo.left_money);
|
colorInfo1.end_index = delegateInfoStr.Length() - 1;
|
if (parseMoneyAsW(delegateInfo.left_money) <= 1500) {
|
colorInfo1.color = *wxRED;
|
delegateColors.push_back(colorInfo1);
|
}
|
|
|
delegateInfoStr.Append("/").Append("·âµ¥").Append(delegateInfo.buy1_money);
|
|
delegateInfoStr.Append(" ¡¾±ÈÀý: ");
|
|
ColorIndexInfo colorInfo2;
|
colorInfo2.start_index = delegateInfoStr.Length();
|
delegateInfoStr.Append(floatToString(delegateInfo.trade_progress_percent)).Append("%");
|
colorInfo2.end_index = delegateInfoStr.Length() - 1;
|
colorInfo2.color = wxColor(206, 14, 95);
|
delegateColors.push_back(colorInfo2);
|
delegateInfoStr.Append("¡¿£¬");
|
|
delegateInfoStr.Append("Òѳɴóµ¥").Append(to_string(delegateInfo.big_num_count)).Append("±Ê").Append(delegateInfo.big_num_money).Append(" ");
|
|
delegateInfoStr.Append("´ý³Éǰ´óµ¥").Append(to_string(delegateInfo.not_deal_big_num_count_pre)).Append("±Ê").Append(delegateInfo.not_deal_big_num_money_pre).Append("£¬");
|
|
|
delegateInfoStr.Append("´ý³Éºó´óµ¥");
|
ColorIndexInfo colorInfo;
|
colorInfo.start_index = delegateInfoStr.Length();
|
delegateInfoStr.Append(to_string(delegateInfo.not_deal_total_big_count_after));
|
colorInfo.end_index = delegateInfoStr.Length() - 1;
|
if (delegateInfo.not_deal_total_big_count_after <= 3) {
|
colorInfo.color = *wxRED;
|
delegateColors.push_back(colorInfo);
|
}
|
|
delegateInfoStr.Append("±Ê").Append(delegateInfo.not_deal_big_num_money_after).Append("£¬");
|
|
|
delegateInfoStr.Append("ÕÇÍ£¼Û:");
|
ColorIndexInfo colorInfo3;
|
|
colorInfo3.start_index = delegateInfoStr.Length();
|
delegateInfoStr.Append(floatToString(delegateInfo.limit_up_price)).Append("Ôª");
|
colorInfo3.end_index = delegateInfoStr.Length();
|
if (delegateInfo.limit_up_price < 3) {
|
colorInfo3.color = *wxRED;
|
delegateColors.push_back(colorInfo3);
|
}
|
delegateInfoStr.Append("£¬");
|
delegateInfoStr.Append(delegateInfo.block).Append("£¬");
|
|
delegateInfoStr.Append(" ÕÇͣʱ¼ä£º").Append(delegateInfo.limit_up_time);
|
}
|
|
float parseMoneyAsW(wxString st) {
|
wxString money = st;
|
if (st.Find("Íò") >= 0) {
|
money = st.Mid(0, st.Find("Íò"));
|
double d;
|
money.ToDouble(&d);
|
return d;
|
}
|
else if (st.Find("ÒÚ") >= 0) {
|
money = st.Mid(0, st.Find("ÒÚ"));
|
double d;
|
money.ToDouble(&d);
|
return d * 10000;
|
}
|
else {
|
double d;
|
money.ToDouble(&d);
|
return d;
|
}
|
}
|
|
void drawOperateLine(wxDC* dc, int startx, int starty, int line_width) {
|
//»æÖƺìµã
|
/* wxFont font(dc->GetFont().GetPixelSize(), wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT), wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);*/
|
|
|
|
|
// »æÖÆÃû×Ö
|
wxString codeInfo = "";
|
codeInfo.Append(delegateInfo.code).Append("(").Append(delegateInfo.codeName).Append(")");
|
|
codeInfo.Append(" ").Append(delegateInfo.zyltgb);
|
|
|
if (delegateInfo.pay_attention) {
|
WidgetsRenderUtil::drawText(dc, codeInfo, wxPoint(startx, starty + 3), line_width, TEXT_LINE_HEIGHT, std::list<ColorIndexInfo>(), *wxRED);
|
wxSize textSize = dc->GetTextExtent(codeInfo);
|
WidgetsRenderUtil::drawText(dc, "****", wxPoint(startx + textSize.GetWidth() + 5 * DPI / 100, starty + 5 * DPI / 100), line_width, TEXT_LINE_HEIGHT, std::list<ColorIndexInfo>(), *wxRED);
|
}
|
else {
|
WidgetsRenderUtil::drawText(dc, codeInfo, wxPoint(startx, starty + 3), line_width, TEXT_LINE_HEIGHT);
|
}
|
// »æÖư´Å¥
|
dc->SetPen(wxColour(225, 225, 225));
|
dc->SetBrush(wxColour(225, 225, 225));
|
|
int btnWidth = 50 * DPI / 100;
|
int btnHeight = 25 * DPI / 100;
|
int padding = 10 * DPI / 100;
|
viewBtnRectMap[delegateInfo.id] = wxRect({ startx + line_width - btnWidth, starty, btnWidth, btnHeight });
|
|
WidgetsRenderUtil::drawBtn(dc, "²é¿´", viewBtnRectMap[delegateInfo.id], *wxWHITE, wxColour(0, 150, 136));
|
|
// ÏàÁڵij·µ¥´íλÏÔʾ
|
cancelBtnRectMap[delegateInfo.id] = wxRect({ startx + line_width - viewBtnRectMap[delegateInfo.id].GetWidth() - btnWidth - padding - (delegateInfo.index % 2 == 0 ? 0 : btnWidth + 5 * DPI / 100), starty, btnWidth, btnHeight });
|
cout << "³·µ¥Î»ÖÃäÖȾ£º" << delegateInfo.index << " - " << cancelBtnRectMap[delegateInfo.id].x << ":" << cancelBtnRectMap[delegateInfo.id].y << endl;
|
WidgetsRenderUtil::drawBtn(dc, "³·µ¥", cancelBtnRectMap[delegateInfo.id], *wxWHITE, wxColour(255, 87, 34));
|
}
|
|
void drawDelegateQueue(wxDC* dc, wxPoint start, int line_width) {
|
|
wxGraphicsContext* gc = wxGraphicsContext::CreateFromUnknownDC(*dc);
|
|
|
|
//wxFont font = dc->GetFont();
|
//font.SetNumericWeight(wxFONTWEIGHT_BOLD);
|
//gc->SetFont(font,*wxRED);
|
|
|
wxSize queueSize(43 * DPI / 100, 22 * DPI / 100);
|
|
// »æÖƱ³¾°ÑÕÉ«
|
wxRect queueRect = wxRect(start, wxSize(line_width, queueSize.y));
|
gc->SetPen(*wxBLACK);
|
gc->SetBrush(*wxBLACK);
|
gc->DrawRectangle(queueRect.x, queueRect.y, queueRect.GetWidth(), queueRect.GetHeight());
|
|
queueRectMap[delegateInfo.id] = queueRect;
|
|
|
int padding = 5 * DPI / 100;
|
int countPerLine = (line_width - padding) / (queueSize.x + padding);
|
|
|
int index = 0;
|
for (list<TradeQueue>::iterator e = delegateInfo.tradeQueueList.begin(); e != delegateInfo.tradeQueueList.end(); e++) {
|
|
wxRect rect = wxRect(start.x + padding + (queueSize.x + padding) * index, start.y, queueSize.x, queueSize.y);
|
|
wxColour color;
|
switch ((*e).type)
|
{
|
case 0:
|
color = *wxRED;
|
break;
|
case 1:
|
color = *wxWHITE;
|
break;
|
case 2:
|
color = wxColor(209, 135, 252);
|
break;
|
default:
|
color = *wxRED;
|
break;
|
}
|
gc->SetFont(dc->GetFont(), color);
|
WidgetsRenderUtil::drawBtnByGC(gc, (*e).num, rect, color, *wxBLACK);
|
|
index++;
|
if (index >= countPerLine) {
|
break;
|
}
|
}
|
|
/*font = dc->GetFont();
|
font.SetNumericWeight(wxFONTWEIGHT_NORMAL);
|
dc->SetFont(font);*/
|
delete gc;
|
}
|
|
|
BtnClickType getClickType(int x_, int y_) {
|
|
cout << "µã»÷λÖãº" << x_ << "-" << y_ << endl;
|
|
wxRect gridPostion = gridPostionMap[delegateInfo.id];
|
wxRect queueRect = queueRectMap[delegateInfo.id];
|
wxRect cancelBtnRect = cancelBtnRectMap[delegateInfo.id];
|
wxRect viewBtnRect = viewBtnRectMap[delegateInfo.id];
|
|
cout << "µ¥ÔªÎ»Öãº" << gridPostion.x << "-" << gridPostion.y << endl;
|
|
int x = gridPostion.x + x_;
|
int y = gridPostion.y + y_;
|
|
cout << "¶ÓÁÐY:" << queueRect.y << endl;
|
|
|
cout << "³·µ¥Î»Öãº" << cancelBtnRect.GetLeft() << " " << cancelBtnRect.GetTop() << " " << cancelBtnRect.GetRight() << " " << cancelBtnRect.GetBottom() << endl;
|
|
if (x >= viewBtnRect.x && x <= viewBtnRect.x + viewBtnRect.GetWidth() && y > viewBtnRect.y && y <= viewBtnRect.y + viewBtnRect.GetHeight()) {
|
|
return CLICK_TYPE_VIEW_DETAIL;
|
}
|
else if (x >= cancelBtnRect.x && x <= cancelBtnRect.x + cancelBtnRect.GetWidth() && y > cancelBtnRect.y && y <= cancelBtnRect.y + cancelBtnRect.GetHeight()) {
|
|
return CLICK_TYPE_CANCEL_BUY;
|
}
|
else if (x >= queueRect.x && x <= queueRect.x + queueRect.GetWidth() && y > queueRect.y && y <= queueRect.y + queueRect.GetHeight()) {
|
|
return CLICK_TYPE_QUEUE;
|
}
|
return CLICK_TYPE_UNKNOWN;
|
}
|
|
|
public:
|
DelegateInfoRenderer(const wxString& varianttype = "string")
|
: wxDataViewCustomRenderer(varianttype, wxDATAVIEW_CELL_ACTIVATABLE)
|
{
|
}
|
|
|
virtual bool Render(wxRect cell, wxDC* dc, int state)
|
{
|
cout << "ÄÚ´æµØÖ·£º" << this << endl;
|
dc->Clear();
|
dc->SetUserScale(1, 1);
|
|
|
|
gridPostionMap[delegateInfo.id] = wxRect(cell.GetPosition(), cell.GetSize());
|
|
//// ÉèÖûæÖư´Å¥µÄλÖúʹóС
|
//dc->SetTextForeground(wxColour(64, 64, 64));
|
//// »æÖư´Å¥µÄÍâ¿ò
|
//dc->SetPen(wxColour(255, 255, 255));
|
|
//dc->SetBrush(wxColour(255, 255, 255));
|
|
loadContent();
|
|
int start_y = cell.GetPosition().y + 3 * DPI / 100;
|
int start_x = cell.GetPosition().x;
|
// »æÖƲÙ×÷ÇøÓò
|
drawOperateLine(dc, start_x, start_y, cell.GetSize().GetWidth());
|
|
// »æÖƼò½éÇø
|
int infoWidth = cell.GetSize().GetWidth();
|
int infoHeight = WidgetsRenderUtil::drawText(dc, delegateInfoStr, wxPoint(start_x, start_y + 25 * DPI / 100), infoWidth, TEXT_LINE_HEIGHT, delegateColors);
|
// »æÖƶÓÁÐ,¸øÎÄ×ÖÐÅÏ¢Áô3ÅÅ×óÓÒµÄλÖÃ
|
|
drawDelegateQueue(dc, wxPoint(start_x, TEXT_LINE_HEIGHT * 3 + start_y + 30 * DPI / 100), infoWidth);
|
dc->SetTextForeground(wxColour(255, 0, 0));
|
wxRect queueRect(cell.GetPosition().x, cell.GetPosition().y + 50 * DPI / 100, infoWidth, infoHeight + 50 * DPI / 100);
|
return false;
|
}
|
|
void cancelOrder(string code) {
|
string results = MyNetworkApi::cancel_order(code);
|
auto doc = JsonUtil::parseUTF16(results);
|
if (doc.IsObject()) {
|
|
if (doc[L"code"].GetInt() == 0) {
|
showMsg(wxString(delegateInfo.codeName).Append("£º³·µ¥Ìá½»³É¹¦").ToStdString(), MSG_TYPE_INFO);
|
MainFrame* mainFrame = getWindowFrame();
|
if (mainFrame) {
|
mainFrame->requestDelegatedInfoList();
|
}
|
}
|
else {
|
showMsg(wxString(doc[L"msg"].GetString()).ToStdString(), MSG_TYPE_WARNING);
|
}
|
}
|
else {
|
showMsg("ÍøÂçÇëÇóʧ°Ü", MSG_TYPE_ERROR);
|
}
|
|
}
|
|
|
MainFrame* getWindowFrame() {
|
wxWindow* window = this->GetOwner()->GetOwner()->GetParent();
|
while (true) {
|
MainFrame* root = dynamic_cast<MainFrame*>(window);
|
if (root)
|
{
|
return root;
|
}
|
else {
|
window = window->GetParent();
|
}
|
}
|
}
|
|
void showMsg(string msg, MsgTypeEnum type) {
|
MainFrame* mainFrame = getWindowFrame();
|
if (mainFrame)
|
{
|
mainFrame->showMsg(msg, type);
|
}
|
}
|
|
/// <summary>
|
/// ²é¿´ÏêÇé
|
/// </summary>
|
/// <param name="code"></param>
|
static void viewDetail(wxString code) {
|
try {
|
Win32Util::addToTHS(code.ToStdString());
|
list<HWND> hwnds = Win32Util::searchWindow("¿´Å̸±ÆÁ");
|
if (hwnds.size() > 0) {
|
for (list<HWND>::iterator e = hwnds.begin(); e != hwnds.end(); ++e) {
|
HWND hwnd = *e;
|
ViewDetailData* data = new ViewDetailData();
|
data->code = code.ToStdString();
|
SendMessage(hwnd, WM_USER + 1024, 0, reinterpret_cast<LPARAM>(&data));
|
}
|
}
|
}
|
catch (...) {
|
}
|
}
|
|
|
// µã»÷ʼþ´¦Àí·½·¨
|
bool ActivateCell(const wxRect& WXUNUSED(cell), wxDataViewModel* WXUNUSED(model), const wxDataViewItem& WXUNUSED(item), unsigned int WXUNUSED(col), const wxMouseEvent* mouseEvent) override {
|
// ´¦Àíµã»÷ʼþ
|
if (mouseEvent->LeftDown()) {
|
BtnClickType clickType = getClickType(mouseEvent->GetX(), mouseEvent->GetY());
|
switch (clickType)
|
{
|
case CLICK_TYPE_CANCEL_BUY:
|
|
cancelOrder(delegateInfo.code.ToStdString());
|
break;
|
case CLICK_TYPE_VIEW_DETAIL:
|
try {
|
thread t(viewDetail, delegateInfo.code);
|
t.detach();
|
}
|
catch (string msg) {
|
wxMessageBox(msg.c_str());
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
if (mouseEvent->LeftDClick()) {
|
BtnClickType clickType = getClickType(mouseEvent->GetX(), mouseEvent->GetY());
|
if (clickType == CLICK_TYPE_QUEUE)
|
{
|
|
WindowPosSize r = MyConfigUtil::getTradeQueueWindowPos();
|
if (r.x == -1 && r.y == -1 && r.width == -1 && r.height == -1) {
|
// ĬÈϵijߴçÓëλÖÃ
|
HWND framePos = GetOwner()->GetOwner()->GetParent()->GetHandle();
|
RECT rect;
|
Win32Util::getWindowRect(framePos, &rect);
|
|
TradeQueueFrame* tradeQueueFrame = new TradeQueueFrame(delegateInfo.codeName, delegateInfo.code, wxPoint(rect.left, rect.top), wxSize(350, 400));
|
tradeQueueFrame->Show(true);
|
}
|
else {
|
TradeQueueFrame* tradeQueueFrame = new TradeQueueFrame(delegateInfo.codeName, delegateInfo.code, wxPoint(r.x, r.y), wxSize(r.width, r.height));
|
tradeQueueFrame->Show(true);
|
}
|
// ĬÈϲ鿴
|
try {
|
thread t(Win32Util::addToTHS, delegateInfo.code.ToStdString());
|
t.detach();
|
}
|
catch (...) {
|
}
|
|
|
|
}
|
}
|
|
|
return false; // ·µ»Ø true ±íʾÒѾ´¦ÀíÁ˵ã»÷ʼþ
|
}
|
|
virtual wxSize GetSize() const
|
{
|
// ·µ»Ø°´Å¥µÄ´óС
|
return wxSize(ROW_WIDTH_DELEGATE_INFO, ROW_HEIGHT);
|
}
|
|
virtual bool SetValue(const wxVariant& value) {
|
wxString id = value;
|
delegateInfo = MainFrame::delegateMap[id];
|
return true;
|
}
|
|
virtual bool GetValue(wxVariant& value) const {
|
|
return true;
|
}
|
};
|
|
|
MainFrame::MainFrame(const wxString& title, wxPoint position, wxSize size) :wxFrame(NULL, wxID_ANY, title, position, size) {
|
|
// Öö¥
|
SetWindowStyle(GetWindowStyle() | wxSTAY_ON_TOP);
|
// ³õʼ»¯
|
killed = false;
|
Bind(wxEVT_CLOSE_WINDOW, &MainFrame::OnClose, this);
|
wxIcon icon;
|
icon.LoadFile("icon.ico", wxBITMAP_TYPE_ICO); // Ìæ»» "app_icon.ico" ΪÄãµÄÓ¦ÓóÌÐòͼ±êÎļþ·¾¶
|
SetIcon(icon);
|
|
SetTransparent(225);
|
|
|
wxPanel* panel = new wxPanel(this, wxID_ANY);
|
|
// ´´½¨ wxDataViewListCtrl ¿Ø¼þ
|
m_listCtrl = new wxDataViewListCtrl(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE | wxDV_NO_HEADER);
|
m_listCtrl->SetBackgroundColour(wxColor(242, 242, 242));
|
// °ó¶¨Ã»ÐеÄÑ¡ÖÐʼþ
|
m_listCtrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MainFrame::OnSelectionChanged, this);
|
|
|
// Ìí¼ÓÁÐ
|
auto bc = new DelegateInfoRenderer();
|
wxDataViewColumn* delegateColumn = new wxDataViewColumn("ίÍÐÐÅÏ¢", bc, 0, ROW_WIDTH_DELEGATE_INFO, wxALIGN_LEFT);
|
m_listCtrl->AppendColumn(delegateColumn);
|
|
|
m_listCtrl->SetRowHeight(ROW_HEIGHT);
|
|
// ÉèÖò¼¾Ö
|
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
|
|
// ÌáʾÐÅÏ¢
|
msgCtrl = new wxStaticText(panel, wxID_ANY, "");
|
|
wxButton* openTradeQueueBtn = new wxButton(panel, wxID_ANY, "²é¿´È«²¿");
|
|
|
avaiableMoneyLabel = new wxStaticText(panel, wxID_ANY, "0.00", wxDefaultPosition, wxSize(80 * DPI / 100, -1));
|
|
wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
topSizer->Add(msgCtrl, 1, wxEXPAND);
|
topSizer->Add(avaiableMoneyLabel, 0, wxEXPAND | wxALL, 3);
|
topSizer->Add(openTradeQueueBtn, 0);
|
|
|
sizer->Add(topSizer, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, 5);
|
sizer->Add(m_listCtrl, 1, wxEXPAND | wxALL, 5);
|
panel->SetSizerAndFit(sizer);
|
|
|
openTradeQueueBtn->Bind(wxEVT_BUTTON, &MainFrame::OnButtonOpenTradeQueueClick, this);
|
|
|
std::thread t1(startRequestDelegatedInfoListTask, this);
|
t1.detach();
|
}
|
|
void MainFrame::showMsg(string msg, MsgTypeEnum type)
|
{
|
// ÏÔʾ15s
|
msgExpireTime = TimeUtil::getNowTimeStamp() + 1000 * 15;
|
switch (type)
|
{
|
case MSG_TYPE_ERROR:
|
msgCtrl->SetForegroundColour(*wxGREEN);
|
break;
|
case MSG_TYPE_WARNING:
|
msgCtrl->SetForegroundColour(*wxGREEN);
|
break;
|
case MSG_TYPE_INFO:
|
msgCtrl->SetForegroundColour(*wxBLACK);
|
break;
|
default:
|
break;
|
}
|
msgCtrl->SetLabelText(msg);
|
// Æô¶¯Ï߳̽áÊøÏÔʾ
|
thread t(clearMsg, this);
|
t.detach();
|
}
|
|
|
void MainFrame::clearMsg(MainFrame* context)
|
{
|
Sleep(15 * 1000);
|
if (TimeUtil::getNowTimeStamp() > context->msgExpireTime) {
|
context->msgCtrl->SetLabelText("");
|
}
|
}
|
|
void MainFrame::OnClose(wxCloseEvent& event)
|
{
|
killed = true;
|
MyConfigUtil::setMainWindowPos(GetPosition(), GetSize());
|
event.Skip();
|
exit(0);
|
}
|
|
void MainFrame::refresh()
|
{
|
cout << "Ë¢ÐÂʱ¼ä£º" << TimeUtil::getNowTimeStamp() << " ÊýÁ¿£º" << delegateList.size() << endl;
|
m_listCtrl->DeleteAllItems();
|
for (list<DelegateInfo>::iterator e = delegateList.begin(); e != delegateList.end(); ++e) {
|
DelegateInfo info = *e;
|
delegateMap[info.id] = info;
|
wxVector<wxVariant> data;
|
data.push_back(info.id);
|
m_listCtrl->AppendItem(data);
|
}
|
m_listCtrl->Refresh();
|
}
|
|
DelegateResult MainFrame::parseDelegates(string result)
|
{
|
list<DelegateInfo> fresults;
|
wxString available_money = "";
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject() && doc[L"code"].GetInt() == 0) {
|
auto root = doc[L"data"].GetObject();
|
auto delegates = root[L"delegates"].GetArray();
|
double money = root[L"account_available_money"].GetDouble();
|
available_money = StringUtil::to_string(money);
|
for (int i = 0; i < delegates.Size(); i++) {
|
auto doc = delegates[i].GetObject();
|
|
auto array = doc[L"code_info"].GetArray();
|
DelegateInfo delegateInfo;
|
delegateInfo.index = i;
|
delegateInfo.id = doc[L"id"].GetString();
|
delegateInfo.code = array[0].GetString();
|
delegateInfo.codeName = array[1].GetString();
|
|
delegateInfo.buy1_money = doc[L"buy1_money"].GetString();
|
delegateInfo.big_num_count = doc[L"big_num_count"].GetInt();
|
delegateInfo.big_num_money = doc[L"big_num_money"].GetString();
|
array = doc[L"not_deal_big_num_count"].GetArray();
|
|
delegateInfo.not_deal_big_num_count_pre = array[0].GetInt();
|
delegateInfo.not_deal_total_big_count_after = array[1].GetInt();
|
|
array = doc[L"not_deal_big_num_money"].GetArray();
|
|
delegateInfo.not_deal_big_num_money_pre = array[0].GetString();
|
delegateInfo.not_deal_big_num_money_after = array[1].GetString();
|
delegateInfo.left_count = doc[L"left_count"].GetInt();
|
delegateInfo.left_money = doc[L"left_money"].GetString();
|
delegateInfo.volume_rate = doc[L"volume_rate"].GetFloat();
|
delegateInfo.pay_attention = doc[L"pay_attention"].GetBool();
|
delegateInfo.trade_progress_percent = doc[L"trade_progress_percent"].GetFloat();
|
delegateInfo.limit_up_price = doc[L"limit_up_price"].GetFloat();
|
delegateInfo.is_near_big_order = doc[L"is_near_big_order"].GetString();
|
delegateInfo.block = doc[L"block"].GetString();
|
if (doc.HasMember(L"limit_up_time")) {
|
delegateInfo.limit_up_time = doc[L"limit_up_time"].GetString();
|
}
|
|
array = doc[L"trade_queue"].GetArray();
|
list<TradeQueue> queueList;
|
for (int j = 0; j < array.Size(); j++) {
|
int num = array[j].GetArray()[0].GetInt();
|
int type = array[j].GetArray()[1].GetInt();
|
queueList.push_back(TradeQueue({ to_string(num),type }));
|
}
|
delegateInfo.tradeQueueList = queueList;
|
|
if (doc.HasMember(L"zyltgb"))
|
delegateInfo.zyltgb = doc[L"zyltgb"].GetString();
|
|
fresults.push_back(delegateInfo);
|
}
|
}
|
else {
|
throw string("ÍøÂçÇëÇó³ö´í");
|
}
|
return DelegateResult({ fresults ,available_money });
|
}
|
|
void MainFrame::startRequestDelegatedInfoListTask(MainFrame* context)
|
{
|
while (TRUE) {
|
try {
|
while (TRUE) {
|
if (context->killed) {
|
break;
|
}
|
try {
|
context->requestDelegatedInfoList();
|
}
|
catch (string st) {
|
|
}
|
catch (...) {
|
}
|
Sleep(2000);
|
}
|
}
|
catch (...) {
|
|
}
|
}
|
}
|
|
void MainFrame::requestDelegatedInfoList()
|
{
|
try {
|
auto start_time = TimeUtil::getNowTimeStamp();
|
string result = MyNetworkApi::get_delegated_buy_code_infos();
|
if (killed) {
|
return;
|
}
|
|
cout << "ÇëÇóίÍÐÁбíºÄʱ£º" << TimeUtil::getNowTimeStamp() - start_time << endl;
|
start_time = TimeUtil::getNowTimeStamp();
|
|
auto doc = JsonUtil::parseUTF8(result);
|
auto delegateResult = parseDelegates(result);
|
cout << "½âÎöÊý¾ÝºÄʱ£º" << TimeUtil::getNowTimeStamp() - start_time << endl;
|
start_time = TimeUtil::getNowTimeStamp();
|
// ¸ù¾ÝID
|
if (this != nullptr) {
|
this->delegateList = delegateResult.delegates;
|
this->avaiableMoneyLabel->SetLabelText(delegateResult.money);
|
this->refresh();
|
cout << "Ë¢ÐÂUIºÄʱ£º" << TimeUtil::getNowTimeStamp() - start_time << endl;
|
}
|
}
|
catch (string st) {
|
|
}
|
|
}
|
|
void MainFrame::OnSelectionChanged(wxDataViewEvent& event)
|
{
|
// ²»ÔÊÐíÏìÓ¦
|
event.Veto();
|
}
|
|
void MainFrame::OnButtonOpenTradeQueueClick(wxCommandEvent& event)
|
{
|
if (delegateList.size() > 0) {
|
WindowPosSize r = MyConfigUtil::getTradeQueueWindowPos();
|
if (r.x == -1 && r.y == -1) {
|
r.x = 0;
|
r.y = 0;
|
r.width = 400;
|
r.height = 400;
|
}
|
for (list<DelegateInfo>::iterator e = delegateList.begin(); e != delegateList.end(); ++e) {
|
auto delegateInfo = *e;
|
TradeQueueFrame* tradeQueueFrame = new TradeQueueFrame(delegateInfo.codeName, delegateInfo.code, wxPoint(r.x, r.y), wxSize(r.width, r.height));
|
tradeQueueFrame->Show(true);
|
}
|
}
|
|
|
|
}
|