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

📄 managedlg.cpp

📁 开发的,食物管理软件,可以在智能家电的终端上直接应用
💻 CPP
字号:
// ManageDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FoodMenu.h"
#include "ManageDlg.h"
#include "AddFood1.h"//add
#include "ColorButton.h"
#include "delete.h"
#include "Find.h"

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

/////////////////////////////////////////////////////////////////////////////
// CManageDlg dialog

CString AlarmfilePath=TEXT("\\Storage Card\\foodMenuData\\食物管理\\Add\\");
CManageDlg::CManageDlg(CWnd* pParent /*=NULL*/)
: CDialog(CManageDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CManageDlg)
	//}}AFX_DATA_INIT
}


void CManageDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CManageDlg)
	DDX_Control(pDX, 12, m_12);
	DDX_Control(pDX, IDC_TIP2, m_tip2);
	DDX_Control(pDX, IDC_TIP1, m_tip1);
	DDX_Control(pDX, 9, m_9);
	DDX_Control(pDX, 8, m_8);
	DDX_Control(pDX, 7, m_7);
	DDX_Control(pDX, 6, m_6);
	DDX_Control(pDX, 5, m_5);
	DDX_Control(pDX, 4, m_4);
	DDX_Control(pDX, 3, m_3);
	DDX_Control(pDX, 11, m_11);
	DDX_Control(pDX, 10, m_10);
	DDX_Control(pDX, 2, m_2);
	DDX_Control(pDX, 1, m_1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CManageDlg, CDialog)
//{{AFX_MSG_MAP(CManageDlg)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_HOME, OnHome)
	ON_BN_CLICKED(1, On1)
	ON_BN_CLICKED(10, On10)
	ON_BN_CLICKED(11, On11)
	ON_BN_CLICKED(13, On13)
	ON_BN_CLICKED(2, On2)
	ON_BN_CLICKED(3, On3)
	ON_BN_CLICKED(4, On4)
	ON_BN_CLICKED(5, On5)
	ON_BN_CLICKED(6, On6)
	ON_BN_CLICKED(7, On7)
	ON_BN_CLICKED(8, On8)
	ON_BN_CLICKED(9, On9)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_FIRST_BUTTON1, OnFirstButton1)
	ON_BN_CLICKED(IDC_LAST_BUTTON4, OnLastButton4)
	ON_BN_CLICKED(IDC_FRONT_BUTTON2, OnFrontButton2)
	ON_BN_CLICKED(IDC_NEXT_BUTTON3, OnNextButton3)
	ON_BN_CLICKED(IDC_LOOK, OnLook)
	ON_BN_CLICKED(IDC_BACK, OnBack)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CManageDlg message handlers


BOOL CManageDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	
	// TODO: Add extra initialization here
	/////////////////////////////////////////////////////////////////////////
	home.LoadBitmaps(IDB_home,IDB_home);
	back.LoadBitmaps(IDB_return,IDB_return);
	first.LoadBitmaps(IDB_first_page,IDB_first_page);
	front.LoadBitmaps(IDB_front_page,IDB_front_page);
	next.LoadBitmaps(IDB_next_page,IDB_next_page);
	last.LoadBitmaps(IDB_last_page,IDB_last_page);
	lookup.LoadBitmaps(IDB_lookup,IDB_lookup);
	dele.LoadBitmaps(IDB_dele,IDB_dele);
	add.LoadBitmaps(IDB_add,IDB_add);
	
	
	VERIFY(home.SubclassDlgItem(IDC_HOME, this));
    VERIFY(back.SubclassDlgItem(IDC_BACK, this));
	VERIFY(first.SubclassDlgItem(IDC_FIRST_BUTTON1, this));
	VERIFY(front.SubclassDlgItem(IDC_FRONT_BUTTON2, this));
	VERIFY(next.SubclassDlgItem(IDC_NEXT_BUTTON3, this));
	VERIFY(last.SubclassDlgItem(IDC_LAST_BUTTON4, this));
	VERIFY(lookup.SubclassDlgItem(IDC_LOOK, this));
	VERIFY(dele.SubclassDlgItem(IDC_DELETE, this));
	VERIFY(add.SubclassDlgItem(IDC_ADD, this));
				
	home.SizeToContent();
	back.SizeToContent();
	first.SizeToContent();
	front.SizeToContent();
	next.SizeToContent();
	last.SizeToContent();
	lookup.SizeToContent();
	dele.SizeToContent();
	add.SizeToContent();
	m_tip1.SetWindowText(TEXT("输入日期  食物名称  保存时间"));
	m_tip2.SetWindowText(TEXT("输入日期  食物名称  保存时间"));
	mFileCount=0;
	SearchAlarmFile(AlarmfilePath);
	page=1;//default is the first page
	//////////////////////////////////////////////////////////////////////////////////
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CManageDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	CAddFood1 AddFood1;
	AddFood1.DoModal();
	SearchAlarmFile(AlarmfilePath);
	UpdateData(false);
}

