int main() { char choice; puts("\t Main Menu:"); puts(" a: Formula 1"); puts(" b: Formula 2"); puts(" e: Exit"); while(1) { scanf("%c", &choice); if (choice == 'a' || choice == 'A') { //puts("You chose Formula 1"); formula1(); } else if (choice == 'b' || choice == 'B') { puts("You chose Formula 2"); } else if (choice == 'e' || choice == 'E') { puts("Exiting now..."); break; } else { puts("Invalid Input... Please try again!"); } getchar(); } return EXIT_SUCCESS; }
/*! * \internal */ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const { static QMap<DataValidation::ValidationType, QString> typeMap; static QMap<DataValidation::ValidationOperator, QString> opMap; static QMap<DataValidation::ErrorStyle, QString> esMap; if (typeMap.isEmpty()) { typeMap.insert(DataValidation::None, QStringLiteral("none")); typeMap.insert(DataValidation::Whole, QStringLiteral("whole")); typeMap.insert(DataValidation::Decimal, QStringLiteral("decimal")); typeMap.insert(DataValidation::List, QStringLiteral("list")); typeMap.insert(DataValidation::Date, QStringLiteral("date")); typeMap.insert(DataValidation::Time, QStringLiteral("time")); typeMap.insert(DataValidation::TextLength, QStringLiteral("textLength")); typeMap.insert(DataValidation::Custom, QStringLiteral("custom")); opMap.insert(DataValidation::Between, QStringLiteral("between")); opMap.insert(DataValidation::NotBetween, QStringLiteral("notBetween")); opMap.insert(DataValidation::Equal, QStringLiteral("equal")); opMap.insert(DataValidation::NotEqual, QStringLiteral("notEqual")); opMap.insert(DataValidation::LessThan, QStringLiteral("lessThan")); opMap.insert(DataValidation::LessThanOrEqual, QStringLiteral("lessThanOrEqual")); opMap.insert(DataValidation::GreaterThan, QStringLiteral("greaterThan")); opMap.insert(DataValidation::GreaterThanOrEqual, QStringLiteral("greaterThanOrEqual")); esMap.insert(DataValidation::Stop, QStringLiteral("stop")); esMap.insert(DataValidation::Warning, QStringLiteral("warning")); esMap.insert(DataValidation::Information, QStringLiteral("information")); } writer.writeStartElement(QStringLiteral("dataValidation")); if (validationType() != DataValidation::None) writer.writeAttribute(QStringLiteral("type"), typeMap[validationType()]); if (errorStyle() != DataValidation::Stop) writer.writeAttribute(QStringLiteral("errorStyle"), esMap[errorStyle()]); if (validationOperator() != DataValidation::Between) writer.writeAttribute(QStringLiteral("operator"), opMap[validationOperator()]); if (allowBlank()) writer.writeAttribute(QStringLiteral("allowBlank"), QStringLiteral("1")); // if (dropDownVisible()) // writer.writeAttribute(QStringLiteral("showDropDown"), QStringLiteral("1")); if (isPromptMessageVisible()) writer.writeAttribute(QStringLiteral("showInputMessage"), QStringLiteral("1")); if (isErrorMessageVisible()) writer.writeAttribute(QStringLiteral("showErrorMessage"), QStringLiteral("1")); if (!errorMessageTitle().isEmpty()) writer.writeAttribute(QStringLiteral("errorTitle"), errorMessageTitle()); if (!errorMessage().isEmpty()) writer.writeAttribute(QStringLiteral("error"), errorMessage()); if (!promptMessageTitle().isEmpty()) writer.writeAttribute(QStringLiteral("promptTitle"), promptMessageTitle()); if (!promptMessage().isEmpty()) writer.writeAttribute(QStringLiteral("prompt"), promptMessage()); QStringList sqref; foreach (CellRange range, ranges()) sqref.append(range.toString()); writer.writeAttribute(QStringLiteral("sqref"), sqref.join(QLatin1Char(' '))); if (!formula1().isEmpty()) writer.writeTextElement(QStringLiteral("formula1"), formula1()); if (!formula2().isEmpty()) writer.writeTextElement(QStringLiteral("formula2"), formula2()); writer.writeEndElement(); //dataValidation return true; }
int getNextTaskId() //searching for a task to start { int id = -1,progress; ostringstream strbuf; strbuf << "SELECT id,progress FROM tasks WHERE started=0 and running=0 ORDER BY date ASC LIMIT 1"; Connection con(use_exceptions); try { Query query = con.query(); con.connect(DATABASE, HOST, USER, PASSWORD); query << strbuf.str(); StoreQueryResult res = query.store(); cout<<strbuf.str()<<endl; if (res && res.num_rows() > 0) { mysqlpp::Row row; row = res.at(0); id = row["id"]; progress = row["progress"]; } } catch (const BadQuery& er) { // Handle any query errors cerr << "getNextTaskId - Query error: " << er.what() << endl; id = -1; } catch (const BadConversion& er) { // Handle bad conversions cerr << "getNextTaskId - Conversion error: " << er.what() << endl << "\tretrieved data size: " << er.retrieved << ", actual size: " << er.actual_size << endl; id = -1; } catch (const Exception& er) { // Catch-all for any other MySQL++ exceptions cerr << "getNextTaskId - Error: " << er.what() << endl; id = -1; } if(id>=1 && ! (progress >=1)) { //first time run, convert formula/density try{ strbuf.str(""); strbuf << "SELECT energy,formula0,formula1,formula12,rhoin0,rhoin1,rhoin12 FROM tasks WHERE id="<<id; Query query = con.query(); con.connect(DATABASE, HOST, USER, PASSWORD); query << strbuf.str(); StoreQueryResult res = query.store(); cout<<strbuf.str()<<endl; mysqlpp::Row row; row = res.at(0); string formula0(row["formula0"]), formula1(row["formula1"]), formula12(row["formula12"]); double energy=row["energy"]; double rhoin0=row["rhoin0"]; double rhoin1=row["rhoin1"]; double rhoin12=row["rhoin12"]; double rho0=0.,rho1=0.,rho12=0.; double beta0=0.,beta1=0.,beta12=0.; cout<<formula0.size()<<endl; cout<<"formula0= "<<formula0<<endl; cout<<"formula1= "<<formula1<<endl; cout<<"formula12= "<<formula12<<endl; cout<<"rhoin0= "<<rhoin0<<endl; cout<<"rhoin1= "<<rhoin1<<endl; cout<<"rhoin12= "<<rhoin12<<endl; compound cmpd0(formula0,energy,rhoin0), cmpd1(formula1,energy,rhoin1), cmpd12(formula12,energy,rhoin12); strbuf.str(""); strbuf << "UPDATE tasks SET rho0="<<cmpd0.rho_el<<",rho1="<<cmpd1.rho_el<<",rho12="<<cmpd12.rho_el<<",beta0="<<cmpd0.beta<<",beta1="<<cmpd1.beta<<",beta12="<<cmpd12.beta<<" WHERE id="<< id; //cout<<strbuf.str()<<endl; query.exec(strbuf.str()); cout<<"rho0="<<cmpd0.rho_el<<"\tbeta="<<cmpd0.beta<<endl; cout<<"rho1="<<cmpd1.rho_el<<"\tbeta="<<cmpd1.beta<<endl; cout<<"rho12(Maximum)="<<cmpd12.rho_el<<"\tbeta="<<cmpd12.beta<<endl; } catch (const BadQuery& er) { // Handle any query errors cerr << "updateDone - Query error: " << er.what() << endl; return -1; } catch (const BadConversion& er) { // Handle bad conversions cerr << "updateDone - Conversion error: " << er.what() << endl << "\tretrieved data size: " << er.retrieved << ", actual size: " << er.actual_size << endl; return -1; } catch (const Exception& er) { // Catch-all for any other MySQL++ exceptions cerr << "updateDone - Error: " << er.what() << endl; return -1; } } return id; }