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

📄 templistcanediteddlg.cpp

📁 本人为出租屋编写的电费管理程序,应用了MFC DAO链接了ACCESS数据库,利用可编辑的listctrl控件,综合考虑了多房间线损耗电的业务细节 和 界面皮肤美观,灵活方便的将物业电费管理轻松掌控.
💻 CPP
字号:
// tempListCanEditedDlg.cpp : implementation file
//

#include "stdafx.h"
#include "tempListCanEdited.h"
#include "tempListCanEditedDlg.h"

#include "math.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTempListCanEditedDlg dialog



CTempListCanEditedDlg::CTempListCanEditedDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTempListCanEditedDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTempListCanEditedDlg)
	m_time = _T("");
	m_LMdianbiao = 0;
	m_totalFenbiao = 0;
	m_tmdianbiao = 0;
	m_tmdushu = 0;
	m_zongtanxiao = 0;
	m_daitanxiao = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTempListCanEditedDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTempListCanEditedDlg)
	DDX_Text(pDX, IDC_TIME, m_time);
	DDX_Text(pDX, IDC_LMdianbiao, m_LMdianbiao);
	DDX_Text(pDX, IDC_FENBIAOHE, m_totalFenbiao);
	DDX_Text(pDX, IDC_TMZONGBIAO, m_tmdianbiao);
	DDX_Text(pDX, IDC_TMDUSHU, m_tmdushu);
	DDX_Text(pDX, IDC_ZONGTANXIAO, m_zongtanxiao);
	DDX_Text(pDX, IDC_DAITANXIAO, m_daitanxiao);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTempListCanEditedDlg, CDialog)
	//{{AFX_MSG_MAP(CTempListCanEditedDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnPrintPreview)
	ON_EN_KILLFOCUS(IDC_TIME, OnKillfocusTime)
	ON_EN_KILLFOCUS(IDC_TMZONGBIAO, OnKillfocusTmzongbiao)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_BEGIN_PRINTING,OnBeginPrinting)
	ON_MESSAGE(WM_END_PRINTING,OnEndPrinting)
	ON_MESSAGE(WM_MY_PRINT,OnMyPrint)
	
	
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTempListCanEditedDlg message handlers

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

	// 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
	this->ShowWindow(SW_SHOWMAXIMIZED);
	m_fillList.InitDB();
	
	
	
	
	CRect rect_nlist(10,300,700,650);
	this->GetClientRect(&rect_nlist);
	


	rect_nlist.top=200;
	rect_nlist.left+=10;
	rect_nlist.right-=10;
	rect_nlist.bottom=560;


	m_list = new CEditedListCtrl;
	m_list->Create(WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_REPORT,rect_nlist,this,ID_NEWLIST);

	m_list->ModifyStyle(LVS_EDITLABELS,0L);   //禁止标题编辑
	m_list->ModifyStyle(0L,LVS_REPORT);
	m_list->ModifyStyle(0L,LVS_SHOWSELALWAYS);
	m_list->ModifyStyle(0L,LVS_NOSORTHEADER);


	m_list->ModifyStyle(LVS_OWNERDRAWFIXED,0L);
	m_list->SetExtendedStyle(LVS_EX_FULLROWSELECT|
		                     LVS_EX_GRIDLINES|
							 LVS_EX_FLATSB
							);
	
	m_list->InsertColumn(0,"房间号");
	m_list->InsertColumn(1,"本月电表数");
	m_list->InsertColumn(2,"上月电表数");
	m_list->InsertColumn(3,"实际用电数");
	m_list->InsertColumn(4,"实际电费");
	m_list->InsertColumn(5,"上月收缴电费");
	m_list->InsertColumn(6,"上月分摊费");
	m_list->InsertColumn(7,"本月分摊费");
	m_list->InsertColumn(8,"本月收缴电费");
	
	RECT rect2;
	m_list->GetWindowRect(&rect2);
	int wid=rect2.right - rect2.left;
	

	for(int i=0; i<9; i++ )
	{

		
		m_list->SetColumnWidth( i, wid/9 );
	}
	
	m_fillList.CFillListOnLastMonth();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CTempListCanEditedDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CString _housenum,_lmdianbiaonum,_lmdianfei,_lmfentanfei;
	m_list-> DeleteAllItems();
	
	POSITION pos=m_fillList.lastMonthRDList.GetHeadPosition();
