diff --git a/bin/Release/EES.exe b/bin/Release/EES.exe index 8f5d138..6208d1e 100644 Binary files a/bin/Release/EES.exe and b/bin/Release/EES.exe differ diff --git a/bin/Release/assets/pv/bkg.png b/bin/Release/assets/pv/bkg.png new file mode 100644 index 0000000..7eccde3 Binary files /dev/null and b/bin/Release/assets/pv/bkg.png differ diff --git a/bin/Release/assets/pv/bkgBox.png b/bin/Release/assets/pv/bkgBox.png new file mode 100644 index 0000000..f343025 Binary files /dev/null and b/bin/Release/assets/pv/bkgBox.png differ diff --git a/bin/Release/assets/pv/downFill.png b/bin/Release/assets/pv/downFill.png new file mode 100644 index 0000000..f4fb0ab Binary files /dev/null and b/bin/Release/assets/pv/downFill.png differ diff --git a/bin/Release/assets/pv/headbkg.png b/bin/Release/assets/pv/headbkg.png new file mode 100644 index 0000000..3d1d165 Binary files /dev/null and b/bin/Release/assets/pv/headbkg.png differ diff --git a/bin/Release/assets/pv/icon1.png b/bin/Release/assets/pv/icon1.png new file mode 100644 index 0000000..0f67e73 Binary files /dev/null and b/bin/Release/assets/pv/icon1.png differ diff --git a/bin/Release/assets/pv/icon2.png b/bin/Release/assets/pv/icon2.png new file mode 100644 index 0000000..a466786 Binary files /dev/null and b/bin/Release/assets/pv/icon2.png differ diff --git a/bin/Release/assets/pv/icon3.png b/bin/Release/assets/pv/icon3.png new file mode 100644 index 0000000..910c542 Binary files /dev/null and b/bin/Release/assets/pv/icon3.png differ diff --git a/bin/Release/assets/pv/icon4.png b/bin/Release/assets/pv/icon4.png new file mode 100644 index 0000000..3bc4e6d Binary files /dev/null and b/bin/Release/assets/pv/icon4.png differ diff --git a/bin/Release/assets/pv/icon5.png b/bin/Release/assets/pv/icon5.png new file mode 100644 index 0000000..3803d35 Binary files /dev/null and b/bin/Release/assets/pv/icon5.png differ diff --git a/bin/Release/assets/pv/map.png b/bin/Release/assets/pv/map.png new file mode 100644 index 0000000..b7389cd Binary files /dev/null and b/bin/Release/assets/pv/map.png differ diff --git a/bin/Release/assets/pv/mapMarker.png b/bin/Release/assets/pv/mapMarker.png new file mode 100644 index 0000000..8001cb6 Binary files /dev/null and b/bin/Release/assets/pv/mapMarker.png differ diff --git a/bin/Release/assets/pv/pv.bkg.main2.png b/bin/Release/assets/pv/pv.bkg.main2.png new file mode 100644 index 0000000..53a44eb Binary files /dev/null and b/bin/Release/assets/pv/pv.bkg.main2.png differ diff --git a/bin/Release/assets/pv/red.png b/bin/Release/assets/pv/red.png new file mode 100644 index 0000000..c90028d Binary files /dev/null and b/bin/Release/assets/pv/red.png differ diff --git a/src/app/AppData.cpp b/src/app/AppData.cpp index 404de1f..85e8996 100644 --- a/src/app/AppData.cpp +++ b/src/app/AppData.cpp @@ -1,6 +1,91 @@ #include "AppData.h" - +#include "common/Utils.h" #include "app/Station.h" +#include "app/Device.h" +#include "database/Dao.h" + + +void InitStation(AppData* appdata) +{ + // 读取数据库 + std::vector result; + DAO::queryStationList(NULL, result); + for (auto& fields: result) + { + int stationId = fields.getInt(DMStation::STATION_ID); + auto station = std::make_shared(stationId); + station->name = fields.value(DMStation::NAME); + station->energyCapacity = fields.getDouble(DMStation::CAPACITY); + appdata->mapStation[stationId] = station; + } +} + +void InitDevice(AppData* appdata) +{ + vector result; + DAO::queryDeviceList(NULL, result); + for (auto& fields: result) + { + int deviceId = fields.getInt(DMDevice::DEVICE_ID); + int stationId = fields.getInt(DMDevice::STATION_ID); + auto station = appdata->getStation(stationId); + if (station) + { + auto device = Device::create(fields); + station->addDevice(deviceId, device); + } + else + { + XLOGE() << "init device error: unknown station_id:[" << stationId << "] device_id=" << deviceId; + } + } +} + +void InitStatData(AppData* appdata) +{ + std::string curDate = Utils::dateStr(); + vector result; + DAO::queryStatDataList(curDate, curDate, result); + for (auto& fields: result) + { + std::string dt = fields.value(DMStatStation::DT); + int stationId = fields.getInt(DMStatStation::STATION_ID); + auto station = appdata->getStation(stationId); + if (station) + { + station->storageIn = fields.getFloat(DMStatStation::STORAGE_ELECT_IN); + station->storageOut = fields.getFloat(DMStatStation::STORAGE_ELECT_OUT); + //station->storageNumIn = fields.getFloat(DMStatStation::STORAGE_NUM); + //station->storageNumOut = fields.getFloat(DMStatStation::STORAGE_NUM); + station->storageNumErr = fields.getFloat(DMStatStation::STORAGE_NUM_ERR); + + station->solarGen = fields.getFloat(DMStatStation::SOLAR_ELECT_GEN); + station->solarGrid = fields.getFloat(DMStatStation::SOLAR_ELECT_GRID); + station->solarNumErr = fields.getFloat(DMStatStation::SOLAR_NUM_ERR); + + station->chargeElect = fields.getFloat(DMStatStation::CHARGE_ELECT); + station->chargeNum = fields.getFloat(DMStatStation::CHARGE_NUM); + station->chargeNumErr = fields.getFloat(DMStatStation::CHARGE_NUM_ERR); + } + else + { + XLOGE() << "init staticis data error: unknown station_id:[" << stationId << "] dt=" << dt; + } + } + +} + +void AppData::init() +{ + // 初始化场站信息 + InitStation(this); + // 读取设备信息,连接设备 + InitDevice(this); + // 读取基础统计信息,在系统总览中需要展示 + InitStatData(this); + + this->initUser(); +} std::shared_ptr AppData::getStation(int stationId) { @@ -24,15 +109,6 @@ std::shared_ptr AppData::getStationByName(std::string name) return nullptr; } -void AppData::getStationNames(std::vector& vecNames) -{ - vecNames.resize(mapStation.size()); - int i = 0; - for (auto iter = mapStation.begin(); iter!=mapStation.end(); ++iter) - { - vecNames[i] = iter->second->name; - } -} std::shared_ptr AppData::getDevice(int stationId, int deviceId) { @@ -44,6 +120,80 @@ std::shared_ptr AppData::getDevice(int stationId, int deviceId) return nullptr; } +std::unordered_map>& AppData::getDeviceTypeDef() +{ + return mapDeviceType; +} + void AppData::loadStatData() { +} + + +void AppData::initUser() +{ + auto dao = DaoEntity::create(""); + std::vector result; + + // 数据库读取角色定义 + mapping.role.clear(); + DAO::queryRoleList(dao, result); + for (auto& fields : result) + { + auto item = std::make_shared(); + item->roleId = fields.getInt(DMRole::ROLE_ID); + item->name = fields.value(DMRole::NAME); + item->isOpen = fields.getInt(DMRole::IS_OPEN); + mapRole[item->roleId] = item; + mapping.role.push_back({std::to_string(item->roleId), item->name}); + } + + // 数据库读取设备类型定义 + result.clear(); + DAO::queryDeviceTypeDef(dao, result); + for (auto& fields : result) + { + auto item = std::make_shared() ; + item->typeId = fields.getInt(DMDeviceTypeDef::TYPE_ID); + item->name = fields.value(DMDeviceTypeDef::NAME); + item->attrs = fields.value(DMDeviceTypeDef::ATTRS); + mapDeviceType[item->typeId] = item; + mapping.deviceType.push_back({std::to_string(item->typeId), item->name}); + } +} + +std::vector AppData::getRoleNames() +{ + std::vector vec(mapRole.size()); + int i = 0; + for (auto iter = mapRole.begin(); iter!=mapRole.end(); ++iter) + { + vec[i] = iter->second->name; + ++i; + } + return vec; +} + +std::vector AppData::getStationNames() +{ + std::vector vec(mapStation.size()); + int i = 0; + for (auto iter = mapStation.begin(); iter!=mapStation.end(); ++iter) + { + vec[i] = iter->second->name; + ++i; + } + return vec; +} + +std::vector AppData::getDeviceTypes() +{ + std::vector vec(mapping.deviceType.size()); + int i = 0; + for (auto iter = mapping.deviceType.begin(); iter!=mapping.deviceType.end(); ++iter) + { + vec[i] = iter->second; + ++i; + } + return vec; } \ No newline at end of file diff --git a/src/app/AppData.h b/src/app/AppData.h index b285c76..cae0f82 100644 --- a/src/app/AppData.h +++ b/src/app/AppData.h @@ -9,20 +9,51 @@ class Station; class Device; +using VecPairSS = std::vector>; + +struct DeviceType +{ + int typeId {}; + std::string name; + std::string attrs; +}; + +struct Role +{ + int roleId {}; + std::string name; + bool isOpen {false}; +}; + class AppData { public: + void init(); + + std::shared_ptr getStation(int stationId); std::shared_ptr getStationByName(std::string name); - void getStationNames(std::vector& vecNames); + std::shared_ptr getDevice(int stationId, int deviceId); + /////////////////////////////////////////////////////////////////////////////////////////////// + // 获取角色名称列表 + std::vector getRoleNames(); + // 获取场站名称列表 + std::vector getStationNames(); + // 获取设备类型 + std::vector getDeviceTypes(); + + // 获取设备类型定义 + std::unordered_map>& getDeviceTypeDef(); + // 读取统计数据: 今日统计数据,累计统计数据 void loadStatData(); + void initUser(); public: /////////////////////////////////////////////////////////////////////////////////////////////// @@ -38,11 +69,26 @@ public: std::string passwd; } db; + struct { + VecPairSS isopen {{"0", "禁用"}, {"1", "启用"}}; + VecPairSS gender {{"0", "女"}, {"1", "男"}}; + // 角色 Mapping (id->name) + VecPairSS role; + + VecPairSS deviceType; + + } mapping; + + /////////////////////////////////////////////////////////////////////////////////////////////// // === 场站信息 === std::unordered_map> mapStation; /////////////////////////////////////////////////////////////////////////////////////////////// // === 角色定义 === + std::unordered_map> mapRole; + /////////////////////////////////////////////////////////////////////////////////////////////// + // === 设备类型定义 === + std::unordered_map> mapDeviceType; }; diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 24b2a1d..d8677c3 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -8,82 +8,6 @@ #include "app/Station.h" #include "app/Device.h" -void InitStation() -{ - AppData& appdata = Application::instance().getAppData(); - - // 读取数据库 - std::vector result; - DAO::queryStationList(result); - for (auto& fields: result) - { - int stationId = fields.getInt(DMStation::STATION_ID); - auto station = std::make_shared(stationId); - station->name = fields.getStr(DMStation::NAME); - station->energyCapacity = fields.getDouble(DMStation::CAPACITY); - appdata.mapStation[stationId] = station; - } -} - -void InitDevice() -{ - AppData& appdata = Application::instance().getAppData(); - - vector result; - DAO::queryDeviceList(result); - for (auto& fields: result) - { - int deviceId = fields.getInt(DMDevice::DEVICE_ID); - int stationId = fields.getInt(DMDevice::STATION_ID); - auto station = appdata.getStation(stationId); - if (station) - { - auto device = Device::create(fields); - station->addDevice(deviceId, device); - } - else - { - XLOGE() << "init device error: unknown station_id:[" << stationId << "] device_id=" << deviceId; - } - } -} - -void InitStatData() -{ - AppData& appdata = Application::instance().getAppData(); - - std::string curDate = Utils::dateStr(); - vector result; - DAO::queryStatDataList(curDate, curDate, result); - for (auto& fields: result) - { - std::string dt = fields.getStr(DMStatStation::DT); - int stationId = fields.getInt(DMStatStation::STATION_ID); - auto station = appdata.getStation(stationId); - if (station) - { - station->storageIn = fields.getFloat(DMStatStation::STORAGE_ELECT_IN); - station->storageOut = fields.getFloat(DMStatStation::STORAGE_ELECT_OUT); - //station->storageNumIn = fields.getFloat(DMStatStation::STORAGE_NUM); - //station->storageNumOut = fields.getFloat(DMStatStation::STORAGE_NUM); - station->storageNumErr = fields.getFloat(DMStatStation::STORAGE_NUM_ERR); - - station->solarGen = fields.getFloat(DMStatStation::SOLAR_ELECT_GEN); - station->solarGrid = fields.getFloat(DMStatStation::SOLAR_ELECT_GRID); - station->solarNumErr = fields.getFloat(DMStatStation::SOLAR_NUM_ERR); - - station->chargeElect = fields.getFloat(DMStatStation::CHARGE_ELECT); - station->chargeNum = fields.getFloat(DMStatStation::CHARGE_NUM); - station->chargeNumErr = fields.getFloat(DMStatStation::CHARGE_NUM_ERR); - } - else - { - XLOGE() << "init staticis data error: unknown station_id:[" << stationId << "] dt=" << dt; - } - } - -} - void Application::init() { // 初始化系统配置,读取配置文件 @@ -102,12 +26,8 @@ void Application::init() // 连接数据库,读取基础信息 - // 初始化场站信息 - InitStation(); - // 读取设备信息,连接设备 - InitDevice(); - // 读取基础统计信息,在系统总览中需要展示 - InitStatData(); + // 初始化系统基础数据 + appdata_.init(); // 创建设备处理线程 std::thread([=]() { runThreadDevice(); }).detach(); @@ -116,10 +36,6 @@ void Application::init() std::thread([=]() { runThreadMain(); }).detach(); } -AppData& Application::getAppData() -{ - return appdata_; -} void Application::runThreadMain() { diff --git a/src/app/Application.h b/src/app/Application.h index 2743bc0..6b8b316 100644 --- a/src/app/Application.h +++ b/src/app/Application.h @@ -15,10 +15,13 @@ public: return app; } + static AppData& data() + { + return Application::instance().appdata_; + } + void init(); - AppData& getAppData(); - bool isQuit() { return isQuit_; } Operator& getOperator() { return op_; } diff --git a/src/app/Dao1.cpp b/src/app/Dao1.cpp index e7a5a1b..09ffaab 100644 --- a/src/app/Dao1.cpp +++ b/src/app/Dao1.cpp @@ -10,12 +10,12 @@ enum class EnDatabaseErr SUCCESS = 0, }; -std::shared_ptr DAO::get(std::string tableName) +std::shared_ptr DAO1::get(std::string tableName) { return std::make_shared(tableName); } -Errcode DAO::login(std::shared_ptr dao, std::string account, std::string passwd, std::string& err) +Errcode DAO1::login(std::shared_ptr dao, std::string account, std::string passwd, std::string& err) { std::string t = Utils::timeStr(); if (!dao) @@ -25,35 +25,35 @@ Errcode DAO::login(std::shared_ptr dao, std::string account, std::str if (!dao->isConnected()) { err = "数据库连接错误"; - DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err); + DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err); return Errcode::ERR_DB_CONN; } std::string sql = "SELECT * FROM user WHERE account='" + account + "';"; - std::vector res; + std::vector res; bool ret = dao->exec(sql, res); if (!ret) { err = "数据库操作错误"; - DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err); + DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err); return Errcode::ERR_DB_CONN; } if (res.size() <=0) { err = "用户不存在"; - DAO::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err); + DAO1::writeSystemLog(dao, 2, "", account, "用户登录失败:" + err); return Errcode::ERR_LOGIN_USER_NOTEXIST; } - DataFields& fields = res[0]; - std::string userId = fields.getStr("user_id"); + Fields& fields = res[0]; + std::string userId = fields.value("user_id"); int loginCount = fields.getInt("login_count"); // 判断密码 - if (passwd != fields.getStr("passwd")) + if (passwd != fields.value("passwd")) { err = "密码错误"; - DAO::writeSystemLog(dao, 2, userId, account, "用户登录失败:" + err); + DAO1::writeSystemLog(dao, 2, userId, account, "用户登录失败:" + err); return Errcode::ERR_LOGIN_PASSWD; } @@ -67,11 +67,11 @@ Errcode DAO::login(std::shared_ptr dao, std::string account, std::str XLOGE() << "更新用户登录信息失败:sql=" << sql; } - DAO::writeSystemLog(dao, 2, userId, account, "用户登录成功"); + DAO1::writeSystemLog(dao, 2, userId, account, "用户登录成功"); return Errcode::OK; } -bool DAO::writeSystemLog(std::shared_ptr dao, int type, std::string userId, std::string account, std::string text) +bool DAO1::writeSystemLog(std::shared_ptr dao, int type, std::string userId, std::string account, std::string text) { if (!dao) { @@ -84,7 +84,7 @@ bool DAO::writeSystemLog(std::shared_ptr dao, int type, std::string u // 数据库写入登录日志 dao->setTableName("system_log"); - DataFields fieldsLog; + Fields fieldsLog; fieldsLog.set("log_id", Snowflake::instance().getIdStr()); fieldsLog.set("type", 2); fieldsLog.set("user_id", userId); @@ -96,7 +96,7 @@ bool DAO::writeSystemLog(std::shared_ptr dao, int type, std::string u } -bool DAO::queryUser(std::vector& res) +bool DAO1::queryUser(std::vector& res) { std::shared_ptr dao = std::make_shared(""); if (!dao->isConnected()) @@ -108,7 +108,7 @@ bool DAO::queryUser(std::vector& res) return ret; } -int DAO::insertUser(DataFields& fields) +int DAO1::insertUser(Fields& fields) { std::shared_ptr dao = std::make_shared("user"); if (!dao->isConnected()) @@ -116,10 +116,10 @@ int DAO::insertUser(DataFields& fields) return 1; } - std::string account = fields.getStr("account"); + std::string account = fields.value("account"); // step1: 查询 - std::vector res; + std::vector res; bool ret = dao->exec("SELECT * from user WHERE account='" + account + "';", res); if (!ret) { @@ -136,7 +136,7 @@ int DAO::insertUser(DataFields& fields) return (ret) ? 0 : 1; } -int DAO::updateUserById(std::string id, DataFields& fields) +int DAO1::updateUserById(std::string id, Fields& fields) { std::shared_ptr dao = std::make_shared("user"); if (!dao->isConnected()) diff --git a/src/app/Dao1.h b/src/app/Dao1.h index a95f15e..9e9f0cd 100644 --- a/src/app/Dao1.h +++ b/src/app/Dao1.h @@ -2,7 +2,7 @@ #include "app/errcode.h" -class DAO +class DAO1 { public: static std::shared_ptr get(std::string tableName=""); @@ -18,15 +18,15 @@ public: /** * 查询用户 */ - static bool queryUser(std::vector& res); + static bool queryUser(std::vector& res); /** * 新增用户 */ - static int insertUser(DataFields& fields); + static int insertUser(Fields& fields); /** * 修改用户信息 */ - static int updateUserById(std::string id, DataFields& fields); + static int updateUserById(std::string id, Fields& fields); }; \ No newline at end of file diff --git a/src/app/Device.cpp b/src/app/Device.cpp index 642ebd6..8732e9a 100644 --- a/src/app/Device.cpp +++ b/src/app/Device.cpp @@ -45,7 +45,7 @@ int Device::startComm() } // 从属性列表中获取通讯方式和通讯地址、端口 - std::string commType = attrs.getStr("commType"); + std::string commType = attrs.value("commType"); // 如果entity的通讯协议类型当前配置不一致,需要关闭连接删除通讯后创建新的通讯 if (commEntity && commEntity->type != commType) @@ -64,15 +64,15 @@ int Device::startComm() return 0; } -std::shared_ptr Device::create(DataFields& fields) +std::shared_ptr Device::create(Fields& fields) { auto device = std::make_shared(); device->deviceId = fields.getInt("device_id"); device->type = fields.getInt("type"); - device->name = fields.getStr("name"); - device->code = fields.getStr("code"); + device->name = fields.value("name"); + device->code = fields.value("code"); device->isOpen = fields.getInt("is_open"); - device->attrsJson = fields.getStr("attrs"); + device->attrsJson = fields.value("attrs"); // 解析属性的JSON字符串,转换成键值对 NJson jsonroot; diff --git a/src/app/Device.h b/src/app/Device.h index 43a90fc..12629fa 100644 --- a/src/app/Device.h +++ b/src/app/Device.h @@ -5,7 +5,7 @@ #include #include -#include +#include "common/Fields.h" class CommEntity; @@ -26,7 +26,7 @@ public: //std::map mapAttrs; - DataFields attrs; + Fields attrs; // 通讯entity std::shared_ptr commEntity; @@ -39,7 +39,7 @@ public: // 启动通讯 int startComm(); - static std::shared_ptr create(DataFields& fields); + static std::shared_ptr create(Fields& fields); }; diff --git a/src/app/errcode.h b/src/app/errcode.h index 689445d..f308f47 100644 --- a/src/app/errcode.h +++ b/src/app/errcode.h @@ -8,8 +8,9 @@ enum class Errcode ERR_DB_CONN = 101, // 数据库连接错误 ERR_DB_SQL = 102, // 数据库查询SQL错误 + ERR_DB_DUPLICATE, // 数据重复 - ERR_LOGIN_USER_NOTEXIST = 103, // 登入错误,用户不存在 - ERR_LOGIN_PASSWD = 104, // 登入错误,密码不正确 + ERR_LOGIN_USER_NOTEXIST, // 登入错误,用户不存在 + ERR_LOGIN_PASSWD, // 登入错误,密码不正确 }; \ No newline at end of file diff --git a/src/common/DataFields.cpp b/src/common/DataFields.cpp deleted file mode 100644 index 8f4fa82..0000000 --- a/src/common/DataFields.cpp +++ /dev/null @@ -1,204 +0,0 @@ -#include "DataFields.h" -#include "common/Utils.h" - -void DataFields::set(string key, string val) -{ - mapFields_[key] = val; -} -void DataFields::set(string key, float val) -{ - mapFields_[key] = std::to_string(val); -} -void DataFields::set(string key, int val) -{ - mapFields_[key] = std::to_string(val); -} -void DataFields::set(string key, int64_t val) -{ - mapFields_[key] = std::to_string(val); -} -string DataFields::getStr(string key) -{ - if (mapFields_.count(key) > 0) - { - return mapFields_[key]; - } - else - { - return ""; - } -} -int DataFields::getInt(string key) -{ - return mapFields_.count(key) > 0 ? Utils::toInt(mapFields_[key]) : 0; -} - -float DataFields::getFloat(string key) -{ - return mapFields_.count(key) > 0 ? Utils::toFloat(mapFields_[key]) : 0.0f; -} - -double DataFields::getDouble(string key) -{ - return mapFields_.count(key) > 0 ? Utils::toDouble(mapFields_[key]) : 0.0; -} - -void DataFields::remove(string key) -{ - auto it = mapFields_.find(key); - if (it != mapFields_.end()) - { - mapFields_.erase(it); - } -} -void DataFields::append(DataFields& datafield) -{ - auto& map_f = datafield.fields(); - for (auto it = map_f.begin(); it != map_f.end(); it++) - { - mapFields_[it->first] = it->second; - } -} -map& DataFields::fields() -{ - return mapFields_; -} - -void DataFields::check(string key, string val, string d) -{ - if (mapFields_.count(key) > 0 && mapFields_[key] == val) - { - mapFields_[key] = d; - } -} - -string DataFields::get_insert_sql(string tbname) -{ - string key; - string val; - for (auto it = mapFields_.begin(); it != mapFields_.end(); it++) - { - if (!key.empty()) - { - key += ","; - val += ","; - } - key += ("`" + it->first + "`"); - if (it->second == "null" || it->second == "NULL") - { - val += "NULL"; - } - else - { - val += ("'" + it->second + "'"); - } - } - return "INSERT INTO `" + tbname + "` (" + key + ") VALUES(" + val + ");"; -} - -string DataFields::get_update_sql(string tbname, string sql_c) -{ - ostringstream oss; - oss << "update " << tbname << " set "; - for (auto iter = mapFields_.begin(); iter != mapFields_.end(); iter++) - { - if (iter != mapFields_.begin()) - { - oss << ","; - }; - oss << "`" << iter->first << "`="; - if (iter->second == "null" || iter->second == "NULL") - { - oss << "NULL"; - } - else - { - oss << "'" << iter->second << "'"; - } - } - oss << " " << sql_c << ";"; - return oss.str(); -} - -string DataFields::get_update_sql(string tbname, std::vector vec_keys, string sql_c) -{ - std::map map_keys; - for (auto& k : vec_keys) { map_keys[k] = true; } - - ostringstream oss; - oss << "update " << tbname << " set "; - for (auto iter = mapFields_.begin(); iter != mapFields_.end(); iter++) - { - auto& k = iter->first; - auto& v = iter->second; - if (!map_keys[k]) { continue; } - if (iter != mapFields_.begin()) - { - oss << ","; - }; - oss << "`" << k << "`="; - if (v == "null" || v == "NULL") - { - oss << "NULL"; - } - else - { - oss << "'" << v << "'"; - } - } - oss << " " << sql_c << ";"; - return oss.str(); -} - -void DataFields::foreachItem(function on_foraach) -{ - for (auto it = mapFields_.begin(); it != mapFields_.end(); it++) - { - if (on_foraach) - { - on_foraach(it->first, it->second); - } - } -} -bool DataFields::isEmpty(string key) -{ - auto& s = mapFields_[key]; - return s.empty(); -} - -bool DataFields::is_float_number(string key) -{ - auto& s = mapFields_[key]; - if (s.empty()) - { - return false; - } - for (auto& c : s) - { - if (std::isdigit(c) == 0 && c != '.') - { - return false; - } - } - return true; -} - -string DataFields::toStr() -{ - string s; - for (auto it = mapFields_.begin(); it != mapFields_.end(); it++) - { - s += ("{" + it->first + ":" + it->second + "} "); - } - return s; -} - -int DataFields::size() -{ - return mapFields_.size(); -} - -void DataFields::clear() -{ - mapFields_.clear(); -} \ No newline at end of file diff --git a/src/common/Fields.cpp b/src/common/Fields.cpp new file mode 100644 index 0000000..2c3680c --- /dev/null +++ b/src/common/Fields.cpp @@ -0,0 +1,213 @@ +#include "Fields.h" +#include "common/Utils.h" + +void Fields::set(string key, string val) +{ + mapFields[key] = val; +} +void Fields::set(string key, float val) +{ + mapFields[key] = std::to_string(val); +} +void Fields::set(string key, int val) +{ + mapFields[key] = std::to_string(val); +} +void Fields::set(string key, int64_t val) +{ + mapFields[key] = std::to_string(val); +} +std::string& Fields::value(std::string key) +{ + static std::string tmp; + auto it = mapFields.find(key); + return (it != mapFields.end()) ? it->second : (tmp = ""); +} + +//string Fields::getStr(string key) +//{ +// return (mapFields.count(key) > 0) ? mapFields[key] : ""; +//} + +int Fields::getInt(string key) +{ + return mapFields.count(key) > 0 ? Utils::toInt(mapFields[key]) : 0; +} + +float Fields::getFloat(string key) +{ + return mapFields.count(key) > 0 ? Utils::toFloat(mapFields[key]) : 0.0f; +} + +double Fields::getDouble(string key) +{ + return mapFields.count(key) > 0 ? Utils::toDouble(mapFields[key]) : 0.0; +} + +std::map::iterator Fields::remove(string key) +{ + auto it = mapFields.find(key); + if (it != mapFields.end()) + { + it = mapFields.erase(it); + } + return it; +} +void Fields::append(Fields& datafield) +{ + auto& map_f = datafield.fields(); + for (auto it = map_f.begin(); it != map_f.end(); it++) + { + mapFields[it->first] = it->second; + } +} +map& Fields::fields() +{ + return mapFields; +} + +void Fields::check(string key, string val, string d) +{ + if (mapFields.count(key) > 0 && mapFields[key] == val) + { + mapFields[key] = d; + } +} + +string Fields::get_insert_sql(string tbname) +{ + string key; + string val; + for (auto it = mapFields.begin(); it != mapFields.end(); it++) + { + if (!key.empty()) + { + key += ","; + val += ","; + } + key += ("`" + it->first + "`"); + if (it->second == "null" || it->second == "NULL") + { + val += "NULL"; + } + else + { + val += ("'" + it->second + "'"); + } + } + return "INSERT INTO `" + tbname + "` (" + key + ") VALUES(" + val + ");"; +} + +string Fields::get_update_sql(string tbname, string sql_c) +{ + ostringstream oss; + oss << "update " << tbname << " set "; + for (auto iter = mapFields.begin(); iter != mapFields.end(); iter++) + { + if (iter != mapFields.begin()) + { + oss << ","; + }; + oss << "`" << iter->first << "`="; + if (iter->second == "null" || iter->second == "NULL") + { + oss << "NULL"; + } + else + { + oss << "'" << iter->second << "'"; + } + } + oss << " " << sql_c << ";"; + return oss.str(); +} + +string Fields::get_update_sql(string tbname, std::vector vec_keys, string sql_c) +{ + std::map map_keys; + for (auto& k : vec_keys) { map_keys[k] = true; } + + ostringstream oss; + oss << "update " << tbname << " set "; + for (auto iter = mapFields.begin(); iter != mapFields.end(); iter++) + { + auto& k = iter->first; + auto& v = iter->second; + if (!map_keys[k]) { continue; } + if (iter != mapFields.begin()) + { + oss << ","; + }; + oss << "`" << k << "`="; + if (v == "null" || v == "NULL") + { + oss << "NULL"; + } + else + { + oss << "'" << v << "'"; + } + } + oss << " " << sql_c << ";"; + return oss.str(); +} + +void Fields::foreachItem(function onForaach) +{ + for (auto it = mapFields.begin(); it != mapFields.end(); it++) + { + if (onForaach) + { + onForaach(it->first, it->second); + } + } +} +bool Fields::isEmpty(string key) +{ + auto& s = mapFields[key]; + return s.empty(); +} + +bool Fields::is_float_number(string key) +{ + auto& s = mapFields[key]; + if (s.empty()) + { + return false; + } + for (auto& c : s) + { + if (std::isdigit(c) == 0 && c != '.') + { + return false; + } + } + return true; +} + +string Fields::toStr() +{ + string s; + for (auto it = mapFields.begin(); it != mapFields.end(); it++) + { + s += ("{" + it->first + ":" + it->second + "} "); + } + return s; +} + +int Fields::size() +{ + return mapFields.size(); +} + +void Fields::clear() +{ + mapFields.clear(); +} + +bool Fields::hasKey(std::string key) +{ + auto iter = mapFields.find(key); + return (iter != mapFields.end()); +} + diff --git a/src/common/DataFields.h b/src/common/Fields.h similarity index 69% rename from src/common/DataFields.h rename to src/common/Fields.h index 7903e10..f3280b5 100644 --- a/src/common/DataFields.h +++ b/src/common/Fields.h @@ -1,5 +1,5 @@ -#ifndef _DataFields_H_ -#define _DataFields_H_ +#ifndef _Fields_H_ +#define _Fields_H_ #include #include @@ -11,12 +11,11 @@ using namespace std; struct PageInfo { int total {0}; - int pageIndex {0}; - int pageSize {10}; - int pageCount {0}; + int index {0}; + int size {10}; }; -class DataFields +class Fields { public: /** @@ -48,10 +47,10 @@ public: void set(string key, int64_t val); /** - * 获取 string 值 + * 获取值 * @param: [string key] 索引名称 */ - string getStr(string key); + std::string& value(std::string key); /** * 获取 int 值 @@ -75,13 +74,13 @@ public: * 删除指定索引的值 * @param: [string key] 索引名称 */ - void remove(string key); + std::map::iterator remove(string key); /** * 追加合并 * @param: [DataFields& fields] 要合并的数据 */ - void append(DataFields& fields); + void append(Fields& fields); /** * 获取数据项map @@ -98,31 +97,31 @@ public: /** * 转换成插入数据的 sql 语句 - * @param: [string tbname] 数据表名称 + * @param: [string tableName] 数据表名称 */ - string get_insert_sql(string tbname); + string get_insert_sql(string tableName); /** * 转换成更新数据的 sql 语句 - * @param: [string tbname] 数据表名称 - * @param: [string sql_c] sql的更新条件,例如: where id='1' + * @param: [string tableName] 数据表名称 + * @param: [string condition] sql的更新条件,例如: where id='1' */ - string get_update_sql(string tbname, string sql_c); + string get_update_sql(string tableName, string condition); /** * 转换成更新数据的 sql 语句 - * @param: [string tbname] 数据表名称 - * @param: [string vec_keys] 需要更新的字段名称 - * @param: [string sql_c] sql的更新条件,例如: where id='1' + * @param: [string tableName] 数据表名称 + * @param: [string vecKeys] 需要更新的字段名称 + * @param: [string condition] sql的更新条件,例如: where id='1' */ - string get_update_sql(string tbname, std::vector vec_keys, string sql_c); + string get_update_sql(string tableName, std::vector vecKeys, string condition); /** * 遍历数据项 - * @param: [function... on_foraach] 回调函数 + * @param: [function... onForaach] 回调函数 */ - void foreachItem(function on_foraach); + void foreachItem(function onForaach); /** * 判断是否含有数据项 @@ -148,8 +147,14 @@ public: void clear(); + bool hasKey(std::string key); + + + + std::map& map() { return mapFields; } + private: - map mapFields_; + std::map mapFields; }; #endif \ No newline at end of file diff --git a/src/database/Dao.cpp b/src/database/Dao.cpp index 0ef8cb0..4017693 100644 --- a/src/database/Dao.cpp +++ b/src/database/Dao.cpp @@ -14,7 +14,7 @@ bool DAO::count(DaoEntity& dao, std::string tableName, std::string condition, in if (!condition.empty()) { sql += " WHERE " + condition; }; sql += ";"; - std::vector result; + std::vector result; bool ret = dao.exec(sql, result); if (ret) { @@ -25,7 +25,7 @@ bool DAO::count(DaoEntity& dao, std::string tableName, std::string condition, in static bool QueryCount(DaoEntity& dao, std::string sqlFrom, int& count) { - std::vector result; + std::vector result; bool ret = dao.exec("SELECT COUNT(*) count " + sqlFrom, result); if (ret) { @@ -35,18 +35,18 @@ static bool QueryCount(DaoEntity& dao, std::string sqlFrom, int& count) } -static bool QueryPagination(std::string sqlFrom, PageInfo& pageInfo, vector& result) +static bool QueryPagination(std::string sqlFields, std::string sqlCondition, PageInfo& page, vector& result) { DaoEntity dao(""); int count {0}; - if (!QueryCount(dao, sqlFrom, count)) + if (!QueryCount(dao, sqlCondition, count)) { return false; } - pageInfo.total = count; - std::string sql = "SELECT * " + sqlFrom + DAO::sqlPageLimit(pageInfo.pageIndex, pageInfo.pageSize); + page.total = count; + std::string sql = "SELECT " + sqlFields + " " + sqlCondition + DAO::sqlPageLimit(page.index, page.size); bool ret = dao.exec(sql, result); if (!ret) { @@ -55,11 +55,47 @@ static bool QueryPagination(std::string sqlFrom, PageInfo& pageInfo, vector& result) +// 新增用户信息 +Errcode DAO::insertUser(Fields& params) { + std::string createTime = Utils::timeStr(); + auto dao = DaoEntity::create(DMUser::TABLENAME); + std::string account = params.value(DMUser::ACCOUNT); + + // step1: 查询 + std::vector result; + bool ret = dao->exec("SELECT * from user WHERE account='" + account + "';", result); + if (!ret) + { + return Errcode::ERR_DB_CONN; + } + if (result.size() > 0) + { + return Errcode::ERR_DB_DUPLICATE; + } + params.set(DMUser::CREATETIME, createTime); + ret = dao->insertFields(params); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + Fields paramsUserRole; + paramsUserRole.set(DMUser::USER_ID, params.value(DMUser::USER_ID)); + paramsUserRole.set(DMRole::ROLE_ID, params.value(DMRole::ROLE_ID)); + paramsUserRole.set(DMUser::UPDATETIME, createTime); + ret = dao->duplicateUpdate(paramsUserRole, {DMUser::USER_ID}); + return Errcode::OK; +} + + +// 分页查询用户信息列表 +bool DAO::queryUserList(PageInfo& pageInfo, vector& result) +{ + std::string sqlFields = "u.*, r.role_id , r.name role_name"; + std::string sqlCondition = "FROM USER u LEFT JOIN user_role ur ON ur.user_id = u.user_id LEFT JOIN ROLE r ON r.role_id =ur.role_id"; + DaoEntity dao(""); - std::string sqlFrom = "FROM " + DMUser::TABLENAME; - bool ret = QueryPagination(sqlFrom, pageInfo, result); + bool ret = QueryPagination(sqlFields, sqlCondition, pageInfo, result); if (!ret) { XLOGE() << "DAO database error: queryUserList failed."; @@ -67,19 +103,52 @@ bool DAO::queryUserList(PageInfo& pageInfo, vector& result) return ret; } -bool DAO::updateUserById(DataFields& params) +Errcode DAO::updateUserById(Fields& params) { - std::string userId = params.getStr(DMUser::USER_ID); - params.remove(DMUser::USER_ID); - DaoEntity dao(DMUser::TABLENAME); - return dao.updateFields(params, "WHERE " + DMUser::USER_ID + "='" + userId + "'"); + std::string createTime = Utils::timeStr(); + std::string userId = params.value(DMUser::USER_ID); + std::string roleId = ""; + if (params.hasKey(DMRole::ROLE_ID)) + { + roleId = params.value(DMRole::ROLE_ID); + params.remove(DMUser::USER_ID); + } + + auto dao = DaoEntity::create(DMUser::TABLENAME); + bool ret = dao->updateFields(params, "WHERE " + DMUser::USER_ID + "='" + userId + "'"); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + + if (!roleId.empty()) + { + dao->setTableName(DMUserRole::TABLENAME); + Fields paramsUserRole; + paramsUserRole.set(DMUserRole::USER_ID, params.value(DMUserRole::USER_ID)); + paramsUserRole.set(DMUserRole::ROLE_ID, params.value(DMUserRole::ROLE_ID)); + paramsUserRole.set(DMUserRole::UPDATETIME, createTime); + ret = dao->duplicateUpdate(paramsUserRole, {DMUser::USER_ID}); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + } + return Errcode::OK; } -bool DAO::queryRoleList(PageInfo& pageInfo, vector& result) +bool DAO::queryRoleList(std::shared_ptr dao, vector& result) +{ + if (!dao) { dao = DaoEntity::create(""); } + std::string sql = "SELECT * FROM " + DMRole::TABLENAME + ";"; + return dao->exec(sql, result); +} + +bool DAO::queryRoleList(PageInfo& pageInfo, vector& result) { DaoEntity dao(""); std::string sqlFrom = "FROM " + DMRole::TABLENAME; - bool ret = QueryPagination(sqlFrom, pageInfo, result); + bool ret = QueryPagination("*", sqlFrom, pageInfo, result); if (!ret) { XLOGE() << "DAO database error: queryRoleList failed."; @@ -87,11 +156,11 @@ bool DAO::queryRoleList(PageInfo& pageInfo, vector& result) return ret; } -bool DAO::queryPermissionList(PageInfo& pageInfo, vector& result) +bool DAO::queryPermissionList(PageInfo& pageInfo, vector& result) { DaoEntity dao(""); std::string sqlFrom = "FROM " + DMPermission::TABLENAME; - bool ret = QueryPagination(sqlFrom, pageInfo, result); + bool ret = QueryPagination("*", sqlFrom, pageInfo, result); if (!ret) { XLOGE() << "DAO database error: queryPermissionList failed."; @@ -99,19 +168,34 @@ bool DAO::queryPermissionList(PageInfo& pageInfo, vector& result) return ret; } -// 查询场站信息列表 -bool DAO::queryStationList(vector& result) +Errcode DAO::insertStation(Fields& params) { + auto dao = DaoEntity::create(DMStation::TABLENAME); + params.remove(DMStation::STATION_ID); + params.check(DMStation::LATITUDE, "", "NULL"); + params.check(DMStation::LONGITUDE, "", "NULL"); + bool ret = dao->insertFields(params); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + return Errcode::OK; +} + +// 查询场站信息列表 +bool DAO::queryStationList(std::shared_ptr dao, vector& result) +{ + if (!dao) { dao = DaoEntity::create(""); } std::string sql = "SELECT * FROM " + DMStation::TABLENAME; return DaoEntity::execOnce(sql, result); } // 分页查询场站信息列表 -bool DAO::queryStationList(PageInfo& pageInfo, vector& result) +bool DAO::queryStationList(PageInfo& pageInfo, vector& result) { DaoEntity dao(""); std::string sqlFrom = "FROM " + DMStation::TABLENAME; - bool ret = QueryPagination(sqlFrom, pageInfo, result); + bool ret = QueryPagination("*", sqlFrom, pageInfo, result); if (!ret) { XLOGE() << "DAO database error: queryStationList failed."; @@ -119,19 +203,37 @@ bool DAO::queryStationList(PageInfo& pageInfo, vector& result) return ret; } -// 查询设备信息列表 -bool DAO::queryDeviceList(vector& result) +Errcode DAO::updateStationById(Fields& params) { + std::string stationId = params.value(DMStation::STATION_ID); + if (stationId.empty()) + { + return Errcode::ERR_DB_SQL; + } + params.remove(DMStation::STATION_ID); + auto dao = DaoEntity::create(DMStation::TABLENAME); + bool ret = dao->updateFields(params, "WHERE " + DMStation::STATION_ID + "='" + stationId + "'"); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + return Errcode::OK; +} + +// 查询设备信息列表 +bool DAO::queryDeviceList(std::shared_ptr dao, vector& result) +{ + if (!dao) { dao = DaoEntity::create(""); } std::string sql = "SELECT * FROM " + DMDevice::TABLENAME; return DaoEntity::execOnce(sql, result); } // 分页查询设备信息列表 -bool DAO::queryDeviceList(PageInfo& pageInfo, vector& result) +bool DAO::queryDeviceList(PageInfo& pageInfo, vector& result) { DaoEntity dao(""); std::string sqlFrom = "FROM " + DMDevice::TABLENAME; - bool ret = QueryPagination(sqlFrom, pageInfo, result); + bool ret = QueryPagination("*", sqlFrom, pageInfo, result); if (!ret) { XLOGE() << "DAO database error: queryDeviceList failed."; @@ -139,12 +241,46 @@ bool DAO::queryDeviceList(PageInfo& pageInfo, vector& result) return ret; } -// 策略管理 -bool DAO::queryPolicyList(PageInfo& pageInfo, vector& result) +// 查询设备类型定义 +bool DAO::queryDeviceTypeDef(std::shared_ptr dao, vector& result) { - DaoEntity dao(""); + if (!dao) { dao = DaoEntity::create(""); } + std::string sql = "SELECT * FROM " + DMDeviceTypeDef::TABLENAME + ";"; + return DaoEntity::execOnce(sql, result); +} + +Errcode DAO::insertDevice(Fields& params) +{ + auto dao = DaoEntity::create(DMDevice::TABLENAME); + bool ret = dao->insertFields(params); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + return Errcode::OK; +} +Errcode DAO::updateDeviceById(Fields& params) +{ + std::string deviceId = params.value(DMDevice::DEVICE_ID); + if (deviceId.empty()) + { + return Errcode::ERR_DB_SQL; + } + auto dao = DaoEntity::create(DMDevice::TABLENAME); + bool ret = dao->updateFields(params, "WHERE " + DMDevice::DEVICE_ID + "='" + deviceId + "'"); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + return Errcode::OK; +} + +// 策略管理 +bool DAO::queryPolicyList(PageInfo& pageInfo, vector& result) +{ + auto dao = DaoEntity::create(""); std::string sqlFrom = "FROM " + DMPolicy::TABLENAME; - bool ret = QueryPagination(sqlFrom, pageInfo, result); + bool ret = QueryPagination("*", sqlFrom, pageInfo, result); if (!ret) { XLOGE() << "DAO database error: queryPolicyList failed."; @@ -153,11 +289,11 @@ bool DAO::queryPolicyList(PageInfo& pageInfo, vector& result) } // 系统日志管理 -bool DAO::querySystemLogList(PageInfo& pageInfo, vector& result) +bool DAO::querySystemLogList(PageInfo& pageInfo, vector& result) { DaoEntity dao(""); std::string sqlFrom = "FROM " + DMSystemLog::TABLENAME; - bool ret = QueryPagination(sqlFrom, pageInfo, result); + bool ret = QueryPagination("*", sqlFrom, pageInfo, result); if (!ret) { XLOGE() << "DAO database error: querySystemLogList failed."; @@ -165,7 +301,7 @@ bool DAO::querySystemLogList(PageInfo& pageInfo, vector& result) return ret; } -bool DAO::queryStatDataList(std::string startDate, std::string endDate, vector& result) +bool DAO::queryStatDataList(std::string startDate, std::string endDate, vector& result) { std::string sql = "SELECT * FROM " + DMStatStation::TABLENAME + " WHERE dt BETWEEN '" + startDate + "' AND '" + endDate + "';"; return DaoEntity::execOnce(sql, result); diff --git a/src/database/Dao.h b/src/database/Dao.h index d2226a0..23dbdc8 100644 --- a/src/database/Dao.h +++ b/src/database/Dao.h @@ -2,6 +2,7 @@ #include "DaoEntity.h" #include "DataModelDef.h" #include "common/Logger.h" +#include "errcode.h" class DAO { @@ -12,43 +13,64 @@ public: /////////////////////////////////////////////////////////////////////////////////////////////// // === 用户管理 - static bool queryUserList(PageInfo& pageInfo, vector& result); + // 新增用户信息 + static Errcode insertUser(Fields& params); + // 分页查询用户信息列表 + static bool queryUserList(PageInfo& pageInfo, vector& result); - static bool updateUserById(DataFields& params); + static Errcode updateUserById(Fields& params); + + /////////////////////////////////////////////////////////////////////////////////////////////// - // === 角色管理 - static bool queryRoleList(PageInfo& pageInfo, vector& result); + // === 角色管理 === + // 查询角色信息列表 + static bool queryRoleList(std::shared_ptr dao, vector& result); + // 分页查询角色信息列表 + static bool queryRoleList(PageInfo& pageInfo, vector& result); + + /////////////////////////////////////////////////////////////////////////////////////////////// - // === 权限管理 - static bool queryPermissionList(PageInfo& pageInfo, vector& result); + // === 权限管理 === + static bool queryPermissionList(PageInfo& pageInfo, vector& result); /////////////////////////////////////////////////////////////////////////////////////////////// - // === 场站管理 + // === 场站管理 === + // 新增场站信息 + static Errcode insertStation(Fields& params); // 查询场站信息列表 - static bool queryStationList(vector& result); + static bool queryStationList(std::shared_ptr dao, vector& result); // 分页查询场站信息列表 - static bool queryStationList(PageInfo& pageInfo, vector& result); + static bool queryStationList(PageInfo& pageInfo, vector& result); + + static Errcode updateStationById(Fields& params); /////////////////////////////////////////////////////////////////////////////////////////////// - // === 设备管理 + // === 设备管理 === // 查询设备信息列表 - static bool queryDeviceList(vector& result); + static bool queryDeviceList(std::shared_ptr dao, vector& result); // 分页查询设备信息列表 - static bool queryDeviceList(PageInfo& pageInfo, vector& result); + static bool queryDeviceList(PageInfo& pageInfo, vector& result); + // 查询设备类型定义 + static bool queryDeviceTypeDef(std::shared_ptr dao, vector& result); + + static Errcode insertDevice(Fields& params); + static Errcode updateDeviceById(Fields& params); /////////////////////////////////////////////////////////////////////////////////////////////// - // === 策略管理 + // === 策略管理 === // 分页查询策略信息列表 - static bool queryPolicyList(PageInfo& pageInfo, vector& result); + static bool queryPolicyList(PageInfo& pageInfo, vector& result); /////////////////////////////////////////////////////////////////////////////////////////////// - // === 系统日志管理 + // === 系统日志管理 === // 分页查询系统日志列表 - static bool querySystemLogList(PageInfo& pageInfo, vector& result); + static bool querySystemLogList(PageInfo& pageInfo, vector& result); /////////////////////////////////////////////////////////////////////////////////////////////// - // === 统计数据管理 - static bool queryStatDataList(std::string startDate, std::string endDate, vector& result); + // === 统计数据管理 === + static bool queryStatDataList(std::string startDate, std::string endDate, vector& result); + + }; \ No newline at end of file diff --git a/src/database/DaoEntity.cpp b/src/database/DaoEntity.cpp index a2aeeb5..e66cda8 100644 --- a/src/database/DaoEntity.cpp +++ b/src/database/DaoEntity.cpp @@ -51,7 +51,7 @@ bool DaoEntity::execOnce(string sql) return db->exec(sql); } -bool DaoEntity::execOnce(string sql, vector& result) +bool DaoEntity::execOnce(string sql, vector& result) { auto db = make_shared(DaoEntity::option_); return db->exec(sql, result); @@ -72,18 +72,18 @@ bool DaoEntity::exec(string sql) return db_->exec(sql); } -bool DaoEntity::exec(string sql, vector& result) +bool DaoEntity::exec(string sql, vector& result) { return db_->exec(sql, result); } -bool DaoEntity::insertFields(DataFields& fields) +bool DaoEntity::insertFields(Fields& fields) { string sql = fields.get_insert_sql(tableName_); return this->db_->exec(sql); } -bool DaoEntity::insertFields(vector& vec_fields) +bool DaoEntity::insertFields(vector& vec_fields) { //"insert into TABLE () values ()"; string sql = "insert into " + tableName_; @@ -128,7 +128,7 @@ bool DaoEntity::insertFields(vector& vec_fields) return this->db_->exec(sql); } -bool DaoEntity::duplicateUpdate(DataFields& fields, vector& keys) +bool DaoEntity::duplicateUpdate(Fields& fields, const vector& keys) { //insert into device_attr(device_id, attr_id, attr_val) values('26', 'model', '型号1') on duplicate key update attr_val='型号1'; string s_key; @@ -149,7 +149,7 @@ bool DaoEntity::duplicateUpdate(DataFields& fields, vector& keys) { s_data += ","; } - s_data += (k + "='" + fields.getStr(k) + "'"); + s_data += (k + "='" + fields.value(k) + "'"); } string sql = "INSERT INTO " + tableName_ + "(" + s_key + ") VALUES (" + s_val + ") ON duplicate KEY UPDATE " + s_data; return this->db_->exec(sql); @@ -163,19 +163,19 @@ bool DaoEntity::duplicateUpdate(DataFields& fields, vector& keys) //} -bool DaoEntity::queryFields(string keys, const string& sql_c, vector& result) +bool DaoEntity::queryFields(string keys, const string& sql_c, vector& result) { ostringstream oss; oss << "SELECT " + keys + " FROM " << tableName_ << (" " + sql_c) << "; "; return this->db_->exec(oss.str(), result); } -bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& pageinfo, vector& result) +bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& page, vector& result) { ostringstream oss; oss << "SELECT count(1) total FROM `" << tableName_ << "` " << sql_c << ";"; - vector res_total; + vector res_total; if (!this->db_->exec(oss.str().c_str(), res_total)) { return false; @@ -183,27 +183,26 @@ bool DaoEntity::queryFields(string keys, const string& sql_c, PageInfo& pageinfo if (res_total.size() <= 0) { - pageinfo.total = 0; + page.total = 0; return true; } - pageinfo.total = res_total[0].getInt("total"); - if (pageinfo.total <= 0) + page.total = res_total[0].getInt("total"); + if (page.total <= 0) { return true; } - pageinfo.pageCount = pageinfo.total / pageinfo.pageSize + (pageinfo.total % pageinfo.pageSize > 0 ? 1 : 0); oss.str(""); - if (pageinfo.pageIndex <= 0) + if (page.index <= 0) { - pageinfo.pageIndex = 1; + page.index = 1; } - int start = (pageinfo.pageIndex - 1) * pageinfo.pageSize; - oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << sql_c << " LIMIT " << start << "," << pageinfo.pageSize << ";"; + int start = (page.index - 1) * page.size; + oss << "SELECT " << keys << " FROM `" << tableName_ << "` " << sql_c << " LIMIT " << start << "," << page.size << ";"; return this->db_->exec(oss.str().c_str(), result); } -bool DaoEntity::updateFields(DataFields& fields, const string& sql_c) +bool DaoEntity::updateFields(Fields& fields, const string& sql_c) { string sql = fields.get_update_sql(tableName_, sql_c); std::cout << sql; @@ -215,7 +214,7 @@ bool DaoEntity::updateFields(DataFields& fields, const string& sql_c) return this->db_->exec(sql.c_str()); } -bool DaoEntity::updateFields(DataFields& fields, vector vec_keys, const string& sql_c) +bool DaoEntity::updateFields(Fields& fields, vector vec_keys, const string& sql_c) { string sql = fields.get_update_sql(tableName_, vec_keys, sql_c); if (sql_c.empty()) diff --git a/src/database/DaoEntity.h b/src/database/DaoEntity.h index cdaa374..9b6ef69 100644 --- a/src/database/DaoEntity.h +++ b/src/database/DaoEntity.h @@ -25,7 +25,7 @@ public: * @param: sql 要执行的完整 sql 语句 * @param: result 返回的结果数据集 */ - static bool execOnce(string sql, vector& result); + static bool execOnce(string sql, vector& result); /** * 设置数据库表名称 @@ -47,34 +47,34 @@ public: /** * 执行sql语句并返回执行(查询)的结果集 */ - bool exec(string sql, vector& result); + bool exec(string sql, vector& result); /** * 数据库插入一条数据, 需要先指定数据表名称 * @param: fields 写入的数据字段和值 */ - bool insertFields(DataFields& vecFields); + bool insertFields(Fields& vecFields); /** * 数据库插入多条数据, 需要先指定数据表名称 * @param: vecFields 写入的数据字段和值的集合 */ - bool insertFields(vector& vecFields); + bool insertFields(vector& vecFields); /** * 数据库插入多条数据,UNIQUE索引或PRIMARY KEY重复时执行更新数据, 需要先指定数据表名称 * @param: vecFields 写入的数据字段和值的集合 * @param: keys 数据重复时需要更新的字段 */ - bool duplicateUpdate(DataFields& vecFields, vector& keys); + bool duplicateUpdate(Fields& vecFields, const vector& keys); /** * 数据库查询,需要先指定数据表名称 * @param: sql_c 查询条件,例:"where id='1'" * @param: result 查询的数据结果集 */ - bool queryFields(string keys, const string& sql_c, vector& result); + bool queryFields(string keys, const string& sql_c, vector& result); /** * 数据库查询,需要先指定数据表名称 @@ -82,14 +82,14 @@ public: * @param: pageinfo 分页信息 * @param: result 查询的数据结果集 */ - bool queryFields(string keys, const string& sql_c, PageInfo& pageinfo, vector& result); + bool queryFields(string keys, const string& sql_c, PageInfo& pageinfo, vector& result); /** * 数据库更新,需要先指定数据表名称 * @param: fields 要更新的数据字段和值 * @param: sql_c 更新条件 */ - bool updateFields(DataFields& fields, const string& sql_c); + bool updateFields(Fields& fields, const string& sql_c); /** * 数据库更新,需要先指定数据表名称 @@ -97,7 +97,7 @@ public: * @param: vecKeys 要更新的字段名称 * @param: cond 更新条件 */ - bool updateFields(DataFields& fields, vector vecKeys, const string& cond); + bool updateFields(Fields& fields, vector vecKeys, const string& cond); protected: static MysqlOption option_; diff --git a/src/database/DataModelDef.h b/src/database/DataModelDef.h index ef7a4bf..26bc4e6 100644 --- a/src/database/DataModelDef.h +++ b/src/database/DataModelDef.h @@ -1,4 +1,6 @@ -#include +#pragma once + +#include using namespace std; /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -18,6 +20,20 @@ namespace DMUser const string LOGINTIME = "login_time"; const string CREATETIME = "create_time"; const string UPDATETIME = "update_time"; + + // 联合查询时使用 + const string ROLE_NAME = "role_name"; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// 用户角色 表结构字段 +namespace DMUserRole +{ + const string TABLENAME = "user_role"; + const string USER_ID = "user_id"; + const string ROLE_ID = "role_id"; + const string CREATETIME = "create_time"; + const string UPDATETIME = "update_time"; } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -71,7 +87,7 @@ namespace DMDevice const string TABLENAME = "device"; const string DEVICE_ID = "device_id"; const string STATION_ID = "station_id"; - const string TYPE = "type"; + const string TYPE_ID = "type_id"; const string NAME = "name"; const string CODE = "code"; const string MODEL = "model"; @@ -84,6 +100,14 @@ namespace DMDevice const string UPDATE_TIME = "update_time"; } +namespace DMDeviceTypeDef +{ + const string TABLENAME = "def_device_type"; + const string TYPE_ID = "type_id"; + const string NAME = "name"; + const string ATTRS = "attrs"; +} + namespace DMPolicy { const string TABLENAME = "policy"; diff --git a/src/database/MysqlClient.cpp b/src/database/MysqlClient.cpp index 7f87e1c..4821894 100644 --- a/src/database/MysqlClient.cpp +++ b/src/database/MysqlClient.cpp @@ -65,7 +65,7 @@ bool MysqlClient::exec(std::string sql) return true; } -bool MysqlClient::exec(std::string sql, vector& result) +bool MysqlClient::exec(std::string sql, vector& result) { result.clear(); if (!mysql_) @@ -108,7 +108,7 @@ bool MysqlClient::exec(std::string sql, vector& result) break; } - DataFields row_data; + Fields row_data; for (size_t i = 0; i < field_names.size(); ++i) { string field_text = (row[i] == NULL) ? "" : row[i]; diff --git a/src/database/MysqlClient.h b/src/database/MysqlClient.h index c76b882..9e10bd5 100644 --- a/src/database/MysqlClient.h +++ b/src/database/MysqlClient.h @@ -11,7 +11,7 @@ #include #include #include "mysql.h" -#include "DataFields.h" +#include "Fields.h" using namespace std; @@ -55,7 +55,7 @@ public: /** * @brief: 执行sql语句, 获取查询结果集 */ - bool exec(std::string, vector& result); + bool exec(std::string, vector& result); private: // mysql数据库连接对象 diff --git a/src/main.cpp b/src/main.cpp index 389230d..678798d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,12 @@ int main(int argc, char** argv) { + std::string str = "用户编号"; + int a = str.size(); + int b = str.length(); + + int x = 5/10 + int(6%10 != 0); + // 设置控制台输出为 UTF-8 编码 SetConsoleOutputCP(CP_UTF8); // 设置控制台输入为 UTF-8 编码(如果需要输入中文) diff --git a/src/protocol/Communicator.cpp b/src/protocol/Communicator.cpp index 510d885..69ac712 100644 --- a/src/protocol/Communicator.cpp +++ b/src/protocol/Communicator.cpp @@ -1,10 +1,10 @@ #include "Communicator.h" #include "TcpEntity.h" -std::shared_ptr Communicator::createEntity(DataFields& data) +std::shared_ptr Communicator::createEntity(Fields& data) { - std::string commType = data.getStr("commType"); - std::string ip = data.getStr("ip"); + std::string commType = data.value("commType"); + std::string ip = data.value("ip"); int port = data.getInt("port"); int isclient = data.getInt("isclient"); diff --git a/src/protocol/Communicator.h b/src/protocol/Communicator.h index c9b0e2e..7f5a599 100644 --- a/src/protocol/Communicator.h +++ b/src/protocol/Communicator.h @@ -3,7 +3,7 @@ #include #include -#include "common/DataFields.h" +#include "common/Fields.h" class CommEntity { @@ -35,5 +35,5 @@ public: class Communicator { public: - static std::shared_ptr createEntity(DataFields& data); + static std::shared_ptr createEntity(Fields& data); }; \ No newline at end of file diff --git a/src/pv/MaskMain.cpp b/src/pv/MaskMain.cpp index faa3185..f9d7169 100644 --- a/src/pv/MaskMain.cpp +++ b/src/pv/MaskMain.cpp @@ -5,7 +5,7 @@ #include "pv/pages/MaskPageStat.h" #include "pv/pages/MaskPageSysmgr.h" -#include "common/DataFields.h" +#include "common/Fields.h" #include #include #include @@ -24,14 +24,14 @@ std::string GetDateTimeWeekday() int MaskMain::initUI() { - pvSetStyleSheet(p, PV_ID_MAIN, "color: white; font: normal 14px \"微软雅黑\";"); + //pvSetStyleSheet(p, PV_ID_MAIN, "color: white; font: normal 14px \"微软雅黑\";"); ui.bkg = PvApp::pvid(p); PvApp::image(p, 0, 0, 0, 1920, 1080, "bkg.png"); - ui.datetime = PvApp::label(p, PV_ID_MAIN, 10, 30, 420, 30, GetDateTimeWeekday(), "font: bold 18px;"); + ui.datetime = PvApp::label(p, PV_ID_MAIN, 10, 30, 420, 30, GetDateTimeWeekday(), qss::label(20)); pvSetAlignment(p, ui.datetime, AlignCenter); - int idStationTitle = PvApp::label(p, 0, 620, 0, 660, 90, "能源站监控与运行管理系统", "font:bold 48px \"Microsoft YaHei\"; color:white"); + int idStationTitle = PvApp::label(p, 0, 620, 0, 660, 90, "能源站监控与运行管理系统", qss::label(48)); pvSetAlignment(p, idStationTitle, AlignCenter); // 初始化子页面 @@ -82,7 +82,7 @@ int MaskMain::initUI() std::string& title = vecMenuItems[i]; EPvCode statusTmp = PvApp::getPvCode(title); int x = x0 + (w+margin)*i; - int id = PvApp::button(p, 0, x, y, w, h, title, (statusTmp == pvcode_) ? STYLE_BTN_ACTIVE : STYLE_BTN); + int id = PvApp::button(p, 0, x, y, w, h, title, (statusTmp == pvcode_) ? qss::BTN_ACTIVE : qss::BTN); mapMenuInfo_[id] = std::make_pair(title, statusTmp); } } diff --git a/src/pv/PvApp.cpp b/src/pv/PvApp.cpp index 47cf6d9..3b07555 100644 --- a/src/pv/PvApp.cpp +++ b/src/pv/PvApp.cpp @@ -102,10 +102,8 @@ int PvApp::label(PARAM* p, int parent, int x, int y, int w, int h, std::string t int id = PvApp::pvid(p); pvQLabel(p, id, parent); pvSetGeometry(p, id, x, y, w, h); - pvSetFont(p, id, FONT_NAME, 14, 1, 0, 0, 0); - pvSetFontColor(p, id, 255, 255, 255); if (!text.empty()) { pvSetText(p, id, text.c_str()); } - if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); } + pvSetStyleSheet(p, id, qss.empty() ? qss::label().c_str() : qss.c_str()); return id; } int PvApp::labelAlignCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) @@ -120,10 +118,8 @@ int PvApp::button(PARAM* p, int parent, int x, int y, int w, int h, std::string int id = PvApp::pvid(p); pvQPushButton(p, id, parent); pvSetGeometry(p, id, x, y, w, h); - pvSetFont(p, id, FONT_NAME, 14, 1, 0, 0, 0); - pvSetFontColor(p, id, 255, 255, 255); if (!text.empty()) { pvSetText(p, id, text.c_str()); } - if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); } + pvSetStyleSheet(p, id, qss.empty() ? qss::button().c_str() : qss.c_str()); return id; } @@ -141,7 +137,7 @@ int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::v int id = PvApp::pvid(p); pvQComboBox(p, id, parent, 0, 0); pvSetGeometry(p, id, x, y, w, h); - pvSetStyleSheet(p, id, QSS_COMBOX_14.c_str()); + pvSetStyleSheet(p, id, qss::COMBOX_14.c_str()); for (int i=0; i& vecItems); static int lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); + + static int textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); }; /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/pv/PvPopWidget.cpp b/src/pv/PvPopWidget.cpp index b00d6f4..c1cf2b4 100644 --- a/src/pv/PvPopWidget.cpp +++ b/src/pv/PvPopWidget.cpp @@ -1,6 +1,11 @@ #include "PvPopWidget.h" -PvPopWidget::PvPopWidget(PARAM* p, int width, int height) : PvObject(p), width(width), height(height) +const std::string POP_OPER_NEW = "新增"; +const std::string POP_OPER_EDIT = "编辑"; +const std::string POP_OPER_DEL = "删除"; + +PvPopWidget::PvPopWidget(PARAM* p, int width, int height, std::string name) + : PvObject(p), width(width), height(height), name(name) { pvid = PvApp::widget(p, PV_ID_MAIN, 0, 0, 1920, 1080); PvApp::label(p, pvid, 0, 0, 1920, 1080, "", "background-color: rgba(30,30,30,180);"); @@ -12,62 +17,97 @@ PvPopWidget::PvPopWidget(PARAM* p, int width, int height) : PvObject(p), width(w PvApp::label(p, ui.widget, 0, 0, 60, height, "", "background-color: transparent; border: 0 solid rgb(42, 149, 245); border-width: 5px 0 5px 5px;"); PvApp::label(p, ui.widget, width-60, 0, 60, height, "", "background-color: transparent; border: 0 solid rgb(42, 149, 245); border-width: 5px 5px 5px 0;"); - ui.title = PvApp::label(p, ui.widget, 20, 10, width-20, 30, "", "font: bold 20px;"); - PvApp::label(p, ui.widget, 20, 40, width*0.5-20, 3, "", QSS_UNDERLINE); + ui.title = PvApp::label(p, ui.widget, 20, 10, width-20, 30, name, qss::label(20)); + PvApp::label(p, ui.widget, 20, 40, width*0.5-20, 3, "", qss::QSS_UNDERLINE); { int w = 100, h = 40, offset = 50; int x = (width- w*2 - offset) *0.5; int y = height - h - 40; - int btnOk = PvApp::button(p, ui.widget, x, y, w, h, "确定", QSS_BTN_CONFIRM); + int btnOk = PvApp::button(p, ui.widget, x, y, w, h, "确定", qss::BTN_CONFIRM); PvApp::bind(p, PvEvent::BUTTON_EVENT, btnOk, [=](std::string) { - this->show(false); if (callbackConfirm) { callbackConfirm(); } }); - int btnCancel = PvApp::button(p, ui.widget, x+w+offset, y, w, h, "取消", QSS_BTN_CANCEL); + int btnCancel = PvApp::button(p, ui.widget, x+w+offset, y, w, h, "取消", qss::BTN_CANCEL); PvApp::bind(p, PvEvent::BUTTON_EVENT, btnCancel, [=](std::string) { this->show(false); }); } + + ui.msg = PvApp::label(p, ui.widget, 50, height-110, width-100, 24, "", qss::label(14, "red")); +} + +std::shared_ptr PvPopWidget::addParamLine(std::string type, std::string key, std::string title, int x, int y, bool editable/* = true*/) +{ + auto line = std::make_shared(type, key); + mapLines[key] = line; + + PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, qss::label(15)); + if (type == "lineEdit") + { + line->widget = PvApp::lineEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, ""); + } + else if (type == "combox") + { + line->widget = PvApp::combox(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, {}); + } + else if (type == "textEdit") + { + line->widget = PvApp::textEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight*4, ""); + } + PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) { + line->val = text; + }); + if (!editable) { pvSetEnabled(p, line->widget, 0); } + return line; } void PvPopWidget::addParamLineEdit(std::string key, std::string title, int x, int y, bool editable/*= true*/) { - auto line = std::make_shared("lineEdit", key); - PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, "font: bold 14px;"); - line->widget = PvApp::lineEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, ""); - if (!editable) { pvSetEnabled(p, line->widget, 0); } - mapLines[key] = line; - PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) { - line->val = text; - }); + this->addParamLine("lineEdit", key, title, x, y, editable); +} + +void PvPopWidget::addParamTextEdit(std::string key, std::string title, int x, int y, bool editable/* = true*/) +{ + this->addParamLine("textEdit", key, title, x, y, editable); } void PvPopWidget::addParamCombox(std::string key, std::string title, int x, int y, std::vector items) { - auto line = std::make_shared("combox", key); - PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, "font: bold 14px;"); - line->widget = PvApp::combox(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, items); - mapLines[key] = line; - PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) { - line->val = text; - }); + auto line = this->addParamLine("combox", key, title, x, y, true); + line->items = items; + for (int i = 0; iwidget, i, NULL, items[i].c_str()); + } } void PvPopWidget::setParamText(std::shared_ptr line, std::string text) { - if (line->type == "lineEdit") + line->val = text; + if (line->type == "combox") { - pvSetText(p, line->widget, text.c_str()); - } - else if (line->type == "combox") - { - int index = 0; - for (int i = 0; iitems.size(); ++i) + int index = -1; + for (int i = 0; iitems.size(); ++i) { - if (line->items[i] == text) { index = i; break; } + if (line->items[i] == text) + { + line->val = line->items[i]; + pvSetCurrentItem(p, line->widget, i); + index = i; + break; + } } - pvSetCurrentItem(p, line->widget, index); + if (index == -1 && line->items.size() > 0) + { + line->val = line->items[0]; + pvSetCurrentItem(p, line->widget, 0); + } + } + else + { + pvClear(p, line->widget); + pvSetText(p, line->widget, text.c_str()); } } @@ -80,34 +120,78 @@ void PvPopWidget::setParamText(std::string key, std::string text) } } -void PvPopWidget::setTitle(std::string title) +void PvPopWidget::setStatus(std::string text) { - pvSetText(p, ui.title, title.c_str()); + status = text; + if (!name.empty()) text = name + "-" + text; + pvSetText(p, ui.title, text.c_str()); } -void PvPopWidget::setData(DataFields fields) +void PvPopWidget::setMsg(std::string msg) { + pvSetText(p, ui.msg, msg.c_str()); +} + +void PvPopWidget::setData(const Fields& fields) +{ + dataOrigin = fields; for (auto iter = mapLines.begin(); iter != mapLines.end(); ++iter) { auto& line = iter->second; - this->setParamText(line, fields.getStr(line->key)); + this->setParamText(line, dataOrigin.value(line->key)); } } -DataFields PvPopWidget::getData() +Fields PvPopWidget::getData() { - DataFields fields; - for (auto iter = mapLines.begin(); iter!=mapLines.end(); ++iter) + Fields fields; + for (auto it = mapLines.begin(); it!=mapLines.end(); ++it) { - auto& line = iter->second; - fields.set(line->key, line->val); + fields.set(it->second->key, it->second->val); } return fields; } +Fields PvPopWidget::getChangedData() +{ + Fields fields; + for (auto it = mapLines.begin(); it!=mapLines.end(); ++it) + { + auto& key = it->second->key; + auto& val = it->second->val; + if (primaryKeys.hasKey(key) || val != dataOrigin.value(key)) + { + fields.set(key, val); + } + } + return fields; +} + +void PvPopWidget::checkChangedData(Fields& fields) +{ + auto& mapItems = fields.map(); + for (auto it = mapItems.begin(); it!= mapItems.end(); ++it) + { + auto& key = it->first; + auto& val = it->second; + if (!primaryKeys.hasKey(key) && val == dataOrigin.value(key)) + { + mapItems.erase(it); + } + } +} + void PvPopWidget::setLineGeometry(int wKey, int wVal, int h) { lineKeyWidth = wKey; lineValWidth = wVal; lineHeight = h; +} + +void PvPopWidget::setPrimaryKeys(std::vector keys) +{ + for (auto& k : keys) + { + primaryKeys.set(k, ""); + } } \ No newline at end of file diff --git a/src/pv/PvPopWidget.h b/src/pv/PvPopWidget.h index 2343389..04348f3 100644 --- a/src/pv/PvPopWidget.h +++ b/src/pv/PvPopWidget.h @@ -1,7 +1,11 @@ #pragma once #include "PvApp.h" -#include "DataFields.h" +#include "Fields.h" + +extern const std::string POP_OPER_NEW; +extern const std::string POP_OPER_EDIT; +extern const std::string POP_OPER_DEL; class PvPopWidget : public PvObject { @@ -16,10 +20,14 @@ public: ParamLine(std::string type, std::string key) : type(type), key(key) {} }; - PvPopWidget(PARAM* p, int width, int height); + PvPopWidget(PARAM* p, int width, int height, std::string name); + + std::shared_ptr addParamLine(std::string type, std::string key, std::string title, int x, int y, bool editable = true); void addParamLineEdit(std::string key, std::string title, int x, int y, bool editable=true); + void addParamTextEdit(std::string key, std::string title, int x, int y, bool editable = true); + void addParamCombox(std::string key, std::string title, int x, int y, std::vector items); void setParamText(std::shared_ptr line, std::string text); @@ -27,13 +35,23 @@ public: void setCallbackConfirm(std::function callback) { callbackConfirm = callback; }; - void setTitle(std::string title); + void setStatus(std::string text); + + void setMsg(std::string msg); + + void setData(const Fields& fields); + Fields getData(); + Fields getChangedData(); + void checkChangedData(Fields& fields); - void setData(DataFields fields); - DataFields getData(); void setLineGeometry(int wKey, int wVal, int h); + void setPrimaryKeys(std::vector keys); + + std::string name; + std::string status; + int width {800}; int height {600}; @@ -44,10 +62,13 @@ public: struct { int widget; int title; + int msg; } ui; std::map> mapLines; - DataFields data; std::function callbackConfirm = nullptr; + + Fields dataOrigin; + Fields primaryKeys; }; \ No newline at end of file diff --git a/src/pv/PvStyle.cpp b/src/pv/PvStyle.cpp new file mode 100644 index 0000000..54aae3a --- /dev/null +++ b/src/pv/PvStyle.cpp @@ -0,0 +1,178 @@ +#include "PvStyle.h" +#include + +std::string BUTTON() +{ + return ""; +} + +namespace qss +{ + std::string label(int fontSize, std::string color, std::string bkgcolor, std::string border) + { + if (color.empty()) { color = "white"; }; + if (bkgcolor.empty()) { bkgcolor = "transparent"; }; + if (border.empty()) { border = "none"; }; + + std::stringstream ss; + ss << "QLabel { " + << "font: bold " << fontSize << "px \"微软雅黑\"; " + << "color: " << color << "; " + << "background-color: " << bkgcolor << "; " + << "border: " << border << "; " + <<"} QLabel:disabled {color:rgb(150, 150, 150);}"; + return ss.str(); + } + + + std::string button(int fontSize, std::string color, std::string bkgcolor, std::string border) + { + if (color.empty()) { color = "white"; }; + if (bkgcolor.empty()) { bkgcolor = "rgb(39, 161, 136)"; }; + if (border.empty()) { border = "none"; }; + + std::stringstream ss; + ss << "QPushButton {" + << "border-radius: 5px;" + << "font: bold " << fontSize << "px \"微软雅黑\";" + << "color: " << color << ";" + << "background-color:" << bkgcolor << ";" + << "border:" << border << "; }" + << "QPushButton:hover {background-color:rgb(10, 125, 215); border:2px solid rgb(1, 239, 255); color:rgb(1, 239, 255)}" + << "QPushButton:pressed { border-width:2px 0 0 2px;background-color:rgb(150,150,150);border-style:inset;}" + << "QPushButton:disabled { color:rgb(150,150,150);}"; + return ss.str(); + } + + const std::string LABEL_BKG_1 = qss::label(14, "", "rgb(5, 47, 77)", "none; border-radius:5px"); + + const std::string LABEL_BKG_2 = qss::label(14, "", "rgb(8, 54, 91)", "none; border-radius:5px"); + + const std::string LABEL_BOX = qss::label(14, "", "rgba(200,200,200,20)", "none; border-radius:2px") + + "QLabel:hover {border: 1px solid rgb(1, 183, 209);}"; + + const std::string QSS_BOX_ACTIVE = + "QLabel { background-color:rgb(7, 72, 111); border:2px solid;border-color:rgb(1, 183, 209); border-radius:2px;font:bold 16px;color:white; }" + "QLabel:hover {border: 1px solid rgb(1, 183, 209);}" + "QLabel:disabled { color:rgb(150,150,150);}"; + + const std::string LABEL_TITLE = qss::label(16, "rgb(99, 196, 216)", "", "none; padding-top: 0px;"); + + const std::string LABEL_KEY = qss::label(13, "rgb(180,180,180)", "", ""); + const std::string LABEL_VAL = qss::label(14, "", "", ""); + + const std::string BTN = + "QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px;}" + "QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" + "QPushButton:pressed { border-width:2px 0 0 2px;background-color:rgb(150,150,150);border-style:inset;}" + "QPushButton:disabled { color:rgb(150,150,150);}"; + + const std::string BTN_ACTIVE = + "QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:2px solid rgb(1,239,255);color:rgb(1,239,255);font:bold 18px;}" + "QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" + "QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" + "QPushButton:disabled { color:rgb(150,150,150);}"; + + const std::string BTN_CONFIRM = + "QPushButton { background-color:rgb(28, 145, 138); border-radius:10px; border: none; color:white; font:bold 18px;}" + "QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" + "QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" + "QPushButton:disabled { color:rgb(150,150,150);}"; + + const std::string BTN_CANCEL = + "QPushButton { background-color:rgb(200, 200, 200);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px;}" + "QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" + "QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" + "QPushButton:disabled { color:rgb(150,150,150);}"; + + const std::string QSS_BTN_MGR = + "QPushButton { background-color:rgb(10, 34, 63); border-radius:5px; border:1px solid rgb(33, 105, 195); color:white; font:bold 16px;}" + "QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}" + //"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" + "QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }" + "QPushButton:disabled{color:rgb(150,150,150);}"; + + const std::string QSS_BTN_MGR_ACTIVE = + "QPushButton { background-color:rgb(39, 161, 136);border-radius:5px; border:1px solid rgb(68, 167, 252);color:white;font:bold 16px; }" + "QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}" + "QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }" + "QPushButton:disabled { color:rgb(150,150,150); }"; + + const std::string COMBOX = + "QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 16px;}" + "QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}" + "QComboBox::drop-down { border-radius: 5px; width: 30px; }" + "QComboBox:disabled { color:rgb(150,150,150);}"; + + const std::string COMBOX_14 = + "QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 14px;}" + "QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}" + "QComboBox::drop-down { border-radius: 5px; width: 30px; }" + "QComboBox:disabled { color:rgb(150,150,150);}"; + + const std::string LINEEDIT = + "QLineEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 15px;}" + "QLineEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}"; + + + + + + + + const std::string STYLE_TITLE_ICON = + "padding-top: 0px;" + "background-color: qlineargradient(x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 71, 105, 255),stop:1 rgba(0, 71, 105, 0));" + "border-radius: 0px; color:white; font: bold 16px; border-left: 8px solid rgba(33,255,210);"; + + const std::string QSS_UNDERLINE = + "background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0,stop:0 rgba(9,194,207,200),stop:1 rgba(9,194,207,0));"; + + + + //"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 transparent, stop:%1 red, stop:1 blue);" + + /////////////////////////////////////////////////////////////////////////////////////////////////// + /// === 表格 + + /////////////////////////////////////////////////////////////////////////////////////////////////// + /// === 表格 + const std::string QSS_TABLE = + qss::label(15, "", "rgb(7, 46, 74)", "1px solid rgb(28, 121, 122)"); + + // 表头标签 + const std::string QSS_TABLE_HEAD = + qss::label(15, "", "rgb(18, 93, 113)", "1px solid rgb(120, 120, 120); border-style:inset solid"); + //"background-color: rgb(18, 93, 113); color:rgb(255, 255, 255); font:bold 16px;" + //"border-width:1 1 1 1px; border-style:inset solid; border-color:rgb(120, 120, 120);"; + + // 单元格 + const std::string QSS_TABLE_CELL = qss::label(14, "", "", "none; padding-left: 10px"); + + const std::string QSS_TABLE_BTN_VIEW = + "QPushButton { background-color: rgb(7, 46, 74); color:white; border-radius:2px; border:none; font:bold 14px;}" + "QPushButton:hover { border: 1px solid white;}" + "QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset;}" + "QPushButton:disabled { color:rgb(150,150,150);}"; + + + + // 表格行的斑马色0 + const std::string QSS_TABLE_ROW_0 = + "background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);"; + // 表格行的斑马色1 + const std::string QSS_TABLE_ROW_1 = + "background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);"; + // 表格行的高亮显示 + const std::string QSS_TABLE_ROW_HIGHLIGHT = + "background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);"; + + + const std::string QSS_CARD_DEVICE = + "QLabel { background-color:rgb(8, 54, 91); border:0px solid rgb(120, 120, 120); border-radius:5px; font:bold 14px; color:white; }" + "QLabel:hover {border: 2px solid rgb(79, 129, 255); border-radius:2px;}" + "QLabel:disabled { color:rgb(150,150,150);}"; + + + +} \ No newline at end of file diff --git a/src/pv/PvStyle.h b/src/pv/PvStyle.h index 1416663..fe82bee 100644 --- a/src/pv/PvStyle.h +++ b/src/pv/PvStyle.h @@ -1,136 +1,66 @@ #pragma once #include -static std::string QSS_BTN_CONFIRM = -"QPushButton { background-color:rgb(28, 145, 138); border-radius:10px; border: none; color:white; font:bold 18px \"Microsoft YaHei\";}" -"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" -"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:disabled { color:rgb(150,150,150);}"; +namespace qss +{ + std::string label(int fontSize = 14, std::string color = "", std::string bkgcolor = "", std::string border = ""); -static std::string QSS_BTN_CANCEL = -"QPushButton { background-color:rgb(200, 200, 200);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px \"Microsoft YaHei\";}" -"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" -"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:disabled { color:rgb(150,150,150);}"; + std::string button(int fontSize = 14, std::string color = "", std::string bkgcolor = "", std::string border = ""); -static std::string QSS_COMBOX = -"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 16px;}" -"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px;}" -"QComboBox::drop-down { border-radius: 5px; width: 30px; }" -"QComboBox:disabled { color:rgb(150,150,150);}"; + extern const std::string LABEL_BKG_1; + extern const std::string LABEL_BKG_2; + extern const std::string LABEL_BOX; + extern const std::string LABEL_KEY; + extern const std::string LABEL_VAL; -static std::string QSS_COMBOX_14 = -"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 14px;}" -"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px;}" -"QComboBox::drop-down { border-radius: 5px; width: 30px; }" -"QComboBox:disabled { color:rgb(150,150,150);}"; + extern const std::string BTN; + extern const std::string BTN_ACTIVE; + extern const std::string BTN_CONFIRM; + extern const std::string BTN_CANCEL; -static std::string QSS_LINEEDIT = -"QLineEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 14px;}" -"QLineEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}"; + extern const std::string COMBOX; + extern const std::string COMBOX_14; -static std::string STYLE_BTN = -"QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px \"Microsoft YaHei\";}" -"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" -"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:disabled { color:rgb(150,150,150);}"; + extern const std::string LINEEDIT; -static std::string STYLE_BTN_ACTIVE = -"QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:2px solid rgb(1,239,255);color:rgb(1,239,255);font:bold 18px \"Microsoft YaHei\";}" -"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}" -"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:disabled { color:rgb(150,150,150);}"; -static std::string QSS_LABEL_BKG_1 = -"QLabel { background-color:rgb(5, 47, 77); border:none; border-radius:5px; }" -"QLabel:disabled { color:rgb(150,150,150);}"; -static std::string QSS_LABEL_BKG_2 = -"QLabel { background-color:rgb(8, 54, 91); border:none; border-radius:5px; }" -"QLabel:disabled { color:rgb(150,150,150);}"; + extern const std::string QSS_BOX_ACTIVE; -static std::string QSS_BOX = -"QLabel { background-color:rgba(200,200,200,20); border:0px solid;border-color:rgb(5,255,255);border-radius:2px;font:bold 16px;color:white; }" -"QLabel:hover {border: 1px solid rgb(1, 183, 209);}" -"QLabel:disabled { color:rgb(150,150,150);}"; + extern const std::string LABEL_TITLE; -static std::string QSS_BOX_ACTIVE = -"QLabel { background-color:rgb(7, 72, 111); border:2px solid;border-color:rgb(1, 183, 209); border-radius:2px;font:bold 16px;color:white; }" -"QLabel:hover {border: 1px solid rgb(1, 183, 209);}" -"QLabel:disabled { color:rgb(150,150,150);}"; + extern const std::string STYLE_TITLE_ICON; -static std::string QSS_TITLE = -"QLabel { background:transparent; color: rgb(99, 196, 216); font: bold 16px; border: none; padding-top: 0px;}" -"QLabel:disabled { color:rgb(150,150,150);}"; + extern const std::string QSS_UNDERLINE; -static std::string STYLE_TITLE_ICON = -"padding-top: 0px;" -"background-color: qlineargradient(x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 71, 105, 255),stop:1 rgba(0, 71, 105, 0));" -"border-radius: 0px; color:white; font: bold 16px; border-left: 8px solid rgba(33,255,210);"; + extern const std::string QSS_BTN_MGR; -static std::string QSS_UNDERLINE = -"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0,stop:0 rgba(9,194,207,200),stop:1 rgba(9,194,207,0));"; + extern const std::string QSS_BTN_MGR_ACTIVE; -const std::string QSS_BTN_MGR = -"QPushButton { background-color:rgb(10, 34, 63); border-radius:5px; border:1px solid rgb(33, 105, 195); color:white; font:bold 18px \"Microsoft YaHei\";}" -"QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}" -//"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }" -"QPushButton:disabled{color:rgb(150,150,150);}"; + //"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 transparent, stop:%1 red, stop:1 blue);" -const std::string QSS_BTN_MGR_ACTIVE = -"QPushButton { background-color:rgb(33, 105, 195);border-radius:5px; border:1px solid rgb(68, 167, 252);color:white;font:bold 18px \"Microsoft YaHei\"; }" -"QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}" -"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }" -"QPushButton:disabled { color:rgb(150,150,150); }"; + /////////////////////////////////////////////////////////////////////////////////////////////////// + /// === 表格 + extern const std::string QSS_TABLE; + // 表头 + extern const std::string QSS_TABLE_HEAD; + // 单元格 + extern const std::string QSS_TABLE_CELL; -//"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 transparent, stop:%1 red, stop:1 blue);" + extern const std::string QSS_TABLE_BTN_VIEW; -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// === 表格 -static const std::string QSS_TABLE = -"border: 1px solid rgb(28, 121, 122); background-color:rgb(7, 46, 74);"; -// 表头 -static const std::string QSS_TABLE_HEAD = -"background-color: rgb(18, 93, 113); color:rgb(255, 255, 255); font:bold 16px;" -"border-width:1 1 1 1px; border-style:inset solid; border-color:rgb(120, 120, 120);"; -// 单元格 -static const std::string QSS_TABLE_CELL = -"background-color:transparent; color:rgb(255,255,255); font:bold 15px;padding-left:1;" -"border-width:0 0 0 0px; border-style:inset solid; border-color:rgba(180,180,180,200);"; + // 表格行的斑马色0 + extern const std::string QSS_TABLE_ROW_0; + // 表格行的斑马色1 + extern const std::string QSS_TABLE_ROW_1; + // 表格行的高亮显示 + extern const std::string QSS_TABLE_ROW_HIGHLIGHT; -static const std::string QSS_TABLE_BTN_VIEW = -"QPushButton { background-color: rgb(28, 145, 138); color:white; border-radius:2px; border:none; font:bold 14px;}" -"QPushButton:hover { border: 1px solid white;}" -"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset;}" -"QPushButton:disabled { color:rgb(150,150,150);}"; -const std::string BTN_NEW = // 78, 149, 143 -"QPushButton{background-color:rgb(38,233,233);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 18px;}" -"QPushButton:hover{background-color:rgb(10,125,215);}" -"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:disabled{color:rgb(150,150,150);}"; + extern const std::string QSS_CARD_DEVICE; -const std::string BTN_EDIT = -"QPushButton{background-color:rgb(248,147,45);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 15px;}" -"QPushButton:hover{background-color:rgb(10,125,215);}" -"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:disabled{color:rgb(150,150,150);}"; +}; -const std::string BTN_DELETE = -"QPushButton{background-color:rgb(252,83,83);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 15px;}" -"QPushButton:hover{background-color:rgb(10,125,215);}" -"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}" -"QPushButton:disabled{color:rgb(150,150,150);}"; -// 表格行的斑马色0 -static const std::string QSS_TABLE_ROW_0 = -"background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);"; -// 表格行的斑马色1 -static const std::string QSS_TABLE_ROW_1 = -"background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);"; -// 表格行的高亮显示 -static const std::string QSS_TABLE_ROW_HIGHLIGHT = -"background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);"; \ No newline at end of file diff --git a/src/pv/PvTable.cpp b/src/pv/PvTable.cpp index f42ad9b..88aa826 100644 --- a/src/pv/PvTable.cpp +++ b/src/pv/PvTable.cpp @@ -1,5 +1,6 @@ #include "PvTable.h" #include "PvStyle.h" +#include "pv/PvApp.h" static const string STYLE_BKG = "border-width:1 1 1 1px; border-style:outset solid; border-color:rgba(180,180,180,255);" @@ -8,469 +9,424 @@ static const string STYLE_BKG = //********************************************************************************************************************* // PvTable PvTable::PvTable(PARAM* p, int parent, int x, int y, int w, int row, Options& opts) - //: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* row + (opts.show_header ? (opts.header_height) : 0))), - : PvObject(p), option_(opts), nRow_(row), nCol_(0) + //: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* row + (opts.show_header ? (opts.header_height) : 0))), + : PvObject(p), option_(opts), nRow_(row), nCol_(0) { - // 计算表格的显示区域 - int h = opts.row_height* row + (opts.show_header ? (opts.head_height) : 0); - rect_.set(x, y, w, h); - // 表格的主窗体(QWidget设置样式无效) - pvid_ = PvApp::widget(p, parent, x, y, w, h+1); - // 表格的背景色和边框样式 - PvApp::label(p, pvid_, 0, 0, w, h+1, "", QSS_TABLE); + // 计算表格的显示区域 + int h = opts.row_height* row + (opts.show_header ? (opts.head_height) : 0); + rect_.set(x, y, w, h); + // 表格的主窗体(QWidget设置样式无效) + pvid_ = PvApp::widget(p, parent, x, y, w, h+1); + // 表格的背景色和边框样式 + + PvApp::label(p, pvid_, 0, 0, w, h+1, "", qss::QSS_TABLE); - vecHead_.resize(0); - vecRows_.resize(nRow_); - vecData_.resize(nRow_); + vecHead_.resize(0); + vecRows_.resize(nRow_); + vecData_.resize(nRow_); - // 创建行高亮显示背景 - for (int row = 0; row < nRow_; row++) - { - int y = item_posy(row); - string qss = (row % 2 != 0) ? QSS_TABLE_ROW_0 : QSS_TABLE_ROW_1; - int rowBkg = PvApp::label(p, pvid_, 1, y, rect_.w-2, option_.row_height, "", qss); - pvHide(p, rowBkg); - vecRows_[row].bkg = rowBkg; - } + // 创建行高亮显示背景 + for (int row = 0; row < nRow_; row++) + { + int y = item_posy(row); + string qss = (row % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1; + int rowBkg = PvApp::label(p, pvid_, 1, y, rect_.w-2, option_.row_height, "", qss); + pvHide(p, rowBkg); + vecRows_[row].bkg = rowBkg; + } } void PvTable::addHead(string id, string text, int width, vector> mapping) { - vecHead_.push_back(Head(id, text, width, mapping)); - nCol_ = vecHead_.size(); + vecHead_.push_back(Head(id, text, width, mapping)); + nCol_ = vecHead_.size(); - if (width <= -1) - { - width = rect_.w-1 - posCol_; - } - int col = nCol_ - 1; + if (width <= -1) { width = rect_.w-1 - posCol_; } + int col = nCol_ - 1; - // 创建表头的标签 - if (option_.show_header) - { - vecHead_[col].pvid = PvApp::label(p, pvid_, posCol_, 0, width, option_.head_height, text, QSS_TABLE_HEAD); - } + // 创建表头的标签 + if (option_.show_header) + { + vecHead_[col].pvid = PvApp::label(p, pvid_, posCol_, 0, width, option_.head_height, text, qss::QSS_TABLE_HEAD); + } - // 创建列的单元格 - for (int row = 0; row < nRow_; ++row) - { - int y = item_posy(row); - int pvid = PvApp::label(p, pvid_, posCol_, y, width, option_.row_height, "", QSS_TABLE_CELL); - vecRows_[row].vecCells.push_back(pvid); - PvApp::bind(p, MOUSE_OVER_EVENT, pvid, [=](string s) { highlight(row, (s == "1")); }); - } - posCol_ += width; + // 创建列的单元格 + for (int row = 0; row < nRow_; ++row) + { + int y = item_posy(row); + int pvid = PvApp::label(p, pvid_, posCol_, y, width, option_.row_height, "", qss::QSS_TABLE_CELL); + vecRows_[row].vecCells.push_back(pvid); + PvApp::bind(p, MOUSE_OVER_EVENT, pvid, [=](string s) { highlight(row, (s == "1")); }); + } + posCol_ += width; } void PvTable::addHead(vector vec_text) { - int colSize = vec_text.size(); - int x = 0; - for (int i = 0; i < vec_text.size(); ++i) - { - int w = float(rect_.w-1) * float(i+1) / float(colSize); - string text = vec_text[i]; - this->addHead(text, text, w-x); - x = w; - } + int colSize = vec_text.size(); + int x = 0; + for (int i = 0; i < vec_text.size(); ++i) + { + int w = float(rect_.w-1) * float(i+1) / float(colSize); + string text = vec_text[i]; + this->addHead(text, text, w-x); + x = w; + } } void PvTable::setRowVisible(int row, bool v) { - if (row < 0 || row >= vecRows_.size()) - { - return; - } - auto& rowItem = vecRows_[row]; - if (rowItem.visible != v) - { - rowItem.visible = v; - rowItem.visible ? pvShow(p, rowItem.bkg) : pvHide(p, rowItem.bkg); - if (!v) - { - for (int col = 0; col= vecRows_.size()) + { + return; + } + auto& rowItem = vecRows_[row]; + if (rowItem.visible != v) + { + rowItem.visible = v; + rowItem.visible ? pvShow(p, rowItem.bkg) : pvHide(p, rowItem.bkg); + if (!v) + { + for (int col = 0; col 0 && row <= vecRows_.size()) - { - if (v) { qss = "background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);"; } - pvSetStyleSheet(p, vecRows_[row].bkg, qss.c_str()); - } + string qss = ((row % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1); + if (vecRows_.size() > 0 && row <= vecRows_.size()) + { + if (v) { qss = "background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);"; } + pvSetStyleSheet(p, vecRows_[row].bkg, qss.c_str()); + } } void PvTable::addOperate(vector vecOpt) { - // 创建表头的标签 - if (option_.show_header) - { - PvApp::label(p, pvid_, posCol_, 0, rect_.w - posCol_, option_.head_height, "操作", QSS_TABLE_HEAD); - } - for (int row = 0; row < nRow_; ++row) - { - int y = item_posy(row); - int btn_opt = PvApp::label(p, pvid_, posCol_, y, rect_.w - posCol_, option_.row_height, "", QSS_TABLE_CELL); - //PvInstance::bind_event(p, MOUSE_OVER_EVENT, btn_opt, [=](string s) { highlight(row, (s == "1")); }); - vecOpt_.push_back({ btn_opt, vector() }); - auto& vec_opt_btn_ = vecOpt_.back().second; + // 创建表头的标签 + if (option_.show_header) + { + PvApp::label(p, pvid_, posCol_, 0, rect_.w - posCol_, option_.head_height, "操作", qss::QSS_TABLE_HEAD); + } + for (int row = 0; row < nRow_; ++row) + { + int y = item_posy(row); + int cellWidget = PvApp::label(p, pvid_, posCol_, y, rect_.w - posCol_, option_.row_height, "", qss::QSS_TABLE_CELL); + //PvInstance::bind_event(p, MOUSE_OVER_EVENT, btn_opt, [=](string s) { highlight(row, (s == "1")); }); + vecOpt_.push_back({ cellWidget, vector() }); + auto& vec_opt_btn_ = vecOpt_.back().second; - int x = 5, w = 60; - for (int i = 0; i < vecOpt.size(); i++) - { - auto& title = vecOpt[i]; - w = 20 + 15 * title.size() / 3; - int btn = PvApp::button(p, btn_opt, x, 4, w, 24, title, QSS_TABLE_BTN_VIEW); - PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { - if (cbOperate_) { cbOperate_(row, 0, title); } - }); - vec_opt_btn_.push_back(btn); - x += (w + 5); - } - pvHide(p, btn_opt); - } + int x = 5, w = 60; + for (int i = 0; i < vecOpt.size(); i++) + { + auto& title = vecOpt[i]; + w = 20 + 15 * title.size() / 3; + int btn = PvApp::button(p, cellWidget, x, 4, w, 24, title, qss::button(14, "", "", "none; border-radius: 0px")); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { + if (cbOperate_) { cbOperate_(row, 0, title); } + }); + vec_opt_btn_.push_back(btn); + x += (w + 5); + } + pvHide(p, cellWidget); + } } void PvTable::setOperateCallback(CallbackTableOpt cb) { - cbOperate_ = cb; + cbOperate_ = cb; }; void PvTable::set_text(PARAM* p, int row, int col, string text, string style) { - if (row < nRow_ && col < nCol_) - { - pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); - if (!style.empty()) - { - int idx = row + 1; - if (idx % 2 != 0) - { - style = item_base_style_ + style; - } - else - { - style = item_base_style_ + style; - } + if (row < nRow_ && col < nCol_) + { + pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); + if (!style.empty()) + { + int idx = row + 1; + if (idx % 2 != 0) + { + style = item_base_style_ + style; + } + else + { + style = item_base_style_ + style; + } - //style = "qproperty-alignment:AlignCenter;" + style + "}"; - string s = "QLabel{" + style + "} QLabel:disabled{color:rgb(150,150,150)}"; - pvSetStyleSheet(p, vecRows_[row].vecCells[col], s.c_str()); - } - } + //style = "qproperty-alignment:AlignCenter;" + style + "}"; + string s = "QLabel{" + style + "} QLabel:disabled{color:rgb(150,150,150)}"; + pvSetStyleSheet(p, vecRows_[row].vecCells[col], s.c_str()); + } + } } -void PvTable::setRowData(int row, DataFields& d) +void PvTable::setRowData(int row, Fields& d) { - if (row >= nRow_) { return; } + if (row >= nRow_) { return; } - vecData_[row] = d; - for (int col = 0; col < vecHead_.size(); ++col) - { - auto& head = vecHead_[col]; - string text = d.getStr(head.id); - text = head.getMapping(text); - pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); - } - setRowVisible(row, true); - this->setOperateVisible(row, d.size() > 0); + vecData_[row] = d; + for (int col = 0; col < vecHead_.size(); ++col) + { + auto& head = vecHead_[col]; + string text = d.value(head.id); + text = head.getMapping(text); + pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); + } + setRowVisible(row, true); + this->setOperateVisible(row, d.size() > 0); } void PvTable::setRowData(int row, std::vector vd) { - if (row >= nRow_) { return; } - pvShow(p, vecRows_[row].bkg); - for (int col = 0; col < vecHead_.size(); ++col) - { - if (col < vd.size()) { - auto& head = vecHead_[col]; - string text = head.getMapping(vd[col]); - pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); - } - } - setRowVisible(row, true); - this->setOperateVisible(row, vd.size() > 0); + if (row >= nRow_) { return; } + pvShow(p, vecRows_[row].bkg); + for (int col = 0; col < vecHead_.size(); ++col) + { + if (col < vd.size()) { + auto& head = vecHead_[col]; + string text = head.getMapping(vd[col]); + pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); + } + } + setRowVisible(row, true); + this->setOperateVisible(row, vd.size() > 0); } -DataFields& PvTable::getRowdata(int row) +Fields PvTable::getRowData(int row) { - static DataFields tmp; - return (row >= 0 && row < vecData_.size()) ? vecData_[row] : tmp; + static Fields tmp; + return (row >= 0 && row < vecData_.size()) ? vecData_[row] : tmp; +} + +void PvTable::mappingData(Fields& fields) +{ + for (int i=0; i< vecHead_.size(); ++i) + { + auto& head = vecHead_[i]; + if (fields.hasKey(head.id)) + { + auto& val = fields.value(head.id); + val = head.getMapping(val); + } + } } void PvTable::set_border_visible(PARAM* p, bool v) { - v ? pvShow(p, border_id_) : pvHide(p, border_id_); + v ? pvShow(p, border_id_) : pvHide(p, border_id_); } int PvTable::item_posy(int row) { - return option_.show_header ? row * option_.row_height + option_.head_height : row * option_.row_height; + return option_.show_header ? row * option_.row_height + option_.head_height : row * option_.row_height; } -//void PvTable::set_item_btn_callback(CallbackTableOpt cb) -//{ -// //cb_opt_ = cb; -//} - void PvTable::add_col_button(PARAM* p, int col, string title, PvRect& rt, string style) { - if (col >= nCol_) - { - return; - } - for (int row = 0; row < nRow_; ++row) - { - int id = PvApp::button(p, vecRows_[row].vecCells[col], rt.x, rt.y, rt.w, rt.h, title, style); - pvHide(p, id); - vec_col_item_btn_[row].push_back(id); - //PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, id, [=](string s) - //{ - // if (cb_operate_) - // { - // cb_operate_(row, col, title); - // } - //}); - } -} - -string GetTableItemButtonStyle(string title) -{ - static unordered_map map_style = - { - //{PV::OPT_NEW, PvStyle::BTN_NEW}, - //{PV::OPT_EDIT, PvStyle::BTN_EDIT}, - //{PV::OPT_DEL, PvStyle::BTN_DELETE} - }; - string style = map_style[title]; - if (style.empty()) - { - style = BTN_EDIT; - } - return style; + if (col >= nCol_) + { + return; + } + for (int row = 0; row < nRow_; ++row) + { + int id = PvApp::button(p, vecRows_[row].vecCells[col], rt.x, rt.y, rt.w, rt.h, title, style); + pvHide(p, id); + vec_col_item_btn_[row].push_back(id); + //PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, id, [=](string s) + //{ + // if (cb_operate_) + // { + // cb_operate_(row, col, title); + // } + //}); + } } void PvTable::add_col_button(PARAM* p, int col, vector vec_title) { - int x = 5; - int w = 0; - for (int i = 0; i < vec_title.size(); i++) - { - auto& title = vec_title[i]; - w = 20 + 20 * title.size() / 3; - this->add_col_button(p, col, title, PvRect(x, 3, w, 28), BTN_EDIT); - x += (w + 5); - } + int x = 5; + int w = 0; + for (int i = 0; i < vec_title.size(); i++) + { + auto& title = vec_title[i]; + w = 20 + 20 * title.size() / 3; + this->add_col_button(p, col, title, PvRect(x, 3, w, 28), qss::button()); + x += (w + 5); + } } void PvTable::setOperateVisible(int row, bool v, int id) { - if (row < vecOpt_.size()) - { - auto& vec_opt_btn = vecOpt_[row].second; - int pvid = id < 0 ? vecOpt_[row].first : ((id < vec_opt_btn.size()) ? vec_opt_btn[id] : PV_ID_NUL); - v ? pvShow(p, pvid) : pvHide(p, pvid); - } + if (row < vecOpt_.size()) + { + auto& vec_opt_btn = vecOpt_[row].second; + int pvid = id < 0 ? vecOpt_[row].first : ((id < vec_opt_btn.size()) ? vec_opt_btn[id] : PV_ID_NUL); + v ? pvShow(p, pvid) : pvHide(p, pvid); + } } int PvTable::border_id() { - return border_id_; + return border_id_; } int PvTable::rows() { - return nRow_; + return nRow_; } int PvTable::colums() { - return nCol_; + return nCol_; } -vector PvTable::data() +vector PvTable::data() { - return vecData_; + return vecData_; } PvTable::Head& PvTable::header(int col) { - return vecHead_[col]; + return vecHead_[col]; } - - - - static const string STYLE_NORMAL = -"QPushButton{background-color:rgba(255,255,255,30);border-radius:0px;font:bold 16px;color:white;border:1px solid #20a481;}" -"QPushButton:hover{background-color:rgba(32,164,128,255);color:white;}" -"QPushButton:pressed{border-width:3px 0 0 3px;border-style:inset;color:white;}"; +"QPushButton { background-color:rgba(255,255,255,30);border-radius:0px;font:bold 16px ;color:white;border:1px solid #20a481;}" +"QPushButton:hover { background-color:rgba(32,164,128,255);color:white;}" +"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset;color:white;}" +"QPushButton:disabled { color: gray; border-color: gray; }"; static const string STYLE_ACTIVE = -"QPushButton{background-color:rgba(32,164,128,255);border-radius:0px;font:bold 16px;color:white;border:1px solid #20a481;}" -"QPushButton:hover{background-color:rgba(32,164,128,255);color:white;}" -"QPushButton:pressed{border-width:3px 0 0 3px;border-style:inset;color:white;}"; +"QPushButton { background-color:rgba(32,164,128,255);border-radius:0px;font:bold 16px ;color:white;border:1px solid #20a481;}" +"QPushButton:hover { background-color:rgba(32,164,128,255);color:white;}" +"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset;color:white;}" +"QPushButton:disabled { color: gray; border-color: gray; }"; -PvPagination::PvPagination(PARAM* p, int parent, const PvRect& rt) - : PvObject(p) +PvPagination::PvPagination(PARAM* p, int parent, int x, int y, int n) + : PvObject(p) { - pvid_ = PvApp::label(p, parent, rt.x, rt.y, rt.w, rt.h, "", ""); - // 分页控件 - int x = 0; - int y = 0; - btn_prev_ = PvApp::button(p, pvid_, x, y, 30, 30, "<", STYLE_NORMAL); - for (int i = 1; i <= 7; i++) - { - int id = PvApp::button(p, pvid_, x += 32, y, 30, 30, std::to_string(i), STYLE_NORMAL); - vec_btn_page_.push_back({id, 0}); - //PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, id, [=](string s) { this->on_click_page(id); }); - } - btn_next_ = PvApp::button(p, pvid_, x += 32, y, 30, 30, ">", STYLE_NORMAL); + pvid = PvApp::label(p, parent, x, y, 2*32 + 80, 30, "", "border: 0px solid gray;"); - //PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, btn_prev_, [=](string e) { this->on_click_prev(); }); - //PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, btn_next_, [=](string e) { this->on_click_next(); }); + // 分页控件 + btnPrev = PvApp::button(p, pvid, 0, 0, 30, 30, "<", STYLE_NORMAL); + for (int i = 0; i < n; i++) + { + int btn = PvApp::button(p, pvid, (i+1)*32, 0, 30, 30, std::to_string(i+1), STYLE_NORMAL); + pvHide(p, btn); + vecBtn.push_back({btn, i}); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](string) { this->activePage(i, true); }); + } + btnNext = PvApp::button(p, pvid, 32, 0, 30, 30, ">", STYLE_NORMAL); + labelInfo = PvApp::label(p, pvid, 2*32, 0, 80, 30, " 共0页", qss::label(14, "rgb(27, 220, 224)")); - this->set_page(0, 0); + pvSetEnabled(p, btnPrev, 0); + pvSetEnabled(p, btnNext, 0); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnPrev, [=](string e) { this->activePage(--pageIndex, true); }); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNext, [=](string e) { this->activePage(++pageIndex, true); }); } -void PvPagination::set_page(int page_id, int max_page) +void PvPagination::setPage(int index, int count) { - this->active_page_button(p, page_id, page_id_); + pageIndex = index; + pageCount = count; - page_id_ = page_id; - page_count_ = max_page; - - int x = 32; - int y = 0;// table_->rect().h + 16; - for (int i = 0; i < vec_btn_page_.size(); ++i) - { - auto& btn_info = vec_btn_page_[i]; - auto btnid = btn_info.first; - int idx = i + 1; - if (idx > page_count_) - { - pvHide(p, btnid); - } - else - { - pvShow(p, btnid); - if (page_count_ > 7) - { - if (idx == 4) - { - idx = 0; - } - else if (idx > 4) - { - idx = page_count_ - (7 - idx); - } - } - btn_info.second = idx; - - string text = to_string(idx); - if (text.empty() || text == "0") - { - text = "..."; - pvSetEnabled(p, btnid, false); - } - pvMove(p, btnid, x, y); - pvSetText(p, btnid, text.c_str()); - if (page_id == idx) - { - this->active_page_button(p, page_id, page_id_); - page_id_ = page_id; - } - x += (32); - } - } - pvMove(p, btn_next_, x, y); + for (int i = 0; i < vecBtn.size(); ++i) + { + auto& btn = vecBtn[i]; + auto btnid = btn.first; + int idx = i + 1; + if (idx > pageCount) + { + pvHide(p, btnid); + } + else + { + pvShow(p, btnid); + //if (pageCount > 7) + //{ + // if (idx == 4) + // { + // idx = 0; + // } + // else if (idx > 4) + // { + // idx = pageCount - (7 - idx); + // } + //} + //btn.second = idx; + //string text = to_string(idx); + //if (text.empty() || text == "0") + //{ + // text = "..."; + // pvSetEnabled(p, btnid, false); + //} + ////pvMove(p, btnid, x, y); + //pvSetText(p, btnid, text.c_str()); + //if (idx == idx) + //{ + // this->active_page_button(p, idx, pageIndex); + // pageIndex = idx; + //} + //x += (32); + } + } + int x = (count+1)*32; + pvMove(p, btnNext, x, 0); + pvMove(p, labelInfo, x+=32, 0); + pvSetText(p, labelInfo, (" 共" + std::to_string(count) + "页").c_str()); + pvResize(p, pvid, x += 81, 30); + this->activePage(pageIndex); } -int PvPagination::pageid() +int PvPagination::page() { - return page_id_; + return pageIndex; }; -void PvPagination::active_page_button(PARAM* p, int new_pageid, int old_pageid) +void PvPagination::activePage(int index, bool invoke) { - for (int i = 0; i < vec_btn_page_.size(); i++) - { - auto& item = vec_btn_page_[i]; - if (item.second != 0) - { - if (item.second == old_pageid) - { - pvSetStyleSheet(p, item.first, STYLE_NORMAL.c_str()); - } - if (item.second == new_pageid) - { - pvSetStyleSheet(p, item.first, STYLE_ACTIVE.c_str()); - } - } - } + if (pageCount == 0) + { + pageIndex = 0; + return; + } + pageIndex = index; + if (pageIndex < 0){ pageIndex = 0; } + if (pageIndex >= pageCount) { pageIndex = pageCount - 1; } + + pvSetEnabled(p, btnPrev, pageIndex != 0); + pvSetEnabled(p, btnNext, (pageIndex != pageCount - 1)); + + if (btnActive != PV_ID_NUL) { pvSetStyleSheet(p, btnActive, STYLE_NORMAL.c_str()); } + btnActive = vecBtn[pageIndex].first; + pvSetStyleSheet(p, btnActive, STYLE_ACTIVE.c_str()); + + if (invoke) + { + if (callback) callback(pageIndex); + } } -void PvPagination::set_goto_page_callback(std::function cb) +void PvPagination::setCallback(std::function func) { - cb_goto_ = cb; + callback = func; } -void PvPagination::on_click_page(int btnid) -{ - for (int i = 0; i < vec_btn_page_.size(); ++i) - { - auto& item = vec_btn_page_[i]; - if (btnid == item.first) - { - int page_id = item.second; - if (cb_goto_) { cb_goto_(page_id); } - return; - } - } -} - -void PvPagination::on_click_prev() -{ - if (page_id_ <= 1) - { - return; - } - if (cb_goto_) - { - cb_goto_(page_id_ - 1); - } -} - -void PvPagination::on_click_next() -{ - if (page_id_ >= page_count_) - { - return; - } - if (cb_goto_) - { - cb_goto_(page_id_ + 1); - } -} - - PvPageTable::PvPageTable(PARAM* p, int parent, int x, int y, int w, int rows, PvTable::Options& opts) //: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* rows + (opts.show_header ? (opts.header_height) : 0))) - : PvObject(p) + : PvObject(p) { - int h = opts.row_height* rows + (opts.show_header ? (opts.head_height) : 0); - int pvid_ = PvApp::widget(p, parent, x, y, w, h); - table_ = make_shared(p, pvid_, 0, 0, w, rows, opts); + int h = opts.row_height* rows + (opts.show_header ? (opts.head_height) : 0); + int pvid_ = PvApp::widget(p, parent, x, y, w, h); + table_ = make_shared(p, pvid_, 0, 0, w, rows, opts); } shared_ptr PvPageTable::getTable() { - return table_; + return table_; } \ No newline at end of file diff --git a/src/pv/PvTable.h b/src/pv/PvTable.h index 61dce6f..1222c2e 100644 --- a/src/pv/PvTable.h +++ b/src/pv/PvTable.h @@ -4,7 +4,7 @@ #include #include "PvApp.h" -#include "DataFields.h" +#include "Fields.h" using CallbackTableOpt = std::function; @@ -66,10 +66,11 @@ public: void set_text(PARAM* p, int row, int col, std::string text, std::string style = ""); - void setRowData(int row, DataFields& d); + void setRowData(int row, Fields& d); void setRowData(int row, std::vector vd); - DataFields& getRowdata(int row); + Fields getRowData(int row); + void mappingData(Fields& fields); void set_border_visible(PARAM* p, bool v); @@ -85,7 +86,7 @@ public: int colums(); - std::vector data(); + std::vector data(); PvTable::Head& header(int col); @@ -98,7 +99,7 @@ private: std::vector vecHead_; std::vector vecRows_; - std::vector vecData_; + std::vector vecData_; vector>> vecOpt_; int nRow_; @@ -119,43 +120,41 @@ private: class PvPagination : public PvObject { public: - PvPagination(PARAM* p, int parent, const PvRect& rt); + PvPagination(PARAM* p, int parent, int x, int y, int n); - void set_page(int page_id, int max_page); + void setPage(int index, int count); - int pageid(); + int page(); - void set_goto_page_callback(std::function cb); + void setCallback(std::function func); private: - void on_click_page(int btnid); - void on_click_prev(); - void on_click_next(); - - void active_page_button(PARAM* p, int new_pageid, int old_pageid); + void activePage(int index, bool invoke=false); private: - int pvid_ = PV_ID_NUL; - // 当前显示的页码索引, 从1开始 - int page_id_ = 1; + int pageIndex = 1; // 总页数 - int page_count_ = 0; + int pageCount = 0; // 上一页按钮 - int btn_prev_ = PV_ID_NUL; + int btnPrev = PV_ID_NUL; // 下一页按钮 - int btn_next_ = PV_ID_NUL; + int btnNext = PV_ID_NUL; // 页面跳转按钮 int btn_gopage_ = PV_ID_NUL; - // 页码列表(最多显示6个页码按钮,前3页和后3页) <按钮ID, 页码> - std::vector> vec_btn_page_; + int btnActive = PV_ID_NUL; - function cb_goto_ = nullptr; + int labelInfo = PV_ID_NUL; + + // 页码列表(最多显示6个页码按钮,前3页和后3页) <按钮ID, 页码> + std::vector> vecBtn; + + function callback = nullptr; }; diff --git a/src/pv/pages/MaskPageForecast.cpp b/src/pv/pages/MaskPageForecast.cpp index 2eb6c2a..f13949d 100644 --- a/src/pv/pages/MaskPageForecast.cpp +++ b/src/pv/pages/MaskPageForecast.cpp @@ -4,9 +4,9 @@ static int CreatePanel(PARAM* p, int parentId, int x, int y, int w, int h, std::string title) { - int id = PvApp::label(p, parentId, x, y, w, h, "", QSS_LABEL_BKG_2); - PvApp::label(p, id, 10, 10, w, 20, title, STYLE_TITLE_ICON); - PvApp::label(p, id, 20, 30, w, 2, "", QSS_UNDERLINE); + int id = PvApp::label(p, parentId, x, y, w, h, "", qss::LABEL_BKG_2); + PvApp::label(p, id, 10, 10, w, 20, title, qss::STYLE_TITLE_ICON); + PvApp::label(p, id, 20, 30, w, 2, "", qss::QSS_UNDERLINE); return id; } diff --git a/src/pv/pages/MaskPageHome.cpp b/src/pv/pages/MaskPageHome.cpp index 874f505..c73425a 100644 --- a/src/pv/pages/MaskPageHome.cpp +++ b/src/pv/pages/MaskPageHome.cpp @@ -8,23 +8,23 @@ static int CreatePanel(PARAM* p, int parent, int x, int y, int w, int h, std::string title) { - int panelId = PvApp::label(p, parent, x, y, w, h, "", QSS_LABEL_BKG_1); - int titleId = PvApp::label(p, panelId, 10, 8, w, 22, title, STYLE_TITLE_ICON); - PvApp::label(p, panelId, 20, 28, w, 2, "", QSS_UNDERLINE); + int panelId = PvApp::label(p, parent, x, y, w, h, "", qss::LABEL_BKG_1); + int titleId = PvApp::label(p, panelId, 10, 8, w, 22, title, qss::STYLE_TITLE_ICON); + PvApp::label(p, panelId, 20, 28, w, 2, "", qss::QSS_UNDERLINE); return panelId; } static int CreatePanel1(PARAM* p, int parent, int x, int y, int w, int h, std::string title) { - int panelId = PvApp::label(p, parent, x, y, w, h, "", "border: none; background-color: transparent;"); + int panelId = PvApp::label(p, parent, x, y, w, h, ""); PvApp::image(p, panelId, 0, 13, 500, 17, "bkgBox.png"); - PvApp::label(p, panelId, 20, 0, w-20, 30, title, "background-color: transparent; font: bold 18px;"); + PvApp::label(p, panelId, 20, 0, w-20, 30, title); return panelId; } static int CreateCard1(PARAM* p, int parentId, int x, int y, int w, int h, std::string title, std::string val) { - int id = PvApp::label(p, parentId, x, y, w, h, "", QSS_LABEL_BKG_1); + int id = PvApp::label(p, parentId, x, y, w, h, "", qss::LABEL_BKG_1); int idTitle = PvApp::label(p, id, 0, h*0.5, w, h*0.5, title, "background:transparent; font: bold 28px;"); int idVal = PvApp::label(p, id, 0, 0, w, h*0.5, val, "background:transparent; font: bold 28px; color:rgb(77,215,240);"); pvSetAlignment(p, idTitle, AlignCenter); @@ -34,9 +34,9 @@ static int CreateCard1(PARAM* p, int parentId, int x, int y, int w, int h, std:: static int CreateCard2(PARAM* p, int parent, int x, int y, int w, int h, std::string title, std::string val) { - int id = PvApp::label(p, parent, x, y, w, h, "", QSS_LABEL_BKG_1); + int id = PvApp::label(p, parent, x, y, w, h, "", qss::LABEL_BKG_1); - int idTitle = PvApp::label(p, id, 0, 0, w, h*0.5, title, "background:transparent; font: bold 16px;"); + int idTitle = PvApp::label(p, id, 0, 0, w, h*0.5, title); int idVal = PvApp::label(p, id, 0, h*0.5, w, h*0.5, val, "background:transparent; font: bold 16px; color:rgb(77,215,240);"); pvSetAlignment(p, idTitle, AlignCenter); pvSetAlignment(p, idVal, AlignCenter); @@ -54,8 +54,9 @@ static int CreateBox(PARAM* p, int parent, int x, int y, int w, int h, std::stri PvApp::label(p, id, w-len, h-len, len, len, "", qss + "border-width: 0 2px 2px 0"); PvApp::label(p, id, 0, h-len, len, len, "", qss + "border-width: 0 0 2px 2px"); } - int titleId = PvApp::label(p, id, 0, 0, w, h*0.5, k, "border:none; background-color: transparent; font: bold 14px; padding-bottom: 0px;"); - int valId = PvApp::label(p, id, 0, h*0.5, w, h*0.5, val, "border:none; background-color: transparent; font: bold 16px; color:rgb(77, 215, 240);"); + // "border:none; background-color: transparent; font: bold 14px; padding-bottom: 0px;" + int titleId = PvApp::label(p, id, 0, 0, w, h*0.5-2, k); + int valId = PvApp::label(p, id, 0, h*0.5+2, w, h*0.5-2, val, qss::label(16, "rgb(77, 215, 240)")); pvSetAlignment(p, titleId, AlignHCenter | AlignBottom); pvSetAlignment(p, valId, AlignHCenter | AlignTop); return valId; @@ -167,7 +168,7 @@ public: } } - void setTitle(std::string title) + void setStatus(std::string title) { pvSetText(p, labelTitle, title.c_str()); } @@ -265,7 +266,7 @@ int MaskPageHome::initUI(EPvCode pvcode) // 中间区域 { - int panel = PvApp::label(p, 0, x = 10+500+10, y, w = 880, h1+h2+h3+20, "", QSS_LABEL_BKG_1); + int panel = PvApp::label(p, 0, x = 10+500+10, y, w = 880, h1+h2+h3+20, "", qss::LABEL_BKG_1); ////// 饼图 //int left = PvApp::widget(p, panel, 100, 100, 100, 100); @@ -287,9 +288,9 @@ int MaskPageHome::initUI(EPvCode pvcode) auto popStation = new PopStation(p); popStation->show(0); - int btn = PvApp::button(p, panel, 10, 20, 100, 30, "场站一", STYLE_BTN); + int btn = PvApp::button(p, panel, 10, 20, 100, 30, "场站一", qss::BTN); PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { - popStation->setTitle("场站一"); + popStation->setStatus("场站一"); pvShow(p, popStation->widget); }); @@ -301,12 +302,16 @@ int MaskPageHome::initUI(EPvCode pvcode) } this->updateUI(); + + + auto pagination = new PvPagination(p, 0, 600, 160, 20); + pagination->setPage(5, 10); return 0; } void MaskPageHome::updateUI() { - auto& appdata = Application::instance().getAppData(); + auto& appdata = Application::data(); int stationNum = appdata.mapStation.size(); // 场站数量 double energyCapacity {}; // 储能容量 diff --git a/src/pv/pages/MaskPageRunning.cpp b/src/pv/pages/MaskPageRunning.cpp index ff0f72d..a715771 100644 --- a/src/pv/pages/MaskPageRunning.cpp +++ b/src/pv/pages/MaskPageRunning.cpp @@ -1,18 +1,11 @@ #include "MaskPageRunning.h" #include "app/Application.h" -static std::string QSS_CARD_DEVICE = -"QLabel { background-color:rgb(8, 54, 91); border:0px solid rgb(120, 120, 120); border-radius:5px; font:bold 14px; color:white; }" -"QLabel:hover {border: 2px solid rgb(79, 129, 255); border-radius:2px;}" -"QLabel:disabled { color:rgb(150,150,150);}"; - -static std::string QSS_PARAM_K = "border:none; background-color: transparent; color: rgb(180,180,180); font: bold 13px;"; -static std::string QSS_PARAM_V = "border:none; background-color: transparent; color: white; font: bold 14px;"; static int CreateParamLabel(PARAM* p, int parent, int x, int y, std::string k, std::string v) { - PvApp::label(p, parent, x, y, 70, 30, k, QSS_PARAM_K); - return PvApp::label(p, parent, x += 70, y, 120, 30, v, QSS_PARAM_V); + PvApp::label(p, parent, x, y, 70, 30, k, qss::LABEL_KEY); + return PvApp::label(p, parent, x += 70, y, 120, 30, v, qss::LABEL_VAL); } class BoxCard : PvObject @@ -25,25 +18,25 @@ public: BoxCard(PARAM* p, int parent, int x, int y) : PvObject(p) { - card_ = PvApp::label(p, parent, x, y, 400, 250, "", QSS_CARD_DEVICE); + card_ = PvApp::label(p, parent, x, y, 400, 250, "", qss::QSS_CARD_DEVICE); PvApp::label(p, card_, 10, 10, 60, 60, "", "border:none; background-color: rgb(39, 158, 145);"); - ui.code = PvApp::label(p, card_, 80, 10, 100, 20, "", "border:none; background-color: transparent;"); - ui.name = PvApp::label(p, card_, 80, 30, 100, 20, "", "border:none; background-color: transparent;"); - ui.type = PvApp::label(p, card_, 80, 50, 100, 20, "", "border:none; background-color: transparent; color: rgb(8, 161, 249);"); + ui.code = PvApp::label(p, card_, 80, 10, 100, 20, ""); + ui.name = PvApp::label(p, card_, 80, 30, 100, 20, ""); + ui.type = PvApp::label(p, card_, 80, 50, 100, 20, "", qss::label(14, "rgb(8, 161, 249)")); int x1 = 190; - ui.online = PvApp::labelAlignCenter(p, card_, x1, 10, 70, 30, "在线", QSS_PARAM_V); - ui.running = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "空闲", QSS_PARAM_V); - ui.err = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "正常", QSS_PARAM_V); + ui.online = PvApp::labelAlignCenter(p, card_, x1, 10, 70, 30, "在线", qss::LABEL_VAL); + ui.running = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "空闲", qss::LABEL_VAL); + ui.err = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "正常", qss::LABEL_VAL); - PvApp::labelAlignCenter(p, card_, x1 = 190, 40, 70, 30, "在线状态", QSS_PARAM_K); - PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "工作状态", QSS_PARAM_K); - PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "故障状态", QSS_PARAM_K); + PvApp::labelAlignCenter(p, card_, x1 = 190, 40, 70, 30, "在线状态", qss::LABEL_KEY); + PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "工作状态", qss::LABEL_KEY); + PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "故障状态", qss::LABEL_KEY); - PvApp::label(p, card_, 10, 80, 80, 30, "运行分析:", QSS_PARAM_K); - PvApp::button(p, card_, 80, 83, 60, 24, "查看", "border:none; border-radius: 5px; background-color: rgb(28, 145, 138); color:white; font: bold 14px;"); + PvApp::label(p, card_, 10, 80, 80, 30, "运行分析:", qss::LABEL_KEY); + PvApp::button(p, card_, 80, 83, 60, 24, "查看"); // 默认创建 10 个参数标签: int n = 10; @@ -53,8 +46,8 @@ public: int row = i/2; int col = i%2; int h = 25; - vecParamLabel_[i].first = PvApp::label(p, card_, 10 + 200*col, 115 + h*row, 70, h, "参数"+std::to_string(i) + ":", QSS_PARAM_K); - vecParamLabel_[i].second = PvApp::label(p, card_, 10 + 200*col + 70, 115 + h*row, 120, h, "---", QSS_PARAM_V); + vecParamLabel_[i].first = PvApp::label(p, card_, 10 + 200*col, 115 + h*row, 70, h, "参数"+std::to_string(i) + ":", qss::LABEL_KEY); + vecParamLabel_[i].second = PvApp::label(p, card_, 10 + 200*col + 70, 115 + h*row, 120, h, "---", qss::LABEL_VAL); } } @@ -117,13 +110,12 @@ int MaskPageRunning::initUI(EPvCode pvcode) PvApp::label(p, 0, 10, 150, 220, 790, "", "background-color: rgb(8, 54, 91); border-radius: 10px;"); int workspace = PvApp::label(p, 0, 240, 150, 1670, 790, "", "background-color: rgba(8, 54, 91, 0); border-radius: 10px;"); - std::vector vecStationNames; - Application::instance().getAppData().getStationNames(vecStationNames); + std::vector vecStationNames = Application::data().getStationNames(); PvApp::label(p, 0, 20, 110, 80, 30, "场站切换", "color:white; font: bold 16px;"); PvApp::combox(p, 0, 100, 110, 150, 30, vecStationNames); if (vecStationNames.size() > 0) { - station_ = Application::instance().getAppData().getStationByName(vecStationNames[0]); + station_ = Application::data().getStationByName(vecStationNames[0]); } PvApp::label(p, 0, 320, 110, 80, 30, "运行模式", "color:white; font: bold 16px;"); @@ -136,8 +128,8 @@ int MaskPageRunning::initUI(EPvCode pvcode) // 储能设备 { ui.storage.name = "储能设备"; - int pid = ui.storage.box = PvApp::label(p, 0, x, y, w, h, "", QSS_BOX); - PvApp::label(p, pid, 10, 0, w-10, 30, ui.storage.name, QSS_TITLE); + int pid = ui.storage.box = PvApp::label(p, 0, x, y, w, h, "", qss::LABEL_BOX); + PvApp::label(p, pid, 10, 0, w-10, 30, ui.storage.name, qss::LABEL_TITLE); ui.storage.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;"); ui.storage.workspace = PvApp::widget(p, workspace, 0, 0, 1670, 790); @@ -156,8 +148,8 @@ int MaskPageRunning::initUI(EPvCode pvcode) // 光伏设备 { ui.solar.name = "光伏设备"; - int pid = ui.solar.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", QSS_BOX); - PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, QSS_TITLE); + int pid = ui.solar.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", qss::LABEL_BOX); + PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, qss::LABEL_TITLE); ui.solar.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;"); ui.solar.workspace = ui.storage.workspace; @@ -166,8 +158,8 @@ int MaskPageRunning::initUI(EPvCode pvcode) // 充电设备 { ui.charge.name = "充电设备"; - int pid = ui.charge.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", QSS_BOX); - PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, QSS_TITLE); + int pid = ui.charge.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", qss::LABEL_BOX); + PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, qss::LABEL_TITLE); ui.charge.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;"); ui.charge.workspace = ui.storage.workspace; @@ -176,8 +168,8 @@ int MaskPageRunning::initUI(EPvCode pvcode) // 环境与安防设备 { ui.security.name = "环境与安防设备"; - int pid = ui.security.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", QSS_BOX); - PvApp::label(p, pid, 10, 0, w-10, 30, ui.security.name, QSS_TITLE); + int pid = ui.security.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", qss::LABEL_BOX); + PvApp::label(p, pid, 10, 0, w-10, 30, ui.security.name, qss::LABEL_TITLE); ui.security.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;"); ui.security.workspace = PvApp::widget(p, workspace, 0, 0, 1670, 790); @@ -222,8 +214,8 @@ void MaskPageRunning::activeBoxPanel(BoxPanel& panel) { static int activeBox = PV_ID_NUL; static int activeWorkspace = PV_ID_NUL; - if (activeBox != PV_ID_NUL) { pvSetStyleSheet(p, activeBox, QSS_BOX.c_str()); } - if (activeBox = panel.box) { pvSetStyleSheet(p, activeBox, QSS_BOX_ACTIVE.c_str()); } + if (activeBox != PV_ID_NUL) { pvSetStyleSheet(p, activeBox, qss::LABEL_BOX.c_str()); } + if (activeBox = panel.box) { pvSetStyleSheet(p, activeBox, qss::QSS_BOX_ACTIVE.c_str()); } if (activeWorkspace != PV_ID_NUL) { pvHide(p, activeWorkspace); } if (activeWorkspace = panel.workspace) { pvShow(p, activeWorkspace); } diff --git a/src/pv/pages/MaskPageStat.cpp b/src/pv/pages/MaskPageStat.cpp index 0c3d6a9..ff40722 100644 --- a/src/pv/pages/MaskPageStat.cpp +++ b/src/pv/pages/MaskPageStat.cpp @@ -4,9 +4,9 @@ static int CreatePanel(PARAM* p, int parentId, int x, int y, int w, int h, std::string title) { - int id = PvApp::label(p, parentId, x, y, w, h, "", QSS_LABEL_BKG_2); - PvApp::label(p, id, 10, 10, w, 20, title, STYLE_TITLE_ICON); - PvApp::label(p, id, 20, 30, w, 2, "", QSS_UNDERLINE); + int id = PvApp::label(p, parentId, x, y, w, h, "", qss::LABEL_BKG_2); + PvApp::label(p, id, 10, 10, w, 20, title, qss::STYLE_TITLE_ICON); + PvApp::label(p, id, 20, 30, w, 2, "", qss::QSS_UNDERLINE); return id; } @@ -52,7 +52,7 @@ static VecStatDef statDef = { int MaskPageStat::initUI(EPvCode pvcode) { - PvApp::label(p, PV_ID_MAIN, 10, 100, 1900, 850, "", QSS_LABEL_BKG_1); + PvApp::label(p, PV_ID_MAIN, 10, 100, 1900, 850, "", qss::LABEL_BKG_1); if (pvcode == EPvCode::MASK_STAT) { pvcode = EPvCode::MASK_STAT_STORAGE; } std::string curModuleName; @@ -63,7 +63,7 @@ int MaskPageStat::initUI(EPvCode pvcode) std::string moduleName = statDef[i].first; // 创建按钮 bool isActive = (PvApp::getPvCode(moduleName) == pvcode); - int pageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*190), 110, 180, 40, moduleName, isActive ? QSS_BTN_MGR_ACTIVE : QSS_BTN_MGR); + int pageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*190), 110, 180, 40, moduleName, isActive ? qss::QSS_BTN_MGR_ACTIVE : qss::QSS_BTN_MGR); mapSubpage_[pageBtn] = moduleName; if (isActive) { diff --git a/src/pv/pages/MaskPageSysmgr.cpp b/src/pv/pages/MaskPageSysmgr.cpp index f14f7f6..3cff900 100644 --- a/src/pv/pages/MaskPageSysmgr.cpp +++ b/src/pv/pages/MaskPageSysmgr.cpp @@ -1,8 +1,12 @@ #include "MaskPageSysmgr.h" -#include "pv/PvTable.h" + #include -#include "database/Dao.h" +#include "common/Snowflake.h" +#include "pv/PvTable.h" #include "pv/PvPopWidget.h" +#include "database/Dao.h" +#include "app/Application.h" +#include "PageSysmgrPop.h" static void createPvTable(PARAM* p) { @@ -69,236 +73,13 @@ static void createPvTable(PARAM* p) } -class PageTable : public PvMask -{ -public: - PageTable(PARAM* p) : PvMask(p) - { - table = std::make_shared(p, 0, 10, 160, 1900, 20, option); - table->setOperateCallback([=](int row, int col, std::string text) { this->onCallbackOperate(row, col, text); }); - }; - - void setPage(int pageIndex, int pageSize, int count) {} - - void updateDataFromDB() - { - std::vector result; - PageInfo pageInfo; - this->queryTable(pageInfo, result); - for (int i = 0; irows(); ++i) - { - if (isetRowData(i, result[i]); - } - else - { - table->setRowVisible(i, false); - } - } - } - - virtual void queryTable(PageInfo& pageInfo, std::vector& result) {} - virtual void onCallbackOperate(int row, int col, std::string text) {}; - - int pageIndex {0}; - PvTable::Options option; - std::shared_ptr table; - std::shared_ptr pop; -}; - -class PageUser : public PageTable -{ -public: - PageUser(PARAM* p, EPvCode pvcode) :PageTable(p) - { - table->addHead(DMUser::USER_ID, "用户编号", 180, {}); - table->addHead(DMUser::ACCOUNT, "用户名", 180, {}); - table->addHead(DMUser::NAME, "姓名", 180, {}); - table->addHead(DMUser::GENDER, "性别", 180, {{"1", "男"}, {"0","女"}}); - table->addHead(DMUser::AGE, "年龄", 180, {}); - table->addHead(DMUser::PHONE, "手机号", 180, {}); - table->addHead(DMUser::EMAIL, "邮箱", 180, {}); - table->addHead("role_id", "角色", 180, {}); - table->addHead(DMUser::LOGINTIME, "上次登录时间", 200, {}); - table->addOperate({"编辑"}); - - pop = std::make_shared(p, 700, 500); - pop->show(0); - pop->setCallbackConfirm([=]() { - auto fields = pop->getData(); - XLOGD() << fields.toStr(); - // 保存数据: - DAO::updateUserById(fields); - }); - - int x = 50, y = 100, w=350, h=60; - pop->addParamLineEdit(DMUser::USER_ID, "用户编号", x, y, false); - pop->addParamCombox(DMRole::ROLE_ID, "角 色", x+w, y, {"系统管理员", "运营管理员", "运营人员"}); - pop->addParamLineEdit(DMUser::ACCOUNT, "用 户 名", x, y+=h); - pop->addParamLineEdit(DMUser::NAME, "姓 名", x+w, y); - pop->addParamLineEdit(DMUser::GENDER, "性 别", x, y+=h); - pop->addParamLineEdit(DMUser::AGE, "年 龄", x+w, y); - pop->addParamLineEdit(DMUser::PHONE, "手 机 号", x, y += h); - pop->addParamLineEdit(DMUser::EMAIL, "邮 箱", x+w, y); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - DAO::queryUserList(pageInfo, result); - } - void onCallbackOperate(int row, int col, std::string text) - { - if (text == "编辑") - { - pop->show(1); - pop->setTitle("编辑用户信息"); - DataFields fields = table->getRowdata(row); - pop->setData(fields); - } - }; -}; - -class PageRole : public PageTable -{ -public: - PageRole(PARAM* p, EPvCode pvcode) : PageTable(p) - { - table->addHead(DMRole::ROLE_ID, "角色编号", 200, {}); - table->addHead(DMRole::NAME, "角色名称", 200, {}); - table->addHead(DMRole::DESCRIBE, "角色描述", 900, {}); - table->addHead(DMRole::IS_OPEN, "是否启用", 200, {{"1", "是"}, {"0", "否"}}); - table->addOperate({"编辑", "设置权限"}); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - DAO::queryRoleList(pageInfo, result); - } -}; - -class PagePermission : public PageTable -{ -public: - PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p) - { - table->addHead(DMPermission::PERMISSION_ID,"权限编号", 200, {}); - table->addHead(DMPermission::NAME, "权限名称", 200, {}); - table->addHead(DMPermission::DESCRIBE, "权限描述", 900, {}); - table->addHead(DMPermission::IS_OPEN, "是否启用", 200, {{"1", "是"}, {"0", "否"}}); - table->addOperate({"查看"}); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - DAO::queryPermissionList(pageInfo, result); - } -}; - -class PageStation : public PageTable -{ -public: - PageStation(PARAM* p, EPvCode pvcode) : PageTable(p) - { - table->addHead(DMStation::STATION_ID, "场站编号", 200, {}); - table->addHead(DMStation::NAME, "场站名称", 200, {}); - table->addHead(DMStation::ADDRESS, "地址", 200, {}); - table->addHead(DMStation::LONGITUDE, "经度", 200, {}); - table->addHead(DMStation::LATITUDE, "维度", 200, {}); - table->addHead(DMStation::TEL, "电话", 200, {}); - table->addHead(DMStation::STATUS, "状态", 200, {{"0","未启用"}, {"1", "启用"}}); - table->addOperate({"查看", "编辑"}); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - DAO::queryStationList(pageInfo, result); - } -}; - -class PageDevice: public PageTable -{ -public: - PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p) - { - table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {}); - table->addHead(DMDevice::TYPE, "设备类型", 120, {}); - table->addHead(DMDevice::NAME, "设备名称", 180, {}); - table->addHead(DMDevice::CODE, "设备编码", 160, {}); - table->addHead(DMDevice::MODEL, "设备型号", 160, {}); - table->addHead(DMDevice::FACTORY, "厂家", 160, {}); - table->addHead(DMDevice::TEL, "厂家电话", 160, {}); - table->addHead(DMDevice::ATTRS, "设备参数", 460, {}); - table->addHead(DMDevice::IS_OPEN, "是否启用", 120, {{"1", "是"}, {"0", "否"}}); - table->addOperate({"查看", "编辑"}); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - DAO::queryDeviceList(pageInfo, result); - } -}; - -class PagePolicy : public PageTable -{ -public: - PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p) - { - table->addHead(DMPolicy::POLICY_ID, "策略编号", 200, {}); - table->addHead(DMPolicy::TYPE, "策略类型", 200, {}); - table->addHead(DMPolicy::NAME, "策略名称", 200, {}); - table->addHead(DMPolicy::DESCRIBE, "策略描述", 400, {}); - table->addHead(DMPolicy::VALUE, "策略参数", 400, {}); - table->addHead(DMPolicy::IS_OPEN, "是否启用", 200, {{"1", "是"}, {"0", "否"}}); - table->addOperate({"查看", "编辑"}); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - DAO::queryPolicyList(pageInfo, result); - } -}; - -class PageSyslog : public PageTable -{ -public: - PageSyslog(PARAM* p, EPvCode pvcode) : PageTable(p) - { - table->addHead(DMSystemLog::LOG_ID, "日志编号", 160, {}); - table->addHead(DMSystemLog::TYPE, "日志类型", 160, {}); - table->addHead(DMSystemLog::USER_ACCOUNT, "用户", 160, {}); - table->addHead(DMSystemLog::CONTENT, "日志详情", 800, {}); - table->addHead(DMSystemLog::STATUS, "状态", 160, {}); - table->addHead(DMSystemLog::CREATE_TIME, "记录时间", 200, {}); - table->addOperate({"查看"}); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - DAO::querySystemLogList(pageInfo, result); - } -}; - -class PageAlertlog : public PageTable -{ -public: - PageAlertlog(PARAM* p, EPvCode pvcode) : PageTable(p) - { - table->addHead(DMAlertLog::LOG_ID, "日志编号", 160, {}); - table->addHead(DMAlertLog::TYPE, "日志类型", 160, {}); - table->addHead(DMAlertLog::DEVICE_ID, "设备ID", 160, {}); - table->addHead(DMAlertLog::CONTENT, "日志详情", 800, {}); - table->addHead(DMAlertLog::STATUS, "状态", 160, {}); - table->addHead(DMAlertLog::CREATE_TIME, "记录时间", 200, {}); - table->addOperate({"查看"}); - } - void queryTable(PageInfo& pageInfo, std::vector& result) - { - //DAO::queryAlertLogList(pageInfo, result); - } -}; - MaskPageSysmgr::MaskPageSysmgr(PARAM* p) : PvMask(p) { } int MaskPageSysmgr::initUI(EPvCode pvcode) { - PvApp::label(p, PV_ID_MAIN, 10, 100, 1900, 850, "", QSS_LABEL_BKG_1); + PvApp::label(p, PV_ID_MAIN, 10, 150, 1900, 790, "", qss::LABEL_BKG_1); if (pvcode == EPvCode::MASK_SYSMGR) { pvcode = EPvCode::MASK_MGR_USER; } @@ -307,7 +88,7 @@ int MaskPageSysmgr::initUI(EPvCode pvcode) { std::string& title = vecPageNames[i]; bool isActive = (PvApp::getPvCode(title) == pvcode); - int idPageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*110), 110, 100, 40, title, isActive ? QSS_BTN_MGR_ACTIVE : QSS_BTN_MGR); + int idPageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*110), 100, 100, 40, title, isActive ? qss::QSS_BTN_MGR_ACTIVE : qss::QSS_BTN_MGR); mapSubpage_[idPageBtn] = title; } diff --git a/src/pv/pages/PageSysmgrPop.cpp b/src/pv/pages/PageSysmgrPop.cpp new file mode 100644 index 0000000..945729d --- /dev/null +++ b/src/pv/pages/PageSysmgrPop.cpp @@ -0,0 +1,518 @@ +#include "PageSysmgrPop.h" + + +#include "app/Application.h" +#include "database/Dao.h" +#include "database/DataModelDef.h" +#include "common/Snowflake.h" + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageTable === +PageTable::PageTable(PARAM* p) : PvMask(p) +{ + table = std::make_shared(p, 0, 20, 210, 1880, pageSize, option); + table->setOperateCallback([=](int row, int col, std::string text) { this->onOperate(row, col, text); }); + + pagination = std::make_shared(p, 0, 20, 780, 20); + pagination->setCallback([=](int index) + { + pageIndex = index; + this->updateDataFromDB(); + }); +} +std::shared_ptr PageTable::addPop(int w, int h, int w0, std::string name, std::vector primaryKeys) +{ + std::shared_ptr pop = std::make_shared(p, w, h, name); + pop->lineValWidth = w0; + pop->setPrimaryKeys(primaryKeys); + pop->setCallbackConfirm([=]() + { + auto fields = pop->getData(); + std::string err = this->onValidation(pop, fields); + pop->setMsg(err); + + if (err.empty()) + { + XLOGD() << "POP get: data=" << fields.toStr(); + if (pop->status == POP_OPER_EDIT) { pop->checkChangedData(fields); } + XLOGD() << "POP get: data=" << fields.toStr(); + table->mappingData(fields); + XLOGD() << "POP get: data=" << fields.toStr(); + err = this->onPopConfirm(pop, fields); + pop->setMsg(err); + if (err.empty()) + { + this->hidePop(0); + this->updateDataFromDB(); + }; + } + }); + pop->show(0); + vecPop.push_back(pop); + return pop; +} +void PageTable::showPop(int index, std::string oper, Fields& fields) +{ + XLOGD() << "POP set: data=" << fields.toStr(); + table->mappingData(fields); + XLOGD() << "POP set: data=" << fields.toStr(); + if (index < vecPop.size()) + { + auto& pop = vecPop[index]; + pop->show(true); + pop->setStatus(oper); + pop->setData(fields); + pop->setMsg(""); + } +} +void PageTable::hidePop(int index) +{ + if (index < vecPop.size()) + { + vecPop[index]->show(false); + } +} +void PageTable::updateDataFromDB() +{ + std::vector result; + PageInfo pageInfo; + pageInfo.size = pageSize; + pageInfo.index = pageIndex; + this->onQueryTable(pageInfo, result); + for (int i = 0; irows(); ++i) + { + if (isetRowData(i, result[i]); + } + else + { + table->setRowVisible(i, false); + } + } + pagination->setPage(pageInfo.index, pageInfo.total/pageInfo.size + int(pageInfo.total%pageInfo.size != 0)); +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageUser === +PageUser::PageUser(PARAM* p, EPvCode pvcode) :PageTable(p) +{ + auto& appdata = Application::data(); + table->addHead(DMUser::USER_ID, "用户编号", 180, {}); + table->addHead(DMUser::ACCOUNT, "用户名", 180, {}); + table->addHead(DMUser::NAME, "姓名", 180, {}); + table->addHead(DMUser::GENDER, "性别", 180, appdata.mapping.gender); + table->addHead(DMUser::AGE, "年龄", 180, {}); + table->addHead(DMUser::PHONE, "手机号", 180, {}); + table->addHead(DMUser::EMAIL, "邮箱", 180, {}); + table->addHead(DMRole::ROLE_ID, "角色", 180, appdata.mapping.role); + table->addHead(DMUser::LOGINTIME, "上次登录时间", 200, {}); + table->addOperate({"编辑"}); + + int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); }); + + int x = 50, y = 80, w = 350, h = 60; + auto pop = this->addPop(700, 500, 180, "用户信息", {DMUser::USER_ID}); + pop->addParamLineEdit(DMUser::USER_ID, "编号", x, y, false); + pop->addParamCombox(DMRole::ROLE_ID, "角色", x+w, y, appdata.getRoleNames()); + pop->addParamLineEdit(DMUser::ACCOUNT, "用户名", x, y += h); + pop->addParamLineEdit(DMUser::NAME, "姓名", x+w, y); + pop->addParamCombox(DMUser::GENDER, "性别", x, y += h, {"女", "男"}); + pop->addParamLineEdit(DMUser::AGE, "年龄", x+w, y); + pop->addParamLineEdit(DMUser::PHONE, "手机号", x, y += h); + pop->addParamLineEdit(DMUser::EMAIL, "邮箱", x+w, y); +} + +void PageUser::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + DAO::queryUserList(pageInfo, result); +} +void PageUser::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +}; +std::string PageUser::onValidation(std::shared_ptr pop, Fields& fields) +{ + if (fields.value(DMUser::ACCOUNT).empty()) { return "请输入用户名"; } + return ""; +}; +std::string PageUser::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + if (pop->status == POP_OPER_NEW) + { + Errcode err = DAO::insertUser(fields); + if (err == Errcode::OK) { return ""; } + else if (err == Errcode::ERR_DB_DUPLICATE) { return "用户名已经存在"; } + else { return "系统错误"; } + } + else if (pop->status == POP_OPER_EDIT) + { + Errcode err = DAO::updateUserById(fields); + if (err == Errcode::OK) { return ""; } + else { return "系统错误"; } + } + return ""; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageRole === +PageRole::PageRole(PARAM* p, EPvCode pvcode) : PageTable(p) +{ + auto& appdata = Application::data(); + + table->addHead(DMRole::ROLE_ID, "角色编号", 200, {}); + table->addHead(DMRole::NAME, "角色名称", 200, {}); + table->addHead(DMRole::DESCRIBE, "角色描述", 900, {}); + table->addHead(DMRole::IS_OPEN, "是否启用", 200, appdata.mapping.isopen); + table->addOperate({"编辑"}); + + int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); }); + + int x = 80, y = 80, h = 60; + auto pop = this->addPop(500, 600, 180, "角色信息", {DMUser::USER_ID}); + pop->addParamLineEdit(DMRole::ROLE_ID, "编号", x, y, false); + pop->addParamLineEdit(DMRole::NAME, "名称", x, y += h); + pop->addParamCombox(DMUser::IS_OPEN, "是否启用", x, y += h, {"启用", "禁用"}); + pop->addParamTextEdit(DMRole::DESCRIBE, "描述", x, y += h); + +} +void PageRole::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + DAO::queryRoleList(pageInfo, result); +} +void PageRole::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +} +std::string PageRole::onValidation(std::shared_ptr pop, Fields& fields) +{ + return ""; +}; +std::string PageRole::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + + return ""; +} +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PagePermission === +PagePermission::PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p) +{ + auto& appdata = Application::data(); + table->addHead(DMPermission::PERMISSION_ID, "权限编号", 200, {}); + table->addHead(DMPermission::NAME, "权限名称", 200, {}); + table->addHead(DMPermission::DESCRIBE, "权限描述", 900, {}); + table->addHead(DMPermission::IS_OPEN, "是否启用", 200, appdata.mapping.isopen); + table->addOperate({"编辑"}); + + int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); }); + + int x = 80, y = 80, h = 60; + auto pop = this->addPop(500, 600, 180, "角色信息", {DMPermission::PERMISSION_ID}); + pop->addParamLineEdit(DMPermission::PERMISSION_ID, "编号", x, y, false); + pop->addParamLineEdit(DMPermission::NAME, "名称", x, y += h); + pop->addParamCombox(DMPermission::IS_OPEN, "是否启用", x, y += h, {"启用", "禁用"}); + pop->addParamTextEdit(DMPermission::DESCRIBE, "描述", x, y += h); +} +void PagePermission::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + DAO::queryPermissionList(pageInfo, result); +} +void PagePermission::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +} +std::string PagePermission::onValidation(std::shared_ptr pop, Fields& fields) +{ + return ""; +}; +std::string PagePermission::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + return ""; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageStation === +PageStation::PageStation(PARAM* p, EPvCode pvcode) : PageTable(p) +{ + auto& appdata = Application::data(); + table->addHead(DMStation::STATION_ID, "场站编号", 200, {}); + table->addHead(DMStation::NAME, "场站名称", 200, {}); + table->addHead(DMStation::ADDRESS, "地址", 200, {}); + table->addHead(DMStation::LONGITUDE, "经度", 200, {}); + table->addHead(DMStation::LATITUDE, "维度", 200, {}); + table->addHead(DMStation::TEL, "电话", 200, {}); + table->addHead(DMStation::STATUS, "状态", 200, appdata.mapping.isopen); + table->addOperate({"编辑"}); + + int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); }); + + int x = 80, y = 80, h = 60; + auto pop = this->addPop(500, 600, 240, "场站信息", {DMStation::STATION_ID}); + pop->addParamLineEdit(DMStation::STATION_ID, "编号", x, y, false); + pop->addParamLineEdit(DMStation::NAME, "名称", x, y += h); + pop->addParamLineEdit(DMStation::ADDRESS, "地址", x, y += h); + pop->addParamLineEdit(DMStation::LONGITUDE, "经度", x, y += h); + pop->addParamLineEdit(DMStation::LATITUDE, "维度", x, y += h); + pop->addParamLineEdit(DMStation::TEL, "电话", x, y += h); + pop->addParamCombox(DMStation::STATUS, "状态", x, y += h, {"启用", "禁用"}); +} +void PageStation::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + DAO::queryStationList(pageInfo, result); +} +void PageStation::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +} +std::string PageStation::onValidation(std::shared_ptr pop, Fields& fields) +{ + return ""; +}; +std::string PageStation::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + if (pop->status == POP_OPER_NEW) + { + Errcode err = DAO::insertStation(fields); + if (err == Errcode::OK) { return ""; } + else { return "系统错误"; } + } + else if (pop->status == POP_OPER_EDIT) + { + Errcode err = DAO::updateStationById(fields); + if (err == Errcode::OK) { return ""; } + else { return "系统错误"; } + } + return ""; +} +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageDevice === +PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p) +{ + auto& appdata = Application::data(); + table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {}); + table->addHead(DMDevice::TYPE_ID, "设备类型", 120, appdata.mapping.deviceType); + table->addHead(DMDevice::NAME, "设备名称", 180, {}); + table->addHead(DMDevice::CODE, "设备编码", 160, {}); + table->addHead(DMDevice::MODEL, "设备型号", 160, {}); + table->addHead(DMDevice::FACTORY, "厂家", 160, {}); + table->addHead(DMDevice::TEL, "厂家电话", 160, {}); + table->addHead(DMDevice::ATTRS, "设备参数", 460, {}); + table->addHead(DMDevice::IS_OPEN, "是否启用", 120, appdata.mapping.isopen); + table->addOperate({"编辑"}); + + int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); }); + + int x = 50, y = 80, w = 350, h = 60; + auto pop = this->addPop(700, 520, 180, "设备信息", {DMDevice::DEVICE_ID}); + pop->addParamLineEdit(DMDevice::DEVICE_ID, "设备编号", x, y, false); + pop->addParamCombox(DMDevice::TYPE_ID, "类型", x+w, y, appdata.getDeviceTypes()); + pop->addParamLineEdit(DMDevice::NAME, "设备名称", x, y += h); + pop->addParamLineEdit(DMDevice::CODE, "设备编码", x+w, y); + pop->addParamLineEdit(DMDevice::MODEL, "设备型号", x, y += h); + pop->addParamLineEdit(DMDevice::FACTORY, "厂家", x+w, y); + pop->addParamLineEdit(DMDevice::TEL, "厂家电话", x, y += h); + pop->addParamCombox(DMDevice::IS_OPEN, "是否启用", x+w, y, {"启用", "禁用"}); + pop->addParamLineEdit(DMDevice::ATTRS, "设备参数", x, y += h); +} +void PageDevice::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + DAO::queryDeviceList(pageInfo, result); +} +void PageDevice::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +} +std::string PageDevice::onValidation(std::shared_ptr pop, Fields& fields) +{ + return ""; +}; +std::string PageDevice::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + if (pop->status == POP_OPER_NEW) + { + Errcode err = DAO::insertDevice(fields); + if (err == Errcode::OK) { return ""; } + else { return "系统错误"; } + } + else if (pop->status == POP_OPER_EDIT) + { + Errcode err = DAO::updateDeviceById(fields); + if (err == Errcode::OK) { return ""; } + else { return "系统错误"; } + } + return ""; +} +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PagePolicy === +PagePolicy::PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p) +{ + auto& appdata = Application::data(); + table->addHead(DMPolicy::POLICY_ID, "策略编号", 200, {}); + table->addHead(DMPolicy::TYPE, "策略类型", 200, {}); + table->addHead(DMPolicy::NAME, "策略名称", 200, {}); + table->addHead(DMPolicy::DESCRIBE, "策略描述", 400, {}); + table->addHead(DMPolicy::VALUE, "策略参数", 400, {}); + table->addHead(DMPolicy::IS_OPEN, "是否启用", 200, appdata.mapping.isopen); + table->addOperate({ "编辑"}); + + int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); + PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); }); + + int x = 80, y = 80, h = 60; + auto pop = this->addPop(500, 600, 180, "策略信息", {DMPolicy::POLICY_ID}); + pop->addParamLineEdit(DMPolicy::POLICY_ID, "编号", x, y, false); +} +void PagePolicy::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + DAO::queryPolicyList(pageInfo, result); +} +void PagePolicy::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +} +std::string PagePolicy::onValidation(std::shared_ptr pop, Fields& fields) +{ + return ""; +}; +std::string PagePolicy::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + + return ""; +} +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageSyslog === +PageSyslog::PageSyslog(PARAM* p, EPvCode pvcode) : PageTable(p) +{ + table->addHead(DMSystemLog::LOG_ID, "日志编号", 160, {}); + table->addHead(DMSystemLog::TYPE, "日志类型", 160, {}); + table->addHead(DMSystemLog::USER_ACCOUNT, "用户", 160, {}); + table->addHead(DMSystemLog::CONTENT, "日志详情", 800, {}); + table->addHead(DMSystemLog::STATUS, "状态", 160, {}); + table->addHead(DMSystemLog::CREATE_TIME, "记录时间", 200, {}); + table->addOperate({"查看"}); +} +void PageSyslog::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + DAO::querySystemLogList(pageInfo, result); +} +void PageSyslog::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +} +std::string PageSyslog::onValidation(std::shared_ptr pop, Fields& fields) +{ + return ""; +}; +std::string PageSyslog::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + return ""; +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageAlertlog === +PageAlertlog::PageAlertlog(PARAM* p, EPvCode pvcode) : PageTable(p) +{ + table->addHead(DMAlertLog::LOG_ID, "日志编号", 160, {}); + table->addHead(DMAlertLog::TYPE, "日志类型", 160, {}); + table->addHead(DMAlertLog::DEVICE_ID, "设备ID", 160, {}); + table->addHead(DMAlertLog::CONTENT, "日志详情", 800, {}); + table->addHead(DMAlertLog::STATUS, "状态", 160, {}); + table->addHead(DMAlertLog::CREATE_TIME, "记录时间", 200, {}); + table->addOperate({"查看"}); +} +void PageAlertlog::onQueryTable(PageInfo& pageInfo, std::vector& result) +{ + //DAO::queryAlertLogList(pageInfo, result); +} +void PageAlertlog::onOperate(int row, int col, std::string oper) +{ + if (oper == POP_OPER_NEW) + { + Fields fields; + fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr()); + this->showPop(0, oper, fields); + } + else if (oper == POP_OPER_EDIT) + { + this->showPop(0, oper, table->getRowData(row)); + } +} +std::string PageAlertlog::onValidation(std::shared_ptr pop, Fields& fields) +{ + return ""; +}; +std::string PageAlertlog::onPopConfirm(std::shared_ptr pop, Fields& fields) +{ + return ""; +} \ No newline at end of file diff --git a/src/pv/pages/PageSysmgrPop.h b/src/pv/pages/PageSysmgrPop.h new file mode 100644 index 0000000..2879ffd --- /dev/null +++ b/src/pv/pages/PageSysmgrPop.h @@ -0,0 +1,137 @@ +#pragma once +#include "pv/PvApp.h" +#include "pv/PvTable.h" +#include "pv/PvPopWidget.h" + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageTable === +class PageTable : public PvMask +{ +public: + PageTable(PARAM* p); + + void setPage(int pageIndex, int pageSize, int count) {} + + std::shared_ptr addPop(int w, int h, int w0, std::string name, std::vector primaryKeys); + + void showPop(int index, std::string optr, Fields& fields); + void hidePop(int index); + + void updateDataFromDB(); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) {} + virtual void onOperate(int row, int col, std::string oper) {}; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) { return ""; }; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) { return ""; }; + + int pageSize {15}; + int pageIndex {0}; + PvTable::Options option; + std::shared_ptr table; + std::shared_ptr pagination; + std::vector> vecPop; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageUser === +class PageUser : public PageTable +{ +public: + PageUser(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageRole === +class PageRole : public PageTable +{ +public: + PageRole(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override ; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PagePermission === +class PagePermission : public PageTable +{ +public: + PagePermission(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageStation === +class PageStation : public PageTable +{ +public: + PageStation(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageDevice === +class PageDevice : public PageTable +{ +public: + PageDevice(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PagePolicy === +class PagePolicy : public PageTable +{ +public: + PagePolicy(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageSyslog === +class PageSyslog : public PageTable +{ +public: + PageSyslog(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// === PageAlertlog === +class PageAlertlog : public PageTable +{ +public: + PageAlertlog(PARAM* p, EPvCode pvcode); + + virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; + virtual void onOperate(int row, int col, std::string oper) override; + virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; + virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; +}; \ No newline at end of file diff --git a/src/pv/pvmain.cpp b/src/pv/pvmain.cpp index fd7f29f..b2e9a6e 100644 --- a/src/pv/pvmain.cpp +++ b/src/pv/pvmain.cpp @@ -48,6 +48,7 @@ int pvMain(PARAM* p) pvStartDefinition(p, 1024); if (mask) { + pvSetFont(p, PV_ID_MAIN, "微软雅黑", 12, 1, 0, 0, 0); mask->initUI(); } pvQLayoutVbox(p, 0, -1); diff --git a/src/widgets/WebHandler.cpp b/src/widgets/WebHandler.cpp index ebb9319..d157d63 100644 --- a/src/widgets/WebHandler.cpp +++ b/src/widgets/WebHandler.cpp @@ -10,7 +10,7 @@ #include "app/Admin.h" #include "app/Device.h" -static void VariantListRes(std::vector& data, QVariantList& listRes) +static void VariantListRes(std::vector& data, QVariantList& listRes) { for (auto& fields: data) { @@ -23,7 +23,7 @@ static void VariantListRes(std::vector& data, QVariantList& listRes) } } -static void JSsetResPaginaion(QVariantMap& result, std::vector& data, int page, int pageSize, int count, int code, string err) +static void JSsetResPaginaion(QVariantMap& result, std::vector& data, int page, int pageSize, int count, int code, string err) { result["code"] = code; result["err"] = "操作成功"; @@ -44,7 +44,7 @@ static void JSsetResPaginaion(QVariantMap& result, std::vector& data result["data"] = listRow; } -static void JSgetReqParam(QString key, QVariantMap& params, DataFields& fields) +static void JSgetReqParam(QString key, QVariantMap& params, Fields& fields) { if (params.contains(key)) fields.set(key.toStdString(), params[key].toString().toStdString()); } @@ -103,7 +103,7 @@ void MyWebHandler::loginOut(const QString& username) QVariantMap MyWebHandler::queryUserList(int page, int pageSize) { XLOGD() << "[cppNative] queryUserList"; - std::vector res; + std::vector res; DAO::queryUser(res); QVariantMap result; @@ -113,7 +113,7 @@ QVariantMap MyWebHandler::queryUserList(int page, int pageSize) int MyWebHandler::insertUser(QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("account", params, fields); fields.set("passwd", "123456"); JSgetReqParam("name", params, fields); @@ -133,7 +133,7 @@ int MyWebHandler::insertUser(QVariantMap params) if (params.contains("role_id")) { int role_id = params["role_id"].toInt(); - DataFields fieldsUserRole; + Fields fieldsUserRole; fieldsUserRole.set("user_id", user_id); fieldsUserRole.set("role_id", role_id); fieldsUserRole.set("create_time", Utils::timeNowStr()); @@ -150,7 +150,7 @@ int MyWebHandler::updateUser(const QString& userId, QVariantMap params) XLOGD() << "[cppNative] updateUser"; int ret = 1; - DataFields fields; + Fields fields; JSgetReqParam("account", params, fields); JSgetReqParam("name", params, fields); @@ -190,7 +190,7 @@ QVariantMap MyWebHandler::queryRoleList(int page, int pageSize) { QVariantMap result; - std::vector res; + std::vector res; auto dao = DAO::get("role"); bool ret = dao->exec("SELECT * FROM role;", res); JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功"); @@ -208,7 +208,7 @@ QVariantMap MyWebHandler::queryRoleList(int page, int pageSize) int MyWebHandler::insertRole(QVariantMap params) { - DataFields fields; + Fields fields; if (params.contains("name")) fields.set("name", params["name"].toString().toStdString()); if (fields.size() == 0) { @@ -226,7 +226,7 @@ int MyWebHandler::insertRole(QVariantMap params) int MyWebHandler::deleteRole(const QString& roleId) { return 1; } int MyWebHandler::updateRole(const QString& roleId, QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("name", params, fields); JSgetReqParam("describe", params, fields); if (fields.size() <= 0) @@ -243,7 +243,7 @@ int MyWebHandler::updateRole(const QString& roleId, QVariantMap params) QVariantList MyWebHandler::queryRolePermissionList(int roleId) { - std::vector result; + std::vector result; std::string sql = "SELECT p.permission_id, p.name, rp.role_id, rp.is_open FROM permission p " "LEFT JOIN role_permission rp ON(rp.permission_id = p.permission_id AND rp.role_id = '" + std::to_string(roleId) +"') WHERE p.is_open='1';"; @@ -269,13 +269,13 @@ int MyWebHandler::updateRolePermission(int roleId, QVariantList params) std::string sql = "DELETE FROM role_permission WHERE role_id='" + std::to_string(roleId) + "';"; bool ret = dao->exec(sql); - std::vector vecFields; + std::vector vecFields; for (QVariant& item: params) { if (item.canConvert()) { QVariantMap itemMap = item.toMap(); - DataFields fields; + Fields fields; fields.set("role_id", roleId); JSgetReqParam("permission_id", itemMap, fields); JSgetReqParam("is_open", itemMap, fields); @@ -290,7 +290,7 @@ int MyWebHandler::updateRolePermission(int roleId, QVariantList params) // 权限管理接口 QVariantMap MyWebHandler::queryPermissionList(int page, int pageSize) { - std::vector res; + std::vector res; auto dao = DAO::get("permission"); bool ret = dao->exec("SELECT * FROM permission;", res); @@ -301,7 +301,7 @@ QVariantMap MyWebHandler::queryPermissionList(int page, int pageSize) int MyWebHandler::insertPermission(QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("name", params, fields); JSgetReqParam("describe", params, fields); JSgetReqParam("is_open", params, fields); @@ -316,7 +316,7 @@ int MyWebHandler::insertPermission(QVariantMap params) int MyWebHandler::deletePermission(const QString& permissionId) { return 1; } int MyWebHandler::updatePermission(const QString& permissionId, QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("name", params, fields); JSgetReqParam("describe", params, fields); JSgetReqParam("is_open", params, fields); @@ -338,7 +338,7 @@ QVariantMap MyWebHandler::queryDeviceList(int page, int pageSize) { XLOGD() << "queryDeviceList:"; - std::vector res; + std::vector res; auto dao = DAO::get("device"); bool ret = dao->exec("SELECT * FROM device;", res); XLOGD() << "queryDeviceList: size=" << res.size(); @@ -397,7 +397,7 @@ QVariantList MyWebHandler::queryDevice(QVariantMap params) std::string sql = "SELECT * FROM device WHERE " + sqlc + ";"; auto dao = DAO::get("device"); - std::vector res; + std::vector res; bool ret = dao->exec(sql, res); XLOGD() << "sql=" << sql; XLOGD() << "queryDevice: size=" << res.size(); @@ -410,7 +410,7 @@ QVariantList MyWebHandler::queryDevice(QVariantMap params) int MyWebHandler::insertDevice(QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("type", params, fields); JSgetReqParam("name", params, fields); JSgetReqParam("code", params, fields); @@ -431,7 +431,7 @@ int MyWebHandler::insertDevice(QVariantMap params) int MyWebHandler::deleteDevice(const QString& deviceId) { return 1; } int MyWebHandler::updateDevice(const QString& deviceId, QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("type", params, fields); JSgetReqParam("name", params, fields); JSgetReqParam("code", params, fields); @@ -477,7 +477,7 @@ QVariantList MyWebHandler::queryDeviceTypeList() // 计费管理接口 QVariantMap MyWebHandler::queryPriceList(int page, int pageSize) { - std::vector res; + std::vector res; auto dao = DAO::get("price"); bool ret = dao->exec("SELECT * FROM price;", res); XLOGD() << "queryPriceList: size=" << res.size(); @@ -488,7 +488,7 @@ QVariantMap MyWebHandler::queryPriceList(int page, int pageSize) } int MyWebHandler::insertPrice(QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("type", params, fields); JSgetReqParam("describe", params, fields); JSgetReqParam("is_open", params, fields); @@ -506,7 +506,7 @@ int MyWebHandler::insertPrice(QVariantMap params) int MyWebHandler::deletePrice(const QString& priceId) { return 1; } int MyWebHandler::updatePrice(const QString& priceId, QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("name", params, fields); JSgetReqParam("type", params, fields); JSgetReqParam("describe", params, fields); @@ -543,7 +543,7 @@ QVariantList MyWebHandler::queryPriceTypeList() QVariantMap MyWebHandler::queryPolicyList(int page, int pageSize) { - std::vector res; + std::vector res; auto dao = DAO::get("policy"); bool ret = dao->exec("SELECT * FROM policy;", res); XLOGD() << "queryPolicyList: size=" << res.size(); @@ -555,7 +555,7 @@ QVariantMap MyWebHandler::queryPolicyList(int page, int pageSize) int MyWebHandler::insertPolicy(QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("type", params, fields); JSgetReqParam("name", params, fields); JSgetReqParam("value", params, fields); @@ -577,7 +577,7 @@ int MyWebHandler::deletePolicy(const QString& policyId) { return 1; } int MyWebHandler::updatePolicy(const QString& policyId, QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("type", params, fields); JSgetReqParam("name", params, fields); JSgetReqParam("value", params, fields); @@ -618,7 +618,7 @@ QVariantList MyWebHandler::queryPolicyTypeList() QVariantMap MyWebHandler::querySyslogList(int page, int pageSize) { - std::vector res; + std::vector res; auto dao = DAO::get("system_log"); bool ret = dao->exec("SELECT * FROM system_log;", res); XLOGD() << "querySyslogList: size=" << res.size(); @@ -630,7 +630,7 @@ QVariantMap MyWebHandler::querySyslogList(int page, int pageSize) QVariantMap MyWebHandler::querySecPolicyList(int page, int pageSize) { - std::vector res; + std::vector res; auto dao = DAO::get("sec_policy"); bool ret = dao->exec("SELECT * FROM sec_policy;", res); XLOGD() << "querySecPolicyList: size=" << res.size(); @@ -642,7 +642,7 @@ QVariantMap MyWebHandler::querySecPolicyList(int page, int pageSize) int MyWebHandler::insertSecPolicy(QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("name", params, fields); JSgetReqParam("type", params, fields); JSgetReqParam("code", params, fields); @@ -664,7 +664,7 @@ int MyWebHandler::insertSecPolicy(QVariantMap params) int MyWebHandler::updateSecPolicy(const QString& policyId, QVariantMap params) { - DataFields fields; + Fields fields; JSgetReqParam("name", params, fields); JSgetReqParam("type", params, fields); JSgetReqParam("code", params, fields); @@ -686,7 +686,7 @@ int MyWebHandler::updateSecPolicy(const QString& policyId, QVariantMap params) QVariantMap MyWebHandler::querySecRecordList(int page, int pageSize) { - std::vector res; + std::vector res; auto dao = DAO::get("sec_record"); bool ret = dao->exec("SELECT * FROM sec_record;", res); XLOGD() << "querySecRecordList: size=" << res.size(); diff --git a/src/widgets/uihelper.cpp b/src/widgets/uihelper.cpp index a71ea9d..47523e9 100644 --- a/src/widgets/uihelper.cpp +++ b/src/widgets/uihelper.cpp @@ -267,7 +267,7 @@ ChartBarView::ChartBarView(QWidget* parent, QRect rt, int xfrag) //chart_->legend()->update(); } -void ChartBarView::setTitle(std::string title) +void ChartBarView::setStatus(std::string title) { //chart_->setTitle(title.c_str()); labTitle_.setText(title.c_str()); diff --git a/src/widgets/uihelper.h b/src/widgets/uihelper.h index deb7e57..1ccdd84 100644 --- a/src/widgets/uihelper.h +++ b/src/widgets/uihelper.h @@ -77,7 +77,7 @@ class ChartBarView : public QChartView public: ChartBarView(QWidget* parent, QRect rt, int xfrag=5); - void setTitle(std::string title); + void setStatus(std::string title); std::shared_ptr chart();