示例#1
0
UserManageDlg::UserManageDlg()
{
    SET_FONT

    setWindowTitle(tr("用户管理"));
    m_pUserCenter = USERCENTER::instance();
    CreateToolBar();

	userTable_ = new QTableWidget(this);
    userTable_->setRowCount(0);
    userTable_->setColumnCount(2);
    userTable_->setColumnWidth(0, 130);
    userTable_->setColumnWidth(1, 200);
    userTable_->setFrameStyle(QFrame::Plain);
    userTable_->setEditTriggers(QAbstractItemView::NoEditTriggers);
    userTable_->setSelectionBehavior(QAbstractItemView::SelectRows);
    userTable_->setSelectionMode(QAbstractItemView::SingleSelection);

	QStringList headList;
	headList << "用户名" << "用户角色";
	userTable_->setHorizontalHeaderLabels(headList);

    QVBoxLayout *layout = new QVBoxLayout();
    layout->addWidget(toolBar_);
    layout->addWidget(userTable_);
    setLayout(layout);

    connect(addUserAct_, SIGNAL(triggered()), this, SLOT(AddUser()));
    connect(delUserAct_, SIGNAL(triggered()), this, SLOT(DelUser()));
    connect(editUserAct_, SIGNAL(triggered()), this, SLOT(EditUser()));

    DisplayUsers();
}
void
WLayoutApplicationMayanX::SL_InternetRequestCompleted(QNetworkReply * poNetworkReply)
	{
	CInternetResponseWebMethodXmlSoap oInternetResponse(poNetworkReply);

	// First of all, check if there is an error from the server
	CXmlNode * pXmlNodeError = oInternetResponse.PGetXmlNodeError();
	if (pXmlNodeError != NULL)
		{
		MessageLog_AppendTextFormatSev(eSeverityErrorWarning, "SL_InternetRequestCompleted() with the following error:\n^N", pXmlNodeError);
		int nCode = pXmlNodeError->NFindElementOrAttributeValueNumeric("nCode");
		if (nCode == eCodeUserNotFound)
			{
			// The user is not found or does not exist, therefore clear the m_strxUserID so we may retry
			m_pApplication->m_strxUserID.Empty();
			}
		if (nCode == eCodeUserAlreadyExist)
			{
			// The user already exists, so fetch the xUserID from the
			m_pApplication->m_strxUserID = pXmlNodeError->PszuFindElementValue("xDescriptionParam");
			SL_ExchangeLogin();	// Attempt to login again
			}
		return;
		}

	CXmlNode * pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserRegister");
	if (pXmlNode != NULL)
		{
		m_pApplication->m_strxUserID = pXmlNode->m_pszuTagValue;
		if (!m_pApplication->m_strxUserID.FIsEmptyString())
			SL_ExchangeLogin();		// Attempt to login with the new UserID.
		else
			EMessageBoxWarning("The API 'UserRegister' returned an invalid UserID of value '$S'", &m_pApplication->m_strxUserID);
		return;
		}
	pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserLogin");
	if (pXmlNode != NULL)
		{
		CBin binChallenge;
		binChallenge.BinAppendBinaryDataFromBase64Szv(pXmlNode->PszuFindElementValue("bChallenge"));
		if (!binChallenge.FIsEmptyBinary())
			{
			// We received a challenge, so respond to it now
			CBin binResponseData = m_pApplication->m_pProfileParent->m_strKeyPublic;
			binResponseData.BinAppendCBin(binChallenge);
			//MessageLog_AppendTextFormatCo(d_coBlue, " bIdentity: {B/}\n bChallenge: {B/}\n bIdentity + bChallenge: {B/}\n", &m_pTreeItemParent->m_binKeyPublic, &binChallenge, &binResponseData);
			binResponseData.BinHashToMd5();

			CInternetRequestWebMethodXmlMayanX oRequest("UserLogin");
			oRequest.BinAppendXmlElementText("xUserID", m_pApplication->m_strxUserID);
			oRequest.BinAppendXmlElementBinaryBase64("bResponse", binResponseData);
			m_oInternetServer.RequestSend(&oRequest);
			return;
			}
		if (m_oInternetServer.m_strxSessionID.FIsEmptyString())
			{
			m_oInternetServer.m_strxSessionID = pXmlNode->PszuFindElementValue("xSessionID");
			//m_oInternetServer.m_strxSessionID = (PSZUC)"as8323jas932e";
			if (!m_oInternetServer.m_strxSessionID.FIsEmptyString())
				{
				MessageLog_AppendTextFormatCo(d_coBlue, "Login successful: xSessionID = $S\n", &m_oInternetServer.m_strxSessionID);
				OLayoutHorizontal * poLayoutOrder = new OLayoutHorizontal((QWidget *)NULL);
				m_poLayoutButtons->addRow(poLayoutOrder);
				m_pwEditQuantity = new WEditNumber;
				poLayoutOrder->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditQuantity);
				m_pwEditPrice = new WEditNumber;
				poLayoutOrder->Layout_AddLabelAndWidgetH_PA("Price:", m_pwEditPrice);
				WButtonTextWithIcon * pwButton = new WButtonTextWithIcon("Place Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
				poLayoutOrder->addWidget(pwButton);
				poLayoutOrder->addWidget(PA_CHILD new QWidget, 1);
				connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderAdd()));

				//Updating user balance
				OLayoutHorizontal * poLayoutUserBalance = new OLayoutHorizontal((QWidget *)NULL);
				m_poLayoutButtons->addRow(poLayoutUserBalance);
                m_pwEditUpdateBalanceQuantity = new WEditNumber;
                m_pwEditUpdateBalanceUserId = new WEditNumber;
                poLayoutUserBalance->Layout_AddLabelAndWidgetH_PA("User Id:", m_pwEditUpdateBalanceUserId);
                poLayoutUserBalance->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditUpdateBalanceQuantity);
                m_pwLabelBalance=new WLabel;
				pwButton = new WButtonTextWithIcon("Update Balance", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUserBalance->addWidget(pwButton);
                poLayoutUserBalance->addWidget(m_pwLabelBalance);
				poLayoutUserBalance->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserBalanceUpdate()));

                //Cancel an Order
                OLayoutHorizontal * poLayoutCancelAnOrder = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutCancelAnOrder);
                m_pwEditIdToCancelOrder = new WEditNumber;
                poLayoutCancelAnOrder->Layout_AddLabelAndWidgetH_PA("Id:", m_pwEditIdToCancelOrder);
				pwButton = new WButtonTextWithIcon("Cancel Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutCancelAnOrder->addWidget(pwButton);
                poLayoutCancelAnOrder->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderCancel()));

                //Update an Order
                OLayoutHorizontal * poLayoutUpdateAnOrder = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutUpdateAnOrder);
                m_pwEditIdToUpdateOrder = new WEditNumber;
                poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Id:", m_pwEditIdToUpdateOrder);
                m_pwEditPriceToUpdateOrder = new WEditNumber;
                poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Price:", m_pwEditPriceToUpdateOrder);
                m_pwEditQuantityToUpdateOrder = new WEditNumber;
                poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditQuantityToUpdateOrder);
				pwButton = new WButtonTextWithIcon("Update Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUpdateAnOrder->addWidget(pwButton);
                poLayoutUpdateAnOrder->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderUpdate()));

                //Update User's Account
                OLayoutHorizontal* poLayoutUpdateUsersAccount = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutUpdateUsersAccount);
                m_pwEditUpdateAccountId=new WEditNumber;
                m_pwEditUpdateAccountName = new WEdit;
                m_pwEditUpdateAccountRole = new WEditNumber;
                poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Id:", m_pwEditUpdateAccountId);
                poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Name:", m_pwEditUpdateAccountName);
                poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Role:", m_pwEditUpdateAccountRole);
				pwButton = new WButtonTextWithIcon("Update User Account", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUpdateUsersAccount->addWidget(pwButton);
                poLayoutUpdateUsersAccount->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserAccountUpdate()));

                //Get User's Document
                OLayoutHorizontal* poLayoutUserDocuments = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutUserDocuments);
                m_pwEditGetUserDocumentId=new WEditNumber;
                poLayoutUserDocuments->Layout_AddLabelAndWidgetH_PA("Document Id:", m_pwEditGetUserDocumentId);
				pwButton = new WButtonTextWithIcon("Get Document", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUserDocuments->addWidget(pwButton);
                poLayoutUserDocuments->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserDocumentGet()));

                //Buttons to Fetch Data
                OLayoutHorizontal* poLayoutFetchData = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutFetchData);
                    //Fetching User's Balances

					pwButton = new WButtonTextWithIcon("Fetch User's' Balances", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUserBalances()));

                    //Fetching Users
					pwButton = new WButtonTextWithIcon("Fetch Users", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUsers()));

                    //Fetching User's Documents
					pwButton = new WButtonTextWithIcon("Fetch User's Documents", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUserDocuments()));

                    //Upload a Document
					pwButton = new WButtonTextWithIcon("Upload a Document...", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUploadADocument()));

                poLayoutFetchData->addWidget(PA_CHILD new QWidget, 1);

				/*
				// We have a valid Session ID, so we may download the bids.  For this, we will display a new button
				WButtonTextWithIcon * pwButton = new WButtonTextWithIcon("Download Market Bids", eMenuIconCoffeeBuy);
				m_poLayoutButtons->addRow(pwButton);
				connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonDownloadMarketBids()));
				*/
				m_pwLabelWelcome->hide();
				m_pwButtonRegister->hide();
				DisplayOrders(0);
                DisplayUserBalances(0);
				}
			}
		return;
		} // if (UserLogin)

	pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderAdd");
	if (pXmlNode != NULL)
		{
		DisplayOrders(pXmlNode);
		DisplayMarketOrders(pXmlNode);	// Also add the new order to the Market Orders
		return;
		}
	pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrders");
	if (pXmlNode != NULL)
		{
		DisplayOrders(pXmlNode);
		return;
		}

	pXmlNode = oInternetResponse.PGetXmlNodeResponse("MarketOrders");
	if (pXmlNode != NULL)
		{
		DisplayMarketOrders(pXmlNode);
		return;
		}

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserBalanceUpdate");
    if (pXmlNode != NULL)
        {
        DisplayUserBalanceUpdated(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("FetchUserBalances");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "Fetching user balances\n\n");
        DisplayUserBalances(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("FetchUsers");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "Fetching all users\n\n");
        DisplayUsers(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserAccountUpdate");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "updating user account\n\n");
        DisplayUserAccountUpdate(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserDocuments");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "getting all user's documents\n\n");
        DisplayAllUsersDocuments(pXmlNode);
        return;
        }


    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserDocumentGet");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "getting all user's documents\n\n");
        SaveUsersDocument(pXmlNode);
        return;
            }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderUpdate");
    if (pXmlNode != NULL)
        {
        UserOrderUpdate(pXmlNode);
        return;
            }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderCancel");
    if (pXmlNode != NULL)
        {
        UserOrderCancel(pXmlNode);
        return;
            }

	} // SL_InternetRequestCompleted()