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

📄 addrelationinfo.cpp

📁 数据库操作源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:



/*******************************************************************
函数名称:ResetCtrlValue()
函数类型:void
函数参数:无
功能描述:1.初始化各控件值
*******************************************************************/
void CAddRelationInfo::ResetCtrlValue()
{
	//初始化各控件值
	m_strComment=_T("");
	m_strComAddre=_T("");
	m_strComName=_T("");
	m_strEmail=_T("");
	m_strHomeAddre=_T("");
	m_strHomeTel=_T("");
	m_strMobile=_T("");
	m_strOfficeTel=_T("");
	m_strWeb=_T("");
	m_strName=_T("");
	UpdateData(FALSE);
}







/*******************************************************************
函数名称:OnInitDialog() 
函数类型:void
函数参数:无
功能描述:1.初始化对话框
*******************************************************************/
BOOL CAddRelationInfo::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	
	CMainFrame* pMainFrm=(CMainFrame*)AfxGetMainWnd();
	CLeftTreeView* pLeftView;
	pLeftView=(CLeftTreeView*)pMainFrm->m_wndSplitter.GetPane(0,0);
	CTreeCtrl& treeCtrl=pLeftView->m_treeCtrl;
	HTREEITEM hRootItem,hChildItem;
	hRootItem=treeCtrl.GetRootItem();
	//初始化第一个组合框
	//此字符串变量只用于中间变量
	CString strTextTem;
	if(hRootItem)
	{
		hChildItem=treeCtrl.GetChildItem(hRootItem);
		if(hChildItem)
		{
			while(hChildItem)
			{
				//加入链表以便以后使用
				m_hItemList.AddTail(hChildItem);
				strTextTem=treeCtrl.GetItemText(hChildItem);
				//将字符串内容加入组合框
				m_ComboFirst.AddString(strTextTem);
				hChildItem=treeCtrl.GetNextSiblingItem(hChildItem);
			}
			//第一个组合框默认选择
			if(!bEdit)
			{
				m_ComboFirst.SetCurSel(0);
				m_ComboFirst.GetLBText(m_ComboFirst.GetCurSel(),m_strFirClass);
			}
			else
			{
				m_ComboSecond.SetWindowText(m_strFirClass);
			}
			//所以经过上述循环后,strText保存的是树中最后一个一级类别
		}
	}
	
	//初始化第二个组合框
	HTREEITEM hSelItem;
	POSITION pos;
	pos=m_hItemList.GetHeadPosition();
	while(pos)
	{
		hSelItem=m_hItemList.GetNext(pos);
		CString strCur;
		strCur=treeCtrl.GetItemText(hSelItem);
		//找到相应的项后,将其子项全部加入第二个组合框
		if(!m_strFirClass.Compare(strCur))
		{			
			//获取二级类别
			hChildItem=treeCtrl.GetChildItem(hSelItem);
			if(hChildItem)
			{
				while(hChildItem)
				{//获取二级类别的标题并加入组合框
					strTextTem=treeCtrl.GetItemText(hChildItem);
					//将字符串内容加入组合框
					m_ComboSecond.AddString(strTextTem);
					hChildItem=treeCtrl.GetNextSiblingItem(hChildItem);
				}
				//默认选择
				if(!bEdit)
				{
					m_ComboSecond.SetCurSel(0);
				}
				else
				{
					m_ComboSecond.SetWindowText(m_strSecClass);
				}
			}
			break;
		}
	}
	//设置对话框标题
	SetWindowText(m_strTitle);
	CEdit* pEdit=(CEdit*)GetDlgItem(IDC_NAME);
	//当前对话框是否用来编辑,姓名类别等不允许编辑
	pEdit->EnableWindow(!bEdit);
	m_ComboSecond.EnableWindow(!bEdit);
	m_ComboFirst.EnableWindow(!bEdit);
	if(bEdit)
	{
		CButton* pButton=(CButton*)GetDlgItem(IDC_INSERT_INFO);
		pButton->ShowWindow(SW_HIDE);
		pButton=(CButton*)GetDlgItem(IDOK);
		pButton->ShowWindow(SW_HIDE);
	}
	else
	{
		CButton* pButton=(CButton*)GetDlgItem(IDC_EDIT_INFO);
		pButton->ShowWindow(SW_HIDE);
		pButton=(CButton*)GetDlgItem(IDCANCEL);
		pButton->ShowWindow(SW_HIDE);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}











