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

📄 sdrksjdlg.cpp

📁 这是一套学校设备管理系统的源码 里面有树形结构使用的很棒的方法
💻 CPP
字号:
// sdrksjdlg.cpp : implementation file
//

#include "stdafx.h"
#include "xxgl.h"
#include "sdrksjdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// Csdrksjdlg dialog
extern char g_yszmcx_qsrksjn[6];
extern char g_yszmcx_qsrksjy[6];
extern char g_yszmcx_qsrksjr[6];
extern char g_yszmcx_jsrksjn[6];
extern char g_yszmcx_jsrksjy[6];
extern char g_yszmcx_jsrksjr[6];
static int cur_focus;

switch_to_english_mode(CWnd *wnd);
switch_to_chinese_mode(CWnd *wnd);
Set_to_item_end(CWnd *wd,int id);

Csdrksjdlg::Csdrksjdlg(CWnd* pParent /*=NULL*/)
	: CDialog(Csdrksjdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(Csdrksjdlg)
	//}}AFX_DATA_INIT
	strcpy(g_yszmcx_qsrksjn,"");
	strcpy(g_yszmcx_qsrksjy,"");
	strcpy(g_yszmcx_qsrksjr,"");
	strcpy(g_yszmcx_jsrksjn,"");
	strcpy(g_yszmcx_jsrksjy,"");
	strcpy(g_yszmcx_jsrksjr,"");
    cur_focus =0;
}


void Csdrksjdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Csdrksjdlg)
	DDX_Control(pDX, IDC_qsy, m_qsy);
	DDX_Control(pDX, IDC_qsn, m_qsn);
	DDX_Control(pDX, IDC_qsr, m_qsr);
	DDX_Control(pDX, IDC_jsy, m_jsy);
	DDX_Control(pDX, IDC_jsr, m_jsr);
	DDX_Control(pDX, IDC_jsn, m_jsn);
	//}}AFX_DATA_MAP
	int year,month,day;

    time_t ltime;    
	struct tm *pti;
	char tmpbuf[100];
	char buf[1000];
	char bu[1000];
	int ret;

    time(&ltime);    
	pti = gmtime(&ltime);
	year = pti->tm_year + 1900;
	month = 1 + pti->tm_mon;
	day = pti->tm_mday;
	itoa(year,buf,10);
	m_qsn.SelectString(0,buf);
	m_jsn.SelectString(0,buf);
	itoa(month,buf,10);
	SetDlgItemText(IDC_qsy,"1");
	m_jsy.SelectString(0,"12");
	itoa(day,buf,10);
	SetDlgItemText(IDC_qsr,"1");
	m_jsr.SelectString(0,"31");
}


