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

📄 hintdlg.cpp

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

#include "stdafx.h"
#include "FoodMenu.h"
#include "HintDlg.h"
 #include <atlconv.h>
#include <stdlib.h>
#include <stdio.h>
#include "ColorButton.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHintDlg dialog


CHintDlg::CHintDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHintDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHintDlg)
	m_name = _T("");
	m_where = _T("");
	//}}AFX_DATA_INIT
}


void CHintDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHintDlg)
	DDX_Control(pDX, IDC_DAY2, m_day2);
	DDX_Control(pDX, IDC_DAY, m_day);
	DDX_Text(pDX, IDC_NAME, m_name);
	DDX_Text(pDX, IDC_WHERE, m_where);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CHintDlg, CDialog)
	//{{AFX_MSG_MAP(CHintDlg)
	ON_CBN_SELCHANGE(IDC_DAY, OnSelchangeDay)
	ON_CBN_SELCHANGE(IDC_DAY2, OnSelchangeDay2)
	ON_BN_CLICKED(IDC_OK_AFN, OnOkAfn)
	ON_BN_CLICKED(IDC_CANCEL_AFN, OnCancelAfn)
	ON_BN_CLICKED(IDC_HOME, OnHome)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_return, Onreturn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHintDlg message handlers

void CHintDlg::lookUpStoreFood()//从冷藏条件中查
{
   //----------------读*.txt-------------
     	CFile file;
 	char *pBuf;//用于存储文件
	   file.Open(L"\\Storage Card\\foodMenuData\\食物管理\\贮藏条件.txt",CFile::modeRead);////
	   DWORD dwFileLen;
	   dwFileLen=file.GetLength();
	   pBuf=new char[dwFileLen+1];
	   pBuf[dwFileLen]=0;
	   file.Read(pBuf,dwFileLen);
	   file.Close();
   //----------------------------------------
     	bool IsFoodName=false;//是不是input原料
		bool IsFoodCondition=false;//是不是冷藏条件
        bool IsFoodDay=false;//是不是冷藏时间
		CString conditionFood;//暂存原料名
		char *s;
	
	 char by=pBuf[0];
   int p=0;
   int temp=0;
    while(by!='\0')
   {
      
    	if(by=='@'&&pBuf[temp+1]!='*')//是原料名
	   {
			 if(IsFoodDay)//冷藏时间
			 {
			 storeDay2=conditionFood;
			  int longstr=conditionFood.GetLength();
                       s=new char[longstr+1];
			 for(DWORD i=0;i<=(DWORD)longstr;i++)
			 {
			   s[i]=(char)conditionFood.GetAt(i);
			 }
			
			 storeDay=atoi(s);
			   break;
			 }
		   IsFoodName=true;
			  temp++;
	        by=pBuf[temp];
	   } 
	   if(by=='@'&&pBuf[temp+1]=='*'&&pBuf[temp+2]!='*')//是food冷藏条件
	   { 
		   IsFoodName=false;
		   if(!IsFoodName)
		   {
                      if( conditionFood.Compare(Inputname)==0 )
					  {
	                       IsFoodCondition=true;
		                   
					  }
		   }
		 conditionFood.Empty();
	         temp+=2;
		     by=pBuf[temp];
	   } 
	    if(by=='@'&&pBuf[temp+1]=='*'&&pBuf[temp+2]=='*')//几天
		{
			if(IsFoodCondition)
			{
		     IsFoodCondition=false;
		     IsFoodDay=true;
			 storeWhere=conditionFood;
			}
			conditionFood.Empty();
           temp+=3;
           by=pBuf[temp];
        }
        if(IsFoodName)//是原料名
		{
		  if(by!='\n')//回车不算
		  {
		     conditionFood+=by;
		  }
		}
	   if(IsFoodCondition)//是food冷藏条件
	   { 
		   if(by!='\n')//回车不算
		  {
		    
		     conditionFood+=by;
          
		  }
	   }
	   if(IsFoodDay)//冷藏时间
	   {
	      if(by!='\n')//回车不算
		  {
		    conditionFood+=by;
		  }
	   }
  	   temp++;
	   by=pBuf[temp];
	   
   }//  while(by!='\0')
}

void CHintDlg::OnSelchangeDay() ////冷藏几天
{
	// TODO: Add your control notification handler code here
	  //----------------------取得组合框的相关信息--------
		CString foodname1;
	    int nIndex ;
	    nIndex = m_day.GetCurSel();
	
		m_day.GetLBText(nIndex,foodname1);
	//------------------------------------------------------
	 addday=foodname1;//冷藏几天
	
}

void CHintDlg::OnSelchangeDay2() //提前几天报警
{
	// TODO: Add your control notification handler code her
	  //----------------------取得组合框的相关信息--------
		CString foodname1;
	    int nIndex ;
	    nIndex = m_day.GetCurSel();
	
		m_day.GetLBText(nIndex,foodname1);
	//------------------------------------------------------
		 beforday=foodname1;//提前几天报警
}