//	POSITION endPos=theApp.Analysis->InstantRDList.GetTailPosition();
//	if(pos==endPos)
//		return;
	
	
	int count=m_fillList.lastMonthRDList.GetCount();
	
	int j=0;
	//填充其他行
	while(count>j)
	{
		
	   
		
	

    	lastMonthRD record;
	    //record=m_fillList.lastMonthRDList.GetHead();//取数据集第一组数据
	
	

		
    
		record=m_fillList.lastMonthRDList.GetAt(pos);	
	
		m_list->InsertItem(j,record.HouseNum);
		
		_lmdianbiaonum.Format("%d",record.LMdianbiaoNum);
		m_list->SetItemText(j,2,_lmdianbiaonum);

		_lmdianfei.Format("%.2f",record.LMdianFei);
	     m_list->SetItemText(j,5,_lmdianfei);

		 _lmfentanfei.Format("%.2f",record.LMfentanFei);
		 m_list->SetItemText(j,6,_lmfentanfei);
		
		
		
		m_fillList.lastMonthRDList.GetNext(pos);
		j++;
	}

}

 void CTempListCanEditedDlg::OnButton2() 
 {
 	// TODO: Add your control notification handler code here
 	CString _housename,_tmdianbiao,_tmshiyong,_tmdianfei,_tmfentanfei,_tmyuefen,str;
    int  dianbiao,shiyong,yuefen;
	float dianfei,fentanfei;
 	int n= m_list->GetItemCount();
 
 	for (int i=0;i<n;i++)
 	{
 		_housename = m_list->GetItemText(i,0);
 		_tmdianbiao = m_list->GetItemText(i,1);
		 dianbiao  =atoi(_tmdianbiao);
		_tmshiyong = m_list->GetItemText(i,3);
		  shiyong = atoi(_tmshiyong);
		_tmdianfei = m_list->GetItemText(i,4);
		  dianfei = atof(_tmdianfei);
		_tmfentanfei = m_list->GetItemText(i,7);
		 fentanfei = atof(_tmfentanfei);
		_tmyuefen = "200806";
		yuefen = 200806;
 	
	
	
		str.Format("INSERT INTO dianfeiGuanli(houseNum,dianbiaoNUm,shiyongNUm,dianFei,fentanFei,yuefen) VALUES('%s','%d','%d','%f','%f','%d')",_housename,dianbiao,shiyong,dianfei,fentanfei,yuefen);
////1方案	/////////////////////////////////////////////////////
		
	//  m_fillList.InitDB();
		bool temp = m_fillList.Kongzhi(yuefen,_housename);
	
		
		
		if (temp)
		{
			m_fillList.m_database.ExecuteSQL(str);
		}
		

	
	
			
	}
	
	AfxMessageBox("数据库保存完毕");
	
}

void CTempListCanEditedDlg::OnPrintPreview() 
{
	// TODO: Add your control notification handler code here
	CPrintFrame *pFrame = new CPrintFrame;
	pFrame->m_pCallerDlg = this;
	pFrame->Create(NULL,"Curve Print Preview",WS_OVERLAPPEDWINDOW,CRect(0,0,0,0));
	pFrame->m_pView->OnMyPrintPreview();
}


