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

📄 sellman.cpp

📁 我自己整理的一些VC源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SellMan.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "SellMan.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "SellManDoc.h"
#include "SellManView.h"
#include "FVChild.h"
#include "FVWangluotu.h"
#include "FVAdRateCalc.h"
#include "FVSupplierAcc.h"
#include "FvJJTG.h"
#include "FVQuery.h"
#include "SupervisePrizeView.h"
#include "WageView.h"
#include "WageCountFView.h"
#include "DlgLogin.h"
#include "UsingProfile.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSellManApp

BEGIN_MESSAGE_MAP(CSellManApp, CWinApp)
	//{{AFX_MSG_MAP(CSellManApp)
	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()

/////////////////////////////////////////////////////////////////////////////
// CSellManApp construction

CSellManApp::CSellManApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSellManApp object

CSellManApp theApp;
_ConnectionPtr connection;
_RecordsetPtr recordset;
//CString strSource = "Provider=sqloledb;Data Source=gui;Initial Catalog=Pubs;User Id=sa;Password=;";
CString strSource = "Driver={SQL Server};Server=qaniu;Uid=sellman;Pwd=sellman;Database=sellman";
BOOL bConnected = FALSE;

/////////////////////////////////////////////////////////////////////////////
// CSellManApp initialization

BOOL CSellManApp::InitInstance()
{
	AfxEnableControlContainer();

	AfxOleInit();

	SYSTEMTIME sysTime;
	memset( &sysTime, 0, sizeof( SYSTEMTIME ) );
	GetLocalTime( &sysTime );
/*
	if( sysTime.wMonth > 4 || (sysTime.wMonth == 4 && sysTime.wDay > 4) )
	{
		AfxMessageBox( "测试版软件已过期,请联系开发人安装正版软件!" );
		return FALSE;
	}
*/
	CUsingProfile profile( ".\\SellMancfg.ini", "SellMan" );
	strSource = profile.GetString( "ConnectString" );

	if( strSource.IsEmpty() ) return FALSE;

	CString strTmp;
	HRESULT hr = connection.CreateInstance( _uuidof( Connection ) );
	_bstr_t source = strSource;
	_bstr_t uid("");
	_bstr_t pwd("");
	Fields * fields = NULL;
	//BSTR bstrColName;
	//VARIANT var_value;
	
	int count = 0;
	if( SUCCEEDED(hr) )
	{
		try
		{
			hr = connection->Open( source, uid, pwd, adConnectUnspecified );
			if( SUCCEEDED(hr) )
			{
				hr = recordset.CreateInstance( _uuidof( Recordset ) );
				if( SUCCEEDED(hr) )
				{
				/*	_bstr_t query( "select * from xc" );
					hr = recordset->Open( query, _variant_t((IDispatch*)connection, true), 
						adOpenDynamic, adLockUnspecified, adCmdText );
					if( SUCCEEDED(hr) )
					{
						recordset->get_Fields( &fields );
						count = fields->GetCount();
						for( long i = 0; i < count; i ++ )
						{
							hr = fields->Item[ i ]->get_Name( &bstrColName );
							strTmp = bstrColName;
							fields->Item[ i ]->get_Value( &var_value );
							strTmp = VariantToString( var_value );
						}
					}*/
					bConnected = TRUE;
				}
			}
		}
		catch( _com_error &e )
		{
			AfxMessageBox( e.ErrorMessage() );
			return FALSE;
		}
	}

	// 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(15);  // 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.

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_SELL_CHILD,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CFVChild));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_WANGLUOTU,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CFVWangluotu));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_ADRATE_CALC,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CFVAdRateCalc));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_SUPPLIERACC,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CFVSupplierAcc));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_TG_JSJL,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CFvJJTG));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_QUERY,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CFVQuery));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_SUPERVISEPRIZE,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CSupervisePrizeView));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_WAGE,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CWageView));
	AddDocTemplate(pDocTemplate);

	pDocTemplate = new CMultiDocTemplate(
		IDR_WAGECOUNT,
		RUNTIME_CLASS(CSellManDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CWageCountFView));
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

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

	cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

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

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
	pMainFrame->UpdateWindow();

	CDlgLogin dlg;
	if ( dlg.DoModal() != IDOK ) return false;

	return TRUE;
}

CString VariantToString( 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 = "";
		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 = "";
		break;
	case VT_DATE:
		cur_time   = (long)var.date;
		time_value = cur_time;
		strValue   = time_value.Format( "%A,%B%d,%Y" );
		break;
	case VT_BOOL:
		strValue.Format( "%d", var.boolVal );
		break;
	case VT_UI2:
		strValue.Format( "%d", var.uiVal );
	case VT_UI4:
		strValue.Format( "%d", var.ulVal );
	case VT_UINT:
		strValue.Format( "%d", var.uintVal );
		break;
	case VT_DECIMAL:
		_i64toa( var.decVal.Lo64, strValue.GetBuffer(0),10 );
		break;
	default:
		strValue = "";
		break;
	}
/*
	switch( var.vt )
	{
	case VT_UI1:
	case VT_I2:
	case VT_I4:
	case VT_R4:
	case VT_R8:
	case VT_BOOL:
	case VT_ERROR:
	case VT_CY:
	case VT_DATE:
	case VT_BSTR:
	case VT_BYREF|VT_DECIMAL:
	case VT_UNKNOWN:
	case VT_DISPATCH:
	case VT_ARRAY:
	case VT_BYREF|VT_UI1:
	case VT_BYREF|VT_I2:
	case VT_BYREF|VT_I4:
	case VT_BYREF|VT_R4:
	case VT_BYREF|VT_R8:
	case VT_BYREF|VT_BOOL:
	case VT_BYREF|VT_ERROR:
	case VT_BYREF|VT_CY:
	case VT_BYREF|VT_DATE:
	case VT_BYREF|VT_BSTR:
	case VT_BYREF|VT_UNKNOWN:
	case VT_BYREF|VT_DISPATCH:
	case VT_BYREF|VT_VARIANT:
	case VT_I1:
	case VT_UI2:
	case VT_UI4:
	case VT_INT:
	case VT_UINT:
	case VT_BYREF|VT_I1:
	case VT_BYREF|VT_UI2:
	case VT_BYREF|VT_UI4:
	case VT_BYREF|VT_INT:
	case VT_BYREF|VT_UINT:
	default:
		break;
	}
*/
	return strValue;

⌨️ 快捷键说明

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