void currencyConversion::populate() { XSqlQuery currencypopulate; QString rateString; if (_curr_rate_id) { QString inverter(""); if (_metrics->value("CurrencyExchangeSense").toInt() == 1) inverter = "1 / "; QString sql = QString("SELECT curr_id, %1 curr_rate AS curr_rate, " "curr_effective, curr_expires " "FROM curr_rate " "WHERE curr_rate_id = :curr_rate_id;") .arg(inverter); currencypopulate.prepare(sql); currencypopulate.bindValue(":curr_rate_id", _curr_rate_id); currencypopulate.exec(); { if (currencypopulate.first()) { _currency->setId(currencypopulate.value("curr_id").toInt()); _dateCluster->setStartDate(currencypopulate.value("curr_effective").toDate()); _dateCluster->setEndDate(currencypopulate.value("curr_expires").toDate()); _rate->setText(rateString.setNum(currencypopulate.value("curr_rate").toDouble(), 'f', 6)); } } } if (_curr_id) { _currency->setId(_curr_id); } }
void currencyConversions::sFillList() { QString inverter(""); if (_metrics->value("CurrencyExchangeSense").toInt() == 1) inverter = "1 / "; // the N in round(%1 curr_rate, N) has to be SCALE - 1 of curr_rate's // NUMERIC(p, SCALE) type definition QString sql = QString("SELECT curr_rate_id, currConcat(curr_id) AS f_curr, " " round(%1 curr_rate, 5), curr_effective, " " curr_expires " "FROM curr_symbol NATURAL JOIN curr_rate " "WHERE curr_base = FALSE " " AND curr_expires >= :startDate " " AND curr_effective <= :endDate ").arg(inverter); if (_queryParameters->isSelected()) { QString intString; sql+= " AND curr_id = :curr_id "; } else if (_queryParameters->isPattern()) { sql += " AND currConcat(curr_id) ~ :currConcat_pattern "; } sql += " ORDER BY f_curr, curr_effective, curr_expires "; q.prepare(sql); _queryParameters->bindValue(q); _dateCluster->bindValue(q); q.exec(); _conversionRates->populate(q); if (q.lastError().type() != QSqlError::NoError) { QMessageBox::critical(this, tr("A System Error occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), q.lastError().databaseText()); } }
void CINF::sendCINFToBlender(hecl::blender::PyOutStream& os, const UniqueID32& cinfId) const { DNAANIM::RigInverter<CINF> inverter(*this); os.format( "arm = bpy.data.armatures.new('CINF_%08X')\n" "arm_obj = bpy.data.objects.new(arm.name, arm)\n" "bpy.context.scene.objects.link(arm_obj)\n" "bpy.context.scene.objects.active = arm_obj\n" "bpy.ops.object.mode_set(mode='EDIT')\n" "arm_bone_table = {}\n", cinfId.toUint32()); for (const DNAANIM::RigInverter<CINF>::Bone& bone : inverter.getBones()) { zeus::simd_floats originF(bone.m_origBone.origin.simd); zeus::simd_floats tailF(bone.m_tail.mSimd); os.format( "bone = arm.edit_bones.new('%s')\n" "bone.head = (%f,%f,%f)\n" "bone.tail = (%f,%f,%f)\n" "bone.use_inherit_scale = False\n" "arm_bone_table[%u] = bone\n", getBoneNameFromId(bone.m_origBone.id)->c_str(), originF[0], originF[1], originF[2], tailF[0], tailF[1], tailF[2], bone.m_origBone.id); } for (const Bone& bone : bones) if (bone.parentId != 2) os.format("arm_bone_table[%u].parent = arm_bone_table[%u]\n", bone.id, bone.parentId); os << "bpy.ops.object.mode_set(mode='OBJECT')\n"; const char* rotMode = os.getConnection().hasSLERP() ? "QUATERNION_SLERP" : "QUATERNION"; for (const DNAANIM::RigInverter<CINF>::Bone& bone : inverter.getBones()) os.format("arm_obj.pose.bones['%s'].rotation_mode = '%s'\n", getBoneNameFromId(bone.m_origBone.id)->c_str(), rotMode); }
int main () { char str; char aux; printf("\n Insira uma string: \n"); scanf("%s",&str); inverter(str); strcpy(str,aux); if(strcmp(str,aux) != 0) { printf("E Palindromo"); } else { printf("Nao e palindromo!"); } return 0; }
int main(int argc, char** argv) { /**Abertura do arquivo da imagem*/ printf("%s\n","Informe o nome do arquivo de imagem a ser aberto:"); scanf("%s",Nome_arquivo); /**Função limpa tela*/ reset(); FILE *arquivo; /**Ler o arquivo*/ arquivo = fopen(Nome_arquivo, "r"); /**Faz o teste de erro na abertura do arquivo*/ if(arquivo == NULL){ printf("%s\n","Erro ao abrir o arquivo de imagem."); }else{ printf("%s\n","Arquivo de imagem aberto com sucesso."); } /**Ler os dados do cabeçalho*/ fscanf(arquivo, "P3 %i %i 255",&largura, &altura); /**Comparação para ver o maior valor da matriz*/ if (largura > altura) { max = largura; }else{ max = altura; } /**Cria uma variável do tipo struct*/ Pixel imagem[max][max]; /**Ler cada Pixel alocando na variável referente ao struct*/ for (i = 0; i < altura; i++){ for(j = 0; j < largura; j++){ fscanf(arquivo, "%i %i %i", &imagem[i][j].r, &imagem[i][j].g, &imagem[i][j].b); } } /**fecha o arquivo*/ fclose(arquivo); do{ /**Menu do programa sendo chamado*/ menu(); printf("\nDigite o comando:>"); /**Comando para leitura do menu*/ scanf("%s",comando); reset(); /**converte as letras para minusculo afim de facilitar a comparação*/ for(i=0;comando[i];i++) comando[i]=tolower(comando[i]); if(strcmp(comando,"lap")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama o Filtro de laplace*/ laplace(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem tratada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"gau")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama o filtro de gaus*/ gaussiano(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem tratada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"blu")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama o filtro Blurring*/ passa_baixa(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem tratada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"sha")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama o filtro sharpening*/ passa_alta(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem tratada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"amp")==0){ printf("\nExecutando o comando: %s\n", comando); printf("\nInforme o zoom desejado:\n"); /**Ler o zoom para ampliar a imagem*/ scanf("%i",&zoom); printf("%s\n", "Informe o nome desejado para saída:"); scanf("%s",arq); /**Chama a função para ampliar da imagem*/ ampliar_img(strcat(arq,".ppm"),zoom,imagem); printf("%s\n", "Imagem ampliada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"red")==0){ printf("\nExecutando o comando: %s\n", comando); printf("\nInforme o zoom desejado:\n"); /**Ler o zoom para reduzir a imagem*/ scanf("%i",&zoom); printf("%s\n", "Informe o nome desejado para saída:"); scanf("%s",arq); /**Chama a função para redução da imagem*/ reduzir_img(strcat(arq,".ppm"),zoom,imagem); printf("%s\n", "Imagem reduzida com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"rel")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama o filtro para aplicar o relevo na imagem*/ relevo(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem tratada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"thr")==0){ printf("\nExecutando o comando: %s\n", comando); printf("\nInforme o valor do thresholding:\n"); scanf("%i",&thr); /**Chama o filtro da binarização*/ binarization(imagem, thr); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem binarizada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"gra")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama o filtro para grayscale*/ grayscale(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem tratada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"inv")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama o filtro para inverter as cores*/ inverter(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem tratada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"esp")==0){ printf("\nExecutando o comando: %s\n", comando); /**Chama a função para espelhar a imagem*/ espelhar(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem espelhada com sucesso."); return (EXIT_SUCCESS); }else if(strcmp(comando,"rot")==0){ printf("%s\n", "Informe o ângulo desejado desejado (90, 180, 270):"); /**Detalha o ângulo de rotação*/ scanf("%i",&angulo); if(angulo == 90){ printf("\nExecutando o comando: %s\n", comando); /**Chama a função para rotacionar a imagem*/ rotacionar_esq(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem rotacionada com sucesso."); return (EXIT_SUCCESS); }else if(angulo == 180){ printf("\nExecutando o comando: %s\n", comando); rotacionar_180(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem rotacionada com sucesso."); return (EXIT_SUCCESS); }else if(angulo == 270){ printf("\nExecutando o comando: %s\n", comando); rotacionar_270(imagem); printf("%s\n", "Informe o nome desejado para saída:"); /**Ler o novo nome para a imagem*/ scanf("%s",arq); gerar_img(imagem, arq); printf("%s\n", "Imagem rotacionada com sucesso."); return (EXIT_SUCCESS); } }else{ /** chama a funcao limpa tela*/ reset(); printf("\nComando desconhecido: %s\n",comando); } }while(strcmp(comando,"exit")!=0); printf("%s\n", "Programa finalizado"); /**Finaliza o programa*/ return (EXIT_SUCCESS); }
bool ReadANCSToBlender(hecl::blender::Connection& conn, const ANCSDNA& ancs, const hecl::ProjectPath& outPath, PAKRouter& pakRouter, const typename PAKRouter::EntryType& entry, const SpecBase& dataspec, std::function<void(const hecl::SystemChar*)> fileChanged, bool force) { /* Extract character CMDL/CSKR first */ std::vector<CharacterResInfo<typename PAKRouter::IDType>> chResInfo; ancs.getCharacterResInfo(chResInfo); for (const auto& info : chResInfo) { const nod::Node* node; const typename PAKRouter::EntryType* cmdlE = pakRouter.lookupEntry(info.cmdl, &node, true, false); if (cmdlE) { hecl::ProjectPath cmdlPath = pakRouter.getWorking(cmdlE); if (force || cmdlPath.isNone()) { cmdlPath.makeDirChain(false); if (!conn.createBlend(cmdlPath, hecl::blender::BlendType::Mesh)) return false; std::string bestName = pakRouter.getBestEntryName(*cmdlE); hecl::SystemStringConv bestNameView(bestName); fileChanged(bestNameView.c_str()); typename ANCSDNA::CSKRType cskr; pakRouter.lookupAndReadDNA(info.cskr, cskr); typename ANCSDNA::CINFType cinf; pakRouter.lookupAndReadDNA(info.cinf, cinf); using RigPair = std::pair<typename ANCSDNA::CSKRType*, typename ANCSDNA::CINFType*>; RigPair rigPair(&cskr, &cinf); PAKEntryReadStream rs = cmdlE->beginReadStream(*node); DNACMDL::ReadCMDLToBlender<PAKRouter, MaterialSet, RigPair, SurfaceHeader, CMDLVersion>( conn, rs, pakRouter, *cmdlE, dataspec, rigPair); conn.saveBlend(); } } } /* Extract attachment CMDL/CSKRs first */ auto attRange = pakRouter.lookupCharacterAttachmentRigs(entry.id); for (auto it = attRange.first; it != attRange.second; ++it) { auto cmdlid = it->second.first.second; const nod::Node* node; const typename PAKRouter::EntryType* cmdlE = pakRouter.lookupEntry(cmdlid, &node, true, false); if (cmdlE) { hecl::ProjectPath cmdlPath = pakRouter.getWorking(cmdlE); if (force || cmdlPath.isNone()) { cmdlPath.makeDirChain(false); if (!conn.createBlend(cmdlPath, hecl::blender::BlendType::Mesh)) return false; std::string bestName = pakRouter.getBestEntryName(*cmdlE); hecl::SystemStringConv bestNameView(bestName); fileChanged(bestNameView.c_str()); const auto* rp = pakRouter.lookupCMDLRigPair(cmdlid); typename ANCSDNA::CSKRType cskr; pakRouter.lookupAndReadDNA(rp->first, cskr); typename ANCSDNA::CINFType cinf; pakRouter.lookupAndReadDNA(rp->second, cinf); using RigPair = std::pair<typename ANCSDNA::CSKRType*, typename ANCSDNA::CINFType*>; RigPair rigPair(&cskr, &cinf); PAKEntryReadStream rs = cmdlE->beginReadStream(*node); DNACMDL::ReadCMDLToBlender<PAKRouter, MaterialSet, RigPair, SurfaceHeader, CMDLVersion>( conn, rs, pakRouter, *cmdlE, dataspec, rigPair); conn.saveBlend(); } } } std::string bestName = pakRouter.getBestEntryName(entry); hecl::SystemStringConv bestNameView(bestName); fileChanged(bestNameView.c_str()); /* Establish ANCS blend */ if (!conn.createBlend(outPath, hecl::blender::BlendType::Actor)) return false; std::string firstName; typename ANCSDNA::CINFType firstCinf; { hecl::blender::PyOutStream os = conn.beginPythonOut(true); os.format( "import bpy\n" "from mathutils import Vector\n" "bpy.context.scene.name = '%s'\n" "bpy.context.scene.hecl_mesh_obj = bpy.context.scene.name\n" "\n" "# Using 'Blender Game'\n" "bpy.context.scene.render.engine = 'BLENDER_GAME'\n" "\n" "# Clear Scene\n" "for ob in bpy.data.objects:\n" " if ob.type != 'LAMP' and ob.type != 'CAMERA':\n" " bpy.context.scene.objects.unlink(ob)\n" " bpy.data.objects.remove(ob)\n" "\n" "actor_data = bpy.context.scene.hecl_sact_data\n" "arm_obj = None\n", pakRouter.getBestEntryName(entry).c_str()); std::unordered_set<typename PAKRouter::IDType> cinfsDone; for (const auto& info : chResInfo) { /* Provide data to add-on */ os.format( "actor_subtype = actor_data.subtypes.add()\n" "actor_subtype.name = '%s'\n\n", info.name.c_str()); /* Build CINF if needed */ if (cinfsDone.find(info.cinf) == cinfsDone.end()) { typename ANCSDNA::CINFType cinf; pakRouter.lookupAndReadDNA(info.cinf, cinf); cinf.sendCINFToBlender(os, info.cinf); if (cinfsDone.empty()) { firstName = ANCSDNA::CINFType::GetCINFArmatureName(info.cinf); firstCinf = cinf; } cinfsDone.insert(info.cinf); } else os.format("arm_obj = bpy.data.objects['CINF_%s']\n", info.cinf.toString().c_str()); os << "actor_subtype.linked_armature = arm_obj.name\n"; /* Link CMDL */ const typename PAKRouter::EntryType* cmdlE = pakRouter.lookupEntry(info.cmdl, nullptr, true, false); if (cmdlE) { hecl::ProjectPath cmdlPath = pakRouter.getWorking(cmdlE); os.linkBlend(cmdlPath.getAbsolutePathUTF8().data(), pakRouter.getBestEntryName(*cmdlE).data(), true); /* Attach CMDL to CINF */ os << "if obj.name not in bpy.context.scene.objects:\n" " bpy.context.scene.objects.link(obj)\n" "obj.parent = arm_obj\n" "obj.parent_type = 'ARMATURE'\n" "actor_subtype.linked_mesh = obj.name\n\n"; } /* Link overlays */ for (const auto& overlay : info.overlays) { os << "overlay = actor_subtype.overlays.add()\n"; os.format("overlay.name = '%s'\n", overlay.first.c_str()); /* Link CMDL */ const typename PAKRouter::EntryType* cmdlE = pakRouter.lookupEntry(overlay.second.first, nullptr, true, false); if (cmdlE) { hecl::ProjectPath cmdlPath = pakRouter.getWorking(cmdlE); os.linkBlend(cmdlPath.getAbsolutePathUTF8().data(), pakRouter.getBestEntryName(*cmdlE).data(), true); /* Attach CMDL to CINF */ os << "if obj.name not in bpy.context.scene.objects:\n" " bpy.context.scene.objects.link(obj)\n" "obj.parent = arm_obj\n" "obj.parent_type = 'ARMATURE'\n" "overlay.linked_mesh = obj.name\n\n"; } } } /* Link attachments */ for (auto it = attRange.first; it != attRange.second; ++it) { os << "attachment = actor_data.attachments.add()\n"; os.format("attachment.name = '%s'\n", it->second.second.c_str()); auto cinfid = it->second.first.first; auto cmdlid = it->second.first.second; if (cinfid) { /* Build CINF if needed */ if (cinfsDone.find(cinfid) == cinfsDone.end()) { typename ANCSDNA::CINFType cinf; pakRouter.lookupAndReadDNA(cinfid, cinf); cinf.sendCINFToBlender(os, cinfid); if (cinfsDone.empty()) { firstName = ANCSDNA::CINFType::GetCINFArmatureName(cinfid); firstCinf = cinf; } cinfsDone.insert(cinfid); } else os.format("arm_obj = bpy.data.objects['CINF_%s']\n", cinfid.toString().c_str()); os << "attachment.linked_armature = arm_obj.name\n"; } /* Link CMDL */ const typename PAKRouter::EntryType* cmdlE = pakRouter.lookupEntry(cmdlid, nullptr, true, false); if (cmdlE) { hecl::ProjectPath cmdlPath = pakRouter.getWorking(cmdlE); os.linkBlend(cmdlPath.getAbsolutePathUTF8().data(), pakRouter.getBestEntryName(*cmdlE).data(), true); /* Attach CMDL to CINF */ os << "if obj.name not in bpy.context.scene.objects:\n" " bpy.context.scene.objects.link(obj)\n" "obj.parent = arm_obj\n" "obj.parent_type = 'ARMATURE'\n" "attachment.linked_mesh = obj.name\n\n"; } } } { hecl::blender::DataStream ds = conn.beginData(); std::unordered_map<std::string, hecl::blender::Matrix3f> matrices = ds.getBoneMatrices(firstName); ds.close(); DNAANIM::RigInverter<typename ANCSDNA::CINFType> inverter(firstCinf, matrices); hecl::blender::PyOutStream os = conn.beginPythonOut(true); os << "import bpy\n" "actor_data = bpy.context.scene.hecl_sact_data\n"; /* Get animation primitives */ std::map<atUint32, AnimationResInfo<typename PAKRouter::IDType>> animResInfo; ancs.getAnimationResInfo(&pakRouter, animResInfo); for (const auto& id : animResInfo) { typename ANCSDNA::ANIMType anim; if (pakRouter.lookupAndReadDNA(id.second.animId, anim, true)) { os.format( "act = bpy.data.actions.new('%s')\n" "act.use_fake_user = True\n", id.second.name.c_str()); anim.sendANIMToBlender(os, inverter, id.second.additive); } os.format( "actor_action = actor_data.actions.add()\n" "actor_action.name = '%s'\n", id.second.name.c_str()); /* Extract EVNT if present */ anim.extractEVNT(id.second, outPath, pakRouter, force); } } conn.saveBlend(); return true; }
int main(int argc, char** argv) { // verifica se um parametro foi passado, senao exibe a forma de uso if (!argv[1]){ mostraUso(); return 0; } // Procedimento que carrega os dados do arquivo em uma matriz int **matriz; int linhas, colunas; printf("Abrindo arquivo...\n"); matriz = (int **)carregaArquivo(argv[1], &linhas, &colunas); if (!matriz){ printf("ERRO: nao foi possivel abrir o arquivo %s\n", argv[1]); return 0; } // entrando no loop do menu int opcao; do{ // limpa a tela se o clear estiver disponível system("clear"); printf("Selecione uma opcao ou 0 para encerrar\n" \ "[1] - Salvar\n" \ "[2] - Limiarizar\n" \ "[3] - Inverter\n" \ "[4] - Media 3x3\n" \ "[5] - Mediana 3x3\n" \ "[6] - Numero de brancos\n" \ "======> "); scanf("%d", &opcao); switch(opcao){ case 0: break; case 1: printf("\nNome do novo arquivo (enter para sobrescrever): "); char caminho[20]; // workaround do buffer sujo getchar(); fgets(caminho, sizeof(caminho), stdin); if (caminho) salvaArquivo(caminho, matriz, linhas, colunas); else salvaArquivo(argv[1], matriz, linhas, colunas); teclaEnter(); break; case 2: limiarizar(matriz, linhas, colunas); mostraMatriz(matriz, linhas, colunas); break; case 3: inverter(matriz, linhas, colunas); mostraMatriz(matriz, linhas, colunas); break; case 4: if (media3x3(matriz, linhas, colunas)) mostraMatriz(matriz, linhas, colunas); break; case 5: if (mediana3x3(matriz, linhas, colunas)) mostraMatriz(matriz, linhas, colunas); break; case 6: printf("\nNumero de brancos: %d\n", nroBrancos(matriz, linhas, colunas)); // espera input do teclado teclaEnter(); break; default: printf("Opcao nao reconhecida"); teclaEnter(); break; } }while(opcao != 0); // liberacao de memoria desalocaMatriz(matriz, linhas); return 0; }
void currencyConversion::_sSave() { XSqlQuery currency_sSave; QList<GuiErrorCheck>errors; errors<<GuiErrorCheck(! _currency->isValid(), _currency, tr("Please specify a currency for this exchange rate.")) <<GuiErrorCheck(_rate->toDouble() == 0, _rate, tr("You must specify a Rate that is not zero.")) <<GuiErrorCheck(!_dateCluster->startDate().isValid(), _dateCluster, tr("Please specify a Start Date for this exchange rate.")) <<GuiErrorCheck(!_dateCluster->endDate().isValid(), _dateCluster, tr("Please specify an End Date for this exchange rate.")) <<GuiErrorCheck(_dateCluster->startDate() > _dateCluster->endDate(), _dateCluster, tr("The Start Date for this exchange rate is " "later than the End Date.\n" "Please check the values of these dates.")); if(GuiErrorCheck::reportErrors(this,tr("Cannot Save Currency Conversion"),errors)) return; currency_sSave.prepare( "SELECT count(*) AS numberOfOverlaps " "FROM curr_rate " "WHERE curr_id = :curr_id" " AND curr_rate_id != :curr_rate_id" " AND ( (curr_effective BETWEEN :curr_effective AND :curr_expires OR" " curr_expires BETWEEN :curr_effective AND :curr_expires)" " OR (curr_effective <= :curr_effective AND" " curr_expires >= :curr_expires) );" ); currency_sSave.bindValue(":curr_rate_id", _curr_rate_id); currency_sSave.bindValue(":curr_id", _currency->id()); currency_sSave.bindValue(":curr_effective", _dateCluster->startDate()); currency_sSave.bindValue(":curr_expires", _dateCluster->endDate()); currency_sSave.exec(); if (currency_sSave.first()) { if (currency_sSave.value("numberOfOverlaps").toInt() > 0) { QMessageBox::warning(this, tr("Invalid Date Range"), tr("The date range overlaps with " "another date range.\n" "Please check the values of these dates.")); _dateCluster->setFocus(); return; } } QString inverter(""); if (_metrics->value("CurrencyExchangeSense").toInt() == 1) inverter = "1 / "; QString sql; if (_mode == cNew) sql = QString("INSERT INTO curr_rate " "(curr_id, curr_rate, curr_effective, curr_expires) " "VALUES " "(:curr_id, %1 CAST(:curr_rate AS NUMERIC), " " :curr_effective, :curr_expires)") .arg(inverter); else if (_mode == cEdit) sql = QString("UPDATE curr_rate SET " "curr_id = :curr_id, " "curr_rate = %1 CAST(:curr_rate AS NUMERIC), " "curr_effective = :curr_effective, " "curr_expires = :curr_expires " "WHERE curr_rate_id = :curr_rate_id") .arg(inverter); _rate->setText(_rate->text().replace(',', '.')); currency_sSave.prepare(sql); currency_sSave.bindValue(":curr_rate_id", _curr_rate_id); currency_sSave.bindValue(":curr_id", _currency->id()); currency_sSave.bindValue(":curr_rate", _rate->toDouble()); currency_sSave.bindValue(":curr_effective", _dateCluster->startDate()); currency_sSave.bindValue(":curr_expires", _dateCluster->endDate()); currency_sSave.exec(); if (currency_sSave.lastError().type() != QSqlError::NoError) { QMessageBox::critical(this, tr("A System Error occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), currency_sSave.lastError().databaseText()); return; } done(_curr_rate_id); }
void currencyConversion::_sSave() { if (! _currency->isValid()) { QMessageBox::warning(this, tr("Missing Currency"), tr("Please specify a currency for this exchange rate.")); _currency->setFocus(); return; } if (_rate->toDouble() == 0) { QMessageBox::warning(this, tr("No Rate Specified"), tr("You must specify a Rate that is not zero.") ); return; } if (!_dateCluster->startDate().isValid()) { QMessageBox::warning( this, tr("Missing Start Date"), tr("Please specify a Start Date for this exchange rate.")); _dateCluster->setFocus(); return; } if (!_dateCluster->endDate().isValid()) { QMessageBox::warning( this, tr("Missing End Date"), tr("Please specify an End Date for this exchange rate. ")); _dateCluster->setFocus(); return; } if (_dateCluster->startDate() > _dateCluster->endDate()) { QMessageBox::warning(this, tr("Invalid Date Order"), tr("The Start Date for this exchange rate is " "later than the End Date.\n" "Please check the values of these dates.")); _dateCluster->setFocus(); return; } QString inverter(""); if (_metrics->value("CurrencyExchangeSense").toInt() == 1) inverter = "1 / "; QString sql; if (_mode == cNew) sql = QString("INSERT INTO curr_rate " "(curr_id, curr_rate, curr_effective, curr_expires) " "VALUES " "(:curr_id, %1 CAST(:curr_rate AS NUMERIC), " " :curr_effective, :curr_expires)") .arg(inverter); else if (_mode == cEdit) sql = QString("UPDATE curr_rate SET " "curr_id = :curr_id, " "curr_rate = %1 CAST(:curr_rate AS NUMERIC), " "curr_effective = :curr_effective, " "curr_expires = :curr_expires " "WHERE curr_rate_id = :curr_rate_id") .arg(inverter); q.prepare(sql); q.bindValue(":curr_rate_id", _curr_rate_id); q.bindValue(":curr_id", _currency->id()); q.bindValue(":curr_rate", _rate->toDouble()); q.bindValue(":curr_effective", _dateCluster->startDate()); q.bindValue(":curr_expires", _dateCluster->endDate()); q.exec(); if (q.lastError().type() != QSqlError::NoError) { QMessageBox::critical(this, tr("A System Error occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), q.lastError().databaseText()); return; } done(_curr_rate_id); }