From 8ea6d363df77de2dca288397da8d4f9c3d3a5c4d Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 18 十月 2024 18:41:57 +0800 Subject: [PATCH] '项目完善' --- CBTrade/MyConfigUtil.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-) diff --git a/CBTrade/MyConfigUtil.cpp b/CBTrade/MyConfigUtil.cpp index 3a63734..d828dbf 100644 --- a/CBTrade/MyConfigUtil.cpp +++ b/CBTrade/MyConfigUtil.cpp @@ -1,6 +1,7 @@ #include "MyConfigUtil.h" #include "../common_nopch/JsonUtil.h" #include <wx/wx.h> +#include <map> JueJinParams MyConfigUtil::getJueJinParams() { @@ -61,6 +62,29 @@ } } +int MyConfigUtil::getSellMoney(string code) +{ + try { + string value = readStringConfig("sell_codes_money"); + std::map<string, int> codeMoneyMap; + if (!value.empty()) { + auto doc = JsonUtil::parseUTF8(value); + for (auto itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) { + // itr->name is the key, itr->value is the value corresponding to the key + codeMoneyMap[itr->name.GetString()] = itr->value.GetInt(); + } + } + + if (codeMoneyMap.find(code) != codeMoneyMap.end()) { + return codeMoneyMap[code]; + } + } + catch (...) { + } + + return getSellMoney(); +} + void MyConfigUtil::setSellMoney(int money) { setIntConfig("sell_money", money); @@ -68,6 +92,42 @@ } +void MyConfigUtil::setSellMoney(string code, int money) +{ + string value = ""; + try { + value = readStringConfig("sell_codes_money"); + } + catch (...) { + + } + std::map<string, int> codeMoneyMap; + if (!value.empty()) { + auto doc = JsonUtil::parseUTF8(value); + for (auto itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) { + // itr->name is the key, itr->value is the value corresponding to the key + codeMoneyMap[itr->name.GetString()] = itr->value.GetInt(); + } + } + + codeMoneyMap[code] = money; + rapidjson::StringBuffer buf; + rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf); + writer.StartObject(); + for (std::map<string, int>::iterator e = codeMoneyMap.begin(); e != codeMoneyMap.end(); ++e) { + writer.Key((*e).first.c_str()); + writer.Int((*e).second); + } + writer.EndObject(); + const char* json_content = buf.GetString(); + setStringConfig("sell_codes_money", json_content); +} + +void MyConfigUtil::clearCodesSellMoney() +{ + setStringConfig("sell_codes_money", ""); +} + void MyConfigUtil::setMainWindowPos(wxPoint point, wxSize size) { rapidjson::StringBuffer buf; -- Gitblit v1.8.0