コード例 #1
0
ファイル: object_cache.cpp プロジェクト: cwarden/quasar
bool
ObjectCache::findAccount(Id account_id, Account& account)
{
    Account* object = findAccount(account_id);
    if (object == NULL) return false;
    account = *object;
    return true;
}
コード例 #2
0
void Account::setName(const QString& name) {
    if (findAccount() == this) {
        removeId();
    }
    m_name = name;
    insertId();
    changed();
}
コード例 #3
0
ファイル: List.c プロジェクト: Bipsy/practice
int feeList(List* list, unsigned int acc_num, int amount) {
    if (list == NULL) return ERROR;
    Node* node = findAccount(list, acc_num);
    if (node == NULL) {
        return NO_ACCOUNT;
    } else {
        return feeNode(node, amount);
    }
}
コード例 #4
0
ファイル: List.c プロジェクト: Bipsy/practice
int depositList(List* list, unsigned int acc_num, int amount) {
    if (list == NULL) return ERROR;
    Node* node = findAccount(list, acc_num);
    if (node == NULL) {
        return makeAccount(list, acc_num, amount);
    } else {
        return depositNode(node, amount);
    }
}
コード例 #5
0
ファイル: open_balances.cpp プロジェクト: cwarden/quasar
bool
OpenBalances::importAccount(QDomNodeList& nodes)
{
    Account account;
    fixed debit = 0.0;
    fixed credit = 0.0;

    for (uint i = 0; i < nodes.count(); ++i) {
	QDomNode node = nodes.item(i);
	if (node.isNull()) continue;

	QDomElement e = node.toElement();
	if (e.isNull()) continue;
	QString tag = e.tagName();
	QString text = e.text();

	if (tag == "name") {
	    if (!findAccount(text, account))
		warning("Can't find account: " + text);
	} else if (tag == "number") {
	    if (!findAccount(text, account))
		warning("Can't find account: " + text);
	} else if (tag == "debit") {
	    debit = text.toDouble();
	} else if (tag == "credit") {
	    credit = text.toDouble();
	} else {
	    warning("Unknown account tag: " + tag);
	}
    }

    if (account.id() == INVALID_ID) {
	warning("Failed account import");
	return false;
    }

    VectorRow* row = new VectorRow(_accounts->columns());
    row->setValue(0, account.id());
    if (debit != 0.0) row->setValue(1, debit);
    if (credit != 0.0) row->setValue(2, credit);
    _accounts->appendRow(row);

    return true;
}
コード例 #6
0
ファイル: bank.cpp プロジェクト: brodskyr/OOP.Labs
void Bank::addAccount (const std::string name, double balance, double limited)
{
	OverdraftAccount * _a = new OverdraftAccount(ID, name, balance, limited);
	ID++;

	if (findAccount(* _a) != -1)
		throw "This account already exists!";

	m_vOverdruftAccounts.push_back(_a);
}
コード例 #7
0
ファイル: List.c プロジェクト: Bipsy/practice
int withdrawList(List* list, unsigned int acc_num, int amount) {
    if (list == NULL) return ERROR;
    Node* node = findAccount(list, acc_num);
    if (node != NULL) {
        int res = withdrawNode(node, amount);
        return res;
    } else {
        return NO_ACCOUNT;
    }
}
コード例 #8
0
ファイル: bank.cpp プロジェクト: brodskyr/OOP.Labs
void Bank::addAccount (const std::string name, double balance)
{
	Account * _a = new Account(ID, name, balance);
	ID++;

	if (findAccount(* _a) != -1)
		throw "This account already exists!";

	m_vAccounts.push_back(_a);
}
コード例 #9
0
ファイル: bank.cpp プロジェクト: brodskyr/OOP.Labs
void Bank::leaveAccount (Account * _a)
{
	int id = findAccount (* _a);

	if (id == -1)
		throw "This account does not exist!";

	for (int i = 0; i < m_vAccounts.size(); i++)
		if (id == m_vAccounts[i]->getID())
			m_vAccounts.erase(m_vAccounts.begin() + i);

	delete _a;
}
コード例 #10
0
Account::~Account() {
    //kDebug(planDbg())<<m_name;
    if (findAccount() == this) {
        removeId(); // only remove myself (I may be just a working copy)
    }
    if (m_list)
        m_list->accountDeleted(this);

    while (!m_accountList.isEmpty())
        delete m_accountList.takeFirst();
    
    while (!m_costPlaces.isEmpty())
        delete m_costPlaces.takeFirst();
}
コード例 #11
0
ファイル: bank.cpp プロジェクト: sylxjtu/CppBigassignment
int Bank::deleteAccount(const QString &ID){
    QString sql;
    char* err;
    QByteArray ba;

    if(!findAccount(ID))
        return 1;

    sql = "DELETE FROM accounts WHERE ID=" + ID;
    ba = sql.toLatin1();
    sqlite3_exec(interface, ba.data(), InitCallback, 0, &err);
    sql = "DELETE FROM trades WHERE ID=" + ID;
    sqlite3_exec(interface, sql.toLatin1().data(), InitCallback, 0, &err);
    return 0;
}
コード例 #12
0
ファイル: bank.cpp プロジェクト: sylxjtu/CppBigassignment
int Bank::validate(const QString &ID, const QString &password){
    if(!findAccount(ID))
        return 1;
    Validate_S vs;
    QByteArray ba = password.toLatin1();
    vs.password = ba.data();
    vs.ok = 2;
    QString sql = "SELECT password FROM accounts WHERE ID=" + ID;
    QByteArray ba2 = sql.toLatin1();
    char* err;
    if(sqlite3_exec(interface, ba2.data(), ValidateCallback, &vs, &err) != SQLITE_OK){
        std::cerr << err;
        throw(err);
    }
    return vs.ok;
}
コード例 #13
0
bool BankManager::deleteAccount ()
{
	bool success = false;
	int accountNumber = 0;
	int counter = 0;

	counter = findAccount ();

	if ((counter < mNumberAccounts) && (mAccountsAvailablePtr[counter] == false)) // we found the account, so delete it
	{
		success = true;
		mAccountsAvailablePtr[counter] = true;
		cout << "Account deleted!" << endl;
	}

	return success;
}
コード例 #14
0
std::shared_ptr<Account> AccountManager::enterServer(int ingameid)
{
	AccountInfo info;
	info.ingameid = ingameid;
	info.session = clock();
	info.logname = getPlayerNameFixed(info.ingameid);

	auto r = accounts.insert(std::make_pair(ingameid, std::make_shared<Account>(info, datasource)));
	if (r.first == accounts.end())
	{
		std::cout << "[AccountManager] Warning: enterServer failed.\n";
		return findAccount(-1);
	}

	SendClientMessageToAll(0xFFFFFFFF, STR(r.first->second->getLogName() << UID(r.first->second) << "进入服务器.").c_str());

	return r.first->second;
}
コード例 #15
0
ファイル: KeyStore.cpp プロジェクト: densmirnov/SteemPressure
AccountKeys* KeyStore::addAccount(QVariantMap account) {
    if (!accountUnsupportedReason(account).isEmpty())
        return nullptr;

    AccountKeys* accountKeys(findAccount(account["name"].toString()));
    if (accountKeys == nullptr) {
        accountKeys = new AccountKeys(this);
        connect(accountKeys, &AccountKeys::updated, this, &KeyStore::persist);
        m_accountList->append(accountKeys);
    }

    accountKeys->setName(account["name"].toString());
    accountKeys->ownerKey()->fromAuthority(account["owner"].toMap());
    accountKeys->activeKey()->fromAuthority(account["active"].toMap());
    accountKeys->postingKey()->fromAuthority(account["posting"].toMap());
    accountKeys->memoKey()->fromPublicKey(account["memo_key"].toString());

    return accountKeys;
}
コード例 #16
0
ファイル: bank.cpp プロジェクト: sylxjtu/CppBigassignment
int Bank::createAccount(const QString &ID, const QString &password){
    QString sql;
    char* err;
    QByteArray ba;

    if(findAccount(ID))
        return 1;

    sql = "INSERT INTO accounts (ID, password, money) VALUES (";
    sql = sql + ID;
    sql = sql + ",";
    sql = sql + password;
    sql = sql + ",0)";
    ba = sql.toLatin1();
    if(sqlite3_exec(interface, ba.data(), InitCallback, 0, &err) != SQLITE_OK){
        std::cerr << err;
        throw(err);
    }
    else
        return 0;
}
コード例 #17
0
ファイル: historywindow.cpp プロジェクト: CyberSys/qutim
void HistoryWindow::fillContactComboBox(int index)
{
	if (ui.accountComboBox->count() == 0)
		return;
	auto accountInfo = ui.accountComboBox->itemData(index).value<History::AccountInfo>();
	ui.fromComboBox->clear();

	history()->contacts(accountInfo).connect(this, [this, accountInfo] (const QVector<History::ContactInfo> &contacts) {
		int index = ui.accountComboBox->currentIndex();
		auto currentAccountInfo = ui.accountComboBox->itemData(index).value<History::AccountInfo>();
		if (!(accountInfo == currentAccountInfo))
			return;

		disconnect(m_contactConnection);

		Account *account = findAccount(accountInfo);

		for (const History::ContactInfo &info : contacts) {
			QString name = info.contact;
			if (ChatUnit *unit = account ? account->getUnit(info.contact) : nullptr) {
				if (unit->title() != name)
					name += QStringLiteral(" - ") + unit->title();
			}

			ui.fromComboBox->addItem(name, QVariant::fromValue(info));
		}

		ui.fromComboBox->model()->sort(0);

		m_contactConnection = connect(ui.fromComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
									  this, &HistoryWindow::fillDateTreeWidget);
		int contactIndex = ui.fromComboBox->findData(QVariant::fromValue(m_unitInfo));
		if (!contactIndex)
			fillDateTreeWidget(0);
		else
			ui.fromComboBox->setCurrentIndex(contactIndex);
	});
}
コード例 #18
0
ファイル: historywindow.cpp プロジェクト: CyberSys/qutim
void HistoryWindow::fillAccountComboBox()
{
	history()->accounts().connect(this, [this] (const QVector<History::AccountInfo> &accounts) {
		for (const History::AccountInfo &info : accounts) {
			QString name = info.account;
			Icon icon(QLatin1String("im-") + info.protocol);

			if (Account *account = findAccount(info)) {
				if (!account->name().isEmpty())
				name += QStringLiteral(" - ") + account->name();
			}
			ui.accountComboBox->addItem(icon, name, QVariant::fromValue(info));
		}

		connect(ui.accountComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
				this, &HistoryWindow::fillContactComboBox);
		int accountIndex = ui.accountComboBox->findData(QVariant::fromValue<History::AccountInfo>(m_unitInfo));
		if (accountIndex < 0)
			fillContactComboBox(0);
		else
			ui.accountComboBox->setCurrentIndex(accountIndex);
	});
}
コード例 #19
0
bool BankManager::updateAccount ()
{
	bool success = false;
	string name = "", dateCreated = "";
	double balance = 0.0, deposit = 0.0;
	int accountNumber = 0, counter = 0, option = 0;

	counter = findAccount ();

	if ((counter < mNumberAccounts) && (mAccountsAvailablePtr[counter] == false)) // we found the account, so delete it
	{
		success = true;

		cout << "1. Update Name" << endl;
		cout << "2. Withdraw Money" << endl;
		cout << "3. Deposit Money" << endl;

		cin >> option;

		switch (option)
		{
			case 1: cout << "Enter name: ";
					cin >> name;
					mAccountsPtr[counter].setName (name);
				    break;
			case 2: cout << "Enter amount to withdraw: ";
					cin >> balance;
					mAccountsPtr[counter].debit (balance);
				    break;
			case 3: cout << "Enter amount to deposit: ";
					cin >> deposit;
					mAccountsPtr[counter].credit (deposit);
				    break;
			default: cout << "ERROR: Invalid option!" << endl;
				     break;
		}
	}
コード例 #20
0
ファイル: object_cache.cpp プロジェクト: cwarden/quasar
DataObject*
ObjectCache::find(Id object_id, bool cacheOnly)
{
    if (object_id == INVALID_ID)
	return NULL;

    if (_objects.find(object_id) != _objects.end())
	return _objects[object_id];

    if (cacheOnly)
	return NULL;

    DataObject object;
    if (!_db->lookup(object_id, object))
	return NULL;

    switch (object.dataType()) {
    case DataObject::ACCOUNT:		return findAccount(object_id);
    case DataObject::ADJUST_REASON:	return findAdjustReason(object_id);
    case DataObject::CARD_ADJUST:	return findCardAdjust(object_id);
    case DataObject::CHARGE:		return findCharge(object_id);
    case DataObject::CHEQUE:		return findCheque(object_id);
    case DataObject::CLAIM:		return findReceive(object_id);
    case DataObject::COMPANY:		return findCompany(object_id);
    case DataObject::COUNT:		return findCount(object_id);
    case DataObject::CUSTOMER:		return findCustomer(object_id);
    case DataObject::CUST_TYPE:		return findCustomerType(object_id);
    case DataObject::DEPT:		return findDept(object_id);
    case DataObject::DISCOUNT:		return findDiscount(object_id);
    case DataObject::EMPLOYEE:		return findEmployee(object_id);
    case DataObject::EXPENSE:		return findExpense(object_id);
    case DataObject::EXTRA:		return findExtra(object_id);
    case DataObject::GENERAL:		return findGeneral(object_id);
    case DataObject::GROUP:		return findGroup(object_id);
    case DataObject::INVOICE:		return findInvoice(object_id);
    case DataObject::ITEM:		return findItem(object_id);
    case DataObject::ITEM_ADJUST:	return findItemAdjust(object_id);
    case DataObject::ITEM_PRICE:	return findItemPrice(object_id);
    case DataObject::LABEL_BATCH:	return findLabelBatch(object_id);
    case DataObject::LOCATION:		return findLocation(object_id);
    case DataObject::NOSALE:		return findNosale(object_id);
    case DataObject::ORDER:		return findOrder(object_id);
    case DataObject::PO_TEMPLATE:	return findOrderTemplate(object_id);
    case DataObject::PAT_GROUP:		return findPatGroup(object_id);
    case DataObject::PAT_WS:		return findPatWorksheet(object_id);
    case DataObject::PAYOUT:		return findPayout(object_id);
    case DataObject::PERSONAL:		return findPersonal(object_id);
    case DataObject::PLU:		assert("Invalid data type: PLU");
    case DataObject::PRICE_BATCH:	return findPriceBatch(object_id);
    case DataObject::PROMO_BATCH:	return findPromoBatch(object_id);
    case DataObject::QUOTE:		return findQuote(object_id);
    case DataObject::RECEIPT:		return findReceipt(object_id);
    case DataObject::RECEIVE:		return findReceive(object_id);
    case DataObject::RECONCILE:		return findReconcile(object_id);
    case DataObject::RECURRING:		return findRecurring(object_id);
    case DataObject::REPORT:		assert("Invalid data type: REPORT");
    case DataObject::RETURN:		return findInvoice(object_id);
    case DataObject::SECURITY_TYPE:	return findSecurityType(object_id);
    case DataObject::SHIFT:		return findShift(object_id);
    case DataObject::SLIP:		return findSlip(object_id);
    case DataObject::STATION:		return findStation(object_id);
    case DataObject::STORE:		return findStore(object_id);
    case DataObject::SUBDEPT:		return findSubdept(object_id);
    case DataObject::TAX:		return findTax(object_id);
    case DataObject::TENDER:		return findTender(object_id);
    case DataObject::TEND_COUNT:	return findTenderCount(object_id);
    case DataObject::TEND_ADJUST:	return findTenderAdjust(object_id);
    case DataObject::TERM:		return findTerm(object_id);
    case DataObject::TODO:		return findTodo(object_id);
    case DataObject::USER:		return findUser(object_id);
    case DataObject::VENDOR:		return findVendor(object_id);
    case DataObject::WITHDRAW:		return findWithdraw(object_id);
    }

    qWarning("Unknown object type: " + object.dataTypeName());
    return NULL;
}
コード例 #21
0
ファイル: historywindow.cpp プロジェクト: CyberSys/qutim
void HistoryWindow::on_dateTreeWidget_currentItemChanged(QTreeWidgetItem *dayItem, QTreeWidgetItem *)
{
	QTreeWidgetItem *monthItem = dayItem ? dayItem->parent() : nullptr;
	if (!dayItem || !monthItem)
		return;

	if (dayItem->data(0, Qt::UserRole).type() != QVariant::Date)
		return;
	if (monthItem->data(0, Qt::UserRole).type() != QVariant::Date)
		return;

	auto contactIndex = ui.fromComboBox->currentIndex();
	auto contactInfo = ui.fromComboBox->itemData(contactIndex).value<History::ContactInfo>();
	auto date = dayItem->data(0, Qt::UserRole).toDate();
	QDateTime from(date, QTime(0, 0));
	QDateTime to(date, QTime(23, 59, 59, 999));
	int count = std::numeric_limits<int>::max();

	history()->read(contactInfo, from, to, count).connect(this, [this, contactInfo, date] (const MessageList &messages) {
		int contactIndex = ui.fromComboBox->currentIndex();
		auto currentContactInfo = ui.fromComboBox->itemData(contactIndex).value<History::ContactInfo>();
		if (!(currentContactInfo == contactInfo))
			return;

		QTextDocument *doc = ui.historyLog->document();
		doc->setParent(0);
		ui.historyLog->setDocument(0);
		doc->clear();
		QTextCursor cursor = QTextCursor(doc);
		QTextCharFormat defaultFont = cursor.charFormat();
		QTextCharFormat serviceFont = cursor.charFormat();
		serviceFont.setForeground(Qt::darkGreen);
		serviceFont.setFontWeight(QFont::Bold);
		QTextCharFormat incomingFont = cursor.charFormat();
		incomingFont.setForeground(Qt::red);
		incomingFont.setFontWeight(QFont::Bold);
		QTextCharFormat outgoingFont = cursor.charFormat();
		outgoingFont.setForeground(Qt::blue);
		outgoingFont.setFontWeight(QFont::Bold);
		const QString serviceMessageTitle = tr("Service message");
		const QString resultString = QStringLiteral("<span style='background: #ffff00'>\\1</span>");
		cursor.beginEditBlock();

		Account *account = findAccount(contactInfo);
		ChatUnit *unit = findContact(contactInfo);

		QString accountNickname = account ? account->name() : contactInfo.account;
		QString fromNickname = unit ? unit->title() : contactInfo.contact;
		int in_count = 0;
		int out_count = 0;

		for (const Message &message : messages) {
			bool service = message.property("service", false);
			QDateTime time = message.time();
			bool incoming = message.isIncoming();
			QString historyMessage = message.html();
			QString sender = message.property("senderName", incoming ? fromNickname : accountNickname);

			incoming ? in_count++ : out_count++;
			if (service) {
				cursor.setCharFormat(serviceFont);
				cursor.insertText(serviceMessageTitle);
			} else {
				cursor.setCharFormat(incoming ? incomingFont : outgoingFont);
				cursor.insertText(sender);
			}
			cursor.insertText(QStringLiteral(" (")
							  % time.toString(QStringLiteral("dd.MM.yyyy hh:mm:ss"))
							  % QStringLiteral(")"));
			cursor.setCharFormat(defaultFont);
			cursor.insertText(QStringLiteral("\n"));
			if (m_search_word.isEmpty()) {
				cursor.insertHtml(historyMessage);
				cursor.insertText(QStringLiteral("\n"));
			} else {
				cursor.insertHtml(historyMessage.replace(m_search, resultString));
				cursor.insertText(QStringLiteral("\n"));
			}
		}
		cursor.endEditBlock();
		doc->setParent(ui.historyLog);
		ui.historyLog->setDocument(doc);
		if (m_search_word.isEmpty())
			ui.historyLog->moveCursor(QTextCursor::End);
		else
			ui.historyLog->find(m_search_word);
		ui.historyLog->verticalScrollBar()->setValue(ui.historyLog->verticalScrollBar()->maximum());

		ui.label_in->setText(tr("In: %L1").arg(in_count));
		ui.label_out->setText(tr("Out: %L1").arg(out_count));
		ui.label_all->setText(tr("All: %L1").arg(in_count + out_count));
	});
}
コード例 #22
0
ファイル: historywindow.cpp プロジェクト: CyberSys/qutim
static inline ChatUnit *findContact(const History::ContactInfo &info)
{
	if (Account *account = findAccount(info))
		return account->getUnit(info.contact);
	return nullptr;
}
コード例 #23
0
ファイル: server.c プロジェクト: dominguerilla/bank-system
/**
* Processes the input from the client, given the command, argument, and state
* of the client. 
*
* The 'state' is simply whether or not the client is in a session.
* -1: Client wishes to exit
*  0: Client is connected, but is not in an account session
*  1: Client is connected and is in an account session
*
*/
int process_input(char *buffer, int state, client_t **client){
	
	int i;
	char *parsed = NULL;
	int len = strlen(buffer);
	for(i = 0; i < len; i++){
		if(buffer[i] == '\n'){
			if(i == 0){
				/*If it's just a newline*/
				break;
			}
			parsed = malloc(sizeof(char)*(i+1));
			strncpy(parsed, buffer, i);
			parsed[i] = '\0';
			break;
		}
	}
	if(parsed == NULL){
		printf("Error parsing buffer.\n");
		return state;
	}

	printf("CLIENT> %s\n", parsed);
	

	Node **list = &((*client)->head);

	char *command, *arg;
	char name[MAX_ARG_LEN];
	command = strtok(parsed, " ");
	arg = strtok(NULL, " ");
	memset(name, '\0', sizeof(name));
	if(arg != NULL){
		strcpy(name, arg);
	}


	if(strcmp(parsed, "exit") == 0){
		printf("Client exits!\n");
		if(state == 1){
			printf("Finishing customer session.\n");
			Node *node = findAccount((*client)->current_acc, *list);
			Account *acc = node->account;
			finishAccount(&acc, state);
			free((*client)->current_acc);
		}
		update_client_count(-1);
		free(parsed);
		return -1;
	}else if(strcmp(command, "open") == 0){
		if(state == 1){
			printf("Still in customer session!\n");
			free(parsed);
			return 1;
		}
		int open = openAccount(list, name);
		char *msg = "Account opened for ";
		printf("%s%s.\n", msg, name);
		if(open == -1){
			printf("Error opening account!\n");
			free(parsed);
			return 0;
		}
		free(parsed);
		return 0;
	}else if(strcmp(command, "start") == 0){
		if(state == 0){
			Node *ptr = findAccount(name, *list);
			if(ptr == NULL){
				free(parsed);
				return 0;
			}
			Account *acc = ptr->account;
			int n = startAccount(&acc, list);
			if(n == 0){
				printf("Account is still in use.\n");
				free(parsed);
				return 0;
			}
			char *current = malloc(strlen(name)*sizeof(char));
			strcpy(current, name);
			(*client)->current_acc = current;
			free(parsed);
			return 1;
		}else{
			printf("Still in session!\n");
			free(parsed);
			return 1;
		}
	}else if(strcmp(command, "credit") == 0){
		if(state == 1){
			float new = updateAccount((*client)->current_acc, list, atof(arg));
			printf("Balance of %s is now %.2f.\n", (*client)->current_acc, new);
			free(parsed);
			return 1;
		}else{