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

📄 timeview.cpp

📁 我上载了那么多怎么都说已经有上载的啦
💻 CPP
字号:
// TimeView.cpp : implementation file
//

#include "stdafx.h"
#include "gpmis.h"
#include "TimeView.h"
#include "mainfrm.h"
#include "global.h"
#include "bcmenu.h"
#include "SpreadSheet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTimeView
extern CGPMISApp theApp;

#define NUM1_COLUMNS	5

static _TCHAR *_gszLabel1[NUM1_COLUMNS] =
{
    _T("周数"), _T("时间"), _T("任务"), _T("负责人"), _T("备注")
};
static int _gnFmt1[NUM1_COLUMNS] = 
{
	LVCFMT_LEFT, LVCFMT_CENTER , LVCFMT_CENTER, LVCFMT_CENTER, LVCFMT_CENTER
};
static int _gnWidth1[NUM1_COLUMNS] = 
{
	75, 145, 360, 105, 90
};

IMPLEMENT_DYNCREATE(CTimeView, CListVwEx)

CTimeView::CTimeView()
{
	m_strTerm = "";
}

CTimeView::~CTimeView()
{
}


BEGIN_MESSAGE_MAP(CTimeView, CListVwEx)
	//{{AFX_MSG_MAP(CTimeView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimeView drawing

void CTimeView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
	PrintList(pDC);
}

/////////////////////////////////////////////////////////////////////////////
// CTimeView diagnostics

#ifdef _DEBUG
void CTimeView::AssertValid() const
{
	CListVwEx::AssertValid();
}

