Example #1
0
rc_t SettingDB::procSet_ResourceStatus(const IGetSetParam* pIGetSetParam) {

  const char_t* strName         = pIGetSetParam->GetCondition(0, NULL);

  uint32_t nLastAlive = 0;
  uint32_t nLastErrNO = 0;

  const char_t* strCurrentSize  = pIGetSetParam->GetCondition(1, &nLastAlive);
  const char_t* strFreeSize     = pIGetSetParam->GetCondition(2, &nLastErrNO);

  const char_t* strLastErrMsg   = pIGetSetParam->GetCondition(3, NULL);
  const char_t* strInfo         = pIGetSetParam->GetCondition(4, NULL);

  if (NULL == strName) { return RC_S_NULL_VALUE; }
  if (NULL == strCurrentSize) { strCurrentSize = NULL_STR; }
  if (NULL == strFreeSize) { strFreeSize = NULL_STR; }
  if (NULL == strLastErrMsg) { strLastErrMsg = NULL_STR; }
  if (NULL == strInfo) { strInfo = NULL_STR; }

  // size
  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strSetResourceStatusFMT, strName
    , strCurrentSize, strFreeSize
    , nLastAlive
    , nLastErrNO, strLastErrMsg
    , strInfo);

  return execSQL(strSQL);
}
Example #2
0
rc_t SettingDB::procSet_UpdateFile(const IGetSetParam* pIGetSetParam) {

  file_id_t file_id = IFileNode::INVALID_FILE_ID;
  const char_t* strCollector  = pIGetSetParam->GetCondition(0, &file_id);
  const char_t* strDir        = pIGetSetParam->GetCondition(1, NULL);
  const char_t* strName       = pIGetSetParam->GetCondition(2, NULL);
  const char_t* strCreateTime = pIGetSetParam->GetCondition(3, NULL);
  const char_t* strPath       = pIGetSetParam->GetCondition(4, NULL);
  const char_t* strFileSize   = pIGetSetParam->GetCondition(5, NULL);

  if (IFileNode::INVALID_FILE_ID == file_id) { return RC_S_NULL_VALUE; }
  if (NULL == strFileSize) {
    if (NULL == strCollector || NULL == strDir || NULL == strName || NULL == strCreateTime || NULL == strPath) {
      return RC_S_NULL_VALUE; }

    strFileSize = kStrZeroSize;
  }
  else {

    strCollector = NULL_STR;
    strDir = NULL_STR;
    strName = NULL_STR;
    strCreateTime = kStrSQLNULL;
    strPath = NULL_STR;
  }

  // size
  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strSetFileInfoFMT, file_id
    , strCollector, strDir, strName, strCreateTime, strPath, strFileSize);
  return execSQL(strSQL);
}
Example #3
0
rc_t SettingDB::logDB(const char_t* lv, const char_t* from
                      , const uint8_t* data, uint32_t dlen
                      , const uint8_t* content, uint32_t clen) {

  ASSERT(lv);
  ASSERT(from);
  ASSERT(data);
  ASSERT(dlen);
  //
  //char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  // please drop it
  // hex encode
  uint32_t nSQLSize = 1024 + dlen * 2 + clen * 2;
  char_t* strSQL = (char_t*)alloca(nSQLSize);
  if (NULL == strSQL) { return RC_E_NOMEM; }

  uint32_t nStrLen = SNPRINTF(strSQL, nSQLSize, nSQLSize, strLogHead, lv, from);

  MEMCPY(strSQL + nStrLen,    nSQLSize - nStrLen, data, dlen);
  ToBase16((uint8_t*)strSQL + nStrLen, dlen);
  nStrLen += dlen * 2;

  MEMCPY(strSQL + nStrLen,    nSQLSize - nStrLen, strLogMid, nStrLogMidLen);
  nStrLen += nStrLogMidLen;

  MEMCPY(strSQL + nStrLen,    nSQLSize - nStrLen, content, clen);
  ToBase16((uint8_t*)strSQL + nStrLen, clen);
  nStrLen += clen * 2;

  MEMCPY(strSQL + nStrLen,    nSQLSize - nStrLen, strLogTail, nStrLogTailLen);
  nStrLen += nStrLogTailLen;
  strSQL[nStrLen] = 0;

  return execSQL(strSQL);
}
Example #4
0
void tabTowar::updateTab(void) {
	BMessage *msg = new BMessage(MSG_NAMECHANGE);
	msg->AddString("_newtitle", data[0]->Text());
	handler->Looper()->PostMessage(msg);
	int i;
	for (i=0;i<=5;i++) {
		ceny[i]->SetText(validateDecimal(ceny[i]->Text()));
	}
	for (i=0;i<vatRows;i++) {
		vatMenuItems[i]->SetMarked((vatIds[i] == curdata->vatid));
	}
	if (curdata->vatid < 0) {
		menuvat->Superitem()->SetLabel("[wybierz]");
		brutto->SetText("???");
		return;
	}
	// usluga?
	magazyn->SetEnabled(usluga->Value() == B_CONTROL_OFF);

	BString sql;
// brać tu pod uwagę rabat/marżę - NIE: robi to but_sell
	sql = "SELECT DECROUND(0"; sql += ceny[0]->Text();
	sql += "*(100+stawka)/100.0) FROM stawka_vat WHERE id = ";
	sql << curdata->vatid;
	brutto->SetText(execSQL(sql.String()));
}
Example #5
0
void pozfaklist::updateStorage(int fakturaid = -1) {
	BString sql, nazwa, magazyn, stare;
	pozfakitem *cur = start;
	int ret;
	int nRows, nCols;
	char **result;
	bool usluga;

	while (cur!=NULL) {
		// get state
		nazwa = cur->data->data[1]; nazwa.ReplaceAll("'","''"); nazwa.Prepend("'"); nazwa.Append("'");
		sql = "SELECT usluga,magazyn FROM towar WHERE nazwa = "; sql += nazwa;
		sqlite_get_table(dbData, sql.String(), &result, &nRows, &nCols, &dbErrMsg);
		if (nRows<1) {
			// nie ma takiego w bazie, nic nie robic
		} else {
			// usluga?
			usluga = toint(result[nCols+0]);
//			printf("usluga:%i\n", usluga);
			if (!usluga) {
				// calc new magazyn state
				magazyn = result[nCols+1];
//				printf("[%s]:mag:%s, nowe:%s\n",nazwa.String(),magazyn.String(),cur->data->data[3].String());
				if (fakturaid > 0) {
					// get old state
					sql = "SELECT ilosc FROM pozycjafakt WHERE fakturaid = "; sql << fakturaid;
					sql += " AND nazwa = "; sql += nazwa;
					stare = execSQL(sql.String());
				} else {
					stare = "0";
				}
				sql = "SELECT 0"; sql += stare; sql += "+0"; sql += magazyn; sql += "-0"; sql += cur->data->data[3];
//printf("sql=[%s],magazyn=[%s]\n",sql.String(),execSQL(sql.String()));
				magazyn = execSQL(sql.String());
//				printf("nowy mag[%s]: [%s]\n",nazwa.String(), magazyn.String());
				// update magazyn state (note that nazwa() is already quoted)
				ret = sqlite_exec_printf(dbData,
					"UPDATE towar SET magazyn = %Q, magzmiana = DATE('now') WHERE nazwa = %s",
					0, 0, &dbErrMsg, magazyn.String(), nazwa.String());
//				printf("got:%i,%s\n",ret,dbErrMsg);
			}
		}
		sqlite_free_table(result);
		cur = cur->nxt;
	}
}
Example #6
0
void pozfaklist::fetch(int fakturaid) {
///printf("fetchpozfak id=%i\n", fakturaid);
	pozfakdata *data;
	int i, j;
	int nRows, nCols;
	char **result;
	BString sql, cbrutto;	

	// clear current list!
	clear();

	sql = "SELECT ";
	sql += "id, lp, ilosc";
	sql += ", nazwa, pkwiu, jm, vatid, netto, rabat";
	sql += " FROM pozycjafakt WHERE fakturaid = ";
	sql << fakturaid;
	sql += " ORDER BY lp";
//printf("sql:%s\n",sql.String());
	sqlite_get_table(dbData, sql.String(), &result, &nRows, &nCols, &dbErrMsg);
//printf ("got:%ix%i, %s\n", nRows, nCols, dbErrMsg);
	if (nRows < 1)
		return;
	// readout data
	i = nCols;
	j = 1;
	while (j <= nRows) {
		data = new pozfakdata();
		i++;							// id, unused
		data->data[0] = result[i++];	// lp, unused
		data->data[3] = result[i++];	// ilosc
		data->data[1] = result[i++];	// nazwa
		data->data[2] = result[i++];	// pkwiu
		data->data[4] = result[i++];	// jm
		data->vatid = toint(result[i++]); //vatid
		data->data[11] = result[i++];	// c.netto
		data->data[5] = result[i++];	// rabat
		addlast(data);
		// 6, 7, 8, 9, 10 - cjednost, w.netto, vat, wvat, wbrutto
		int nCols;
		char **result = calcBrutto(data->data[11].String(), data->data[5].String(), data->data[3].String(), data->vatid, &nCols);
		if (nCols<1) {
			data->data[6] = data->data[7] = data->data[9] = data->data[10] = "";
		} else {
			data->data[6] = result[nCols+0];
			data->data[7] = result[nCols+3];
			data->data[9] = result[nCols+4];
			data->data[10] = result[nCols+5];
		}
		calcBruttoFin(result);
		// vat = stawka
		sql = "SELECT nazwa FROM stawka_vat WHERE id = "; sql << data->vatid;
		data->data[8] = execSQL(sql.String());
		j++;							// next row
	}
	sqlite_free_table(result);
	setlp();							// reset lp
}
Example #7
0
const char *pozfaklist::calcSumPayment(void) {
	static BString result;
	int ret;

	execSQL("CREATE TEMPORARY TABLE sumpayment ( cbrutto )");

	pozfakitem *cur = start;

	while (cur!=NULL) {
		ret = sqlite_exec_printf(dbData,
		"INSERT INTO sumpayment (cbrutto) VALUES (%Q);",
		0, 0, &dbErrMsg, cur->data->data[10].String() );
		cur = cur->nxt;
	}
	result = execSQL("SELECT DECROUND(SUM(cbrutto)) FROM sumpayment");
	execSQL("DROP TABLE sumpayment");
	return result.String();
}
Example #8
0
rc_t SettingDB::procGet_LogTypeRule(IGetSetParam* pIGetSetParam) {

  const char_t* strLogType   = pIGetSetParam->GetCondition(0, NULL);
  if (NULL == strLogType) { return RC_S_NULL_VALUE; }

  // size
  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strGetLogTypeRuleFMT, strLogType);

  return execSQL(pIGetSetParam, strSQL);
}
Example #9
0
rc_t SettingDB::procGet_CollectRule(IGetSetParam* pIGetSetParam) {

  ASSERT(pIGetSetParam);

  const char_t* strCollector  = pIGetSetParam->GetCondition(0, NULL);
  if (NULL == strCollector) { return RC_S_NULL_VALUE; }

  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strCollectorRuleFMT, strCollector);

  return execSQL(pIGetSetParam, strSQL);
}
Example #10
0
/*
 * headbeatServer()
 *
 * This fucntion does heatbeating to given server using HEARTBEAT_SQL.
 * If could not establish connection to server or server didn't reaction,
 * emits log message and return false.
 */
