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

📄 yaodlg.cpp

📁 物流单据管理系统 我本人费了两个月才完成的 是信息系统与分析的课程设计
💻 CPP
字号:
// YaoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Yao.h"
#include "YaoDlg.h"

#include "BillDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CYaoDlg dialog

CYaoDlg::CYaoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CYaoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CYaoDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CYaoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CYaoDlg)
	DDX_Control(pDX, IDC_EXIT_WINDOW, m_btExitWindow);
	DDX_Control(pDX, IDC_SALE_ADD, m_btSaleAdd);
	DDX_Control(pDX, IDC_BUY_ADD, m_btBuyAdd);
	DDX_Control(pDX, IDC_BILL_SHOW, m_btShowBill);
	DDX_Control(pDX, IDC_LIST_BILLS, m_ctrlBillsLst);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CYaoDlg, CDialog)
	//{{AFX_MSG_MAP(CYaoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUY_ADD, OnBuyAdd)
	ON_BN_CLICKED(IDC_SALE_ADD, OnSaleAdd)
	ON_BN_CLICKED(IDC_BILL_SHOW, OnBillShow)
	ON_BN_CLICKED(IDC_EXIT_WINDOW, OnExitWindow)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CYaoDlg message handlers

BOOL CYaoDlg::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
	//设置按钮风格
	m_btBuyAdd.LoadBitmaps(IDB_BUY_ADD,IDB_BUY_ADD,IDB_BUY_ADD);
	m_btBuyAdd.SetTextAlignment(CTrackLookButton::AlignRight);
	m_btSaleAdd.LoadBitmaps(IDB_SALE_ADD,IDB_SALE_ADD,IDB_SALE_ADD);
	m_btSaleAdd.SetTextAlignment(CTrackLookButton::AlignRight);
	m_btShowBill.LoadBitmaps(IDB_SHOW_BILL,IDB_SHOW_BILL,IDB_SHOW_BILL);
	m_btShowBill.SetTextAlignment(CTrackLookButton::AlignRight);
	m_btExitWindow.LoadBitmaps(IDB_EXIT,IDB_EXIT,IDB_EXIT);
	m_btExitWindow.SetTextAlignment(CTrackLookButton::AlignRight);

	//设置ListCtr列表框风格
	SetLstCtrlStyle();
	AddLstCtrlHeader();

	//罗列单据
	ListBills();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

// 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 CYaoDlg::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 CYaoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//设置列表控件的风格
void CYaoDlg::SetLstCtrlStyle()
{
	DWORD dwStyle;
	dwStyle = ::GetWindowLong(m_ctrlBillsLst.m_hWnd,GWL_STYLE);
	dwStyle |= LVS_REPORT|LVS_SHOWSELALWAYS|LVS_EDITLABELS;
	::SetWindowLong(m_ctrlBillsLst.m_hWnd,GWL_STYLE,dwStyle);
	dwStyle = m_ctrlBillsLst.GetExtendedStyle();
	dwStyle |= LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT;
	m_ctrlBillsLst.SetExtendedStyle(dwStyle);

	m_ctrlBillsLst.SetBkColor(RGB(0xFF, 0xFF, 0xE0));
	m_ctrlBillsLst.SetTextBkColor(RGB(0xFF, 0xFF, 0xE0));
}

//设置列表控件的表头
void CYaoDlg::AddLstCtrlHeader()
{
	LVCOLUMN lvColumn;
	char HeaderTxt[8][10]= {"单据编号","单据类型","录单日期","客户",
		"银行帐户","仓库","经手人","附加说明"};
	for(int i=0;i<8;i++)
	{
		lvColumn.mask = LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH|LVCF_FMT;
		lvColumn.fmt = LVCFMT_CENTER;
		lvColumn.iSubItem = i;
		lvColumn.pszText = HeaderTxt[i];
		lvColumn.cx = 110;
		m_ctrlBillsLst.InsertColumn(i,&lvColumn);
	}
}

//罗列单据
void CYaoDlg::ListBills()
{
	//先清空列表
	m_ctrlBillsLst.DeleteAllItems();

	
	CYaoApp* pApp = (CYaoApp*)AfxGetApp();
	HRESULT hr = pApp->m_pRecordset->Open("select * from bill",
		pApp->m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	if(!SUCCEEDED(hr))
	{
		AfxMessageBox("打开bill表出错");
		return;
	}

	//将数据填入表中
	LVITEM lvItem;
	lvItem.mask = LVIF_TEXT;
	int iActive = 0;
	int iItem = 0;
	while(!pApp->m_pRecordset->adoEOF)
	{
		for(int i=0;i<8;i++)
		{
			if(i==0)
				lvItem.iItem = iItem;
			else
				lvItem.iItem = iActive;
			lvItem.iSubItem = i;
			CString str;
			switch(i)
			{
			case 0://单据编号
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("id"));
				break;
			case 1://单据类型
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("type"));
				if(str == "0")
					str = "进货单";
				else if(str == "1")
					str = "销售单";
				else
					str = "未知单据";
				break;
			case 2://录单日期
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("time"));
				break;
			case 3://客户
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("client"));
				break;
			case 4://银行帐户
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("account"));
				break;
			case 5://仓库
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("storage"));
				break;
			case 6://经手人
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("operator"));
				break;
			case 7://附加说明
				str = (char*)(_bstr_t)pApp->m_pRecordset->GetCollect(_variant_t("comment"));

			}
			lvItem.pszText = str.GetBuffer(0);
			if(i==0)
				iActive = m_ctrlBillsLst.InsertItem(&lvItem);
			else
				m_ctrlBillsLst.SetItem(&lvItem);
		}
		iItem ++;
		
		pApp->m_pRecordset->MoveNext();
	}
	pApp->m_pRecordset->Close();
}


void CYaoDlg::OnBuyAdd() 
{
	CBillDlg dlg;
	dlg.m_nBillType = 0;
	dlg.DoModal();
	ListBills();
}

void CYaoDlg::OnSaleAdd() 
{
	CBillDlg dlg;
	dlg.m_nBillType = 1;
	dlg.DoModal();
	ListBills();
}

//查看单据
void CYaoDlg::OnBillShow() 
{
	POSITION pos = m_ctrlBillsLst.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nFirstSelItem = m_ctrlBillsLst.GetNextSelectedItem(pos);
		CBillDlg dlg;
		dlg.m_bShowBill = TRUE;

		//判断单据类型
		CString strBillType = m_ctrlBillsLst.GetItemText(nFirstSelItem,1);
		if( strBillType== "进货单" )
			dlg.m_nBillType = 0;
		else if( strBillType== "销售单" )
			dlg.m_nBillType = 1;
		else
		{
			AfxMessageBox("未知单据类型,不能查看");
			return;
		}

		//设置单据号
		dlg.m_strBillID = m_ctrlBillsLst.GetItemText(nFirstSelItem,0);
		dlg.DoModal();
	}
	else
	{
		AfxMessageBox("请选择一张单据!");
		return;
	}
}

//退出程序
void CYaoDlg::OnExitWindow() 
{
	CDialog::OnCancel();	
}

⌨️ 快捷键说明

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