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

📄 fhf.cpp

📁 功能进化对于设计人员来说有着及其重要的作用
💻 CPP
字号:
// fhf.cpp : implementation file
//

#include "stdafx.h"
#include "duoshi2.h"
#include "fhf.h"

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

/////////////////////////////////////////////////////////////////////////////
// fhf dialog


fhf::fhf(CWnd* pParent /*=NULL*/)
	: CDialog(fhf::IDD, pParent)
{
	//{{AFX_DATA_INIT(fhf)
	m_text = _T("");
	//}}AFX_DATA_INIT
}


void fhf::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(fhf)
	DDX_Control(pDX, IDC_LIST3, m_list3);
	DDX_Control(pDX, IDC_LIST2, m_list2);
	DDX_Control(pDX, IDC_LIST1, m_list1);
	DDX_Text(pDX, IDC_EDIT1, m_text);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(fhf, CDialog)
	//{{AFX_MSG_MAP(fhf)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
	ON_LBN_DBLCLK(IDC_LIST2, OnDblclkList2)
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
	ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
	ON_LBN_SELCHANGE(IDC_LIST3, OnSelchangeList3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// fhf message handlers

void fhf::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}


BOOL fhf::OpenRecordSet(_RecordsetPtr &recPtr, CString &strSQL)
{
	CDuoshi2App* pApp=(CDuoshi2App*)AfxGetApp();
	//创建记录集对象
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	//在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
    //因为它有时会经常出现一些想不到的错误
	try
	{
		//从数据库中打开表
		recPtr->Open(strSQL.AllocSysString(), 
			pApp->m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);
	}
	catch (_com_error e)
	{
		CString strError;
		strError.Format("警告: 打开数据表时发生异常。 错误信息: %s",\
			e.ErrorMessage());
		AfxMessageBox(strError);
		return FALSE;
	}
	return TRUE;
}


CString fhf::VariantToCString(const _variant_t &var)
{
	CString strValue;	
	switch (var.vt)
	{
	case VT_BSTR://字符串
	case VT_LPSTR:
	case VT_LPWSTR:
		strValue = (LPCTSTR)(_bstr_t)var;
		break;
	case VT_I1://无符号字符
	case VT_UI1:
		strValue.Format("%d", var.bVal);
		break;
	case VT_I2://短整型
		strValue.Format("%d", var.iVal);
		break;
	case VT_UI2://无符号短整型
		strValue.Format("%d", var.uiVal);
		break;
	case VT_INT://整型
		strValue.Format("%d", var.intVal);
		break;
	case VT_I4: //整型
	case VT_I8: //长整型
		 strValue.Format("%d", var.lVal);
		break;
	case VT_UINT://无符号整型
		strValue.Format("%d", var.uintVal);
		break;
	case VT_UI4: //无符号整型
	case VT_UI8: //无符号长整型
		 strValue.Format("%d", var.ulVal);
		 break;
	case VT_VOID:
		strValue.Format("%8x", var.byref);
		break;
	case VT_R4://浮点型
		strValue.Format("%.4f", var.fltVal);
		break;
	case VT_R8://双精度型
		strValue.Format("%.8f", var.dblVal);
		break;
	case VT_DECIMAL: //小数
		strValue.Format("%.8f", (double)var);
		break;
	case VT_CY:
		{
			COleCurrency cy = var.cyVal;
			strValue = cy.Format();
		}
		break;
	case VT_BLOB:
	case VT_BLOB_OBJECT:
	case 0x2011:
		strValue = "[BLOB]";
		break;
	case VT_BOOL://布尔型		
		strValue = var.boolVal ? "TRUE" : "FALSE";
		break;
	case VT_DATE: //日期型
		{
			DATE dt = var.date;
			COleDateTime da = COleDateTime(dt); 
			strValue = da.Format("%Y-%m-%d %H:%M:%S");
		}
		break;
	case VT_NULL://NULL值
	case VT_EMPTY://空
		 strValue = "";
		 break;
	case VT_UNKNOWN://未知类型
	default:
		strValue = "UN_KNOW";
		break;
	}
	return strValue;
}

