www.pudn.com > 数控仿真与网络控制系统.rar > InsertTimeDateDialog.cpp


// InsertTimeDateDialog.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "NoteXpad.h" 
#include "InsertTimeDateDialog.h" 
#include "NoteXpadView.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
extern BOOL CHANGED; 
///////////////////////////////////////////////////////////////////////////// 
// CInsertTimeDateDialog dialog 
 
 
CInsertTimeDateDialog::CInsertTimeDateDialog(CWnd* pParent /*=NULL*/) 
	: CDialog(CInsertTimeDateDialog::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CInsertTimeDateDialog) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CInsertTimeDateDialog::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CInsertTimeDateDialog) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CInsertTimeDateDialog, CDialog) 
	//{{AFX_MSG_MAP(CInsertTimeDateDialog) 
	ON_LBN_DBLCLK(IDC_FORMATS, OnDblclkFormats) 
	ON_LBN_SELCHANGE(IDC_FORMATS, OnSelchangeFormats) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CInsertTimeDateDialog message handlers 
 
void CInsertTimeDateDialog::OnOK()  
{ 
	CListBox* theList = (CListBox*)GetDlgItem(IDC_FORMATS); 
	CString theTime; 
	theList->GetText(theList->GetCurSel(),theTime); 
	InsertTimeDate(theTime); 
	 
	CDialog::OnOK(); 
} 
 
void CInsertTimeDateDialog::OnCancel()  
{ 
	// TODO: Add extra cleanup here 
	 
	CDialog::OnCancel(); 
} 
 
BOOL CInsertTimeDateDialog::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	CString time[7]; 
	CTime clock; 
	CListBox* theList = (CListBox*)GetDlgItem(IDC_FORMATS); 
	int Hour; 
	int Minute; 
	int Second; 
	int Month; 
	int Day; 
	int Year; 
	int DayOfWeek; 
 
	CString strMonth; 
	CString strDay; 
	clock= CTime::GetCurrentTime(); 
	Hour = clock.GetHour(); 
	Minute = clock.GetMinute(); 
	Second = clock.GetSecond(); 
	Month = clock.GetMonth(); 
	Day = clock.GetDay(); 
	Year = clock.GetYear(); 
	DayOfWeek = clock.GetDayOfWeek(); 
	strMonth = MonthFromInt(Month); 
	strDay = DayFromInt(DayOfWeek); 
	CString strAMPM = "AM"; 
	 
 
    if( Hour > 12 ) 
    { 
		strAMPM = "PM"; 
		Hour = Hour - 12; 
    } 
   CString temp; 
 
	time[0].Format("%d:",Hour); 
	time[0]= time[0] + clock.Format("%M:%S "); 
	time[0] = time[0] + strAMPM +  clock.Format(" - %m/%d/%y"); 
	time[1]= clock.Format("%m/%d/%y"); 
	time[2]= clock.Format(" %d, %y"); 
	time[2]= strMonth + time[2]; 
	time[3]= clock.Format("%m.%d.%y"); 
	time[4]=clock.Format(" %d"); 
	time[4]=strDay + ", " + strMonth + time[4]; 
 
	temp.Format("%d",Hour); 
	time[5] = temp; 
	temp= clock.Format(":%M "); 
	time[5] = time[5]+temp; 
	time[5] = time[5] + strAMPM; 
 
	for(int x =0;x < 6;x++) 
	{ 
		theList->AddString(time[x]); 
		 
	} 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
CString CInsertTimeDateDialog::MonthFromInt(int Month) 
{ 
	CString result; 
	switch (Month) 
	{ 
 
	case 1: 
		result = "January"; 
		return result; 
	case 2: 
		result = "February"; 
		return result; 
	case 3: 
		result = "March"; 
		return result; 
	case 4: 
		result = "April"; 
		return result; 
	case 5: 
		result = "May"; 
		return result; 
	case 6: 
		result = "June"; 
		return result; 
	case 7: 
		result = "July"; 
		return result; 
	case 8: 
		result = "August"; 
		return result; 
	case 9: 
		result = "September"; 
		return result; 
	case 10: 
		result = "October"; 
		return result; 
	case 11: 
		result = "November"; 
		return result; 
	case 12: 
		result = "December"; 
		return result; 
 
	} 
	return result; 
	 
} 
 
CString CInsertTimeDateDialog::DayFromInt(int Day) 
{ 
	CString result; 
 
	switch (Day) 
 
	{ 
 
	case 1: 
		result = "Sunday"; 
		return result; 
	case 2: 
		result = "Monday"; 
		return result; 
	case 3: 
		result = "Tuesday"; 
		return result; 
	case 4: 
		result = "Wednesday"; 
		return result; 
	case 5: 
		result = "Thursday"; 
		return result; 
	case 6: 
		result = "Friday"; 
		return result; 
	case 7: 
		result = "Saturday"; 
		return result; 
 
	} 
 
return result; 
 
} 
void CInsertTimeDateDialog::OnDblclkFormats()  
{ 
	OnOK(); 
	 
} 
 
void CInsertTimeDateDialog::OnSelchangeFormats()  
{ 
	CListBox* theList = (CListBox*)GetDlgItem(IDC_FORMATS); 
	CButton* InsertButton = (CButton*)GetDlgItem(IDOK); 
	CString string; 
	theList->GetText(theList->GetCurSel(),string); 
	 
	if (string != "") 
		InsertButton->EnableWindow(TRUE); 
} 
void CInsertTimeDateDialog::InsertTimeDate(CString WhatTime) 
{ 
	CString currentText; 
	CString Right; 
	CString Left; 
	int one; 
	int two; 
 
	CFrameWnd* theFrame = (CFrameWnd*)AfxGetMainWnd(); 
	CEdit* theView = (CEdit*)theFrame->GetActiveView(); 
	CDocument* theDoc = (CDocument*)theFrame->GetActiveDocument(); 
	theView->ReplaceSel(WhatTime,TRUE); 
	CHANGED = TRUE; 
	theDoc->SetModifiedFlag(TRUE); 
	 
}