예제 #1
0
void ServerController::addMember(sf::Packet &packet, sf::TcpSocket &client, Account::AccessLevel level)
{
	sf::Packet response;
	std::string username, conference, targetUser;
	packet >> username >> conference >> targetUser;
	
	bool success = false;
	
	int findIndex = checkAccount(username);
	int targetIndex = checkAccount(targetUser);
	int confIndex = checkConference(conference);
	if (findIndex == -1 || targetIndex == -1 || confIndex == -1)
	{
		success = false;
		response << success;
		client.send(response);
		return;
	}
	// add access to the conference in the target user's accessmap
	data.accounts[targetIndex].addAccess(conference, level);
	if (level == Account::Access_Reviewer)
	{
		data.conferences[confIndex].addReviewer(targetUser);
	}
	// add welcome notification to the user
	addNotification(targetUser, "Welcome to " + conference + "!");
	success = true;
	response << success;
	client.send(response);
	data.saveAccounts();
	data.saveConferences();
}
예제 #2
0
void ServerController::getAccountName(sf::Packet &packet, sf::TcpSocket &client)
{
	sf::Packet response;
	std::string username, target, first, last;
	bool exists = false;
	packet >> username >> target;
	std::cout << "Attempting to find full name for User " << target << std::endl;
	// authenticate request
	if (checkAccount(username) == -1)
	{
		return;
	}
	int targetIndex = checkAccount(target);
	if (targetIndex != -1)
	{
		std::cout << "User does exist" << std::endl;
		first = data.accounts[targetIndex].getFirstName();
		last = data.accounts[targetIndex].getLastName();
		exists = true;
		response << exists << first << last;
		client.send(response);
		return;
	}
	std::cout << "User does not exist" << std::endl;
	response << exists;
	client.send(response);
}
예제 #3
0
void ServerController::getLimit(sf::Packet &packet, sf::TcpSocket &client, const std::string &mode)
{
	sf::Packet response;
	std::string username, conference;
	sf::Int16 limit;
	packet >> username >> conference >> limit;
	// authenticate request
	int accIndex = checkAccount(username);
	if (accIndex == -1)
	{
		return;
	}
	// authenticate conference
	int confIndex = checkConference(conference);
	if (confIndex == -1)
	{
		return;
	}
	if (mode == "ALLOCATED")
	{
		limit = data.conferences[confIndex].getMaxReviewedPapers();
	}
	else if (mode == "PAPERREV")
	{
		limit = data.conferences[confIndex].getMaxPaperReviewers();
	}
	response << limit;
	client.send(response);
}
예제 #4
0
void ServerController::getReview(sf::Packet &packet, sf::TcpSocket &client)
{
	sf::Packet response;
	std::string username, conf, id;
	Review aReview;
	bool found = false;
	packet >> username >> conf >> id;
	// authenticate request
	if (checkAccount(username) == -1)
	{
		return;
	}
	// authenticate conference
	if (checkConference(conf) == -1)
	{
		return;
	}
	// find review with id
	std::vector<Review>::iterator it;
	for (it = data.reviews.begin(); it != data.reviews.end(); ++it)
	{
		if (it->getReviewID() == id)
		{
			aReview = *it;
			found = true;
			break;
		}
	}
	response << found;
	if (found)
	{
		response << aReview;
	}
	client.send(response);
}
예제 #5
0
void ServerController::checkReviewed(sf::Packet &packet, sf::TcpSocket &client)
{
	sf::Packet response;
	std::string user, conference, paper, first, last;
	packet >> user >> conference >> paper;
	
	// authenticate request
	int	findIndex = checkAccount(user);
	if (findIndex != -1)
	{
		first = data.accounts[findIndex].getFirstName();
		last = data.accounts[findIndex].getLastName();
	}
	
	bool hasReviewed = false;
	for (int i = 0; i < (int)data.reviews.size(); ++i)
	{
		if (data.reviews[i].getTitle() == paper && data.reviews[i].getConference() == conference)
		{
			if (data.reviews[i].getPCMember() == (first + " " + last))
			{
				hasReviewed = true;
				break;
			}
		}
	}
	response << hasReviewed;
	client.send(response);
}
예제 #6
0
void ServerController::assignReviewer(sf::Packet &packet, sf::TcpSocket &client)
{
	std::string conference, paperTitle, targetUsername;
	std::string firstname, lastname;
	
	packet >> conference >> paperTitle >> targetUsername;
	int findIndex = checkAccount(targetUsername);
	firstname = data.accounts[findIndex].getFirstName();
	lastname = data.accounts[findIndex].getLastName();
	int confIndex = checkConference(conference);
	int maxReviewers = data.conferences[confIndex].getMaxPaperReviewers();
	
	for (int i = 0; i < (int)data.submissions.size(); i++)
	{
		if (data.submissions[i].getConference() == conference);
		{
			if (data.submissions[i].getTitle() == paperTitle)
			{
				if (!data.submissions[i].isAuthorIncluded(firstname, lastname)
					&& !data.submissions[i].hasReviewer(targetUsername))
				{
					data.submissions[i].addReviewer(targetUsername);
					data.accounts[findIndex].incrementAllocated(conference, maxReviewers);
				}
			}
		}
	}	
	data.saveAccounts();
	data.saveSubmissions();			
}
예제 #7
0
void ServerController::loginAccount(sf::Packet &packet, sf::TcpSocket &client){

	sf::Packet validate;
	std::string username, password;
	
	bool valid = false;
	
	packet >> username >> password;
	int findIndex = checkAccount(username,password);
	
	if (findIndex != -1) 
	{
		valid = true;
	}
	
	if (valid)
	{
		// set the user as logged in
		data.accounts[findIndex].startSession();
		data.addLog(username + " has logged in.");
		data.saveAccounts();
	}
	validate << valid;
	client.send(validate);
}
예제 #8
0
void ServerController::paperSubmission(sf::Packet &packet, sf::TcpSocket &client)
{
	sf::Packet response;
	Submission sub;
	bool exists = false;
	std::string username, conference, title;
	
	packet >> username;
	int findIndex = checkAccount(username);		//get Account index
	if (findIndex == -1)
	{
		return;		// ignore request if user is not found
	}
	packet >> sub;
	conference = sub.getConference();
	title = sub.getTitle();
	int confIndex = checkConference(conference);
	if (confIndex == -1)
	{
		return; 	// ignore request if conference is not found
	}
	if (data.accounts[findIndex].getAccess(conference) < Account::Access_Author)
	{
		return;		// ignore request if user is not at least an author of that conference
	}
	
	// check conference is in submission phase
	if (data.conferences[confIndex].getCurrentPhase() != "Submission")
	{
		return;		// ignore request if conference is not accepting submissions
	}
	
	// check that the paper does not already exist
	if (checkSubmission(title, conference) == -1)
	{
		// set the papers university to the submitting author
		sub.setUniversity(data.accounts[findIndex].getUniversity());
		// add the submitting author as an author
		std::string firstname = data.accounts[findIndex].getFirstName();
		std::string lastname = data.accounts[findIndex].getLastName();
		
		sub.addAuthor(firstname, lastname);
		data.submissions.push_back(sub);
		data.saveSubmissions();
		
		data.addLog("Paper was submitted: " + title + " by " + username + " for conference " + conference);
		addNotification(username, "You submitted a paper '" + title + "' to " + conference);
		notifyConference(conference, 
			username + " submitted a paper '" + title + "' to " + conference, 
				Account::Access_Chairman);
	}
	else
	{
		exists = true;
	}
	response << exists;
	client.send(response);
}
/**
	存款,存款前需要判断账号及密码是否正确
*/
void save() {
	float m;
	if(checkAccount()) { // 如果账号检测为真
		printf("请输入存款金额:\n");
		scanf("%f", &m);
		money += m; //更新余额
		printAccountInfo();
	}
}
예제 #10
0
void ServerController::changePassword(sf::Packet &packet, sf::TcpSocket &client)
{
	std::string username, password;
	packet >> username >> password;
	
	int findIndex = checkAccount(username);
	
	data.accounts[findIndex].setPassword(password);
	data.saveAccounts();
}
예제 #11
0
/**
	取款,取款前需要判断账号及密码是否正确,余额需要变更
*/
void getMoney() {
	float m;
	if(checkAccount()) {
		printf("请输入取款金额:\n");
		scanf("%f", &m);
		if(m > money) {
			printf("余额不足\n");
		} else {
			money -= m; //更新余额
			printf("成功取出%f元\n", m);
			printAccountInfo();
		}
	}
}
예제 #12
0
void ServerController::getReviewList(sf::Packet &packet, sf::TcpSocket &client, const bool allReviewers)
{
	sf::Packet response;
	std::string conference, paperTitle, user, first, last;
	packet >> conference >> paperTitle;
	int findIndex = -1;
	if (!allReviewers)
	{
		packet >> user;
		findIndex = checkAccount(user);
		if (findIndex != -1)
		{
			first = data.accounts[findIndex].getFirstName();
			last = data.accounts[findIndex].getLastName();
		}
	}
예제 #13
0
//---------------------------------------------------------------------
void AccountManager::processAccountTest(NetPack* pPack)
{
	
	UserAccount* puser=reinterpret_cast<UserAccount*>(pPack->getData());
	RespondAccount respond;
	memset(&respond,0,sizeof(RespondAccount));
	strcpy(respond.m_userip,puser->m_ip);

	if(checkAccount(puser->m_account,puser->m_password,respond.m_accountID))
	{
     	respond.m_login=1;
	}else
	{
       	respond.m_login=0;
	}
	NetWorkServer::getSingleton().send( GM_ACCOUNT_RESPOND,respond,pPack->getAddress());

	return ;
}
예제 #14
0
bool ServerController::registerAccount(sf::Packet &packet, sf::TcpSocket &client){
	sf::Packet existsPacket;
	std::string username,password,email,university, firstname, lastname;
	std::vector<std::string> keywords;
	int keywordSize = 0;

	packet >> username >> password >> firstname >> lastname >> email >> university >> keywordSize;
	std::string tmpkeyword;
	for (int i = 0; i < keywordSize; ++i)
	{
		packet >> tmpkeyword;
		keywords.push_back(tmpkeyword);
	}
	
	bool exists = false;
	int index = checkAccount(username);
	if (index == -1)
	{
		data.addLog("New user registered! Welcome " + username);
		Account tmp;
		tmp.setUsername(username);
		tmp.setPassword(password);
		tmp.setFirstName(firstname);
		tmp.setLastName(lastname);
		tmp.setEmail(email);
		tmp.setUniversity(university);
		for (int i = 0; i < keywordSize; ++i)
		{
			tmp.addKeyword(keywords[i]);
		}
		// registered users start logged in
		tmp.startSession();	
		data.accounts.push_back(tmp);
		data.saveAccounts();
	}
	else
	{
		exists = true;
	}
	existsPacket << exists;
	client.send(existsPacket);
}
예제 #15
0
void ServerController::changeLimit(sf::Packet &packet, sf::TcpSocket &client, const std::string &mode)
{
	std::string username, conference;
	sf::Int16 val;
	packet >> username >> conference >> val;
	int setVal = val;
	// authenticate request
	int accIndex = checkAccount(username);
	if (accIndex == -1)
	{
		return;
	}
	// authenticate conference
	int confIndex = checkConference(conference);
	if (confIndex == -1)
	{
		return;
	}
	// authenticate privileges
	if (data.accounts[accIndex].getAccess(conference) < Account::Access_Chairman)
	{
		return;
	}
	if (val > 0 && val < MAXIMUM_USEABLEINT_LIMIT)
	{
		if (mode == "ALLOCATED")
		{
			data.conferences[confIndex].setMaxReviewedPapers(setVal);
			notifyConference(conference, 
				username + " has changed the max papers per reviewer limit for " + conference, 
					Account::Access_Chairman);
		}
		else if (mode == "PAPERREV")
		{
			data.conferences[confIndex].setMaxPaperReviewers(setVal);
			notifyConference(conference, 
				username + " has changed the max reviewers per paper limit for " + conference, 
					Account::Access_Chairman);
		}
		data.saveConferences();
	}
}
예제 #16
0
void ServerController::getFreeReviewers(sf::Packet &packet, sf::TcpSocket &client)
{
	sf::Packet response;
	std::string conference;
	std::vector<std::string> reviewerList;
	std::vector<std::string> freeList;
	
	packet >> conference;
	
	int confIndex = checkConference(conference);
	if (confIndex == -1)
	{
		return;
	}
	data.conferences[confIndex].getReviewers(reviewerList);
	int maxReviewers = data.conferences[confIndex].getMaxPaperReviewers();
	
	std::cout << "Getting a list of free reviewers for conference " << conference << std::endl;
	for (int i = 0; i < (int)reviewerList.size(); i++)
	{
		int findIndex = checkAccount(reviewerList[i]);
		if (findIndex != -1)
		{
			std::cout << "Displaying Reviewers: " << reviewerList[i] << std::endl;
			if (data.accounts[findIndex].checkAllocation(conference, maxReviewers))
			{
				std::cout << "Pushing" << std::endl;
				freeList.push_back(reviewerList[i]);
			}
		}
	}
	
	response << (int)freeList.size();
	for (int i = 0; i < (int)freeList.size(); i++)
	{
		response << freeList[i];
	}
	
	client.send(response);
} 
예제 #17
0
void ServerController::getFinalReview(sf::Packet &packet, sf::TcpSocket &client)
{
	sf::Packet response;
	std::string username, conference, paper;
	std::string finalRev;
	bool exists = false;
	packet >> username >> conference >> paper;
	// authenticate request
	int accIndex = checkAccount(username);
	if (accIndex == -1)
	{
		return;
	}
	// authenticate conference
	int confIndex = checkConference(conference);
	if (confIndex == -1)
	{
		return;
	}
	if (data.accounts[accIndex].getAccess(conference))
	{
		for (int i = 0; i < (int)data.reviews.size(); ++i)
		{
			if (data.reviews[i].getConference() == conference &&
				data.reviews[i].getTitle() == paper &&
					data.reviews[i].getFinal())
			{
				finalRev = data.reviews[i].getReviewID();
				exists = true;
				break;
			}
		}
		response << exists << finalRev;
	}
	else
	{
		response << exists;
	}
	client.send(response);
}
예제 #18
0
/**
	转账,取款前需要判断账号及密码是否正确,余额需要变更
*/
void transfer() {
	int acc1, acc2;
	float m;
	if(checkAccount()) {
		printf("请输入对方账号:\n");
		scanf("%d", &acc1);
		printf("请确认对方账号:\n");
		scanf("%d", &acc2);
		if(acc1 == acc2) {
			printf("请输入转账金额(此笔转账需要5元手续费):\n");
			scanf("%f", &m);
			if(m > money) {
				printf("余额不足\n");
			} else {
				money -= (m + 5); // 更新余额
				printf("转账成功\n");
				printAccountInfo();
			}
		} else {
			printf("两次输入的账号不一致\n");
		}
	}
}
예제 #19
0
void ServerController::decidePaper(sf::Packet &packet, sf::TcpSocket &client, const bool approved)
{
	std::string username, conference, paper;
	packet >> username >> conference >> paper;
	// authenticate request
	int accIndex = checkAccount(username);
	if (accIndex == -1)
	{
		return;
	}
	// authenticate conference
	int confIndex = checkConference(conference);
	if (confIndex == -1)
	{
		return;
	}
	// authenticate privileges
	if (data.accounts[accIndex].getAccess(conference) < Account::Access_Chairman)
	{
		return;
	}
	// authenticate paper
	int paperIndex = checkSubmission(paper, conference);
	if (paperIndex == -1)
	{
		return;		// ignore request if submission does not exist
	}
	if (approved)
	{
		data.submissions[paperIndex].accept();
	}
	else
	{
		data.submissions[paperIndex].reject();
	}
}
예제 #20
0
파일: gltx_db.cpp 프로젝트: cwarden/quasar
// Create a Gltx
bool
QuasarDB::create(Gltx& gltx)
{
    // Can't create transaction before close date
    Company company;
    lookup(company);
    QDate startOfYear = company.startOfYear();

    if (!company.closeDate().isNull()) {
	if (gltx.postDate() <= company.closeDate())
	    return error("Can't create transaction before close date");
    }
    if (!startOfYear.isNull() && company.lastYearClosed()) {
	if (gltx.postDate() < startOfYear)
	    return error("Can't post to last year");
    }

    // Verify station/employee are specified
    if (company.shiftMethod() == Company::BY_STATION) {
	if (gltx.stationId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("A station is required");
	    default:
		break;
	    }
	}
    }
    if (company.shiftMethod() == Company::BY_EMPLOYEE) {
	if (gltx.employeeId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("An employee is required");
	    default:
		break;
	    }
	}
    }

    // Check shift is not posted if set
    if (gltx.shiftId() != INVALID_ID) {
	Shift shift;
	lookup(gltx.shiftId(), shift);
	if (shift.shiftId() != INVALID_ID)
	    return error("Can't post to a posted shift");
    }

    // Check that change data exists and create if needed
    checkAccount(gltx);
    checkCard(gltx);
    checkItem(gltx);

    // Auto allocate transaction number
    if (gltx.number().stripWhiteSpace() == "#") {
	fixed number = uniqueTxNumber(gltx.dataType());
	gltx.setNumber(number.toString());
    }

    QString cmd = insertCmd("gltx", "gltx_id", "number,reference_str,"
			    "post_date,post_time,memo,station_id,"
			    "employee_id,card_id,store_id,shift_id,"
			    "link_id,printed,paid,amount,data_type");
    Stmt stmt(_connection, cmd);

    insertData(gltx, stmt);
    stmtSetString(stmt, gltx.number());
    stmtSetString(stmt, gltx.reference());
    stmtSetDate(stmt, gltx.postDate());
    stmtSetTime(stmt, gltx.postTime());
    stmtSetString(stmt, gltx.memo());
    stmtSetId(stmt, gltx.stationId());
    stmtSetId(stmt, gltx.employeeId());
    stmtSetId(stmt, gltx.cardId());
    stmtSetId(stmt, gltx.storeId());
    stmtSetId(stmt, gltx.shiftId());
    stmtSetId(stmt, gltx.linkId());
    stmtSetBool(stmt, gltx.printed());
    stmtSetBool(stmt, false);
    stmtSetFixed(stmt, gltx.total());
    stmtSetInt(stmt, gltx.dataType());
    execute(stmt);

    sqlCreateLines(gltx);

    if (!startOfYear.isNull() && gltx.postDate() < startOfYear &&
	    gltx.isActive()) {
	Store store;
	if (!lookup(gltx.storeId(), store)) return false;

	Gltx orig, transfer;
	if (!lookup(store.yearEndTransferId(), transfer)) return false;
	orig = transfer;

	fixed total = 0.0;
	for (unsigned int i = 0; i < gltx.accounts().size(); ++i) {
	    Account account;
	    lookup(gltx.accounts()[i].account_id, account);
	    if (account.type() < Account::Income) continue;

	    AccountLine line;
	    line.account_id = account.id();
	    line.amount = -gltx.accounts()[i].amount;
	    transfer.accounts().push_back(line);

	    total += line.amount;
	}

	if (total != 0.0) {
	    AccountLine line;
	    line.account_id = company.retainedEarnings();
	    line.amount = -total;
	    transfer.accounts().push_back(line);
	}

	if (transfer != orig)
	    if (!update(orig, transfer))
		return false;
    }

    return true;
}
예제 #21
0
파일: gltx_db.cpp 프로젝트: cwarden/quasar
// Update a Gltx
bool
QuasarDB::update(const Gltx& orig, Gltx& gltx)
{
    if (gltx.number() == "#")
	return error("Can't change number to '#'");

    if (orig.dataType() != gltx.dataType()) {
	bool allowed = false;
	switch (orig.dataType()) {
	case DataObject::INVOICE:
	    if (gltx.dataType() == DataObject::RETURN)
		allowed = true;
	    break;
	case DataObject::RETURN:
	    if (gltx.dataType() == DataObject::INVOICE)
		allowed = true;
	    break;
	case DataObject::RECEIVE:
	    if (gltx.dataType() == DataObject::CLAIM)
		allowed = true;
	    break;
	case DataObject::CLAIM:
	    if (gltx.dataType() == DataObject::RECEIVE)
		allowed = true;
	    break;
	default:
	    break;
	}

	if (!allowed)
	    return error("Can't change data type");
    }

    // Can't void or unvoid reconciled or shift posted transaction
    if (orig.isActive() != gltx.isActive()) {
	for (unsigned int i = 0; i < gltx.accounts().size(); ++i)
	    if (!gltx.accounts()[i].cleared.isNull())
		return error("Can't change reconciled transaction");

	if (gltx.shiftId() != INVALID_ID) {
	    Shift shift;
	    lookup(gltx.shiftId(), shift);
	    if (shift.shiftId() != INVALID_ID)
		return error("Can't change transaction from a posted shift");
	}
    }

    // If shift changed, neither can be posted
    if (orig.shiftId() != gltx.shiftId()) {
	if (orig.shiftId() != INVALID_ID) {
	    Shift shift;
	    lookup(orig.shiftId(), shift);
	    if (shift.shiftId() != INVALID_ID)
		return error("Can't change from a posted shift");
	}

	if (gltx.shiftId() != INVALID_ID) {
	    Shift shift;
	    lookup(gltx.shiftId(), shift);
	    if (shift.shiftId() != INVALID_ID)
		return error("Can't insert into a posted shift");
	}
    }

    // Can't change tenders if in a posted shift
    if (gltx.shiftId() != INVALID_ID && orig.tenders() != gltx.tenders()) {
	Shift shift;
	lookup(gltx.shiftId(), shift);
	if (shift.shiftId() != INVALID_ID)
	    return error("Can't change tenders if posted");
    }

    // Reconcile information must match.  Also copy over cleared date
    // when needed since it can be lost on changed transactions.
    for (unsigned int i = 0; i < orig.accounts().size(); ++i) {
	const AccountLine& line = orig.accounts()[i];
	if (line.cleared.isNull()) continue;

	if (i >= gltx.accounts().size())
	    return error("Invalid change to reconciled transaction");
	if (gltx.accounts()[i].account_id != line.account_id)
	    return error("Invalid change to reconciled transaction");
	if (gltx.accounts()[i].amount != line.amount)
	    return error("Invalid change to reconciled transaction");
	gltx.accounts()[i].cleared = line.cleared;
    }

    // Can't change transaction before close date
    Company company;
    lookup(company);
    if (!company.closeDate().isNull()) {
	if (gltx.postDate() <= company.closeDate())
	    return error("Can't change date to before close date");
	if (orig.postDate() <= company.closeDate())
	    return error("Can't change transaction before close date");
    }
    if (!company.startOfYear().isNull()) {
	if (gltx.postDate() < company.startOfYear())
	    return error("Can't change date into last year");
	if (orig.postDate() < company.startOfYear())
	    return error("Can't change transaction in last year");
    }

    // Verify station/employee are specified
    if (company.shiftMethod() == Company::BY_STATION) {
	if (gltx.stationId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("A station is required");
	    default:
		break;
	    }
	}
    }
    if (company.shiftMethod() == Company::BY_EMPLOYEE) {
	if (gltx.employeeId() == INVALID_ID) {
	    // Error if its a transaction type involving cashrec
	    switch (gltx.dataType()) {
	    case DataObject::INVOICE:
	    case DataObject::RECEIPT:
	    case DataObject::NOSALE:
	    case DataObject::PAYOUT:
	    case DataObject::RETURN:
	    case DataObject::SHIFT:
	    case DataObject::TEND_ADJUST:
	    case DataObject::WITHDRAW:
		return error("An employee is required");
	    default:
		break;
	    }
	}
    }

    // Check that change data exists and create if needed
    checkAccount(gltx);
    checkCard(gltx);
    checkItem(gltx);

    // NOTE: this doesn't include paid and shouldn't
    QString cmd = updateCmd("gltx", "gltx_id", "number,reference_str,"
			    "post_date,post_time,memo,station_id,"
			    "employee_id,card_id,store_id,shift_id,"
			    "link_id,printed,amount,data_type");
    Stmt stmt(_connection, cmd);

    updateData(orig, gltx, stmt);
    stmtSetString(stmt, gltx.number());
    stmtSetString(stmt, gltx.reference());
    stmtSetDate(stmt, gltx.postDate());
    stmtSetTime(stmt, gltx.postTime());
    stmtSetString(stmt, gltx.memo());
    stmtSetId(stmt, gltx.stationId());
    stmtSetId(stmt, gltx.employeeId());
    stmtSetId(stmt, gltx.cardId());
    stmtSetId(stmt, gltx.storeId());
    stmtSetId(stmt, gltx.shiftId());
    stmtSetId(stmt, gltx.linkId());
    stmtSetBool(stmt, gltx.printed());
    stmtSetFixed(stmt, gltx.total());
    stmtSetInt(stmt, gltx.dataType());
    stmtSetId(stmt, orig.id());
    stmtSetInt(stmt, orig.version());
    execute(stmt);
    if (stmt.getUpdateCount() != 1)
	return error("Data has been changed by another user");

    sqlDeleteLines(orig);
    sqlCreateLines(gltx);

    return true;
}
예제 #22
0
bool executeCommand(sqlite3 *db, const char *command)
{
    char **params;
    int paramsCount;
    int i;

    int from, to;
    double sum;

    (void)db;   // unused


    // parse command
    paramsCount = countWords(command);
    params = malloc(sizeof(char*) * paramsCount);
    for (i=0; i<paramsCount; i++)
        params[i] = getWord(command, i);            

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_HELP)))
        commandHelp();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_1)))
        command1();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_2)))
        command2();

    if ((paramsCount >= 4) && (!strcmp(params[0], COMMAND_TRANSF)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[3], "%lf", &sum);
        sscanf(params[2], "%i", &to);
        //transfer(db, from, to, sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
        credit(db, to, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_DEB)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_CRED)))
    {
        sscanf(params[1], "%i", &to);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0) return false;
        credit(db, to, sum);
    }

    if ((paramsCount >= 2) && (!strcmp(params[0], COMMAND_CHCK)))
    {
        sscanf(params[1], "%i", &to);
        checkAccount(db, to);
    }

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_UNDO)))
        undo(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADD)))
        createNewCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DEL)))
        deleteCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DELACC)))
        deleteAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADDACC)))
        addAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_COMMIT)))
        commit(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_SHOW)))
        showAll(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_LOGGER)))
        logger(db);

    for (i=0; i<paramsCount; i++)
        free(params[i]);
    free(params);

    return true;
}
void FDInitDatabase::createDatabase()
{
	KLDM->setHostName(m_server->text());
	KLDM->setDatabaseName("template1");
	KLDM->setUserName(m_login->text());
	KLDM->setPassword(m_passwd->text());
	if ( KLDM->open() )
	{
		if ( ! checkAccount() )
		{
			KMessageBox::error(this, i18n("Your account is invalid, you need a user which can create users and databases"));
			return;
		}
		
		QSqlQuery q;
		
		q = KLDM->exec("CREATE DATABASE "+m_dbname->text());
		if ( ! q.isActive() )
		{
			int opt = KMessageBox::questionYesNo(this, i18n("I can't create %1\n The error was %2\ntry remove it?").arg(m_dbname->text()).arg((KLDM->lastError()).text()), i18n("Error"));
			
			switch( opt )
			{
				case KMessageBox::Yes:
				{
					KLDM->dropTables();
					KLDM->exec("DROP DATABASE "+m_dbname->text());
					KLDM->exec("CREATE DATABASE "+m_dbname->text()); 
					KLDM->dropTables();
				}
				break;
				case KMessageBox::No:
				{
					m_createButton->setEnabled(false);
					KLDM->setDatabaseName(m_dbname->text());
					emit gotoFinish();
					return;
				}
				break;
			}
		}
		
		KLDM->setDatabaseName(m_dbname->text());
		
		KLDM->close();
	
		if ( ! KLDM->open() )
		{
			qDebug("I can't open database: "+m_dbname->text());
		}
		
		m_pbar->setTotalSteps(7);
		connect(KLDM, SIGNAL(progress(int)), m_pbar, SLOT(setProgress(int)));
		
		if ( ! KLDM->createTables() )
		{
			KMessageBox::error(this, i18n("I can't create (all) tables in database %1").arg(KLDM->databaseName()), i18n("Error"));
			//KLDM->dropTables();
		}
		else
		{
			KMessageBox::information(this, i18n("The database %1 was create succesfully!\n").arg(KLDM->databaseName())+	i18n("You can continue to next step"));
			m_createButton->setEnabled(false);
			emit enableNext(this, true);
		}
	}
	else
	{
		KMessageBox::error(this, i18n("I can't open the database!\n"
				"The error was %1").arg((KLDM->lastError()).text())  , i18n("Error"));
	}
	
// 	if ( KLDM->isOpen())
// 		KLDM->close();
}
예제 #24
0
void query() {
	if(checkAccount()) {
		printAccountInfo();
	}
}
예제 #25
0
void ServerController::submitReview(sf::Packet &packet, sf::TcpSocket &client)
{
	std::string username, conference, paperTitle;
	Review review;
	std::string firstname, lastname;
	
	packet >> username >> conference >> paperTitle;
	packet >> review;
	
	int findIndex = checkAccount(username);
	if (findIndex == -1)
	{
		return;		// ignore request if user does not exist
	}
	firstname = data.accounts[findIndex].getFirstName();
	lastname = data.accounts[findIndex].getLastName();
	
	review.setPCMember(firstname + " " + lastname);
	
	for (int i = 0; i < (int)data.submissions.size(); i++)
	{
		if (data.submissions[i].getConference() == conference)
		{
			if (data.submissions[i].getTitle() == paperTitle)
			{
				if (data.submissions[i].hasReviewer(username) || review.getFinal())
				{					
					// overwrite the old review by this reviewer
					bool exists = false;
					for (int q = 0; q < (int)data.reviews.size(); ++q)
					{
						if (data.reviews[q].getConference() == conference &&
							data.reviews[q].getTitle() == paperTitle &&
								data.reviews[q].getPCMember() == (firstname + " " + lastname))
						{
							data.reviews[q] = review;		// overwrite the old review
							exists = true;
							break;
						}
					}
					if (!exists)
					{
						data.addLog("Review submitted in Conference " + conference + 
							" for Paper " + paperTitle + " by " + username);
						data.reviews.push_back(review);
						data.saveReviews();
					}
					else
					{
						data.addLog("Review resubmitted in Conference " + conference +
							" for Paper " + paperTitle + " by " + username);
					}
					if (review.getFinal())
					{
						data.addLog("Submitted review is final");
						data.submissions[i].setReviewed();
						data.saveSubmissions();
					}
					break;
				}
			}
		}
	}
}