bool
heartbeatServer(const char *conninfo, int r_count)
{
	if (!(execSQL(conninfo, HEARTBEAT_SQL)))
	{
		ereport(LOG,
				(errmsg("pg_keeper failed to execute pooling %d time(s)", r_count + 1)));
		return false;
	}

	return true;
}
uint NotificationManager::Notify(const QString &appName, uint replacesId, const QString &appIcon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &originalHints, int expireTimeout)
{
    uint id = replacesId != 0 ? replacesId : nextAvailableNotificationID();

    if (replacesId == 0 || notifications.contains(id)) {
        // Apply a category definition, if any, to the hints
        QVariantHash hints(originalHints);
        applyCategoryDefinition(hints);

        // Ensure the hints contain a timestamp
        addTimestamp(hints);

        if (replacesId == 0) {
            // Create a new notification
            Notification *notification = new Notification(appName, id, appIcon, summary, body, actions, hints, expireTimeout, this);
            connect(notification, SIGNAL(actionInvoked(QString)), this, SLOT(invokeAction(QString)));
            notifications.insert(id, notification);
        } else {
            // Only replace an existing notification if it really exists
            Notification *notification = notifications.value(id);
            notification->setAppName(appName);
            notification->setAppIcon(appIcon);
            notification->setSummary(summary);
            notification->setBody(body);
            notification->setActions(actions);
            notification->setHints(hints);
            notification->setExpireTimeout(expireTimeout);

            // Delete the existing notification from the database
            execSQL(QString("DELETE FROM notifications WHERE id=?"), QVariantList() << id);
            execSQL(QString("DELETE FROM actions WHERE id=?"), QVariantList() << id);
            execSQL(QString("DELETE FROM hints WHERE id=?"), QVariantList() << id);
        }

        // Add the notification, its actions and its hints to the database
        execSQL("INSERT INTO notifications VALUES (?, ?, ?, ?, ?, ?)", QVariantList() << id << appName << appIcon << summary << body << expireTimeout);
        foreach (const QString &action, actions) {
            execSQL("INSERT INTO actions VALUES (?, ?)", QVariantList() << id << action);
        }
Example #12
0
rc_t SettingDB::procGet_ModuleSetting(IGetSetParam* pIGetSetParam) {

  const char_t* strModule   = pIGetSetParam->GetCondition(0, NULL);
  const char_t* strName     = pIGetSetParam->GetCondition(1, NULL);
  if (NULL == strModule) { return RC_S_NULL_VALUE; }

  if (NULL == strName) { strName = NULL_STR; }

  // size
  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strGetModuleSettingFMT, strModule, strName);

  return execSQL(pIGetSetParam, strSQL);
}
Example #13
0
rc_t SettingDB::procGet_CollectorFile(IGetSetParam* pIGetSetParam) {

  ASSERT(pIGetSetParam);

  char_t strSQL[kMAX_SQL_LEN + 1] = {0};

  const char_t* strCollector  = pIGetSetParam->GetCondition(0, NULL);
  const char_t* strName       = pIGetSetParam->GetCondition(1, NULL);
  if (NULL == strCollector) { strCollector = NULL_STR; }
  if (NULL == strName) { strName = NULL_STR; }

  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strCollectorFileFMT, strCollector, strName);
  return execSQL(pIGetSetParam, strSQL);
}
Example #14
0
rc_t SettingDB::procSet_ModuleSetting(const IGetSetParam* pIGetSetParam) {

  const char_t* strModule   = pIGetSetParam->GetCondition(0, NULL);
  const char_t* strName     = pIGetSetParam->GetCondition(1, NULL);
  const char_t* strVal      = pIGetSetParam->GetCondition(2, NULL);
  const char_t* strData     = pIGetSetParam->GetCondition(3, NULL);
  if (NULL == strModule || NULL == strName) { return RC_S_NULL_VALUE; }

  if (NULL == strVal) { strVal = NULL_STR; }
  if (NULL == strData) { strData = NULL_STR; }

  // size
  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strSetModuleSettingFMT, strModule, strName, strVal, strData);

  return execSQL(strSQL);
}
void CAsyncTask::execSQL_( const char * format, ... )
{
    m_pszSQL[0] = '\0';

    va_list ap;
    va_start(ap, format);
    int ret = vsnprintf( m_pszSQL, MAX_QUERY_LEN, format, ap);
    va_end(ap);

    if( -1 == ret)
    {
        log_error("SQL Query error(not execute) for format '%s'.", format);
        return;
    }

    execSQL(string(m_pszSQL));
}
Example #16
0
rc_t SettingDB::procSet_CollectorStatus(const IGetSetParam* pIGetSetParam) {

  const char_t* strCollector      = pIGetSetParam->GetCondition(0, NULL);
  const char_t* strRecvFileReport = pIGetSetParam->GetCondition(1, NULL);

  uint32_t nLogonTime = 0;
  uint32_t nLastKeepAlive = 0;
  const char_t* strRecvFile       = pIGetSetParam->GetCondition(2, &nLogonTime);
  const char_t* strRecvFileReal   = pIGetSetParam->GetCondition(3, &nLastKeepAlive);
  
  if (NULL == strCollector) { return RC_S_NULL_VALUE; }

  // size
  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strSetCollectorStatusFMT, strCollector
    , strRecvFileReport, strRecvFile, strRecvFileReal, nLogonTime, nLastKeepAlive);

  return execSQL(strSQL);
}
Example #17
0
rc_t SettingDB::procGet_FileID(IGetSetParam* pIGetSetParam) {

  //
  const char_t* strCollector  = pIGetSetParam->GetCondition(0, NULL);
  const char_t* strDir        = pIGetSetParam->GetCondition(1, NULL);
  const char_t* strName       = pIGetSetParam->GetCondition(2, NULL);
  const char_t* strCreateTime = pIGetSetParam->GetCondition(3, NULL);
  if (NULL == strCollector || NULL == strDir || NULL == strName || NULL == strCreateTime) { return RC_S_NULL_VALUE; }
  /*
  char_t strDirHex[kMAX_PATH * 2 + 1] = {0};
  size_t nDirLen = (uint32_t)STRLEN(strDir);
  if (nDirLen > kMAX_PATH) { return RC_E_NOMEM; }
  ToBase16_WT((uint8_t*)strDirHex, (const uint8_t*)strDir, nDirLen);
  */
  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strGetFileIDFMT, strCollector, strDir, strName, strCreateTime);

  return execSQL(pIGetSetParam, strSQL);
}
Example #18
0
void DB::termDB() {
  if(!ntop->getPrefs()->do_dump_flows_on_db()) return;

  if(db) {
    execSQL(db, (char*)"COMMIT;");
    sqlite3_close(db);
    db = NULL;
  }

  for(int i=0; i<CONST_NUM_OPEN_DB_CACHE; i++) {
    if(contacts_cache[i].db != NULL) {
      char *zErrMsg = NULL;

      if(sqlite3_exec(contacts_cache[i].db, "COMMIT;", NULL, 0, &zErrMsg) != SQLITE_OK)
	sqlite3_free(zErrMsg);
    }
  }

  end_dump = 0;
}
Example #19
0
void DB::initDB(time_t when, const char *create_sql_string) {
  char path[MAX_PATH];

  if(!ntop->getPrefs()->do_dump_flows_on_db()) return;

  if(db != NULL) {
    if(when < end_dump)
      return;
    else
      termDB(); /* Too old: we first close it */
  }

  when -= when % dir_duration;

  strftime(path, sizeof(path), "%y/%m/%d/%H", localtime(&when));
  snprintf(db_path, sizeof(db_path), "%s/%s/flows/%s",
	   ntop->get_working_dir(), iface->get_name(), path);
  ntop->fixPath(db_path);

  if(Utils::mkdir_tree(db_path)) {
    strftime(path, sizeof(path), "%y/%m/%d/%H/%M", localtime(&when));
    snprintf(db_path, sizeof(db_path), "%s/%s/flows/%s.sqlite",
	     ntop->get_working_dir(), iface->get_name(), path);

    end_dump = when + dir_duration;
    if(sqlite3_open(db_path, &db) != 0) {
      ntop->getTrace()->traceEvent(TRACE_ERROR,
				   "[DB] Unable to open/create DB %s [%s]",
				   db_path, sqlite3_errmsg(db));
      end_dump = 0, db = NULL;
    } else {
      execSQL(db, (char*)create_sql_string);
      ntop->getTrace()->traceEvent(TRACE_INFO,
				   "[DB] Created %s", db_path);
    }
  } else
    ntop->getTrace()->traceEvent(TRACE_ERROR,
				 "[DB] Unable to create directory tree %s", db_path);
}
Example #20
0
bool DB::dumpFlow(time_t when, Flow *f) {
  const char *create_flows_db = "BEGIN; CREATE TABLE IF NOT EXISTS flows (vlan_id number, cli_ip string KEY, cli_port number, "
    "srv_ip string KEY, srv_port number, proto number, bytes number, duration number, json string);";
  char sql[4096], cli_str[64], srv_str[64], *json;

  initDB(when, create_flows_db);

  json = f->serialize();
  snprintf(sql, sizeof(sql),
	   "INSERT INTO flows VALUES (%u, '%s', %u, '%s', %u, %lu, %u, %u, '%s');",
	   f->get_vlan_id(),
	   f->get_cli_host()->get_ip()->print(cli_str, sizeof(cli_str)),
	   f->get_cli_port(),
	   f->get_srv_host()->get_ip()->print(srv_str, sizeof(srv_str)),
	   f->get_srv_port(),
	   (unsigned long)f->get_bytes(), f->get_duration(),
	   f->get_protocol(), json ? json : "");

  if(json) free(json);
  execSQL(db, sql);
  return(true);
}
Example #21
0
rc_t SettingDB::procSet_RPCInvoke(const IGetSetParam* pIGetSetParam) {

  const char_t* strID     = pIGetSetParam->GetCondition(0, NULL);
  const char_t* strErrNo  = pIGetSetParam->GetCondition(1, NULL);
  const char_t* strErrMsg = pIGetSetParam->GetCondition(2, NULL);

  uint32_t nResultLen = 0;
  const char_t* strResult = pIGetSetParam->GetCondition(3, &nResultLen);

  if (NULL == strID) { return RC_S_NULL_VALUE; }

  const uint32_t kMAX_RESULT_LEN  = 8 * 1024;
  char_t strHexResult[kMAX_RESULT_LEN + 1] = {0};
  nResultLen = nResultLen > kMAX_RESULT_LEN / 2 ? kMAX_RESULT_LEN / 2 : kMAX_RESULT_LEN;
  if (strResult && nResultLen) {
    ToBase16_WT((uint8_t *)strHexResult, (const uint8_t*)strResult, nResultLen);
  }

  char_t strSQL[kMAX_SQL_LEN + 1] = {0};
  SNPRINTF(strSQL, kMAX_SQL_LEN, kMAX_SQL_LEN, strSetRPCInvokeFMT, strID, strErrNo, strErrMsg, strHexResult);
  return execSQL(strSQL);
}
void RecipeDB::initializeData( void )
{
	kDebug();
	// Populate with data

	// Read the commands form the data file
	QString dataFilename =  KStandardDirs::locate( "appdata", "data/data-" + KGlobal::locale() ->language() + ".sql" );
	if ( dataFilename.isEmpty() ) {
		kDebug() << "NOTICE: Sample data (categories, units, etc.) for the language \"" << KGlobal::locale() ->language() << "\" is not available.  However, if you would like samples data for this language included in future releases of Krecipes, we invite you to submit your own. Contact me at [email protected] for details." ;

		dataFilename =  KStandardDirs::locate( "appdata", "data/data-en_US.sql" ); //default to English
	}

	QFile dataFile( dataFilename );
	if ( dataFile.open( QIODevice::ReadOnly ) ) {
		kDebug() << "Loading: " << dataFilename ;
		QTextStream stream( &dataFile );
		execSQL(stream);
		dataFile.close();
	}
	else
		kDebug() << "Unable to find or open sample data file (data-en_US.sql)" ;
}
Example #23
0
rc_t SettingDB::procGet_TC50LogRule(IGetSetParam* pIGetSetParam) {
  return execSQL(pIGetSetParam, strGetTc50LogRuleFMT);
}
Example #24
0
rc_t SettingDB::procGet_SystemSetting(IGetSetParam* pIGetSetParam) {
  return execSQL(pIGetSetParam, strGetSysSettingFMT);
}
Example #25
0
void pozfaklist::calcBruttoFin(char **result) {
	sqlite_free_table(result);
	execSQL("DROP TABLE calcs");
}
Example #26
0
rc_t SettingDB::procGet_RPCInvoke(IGetSetParam* pIGetSetParam) {
  return execSQL(pIGetSetParam, strGetRPCInvokeFMT);
}
Example #27
0
rc_t SettingDB::procGet_CheckSystem(IGetSetParam* pIGetSetParam) {
  return execSQL(pIGetSetParam, strGetCheckSystemFMT);
}
Example #28
0
rc_t SettingDB::procSet_CheckPoint(const IGetSetParam* pIGetSetParam) {

  UNUSED_PARAM(pIGetSetParam);
  return execSQL(strSetCheckPointFMT);
}
Example #29
0
void tabTowar::MessageReceived(BMessage *Message) {
	int32 item;
	const char *tmp;
	BString result,sql;

	switch (Message->what) {
		case DC:
			this->dirty = true;
			updateTab();
			break;
		case B_F5_KEY:
		case BUT_NEW:
			if (CommitCurdata()) {
				list->DeselectAll();
				// clear curdata
				curdata->clear();
				// refresh tabs
				curdataToTab();
				data[0]->MakeFocus();
			}
			break;
		case B_F6_KEY:
		case BUT_RESTORE:
			DoFetchCurdata();
			break;
		case B_F8_KEY:
		case BUT_DEL:
			DoDeleteCurdata();
			break;
		case BUT_SAVE:
			curdataFromTab();
			DoCommitCurdata();
			curdataToTab();
			break;
		case BUT_SELL:
//			printf("calc sell\n");
			sql = "SELECT DECROUND(0";
			sql += validateDecimal(ceny[1]->Text());
			sql += "*(1.0+";
			sql += validateDecimal(ceny[2]->Text());
			sql += "/100.0)";
			sql += "*(1.0-";
			sql += validateDecimal(ceny[3]->Text());
			sql += "/100.0))";
			result = execSQL(sql.String());
//			printf("sql:[%s]\nres[%s]\n",sql.String(),result.String());
			ceny[0]->SetText(result.String());
			updateTab();
			break;
		case BUT_MARZA:
//			printf("calc marza\n");
			sql = "SELECT (0+";
			sql += validateDecimal(ceny[1]->Text());
			sql += ")>0";
			if (toint(execSQL(sql.String()))) {
				sql = "SELECT DECROUND((0";
				sql += validateDecimal(ceny[0]->Text());
				sql += "/(0";
				sql += validateDecimal(ceny[1]->Text());
				sql += "*(1.0-";
				sql += validateDecimal(ceny[3]->Text());
				sql += "/100.0)*";
				sql += validateDecimal(ceny[4]->Text());
				sql += "*(1+";
				sql += validateDecimal(ceny[5]->Text());
				sql += "/100.0))-1)*100)";
				result = execSQL(sql.String());
//				printf("sql:[%s]\nres[%s]\n",sql.String(),result.String());
				ceny[2]->SetText(result.String());
				updateTab();
			}
			break;
		case BUT_IMPORT:
//			printf("calc import\n");
			sql = "SELECT DECROUND(0";
			sql += validateDecimal(ceny[1]->Text());
			sql += "*(1.0+";
			sql += validateDecimal(ceny[2]->Text());
			sql += "/100.0)*";
			sql += validateDecimal(ceny[4]->Text());
			sql += "*(1.0+";
			sql += validateDecimal(ceny[5]->Text());
			sql += "/100.0)*(1.0-";
			sql += validateDecimal(ceny[3]->Text());
			sql += "/100.0))";
			result = execSQL(sql.String());
//			printf("sql:[%s]\nres[%s]\n",sql.String(),result.String());
			ceny[0]->SetText(result.String());
			updateTab();
			break;
		case LIST_SEL:
		case LIST_INV:
			{	int i = list->CurrentSelection(0);
				if (i>=0) {
					i = ((tab2ListItem*)list->ItemAt(list->CurrentSelection(0)))->Id();
					if (i>=0)
						ChangedSelection(i);
				} else {
					// deselection, what to do?				
				}
				break;
			}
		case MENUJM:
			if (Message->FindString("_jm", &tmp) == B_OK) {
				data[3]->SetText(tmp);
				this->dirty = true;
			}
			break;
		case MENUVAT:
			this->dirty = true;
			if (Message->FindInt32("_vatid", &item) == B_OK) {
				curdata->vatid = item;
			}
			updateTab();
			break;
		case MSG_REQVATUP:
			RefreshVatSymbols();
			break;
		case MSG_REQTOWARLIST:
			{
				RefreshIndexList();
				BMessage *msg = new BMessage(MSG_REQTOWARUP);
				handler->Looper()->PostMessage(msg);
				break;
			}
		default:
			break;
	}
}
Example #30
0
// perform checks against supplied data
bool tabTowar::validateTab(void) {
	BAlert *error;
	BString sql, tmp;
	int i;
	// nazwa - niepusta
	if (strlen(data[0]->Text()) == 0) {
		error = new BAlert(APP_NAME, "Nie wpisano nazwy towaru!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		error->Go();
		data[0]->MakeFocus();
		return false;
	}
	// nazwa - unikalna
	tmp = data[0]->Text(); tmp.ReplaceAll("'","''");	// sql quote
	sql = "SELECT id FROM towar WHERE nazwa = '"; sql += tmp; sql += "'";
	i = toint(execSQL(sql.String()));
	if (((curdata->id < 0) && ( i!= 0 )) || ((curdata->id > 0) && (i != 0) && (i != curdata->id))) {
		error = new BAlert(APP_NAME, "Nazwa towaru nie jest unikalna!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		error->Go();
		data[0]->MakeFocus();
		return false;
	}
	// symbol - niepusty
	if (strlen(data[1]->Text()) == 0) {
		error = new BAlert(APP_NAME, "Nie wpisano symbolu towaru!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		error->Go();
		data[1]->MakeFocus();
		return false;
	}
	// symbol - unikalny
	tmp = data[1]->Text(); tmp.ReplaceAll("'","''");	// sql quote
	sql = "SELECT id FROM towar WHERE symbol = '"; sql += tmp; sql += "'";
	i = toint(execSQL(sql.String()));
	if (((curdata->id < 0) && ( i!= 0 )) || ((curdata->id > 0) && (i != 0) && (i != curdata->id))) {
		error = new BAlert(APP_NAME, "Symbol towaru nie jest unikalny!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		error->Go();
		data[1]->MakeFocus();
		return false;
	}
	// pkwiu - ostrzeżenie że pusty
	if (strlen(data[2]->Text()) == 0) {
		error = new BAlert(APP_NAME, "Nie wpisano kodu PKWiU towaru.\nKontynuować?", "Tak", "Nie", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		if (error->Go() == 1) {
			data[2]->MakeFocus();
			return false;
		}
	}
	// jm - ostrzeżenie że pusty
	if (strlen(data[3]->Text()) == 0) {
		error = new BAlert(APP_NAME, "Nie wybrano jednostki miary.\nKontynuować?", "Tak", "Nie", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		if (error->Go() == 1) {
			data[3]->MakeFocus();
			return false;
		}
	}
	// stawka vat
	if (curdata->vatid < 0) {
		error = new BAlert(APP_NAME, "Nie wybrano stawki VAT!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		error->Go();
		return false;
	}
	// cena niezerowa
	sql = "SELECT 100*0"; sql += ceny[0]->Text();
	i = toint(execSQL(sql.String()));
	if (i == 0) {
		error = new BAlert(APP_NAME, "Cena towaru jest równa zero.\nKontynuować?", "Tak", "Nie", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		if (error->Go() == 1) {
			ceny[0]->MakeFocus();
			return false;
		}
	}
	return true;
}