源码参考:
#include "CServerManager.h"
CServerManager* CServerManager::m_pInstance = NULL;
CServerManager::CServerManager(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags),
m_strServerIP("10.23.188.23"),
m_iServerPort(10001)
{
ui.setupUi(this);
initLayout();
}
CServerManager* CServerManager::getInstance()
{
if ( NULL == m_pInstance)
{
m_pInstance = new CServerManager;
}
return m_pInstance;
}
CServerManager::~CServerManager()
{
}
void CServerManager::initLayout()
{
ui.gridLayout_4->setColumnStretch(0, 1);
ui.gridLayout_4->setColumnStretch(1, 1);
ui.gridLayout_5->setColumnStretch(0, 1);
ui.gridLayout_5->setColumnStretch(1, 4);
ui.lineEditIP->setMaximumWidth(120);
ui.lineEditPort->setMaximumWidth(120);
ui.gridLayout->setColumnStretch(0 ,1);
ui.gridLayout->setColumnStretch(1 ,1);
//IP端口初始化
ui.gridLayout->setContentsMargins(10, 10,10, 10);
ui.groupBoxNodeManage->setMaximumHeight(200);
ui.comboBoxConfig->setMinimumWidth(150);
ui.groupBoxDNS->setMaximumHeight(55);
ui.comboBoxIP->setMinimumWidth(120);
ui.mainDNSlineEdit->setMinimumWidth(120);
ui.spareDNSlineEdit->setMinimumWidth(120);
ui.mainDNSlineEdit->setMaximumWidth(120);
ui.spareDNSlineEdit->setMaximumWidth(120);
//正则表达
QRegExp rxIP(cstIpRegExp);
QValidator *pValidatorIP = new QRegExpValidator(rxIP, this);
QRegExp rxPort(cstPortRegExp);
QValidator* pValidatorPort = new QRegExpValidator(rxPort, this);
QRegExp rxDNSMain(cstIpRegExp);
QValidator *pValidatorDNSMain = new QRegExpValidator(rxDNSMain, this);
QRegExp rxDNSSpace(cstIpRegExp);
QValidator *pValidatorDNSSpace = new QRegExpValidator(rxDNSSpace, this);
//DNS输入设置
ui.mainDNSlineEdit->setValidator(pValidatorDNSMain);
ui.spareDNSlineEdit->setValidator(pValidatorDNSSpace);
//设置服务器IP和端口号
ui.lineEditIP->setValidator(pValidatorIP);
ui.lineEditPort->setValidator(pValidatorPort);
m_cApsServerManageClient = CApsServerManageClient::getInstance();
//界面表格初始化
m_pTableNetConfig = new QTableWidget(ui.groupBoxNetConfig);
m_pTableRounting = new QTableWidget(ui.groupBoxRoutingTable);
m_pTableNodeManage = new QTableWidget(ui.groupBoxNodeManage);
m_pTableSeverManage = new QTableWidget(ui.groupBoxSeverManage);
m_pTableConfigManage = new QTableWidget(ui.groupBoxConfigManage);
//设置路由表格的右键弹出菜单
m_pActionAddRout = new QAction(tr("增加行"), ui.groupBoxRoutingTable);
m_pActionDelRout = new QAction(tr("删除"), ui.groupBoxRoutingTable);
m_pActionModefyRout = new QAction(tr("更新"), ui.groupBoxRoutingTable);
//设置IP及端口
connect(ui.pushButtonInitConfig, SIGNAL(clicked()), this, SLOT(OnInitIPPort()));
//设置网络配置表格的右键弹出菜单
m_pActionAddNetConfig = new QAction(tr("增加行"), ui.groupBoxNetConfig);
//m_pActionDelNetConfig = new QAction(tr("删除"), ui.groupBoxNetConfig);
m_pActionRestartNetConfig = new QAction(tr("重启"), ui.groupBoxNetConfig);
m_pActionStartNetConfig = new QAction(tr("启动"), ui.groupBoxNetConfig);
m_pActionStopNetConfig = new QAction(tr("停止"), ui.groupBoxNetConfig);
m_pActionModefyNetConfig = new QAction(tr("更新"), ui.groupBoxNetConfig);
//设置节点服务器右键弹出菜单
m_pActionNodeManageAdd = new QAction(tr("增加行"), ui.groupBoxNodeManage);
m_pActionNodeManageDel = new QAction(tr("删除节点"), ui.groupBoxNodeManage);
m_pActionNodeManageRestart = new QAction(tr("重启节点"), ui.groupBoxNodeManage);
m_pActionNodeManageChangePwd = new QAction(tr("修改密码"), ui.groupBoxNodeManage);
m_pActionNodeManageModefy = new QAction(tr("添加节点"), ui.groupBoxNodeManage);
//设置服务管理右键弹出菜单
m_pActionSeverManageStart = new QAction(tr("启动"), ui.groupBoxSeverManage);
m_pActionSeverManageStop = new QAction(tr("停止"), ui.groupBoxSeverManage);
m_pActionSeverManageRestart = new QAction(tr("重启"), ui.groupBoxSeverManage);
m_pActionSeverManageInstall = new QAction(tr("安装"), ui.groupBoxSeverManage);
m_pActionSeverManageUnload = new QAction(tr("卸载"), ui.groupBoxSeverManage);
m_pActionSeverManagePromotion = new QAction(tr("升级"), ui.groupBoxSeverManage);
m_pActionSeverManageAdd = new QAction(tr("增加行"), ui.groupBoxSeverManage);
//设置配置文件表格右键弹出菜单
m_pActionUploadConfig = new QAction(tr("上传配置"), ui.groupBoxConfigManage);
m_pActionAddConfig = new QAction(tr("增加行"), ui.groupBoxConfigManage);
QHeaderView* pVHeadViewNetConfig = m_pTableNetConfig->verticalHeader();
pVHeadViewNetConfig->setContextMenuPolicy(Qt::CustomContextMenu);
QHeaderView* pVHeadViewRouting = m_pTableRounting->verticalHeader();
pVHeadViewRouting->setContextMenuPolicy(Qt::CustomContextMenu);
QHeaderView* pVHeadViewNodeManage = m_pTableNodeManage->verticalHeader();
pVHeadViewNodeManage->setContextMenuPolicy(Qt::CustomContextMenu);
QHeaderView* pVHeadViewSeverManage = m_pTableSeverManage->verticalHeader();
pVHeadViewSeverManage->setContextMenuPolicy(Qt::CustomContextMenu);
m_pTableConfigManage->setContextMenuPolicy(Qt::CustomContextMenu);
connect(pVHeadViewRouting, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnRoutingcustomContextMenuRequested(const QPoint&)));
connect(pVHeadViewNetConfig, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnNetworkcustomContextMenuRequested(const QPoint&)));
connect(pVHeadViewNodeManage, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnNodeManagecustomContextMenuRequested(const QPoint&)));
connect(pVHeadViewSeverManage, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnSeverManagecustomContextMenuRequested(const QPoint&)));
connect(m_pTableConfigManage, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OnConfigManagecustomContextMenuRequested(const QPoint&)));
connect(ui.comboBoxIP, SIGNAL(activated(int)), this, SLOT(OnUpdataComboxChange(int)));
connect(ui.comboBoxConfig, SIGNAL(activated(int)), this, SLOT(OnShowConfigManage(int)));
connect(m_pActionAddRout, SIGNAL(triggered()), this, SLOT(OnAddRouting()));
connect(m_pActionDelRout, SIGNAL(triggered()), this, SLOT(OnDelRouting()));
connect(m_pActionModefyRout, SIGNAL(triggered()), this, SLOT(OnUpdataRoutingModefy()));
connect(m_pActionAddNetConfig, SIGNAL(triggered()), this, SLOT(OnAddNetConfig()));
//connect(m_pActionDelNetConfig, SIGNAL(triggered()), this, SLOT(OnDelNetConfig()));
connect(m_pActionRestartNetConfig, SIGNAL(triggered()), this, SLOT(OnRestartNetConfig()));
connect(m_pActionStartNetConfig, SIGNAL(triggered()), this, SLOT(OnStartNetConfig()));
connect(m_pActionStopNetConfig, SIGNAL(triggered()), this, SLOT(OnStopNetConfig()));
connect(m_pActionModefyNetConfig, SIGNAL(triggered()), this, SLOT(OnModefyNetConfig()));
connect(m_pActionNodeManageAdd, SIGNAL(triggered()), this, SLOT(OnNodeManageAdd()));
connect(m_pActionNodeManageDel, SIGNAL(triggered()), this, SLOT(OnNodeManageDel()));
connect(m_pActionNodeManageRestart, SIGNAL(triggered()), this, SLOT(OnNodeManageRestart()));
connect(m_pActionNodeManageChangePwd, SIGNAL(triggered()), this, SLOT(OnNodeManageChangePwd()));
connect(m_pActionNodeManageModefy, SIGNAL(triggered()), this, SLOT(OnNodeManageModefy()));
connect(m_pActionSeverManageAdd, SIGNAL(triggered()), this, SLOT(OnSeverManageAdd()));
connect(m_pActionSeverManageStart, SIGNAL(triggered()), this, SLOT(OnSeverManageStart()));
connect(m_pActionSeverManageStop, SIGNAL(triggered()), this, SLOT(OnSeverManageStop()));
connect(m_pActionSeverManageRestart, SIGNAL(triggered()), this, SLOT(OnSeverManageRestart()));
connect(m_pActionSeverManageInstall, SIGNAL(triggered()), this, SLOT(OnSeverManageInstall()));
connect(m_pActionSeverManageUnload, SIGNAL(triggered()), this, SLOT(OnSeverManageUnload()));
connect(m_pActionSeverManagePromotion, SIGNAL(triggered()), this, SLOT(OnSeverManagePromotion()));
connect(m_pActionAddConfig, SIGNAL(triggered()), this, SLOT(OnConfigManageAdd()));
connect(m_pActionUploadConfig, SIGNAL(triggered()), this, SLOT(OnConfigManageUpload()));
connect(ui.pushButtonAddDNS, SIGNAL(clicked()), this, SLOT(OnAddDNS()));
connect(ui.pushButtonDelDNS, SIGNAL(clicked()), this, SLOT(OnDelDNS()));
//开启线程
qRegisterMetaType<CGetClusterStat>("CGetClusterStat");
m_pCSeverThread = new CSeverThread;
connect(m_pCSeverThread, SIGNAL(sigLogReturn(CGetClusterStat)), this, SLOT(OnGetDataThread(CGetClusterStat)));
QFile file("./res/OMSCONFIG.xml");
if (!file.open(QIODevice::ReadOnly))
{
//QMessageBox::information(this, tr("提示"), tr("文件读取失败"));
return;
}
QByteArray data = file.readAll();
file.close();
QDomDocument doc;
QString strError;
if(!doc.setContent(data, false, &strError))
{
//QMessageBox::information(this, tr("提示"), tr("文件读取失败"));
return;
}
QDomElement docElem = doc.documentElement();
if (docElem.tagName() != QString("OMSCONFIG"))
{
//QMessageBox::information(this, tr("提示"), tr("文件读取失败"));
return;
}
QDomElement docItem = docElem.firstChildElement(QString("SeverConfig"));
QDomElement itemFirstchild = docItem.firstChildElement(QString("node"));
while (!itemFirstchild.isNull())
{
m_strServerIP = itemFirstchild.attribute(QString("SeverConfigIP"));
m_iServerPort = itemFirstchild.attribute(QString("SeverConfigPort")).toInt();
itemFirstchild = itemFirstchild.nextSiblingElement("node");
}
ui.lineEditIP->setText(m_strServerIP);
ui.lineEditPort->setText(QString::number(m_iServerPort));
}
void CServerManager::OnGetDataThread(CGetClusterStat cGetCluStat)
{
if (cGetCluStat.m_cOptRet.m_iOprCode == 0)
{
m_pmsgBox->close();
//QMessageBox::information(this, tr("提示"), tr("连接成功"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("配置连接成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
m_cGetCluStat = cGetCluStat;
}
else
{
m_pmsgBox->close();
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置连接失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("连接失败,请检查网络"));
return;
}
// 获取节点列表
std::vector<CNodeInfo> vecNodeInfo = m_cGetCluStat.m_cNodeInfoVector;
std::vector<CNodeInfo>::const_iterator iteVecNodeInfo = vecNodeInfo.begin();
ui.comboBoxIP->clear();
for (; iteVecNodeInfo != vecNodeInfo.end(); iteVecNodeInfo++)
{
ui.comboBoxIP->addItem(QString::fromStdString(iteVecNodeInfo->m_sIPAddr));
}
ui.comboBoxIP->setCurrentIndex(0);
//OnUpdataComboxChange(0);
//OnShowConfigManage(0);
//保存IP 端口
QFile fileTmp("./res/OMSCONFIG.xml");
if(!fileTmp.open(QIODevice::ReadOnly))
{
//QMessageBox::information(this, tr("提示"), tr("文件操作失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置保存失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
// mesBox.exec();
fileTmp.close();
return;
}
QByteArray data = fileTmp.readAll();
fileTmp.close();
QDomDocument doc;
QString strError;
if(!doc.setContent(data, false, &strError))
{
//QMessageBox::information(this, tr("提示"), tr("文件操作失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置保存失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
//mesBox.exec();
return;
}
QDomElement docElem = doc.documentElement();
if (docElem.tagName() != QString("OMSCONFIG"))
{
//QMessageBox::information(this, tr("提示"), tr("文件操作失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置保存失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
//mesBox.exec();
return;
}
QDomElement docItem = docElem.firstChildElement(QString("SeverConfig"));
QDomElement itemFirstchild = docItem.firstChildElement(QString("node"));
while (!itemFirstchild.isNull())
{
itemFirstchild.removeAttribute(QString("SeverConfigIP"));
itemFirstchild.removeAttribute(QString("SeverConfigPort"));
itemFirstchild.setAttribute(QString("SeverConfigIP"), ui.lineEditIP->text());
itemFirstchild.setAttribute(QString("SeverConfigPort"), ui.lineEditPort->text());
itemFirstchild = itemFirstchild.nextSiblingElement("node");
}
QFile file("./res/OMSCONFIG.xml");
if(!file.open(QIODevice::WriteOnly))
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置保存失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
//mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("文件操作失败"));
file.close();
return;
}
if(-1 == file.write(doc.toByteArray()))
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置保存失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
//mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("文件操作失败"));
file.close();
return;
}
else
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("配置保存成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
//mesBox.exec();
}
file.close();
}
void CServerManager::resizeEvent(QResizeEvent * event)
{
initTableRouting();
initTableNetConfig();
initNodeManage();
initSeverManage();
initConfigManage();
}
//表格初始化
void CServerManager::showEvent(QShowEvent *event)
{
initTableRouting();
initTableNetConfig();
initNodeManage();
initSeverManage();
initConfigManage();
}
/************************************************************************/
/*初始化表格 */
/************************************************************************/
//初始化网络配置表头
void CServerManager::initTableNetConfig()
{
m_pTableNetConfig->clear();
int iWidth = ui.groupBoxNetConfig->width();
int iHeight = ui.groupBoxNetConfig->height();
//设置表头
m_pTableNetConfig->setColumnCount(6);
m_pTableNetConfig->setHorizontalHeaderItem(0,new QTableWidgetItem(tr("名称")));
m_pTableNetConfig->setHorizontalHeaderItem(1,new QTableWidgetItem("IP"));
m_pTableNetConfig->setHorizontalHeaderItem(2,new QTableWidgetItem(tr("子网掩码")));
m_pTableNetConfig->setHorizontalHeaderItem(3,new QTableWidgetItem(tr("网关")));
m_pTableNetConfig->setHorizontalHeaderItem(4,new QTableWidgetItem(tr("启动方")));
m_pTableNetConfig->setHorizontalHeaderItem(5,new QTableWidgetItem(tr("是否启动")));
m_pTableNetConfig->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
//自动适应大小
m_pTableNetConfig->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
//设置代理
CLineEditDelegate* cLineEditDelegate = new CLineEditDelegate;
m_pTableNetConfig->setItemDelegateForColumn(1, cLineEditDelegate);
m_pTableNetConfig->setItemDelegateForColumn(2, cLineEditDelegate);
m_pTableNetConfig->setItemDelegateForColumn(3, cLineEditDelegate);
QList<QString> lstComboBoxItemsbStart;
lstComboBoxItemsbStart.append(tr("是"));
lstComboBoxItemsbStart.append(tr("否"));
CComboBoxDelegate* cComboBoxDelegateBstart = new CComboBoxDelegate(lstComboBoxItemsbStart);
m_pTableNetConfig->setItemDelegateForColumn(5, cComboBoxDelegateBstart);
QList<QString> lstComboBoxItemBootProto;
lstComboBoxItemBootProto.append("none");
lstComboBoxItemBootProto.append("static");
lstComboBoxItemBootProto.append("dhcp");
CComboBoxDelegate* cComboBoxDelegateBootProto = new CComboBoxDelegate(lstComboBoxItemBootProto);
m_pTableNetConfig->setItemDelegateForColumn(4, cComboBoxDelegateBootProto);
//设置表格显示位置
m_pTableNetConfig->resize(iWidth - 30, iHeight - 30);
m_pTableNetConfig->move(15, 15);
}
//路由配置表格初始化
void CServerManager::initTableRouting()
{
m_pTableRounting->clear();
int iWidth = ui.groupBoxRoutingTable->width();
int iHeight = ui.groupBoxRoutingTable->height();
//设置表头
m_pTableRounting->setColumnCount(4);
m_pTableRounting->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("目的网络")));
m_pTableRounting->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("网关")));
m_pTableRounting->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("子网掩码")));
m_pTableRounting->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("网卡名称")));
//自动适应大小
m_pTableRounting->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
//设置代理
CLineEditDelegate* cLineEditDelegate = new CLineEditDelegate;
m_pTableRounting ->setItemDelegateForColumn(0, cLineEditDelegate);
m_pTableRounting ->setItemDelegateForColumn(1, cLineEditDelegate);
m_pTableRounting ->setItemDelegateForColumn(2, cLineEditDelegate);
//设置表格显示位置
m_pTableRounting->resize(iWidth - 30, iHeight - 30);
m_pTableRounting->move(15, 15);
}
//节点管理表格初始化
void CServerManager::initNodeManage()
{
int iWidth = ui.groupBoxNodeManage->width();
int iHeight = ui.groupBoxNodeManage->height();
//设置表头
m_pTableNodeManage->setColumnCount(6);
m_pTableNodeManage->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("名称")));
m_pTableNodeManage->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("IP")));
m_pTableNodeManage->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("端口")));
m_pTableNodeManage->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("用户名")));
m_pTableNodeManage->setHorizontalHeaderItem(4, new QTableWidgetItem(tr("密码")));
m_pTableNodeManage->setHorizontalHeaderItem(5, new QTableWidgetItem(tr("描述")));
//自动适应大小
m_pTableNodeManage->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
//设置表格显示位置
m_pTableNodeManage->resize(iWidth - 30, iHeight - 30);
m_pTableNodeManage->move(15, 15);
//设置代理
CLineEditDelegate* cLineEditDelegate = new CLineEditDelegate;
m_pTableNodeManage->setItemDelegateForColumn(1, cLineEditDelegate);
CLineEditDelegateNoEdit* cLineEditDelegateNoEdit = new CLineEditDelegateNoEdit;
m_pTableNodeManage->setItemDelegateForColumn(5, cLineEditDelegateNoEdit);
CLineEditDelegatePWD* cLineEditDelegatePWD = new CLineEditDelegatePWD;
m_pTableNodeManage->setItemDelegateForColumn(4, cLineEditDelegatePWD);
}
//初始化服务器管理表格
void CServerManager::initSeverManage()
{
int iWidth = ui.groupBoxSeverManage->width();
int iHeight = ui.groupBoxSeverManage->height();
//设置表头
m_pTableSeverManage->setColumnCount(2);
m_pTableSeverManage->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("名称")));
m_pTableSeverManage->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("状态")));
//自动适应大小
m_pTableSeverManage->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
//设置表格显示位置
m_pTableSeverManage->resize(iWidth - 30, iHeight - 30);
m_pTableSeverManage->move(15, 15);
//设置代理
CLineEditDelegateNoEdit* cLineEditDelegateNoEditStat = new CLineEditDelegateNoEdit;
m_pTableSeverManage->setItemDelegateForColumn(1, cLineEditDelegateNoEditStat);
}
//初始化配置文件表格
void CServerManager::initConfigManage()
{
int iWidth = ui.groupBoxConfigManage->width();
int iHeight = ui.groupBoxConfigManage->height();
//设置表头
m_pTableConfigManage->setColumnCount(3);
m_pTableConfigManage->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("名称")));
m_pTableConfigManage->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("值")));
m_pTableConfigManage->setHorizontalHeaderItem(2, new QTableWidgetItem(tr(" 描述")));
//自动适应大小
m_pTableConfigManage->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
//设置表格显示位置
m_pTableConfigManage->resize(iWidth - 30, iHeight - 30);
m_pTableConfigManage->move(15, 15);
//设置代理
CLineEditDelegateNoEdit* cLineEditDelegateNoEdit = new CLineEditDelegateNoEdit;
m_pTableConfigManage->setItemDelegateForColumn(2, cLineEditDelegateNoEdit);
}
/************************************************************************/
/* 获取表格的数据 */
/************************************************************************/
//获取网络配置数据
int CServerManager::GetNetWorkConfigData()
{
m_cApsServerManageClient->GetNetWorkInfo(ui.comboBoxIP->currentText().toStdString(), m_cNodeNetWorkInfo);
if (m_cNodeNetWorkInfo.m_cOptRet.m_iOprCode != 0)
{
//QString strResult = QString::fromLocal8Bit(m_cNodeNetWorkInfo.m_cOptRet.m_sOprDesc.c_str());
//QMessageBox::information(this, tr("提示"), strResult);
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("获取网络配置数据失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return -1;
}
return 0;
}
//获取路由表数据
int CServerManager::GetRoutingData()
{
m_cApsServerManageClient->GetRouteTable(ui.comboBoxIP->currentText().toStdString(), m_cGetRouteTableInfo);
if (m_cGetRouteTableInfo.m_cOptRet.m_iOprCode != 0)
{
//QMessageBox::information(this, tr("提示"), QString::fromStdString(m_cGetRouteTableInfo.m_cOptRet.m_sOprDesc));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("获取路由表数据失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return -1;
}
return 0;
}
//获取服务管理数据
int CServerManager::GetSeverManageData()
{
m_cApsServerManageClient->GetServerNameList(ui.comboBoxIP->currentText().toStdString(), m_cGetAllServerList);
if (m_cGetAllServerList.m_cOptRet.m_iOprCode != 0)
{
//QMessageBox::information(this, tr("提示"), QString::fromStdString(m_cGetAllServerList.m_cOptRet.m_sOprDesc));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("获取服务数据失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return -1;
}
else
{
return 0;
}
}
//获取配置文件列表
int CServerManager::GetConfigManageData()
{
m_cApsServerManageClient->GetNodeConfigList(ui.comboBoxIP->currentText().toStdString(), m_cGetMachineConfig);
if (m_cGetMachineConfig.m_cOptRet.m_iOprCode != 0)
{
//QMessageBox::information(this, tr("提示"), QString::fromStdString(m_cGetMachineConfig.m_cOptRet.m_sOprDesc));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("获取配置文件列表失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return -1;
}
return 0;
}
/************************************************************************/
/* 显示每个表格数据 */
/************************************************************************/
//显示网络配置表格
void CServerManager::OnShowTableNetConfig()
{
//显示内容
int iRow = 0;
std::vector<CEthInfo> vecCEthInfo = m_cNodeNetWorkInfo.m_vEthInfo;
std::vector<CEthInfo>::const_iterator iteVecCEthInfo = vecCEthInfo.begin();
int icolumn = vecCEthInfo.size();
m_pTableNetConfig->setRowCount(icolumn + 1);
for(; iteVecCEthInfo != vecCEthInfo.end(); iteVecCEthInfo++)
{
m_pTableNetConfig->setItem(iRow, 0, new QTableWidgetItem(QString::fromStdString(iteVecCEthInfo->m_sEthName)));
m_pTableNetConfig->setItem(iRow, 1, new QTableWidgetItem(QString::fromStdString(iteVecCEthInfo->m_sIPAddr)));
m_pTableNetConfig->setItem(iRow, 2, new QTableWidgetItem(QString::fromStdString(iteVecCEthInfo->m_sNetMask)));
m_pTableNetConfig->setItem(iRow, 3, new QTableWidgetItem(QString::fromStdString(iteVecCEthInfo->m_sGateWay)));
m_pTableNetConfig->setItem(iRow, 4, new QTableWidgetItem(QString::fromStdString(iteVecCEthInfo->m_sBootProto)));
if (iteVecCEthInfo->m_bStarted)
{
m_pTableNetConfig->setItem(iRow, 5, new QTableWidgetItem(tr("是")));
}
else
{
m_pTableNetConfig->setItem(iRow, 5, new QTableWidgetItem(tr("否")));
}
iRow++;
m_lstComboBoxItems.append(QString::fromStdString(iteVecCEthInfo->m_sEthName));
}
//记录当前总行数
m_iNetConfigRowSum = m_pTableNetConfig->rowCount();
}
//显示路由表格
void CServerManager::OnShowTableRouting()
{
//显示数据
int iRow = 0;
std::vector<CRouteInfo> vRouteInfo = m_cGetRouteTableInfo.m_cRouteTableInfo.m_vRouteInfo;
std::vector<CRouteInfo>::const_iterator iteVRouteInfo = vRouteInfo.begin();
int iRowCount = vRouteInfo.size();
m_pTableRounting->setRowCount(iRowCount + 1);
for(; iteVRouteInfo != vRouteInfo.end(); iteVRouteInfo++)
{
QRegExp rxIP(cstIpRegExp);
QValidator *pValidatorIP = new QRegExpValidator(rxIP, this);
if (iteVRouteInfo->m_sDestination == "default")
{
m_pTableRounting->setItem(iRow, 0, new QTableWidgetItem("0.0.0.0"));
}
else
{
m_pTableRounting->setItem(iRow, 0, new QTableWidgetItem(QString::fromStdString(iteVRouteInfo->m_sDestination)));
}
if (iteVRouteInfo->m_sGateway == "default")
{
m_pTableRounting->setItem(iRow, 1, new QTableWidgetItem("0.0.0.0"));
}
else
{
m_pTableRounting->setItem(iRow, 1, new QTableWidgetItem(QString::fromStdString(iteVRouteInfo->m_sGateway)));
}
m_pTableRounting->setItem(iRow, 2, new QTableWidgetItem(QString::fromStdString(iteVRouteInfo->m_sGenMask)));
m_pTableRounting->setItem(iRow, 3, new QTableWidgetItem(QString::fromStdString(iteVRouteInfo->m_sEthName)));
iRow++;
}
//网卡名称设置代理
CComboBoxDelegate* cComboBoxDelegate = new CComboBoxDelegate(m_lstComboBoxItems);
m_pTableRounting->setItemDelegateForColumn(3, cComboBoxDelegate);
//记录当前总行数
m_iRoutingRowSum = m_pTableRounting->rowCount();
}
//显示节点管理表格
void CServerManager::OnShowTableNodeManage()
{
//显示数据
int iRow = 0;
std::vector<CNodeInfo> vNodeInfo = m_cGetCluStat.m_cNodeInfoVector;
std::vector<CNodeInfo>::const_iterator iteVNodeInfo = vNodeInfo.begin();
m_pTableNodeManage->setRowCount(vNodeInfo.size() + 1);
for(; iteVNodeInfo != vNodeInfo.end(); iteVNodeInfo++)
{
m_pTableNodeManage->setItem(iRow, 0, new QTableWidgetItem(QString::fromStdString("")));
m_pTableNodeManage->setItem(iRow, 1, new QTableWidgetItem(QString::fromStdString(iteVNodeInfo->m_sIPAddr)));
m_pTableNodeManage->setItem(iRow, 2, new QTableWidgetItem(QString::number(iteVNodeInfo->m_iSrvProxyPort)));
m_pTableNodeManage->setItem(iRow, 3, new QTableWidgetItem(QString::fromStdString("Root")));
m_pTableNodeManage->setItem(iRow, 4, new QTableWidgetItem(QString::fromStdString("******")));
m_pTableNodeManage->setItem(iRow, 5, new QTableWidgetItem(QString::fromStdString("")));
iRow++;
}
}
//显示DNS配置数据
void CServerManager::OnShowTableDNS()
{
m_cApsServerManageClient->GetDNS(ui.comboBoxIP->currentText().toStdString(), m_cDnsInfo);
std::vector<std::string> vDnsAddr = m_cDnsInfo.m_vDnsAddr;
int iSizeVDns = vDnsAddr.size();
if (iSizeVDns == 0)
{
return;
}
else if (iSizeVDns == 1)
{
ui.mainDNSlineEdit->setText(QString::fromStdString(vDnsAddr.at(0)));
}
else if (iSizeVDns == 2)
{
ui.mainDNSlineEdit->setText(QString::fromStdString(vDnsAddr.at(0)));
ui.spareDNSlineEdit->setText(QString::fromStdString(vDnsAddr.at(1)));
}
}
//显示服务管理表格
void CServerManager::OnShowTableSeverManage()
{
//显示数据
int iRow = 0;
std::vector<CServerInfo> vSeverInfo = m_cGetAllServerList.m_vServerList;
std::vector<CServerInfo>::const_iterator iteVSeverInfo = vSeverInfo.begin();
m_pTableSeverManage->setRowCount(vSeverInfo.size() + 1);
for(; iteVSeverInfo != vSeverInfo.end(); iteVSeverInfo++)
{
m_pTableSeverManage->setItem(iRow, 0, new QTableWidgetItem(QString::fromStdString(iteVSeverInfo->m_sServerName)));
int iCurStat = iteVSeverInfo->m_iCurStat;
switch(iCurStat)
{
case SERVER_STATE_START_FAILED:
{
m_pTableSeverManage->setItem(iRow, 1, new QTableWidgetItem(tr("启动失败")));
break;
}
case SERVER_STATE_INIT:
{
m_pTableSeverManage->setItem(iRow, 1, new QTableWidgetItem(tr("初始状态")));
break;
}
case SERVER_STATE_START:
{
m_pTableSeverManage->setItem(iRow, 1, new QTableWidgetItem(tr("启动")));
break;
}
case SERVER_STATE_ERR:
{
m_pTableSeverManage->setItem(iRow, 1, new QTableWidgetItem(tr("异常")));
break;
}
case SERVER_NOT_CONFIG:
{
m_pTableSeverManage->setItem(iRow, 1, new QTableWidgetItem(tr("未配置")));
break;
}
default:
break;
}
iRow++;
}
m_iSeverManageSum = m_pTableSeverManage->rowCount();
}
//显示配置文件表格
void CServerManager::OnShowConfigManage(int index)
{
//获取数据
m_cApsServerManageClient->LoadConfig(ui.comboBoxIP->currentText().toStdString(), ui.comboBoxConfig->currentText().toStdString(), m_cConfigOption);
if (m_cConfigOption.m_cOptRet.m_iOprCode != 0)
{
//QMessageBox::information(this, tr("提示"), QString::fromStdString(m_cGetMachineConfig.m_cOptRet.m_sOprDesc));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("获取配置文件内容失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
//显示数据
int iRow = 0;
std::vector<CConfigOption> vConfigOption = m_cConfigOption.m_vConfigOption;
std::vector<CConfigOption>::const_iterator iteVconfigOption = vConfigOption.begin();
m_pTableConfigManage->setRowCount(vConfigOption.size());
for (; iteVconfigOption != vConfigOption.end(); iteVconfigOption++)
{
m_pTableConfigManage->setItem(iRow , 0, new QTableWidgetItem(QString::fromStdString(iteVconfigOption->m_sKeyName)));
m_pTableConfigManage->setItem(iRow , 1, new QTableWidgetItem(QString::fromStdString(iteVconfigOption->m_sKeyValue)));
m_pTableConfigManage->setItem(iRow , 2, new QTableWidgetItem(tr(iteVconfigOption->m_sKeyDes.c_str())));
iRow++;
}
m_iConfigManageSum = m_pTableConfigManage->rowCount();
}
//将配置文件列表传到ComboBox
void CServerManager::SetConfigManageComboBoxList()
{
if (GetConfigManageData() == -1)
{
return;
}
std::vector<std::string> vConfig = m_cGetMachineConfig.m_vConfig;
std::vector<std::string>::const_iterator iteVConfigManage = vConfig.begin();
ui.comboBoxConfig->clear();
for(; iteVConfigManage != vConfig.end(); iteVConfigManage++)
{
ui.comboBoxConfig->addItem(QString::fromStdString(*iteVConfigManage));
}
ui.comboBoxConfig->setCurrentIndex(0);
}
//更换IP节点后刷新表格数据
void CServerManager::OnUpdataComboxChange(int index)
{
if (0 == GetNetWorkConfigData())
{
OnShowTableNetConfig();
}
if(0 == GetRoutingData())
{
OnShowTableRouting();
}
OnShowTableNodeManage(); //获取数据后台未提供返回值,无法判断
if (0 == GetSeverManageData())
{
OnShowTableSeverManage(); //后台反馈较慢
}
SetConfigManageComboBoxList();
OnShowTableDNS();
}
/************************************************************************/
/* 表格右键功能实现 */
/************************************************************************/
//路由配置表右键菜单功能
void CServerManager::OnRoutingcustomContextMenuRequested(const QPoint& point)
{
//限定鼠标右击位置
int iCurrentRow = m_pTableRounting->verticalHeader()->logicalIndexAt(point);
if (iCurrentRow == -1)
{
return;
}
m_pTableRounting->selectRow(iCurrentRow);
QMenu* menuRouting = new QMenu(this);
menuRouting->addAction(m_pActionAddRout);
menuRouting->addAction(m_pActionDelRout);
menuRouting->addAction(m_pActionModefyRout);
menuRouting->exec(QCursor::pos());
}
//网络配置表右键菜单功能
void CServerManager::OnNetworkcustomContextMenuRequested(const QPoint& point)
{
//限定鼠标右击位置
int iCurrentRow = m_pTableNetConfig->verticalHeader()->logicalIndexAt(point);
if (iCurrentRow == -1)
{
return;
}
m_pTableNetConfig->selectRow(iCurrentRow);
QMenu* menuNetConfig = new QMenu(this);
menuNetConfig->addAction(m_pActionAddNetConfig);
//menuNetConfig->addAction(m_pActionDelNetConfig);
menuNetConfig->addAction(m_pActionRestartNetConfig);
menuNetConfig->addAction(m_pActionStartNetConfig);
menuNetConfig->addAction(m_pActionStopNetConfig);
menuNetConfig->addAction(m_pActionModefyNetConfig);
menuNetConfig->exec(QCursor::pos());
}
//节点服务右键菜单功能
void CServerManager::OnNodeManagecustomContextMenuRequested(const QPoint& point)
{
//限定鼠标右击位置
int iCurrentRow = m_pTableNodeManage->verticalHeader()->logicalIndexAt(point);
if (iCurrentRow == -1)
{
return ;
}
m_pTableNodeManage->selectRow(iCurrentRow);
QMenu* menuNodeMange = new QMenu(this);
menuNodeMange->addAction(m_pActionNodeManageModefy);
menuNodeMange->addAction(m_pActionNodeManageDel);
menuNodeMange->addAction(m_pActionNodeManageRestart);
menuNodeMange->addAction(m_pActionNodeManageChangePwd);
menuNodeMange->addAction(m_pActionNodeManageAdd);
menuNodeMange->exec(QCursor::pos());
}
//服务管理右键功能添加
void CServerManager::OnSeverManagecustomContextMenuRequested(const QPoint& point)
{
//限定鼠标右击位置
int iCurrentRow = m_pTableSeverManage->verticalHeader()->logicalIndexAt(point);
if (iCurrentRow == -1)
{
return ;
}
m_pTableSeverManage->selectRow(iCurrentRow);
QMenu* menuSeverMange = new QMenu(this);
menuSeverMange->addAction(m_pActionSeverManageAdd);
menuSeverMange->addAction(m_pActionSeverManageStart);
menuSeverMange->addAction(m_pActionSeverManageStop);
menuSeverMange->addAction(m_pActionSeverManageRestart);
menuSeverMange->addAction(m_pActionSeverManageInstall);
menuSeverMange->addAction(m_pActionSeverManagePromotion);
menuSeverMange->addAction(m_pActionSeverManageUnload);
menuSeverMange->exec(QCursor::pos());
}
//配置管理右键功能添加
void CServerManager::OnConfigManagecustomContextMenuRequested(const QPoint& point)
{
QMenu* menuConfigMange = new QMenu(ui.groupBoxConfigManage);
menuConfigMange->addAction(m_pActionUploadConfig);
menuConfigMange->addAction(m_pActionAddConfig);
menuConfigMange->exec(QCursor::pos());
}
//添加路由配置表行
void CServerManager::OnAddRouting()
{
//添加新行
QModelIndex modelIndex = m_pTableRounting->currentIndex();
int iRow = modelIndex.row() + 1;
m_pTableRounting->insertRow(iRow);
m_pTableRounting->setItem(iRow, 0, new QTableWidgetItem("0.0.0.0"));
m_pTableRounting->setItem(iRow, 1, new QTableWidgetItem("0.0.0.0"));
m_pTableRounting->setItem(iRow, 2, new QTableWidgetItem("0.0.0.0"));
m_pTableRounting->setItem(iRow, 3, new QTableWidgetItem(""));
//记录当前总行数
m_iRoutingRowSum = m_pTableRounting->rowCount();
}
//添加网络配置
void CServerManager::OnAddNetConfig()
{
//添加新行
QModelIndex modelIndex = m_pTableNetConfig->currentIndex();
int iRow = modelIndex.row() + 1;
m_pTableNetConfig->insertRow(iRow);
m_pTableNetConfig->setItem(iRow, 0, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(iRow, 1, new QTableWidgetItem("0.0.0.0"));
m_pTableNetConfig->setItem(iRow, 2, new QTableWidgetItem("0.0.0.0"));
m_pTableNetConfig->setItem(iRow, 3, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(iRow, 4, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(iRow, 5, new QTableWidgetItem(""));
//记录当前总行数
m_iNetConfigRowSum = m_pTableRounting->rowCount();
}
//删除网络配置
void CServerManager::OnDelNetConfig()
{
//std::string sEthName;
CMSOprResult cOptRet;
QModelIndex modelIndex = m_pTableNetConfig->currentIndex();
int iRow = modelIndex.row();
QList<QTableWidgetItem *> lstItem = m_pTableNetConfig->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemEthName = m_pTableNetConfig->item(iRow, 0);
if (twItemEthName == NULL)
{
//QMessageBox::information(this, tr("提示"), tr("网络配置删除失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("网络配置删除失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
QString strEthName = twItemEthName->text();
//sEthName = strEthName.toStdString();
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("提示"));
msgBox.setText(QString(tr("正在删除第%1行,请确认")).arg(QString::number(iRow + 1)));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setButtonText(QMessageBox::Ok, tr("确定"));
msgBox.setButtonText(QMessageBox::Cancel, tr("取消"));
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Ok:
{
m_cApsServerManageClient->DeleteNetwork(ui.comboBoxIP->currentText().toStdString(), strEthName.toStdString(), cOptRet);
if (cOptRet.m_iOprCode == 0)
{
m_pTableNetConfig->removeRow(iRow);
//记录当前总行数
m_iNetConfigRowSum = m_pTableNetConfig->rowCount();
//QMessageBox::information(this, tr("提示"), tr("网络配置删除成功"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("网络配置删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("网络配置删除失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("网络配置删除失败"));
}
break;
}
case QMessageBox::Cancel:
{
break;
}
default:
break;
}
}
//删除行
else
{
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("提示"));
msgBox.setText(QString(tr("正在删除第%1行,请确认")).arg(QString::number(iRow + 1)));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setButtonText(QMessageBox::Ok, tr("确定"));
msgBox.setButtonText(QMessageBox::Cancel, tr("取消"));
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Ok:
{
m_pTableNetConfig->removeRow(iRow);
//记录当前总行数
m_iNetConfigRowSum = m_pTableNetConfig->rowCount();
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("当前行删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
// QMessageBox::information(this, tr("提示"), tr("当前行删除成功"));
break;
}
case QMessageBox::Cancel:
{
break;
}
default:
break;
}
}
//删除所有行时自动添加一行空行
if (m_iNetConfigRowSum == 0)
{
m_pTableNetConfig->setRowCount(1);
m_pTableNetConfig->setItem(0, 0, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(0, 1, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(0, 2, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(0, 3, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(0, 4, new QTableWidgetItem(""));
m_pTableNetConfig->setItem(0, 5, new QTableWidgetItem(""));
}
}
//重启网络
void CServerManager::OnRestartNetConfig()
{
CMSOprResult cOptRet;
QModelIndex mIndex = m_pTableNetConfig->currentIndex();
int iRow = mIndex.row();
QList<QTableWidgetItem *> lstItem = m_pTableNetConfig->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemName = m_pTableNetConfig->item(iRow, 0);
QTableWidgetItem* twItemIP = m_pTableNetConfig->item(iRow, 1);
if (twItemIP == NULL || twItemName == NULL)
{
//QMessageBox::information(this, tr("提示"), tr("重启失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("重启网络失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
QString strName = twItemName->text();
QString strIp = twItemIP->text();
if(-1 == OnCheckIP(strIp.toStdString()))
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
m_cApsServerManageClient->ReStartNetwork(strIp.toStdString(), strName.toStdString(), cOptRet);
if(cOptRet.m_iOprCode == 0)
{
//QMessageBox::information(this, tr("提示"), tr("重启成功"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("重启网络成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
else
{
//QMessageBox::information(this, tr("提示"), tr("重启失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("重启网络失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
}
else
{
//QMessageBox::information(this, tr("提示"), tr("无此节点,重启失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("重启网络失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
}
//启动网络
void CServerManager::OnStartNetConfig()
{
QModelIndex mIndex = m_pTableNetConfig->currentIndex();
int iRow = mIndex.row();
CMSOprResult cOptRet;
QList<QTableWidgetItem *> lstItem = m_pTableNetConfig->selectedItems();
if(!lstItem.isEmpty())
{
QTableWidgetItem* twItemName = m_pTableNetConfig->item(iRow, 0);
QTableWidgetItem* twItemIP = m_pTableNetConfig->item(iRow, 1);
if (twItemIP == NULL || twItemName == NULL)
{
//QMessageBox::information(this, tr("提示"), tr("启动失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("启动网络失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
QString strName = twItemName->text();
QString strIp = twItemIP->text();
if(-1 == OnCheckIP(strIp.toStdString()))
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
m_cApsServerManageClient->StartNetwork(strIp.toStdString(), strName.toStdString(), cOptRet);
if(cOptRet.m_iOprCode == 0)
{
//QMessageBox::information(this, tr("提示"), tr("启动成功"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("启动网络成功"), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("启动网络失败"), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("启动失败"));
}
}
else
{
//QMessageBox::information(this, tr("提示"), tr("无此节点,启动失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("启动网络失败"), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
}
//停止网络
void CServerManager::OnStopNetConfig()
{
QModelIndex mIndex = m_pTableNetConfig->currentIndex();
int iRow = mIndex.row();
CMSOprResult cOptRet;
QList<QTableWidgetItem *> lstItem = m_pTableNetConfig->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemName = m_pTableNetConfig->item(iRow, 0);
QTableWidgetItem* twItemIP = m_pTableNetConfig->item(iRow, 1);
if (twItemIP == NULL || twItemName == NULL)
{
//QMessageBox::information(this, tr("提示"), tr("停止失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("启动网络失败"), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
QString strName = twItemName->text();
QString strIp = twItemIP->text();
if(-1 == OnCheckIP(strIp.toStdString()))
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
m_cApsServerManageClient->StopNetwork(strIp.toStdString(), strName.toStdString(), cOptRet);
if(cOptRet.m_iOprCode == 0)
{
//QMessageBox::information(this, tr("提示"), tr("停止成功"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("停止网络成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("停止网络失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("停止失败"));
}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("停止网络失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("无此节点,停止失败"));
}
}
//网络配置更新
void CServerManager::OnModefyNetConfig()
{
QModelIndex mIndex = m_pTableNetConfig->currentIndex();
int iRow = mIndex.row();
CEthInfo cEthInfo;
CMSOprResult cOptRet;
QList<QTableWidgetItem*> lstItem = m_pTableNetConfig->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemName = m_pTableNetConfig->item(iRow, 0);
QTableWidgetItem* twItemIP = m_pTableNetConfig->item(iRow, 1);
QTableWidgetItem* twItemNetMask = m_pTableNetConfig->item(iRow, 2);
QTableWidgetItem* twItemGateWay = m_pTableNetConfig->item(iRow, 3);
QTableWidgetItem* twItemBootProto = m_pTableNetConfig->item(iRow, 4);
QTableWidgetItem* twItemIsBoot = m_pTableNetConfig->item(iRow, 5);
if (twItemName == NULL || twItemIP == NULL || twItemNetMask ==NULL ||twItemGateWay == NULL || twItemBootProto == NULL || twItemIsBoot == NULL)
{
//QMessageBox::information(this, tr("提示"), tr("无此节点,停止失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("网络配置更新失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
QString strName = twItemName->text();
QString strIp = twItemIP->text();
if(-1 == OnCheckIP(strIp.toStdString()))
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
QString strNetMask = twItemNetMask->text();
QString strGateWay = twItemGateWay->text();
QString strBootProto = twItemBootProto->text();
QString strIsBoot = twItemIsBoot->text();
cEthInfo.m_sEthName = strName.toStdString();
cEthInfo.m_sIPAddr = strIp.toStdString();
cEthInfo.m_sNetMask = strNetMask.toStdString();
cEthInfo.m_sGateWay = strGateWay.toStdString();
cEthInfo.m_sBootProto = strBootProto.toStdString();
if (strIsBoot == tr("是"))
{
cEthInfo.m_bStarted = true;
}
else
{
cEthInfo.m_bStarted = false;
}
m_cApsServerManageClient->ConfigNetWork(ui.comboBoxIP->currentText().toStdString(), cEthInfo, cOptRet);
if (cOptRet.m_iOprCode != 0)
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("网络配置更新成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"),tr("网络配置更新成功"));
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("网络配置更新失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"),tr("网络配置更新失败"));
}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("网络配置更新失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"),tr("缺少数据,网络配置更新失败"));
}
}
//节点添加
void CServerManager::OnNodeManageAdd()
{
//添加新行
QModelIndex modelIndex = m_pTableNodeManage->currentIndex();
int iRow = modelIndex.row() + 1;
m_pTableNodeManage->insertRow(iRow);
m_pTableNodeManage->setItem(iRow, 0, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(iRow, 1, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(iRow, 2, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(iRow, 3, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(iRow, 4, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(iRow, 5, new QTableWidgetItem(""));
//记录当前总行数
m_iNodeManageSum = m_pTableNodeManage->rowCount();
}
//删除节点服务
void CServerManager::OnNodeManageDel()
{
CMSOprResult cOptRet;
QModelIndex modelIndex = m_pTableNodeManage->currentIndex();
int iRow = modelIndex.row();
QList<QTableWidgetItem *> lstItem = m_pTableNodeManage->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemIP = m_pTableNodeManage->item(iRow, 1);
if (twItemIP == NULL)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点删除失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("节点删除失败"));
return;
}
QString strIp = twItemIP->text();
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("提示"));
msgBox.setText(QString(tr("正在删除第%1行,请确认")).arg(QString::number(iRow + 1)));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Ok:
{
if(-1 == OnCheckIP(strIp.toStdString()))
{
m_pTableNodeManage->removeRow(iRow);
//记录当前总行数
m_iNodeManageSum = m_pTableNodeManage->rowCount();
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("当前行删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("节点删除成功"));
return;
}
m_cApsServerManageClient->DelClusterNode(strIp.toStdString(), cOptRet);
if (cOptRet.m_iOprCode == 0)
{
m_pTableNodeManage->removeRow(iRow);
//记录当前总行数
m_iNodeManageSum = m_pTableNodeManage->rowCount();
//QMessageBox::information(this, tr("提示"), tr("节点删除成功"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("节点删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点删除失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("节点删除失败"));
}
break;
}
case QMessageBox::Cancel:
{
break;
}
default:
break;
}
}
//删除行
else
{
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("提示"));
msgBox.setText(QString(tr("正在删除第%1行,请确认")).arg(QString::number(iRow + 1)));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Ok:
{
m_pTableNodeManage->removeRow(iRow);
//记录当前总行数
m_iNodeManageSum = m_pTableNodeManage->rowCount();
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("当前行删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("当前行删除成功"));
break;
}
case QMessageBox::Cancel:
{
break;
}
default:
break;
}
}
//删除所有行时自动添加一行空行
if (m_iNodeManageSum == 0)
{
m_pTableNodeManage->setRowCount(1);
m_pTableNodeManage->setItem(0, 0, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(0, 1, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(0, 2, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(0, 3, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(0, 4, new QTableWidgetItem(""));
m_pTableNodeManage->setItem(0, 5, new QTableWidgetItem(""));
}
}
//节点重启
void CServerManager::OnNodeManageRestart()
{
QModelIndex modelIndex = m_pTableNodeManage->currentIndex();
int iRow = modelIndex.row();
CMSOprResult cOptRet;
QList<QTableWidgetItem *> lstItem = m_pTableNodeManage->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemIP = m_pTableNodeManage->item(iRow, 1);
if (twItemIP == NULL)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点重启失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("重启失败"));
return;
}
QString strIp = twItemIP->text();
if(-1 == OnCheckIP(strIp.toStdString()))
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
m_cApsServerManageClient->RebootMachine(strIp.toStdString(), cOptRet);
if(cOptRet.m_iOprCode == 0)
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("节点重启成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("重启成功"));
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点重启失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("重启失败"));
}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点重启失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("无此节点,重启失败"));
}
}
//修改节点密码
void CServerManager::OnNodeManageChangePwd()
{
}
//更新新的节点服务
void CServerManager::OnNodeManageModefy()
{
CMSOprResult cOptRet;
QModelIndex mIndex = m_pTableNodeManage->currentIndex();
int iRow = mIndex.row();
QList<QTableWidgetItem *> lstItem = m_pTableNodeManage->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem *twItemName = m_pTableNodeManage->item( iRow, 0);
QTableWidgetItem *twItemIP = m_pTableNodeManage->item( iRow, 1);
QTableWidgetItem *twItemPort = m_pTableNodeManage->item( iRow, 2);
QTableWidgetItem *twItemPwd = m_pTableNodeManage->item( iRow, 4);
QTableWidgetItem *twItemUserName = m_pTableNodeManage->item(iRow, 3);
if (twItemName == NULL || twItemIP == NULL || twItemPort == NULL || twItemPwd == NULL || twItemUserName == NULL)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点更新失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("添加失败,请输入数据"));
return;
}
QString strPwd = twItemPwd->data(Qt::UserRole).toString();
QString strName = twItemName->text();
QString strIp = twItemIP->text();
if(-1 == OnCheckIP(strIp.toStdString()))
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
// QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
return;
}
QString strPort = twItemPort->text();
QString strUserName = twItemUserName->text();
if (!(strUserName == "Root" || strUserName == "root"))
{
QMessageBox::information(this, tr("提示"), tr("用户名有误"));
return;
}
//符合要求时调用后台
//if (!strName.isEmpty() && !strIp.isEmpty() && !strPort.isEmpty() && !strUserName.isEmpty() && !strPwd.isEmpty())
//{
m_cApsServerManageClient->ConfigNodeRootPwd(strIp.toStdString(), strPwd.toStdString(), cOptRet);
if (cOptRet.m_iOprCode != 0)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("密码验证失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("密码验证失败"));
}
else
{
CMSOprResult cOptRetAddNode;
m_cApsServerManageClient->AddClusterNode(strName.toStdString(), strIp.toStdString(), strPort.toUInt(), cOptRetAddNode);
if (cOptRetAddNode.m_iOprCode != 0)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点操作失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("节点操作失败"));
}
else
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("节点操作成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("节点操作成功"));
}
}
//}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("节点操作失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
// QMessageBox::information(this, tr("提示"), tr("没有数据,操作失败"));
}
}
//更新路由表配置
void CServerManager::OnUpdataRoutingModefy()
{
CRouteInfo cRoutInfo;
CMSOprResult cOptRet;
QList<QTableWidgetItem *> lstItem = m_pTableRounting->selectedItems();
if (lstItem.size() == 4)
{
QString strDestination = lstItem.at(0)->text();
if (strDestination == "0.0.0.0")
{
cRoutInfo.m_sDestination = "default";
}
else
{
cRoutInfo.m_sDestination = strDestination.toStdString();
}
QString strGateway = lstItem.at(1)->text();
if (strDestination == "0.0.0.0")
{
cRoutInfo.m_sGateway = "default";
}
else
{
cRoutInfo.m_sGateway = strGateway.toStdString();
}
QString strGenMask = lstItem.at(2)->text();
cRoutInfo.m_sGenMask = strGenMask.toStdString();
QString strEthName = lstItem.at(3)->text();
cRoutInfo.m_sEthName = strEthName.toStdString();
//符合要求时调用后台
//if (!strDestination.isEmpty() && !strEthName.isEmpty() && !strGateway.isEmpty() && !strGenMask.isEmpty())
//{
m_cApsServerManageClient->AddRouteInfo(ui.comboBoxIP->currentText().toStdString(), cRoutInfo, cOptRet);
if (cOptRet.m_iOprCode == 0)
{
//QMessageBox::information(this, tr("提示"), tr("路由配置更新成功"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("路由配置更新成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("路由配置更新失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("路由配置更新失败"));
}
//}
/*else
{
QMessageBox::information(this, tr("提示"), tr("缺少数据,路由配置更新失败"));
}*/
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("路由配置更新失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("缺少数据,路由配置更新失败"));
}
}
//调用后台服务删除路由节点
void CServerManager::OnDelRouting()
{
CRouteInfo cRoutInfo;
CMSOprResult cOptRet;
bool bHasUsedSeverFunction = false;
QModelIndex modelIndex = m_pTableRounting->currentIndex();
int iRow = modelIndex.row();
QList<QTableWidgetItem *> lstItem = m_pTableRounting->selectedItems();
if (!lstItem.isEmpty())
{
if (lstItem.size() == 4)
{
QString strDestination = lstItem.at(0)->text();
if (strDestination == "0.0.0.0")
{
cRoutInfo.m_sDestination = "default";
}
else
{
cRoutInfo.m_sDestination = strDestination.toStdString();
}
QString strGateway = lstItem.at(1)->text();
if (strDestination == "0.0.0.0")
{
cRoutInfo.m_sGateway = "default";
}
else
{
cRoutInfo.m_sGateway = strGateway.toStdString();
}
QString strGenMask = lstItem.at(2)->text();
cRoutInfo.m_sGenMask = strGenMask.toStdString();
QString strEthName = lstItem.at(3)->text();
cRoutInfo.m_sEthName = strEthName.toStdString();
//符合要求时调用后台
//if (!strDestination.isEmpty() && !strEthName.isEmpty() && !strGateway.isEmpty() && !strGenMask.isEmpty())
//{
bHasUsedSeverFunction = true;
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("提示"));
msgBox.setText(QString(tr("正在删除第%1行,请确认")).arg(QString::number(iRow + 1)));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Ok:
{
m_cApsServerManageClient->DelRouteInfo(ui.comboBoxIP->currentText().toStdString(), cRoutInfo, cOptRet);
if (cOptRet.m_iOprCode == 0)
{
m_pTableRounting->removeRow(iRow);
//记录当前总行数
m_iRoutingRowSum = m_pTableRounting->rowCount();
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("路由配置删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("路由配置删除成功"));
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("路由配置删除失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("路由配置删除失败"));
}
break;
}
case QMessageBox::Cancel:
{
break;
}
default:
break;
}
//}
}
}
//删除行
if(!bHasUsedSeverFunction)
{
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("提示"));
msgBox.setText(QString(tr("正在删除第%1行,请确认")).arg(QString::number(iRow + 1)));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Ok:
{
m_pTableRounting->removeRow(iRow);
//记录当前总行数
m_iRoutingRowSum = m_pTableRounting->rowCount();
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("当前行删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("当前行删除成功"));
break;
}
case QMessageBox::Cancel:
{
break;
}
default:
break;
}
}
//删除所有行时自动添加一行空行
if (m_iRoutingRowSum == 0)
{
m_pTableRounting->setRowCount(1);
m_pTableRounting->setItem(0, 0, new QTableWidgetItem("0.0.0.0"));
m_pTableRounting->setItem(0, 1, new QTableWidgetItem("0.0.0.0"));
m_pTableRounting->setItem(0, 2, new QTableWidgetItem("0.0.0.0"));
m_pTableRounting->setItem(0, 3, new QTableWidgetItem(""));
}
}
//服务管理添加行
void CServerManager::OnSeverManageAdd()
{
QModelIndex indexRow = m_pTableSeverManage->currentIndex();
int iRow = indexRow.row() + 1;
m_pTableSeverManage->insertRow(iRow);
m_pTableSeverManage->setItem(iRow,0, new QTableWidgetItem(""));
m_pTableSeverManage->setItem(iRow,1, new QTableWidgetItem(""));
m_iSeverManageSum = m_pTableSeverManage->rowCount();
}
//服务管理启动
void CServerManager::OnSeverManageStart()
{
QModelIndex mIndex = m_pTableSeverManage->currentIndex();
int iRow = mIndex.row();
CMSOprResult cOptRet;
QList<QTableWidgetItem *> lstItem = m_pTableSeverManage->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemName = m_pTableSeverManage->item(iRow, 0);
if (twItemName == NULL)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务启动失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("服务启动失败"));
return;
}
QString strSeverManageName = twItemName->text();
if(!strSeverManageName.isEmpty())
{
m_cApsServerManageClient->StartServer(ui.comboBoxIP->currentText().toStdString(), strSeverManageName.toStdString(), cOptRet);
if (cOptRet.m_iOprCode == 0)
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("服务启动成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
GetSeverManageData();
OnShowTableSeverManage();
//QMessageBox::information(this, tr("提示"), tr("服务启动成功"));
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务启动失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("服务启动失败"));
}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务启动失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("无此节点,服务启动失败"));
}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务启动失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("无此节点,服务启动失败"));
}
}
//服务管理停止
void CServerManager::OnSeverManageStop()
{
QModelIndex mIndex = m_pTableSeverManage->currentIndex();
int iRow = mIndex.row();
CMSOprResult cOptRet;
QList<QTableWidgetItem* > lstItem = m_pTableSeverManage->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemName = m_pTableSeverManage->item(iRow, 0);
if (twItemName == NULL)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务停止失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("服务停止失败"));
return;
}
QString strSeverManageName = twItemName ->text();
m_cApsServerManageClient->StopServer(ui.comboBoxIP->currentText().toStdString(), strSeverManageName.toStdString(), cOptRet);
if (cOptRet.m_iOprCode == 0)
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("服务停止成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
GetSeverManageData();
OnShowTableSeverManage();
//QMessageBox::information(this, tr("提示"), tr("服务停止成功"));
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务停止失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("服务停止失败"));
}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务停止失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("无此节点,服务停止失败"));
}
}
//服务管理重启
void CServerManager::OnSeverManageRestart()
{
QModelIndex mIndex = m_pTableSeverManage->currentIndex();
int iRow = mIndex.row();
CMSOprResult cOptRet;
QList<QTableWidgetItem* > lstItem = m_pTableSeverManage->selectedItems();
if (!lstItem.isEmpty())
{
QTableWidgetItem* twItemName = m_pTableSeverManage->item(iRow, 0);
if (twItemName == NULL)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务重启失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("服务重启失败"));
return;
}
QString strSeverManageName = twItemName ->text();
m_cApsServerManageClient->ReStartNetwork(ui.comboBoxIP->currentText().toStdString(), strSeverManageName.toStdString(), cOptRet);
if (cOptRet.m_iOprCode == 0)
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("服务重启成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
GetSeverManageData();
OnShowTableSeverManage();
//QMessageBox::information(this, tr("提示"), tr("服务重启成功"));
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务重启失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("服务重启失败"));
}
}
else
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("服务重启失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("无此节点,服务重启失败"));
}
}
//服务管理安装
void CServerManager::OnSeverManageInstall()
{
}
//服务管理卸载
void CServerManager::OnSeverManageUnload()
{
}
//服务管理升级
void CServerManager::OnSeverManagePromotion()
{
}
//添加配置文件表格行
void CServerManager::OnConfigManageAdd()
{
m_pTableConfigManage->insertRow(m_iConfigManageSum);
m_pTableConfigManage->setItem(m_iConfigManageSum, 0, new QTableWidgetItem(""));
m_pTableConfigManage->setItem(m_iConfigManageSum, 1, new QTableWidgetItem(""));
m_pTableConfigManage->setItem(m_iConfigManageSum, 2, new QTableWidgetItem(""));
m_iConfigManageSum = m_iConfigManageSum + 1;
}
//上传配置文件
void CServerManager::OnConfigManageUpload()
{
if (m_iConfigManageSum == 0)
{
//QMessageBox::information(this, tr("提示"), tr("没有数据,操作失败"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置上传失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
for (int i = 0; i < m_iConfigManageSum; i++)
{
QString strKeyName = m_pTableConfigManage->item(i, 0)->text();
QString strKeyValue = m_pTableConfigManage->item(i, 1)->text();
QString strKeyDes = m_pTableConfigManage->item(i, 2)->text();
if (strKeyName.isEmpty())
{
break;
}
else
{
m_cConfigOption.m_vConfigOption.at(i).m_sKeyName.clear();
m_cConfigOption.m_vConfigOption.at(i).m_sKeyName = strKeyName.toStdString();
m_cConfigOption.m_vConfigOption.at(i).m_sKeyValue.clear();
m_cConfigOption.m_vConfigOption.at(i).m_sKeyValue = strKeyValue.toStdString();
m_cConfigOption.m_vConfigOption.at(i).m_sKeyDes .clear();
m_cConfigOption.m_vConfigOption.at(i).m_sKeyDes = strKeyDes.toStdString();
}
}
CMSOprResult cOptRet;
m_cApsServerManageClient->UploadConfig(ui.comboBoxIP->currentText().toStdString(), ui.comboBoxConfig->currentText().toStdString(), m_cConfigOption.m_vConfigOption, cOptRet);
if (cOptRet.m_iOprCode != 0)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("配置上传失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("配置失败"));
}
else
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("配置上传成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("配置成功"));
}
}
//添加DNS配置
void CServerManager::OnAddDNS()
{
std::vector<std::string > vDNSAdd;
std::string strDNSMain = ui.mainDNSlineEdit->text().toStdString();
std::string strDNSSpare = ui.spareDNSlineEdit->text().toStdString();
if(OnCheckIP(strDNSMain) == -1 || OnCheckIP(strDNSSpare) == -1)
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
CMSOprResult cOptRet;
vDNSAdd.push_back(strDNSMain);
vDNSAdd.push_back(strDNSSpare);
m_cApsServerManageClient->AddDNS(ui.comboBoxIP->currentText().toStdString(), vDNSAdd, cOptRet);
if (cOptRet.m_iOprCode != 0)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("DNS配置失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("DNS配置失败"));
}
else
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("DNS配置成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("DNS配置成功"));
}
}
//删除DNS配置
void CServerManager::OnDelDNS()
{
std::string strDNSMain = ui.mainDNSlineEdit->text().toStdString();
std::string strDNSSpare = ui.spareDNSlineEdit->text().toStdString();
if(OnCheckIP(strDNSMain) == -1 || OnCheckIP(strDNSSpare) == -1)
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("IP格式错误 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
CMSOprResult cOptRet;
m_cApsServerManageClient->DelDNS(ui.comboBoxIP->currentText().toStdString(), strDNSMain, cOptRet);
if (cOptRet.m_iOprCode != 0)
{
QMessageBox mesBox(QMessageBox::Warning, tr("提示"), tr("DNS删除失败 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("DNS删除失败"));
}
else
{
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("DNS删除成功 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
//QMessageBox::information(this, tr("提示"), tr("DNS删除成功"));
ui.mainDNSlineEdit->setText("");
ui.spareDNSlineEdit->setText("");
}
}
//检查IP是否合格
int CServerManager::OnCheckIP(std::string& strIP)
{
if (strIP.empty())
{
//QMessageBox::information(this, tr("提示"), tr("请输入数据"));
return -1;
}
char* cstrIP = NULL;
char* cstrIPTmp = NULL;
cstrIP = new char[strIP.size() + 1];
cstrIPTmp = cstrIP;
strcpy(cstrIP, strIP.c_str());
int iNum = 0;
for (int i = 0; i < (strIP.size()); i++)
{
if (*cstrIPTmp == '.')
{
iNum++;
}
if (iNum == 3)
{
if (*(cstrIPTmp + 1) == ' ')
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
delete[] cstrIP;
return -1;
}
else
{
break;
}
}
cstrIPTmp++;
}
if(iNum < 3)
{
//QMessageBox::information(this, tr("提示"), tr("输入格式错误"));
delete[] cstrIP;
return -1;
}
delete[] cstrIP;
return 0;
}
CApsServerManageClient* CServerManager::GetApsSerManaClient()
{
return m_cApsServerManageClient;
}
//设置IP 端口
void CServerManager::OnInitIPPort()
{
m_strServerIP = ui.lineEditIP->text();
m_iServerPort = ui.lineEditPort->text().toInt();
if (m_iServerPort == 0 || m_strServerIP.isEmpty())
{
//QMessageBox::information(this, tr("提示"), tr("请输入数据"));
QMessageBox mesBox(QMessageBox::Information, tr("提示"), tr("请输入数据 "), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
mesBox.setButtonText(QMessageBox::Ok, tr("确定"));
mesBox.exec();
return;
}
else if(-1 == OnCheckIP(m_strServerIP.toStdString()))
{
return;
}
else
{
m_cApsServerManageClient->initConfig(m_strServerIP.toStdString(), m_iServerPort);
m_pmsgBox = new QMessageBox(QMessageBox::Information, tr("提示"), tr("服务器连接中..."), QMessageBox::Ok, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint );
m_pmsgBox->setButtonText(QMessageBox::Ok, tr("确定"));
m_pmsgBox->open();
m_pCSeverThread->begin();
}
}
void CServerManager::OnGetNodeManagePwd(int row, int column)
{
/*if (column)
{
}*/
}
QString CServerManager::GetSeverIP()
{
return m_strServerIP;
}
int CServerManager::GetSeverPort()
{
return m_iServerPort;
}
//void QTableWidget::itemChanged ( QTableWidgetItem * item ) [signal]
插入空白行:
void insertTimeBlankEntry()
{
m_bTimeFlag = false;
int iRow = m_pTimeModel->rowcount();
m_pTimeModel->insertRows(iRow, 1, QModelIndex());
m_pTimeModel->setData(m_pTimeModel->index(iRow, 0), m_iTimeMaxkey);
m_pTimeModel->setData(m_pTimeModel->index(iRow, 1), QVariant("").toTime());
m_pTimeModel->setData(m_pTimeModel->index(iRow, 2), QVariant("").toTime());
m_pTimeModel->item(iRow, 0)->setEditable(false);
m_iTimeBlankKey = m_iTimeMaxkey;
m_bTimeFalg = true;
}