⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systemdlg.cpp

📁 实现了将图像目录保存在数据库中
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/
			((double)pDC->GetDeviceCaps(VERTSIZE)*105.0);  
        if(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,
			hmHeight,hmWidth,-hmHeight,NULL)))  
        {
            pPic->Release();
            return false;
        }
        pPic->Release();  
    }  
    else  
    {
        return false;  
    }
    return true;
}



void CSystemDlg::OnBtntodisk() 
{
	static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|All Files (*.*)|*.*||";
	CFileDialog dlg2(FALSE,NULL,NULL,  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
	if(dlg2.DoModal() == IDOK)
	{
		CFile mFile(TextPathName, CFile::modeWrite|CFile::modeCreate);
		LoadImgFile(TextPathName);
        mFile.Write(m_pImgBuffer,m_nFileLen);
        mFile.Flush();
       mFile.Close();
		MessageBox("图片导入本地文件夹成功!","提示",64);
	}
	return;	
}






void CSystemDlg::OnBtnAddOnePicture() 
{
	m_ShowInformation.SetWindowText("");
	CString str1,str2;
	m_Bnumber.GetWindowText(str1);
	m_Bname.GetWindowText(str2);
	CString str;
	CFile fileMultiOpen;
	static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|All Files (*.*)|*.*||";
	CFileDialog dlg1(TRUE,"BMP",NULL,  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
	dlg1.m_ofn.lpstrFile=str.GetBuffer(10000);
	str.ReleaseBuffer();
	dlg1.m_ofn.nMaxFile=9000;
	if(dlg1.DoModal()==IDOK)
	{
		POSITION pos=dlg1.GetStartPosition();
		while(pos!=NULL)
		{
			CString strFileName=dlg1.GetNextPathName(pos);
			LoadImgFile(strFileName);
		}
		CClientDC dc(this); 
		ShowJpgGif(&dc,m_pImgBuffer,m_nFileLen,380,30);
	}
	else
		return;
}



void CSystemDlg::Destroypicture()
{
	if(m_pImgBuffer)
		delete m_pImgBuffer;
	m_pImgBuffer=NULL;
}



BOOL CSystemDlg::DestroyWindow() 
{	
	Destroypicture();
	return CDialog::DestroyWindow();
}



void CSystemDlg::OnBtnRearch() 
{
	CString sql,strr0,strr1,strr2,strr3;
	m_Bname.GetWindowText(strr0);
	m_Bnumber.GetWindowText(strr1);
	m_Bold.GetWindowText(strr2);
	m_Baddress.GetWindowText(strr3);
	DBgrid.SetRefDataSource(NULL);
	theApp.datamanage->GetRecordset()->raw_Close();
	if(!strr0.IsEmpty())
	{
		sql.Format("select UID as 编号,UNAME as 姓名,UOLD as 年龄, UADDR as 地址 from USERINFO where UNAME like '%s'",strr0);
	}
	else
		if(!strr1.IsEmpty())
		{
			sql.Format("select UID as 编号,UNAME as 姓名,UOLD as 年龄, UADDR as 地址 from USERINFO where UID like '%s'",strr1);
		}
	else
		if(!strr2.IsEmpty())
		{
			sql.Format("select UID as 编号,UNAME as 姓名,UOLD as 年龄, UADDR as 地址 from USERINFO where UOLD like '%s'",strr2);
		}
	else
		if(!strr3.IsEmpty())
		{
			sql.Format("select UID as 编号,UNAME as 姓名,UOLD as 年龄, UADDR as 地址 from USERINFO where UADDR like '%s'",strr3);
		}
	else
		{
			sql.Format("select UID as 编号,UNAME as 姓名,UOLD as 年龄, UADDR as 地址 from USERINFO");
		}
	theApp.datamanage->GetRecordset()->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
	if(theApp.datamanage->GetRecordset()->RecordCount>0)
	{
      	DBgrid.SetRefDataSource(theApp.datamanage->GetRecordset()->DataSource);	
		TextFromDataToWindow(strr1);
	}
	else
	{
		RefreshShow();
		MessageBox("没有你要查询的相关信息!请重新输入","提示",64);
	}
}



void CSystemDlg::OnBtnReportSorted() 
{
	_Application ExcelApp;
	Workbooks wbsMyBooks;
	_Workbook wbMyBook;
	Sheets wssMysheets;
	_Worksheet wsMysheet;
	Range rgMyRge;
	_RecordsetPtr temp=theApp.datamanage->Record1;
	temp->raw_Close();
	temp->Open("select * from USERINFO ",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	if(!ExcelApp.CreateDispatch("Excel.Application",NULL))
	{
		AfxMessageBox("创建Excel服务失败!");
		exit(1);
	}
	ExcelApp.SetVisible(false);
	char path[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,path);
	CString strPath=path;
	strPath += "\\reporttemplate";
	wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true); 
	wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t(strPath))); 	
	wssMysheets.AttachDispatch(wbMyBook.GetWorksheets(),true); 
	wsMysheet.AttachDispatch(wssMysheets.GetItem(_variant_t("sheet1")),true);
	CString str1;
	wsMysheet.AttachDispatch(wssMysheets.GetItem(_variant_t("sheet1")),true);
	str1 = "第1页";
	wsMysheet.SetName(str1);
	for( int i=0;i<wssMysheets.GetCount()-1;i++){
		wsMysheet = wsMysheet.GetNext();
		str1.Format("第%d页",i+2);
		wsMysheet.SetName(str1);
	}
	wsMysheet.AttachDispatch(wssMysheets.GetItem(_variant_t("第1页")),true);
	rgMyRge.AttachDispatch(wsMysheet.GetCells(),true); 
     CTime tDate;
	 CString sDate;
	temp->MoveFirst();
	  for(int setnum=0;setnum<theApp.datamanage->GetRecordset()->RecordCount;setnum++)
	  {
	     rgMyRge.SetItem(_variant_t((long)(3+setnum)),_variant_t((long)(1)),_variant_t(temp->GetCollect("UID")));  
         rgMyRge.SetItem(_variant_t((long)(3+setnum)),_variant_t((long)(2)),_variant_t(temp->GetCollect("UNAME"))); 
         rgMyRge.SetItem(_variant_t((long)(3+setnum)),_variant_t((long)(3)),_variant_t(temp->GetCollect("UOLD")));  
         rgMyRge.SetItem(_variant_t((long)(3+setnum)),_variant_t((long)(4)),_variant_t(temp->GetCollect("UADDR")));    
         temp->MoveNext();       
	  }
	strPath = path;
	strPath += "\\UserInforeport.xls";
	wsMysheet.SaveAs(strPath,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing);
	ExcelApp.SetVisible(true); 
	wbMyBook.PrintPreview(_variant_t(false)); 
	rgMyRge.ReleaseDispatch(); 
	wsMysheet.ReleaseDispatch(); 
	wssMysheets.ReleaseDispatch(); 
	wbMyBook.ReleaseDispatch(); 
	wbsMyBooks.ReleaseDispatch();
	ExcelApp.ReleaseDispatch(); 
	MessageBox("导入Excel成功!","创合世纪员工信息管理",64);
}