LRESULT CTempListCanEditedDlg::OnMyPrint(WPARAM wParam,LPARAM lParam)
{

	UINT gl_uNumOfPoints = 52;
	CDC* pDC			= (CDC*)wParam;
	CPrintInfo* pInfo	= (CPrintInfo *)lParam;
	int nPageNumber = pInfo->m_nCurPage;
	int i,j;
	CFont *pOldFont;
	CFont DataFont;
	DataFont.CreatePointFont(120,"宋体",pDC);
	if(nPageNumber==1)
	{
	
			TCHAR *pszTitle[3]={"房间号","用电度数","金额"};
			pOldFont=pDC->SelectObject(&DataFont);
			pDC->Rectangle(m_cxOffset,(int)((2.5 + PRINTMARGIN)*m_cyPrinter),m_cxOffset+m_cxWidth,(m_nLinesPerPage+3 + PRINTMARGIN)*m_cyPrinter+20);
			
			
				pDC->MoveTo(m_cxOffset+1.5*m_cxWidth/8,(int)((2.5 + PRINTMARGIN)*m_cyPrinter));
				pDC->LineTo(m_cxOffset+1.5*m_cxWidth/8,(3 +m_nLinesPerPage+PRINTMARGIN)*m_cyPrinter+20);
				pDC->MoveTo(m_cxOffset+6*m_cxWidth/8,(int)((2.5 + PRINTMARGIN)*m_cyPrinter));
				pDC->LineTo(m_cxOffset+6*m_cxWidth/8,(3 +m_nLinesPerPage+PRINTMARGIN)*m_cyPrinter+20);
			
			
			
			pDC->MoveTo(m_cxOffset,(4 + PRINTMARGIN)*m_cyPrinter);
			pDC->LineTo(m_cxOffset+m_cxWidth,(4 + PRINTMARGIN)*m_cyPrinter);
			
			
			pDC->TextOut(m_cxOffset+0.5*m_cxWidth/8,(int)((2.8 + PRINTMARGIN)*m_cyPrinter),CString(pszTitle[0]));
			pDC->TextOut(m_cxOffset+50+3*m_cxWidth/8,(int)((2.8 + PRINTMARGIN)*m_cyPrinter),CString(pszTitle[1]));
			pDC->TextOut(m_cxOffset+50+6*m_cxWidth/8,(int)((2.8 + PRINTMARGIN)*m_cyPrinter),CString(pszTitle[2]));
					
					
					
					
//			for(i=0;i<(int)m_nLinesPerPage-1;i++)
			for(i=0;i<m_list->GetItemCount();i++)
			{
				CString str[3];
			//	int nIndex = (nPageNumber-1)*(m_nLinesPerPage-1)+i;
			//	if(nIndex<(int)gl_uNumOfPoints)
			//	{
					
// 					str[0].Format("%.3f",(double)(i+1));
// 					str[1].Format("%.3f",1+sin(i));
// 					str[2].Format("%.3f",1+cos(i));
// 					str[3].Format("%.3f",1+sin(0.5*i));
// 					
// 					str[4].Format("%.3f",1+cos(0.5*i));
// 					str[5].Format("%.3f",1+sin(0.1*i));
// 					str[6].Format("%.3f",1+cos(0.1*i));
					CString temp[3];
				
					
					temp[0] = m_list->GetItemText(i,1);
					temp[1] = m_list->GetItemText(i,2);
					temp[2] = m_list->GetItemText(i,7);
					
					int s = atoi(temp[0])+atoi(temp[2])/0.65-atoi(temp[1]);
					
					
					str[0] = m_list->GetItemText(i,0);
					str[1].Format("本月%s - 上月%s = %d",temp[0],temp[1],s);
					str[2] = m_list->GetItemText(i,8);
				//	for(j=0;j<7;j++)
				//	{
						pDC->TextOut(m_cxOffset+50+0.5*m_cxWidth/8,(4 + PRINTMARGIN+i)*m_cyPrinter+5,str[0]);
						pDC->TextOut(m_cxOffset+50+3*m_cxWidth/8,(4 + PRINTMARGIN+i)*m_cyPrinter+5,str[1]);
						pDC->TextOut(m_cxOffset+50+5*m_cxWidth/8,(4 + PRINTMARGIN+i)*m_cyPrinter+5,str[2]);
						
						
				//	}
			//	}
			}
			pDC->SelectObject (pOldFont);
		
	}
/*	if(nPageNumber==2)
	{
		HBITMAP hBitmap=::LoadBitmap(AfxGetInstanceHandle(),(LPCTSTR)IDB_BITMAP1);
		BITMAP bitmap;
		::GetObject(hBitmap,sizeof(BITMAP),&bitmap);
		double dScale=(double)m_cxWidth/bitmap.bmWidth;
		int nScaledWidth=m_cxWidth;
		int nScaledHeight=(int)(bitmap.bmHeight*dScale);
		
		HDC dcMem;
		dcMem=::CreateCompatibleDC(pDC->m_hDC);
		HBITMAP hOldBmp=(HBITMAP)::SelectObject(dcMem,hBitmap);
		
		int nVertCenterPos = pDC->GetDeviceCaps (VERTRES) / 2;
		::StretchBlt(pDC->m_hDC,m_cxOffset,(4 + PRINTMARGIN)*m_cyPrinter,nScaledWidth,nScaledHeight,dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
		
		
		::SelectObject(dcMem,hOldBmp);
		::DeleteDC(dcMem);
		::DeleteObject(hBitmap);
	}*/
//	if(m_bPrintHead)
//		PrintPageHeader(pDC,pInfo->m_nCurPage,  pInfo);
	return TRUE;
}