/*******************************************************************
函数名称:OnSelendokFirstClass()
函数类型:void
函数参数:无
功能描述:1.选中一级类别时,显示相应的病人主要信息,隐藏具体信息
*******************************************************************/
void CAddRelationInfo::OnSelendokFirstClass() 
{
	// TODO: Add your control notification handler code here
	CMainFrame* pMainFrm=(CMainFrame*)AfxGetMainWnd();
	CLeftTreeView* pLeftView;
	pLeftView=(CLeftTreeView*)pMainFrm->m_wndSplitter.GetPane(0,0);
	CTreeCtrl& treeCtrl=pLeftView->m_treeCtrl;
	HTREEITEM hChildItem,hSelItem;
	CString strText;
	m_ComboFirst.GetLBText(m_ComboFirst.GetCurSel(),strText);
	//初始化第二个组合框,,首先清除组合框中所有内容
	m_ComboSecond.ResetContent();
	POSITION pos;
	pos=m_hItemList.GetHeadPosition();
	while(pos)
	{
		hSelItem=m_hItemList.GetNext(pos);
		CString strCur;
		strCur=treeCtrl.GetItemText(hSelItem);
		//找到相应的项后,将其子项全部加入第二个组合框
		if(!strText.Compare(strCur))
		{			
			hChildItem=treeCtrl.GetChildItem(hSelItem);
			if(hChildItem)
			{
				while(hChildItem)
				{
					strText=treeCtrl.GetItemText(hChildItem);
					m_ComboSecond.AddString(strText);
					hChildItem=treeCtrl.GetNextSiblingItem(hChildItem);
				}
			}
			break;
		}
	}
	m_ComboSecond.SetCurSel(0);
}






/*******************************************************************
函数名称:OnEditInfo()  
函数类型:void
函数参数:无
功能描述:1.完成“添加”对话框中“编辑”按钮的消息响应,
            将编辑后的信息导入数据库中。
*******************************************************************/
void CAddRelationInfo::OnEditInfo() 
{
	//定义变量
	CString strSQL;
	//更新控件变量的值
	UpdateData(TRUE);
	//姓名、类别为空时返回
	m_ComboFirst.GetWindowText(m_strFirClass);
	m_ComboSecond.GetWindowText(m_strSecClass);
	m_strFirClass.Remove(' ');//删除空格
	m_strSecClass.Remove(' ');
	if(m_strFirClass.IsEmpty()||m_strSecClass.IsEmpty())
	{
		AfxMessageBox("类别不能为空");
		return;
	}
	//打开记录集 选择表名
	CString strTem;
	strTem.Format("姓名='%s' and 二级类别='%s' and 一级类别='%s'\
		",m_strName,m_strSecClass,m_strFirClass);
	strSQL="select * from info where "+strTem;
	if(!OpenRecordSet(m_pRecordset,strSQL))
	{
		AfxMessageBox("没有成功打开数据表");
		return;
	}
	if(!m_pRecordset->BOF)
	{
		m_pRecordset->MoveFirst();
	}
	//上述准备完毕,下面开始插入内容
	try
	{
		//添加数据,姓名、一级二级类别只允许添加不允许更改
//		m_pRecordset->PutCollect("姓名",_variant_t(m_strName));
		m_pRecordset->PutCollect("工作单位",_variant_t(m_strComName));
		m_pRecordset->PutCollect("单位地址",_variant_t(m_strComAddre));
		m_pRecordset->PutCollect("办公电话",_variant_t(m_strOfficeTel));
		m_pRecordset->PutCollect("家庭地址",_variant_t(m_strHomeAddre));
		m_pRecordset->PutCollect("家庭电话",_variant_t(m_strHomeTel));
		m_pRecordset->PutCollect("移动电话",_variant_t(m_strMobile));
		m_pRecordset->PutCollect("入住病区",_variant_t(m_strEmail));
		m_pRecordset->PutCollect("床位号码",_variant_t(m_strWeb));
		m_pRecordset->PutCollect("相关病历",_variant_t(m_strComment));
		//类别
/*		CString strText;
		m_ComboFirst.GetWindowText(strText);
		m_pRecordset->PutCollect("一级类别",_variant_t(strText));
		m_ComboSecond.GetWindowText(strText);
		m_pRecordset->PutCollect("二级类别",_variant_t(strText));
		*/
		//出生日期 
		COleDateTime oleTime;
		CDateTimeCtrl* pDtCtrl=(CDateTimeCtrl*)GetDlgItem(IDC_BIRTHDAY);
		pDtCtrl->GetTime(oleTime);
		m_pRecordset->PutCollect("出生日期",_variant_t(oleTime));
		//照片
		if(!m_strPhotoPath.IsEmpty())
		{
			SetFileToDb(m_pRecordset,m_strPhotoPath);
		}
		//更新数据库
		m_pRecordset->Update();		
		//当前记录移动到最后
		m_pRecordset->MoveLast();
	}
	catch(_com_error e)
	{
		CString strError;
		strError.Format("警告:插入信息时发生异常。错误信息: %s",\
			e.ErrorMessage());
		AfxMessageBox(strError);
	}
	m_pRecordset->Close();	
	m_pRecordset=NULL;	
	//编辑完成后,对话框自动消失,模拟点击OK
	WPARAM wParam=MAKEWPARAM(IDOK,BN_CLICKED);
	SendMessage(WM_COMMAND,wParam);//第三个参数为控件句柄
	//更新树
	CMainFrame* pMainFrm=(CMainFrame*)AfxGetMainWnd();
	CLeftTreeView* pLeftView;
	pLeftView=(CLeftTreeView*)pMainFrm->m_wndSplitter.GetPane(0,0);	
	pLeftView->ShowTree();
	AfxMessageBox("编辑成功");
}


⌨️ 快捷键说明

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