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

📄 vchomeworkdlg.cpp

📁 本程序界面采用基于对话框技术,并用ADO数据库技术
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// VcHomeworkDlg.cpp : implementation file
//

#include "stdafx.h"
#include "VcHomework.h"
#include "VcHomeworkDlg.h"
#include "DlgWelcome.h"
#include "PowerDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVcHomeworkDlg dialog

CVcHomeworkDlg::CVcHomeworkDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CVcHomeworkDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVcHomeworkDlg)
	m_str1 = _T("");
	m_str2 = _T("");
	m_str3 = _T("");
	m_radio1 = -1;
	m_radio2 = -1;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_conn = NULL;
	flag = 1;
	m_mark = 1;
	m_Eflag = 0;
}

void CVcHomeworkDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVcHomeworkDlg)
	DDX_Control(pDX, IDC_LIST_INFO, m_info);
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Text(pDX, IDC_EDIT1, m_str1);
	DDX_Text(pDX, IDC_EDIT2, m_str2);
	DDX_Text(pDX, IDC_EDIT3, m_str3);
	DDX_Radio(pDX, IDC_RADIO1, m_radio1);
	DDX_Radio(pDX, IDC_RADIO5, m_radio2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CVcHomeworkDlg, CDialog)
	//{{AFX_MSG_MAP(CVcHomeworkDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
	ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
	ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
	ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
	ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
	ON_BN_CLICKED(IDC_RADIO8, OnRadio8)
	ON_NOTIFY(NM_CLICK, IDC_LIST_INFO, OnClickListInfo)
	ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
	ON_BN_CLICKED(IDC_BUTTON_ABOUT, OnButtonAbout)
	ON_BN_CLICKED(IDC_BUTTON_FIT, OnButtonFit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVcHomeworkDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	CoInitialize(NULL);
	CDlgWelcome dlg;
	if(dlg.DoModal()==IDCANCEL)
        EndDialog(0);
	CString sql;
	try
	{
		m_conn.CreateInstance(__uuidof(Connection));
		
		sql.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Manage.mdb");
		_bstr_t sql_=sql;
		m_conn->Open(sql_,"","",-1);
	}
    catch(_com_error& e)
	{
		AfxMessageBox(e.ErrorMessage());
		this->EndDialog(0);
			
	}
	m_radio1 = 0;
	UpdateData(FALSE);
    if(m_radio1 == 0)
	{
		CString str1,str2,str3;
		str1 = "客户ID";
		str2 = "客户姓名";
		str3 = "客户单位";
		SetDlgItemText(IDC_STATIC1,str1);
		SetDlgItemText(IDC_STATIC2,str2);
		SetDlgItemText(IDC_STATIC3,str3);
	}

	m_list.InsertColumn(0,"客户ID");
	m_list.InsertColumn(1,"客户姓名");
	m_list.InsertColumn(2,"客户单位");
    RECT rect;
	m_list.GetWindowRect(&rect);
	int wid = rect.right - rect.left;
	m_list.SetColumnWidth(0,wid/3);
	m_list.SetColumnWidth(1,wid/3);
	m_list.SetColumnWidth(2,wid/3);

	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	Refurbish();
	m_radio2 = 0;
	UpdateData(FALSE);
	RECT rect1;
	
	m_info.DeleteColumn(0);
	m_info.InsertColumn(0,"客户ID");
	m_info.GetWindowRect(&rect1);
    int wid1 = rect1.right - rect1.left;
	m_info.SetColumnWidth(0,wid1);
	m_info.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	m_info.DeleteAllItems();
	m_info.SetRedraw(FALSE);
	_bstr_t str1("select * from client");
	_variant_t temp;
	try
	{ 
		int i = 0;
	    m_Ptr.CreateInstance(__uuidof(Recordset));
		m_Ptr = m_conn->Execute(str1,NULL,adCmdText);
		m_Ptr->MoveFirst();
		while(!m_Ptr->adoEOF)
		{
			temp = m_Ptr->GetCollect("客户ID");
			if(temp.vt != VT_NULL)
			   m_info.InsertItem(i,(char*)(_bstr_t)temp);
			m_Ptr->MoveNext();
		}
        m_Ptr->Close();
	}
    catch(_com_error& e)
	{
		 AfxMessageBox(e.ErrorMessage());
	}
	m_info.SetRedraw(TRUE);
	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CVcHomeworkDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

void CVcHomeworkDlg::OnDestroy()
{
	WinHelp(0L, HELP_QUIT);
	CDialog::OnDestroy();
//	if(m_connect->GetState())
	m_conn->Close();
	CoUninitialize();

}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CVcHomeworkDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CVcHomeworkDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CVcHomeworkDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	CString str1,str2,str3;
	str1 = "客户ID";
	str2 = "客户姓名";
	str3 = "客户单位";
	SetDlgItemText(IDC_STATIC1,str1);
	SetDlgItemText(IDC_STATIC2,str2);
	SetDlgItemText(IDC_STATIC3,str3);
	m_radio1 = 0;
	flag = 1;
	
	m_list.DeleteColumn(0);
	m_list.DeleteColumn(1);
	m_list.DeleteColumn(2);
	m_list.InsertColumn(0,"客户ID");
	m_list.InsertColumn(1,"客户姓名");
	m_list.InsertColumn(2,"客户单位");
    RECT rect;
	m_list.GetWindowRect(&rect);
	int wid = rect.right - rect.left;
	m_list.SetColumnWidth(0,wid/3);
	m_list.SetColumnWidth(1,wid/3);
	m_list.SetColumnWidth(2,wid/3);
    m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	Refurbish();
	m_str1 = "";
	m_str2 = "";
	m_str3 = "";
	UpdateData(FALSE);

}