void CSystemDlg::OnBtnReportToDatabase() 
{
	CString filename;
	static char BASED_CODE szFilter[] = "所有Microsoft Office Excel 文件(*.xls)|*.xls|All Files (*.*)|*.*||";
	CFileDialog dlg(TRUE,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
	if(dlg.DoModal() == IDOK)
	{	
		filename=dlg.GetPathName();
		CSpreadSheet mySheet(filename, "第1页");
		CString  Column1,Column2,Column3,Column4;		
		for (int i =3;i<=mySheet.GetTotalRows(); i++)
		{
			mySheet.ReadCell(Column1,1,i);
			mySheet.ReadCell(Column2,2,i);
			mySheet.ReadCell(Column3,3,i);
			mySheet.ReadCell(Column4,4,i);
			if((!Column1.IsEmpty())&&(!Column2.IsEmpty())&&(!Column3.IsEmpty())&&(!Column4.IsEmpty()))
			{	
				if(!IsRepeated(Column1))
				{			
					try
					{
						CString sqld;
						theApp.datamanage->GetRecordset()->raw_Close();
						sqld.Format("insert into USERINFO values('%s','%s','%s','%s')",Column1,Column2,Column3,Column4);
						theApp.datamanage->ExecSQL(sqld);
					}
					catch(_com_error e)
					{
						AfxMessageBox(e.ErrorMessage());
					}
				}
				else 
				{
					AfxMessageBox("数据信息重复,请核对再导入!");
					return;
				}
			}
			else 
			{
				RefreshShow();
				MessageBox("导入数据库成功!");
				return;
			}
		}		
	}
	else 
		return;
}





void CSystemDlg::OnBtnPre() 
{
	_RecordsetPtr temp1=theApp.datamanage->Record1;
	temp1->raw_Close();
	CString sql;
	sql.Format("select * from tbTEXTINFO where Tid='%s'",str1);
	try
	{
		temp1->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
		if(temp1->RecordCount>0)
		{	
			temp1->MoveLast();
			while(!temp1->BOF)
			{
				CString TextPathName=temp1->GetCollect("Tpathname").bstrVal;
				LoadImgFile(TextPathName);
				CClientDC dc(this); 
				ShowJpgGif(&dc,m_pImgBuffer,m_nFileLen,380,30);
				m_pImgBuffer=NULL;
				temp1->MovePrevious();
			}	
			if(temp1->BOF)
				MessageBox("浏览完毕!","提示",64);
			m_button2.EnableWindow();
			m_button1.EnableWindow(FALSE);
		}
		else
		{
			MessageBox("暂时还没有添加该用户的照片!","提示",64);
			return;
		}
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.ErrorMessage());	
	}
}