BEGIN_MESSAGE_MAP(Csdrksjdlg, CDialog)
	//{{AFX_MSG_MAP(Csdrksjdlg)
	ON_CBN_EDITCHANGE(IDC_qsn, OnEditchangeqsn)
	ON_CBN_EDITCHANGE(IDC_jsn, OnEditchangejsn)
	ON_CBN_EDITCHANGE(IDC_jsr, OnEditchangejsr)
	ON_CBN_EDITCHANGE(IDC_jsy, OnEditchangejsy)
	ON_CBN_EDITCHANGE(IDC_qsr, OnEditchangeqsr)
	ON_CBN_EDITCHANGE(IDC_qsy, OnEditchangeqsy)
	ON_CBN_SETFOCUS(IDC_qsn, OnSetfocusqsn)
	ON_CBN_SETFOCUS(IDC_qsy, OnSetfocusqsy)
	ON_CBN_SETFOCUS(IDC_qsr, OnSetfocusqsr)
	ON_CBN_SETFOCUS(IDC_jsn, OnSetfocusjsn)
	ON_CBN_SETFOCUS(IDC_jsr, OnSetfocusjsr)
	ON_CBN_SETFOCUS(IDC_jsy, OnSetfocusjsy)
	ON_CBN_SELCHANGE(IDC_qsn, OnSelchangeqsn)
	ON_CBN_SELCHANGE(IDC_jsn, OnSelchangejsn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Csdrksjdlg message handlers

void Csdrksjdlg::OnOK() 
{
	// TODO: Add extra validation here
	int n;
	int t;
	long bl,el;
	int qsn,qsy,qsr;
	int jsn,jsy,jsr;
	char buf[20];

    CWnd *wn_qsn;
	CWnd *wn_qsy;
	CWnd *wn_qsr;
	CWnd *wn_jsn ;
	CWnd *wn_jsy ;
	CWnd *wn_jsr ;
	CWnd *wn_ok;
	CWnd *wn_cur;

	wn_qsn = GetDlgItem(IDC_qsn);
	wn_qsy = GetDlgItem(IDC_qsy);
	wn_qsr = GetDlgItem(IDC_qsr);
	wn_jsn = GetDlgItem(IDC_jsn);
	wn_jsy = GetDlgItem(IDC_jsy);
	wn_jsr = GetDlgItem(IDC_jsr);
    wn_ok =  GetDlgItem(IDOK);
	wn_cur = GetFocus();
	if (wn_cur->m_hWnd != wn_ok->m_hWnd){
	if (cur_focus == 1){   
		wn_qsy->SetFocus();
	     return; 
	}
	
	if (cur_focus == 2){
		
		wn_qsr->SetFocus();
         return;
	}
	if (cur_focus == 3){
		wn_jsn->SetFocus();
	     return;
    }
	if (cur_focus == 4){
	    wn_jsy->SetFocus();
		 return;
	}
    if (cur_focus == 5){ 
	   wn_jsr->SetFocus();
	    return;
	}    
	if (cur_focus == 6){
        wn_ok->SetFocus();
		cur_focus = 0;
		return ;
	}  	
	}

	GetDlgItemText(IDC_qsn,buf,20);
	t = atoi(buf);
	qsn = atoi(buf);
	if ((t < 1970)||(t > 2100)){
		MessageBox("起始年份错误.","",MB_OK);
		wn_qsn->SetFocus();
		return;
    }
    strcpy(g_yszmcx_qsrksjn,buf);
	GetDlgItemText(IDC_qsy,buf,20);
	t = atoi(buf);
	qsy = atoi(buf);
	if ((t < 1)||(t > 12)){
		MessageBox("起始月份错误.","",MB_OK);
		wn_qsy->SetFocus();
		return;
    }
    strcpy(g_yszmcx_qsrksjy,buf);
	GetDlgItemText(IDC_qsr,buf,20);
	t = atoi(buf);
	qsr = atoi(buf);
	if ((t < 1)||(t > 31)){
		MessageBox("起始日期错误.","",MB_OK);
		wn_qsr->SetFocus();
		return;
    }
    strcpy(g_yszmcx_qsrksjr,buf);

	GetDlgItemText(IDC_jsn,buf,20);
	t = atoi(buf);
	jsn = atoi(buf);
	if ((t < 1970)||(t > 2100)){
		MessageBox("结束年份错误.","",MB_OK);
		wn_jsn->SetFocus();
		return;
    }
    strcpy(g_yszmcx_jsrksjn,buf);
	GetDlgItemText(IDC_jsy,buf,20);
	t = atoi(buf);
	jsy = atoi(buf);
	if ((t < 1)||(t > 12)){
		MessageBox("结束月份错误.","",MB_OK);
		wn_jsy->SetFocus();
		return;
    }
    strcpy(g_yszmcx_jsrksjy,buf);
	GetDlgItemText(IDC_jsr,buf,20);
	t = atoi(buf);
	jsr = atoi(buf);
	if ((t < 1)||(t > 31)){
		MessageBox("结束日期错误.","",MB_OK);
		wn_jsr->SetFocus();
		return;
    }
    strcpy(g_yszmcx_jsrksjr,buf);

	bl = qsn*10000L + qsy*100L + qsr;
	el = jsn*10000L + jsy*100L + jsr;
	if (bl > el){
		MessageBox("起始日期后于结束日期.请重新输入.","",MB_OK);
		wn_qsn->SetFocus();
		return;
    }
	CDialog::OnOK();
}

void Csdrksjdlg::OnEditchangeqsn() 
{
	// TODO: Add your control notification handler code here
	char buf[40];

	int l,i,flag,j;
	
	GetDlgItemText(IDC_qsn,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 4){
			buf[4] = 0;
	        SetDlgItemText(IDC_qsn,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"2000");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_qsn,buf);
		  }
		}
	}
	SetDlgItemText(IDC_jsn,buf);
}

