Esempio n. 1
0
BOOL CVendorAddView::AddVendor()
{
	ERRCODE errRet = err_OK;
	CString csMsg;
	CString csName, csTelephone, csAddress;
	GetDlgItemText(IDC_EDIT_VENDOR_NAME, csName);
	GetDlgItemText(IDC_EDIT_VENDOR_TEL, csTelephone);
	GetDlgItemText(IDC_EDIT_VENDOR_ADDRESS, csAddress);

	csName.Trim();
	csTelephone.Trim();
	csAddress.Trim();
	if (csName == _T(""))
	{
		csMsg.Format("生产厂家名称不能为空!");
		MessageBox(csMsg, _T("生产厂家管理"), MB_ICONERROR);
		return FALSE;
	}

	CVendorDB vendorDB;
	m_vendor.csName = csName;
	m_vendor.csTelephone = csTelephone;
	m_vendor.csAddress = csAddress;
	if (m_viewType != VIEW_EDIT)
	{
		errRet = vendorDB.AddVendor(&m_vendor);
		if (errRet != err_OK)
		{
			csMsg.Format(_T("添加生产厂家失败,%s"), GetErrMsg(errRet));
			MessageBox(csMsg, _T("生产厂家管理"), MB_ICONERROR);
			return FALSE;
		}
	}
	else
	{
		errRet = vendorDB.UpdateVendor(m_vendor.csID.GetBuffer(), csName.GetBuffer(), csTelephone.GetBuffer(), csAddress.GetBuffer());
		if (errRet == err_Vendor_AlreadyExist)
		{
			csMsg.Format(_T("生产厂家名称已经存在,请重新输入"));
			MessageBox(csMsg, _T("生产厂家管理"), MB_ICONINFORMATION);
			return FALSE;
		}
		else if (errRet != err_OK)
		{
			csMsg.Format(_T("修改生产厂家失败,%s"), GetErrMsg(errRet));
			MessageBox(csMsg, _T("生产厂家管理"), MB_ICONERROR);
			return FALSE;
		}
	}

	return TRUE;
}
Esempio n. 2
0
// [ranqd] 投递IO读请求
void CSocket::ReadByte( DWORD size )
{
	BOOL    bresult;
	int     err;
	DWORD   numRead;

	m_RecvBuffer.wr_reserve( size );

	if( size == 0 ) 
	{
		int iii = 0;
	}
	DWORD m_DwFlag = 0;
	// 请求读取数据
	bresult = WSARecv(sock,(LPWSABUF)m_RecvBuffer.wr_buf(),1,&numRead,&m_DwFlag,(LPOVERLAPPED)&m_ovIn,NULL);
	/*bresult = ReadFile(
	(HANDLE)sock,
	m_RecvBuffer.wr_buf(),
	size,
	&numRead,
	(LPOVERLAPPED)&m_ovIn );*/
	// 这里,等待一个信息包.
	if (bresult == WSA_IO_PENDING) return;//操作成功返回
	err = GetLastError();
	if (err == 64)//连接已关闭
	{
		CIocp::getInstance().PostStatus(this,&m_ovIn);//发送读取失败的完成信息
		return;
	}
	if( err != 997 )
	{
		printf( "接收数据时重叠I/O操作发生错误: %s\n",GetErrMsg(err) );
	}
}
Esempio n. 3
0
BOOL CMsgThread::CreateThread( )
{
    int nret = 0 ;
    bool br = true;

    m_pSemaphore = new COSSemaphore(0) ;
    ASSERT(m_pSemaphore);

#if defined(_WIN32) || defined(_WIN64)
	m_hThread = beginthread(NULL, 0, DefaultThreadProc, (LPVOID)this, 0, &m_ThreadId);
	if(NULL == m_hThread)
	{
		br = false;
	}
#else
    nret = beginthread(&m_hThread, NULL, DefaultThreadProc, (void*)this);

    if (0 != nret)
    {
        printf(("create CMsgThread failed err code = %d %s\n"),nret,(GetErrMsg(nret)).c_str());
        br = false;
    }
#endif
    return br;
}
Esempio n. 4
0
// [ranqd] 通过Iocp发送数据
int CSocket::SendData( DWORD dwNum = 0 )
{
	BOOL    bresult;
	int     err;
	DWORD   numRead;

	// [ranqd] 记录发送数据量
	InterlockedExchangeAdd(&g_SendSize, (long)dwNum);

	tQueue.rd_flip( dwNum );

	m_dwSendCount += dwNum;

	int size = tQueue.rd_size();

	// 没有数据可发送了,返回
	if( size == 0 )
	{
		return dwNum;
	}

	if( sock == INVALID_SOCKET ) return -1;

	tQueue.Lock();

	bresult = WSASend(sock,(LPWSABUF)tQueue.rd_buf(),1,&numRead,0,(LPOVERLAPPED)&m_ovOut,NULL);
	/*bresult = WriteFile(
	(HANDLE)sock,
	tQueue.rd_buf(),
	size,
	&numRead,
	(LPOVERLAPPED)&m_ovOut );*/

	tQueue.UnLock();

	// 这里,等待一个信息包.
	if (bresult) return size;

	if(bresult==SOCKET_ERROR && (ERROR_IO_PENDING != WSAGetLastError())) 
	{
		printf( "发送数据时重叠I/O操作发生错误: %s\n",GetErrMsg(err) );
		return -1;		
	}
	//err = GetLastError();

	//if( err == 64 )//连接已关闭
	//{
	//	CIocp::getInstance().PostStatus(this,&m_ovOut);//发送写数据失败的完成信息
	//	return -1;
	//}

	//if( err != 997 )
	//{
	//	printf( "发送数据时重叠I/O操作发生错误: %s\n",GetErrMsg(err) );
	//	return -1;
	//}

	return size;
}
Esempio n. 5
0
void CThreadScheduler::CreateSchedulerThread()
{
	if ((m_thread && m_thread->IsAlive()) || m_tasks.empty()) {
		return;
	}

	// A thread can only be run once, so the old one must be safely disposed of
	if (m_thread) {
		AddDebugLogLineN(logThreads, wxT("CreateSchedulerThread: Disposing of old thread."));
		m_thread->Stop();
		delete m_thread;
	}
	
	m_thread = new CTaskThread(this);

	wxThreadError err = m_thread->Create();
	if (err == wxTHREAD_NO_ERROR) {
		// Try to avoid reducing the latency of the main thread
		m_thread->SetPriority(WXTHREAD_MIN_PRIORITY);
		
		err = m_thread->Run();
		if (err == wxTHREAD_NO_ERROR) {
			AddDebugLogLineN(logThreads, wxT("Scheduler thread started"));
			return;
		} else {
			AddDebugLogLineC(logThreads, wxT("Error while starting scheduler thread: ") + GetErrMsg(err));
		}
	} else {
		AddDebugLogLineC(logThreads, wxT("Error while creating scheduler thread: ") + GetErrMsg(err));
	}
	
	// Creation or running failed.
	m_thread->Stop();
	delete m_thread;
	m_thread = NULL;
}
Esempio n. 6
0
void CVendorAddView::DisplayVendorInfo(LPTSTR lpVendorID)
{
	CVendorDB vendorDB;
	CString csMsg;
	ERRCODE errRet = vendorDB.GetVendor(lpVendorID, &m_vendor);
	if (errRet != err_OK)
	{
		csMsg.Format(_T("获取生产厂家信息错误!%s"), GetErrMsg(errRet));
		MessageBox(csMsg, _T("生产厂家管理"), MB_ICONERROR);
		return;
	}

	SetDlgItemText(IDC_EDIT_VENDOR_NAME, m_vendor.csName);
	SetDlgItemText(IDC_EDIT_VENDOR_TEL, m_vendor.csTelephone);
	SetDlgItemText(IDC_EDIT_VENDOR_ADDRESS, m_vendor.csAddress);
}
Esempio n. 7
0
STDMETHODIMP CbDevice::TranslateError(HRESULT code,BSTR *retVal)
{
    if (IS_CBI_ERROR(code) ) // if a cbi error
    {
        
        // Allocate memory and copy input retVal. The Detach is required
        // so that the memory will not be freed. We need the string to be 
        // returned to the 'engine'.
        
        *retVal = GetErrMsg((short)CBI_XLATE_INV(code)).Detach();
    }
    if (IS_LOCAL_ERROR(code))
    {
		// Must cast to USHORT for CComBSTR::LoadString to work
		CComBSTR retval;
        if(!retval.LoadString((USHORT)(ERR_XLATE_INV(code)))
        {
            retval=L"Unknown adaptor error.";
            // translate error message?
        }
        *retVal=retval.Detach();
    }
    return S_OK;
}
Esempio n. 8
0
int CDRTPHelper::SendRequest(int timeout /*=0*/)
{
	m_errcode = 0;
	memset(&m_errmsg,0,sizeof m_errmsg);
	int len = sizeof m_drtpBuf;
	int retries = 3;
	BOOL bRet = FALSE;
	m_currRecord = NULL;
	m_currIndex = 0;
	m_currRecordCount = 0;
	m_timeout = timeout;
	m_requestPack.head.recCount = m_rec_cnt;
	m_requestPack.head.retCode = 0;
	
	
	memset(m_drtpBuf,0,sizeof m_drtpBuf);
	
	if(!EncodeBuf(&m_requestPack, m_drtpBuf,&len, m_errmsg))
		return -3;

	/*
	bRet = DrtpSendMessage((char*)m_drtpBuf,len,&m_errcode,m_errmsg,&m_tag,
		0,-1,0,-1,2);
	*/
	bRet = DrtpPostMessage(5,m_drtpNo,m_funcNo,(char*)m_drtpBuf,len,&m_errcode,m_errmsg,m_drtpHandle,0,1);
	if(bRet == FALSE)
	{
		GetErrMsg();
		testDrtpHandle();
		return -1;
	}
	retries = 3;
	int readLen = 0;

	bRet = DrtpReadMessage((char*)m_drtpBuf, sizeof m_drtpBuf,&readLen,
		m_drtpHandle,&m_tag,&m_errcode,m_errmsg,m_timeout);

	if(bRet == FALSE)
	{
		GetErrMsg();
		logDrtpErrMsg();
		testDrtpHandle();
		return -1;
	}
	memset(&m_responsePack,0,sizeof(m_responsePack));
	memset(m_dataArray, 0, sizeof(m_dataArray));
	// 把接收缓冲区中的内容解码到Pack和DataArray中
	len = sizeof m_drtpBuf;
	int nCount = 0;
	bRet = DecodeBufWithArray((BYTE*)m_drtpBuf,readLen, &m_responsePack
		,m_dataArray, &nCount, 0);
	if(bRet == FALSE)
	{
		GetErrMsg();
		logDrtpErrMsg();
		return -1;
	}
	// 记录返回结果集数
	m_currRecordCount = m_responsePack.head.recCount;
	return 0;
}
Esempio n. 9
0
int CDRTPHelper::SendRequest(int timeout /*=0*/)
{
	m_errcode = 0;
	memset(&m_errmsg,0,sizeof m_errmsg);
	int len = sizeof m_drtpBuf;
	int retries = 3;
	BOOL bRet = FALSE;
	m_currRecord = NULL;
	m_currIndex = 0;
	m_currRecordCount = 0;
	m_timeout = timeout;
	m_requestPack.head.recCount = m_rec_cnt;
	TAG_DRTPHANDLE tag;
	memset(&tag,0,sizeof(tag));
	memset(m_drtpBuf,0,sizeof m_drtpBuf);
	if(!DrtpAttachServer(m_drtpNo,m_funcNo,m_drtpHandle,&tag,&m_errcode,m_errmsg))
	{
		try
		{
			testDrtpHandle();
			return -1;
		}
		catch (DrtpConnectException&)
		{
			return -2;
		}
	}
	EncodeBuf(&m_requestPack, m_drtpBuf,&len, NULL);

	bRet = DrtpSendMessage((char*)m_drtpBuf,len,&m_errcode,m_errmsg,&tag,
		0,-1,0,-1,2);
	if(bRet == FALSE)
	{
		GetErrMsg();
		testDrtpHandle();
		return -1;
	}
	retries = 3;
	int readLen = 0;

	bRet = DrtpReadMessage((char*)m_drtpBuf, sizeof m_drtpBuf,&readLen,
		m_drtpHandle,&tag,&m_errcode,m_errmsg,m_timeout);

	if(bRet == FALSE)
	{
		GetErrMsg();
		logDrtpErrMsg();
		return -1;
	}
	memset(&m_responsePack,0,sizeof(m_responsePack));
	memset(m_dataArray, 0, sizeof(m_dataArray));
	// 把接收缓冲区中的内容解码到Pack和DataArray中
	len = sizeof m_drtpBuf;
	int nCount = 0;
	bRet = DecodeBufWithArray((BYTE*)m_drtpBuf,readLen, &m_responsePack
		,m_dataArray, &nCount, 0);
	if(bRet == FALSE)
	{
		GetErrMsg();
		logDrtpErrMsg();
		return -1;
	}
	// 记录返回结果集数
	m_currRecordCount = m_responsePack.head.recCount;
	return 0;
}