void CSystemDlg::OnBrnNext() 
{
	_RecordsetPtr temp1=theApp.datamanage->Record1;
	temp1->raw_Close();
	CString sql;
	sql.Format("select * from tbTEXTINFO where Tid='%s'",str1);
	temp1->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	if(temp1->RecordCount>0)
	{		
		temp1->MoveFirst();
		while(!temp1->adoEOF)
		{
			CString TextPathName=temp1->GetCollect("Tpathname").bstrVal;
			LoadImgFile(TextPathName);
			CClientDC dc(this); 
			ShowJpgGif(&dc,m_pImgBuffer,m_nFileLen,380,30);
			m_pImgBuffer=NULL;
			temp1->MoveNext();
		}	
		if(temp1->adoEOF)
		MessageBox("浏览完毕!","提示",64);
		m_button1.EnableWindow();
		m_button2.EnableWindow(FALSE);
	}
	else
	{
		MessageBox("暂时还没有添加该用户的照片!","提示",64);
		return;
	}
}



void CSystemDlg::OnBtnTextToData() 
{
	m_ShowInformation.SetWindowText("");
	CString str1,str2;
	m_Bnumber.GetWindowText(str1);
	m_Bname.GetWindowText(str2);
	CString str;
	CFile fileMultiOpen;
	static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|All Files (*.*)|*.*||";
	CFileDialog dlg(TRUE,0,0,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING,szFilter);
	dlg.m_ofn.lpstrFile=str.GetBuffer(10000);
	str.ReleaseBuffer();
	dlg.m_ofn.nMaxFile=7000;
	Invalidate();
	if(dlg.DoModal()==IDOK)
	{	
		POSITION pos=dlg.GetStartPosition();
		while(pos!=NULL)
		{
			CString strFileName=dlg.GetNextPathName(pos);
			AddSomeTextToData(str1,strFileName);
		}
		Invalidate();
		MessageBox("批量添加完毕!","提示",64);
	}
	else
		return;
}






void CSystemDlg::TextFromDataToWindow(CString str)
{
	temp12=theApp.datamanage->Record1;
	temp12->raw_Close();
	CString sql;
	sql.Format("select * from tbTEXTINFO where Tid='%s'",str);
	temp12->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
	if(temp12->RecordCount>0)
	{		
		TextPathName="";
		temp12->MoveFirst();
		TextPathName=temp12->GetCollect("Tpathname").bstrVal;
		LoadImgFile(TextPathName);
		CClientDC dc(this); 
		ShowJpgGif(&dc,m_pImgBuffer,m_nFileLen,380,30);
		m_pImgBuffer=NULL;	
	}
	else
	{
		MessageBox("暂时还没有添加该用户的照片!","提示",64);
		return;
	}
}