LRESULT CTempListCanEditedDlg::OnEndPrinting(WPARAM wParam,LPARAM lParam)
{

	if(m_fontPrinter.m_hObject!=NULL)
		m_fontPrinter.DeleteObject ();
	return TRUE;
}

LRESULT CTempListCanEditedDlg::OnBeginPrinting(WPARAM wParam,LPARAM lParam)
{

	CDC* pDC			= (CDC*)wParam;
	CPrintInfo* pInfo	= (CPrintInfo *)lParam;
	if(m_fontPrinter.m_hObject==NULL)
		m_fontPrinter.CreatePointFont(120,"FixedSys",pDC);
    TEXTMETRIC tm;
    CFont* pOldFont = pDC->SelectObject (&m_fontPrinter);
    pDC->GetTextMetrics (&tm);
    m_cyPrinter = tm.tmHeight + tm.tmExternalLeading;
    CSize size = pDC->GetTextExtent (_T ("---------1---------2---------" \
        "3---------4---------5---------6---------7---------8---"), 81);
    pDC->SelectObject (pOldFont);
    m_cxWidth = size.cx;

    m_nLinesPerPage = (pDC->GetDeviceCaps (VERTRES) -
        (m_cyPrinter * (3 + (2 * PRINTMARGIN)))) / m_cyPrinter;
	pInfo->SetMaxPage (2);

    m_cxOffset = (pDC->GetDeviceCaps (HORZRES) - size.cx) / 2;
	return TRUE;
}

void CTempListCanEditedDlg::OnKillfocusTime() 
{
	// TODO: Add your control notification handler code here
	GetDlgItemText(IDC_TIME,m_time);
	
    tempTime = m_time;
	SetDlgItemText(IDC_LMdianbiao,m_fillList.GetTotalNumOnLM(atoi(m_time)-1));
}

void CTempListCanEditedDlg::OnKillfocusTmzongbiao() 
{
	// TODO: Add your control notification handler code here
	//GetDlgItemText(IDC_TMZONGBIAO,m_tmdianbiao);
	UpdateData(TRUE);
//	ASSERT(m_tmdianbiao >0);     这里我用ASSERT判断m_tmdianbiao 是否从updatedata取下了值
	
	CString str;
	str.Format("%d",m_tmdianbiao-m_LMdianbiao);
	SetDlgItemText(IDC_TMDUSHU,str);


}

⌨️ 快捷键说明

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