void CVcHomeworkDlg::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	CString str1,str2,str3;
	str1 = "样品ID";
	str2 = "客户ID";
	str3 = "仪器ID";
	SetDlgItemText(IDC_STATIC1,str1);
	SetDlgItemText(IDC_STATIC2,str2);
	SetDlgItemText(IDC_STATIC3,str3);
	m_radio1 = 1;
	flag = 2;
	
	m_list.DeleteColumn(0);
	m_list.DeleteColumn(1);
	m_list.DeleteColumn(2);
	m_list.InsertColumn(0,"样品ID");
	m_list.InsertColumn(1,"客户ID");
	m_list.InsertColumn(2,"仪器ID");
    RECT rect;
	m_list.GetWindowRect(&rect);
	int wid = rect.right - rect.left;
	m_list.SetColumnWidth(0,wid/3);
	m_list.SetColumnWidth(1,wid/3);
	m_list.SetColumnWidth(2,wid/3);

	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	Refurbish();
	m_str1 = "";
	m_str2 = "";
	m_str3 = "";
	UpdateData(FALSE);

}

void CVcHomeworkDlg::OnRadio3() 
{
	// TODO: Add your control notification handler code here
	CString str1,str2,str3;
	str1 = "仪器ID";
	str2 = "仪器类型";
	str3 = "仪器型号";
	SetDlgItemText(IDC_STATIC1,str1);
	SetDlgItemText(IDC_STATIC2,str2);
	SetDlgItemText(IDC_STATIC3,str3);
	m_radio1 = 2;
	flag = 3;
	
	m_list.DeleteColumn(0);
	m_list.DeleteColumn(1);
	m_list.DeleteColumn(2);
	m_list.InsertColumn(0,"仪器ID");
	m_list.InsertColumn(1,"仪器类型");
	m_list.InsertColumn(2,"仪器型号");
    RECT rect;
	m_list.GetWindowRect(&rect);
	int wid = rect.right - rect.left;
	m_list.SetColumnWidth(0,wid/3);
	m_list.SetColumnWidth(1,wid/3);
	m_list.SetColumnWidth(2,wid/3);

	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	Refurbish();
	m_str1 = "";
	m_str2 = "";
	m_str3 = "";
	UpdateData(FALSE);

}

void CVcHomeworkDlg::OnRadio4() 
{
	// TODO: Add your control notification handler code here
	CString str1,str2,str3;
	str1 = "样品ID";
	str2 = "自变量X";
	str3 = "因变量Y";
	SetDlgItemText(IDC_STATIC1,str1);
	SetDlgItemText(IDC_STATIC2,str2);
	SetDlgItemText(IDC_STATIC3,str3);
	m_radio1 = 3;
	flag = 4;
	
	m_list.DeleteColumn(0);
	m_list.DeleteColumn(1);
	m_list.DeleteColumn(2);
	m_list.InsertColumn(0,"样品ID");
	m_list.InsertColumn(1,"自变量X");
	m_list.InsertColumn(2,"因变量Y");
    RECT rect;
	m_list.GetWindowRect(&rect);
	int wid = rect.right - rect.left;
	m_list.SetColumnWidth(0,wid/3);
	m_list.SetColumnWidth(1,wid/3);
	m_list.SetColumnWidth(2,wid/3);

	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	Refurbish();
	m_str1 = "";
	m_str2 = "";
	m_str3 = "";
	UpdateData(FALSE);

}

void CVcHomeworkDlg::Refurbish()
{
  switch(flag)
  {
  case 1:
	  {
		  m_list.DeleteAllItems();
	      m_list.SetRedraw(FALSE);
           _bstr_t SQL("SELECT* FROM client");
	      _RecordsetPtr Ptr;
	      int i=0;
	      try
		  {  
		     Ptr.CreateInstance(__uuidof(Recordset));
		     Ptr = m_conn->Execute(SQL,NULL,adCmdText);
		     _variant_t roader;
		     while(!Ptr->adoEOF)
			 {
                roader = Ptr->GetCollect("客户ID");
			    if(roader.vt != VT_NULL)
				  m_list.InsertItem(i,(char*)(_bstr_t)roader);

⌨️ 快捷键说明

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