void fhf::OnButton1() 
{   m_list1.ResetContent();
	CString name;
    CString strSQL;
	strSQL="select 第一层 from 第一层表";

	//打开记录集 选择表名
	if(!OpenRecordSet(m_pRecordset,strSQL))
	{
		AfxMessageBox("没有成功打开数据表");
		return;
	}
	if(!m_pRecordset->BOF)
	{
		m_pRecordset->MoveFirst();
	}
	while(!m_pRecordset->adoEOF)
	{

    name=VariantToCString(m_pRecordset->GetCollect("第一层"));
	m_list1.AddString(name);
   
		m_pRecordset->MoveNext();
	}

   //关闭
	m_pRecordset->Close();
	m_pRecordset=NULL;	
    //MessageBox(name);
	
}

void fhf::OnDblclkList1() 
{
m_list2.ResetContent();
int index;
index=m_list1.GetCurSel();
index++;
CString ad;
ad.Format("%d",index);	
//MessageBox(ad);



    CString strSQL1;
//	strSQL1.Format("select * from 第二层表 where ID='%s' \
//	",\
//		ad
//		);
	strSQL1="select * from 第二层表";
	//打开记录集 选择表名
	if(!OpenRecordSet(m_pRecordset,strSQL1))
	{
		AfxMessageBox("没有成功打开数据表");
		return;
	}	
		if(!m_pRecordset->BOF)
	{
		m_pRecordset->MoveFirst();
	}
			while(!m_pRecordset->adoEOF)
			{
				if(VariantToCString(m_pRecordset->GetCollect("上层的序号"))==ad)
				{
        CString cindex1=VariantToCString(m_pRecordset->GetCollect("第二层"));
        m_list2.AddString(cindex1);

				}
				else{}
				m_pRecordset->MoveNext();
			}
	//关闭
	m_pRecordset->Close();
	m_pRecordset=NULL;
	
}

void fhf::OnDblclkList2() 
{
	m_list3.ResetContent();
	int index;
   index=m_list2.GetCurSel();
   CString term1;

   m_list2.GetText(index,term1);
  // MessageBox(term1);
  
   CString cindex1;
 
   
    CString strSQL1;
	strSQL1.Format("select * from 第二层表 where 第二层='%s' \
	",\
		term1
		);
	//打开记录集 选择表名
	if(!OpenRecordSet(m_pRecordset,strSQL1))
	{
		AfxMessageBox("没有成功打开数据表");
		return;
	}	
   cindex1=VariantToCString(m_pRecordset->GetCollect("ID"));
  
	//关闭
	m_pRecordset->Close();
	m_pRecordset=NULL;	

//	MessageBox(cindex1);



CString strSQL2;
//	strSQL1.Format("select * from 第二层表 where ID='%s' \
//	",\
//		ad
//		);
	strSQL2="select * from 第三层表";
	//打开记录集 选择表名
	if(!OpenRecordSet(m_pRecordset,strSQL2))
	{
		AfxMessageBox("没有成功打开数据表");
		return;
	}	
		if(!m_pRecordset->BOF)
	{
		m_pRecordset->MoveFirst();
	}
			while(!m_pRecordset->adoEOF)
			{
				if(VariantToCString(m_pRecordset->GetCollect("ID"))==cindex1)
				{
        CString cindex2=VariantToCString(m_pRecordset->GetCollect("第三层"));
        m_list3.AddString(cindex2);

				}
				else{}
				m_pRecordset->MoveNext();
			}
	//关闭
	m_pRecordset->Close();
	m_pRecordset=NULL;

}

void fhf::OnSelchangeList1() 
{ UpdateData(true);
	int index;
   index=m_list1.GetCurSel();
   CString term1;

   m_list1.GetText(index,term1);
   m_text=term1;
   UpdateData(false);

	
}

void fhf::OnSelchangeList2() 
{
	UpdateData(true);
	int index;
   index=m_list2.GetCurSel();
   CString term1;

   m_list2.GetText(index,term1);
   m_text=term1;
   UpdateData(false);
	
}

void fhf::OnSelchangeList3() 
{
	UpdateData(true);
	int index;
   index=m_list3.GetCurSel();
   CString term1;

   m_list3.GetText(index,term1);
   m_text=term1;
   UpdateData(false);
	
}

⌨️ 快捷键说明

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