void Csdrksjdlg::OnEditchangejsn() 
{
	// TODO: Add your control notification handler code here
	char buf[40];

	int l,i,flag,j;
	
	GetDlgItemText(IDC_jsn,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 4){
			buf[4] = 0;
	        SetDlgItemText(IDC_jsn,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"2000");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_jsn,buf);
		  }
		}
	}
	SetDlgItemText(IDC_qsn,buf);
	
}

void Csdrksjdlg::OnEditchangejsr() 
{
	// TODO: Add your control notification handler code here
	char buf[40];

	int l,i,flag,j;
	
	GetDlgItemText(IDC_jsr,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 2){
			buf[2] = 0;
	        SetDlgItemText(IDC_jsr,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"15");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_jsr,buf);
		  }
		}
	}
	
}

void Csdrksjdlg::OnEditchangejsy() 
{
	// TODO: Add your control notification handler code here
	char buf[40];

	int l,i,flag,j;
	
	GetDlgItemText(IDC_jsy,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 2){
			buf[2] = 0;
	        SetDlgItemText(IDC_jsy,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"6");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_jsy,buf);
		  }
		}
	}	
}

void Csdrksjdlg::OnEditchangeqsr() 
{
	// TODO: Add your control notification handler code here
	char buf[40];

	int l,i,flag,j;
	
	GetDlgItemText(IDC_qsr,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 2){
			buf[2] = 0;
	        SetDlgItemText(IDC_qsr,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"15");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_qsr,buf);
		  }
		}
	}
	
}

void Csdrksjdlg::OnEditchangeqsy() 
{
	// TODO: Add your control notification handler code here
	
	char buf[40];

	int l,i,flag,j;
	
	GetDlgItemText(IDC_qsy,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 2){
			buf[2] = 0;
	        SetDlgItemText(IDC_qsy,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"6");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_qsy,buf);
		  }
		}
	}	
}

void Csdrksjdlg::OnSetfocusqsn() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_qsn);
    switch_to_english_mode(wnd);
		cur_focus = 1;
}

void Csdrksjdlg::OnSetfocusqsy() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_qsy);
    switch_to_english_mode(wnd);
        cur_focus = 2;
}

void Csdrksjdlg::OnSetfocusqsr() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_qsr);
    switch_to_english_mode(wnd);
        cur_focus =3;
}

void Csdrksjdlg::OnSetfocusjsn() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_jsn);
    switch_to_english_mode(wnd);
	cur_focus =4;
}

void Csdrksjdlg::OnSetfocusjsr() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_jsr);
    switch_to_english_mode(wnd);
	cur_focus = 6;
}

void Csdrksjdlg::OnSetfocusjsy() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_jsy);
    switch_to_english_mode(wnd);
	cur_focus = 5;
}

void Csdrksjdlg::OnSelchangeqsn() 
{
	// TODO: Add your control notification handler code here
	char buf[40];
	int l,i,flag,j;
	int n;
	
	n = m_qsn.GetCurSel();
	m_qsn.GetLBText(n,buf);
    l = strlen(buf);
	if (l > 0){
		if (l > 4){
			buf[4] = 0;
	        SetDlgItemText(IDC_qsn,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"2000");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_qsn,buf);
		  }
		}
	}
	SetDlgItemText(IDC_jsn,buf);
	
}

void Csdrksjdlg::OnSelchangejsn() 
{
	// TODO: Add your control notification handler code here
	char buf[40];
	int l,i,flag,j;
	int n;
	
	n = m_jsn.GetCurSel();
	m_jsn.GetLBText(n,buf);
    l = strlen(buf);
	if (l > 0){
		if (l > 4){
			buf[4] = 0;
	        SetDlgItemText(IDC_jsn,buf);
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
			if (i == 0){
				strcpy(buf,"2000");
			}
			else
		      buf[i] = 0;
	        SetDlgItemText(IDC_jsn,buf);
		  }
		}
	}
	SetDlgItemText(IDC_qsn,buf);
	
}

⌨️ 快捷键说明

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