void CManageDlg::OnHome() 
{
	CDialog::OnOK();
	CDialog::DestroyWindow();
}


void CManageDlg::SearchAlarmFile(CString AlarmFilePath)
{
	int n=0;
	int i=1;
	BOOL FileEnd=1;
	file = FindFirstFile(AlarmfilePath+TEXT("*.txt"),&lpFileData);
	if(file!=INVALID_HANDLE_VALUE)       //如果出错,返回一个INVALID_HANDLE_VALUE常数
	{
		CFile file;
		char *pBuf;//用于存储文件
		file.Open(AlarmfilePath+lpFileData.cFileName,CFile::modeRead);////
		DWORD dwFileLen;
		dwFileLen=file.GetLength();
		pBuf=new char[dwFileLen+1];
		file.Read(pBuf,dwFileLen);
//		pBuf[dwFileLen+1]='\0';
		Alarmfile[0]=pBuf;
		GetDlgItem(1)->SetWindowText(Alarmfile[0]);
		Alarmfilename[0]=lpFileData.cFileName;
		Activefile=Alarmfilename[0];
		mFileCount++;
		UpdateData(false);
		file.Close();
		delete pBuf;   	
	}
	while(FileEnd=FindNextFile(file,&lpFileData)&&n<100)
	{
		i++;
		n++;
		mFileCount++;
		CFile file;
		char *pBuf;//用于存储文件
		file.Open(AlarmfilePath+lpFileData.cFileName,CFile::modeRead);////
		DWORD dwFileLen;
		dwFileLen=file.GetLength();
		pBuf=new char[dwFileLen+1];
		file.Read(pBuf,dwFileLen);
//		pBuf[dwFileLen+1]='\0';
		Alarmfile[n]=pBuf;
		if(i<=12)
		GetDlgItem(i)->SetWindowText(Alarmfile[n]);
		Alarmfilename[n]=lpFileData.cFileName;
		UpdateData(false);
		file.Close();
		delete pBuf;   	
	}
	FileEnd=FindNextFile(file,&lpFileData);
	FindClose(file);
}

void CManageDlg::On1() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[0];
}

void CManageDlg::On10() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[9];
	
}

void CManageDlg::On11() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[10];
	
}

void CManageDlg::On13() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[12];
	
}

void CManageDlg::On2() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[1];

	
}

void CManageDlg::On3() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[2];

	
}

void CManageDlg::On4() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[3];
	
}

void CManageDlg::On5() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[4];
	
}

void CManageDlg::On6() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[5];
	
}

void CManageDlg::On7() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[6];
	
}

void CManageDlg::On8() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[7];
	
}

void CManageDlg::On9() 
{
	Activefile.Empty();
	Activefile=Alarmfilename[8];
	
}

void CManageDlg::OnDelete() 
{
	Cdelete dlg;
	if( dlg.DoModal()==IDOK)
	{
		CString filepath=AlarmfilePath+Activefile;
		CFile::Remove(filepath);
//		SearchAlarmFile(AlarmfilePath);
		UpdateData(false);
		CDialog::OnOK();
		CDialog::DestroyWindow();
	}
}

void CManageDlg::OnFirstButton1() 
{
//	SearchAlarmFile(AlarmfilePath);
	int i,j;
	for(i=1,j=0;i<=mFileCount&&j<12;i++,j++)
		GetDlgItem(i)->SetWindowText(Alarmfile[j]);
	page=1;
}

