示例#1
0
/*!
    \fn MMascota::agregarMascota( QVariant nombre, QVariant raza, QVariant genero, QModelIndex dueno )
 */
bool MMascota::agregarMascota( QVariant nombre, QVariant raza, QVariant genero, QModelIndex dueno )
{
 if( !dueno.isValid() )
 {return false;}
 QVariant id_dueno = relationModel( 1 )->data( dueno, 0 );
 if( id_dueno.isValid() && id_dueno.toInt() <= 0 )
 {return false;}
 QSqlRecord registro = record();
 registro.setValue( 1, id_dueno );
 registro.setValue( 2, nombre );
 registro.setValue( 3, raza );
 registro.setValue( 4, genero );
 if( this->insertRecord( -1, registro ) )
 {
  return true;
 }
 else
 {
  qDebug( "Error al insertar registro de mascota" );
  qDebug( QString( "Detalles: tipo: %1, errno: %2, descripcion: %3" ).arg( lastError().type() ).arg( lastError().number() ).arg( lastError().text() ).toLocal8Bit() );
  return false;
 }
}
示例#2
0
ProductsModel::ProductsModel(QObject *parent) :
    QSqlRelationalTableModel(parent)
{

    //    Language setup
    QString app_path;
    app_path = QApplication::applicationDirPath() + QDir::separator() + "settings.ini";
    QSettings settings(app_path,QSettings::IniFormat);
    QString content = settings.value("s_language","").toString();
    QString lanCode;
    QString lanName;
    if(content == "tamil_language"){
        QTranslator translator;
        translator.load("tamilLanguage_la");
    //  QApplication::installTranslator(&translator);
        QApplication::instance()->installTranslator(&translator);
        lanCode = ProductForm::tr("Code");
        lanName = ProductForm::tr("Name");
     }else{
        QTranslator translator;
        translator.load("englishLanguage_la");
    //  QApplication::installTranslator(&translator);
        QApplication::instance()->installTranslator(&translator);
        lanCode = ProductForm::tr("Code");
        lanName = ProductForm::tr("Name");
    }

    setTable("products");
    setRelation(4, QSqlRelation("categories", "id", "name"));
    setEditStrategy(QSqlTableModel::OnManualSubmit);
    setHeaderData(fieldIndex("code"), Qt::Horizontal, lanCode);
    setHeaderData(fieldIndex("name"), Qt::Horizontal, lanName);
    setFilter("products.status = 'A'");
    relationModel(4)->setFilter("status = 'A'");
    setSort(fieldIndex("name"),Qt::AscendingOrder);
    select();
}