void CTimeView::Dump(CDumpContext& dc) const
{
	CListVwEx::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTimeView message handlers

void CTimeView::OnInitialUpdate() 
{
	CListVwEx::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	DrawLabel();
	DrawList();
	
	BOOL bCanEdit[64];
	bCanEdit[0] = FALSE;	
	bCanEdit[1] = FALSE;	
	bCanEdit[2] = FALSE;	
	bCanEdit[3] = FALSE;	
	bCanEdit[4] = FALSE;	
	bCanEdit[5] = FALSE;	
	bCanEdit[6] = FALSE;	
	bCanEdit[7] = FALSE;	
	bCanEdit[8] = FALSE;	
	bCanEdit[9] = FALSE;	
	SetCanEdit(bCanEdit);

	GetListCtrl().SetExtendedStyle(LVS_EX_GRIDLINES);

}

void CTimeView::DrawLabel()
{
	int i;
	LV_COLUMN lvc;
	CListCtrl& ListCtrl = GetListCtrl();

	// delete columns
	int sum = NUM1_COLUMNS;
	_TCHAR **szLabel = _gszLabel1;
	int *nWidth = _gnWidth1;
	int *nFmt = _gnFmt1;

	for(i = 0; i<NUM1_COLUMNS; i++)
	{
		ListCtrl.DeleteColumn(0);
	}

	// insert columns
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

	for(i = 0; i<sum; i++)
	{
		lvc.iSubItem = i;
		lvc.pszText = szLabel[i];
		lvc.cx = nWidth[i];
		lvc.fmt = nFmt[i];
		ListCtrl.InsertColumn(i,&lvc);
	}

	SetSortFirstCol(TRUE);
	ListCtrl.EnableToolTips(TRUE);
}

extern const char* TermItem[];
void CTimeView::DrawList()
{
	LV_ITEM lvi;
	CListCtrl& ListCtrl = GetListCtrl();
	char cNum[100];

	// delete list items
	ListCtrl.DeleteAllItems();

	lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
	lvi.iSubItem = 0;
	lvi.iImage = 0;
	lvi.stateMask = LVIS_STATEIMAGEMASK;
	lvi.state = INDEXTOSTATEIMAGEMASK(1);
	
	char szPath[MAX_PATH];
	sprintf(szPath,"%s\\Document\\Plan.xls",theApp.GetWorkDirectory());

	const char* title[] = { "周数",  "任务",  "负责人",  "备注", "\0" };
	
	CSpreadSheet SS(szPath, "Sheet1");
	CStringArray Rows;
	int nCount = 0;
	BOOL bDisplay = FALSE;;

	CString strContents[5];
	int rowCount = SS.GetTotalRows();


	CString strTerm7;
	theApp.GetRegistryValue("Parameters\\Term","7",strTerm7,"2006-9-11");
	CString strTerm8;
	theApp.GetRegistryValue("Parameters\\Term","8",strTerm8,"2007-2-19");
	char szTemp[20];
	strcpy(szTemp, strTerm7);
	int y7, m7, d7;
	sscanf(szTemp, "%d-%d-%d", &y7, &m7, &d7);
	CTime t7 = CTime(y7, m7, d7, 0, 0, 0);

	strcpy(szTemp, strTerm8);
	int y8, m8, d8;
	sscanf(szTemp, "%d-%d-%d", &y8, &m8, &d8);
	CTime t8 = CTime(y8, m8, d8, 0, 0, 0);

	CTime ts = t8;
	if( m_strTerm == "" || m_strTerm == TermItem[0] )
	{
		bDisplay = TRUE;
		ts = t7;
	}

	int k = 0;
	SetClrArraySize(rowCount);
	int nClr = -1;
	for (int i = 2; i <= rowCount; i++)
	{
		// 读取一行
		SS.ReadRow(Rows, i);
		for (int j = 0; j < 4; j++)
		{
			strContents[j] = Rows.GetAt(j);
		}

		if( m_strTerm == "" && strContents[1] == "" )
		{
			ts = t8;
		}
		if( strContents[1] == "" && m_strTerm == TermItem[0] )
		{
			bDisplay = FALSE;
			continue;
		}
		if( bDisplay == FALSE && strContents[1] == "" && m_strTerm == TermItem[1] )
		{
			bDisplay = TRUE;
			continue;
		}


		if( bDisplay )
		{
			if( strContents[0] != "" )
			{
				if( nClr == -1 || (nClr%10) == 1 )
					nClr = 0;
				else if( (nClr%10) == 0 )
					nClr = 1;
			}
			if( strContents[0] == ""  && strContents[1] == "" )
			{
				nClr = -1;
			}
			if( nClr == -1 )
				SetRowClr(k, RGB(255,255,255));
			if( nClr == 0 )
				SetRowClr(k, LIGHT_YELLOW);
			if( nClr == 1 )
				SetRowClr(k, LIGHT_BLUE);
			if( nClr >= 10 )
				SetRowClr(k, LIGHT_RED);

			sprintf(cNum,"%s",strContents[0]);
			lvi.iItem = k;
			lvi.pszText = (LPTSTR)cNum;
			ListCtrl.InsertItem(&lvi);

			if( strContents[0] != "" )
			{
				if( strContents[0].Find("周") > 0 )
				{
					CTime t1, t2;
					CString strTime;
					if( strContents[0].Find("第") == 0 )
					{
						CString sTemp = strContents[0].Mid(2, strContents[0].GetLength() -4);
						int index = sTemp.Find("-");
						int n1 = 0;
						int n2 = 0;
						if( index > 0 )
						{
							n1 = atoi(sTemp.Left(index))-1;
							n2 = atoi(sTemp.Mid(index+1))-1;
						}
						else
						{
							n1 = n2 = atoi(sTemp) - 1;
						}
						t1 = ts + CTimeSpan(n1*7,0,0,0);
						t2 = ts + CTimeSpan(n2*7+6,0,0,0);
					}
					else
					{
						int week = 0;
						int day = 0;
						if( strContents[0].Find("前") > 0  )
						{
							strcpy(szTemp, strContents[0]);
							sscanf(szTemp,"%d周前%d天",&week, &day);
							week--;
							if( week >= 0  && day >0 )
							{
								t1 = ts + CTimeSpan(week*7,0,0,0);
								t2 = ts + CTimeSpan(week*7+day-1,0,0,0);
							}
						}
						if( strContents[0].Find("后") > 0  )
						{
							strcpy(szTemp, strContents[0]);
							sscanf(szTemp,"%d周后%d天",&week, &day);
							week--;
							if( week >= 0  && day >0 )
							{
								t1 = ts + CTimeSpan(week*7+5-day,0,0,0);
								t2 = ts + CTimeSpan(week*7+4,0,0,0);
							}
						}
					}
					if( t1.GetYear() > 2000 )
					{
						strTime.Format("%d-%d-%d  %d-%d-%d", 
							t1.GetYear(), t1.GetMonth(), t1.GetDay(),
							t2.GetYear(), t2.GetMonth(), t2.GetDay());
						ListCtrl.SetItemText(k, 1, strTime);

						if( t1 <= CTime::GetCurrentTime() && (t2 + CTimeSpan(0, 23, 59, 59))>= CTime::GetCurrentTime() )
						{
							nClr += 10;
							SetRowClr(k, LIGHT_RED);
						}
					}
				}

			}

			ListCtrl.SetItemText(k, 2, strContents[1]);
			ListCtrl.SetItemText(k, 3, strContents[2]);
			ListCtrl.SetItemText(k, 4, strContents[3]);

			k++;
		}
	}
}

void CTimeView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	CRect Rect;
	long lWidth, lHeight;

	GetClientRect(&Rect);
	lWidth = Rect.Width();
	lHeight = Rect.Height();

	PrintList(pDC);
	lHeight = m_lHeight;
	// get toolbar state
	m_nPageWidth  = pDC->GetDeviceCaps(HORZRES);
	m_nPageHeight = pDC->GetDeviceCaps(VERTRES);

	m_nXPage = (unsigned int)((float)lWidth*2.54+m_nPageWidth-5)/m_nPageWidth;
	m_nYPage = (unsigned int)((float)lHeight*2.54+m_nPageHeight-5)/m_nPageHeight;
	m_nXPage = (m_nXPage > 0) ? m_nXPage : 1;
	m_nYPage = (m_nYPage > 0) ? m_nYPage : 1;
	pInfo->SetMaxPage(m_nXPage*m_nYPage);
	
	CListVwEx::OnBeginPrinting(pDC, pInfo);
}

