jnartifice.cpp

来自「此次上传的使linux下的文件传输协议」· C++ 代码 · 共 294 行

CPP
294
字号
#include "stdafx.h"
#include "Prog.h"
#include "JnArtifice.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

JnArtifice::JnArtifice()
{

}

JnArtifice::~JnArtifice()
{

}

/***************************************************************************
函数名称:GetComboCurText
函数功能:获得组合框当前的文本
函数原理:
****************************************************************************/
CString JnArtifice::GetComboCurText(CComboBox& combo)
{
	int n;
	CString str=_T("");
	n=combo.GetCurSel();
	if(n>-1)
		combo.GetLBText(n,str);
	return str;
}

/***************************************************************************
函数名称:GetListCurText
函数功能:获得列表框当前的文本
函数原理:
****************************************************************************/
CString JnArtifice::GetListCurText(CListBox& list)
{
	int n;
	CString str=_T("");
	n=list.GetCurSel();
	if(n>-1)
		list.GetText(n,str);
	return str;
}

/***************************************************************************
函数名称:CalcQulin
函数功能:根据酒店的规则计算去零价
函数原理:
****************************************************************************/
void JnArtifice::CalcQulin(double &_dJine, double &_dLin)
{
	int n1=theApp.jns.DoubleToInt(_dJine);
	if(div(n1,10).rem==4)
		n1--;
	_dLin=_dJine-n1;
	_dJine=n1;
}

/***************************************************************************
函数名称:MsgBox
函数功能:用弹出对话框报告整型数值
函数原理:
****************************************************************************/
void JnArtifice::MsgBox(int n)
{
	CString str;
	str.Format("%d",n);
	AfxMessageBox(str);
}

CString JnArtifice::GetAdosConn()
{
	CString sRet=_T("");
	HRESULT hr = S_OK;
	IDataSourceLocatorPtr dlPrompt = NULL;
	_ConnectionPtr pConn=NULL;
	try
	{
		TESTHR(hr = dlPrompt.CreateInstance(__uuidof(DataLinks)) );

		pConn=dlPrompt->PromptNew();
		if(pConn ) 
		{
			sRet=(LPCTSTR)pConn->ConnectionString;
		}
	}
	catch ( _com_error &ce )
	{
		GenerateProviderError(pConn);
        GenerateComError(ce.Error(), ce.Description());
		if(pConn!= NULL)
			pConn.Release();
	}
	return sRet;
}

int JnArtifice::FindArray(CStringArray &array, CString& sFind)
{
	int i;
	int j=-1;
	for(i=0;i<array.GetSize();i++)
	{
		if(array.GetAt(i)==sFind)
		{
			j=i;
			break;
		}
	}
	return j;
}


/***************************************************************************
函数名称:GenerateComError()
函数功能:报告出COM接口的错误
函数原理:
****************************************************************************/
void JnArtifice::GenerateComError(HRESULT hr, PWSTR pwszDescription)
{
	CString strError;
	strError.Format("Run-time error '%d (%x)'", hr, hr);
	strError += "\n\n";
	strError += pwszDescription;
	AfxMessageBox(strError);
}

/***************************************************************************
函数名称:GenerateProviderError()
函数功能:报告出连接字符串的错误
函数原理:
****************************************************************************/
void JnArtifice::GenerateProviderError(_ConnectionPtr pConnection)
{
 	if(pConnection == NULL)
		return;
    ErrorPtr  pErr = NULL;
	CString strError;
    if( (pConnection->Errors->Count) > 0)
    {
        long nCount = pConnection->Errors->Count;
        for(long i = 0; i < nCount; i++)
        {
            pErr = pConnection->Errors->GetItem(i);
            strError.Format("\t Error number: %x\t%s", pErr->Number,
                pErr->Description);
			AfxMessageBox(strError);

        }
    }
}

int JnArtifice::FindListString(CListBox &list,CString& str)
{
	int n,l=-1;
	CString str1=_T("");
	for(int k=0;k<list.GetCount();k++)
	{
		n=list.FindString(k,str);
		list.GetText(n,str1);
		if(str==str1)
		{
			l=n;
			break;
		}
	}
	return l;
}

BOOL JnArtifice::DirExist(const char* Fn)
{
	WIN32_FIND_DATA fData;
	HANDLE FindFile;
	FindFile=FindFirstFile(Fn,&fData);
	if(FindFile==INVALID_HANDLE_VALUE)
		return FALSE;
	if(fData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
	{
		FindClose(FindFile);
		return TRUE;
	}
	while(FindNextFile(FindFile,&fData))
	{
		if(fData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
		{
			FindClose(FindFile);
			return TRUE;
		}
	}
	FindClose(FindFile);
	return FALSE;
}

BOOL JnArtifice::FileExist(CString sFile)
{
	CFileFind finder;
	return finder.FindFile(sFile);
}

void JnArtifice::GetCheckedListItem(CCheckListBox &m_List, CStringArray &array)
{
	array.RemoveAll();
	CString str;
	for(int i=0;i<m_List.GetCount();i++)
	{
		if(m_List.GetCheck(i)==1)
		{
			m_List.GetText(i,str);
			if(str!=_T(""))
			{
				array.Add(str);
			}
		}
	}
}

void JnArtifice::AddListItem(CListBox &m_List, CStringArray &array, int nType)
{
	for(int i=0;i<array.GetSize();i++)
	{
		if(nType==0)  //允许重复添加
		{
			m_List.AddString(array.GetAt(i));
		}
		else if(nType==1)  //不允许重复添加
		{
			if(m_List.FindString(0,array.GetAt(i))<0)
			{
				m_List.AddString(array.GetAt(i));
			}
		}
	}
}

BOOL JnArtifice::OpenMulu(CString sDirName)
{
	HANDLE hDir;
	hDir=CreateFile(sDirName,
		GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_DELETE,
		NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL); 
	if(hDir==INVALID_HANDLE_VALUE ) 
		return FALSE; // 打开失败时返回 
	return TRUE;
}

void JnArtifice::SetCheckedListItem(CCheckListBox &list, CStringArray &array)
{
	int nPos=-1;
	for(int i=0;i<array.GetSize();i++)
	{
		nPos=FindListString(list,array.GetAt(i));
		if(nPos>-1)
		{
			list.SetCheck(nPos,1);
		}
	}
}

CString JnArtifice::GetLsh()
{
	return theApp.jnt.GetCurSysTime(20);
}

void JnArtifice::CenterWindow(CDialog *pDlg)
{
	if(pDlg)
	{
		CRect rect;
		pDlg->GetWindowRect(rect);
		int cy=GetSystemMetrics(SM_CYSCREEN);
		int cx=GetSystemMetrics(SM_CXSCREEN);
		int x=theApp.jns.DoubleToInt(cx/2);
		int y=theApp.jns.DoubleToInt(cy/2);
		int w,h;
		w=theApp.jns.DoubleToInt(rect.Width()/2);
		h=theApp.jns.DoubleToInt(rect.Height()/2);
		rect.left=x-w;
		rect.top=y-h;
		rect.right=x+w;
		rect.bottom=y+h;
		pDlg->MoveWindow(rect);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?