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

📄 store.cpp

📁 企业库存管理系统, 企业库存管理系统
💻 CPP
字号:
// Store.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Store.h"

#include "MainFrm.h"
#include "StoreDoc.h"
#include "StoreView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStoreApp

BEGIN_MESSAGE_MAP(CStoreApp, CWinApp)
	//{{AFX_MSG_MAP(CStoreApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStoreApp construction

CStoreApp::CStoreApp()
{
	// TODO: add construction code here,
	TreeConnString=_T("Data Source=SaleData;UID=sa;PWD=;");
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CStoreApp object

CStoreApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CStoreApp initialization

BOOL CStoreApp::InitInstance()
{
	AfxOleInit();
	/******************连接通讯录数据库********************/
    HRESULT hRes;
	try
	{
        hRes=m_pConn.CreateInstance(_T("ADODB.Connection"));
		m_pConn->ConnectionTimeout = 8;
		//连接ACCESS2000
		hRes=m_pConn->Open(_bstr_t((LPCTSTR) TreeConnString),
            _T(""),_T(""),adModeUnknown);
	}
	catch(_com_error e)///捕捉异常
	{
		 CString errormessage;
		 errormessage.Format(_T("连接SaleData数据库失败!\r\n错误信息:%s"),e.ErrorMessage());
		 AfxMessageBox(errormessage);///显示错误信息
         return FALSE;
	} 
//	CLand dlg;
//	if(dlg.DoModal()==IDOK)
//	{
//		return false;
//	}
	CString strSQL;
	strSQL="select * from IDTable";
	hRes = m_pIDRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hRes))
	{
		hRes = m_pIDRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
		if(SUCCEEDED(hRes))
		{
			TRACE(_T("连接成功!\n"));
		}
 	}
	AfxEnableControlContainer();


	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CStoreDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CStoreView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}

CString CStoreApp::ToStringCTime(COleDateTime ct)
{
	CString str;
	str.Format("%d-%d-%d",ct.GetYear(),ct.GetMonth(),ct.GetDay());

	return str;
}
CString CStoreApp::VariantToCString(VARIANT var)
{
	CString strValue;
	_variant_t var_t;
	_bstr_t bst_t;
	time_t cur_time;
	CTime time_value;
	COleCurrency var_currency;
	switch(var.vt)
	{
	case VT_EMPTY:strValue=_T("");break;
	case VT_UI1:strValue.Format ("%d",var.bVal);break;
	case VT_I2:strValue.Format ("%d",var.iVal );break;
	case VT_I4:strValue.Format ("%d",var.lVal);break;
	case VT_R4:strValue.Format ("%f",var.fltVal);break;
	case VT_R8:strValue.Format ("%f",var.dblVal);break;
	case VT_CY:
		var_currency=var;
		strValue=var_currency.Format(0);
		break;
	case VT_BSTR:
		var_t=var;
		bst_t=var_t;
		strValue.Format ("%s",(const char*)bst_t);
		break;
	case VT_NULL:strValue=_T("");break;
	case VT_DATE:
		cur_time=var.date;
		time_value=cur_time;
		strValue=time_value.Format("%A,%B%d,%Y");
		break;
	case VT_BOOL:strValue.Format ("%d",var.boolVal );break;
	default:strValue=_T("");break;
	}
	return strValue;
}


CString CStoreApp::GetStringFromVariant(_variant_t var)
{
	return var.vt==VT_NULL?"":(char*)(_bstr_t)var;
}

/////////////////////////////////////////////////////////////////////////////
// CSaleApp message handlers

int CStoreApp::compareTwoCString(CString str1,CString str2)
{
	int len=str1.GetLength();
	int i;
	for(i=0;i<len;i++)
		if(str1.GetAt(i)!=str2.GetAt(i))
			break;
	if(i==len)
		return 0;
	
}


/////////////////////////////////////////////////////////////////////////////
// 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)
		// No message handlers
	//}}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()

// App command to run the dialog
void CStoreApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CStoreApp message handlers

⌨️ 快捷键说明

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