void CHintDlg::begincombo()
{
    // int nIndex=m_day.AddString(storeDay2+L"天");

	 //CString str=storeDay2+L"天";
	 m_day.AddString(L"1天");
	 m_day.AddString(L"2天");
	 m_day.AddString(L"3天");
	 m_day.AddString(L"4天");
	 m_day.AddString(L"5天");
	 m_day.AddString(L"6天");
	 m_day.AddString(L"7天");
	 m_day.AddString(L"8天");
	 m_day.AddString(L"9天");
	 m_day.AddString(L"10天");
	 m_day.AddString(L"11天");
	 m_day.AddString(L"12天");
	 m_day.AddString(L"13天");
	 m_day.AddString(L"14天");
	 m_day.AddString(L"15天");
	 m_day.AddString(L"16天");
	 m_day.AddString(L"17天");
	 m_day.AddString(L"18天");
	 m_day.AddString(L"19天");
	 m_day.AddString(L"20天");
	 m_day.AddString(L"21天");
	 m_day.AddString(L"22天");
	 m_day.AddString(L"23天");
	 m_day.AddString(L"24天");
	 m_day.AddString(L"25天");
	 m_day.AddString(L"26天");
	 m_day.AddString(L"27天");
	 m_day.AddString(L"28天");
	 m_day.AddString(L"29天");
	 m_day.AddString(L"30天");
	/// int nIndex;
     //m_day.FindString(nIndex,str);
     m_day.SetCurSel(0);

	 m_day2.AddString(L"提前1天");
	  m_day2.AddString(L"提前2天");
	   m_day2.AddString(L"提前3天");
        m_day2.SetCurSel(0);
}

BOOL CHintDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	home.LoadBitmaps(IDB_home);
	VERIFY(home.SubclassDlgItem(IDC_HOME, this));
	home.SizeToContent();

	back.LoadBitmaps(IDB_return);
	VERIFY(back.SubclassDlgItem(IDC_return, this));
	back.SizeToContent();

	btnok.LoadBitmaps(IDB_ok);
	VERIFY(btnok.SubclassDlgItem(IDC_OK_AFN, this));
	btnok.SizeToContent();

	btncancel.LoadBitmaps(IDB_cancel);
	VERIFY(btncancel.SubclassDlgItem(IDC_CANCEL_AFN, this));
	btncancel.SizeToContent();	
/*
	addFont= new CFont;
	addFont->CreateFont(30, 0, 0, 0, 900, FALSE, FALSE, 0,
          ANSI_CHARSET, OUT_DEFAULT_PRECIS,
          CLIP_DEFAULT_PRECIS  ,
          DEFAULT_QUALITY,
          DEFAULT_PITCH | FF_SWISS,
		  _T("宋体"));
*/
  //	m_name.SetFont(addFont);
//	m_where.SetFont(addFont);
			m_brush.CreateSolidBrush(RGB(255,255,255));//此处设置的RGB值可以改变static控件的背景色。
	m_color=RGB(0,0,0);//此处设置static控件的文字初始颜色。
		//storeDay=0;
		storeWhere=TEXT("冷藏室");
		addday=TEXT("3天");//默认
		beforday=TEXT("提前1天");
		m_name=Inputname;//名字
		m_where=storeWhere;//放哪里
		UpdateData(false);
		lookUpStoreFood();//从冷藏条件中查
        begincombo();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CHintDlg::OnOkAfn() 
{
////////保存报警文档(Main程序的共享文档)/////////////
	USES_CONVERSION;
	char *p;
    p=(char*)W2A((LPCTSTR)beforday);
    CFile mFile(L"\\Storage Card\\AlarmFile\\FoodMenu\\"+Inputname+L".txt",CFile::modeCreate|CFile::modeWrite);
    mFile.Write(p,10);//;
    mFile.Flush();
    mFile.Close();
/////////////////////////////////
//////////保存添加的食物/////////
	CString mContent,sTime,sMonth,sDay;
	SYSTEMTIME systime;
	GetLocalTime(&systime);
//	sYear.Format(_T("%u."),systime.wYear); 
	if(systime.wMonth<10)
	{
		sMonth.Format(_T("0%u"),systime.wMonth);//如果月份小于10,前面加0
	}
	else
	{
		sMonth.Format(_T("%u"),systime.wMonth);
	}
	if(systime.wDay<10)
	{
		sDay.Format(_T("0%u"),systime.wDay);
	}
	else
	{
		sDay.Format(_T("%u"),systime.wDay); 
	}
 
    sTime =sMonth+TEXT("月")+ sDay+TEXT("日"); //输入日期;
	mContent=sTime+TEXT("      ")+Inputname+TEXT("      ")+addday;//显示的总内容
//	MessageBox(mContent);
	char *p2;
    p2=(char*)W2A((LPCTSTR)mContent);
    CFile mFile2(TEXT("\\Storage Card\\foodMenuData\\食物管理\\Add\\")+Inputname+L".txt",CFile::modeCreate|CFile::modeWrite);
    mFile2.Write(p2,30);//;
    mFile2.Flush();
    mFile2.Close();

	CDialog::OnCancel();
	CDialog::DestroyWindow(); 
}

void CHintDlg::OnCancelAfn() 
{
	// TODO: Add your control notification handler code here
	OnOK();
	DestroyWindow();
}

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

HBRUSH CHintDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	if(nCtlColor== CTLCOLOR_STATIC)
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(m_color);
		return (HBRUSH)m_brush.GetSafeHandle();
	}
	return hbr;
}

void CHintDlg::Onreturn() 
{
	CDialog::OnOK();
	DestroyWindow();	
}

⌨️ 快捷键说明

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