DbConn dbConn;
QString tabChnName,tabEngName;//编辑权限(允许1/禁止0)、表格名称
QString sqlString;
QSqlDatabase myDB = dbConn.GetDatabase();
if(!myDB.open())
{
QMessageBox::critical(0,QObject::tr("数据库连接错误----"),myDB.lastError().text());
return;
}
QList<QTreeWidgetItem *> treeWidgetItemList = roleAuthEditTree->selectedItems();
sqlString.append("select name, tbpermmodeforedit, tbpermmodeforead, tbroleforedit, tbroleforead from tbPlateRole where name = '");//角色名、编辑权限(允许1/禁止0)、拥有权限的表格名称
sqlString.append(sysRoleList->currentText());
sqlString.append("'");
QList<QSqlRecord> list = dbConn.GetRecordsbyQueryStr(sqlString);
for(int i =0;i < treeWidgetItemList.count();i++)
{
if(list.count() == 1)
{
if(!list.at(0).value(3).toString().contains(tabEngName,Qt::CaseInsensitive))//没有记录此表
{
myDB.close();
if(!myDB.open("vesta","sht2010"))
{
QMessageBox::information(this,tr("提示"),tr("数据库连接打不开!"));
QMessageBox::critical(0,QObject::tr("原因:"),myDB.lastError().text());
//continue;
}
if(!myDB.isOpenError())
{
QMessageBox::information(this,tr("提示"),tr("打开出错!"));
//continue;
}
if(!myDB.isOpen())
{
QMessageBox::information(this,tr("提示"),tr("数据库处于关闭状态!"));
//continue;
}
QString tmpEdit;
if(list.at(0).value(1).toString().toInt() == 0)//禁止模式,已有记录应该删除
{//加进去
tmpEdit.append(list.at(0).value(3).toString());
tmpEdit.remove(tabEngName,Qt::CaseInsensitive);
if(!dbConn.SetValbyVarName("tbPlateRole",-1,sysRoleList->currentText(),"name",tmpEdit,"tbPlateRole.tbroleforedit"))
{
QMessageBox::information(this,tr("提示"),tr("更新数据失败!"));
QMessageBox::critical(0,QObject::tr("出错原因:"),dbConn.ErrStr());
QMessageBox::information(this,tr("sql观察"),dbConn.QueryStr());
}
}
else if(list.at(0).value(1).toString().toInt() == 1)//允许模式,已经允许。
{
QString tip = tr("已经允许编辑“<font color=#990000>") + tabChnName + tr("</font>”了,操作重复!");
QMessageBox::information(this,tr("提示"),tip);
}
else
{
QMessageBox::information(this,tr("提示"),tr("权限模式值异常!"));
}
}
。。。。。。。。。。。。。。。。。。。