void CManageDlg::OnLastButton4() 
{
	int i,j;
	if(mFileCount<12)
	{
		UpdateData(false);
		page=1;
	}
	else if(mFileCount>12&&mFileCount<=24)
	{
		Clear();
		for(i=1,j=0;(12+j)<=mFileCount&&i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[12+j]);
		page=2;
	}
	else if(mFileCount>=24&&mFileCount<36)
	{
		Clear();
		for(i=1,j=0;(24+j)<=mFileCount&&i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[24+j]);
		page=3;
	}
	else if(mFileCount>=36&&mFileCount<48)
	{
		Clear();
		for(i=1,j=0;(36+j)<=mFileCount&&i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[36+j]);
		page=4;
	}
	else if(mFileCount>=48&&mFileCount<60)
	{
		Clear();
		for(i=1,j=0;(48+j)<=mFileCount&&i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[48+j]);
		page=5;
	}
	else if(mFileCount>=60&&mFileCount<72)
	{
		Clear();
		for(i=1,j=0;(60+j)<=mFileCount&&i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[60+j]);
		page=5;
	}
}

void CManageDlg::OnFrontButton2() 
{
	int i,j;
	switch(page)
	{
		case 1:
			break;
		case 2:
			for(i=1,j=0;i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[j]);
			page=1;
			break;
		case 3:
			for(i=1,j=0;i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[12+j]);
			page=2;
			break;
		case 4:
			for(i=1,j=0;i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[24+j]);
			page=3;
			break;
		case 5:
			for(i=1,j=0;i<13;i++,j++)
			GetDlgItem(i)->SetWindowText(Alarmfile[36+j]);
			page=4;
			break;
		default:
			break;
	}
}

void CManageDlg::OnNextButton3() 
{
	int i,j;
	switch(page)
	{
		case 1:
			if(12<mFileCount&&mFileCount<=24)
			{
				Clear();
				for(i=1,j=0;(12+j)<=mFileCount&&i<13;i++,j++)
				GetDlgItem(i)->SetWindowText(Alarmfile[12+j]);
				page=2;
			}
			break;
		case 2:
			if(24<mFileCount&&mFileCount<=36)
			{
				Clear();
				for(i=1,j=0;(24+j)<=mFileCount&&i<13;i++,j++)
				GetDlgItem(i)->SetWindowText(Alarmfile[24+j]);
				page=3;
			}
			UpdateData(false);
			break;
		case 3:
			if(36<mFileCount&&mFileCount<=48)
			{
				Clear();
				for(i=1,j=0;(36+j)<=mFileCount&&i<13;i++,j++)
				GetDlgItem(i)->SetWindowText(Alarmfile[36+j]);
				page=4;
			}
			UpdateData(false);
			break;
		case 4:
			if(48<mFileCount&&mFileCount<=60)
			{
				Clear();
				for(i=1,j=0;(48+j)<=mFileCount&&i<13;i++,j++)
				GetDlgItem(i)->SetWindowText(Alarmfile[48+j]);
				page=5;
			}
			UpdateData(false);
			break;
		case 5:
			if(60<mFileCount&&mFileCount<=72)
			{
				Clear();
				for(i=1,j=0;(60+j)<=mFileCount&&i<13;i++,j++)
				GetDlgItem(i)->SetWindowText(Alarmfile[60+j]);
				page=6;
			}
			UpdateData(false);
			break;
		default:
			break;
	}
}

void CManageDlg::OnLook() 
{
	CFind dlg;
	dlg.countfile=mFileCount;
	for(int x=0;x<=mFileCount;x++)
	{
		Alarmfilename[x].TrimRight(TEXT(".txt"));
		dlg.Alarmfile[x]=Alarmfilename[x];
	}
	dlg.DoModal();
}

void CManageDlg::Clear()
{
	for(int i=1;i<13;i++)
		GetDlgItem(i)->SetWindowText(TEXT(""));
}

void CManageDlg::OnBack() 
{
	CDialog::OnOK();
	DestroyWindow();	
}

⌨️ 快捷键说明

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