dlgaddtattachment.cpp

来自「使用vc开发的个人信息管理系统」· C++ 代码 · 共 172 行

CPP
172
字号
// DlgAddTAttachment.cpp : implementation file
//

#include "stdafx.h"
#include "dotNET界面.h"
#include "MyFolder.h"
#include "DlgAddTAttachment.h"
#include ".\dlgaddtattachment.h"

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

/////////////////////////////////////////////////////////////////////////////
// DlgAddTAttachment dialog


DlgAddTAttachment::DlgAddTAttachment(CWnd* pParent /*=NULL*/)
	: CDialog(DlgAddTAttachment::IDD, pParent)
{
	//{{AFX_DATA_INIT(DlgAddTAttachment)
	m_strAnnexName = _T("");
	m_strPath = _T("");
	//}}AFX_DATA_INIT
}


void DlgAddTAttachment::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DlgAddTAttachment)
	DDX_Text(pDX, IDC_EDIT_ANNEXNAME, m_strAnnexName);
	DDX_Text(pDX, IDC_EDIT_PATH, m_strPath);
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_PROGRESS, pProg);
	DDX_Control(pDX, IDC_BUTTON_PATH, c_Path);
	DDX_Control(pDX, IDOK, c_IdOk);
	DDX_Control(pDX, IDC_EDIT_ANNEXNAME, c_EditAnnexName);
}


BEGIN_MESSAGE_MAP(DlgAddTAttachment, CDialog)
	//{{AFX_MSG_MAP(DlgAddTAttachment)
	ON_BN_CLICKED(IDC_BUTTON_PATH, OnButtonPath)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DlgAddTAttachment message handlers

void DlgAddTAttachment::OnButtonPath() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	static char BASED_CODE szFilter[] =
			"TAttachment Files (*.rar,*.zip)|*.rar;*.zip|";

	CFileDialog dlg(TRUE,NULL,NULL,NULL,szFilter);

	if(dlg.DoModal() == IDOK)
	{
		m_strPath = dlg.GetPathName();
		m_strFileName=dlg.GetFileName();
	}
	//AfxMessageBox(m_strFileName);
	UpdateData(FALSE);
}

void DlgAddTAttachment::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(true);
	if(m_strAnnexName.IsEmpty()){
		AfxMessageBox("你没有输入附件标题");
		return ;
	}
	MSG message;
	CString strFilePath,strFileName,strAnnexName;
	CFileException e;
	long nStep;
	int j=0;
	char * m_pBMPBuffer;
	_RecordsetPtr MySet;
	MySet.CreateInstance(__uuidof(Recordset));
	CFile file;
	c_Path.EnableWindow(false);
	c_IdOk.EnableWindow(false);
	c_EditAnnexName.EnableWindow(false);
	//_variant_t strDown="select * from drv_photo";
	_variant_t _strSQL("SELECT * FROM TAttachment");
	if(!theApp.ADOExecute(MySet,_strSQL)) return ;
	if( !file.Open( m_strPath, CFile::modeRead)){
		AfxMessageBox("没有打开文件");
		#ifdef _DEBUG
			afxDump << "File could not be opened " << e.m_cause << "\n";
		#endif
		return ;
	}
	long m_nFileLen = file.GetLength();
	pProg.SetRange(0,100);
	nStep=(m_nFileLen-m_nFileLen%100)/100;
	m_pBMPBuffer = new char[m_nFileLen + 1];
	if(!m_pBMPBuffer){
		AfxMessageBox("定义的缓冲区为空");
		return ;
	}
	if(!file.Read(m_pBMPBuffer,m_nFileLen)){
		AfxMessageBox("从文件中读入数据错误");
		return ;
	}
	if(m_pBMPBuffer == NULL)
	{
		AfxMessageBox("您没有提供完整的用户信息。\r\n这些信息包括:附件文件");
		return ;
	}
	char			*pBuf = m_pBMPBuffer;
	VARIANT			varBLOB;
	SAFEARRAY		*psa;
	SAFEARRAYBOUND	rgsabound[1];
	MySet->AddNew();
	MySet->PutCollect("NodeId",_variant_t(m_strAttachment));
	MySet->PutCollect("FileName",_variant_t(m_strFileName));
	MySet->PutCollect("TAttachmentName",_variant_t(m_strAnnexName));
	if(pBuf)
	{    
		rgsabound[0].lLbound = 0;
		rgsabound[0].cElements = m_nFileLen;
		psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
		for (long i = 0; i < (long)m_nFileLen; i++){
			SafeArrayPutElement (psa, &i, pBuf++);
			if(i%nStep==0){
				j++;
				pProg.SetPos(j);
				UpdateData(false);
			}
			if(::PeekMessage(&message,NULL,0,0,PM_REMOVE)){
				::TranslateMessage(&message);
				::DispatchMessage(&message);
			}

		}
		varBLOB.vt = VT_ARRAY | VT_UI1;
		varBLOB.parray = psa;
		MySet->GetFields()->GetItem("Data")->AppendChunk(varBLOB);
	}
	MySet->Update();
	_variant_t _strSQLUpdate("UPDATE TContent SET AttachmentId='1' WHERE NodeId='"+m_strAttachment+"'");
	theApp.ADOExecute(MySet,_strSQLUpdate);
	if(m_pBMPBuffer)
	{
		delete m_pBMPBuffer;
		m_pBMPBuffer = NULL;
	}
	theApp.pDlg->VectorAddAttachment(m_strAttachment);
	if(adStateOpen==MySet->State)	MySet->Close();
	MySet.Release();
	CDialog::OnOK();
}

BOOL DlgAddTAttachment::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  在此添加额外的初始化
	UpdateData(true);
	SetWindowText("为 \""+m_strDlgName+"\" 添加附件");
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

⌨️ 快捷键说明

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