示例#1
0
std::shared_ptr<Client> ClientController::CreateClient(const Client &client)
{
    if(!(UserSingleton::GetInstance().GetPermissions() & PLM::PermissionsFlag::WRITE_CLIENTS))
    {
        return std::shared_ptr<Client>();
    }

    std::unique_ptr<Client> newClient(new Client());
    CopyContactData(client, *newClient);

    if(!CreateContact(*newClient))
    {
        return std::shared_ptr<Client>();
    }

    QSqlQuery query = GetDb().CreateQuery();
    query.prepare("INSERT INTO \"Client\" "
        "("
        "\"ContactId\", "
        "\"CompanyName\""
        ") "
        "VALUES"
        "("
        ":contactId, "
        ":companyName"
        ")"
        " RETURNING \"ClientId\";"
    );

    query.bindValue(":companyName", newClient->GetAccountName());
    query.bindValue(":contactId", newClient->GetId());

    if(!query.exec())
    {
        return std::shared_ptr<Client>();
    }

    query.next();
    qint32 clientId = query.value("ClientId").toInt();
    newClient->SetClientId(clientId);

    auto sharedPtr = AddClient(std::move(newClient));
    emit sigClientAdded(*sharedPtr);
    return sharedPtr;
}
示例#2
0
static LRESULT CALLBACK myspace_links_watcherwndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
        case WM_COPYDATA:
        {
            char *szData, *s;
            COPYDATASTRUCT *cds = (COPYDATASTRUCT *) lParam;

            //LOG(LOG_DEBUG, "Links: WM_COPYDATA");
            // Check to see if link support is enabled
            // We shouldn't need this check since the class instance shouldn't be running
            // but lets be safe
            if (!DBGetContactSettingByte(NULL, MODULE, "EnableLinkHandling", 0))
                break;
            if (!(char *) cds->lpData)
                break;
            s = szData = strdup((char *) cds->lpData);

            s += 5;
			if (!_strnicmp(s, "addContact?", 11)) {
				s =strstr(s, "cID=");
				if(s) {
					s += 4;
					char *t = strchr(s, '&');
					if(t) *t = 0;
					
					HANDLE hContact;
					int uid;
					for(t = strtok(s, ","); t ;t = strtok(0, ",")) {
						uid = atoi(t);
						hContact = FindContact(uid);
						if(!hContact) {
							hContact = CreateContact(uid, 0, 0, true);
							LookupUID(uid);
						}
					}
				}
			}
            else if (_strnicmp(s, "sendIM?", 7) == 0 && ServiceExists(MS_MSG_SENDMESSAGE))
			{
				s=strrchr(s, '=');
				if(s) {
					s++;
					int uid = atoi(s);

					HANDLE hContact = FindContact(uid);
					if(!hContact) {
						hContact = CreateContact(uid, 0, 0, false);
						DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
						DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
						LookupUID(uid);
					}
					CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0);
				}
			}

			free(szData);
        }
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}