BOOL CSystemDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	CString sClassName;
	::GetClassName(pWnd->GetSafeHwnd(),sClassName.GetBuffer(80),80);
	if (sClassName=="Button" && m_cursor) 
	{
		::SetCursor(m_cursor);	
		return TRUE;
	}		
	return CDialog::OnSetCursor(pWnd, nHitTest, message);
}





void CSystemDlg::OnBtnStopTrans() 
{
	try
	{	
		TextPathName="";
		temp12->MoveNext();
		TextPathName=temp12->GetCollect("Tpathname").bstrVal;
		LoadImgFile(TextPathName);
		CClientDC dc(this); 
		ShowJpgGif(&dc,m_pImgBuffer,m_nFileLen,380,30);
		m_pImgBuffer=NULL;	
		m_bpre.EnableWindow();
		if(temp12->adoEOF)
		{
			temp12->MoveLast();	
		}
	}
	catch(...)
	{
		m_button21.EnableWindow(FALSE);
	}
}



void CSystemDlg::OnBtnOnePictureTran() 
{	
	try
	{	
		TextPathName="";
		temp12->MovePrevious();
		TextPathName=temp12->GetCollect("Tpathname").bstrVal;
		LoadImgFile(TextPathName);
		CClientDC dc(this); 
		ShowJpgGif(&dc,m_pImgBuffer,m_nFileLen,380,30);
		m_pImgBuffer=NULL;
		m_button21.EnableWindow();
		if(temp12->BOF)
		{
			temp12->MoveFirst();	
		}
	}
	catch(...)
	{
		m_bpre.EnableWindow(FALSE);
	}
}



void CSystemDlg::OnOK()
{

}

BOOL CSystemDlg::PreTranslateMessage(MSG* pMsg) 
{	
	return CDialog::PreTranslateMessage(pMsg);
}





void CSystemDlg::OnTimer(UINT nIDEvent) 
{	
	CRect dlgRect;
	GetWindowRect(dlgRect);
	CRect desktopRect;
	GetDesktopWindow()->GetWindowRect(desktopRect);
	if(nIDEvent==1)
	{
		MoveWindow((-dx+desktopRect.Width()-dlgRect.Width())/2,
			(-dy+desktopRect.Height()-dlgRect.Height())/2,
			+dx+dlgRect.Width(),
			+dy+dlgRect.Height());
		if(dlgRect.Width()>=nWidth) 
			dx=0; // do not over grow
		if(dlgRect.Height()>=nHeight)
			dy=0; // do not over grow
		if((dlgRect.Width()>=nWidth)&&(dlgRect.Height()>=nHeight))
			KillTimer(1); //Stop the timer
	}
	if((dlgRect.Width() >=nWidth) && (dlgRect.Height() >=nHeight))
		KillTimer(1); //Stop the timer
	if(nIDEvent == 2)
	{
		MoveWindow((+dx+desktopRect.Width() - dlgRect.Width()) / 2,
			(+dy+desktopRect.Height() - dlgRect.Height()) / 2,
			-dx1+dlgRect.Width(),
			-dy1+dlgRect.Height());
		if(dlgRect.Width() <= 0) 
			dx1=0;// do not over grow
		if(dlgRect.Height()<=0)
			dy1=0;// do not over grow
		if((dlgRect.Width() <= 0 ) && (dlgRect.Height()<=0))
		{KillTimer(2); //Stop the timer
		CDialog::OnOK();
		}
	}
	CDialog::OnTimer(nIDEvent);
}






void CSystemDlg::AddSomeTextToData(CString strx, CString strz)
{	
	CString sql;
	sql.Format("insert into tbTEXTINFO(Tid,Tpathname) values('%s','%s')",strx,strz);			
	theApp.datamanage->ExecSQL(sql);
}

⌨️ 快捷键说明

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