#include "AxisCfgDao.h" AxisCfgDao::AxisCfgDao(SQLite::Database* pdb) :BaseDao(pdb) { } AxisCfgDao::~AxisCfgDao() { } void AxisCfgDao::CreateTable() { if (m_pDB->tableExists(AxisCfg::TABLE_NAME))return; char buffer[1024]; sprintf_s(buffer, sizeof(buffer), "CREATE TABLE %s(%s INTEGER PRIMARY KEY AUTOINCREMENT,%s INTEGER,%s VARCHAR(50),%s VARCHAR(50),UNIQUE(%s,%s))" , AxisCfg::TABLE_NAME.c_str(), AxisCfg::FIELD_ID.c_str(), AxisCfg::FIELD_AXIS_ID.c_str(), AxisCfg::FIELD_CODE.c_str(), AxisCfg::FIELD_VALUE.c_str(), AxisCfg::FIELD_AXIS_ID.c_str(), AxisCfg::FIELD_CODE.c_str()); m_pDB->exec(buffer); } void AxisCfgDao::Find(map& cfgMap) { char buffer[2048]; vector needins; for (map::iterator it = cfgMap.begin(); it != cfgMap.end();it++) { AxisCfg* cfg = it->second; sprintf_s(buffer, sizeof(buffer),"SELECT * FROM %s WHERE %s=%d",AxisCfg::TABLE_NAME.c_str(),AxisCfg::FIELD_AXIS_ID.c_str(),cfg->m_axis_id); SQLite::Statement query(*m_pDB, buffer); map valueMap; while (query.executeStep()) { valueMap[query.getColumn(AxisCfg::FIELD_CODE.c_str()).getString()]=query.getColumn(AxisCfg::FIELD_VALUE.c_str()).getString(); } sprintf_s(buffer, sizeof(buffer), "INSERT INTO %s(%s,%s,%s) VALUES(%d,", AxisCfg::TABLE_NAME.c_str(), AxisCfg::FIELD_AXIS_ID.c_str(), AxisCfg::FIELD_CODE.c_str(), AxisCfg::FIELD_VALUE.c_str(), cfg->m_axis_id); string strhead=string(buffer); if (valueMap.find(AxisCfg::CODE_NAME) != valueMap.end()) { cfg->m_name = valueMap[AxisCfg::CODE_NAME]; } else { sprintf_s(buffer, sizeof(buffer),"%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_NAME.c_str(),cfg->m_name.c_str()); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_ACTIVE_LIMIT) != valueMap.end()) { cfg->m_active_limit->SetValue(stoi(valueMap[AxisCfg::CODE_ACTIVE_LIMIT])); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_ACTIVE_LIMIT.c_str(), cfg->m_active_limit->GetValueStr().c_str()); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_NEGACTIVE_LIMIT) != valueMap.end()) { cfg->m_negactive_limit->SetValue(stoi(valueMap[AxisCfg::CODE_NEGACTIVE_LIMIT])); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_NEGACTIVE_LIMIT.c_str(), cfg->m_negactive_limit->GetValueStr().c_str()); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_ACTIVE_DIRECT) != valueMap.end()) { cfg->m_active_direct->SetValue(stoi(valueMap[AxisCfg::CODE_ACTIVE_DIRECT])); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_ACTIVE_DIRECT.c_str(), cfg->m_active_direct->GetValueStr().c_str()); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_OVER_LOAD_LIMIT) != valueMap.end()) { cfg->m_OverLoadLimit->SetValue(stof(valueMap[AxisCfg::CODE_OVER_LOAD_LIMIT])); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_OVER_LOAD_LIMIT.c_str(), cfg->m_OverLoadLimit->GetValueStr().c_str()); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_SHOW_POS_INV) != valueMap.end()) { cfg->m_ShowPosInv->SetValue(stoi(valueMap[AxisCfg::CODE_SHOW_POS_INV])>0?true:false); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_SHOW_POS_INV.c_str(), cfg->m_ShowPosInv?"1":"0"); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_SHOW_REF_ZERO) != valueMap.end()) { cfg->m_ShowRefZero->SetValue(stod(valueMap[AxisCfg::CODE_SHOW_REF_ZERO])); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_SHOW_REF_ZERO.c_str(), cfg->m_ShowRefZero->GetValueStr().c_str()); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_MAX_LOAD_VALUE) != valueMap.end()) { cfg->m_MaxLoadValue->SetValue(stof(valueMap[AxisCfg::CODE_MAX_LOAD_VALUE])); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_MAX_LOAD_VALUE.c_str(), cfg->m_MaxLoadValue->GetValueStr().c_str()); needins.push_back(buffer); } if (valueMap.find(AxisCfg::CODE_SAFE_LIMIT) != valueMap.end()) { cfg->m_SafeLimit->SetValue( stoi(valueMap[AxisCfg::CODE_SAFE_LIMIT])>0?true:false); } else { sprintf_s(buffer, sizeof(buffer), "%s'%s','%s')", strhead.c_str(), AxisCfg::CODE_SAFE_LIMIT.c_str(), cfg->m_SafeLimit?"1":"0"); needins.push_back(buffer); } } if (!needins.empty()) { SQLite::Transaction transaction(*m_pDB); for (size_t i = 0; i < needins.size(); ++i) { m_pDB->exec(needins[i]); } transaction.commit(); } } void AxisCfgDao::Save(map& axismap) { vector ups; axismap[GTS_AXIS_ID_MOLD]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_LOAD]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_ARM]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_SUPPLY]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_CLEAN]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_ELE]->GetUpdateSql(ups); for (size_t i = 0; i < ups.size();i++) { m_pDB->exec(ups[i]); } } void AxisCfgDao::Export(map& axismap, stringstream &sql) { vector ups; axismap[GTS_AXIS_ID_MOLD]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_LOAD]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_ARM]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_SUPPLY]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_CLEAN]->GetUpdateSql(ups); axismap[GTS_AXIS_ID_ELE]->GetUpdateSql(ups); for (size_t i = 0; i < ups.size(); i++) { sql<exec(buffer); }