void CTimeView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CListVwEx::OnPrepareDC(pDC, pInfo);

	if(!pInfo)
		return;

	pDC->SetViewportOrg(-m_nPageWidth*((pInfo->m_nCurPage-1)/m_nYPage), -m_nPageHeight*((pInfo->m_nCurPage-1)%m_nYPage));
}

BOOL CTimeView::OnPreparePrinting(CPrintInfo* pInfo) 
{
	// TODO: call DoPreparePrinting to invoke the Print dialog box
	return DoPreparePrinting(pInfo);
	
//	return CListVwEx::OnPreparePrinting(pInfo);
}

void CTimeView::PrintList(CDC *pDC)
{
	CRect Rect1,Rect2;
	CMyListCtrl& ListCtrl = (CMyListCtrl&)GetListCtrl();
	CHeaderCtrl* pHeaderCtrl = ListCtrl.GetHeaderCtrl();
	CString strTemp, strTitle;
	int nTitleY = 10;
	int nHeight = 100;
	int nLeft, nRight;
	int sum = NUM1_COLUMNS;
	_TCHAR **szLabel;
	int *nFmt;

	szLabel = _gszLabel1;
	nFmt = _gnFmt1;

	pDC->SetMapMode(MM_ISOTROPIC );
	pDC->SetTextAlign(TA_LEFT);

	CFont* pOldFont = pDC->SelectObject(&m_ftFont);

	for( int j = 0; j<pHeaderCtrl->GetItemCount(); j++) 
	{
		pHeaderCtrl->GetItemRect(j, &Rect1);
		
		strTemp.Format("%s",szLabel[j]);
		Rect2.left = (LONG)(Rect1.left*2.54);
		Rect2.right = (LONG)(Rect1.right*2.54);
		Rect2.top = (LONG)(-Rect1.top*2.54-nHeight);
		Rect2.bottom = (LONG)(-Rect1.bottom*2.54-nHeight);
		if( nFmt[j] == LVCFMT_LEFT )
			pDC->DrawText(strTemp,Rect2,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
		if( nFmt[j] == LVCFMT_CENTER )
			pDC->DrawText(strTemp,Rect2,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		if( nFmt[j] == LVCFMT_RIGHT )
			pDC->DrawText(strTemp,Rect2,DT_RIGHT|DT_VCENTER|DT_SINGLELINE);
		pDC->MoveTo(Rect2.left, Rect2.bottom);
		pDC->LineTo(Rect2.right, Rect2.bottom);
		if( j == 0 )
			nLeft = Rect2.left;
		if( j == pHeaderCtrl->GetItemCount()-1 )
			nRight = Rect2.right;

		for( int i = 0; i<ListCtrl.GetItemCount(); i++)
		{
			ListCtrl.GetItemRect(i,&Rect2,LVIR_BOUNDS);   
			strTemp = ListCtrl.GetItemText(i,j);
			Rect2.left = (LONG)(Rect1.left*2.54);
			Rect2.right = (LONG)(Rect1.right*2.54);
			Rect2.top = (LONG)(-(Rect2.top*2.54 + 10)-nHeight);
			Rect2.bottom = (LONG)(-(Rect2.bottom*2.54 + 10)-nHeight);
			if( nFmt[j] == LVCFMT_LEFT )
				pDC->DrawText(strTemp,Rect2,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
			if( nFmt[j] == LVCFMT_CENTER )
				pDC->DrawText(strTemp,Rect2,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
			if( nFmt[j] == LVCFMT_RIGHT )
				pDC->DrawText(strTemp,Rect2,DT_RIGHT|DT_VCENTER|DT_SINGLELINE);

		}
	}
	pDC->MoveTo(nLeft, Rect2.bottom);
	pDC->LineTo(nRight, Rect2.bottom);

	pDC->SelectObject(pOldFont);

	m_lHeight = -Rect2.bottom+60;
}


⌨️ 快捷键说明

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