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

📄 basetabctrl1.cpp

📁 这是一个管理信息系统
💻 CPP
字号:
// BaseTabCtrl1.cpp : implementation file
//

#include "stdafx.h"
#include "BaseTabCtrl1.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBaseTabCtrl

CBaseTabCtrl::CBaseTabCtrl(int nfield)
	:mc_iNumber(nfield)
{
	this->m_statics=new CStatic[mc_iNumber];
	this->m_edits=new CEdit[mc_iNumber];
	m_list=new CListCtrl;
	m_btn=new CButton[5];
}

CBaseTabCtrl::~CBaseTabCtrl()
{

}
BEGIN_MESSAGE_MAP(CBaseTabCtrl, CTabCtrl)
	//{{AFX_MSG_MAP(CBaseTabCtrl)
	ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)//NM_DBLCLK
	ON_NOTIFY(NM_DBLCLK, ID_TABLIST, OnDblclkList)
	ON_CBN_SELENDOK(ID_COMBOFIELDS, OnSelendokComboFields)
	ON_BN_CLICKED(ID_BUTTONS_1+3,OnBaoCunClick)
	ON_BN_CLICKED(ID_BUTTONS_1,OnZengJiaClick)
	ON_BN_CLICKED(ID_BUTTONS_1+2,OnShanChuClick)
	ON_BN_CLICKED(ID_BUTTONS_1+1,OnXiuGaiClick)
	ON_BN_CLICKED(ID_BUTTONS_1+4,OnCancelClick)
	ON_BN_CLICKED(ID_CHECK,OnCheckClick)
	ON_BN_CLICKED(ID_BUTTONCHAXUN,OnChaXun)//	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBaseTabCtrl message handlers
void CBaseTabCtrl::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	this->OnListReturn();
	*pResult = 0;
}

bool CBaseTabCtrl::InitBaseInfo()
{/*
	//初始化基本信息页
	TRACE("InitBaseInfo\n");
	//确定statics edits显示位置:rect1,rect2,rect3,rect4;
	CRect rect;
	this->GetClientRect(&rect);

	int height=25;
	int top=60;
	int wid=rect.Width()/4;

	CRect rect1,rect2,rect3,rect4;
	rect1.top=top;
	rect1.bottom=top+20;
	rect1.left=10;
	rect1.right=(long)rect.Width()/8;
	rect2.top=top;
	rect2.bottom=top+20;
	rect2.left=(long)rect.Width()/8+10;
	rect2.right=(long)rect.Width()/2-10;

	rect3.top=top;
	rect3.bottom=top+20;
	rect3.left=rect.Width()/2+10;
	rect3.right=(long)rect.Width()*5/8;
	rect4.top=top;
	rect4.bottom=top+20;
	rect4.left=(long)rect.Width()*5/8+10;
	rect4.right=(long)rect.Width()-10;

	int n=this->mc_iNumber/2;
	int yu=this->mc_iNumber%2;
	for(int i=0;i<n;i++)
	{

		this->m_statics[i*2].Create(m_ss[i*2]+":",WS_CHILD,rect1,this,ID_STATICS_1+i*2);
		this->m_statics[i*2+1].Create(m_ss[i*2+1]+":",WS_CHILD,rect3,this,ID_STATICS_1+i*2+1);
		this->m_edits[i*2].Create(WS_CHILD|ES_AUTOHSCROLL|WS_BORDER,rect2,this,ID_EDITS_1+i*2);
		this->m_edits[i*2+1].Create(WS_CHILD|ES_AUTOHSCROLL|WS_BORDER,rect4,this,ID_EDITS_1+i*2+1);

		rect1.OffsetRect(0,height);
		rect2.OffsetRect(0,height);
		rect3.OffsetRect(0,height);
		rect4.OffsetRect(0,height);
	}

	if(yu)
	{
		this->m_statics[i*2].Create(m_ss[i*2]+":",WS_CHILD,rect1,this,ID_STATICS_1+i*2);
		this->m_edits[i*2].Create(WS_CHILD|ES_AUTOHSCROLL|WS_BORDER,rect2,this,ID_EDITS_1+i*2);
	}
	baseinfo_state=NORMAL;*/
	return true;
}

bool CBaseTabCtrl::EnableBaseInfo(bool enabled)
{
	for(int i=0;i<this->mc_iNumber;i++)
	{
			m_edits[i].SetReadOnly(!enabled);
	}
	return enabled;
}

int  CBaseTabCtrl::ShowBaseInfo(int show)
{
	for(int i=0;i<this->mc_iNumber;i++)
	{
		this->m_edits[i].ShowWindow(show);
	}
	for(int j=0;j<this->mc_iNumber;j++)
	{
		this->m_statics[j].ShowWindow(show);
	}
	for(int k=0;k<5;k++)
	{
		this->m_btn[k].ShowWindow(show);
	}
	return show;
}
bool CBaseTabCtrl::InitList()
{
	//初始化列表框页
	CRect rect_nlist;
	this->GetClientRect(&rect_nlist);
	rect_nlist.top+=100;
//	m_list=new CListCtrl;
	m_list->Create(WS_CHILD|LVS_REPORT|WS_BORDER|LVS_SINGLESEL,rect_nlist,this,ID_TABLIST);
	this->m_list->ModifyStyle(LVS_EDITLABELS, 0L);			//禁止标题编辑
	m_list->ModifyStyle(0L, LVS_REPORT);					//设为Report类型
	m_list->ModifyStyle(0L, LVS_SHOWSELALWAYS);				//始终高亮度被选中的表项
	m_list->ModifyStyle(0L, LVS_NOSORTHEADER);
	m_list->SetBkColor(RGB(0,200,200));
	m_list->SetTextBkColor(RGB(0,200,200));
	m_list->ModifyStyle(LVS_OWNERDRAWFIXED ,0L);
	m_list->SetExtendedStyle( LVS_EX_FULLROWSELECT |		//允许整行选中
		LVS_EX_HEADERDRAGDROP |								//允许整列拖动
		LVS_EX_GRIDLINES |									//画出网格线
		LVS_EX_FLATSB										//扁平风格的滚动条	
		);	

	rect_nlist.top=70;
	rect_nlist.bottom=rect_nlist.top+20;
	rect_nlist.left=20;
	rect_nlist.right=rect_nlist.left+180;
	this->m_check.Create("是否在查询结果中查询",0x00010003|WS_CHILD,rect_nlist,this,ID_CHECK);

	rect_nlist.top=30;
	rect_nlist.bottom=rect_nlist.top+120;
	rect_nlist.left=20;
	rect_nlist.right=rect_nlist.left+150;

	m_combofields.Create(0x00010203|WS_CHILD|CBS_AUTOHSCROLL|WS_VSCROLL   ,rect_nlist,this,ID_COMBOFIELDS);
	rect_nlist.OffsetRect(200,0);
	rect_nlist.right-=90;
	m_combofuhao.Create(0x00010203|WS_CHILD|CBS_AUTOHSCROLL|WS_VSCROLL  ,rect_nlist,this,ID_COMBOFUHAO);
	rect_nlist.OffsetRect(100,0);
	rect_nlist.right+=140;
	rect_nlist.bottom=rect_nlist.top+21;
	this->m_editvalue.Create(WS_CHILD|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP,rect_nlist,this,ID_EDITVALUE);
	rect_nlist.bottom=rect_nlist.top+22;
	rect_nlist.right=rect_nlist.left+100;
	m_tcvalue.Create(WS_CHILD,rect_nlist,this,233);
	rect_nlist.OffsetRect(10,40);
	rect_nlist.right=rect_nlist.left+80;
	rect_nlist.bottom=rect_nlist.top+25;

	this->m_btnchaxun.Create("查询",WS_CHILD,rect_nlist,this,ID_BUTTONCHAXUN);
	return true;
}

bool CBaseTabCtrl::InitSelf()
{

	SetItemSize(CSize(50,20));
	return true;
}

BOOL CBaseTabCtrl::Create(DWORD dwStyle, const RECT &rect, CWnd *pParentWnd, UINT nID)
{
	this->InitValues();
	if(!CTabCtrl::Create(dwStyle,rect,pParentWnd,nID))return false;
	this->InitBaseInfo();
	this->InitBtn();
	this->InitList();
	this->InitSelf();
	this->ShowListChaXun(SW_SHOW);
	this->ShowBaseInfo(SW_HIDE);
	//this->m_list->SetFocus();
	return true;
}
void CBaseTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int i=this->GetCurSel();
	switch(i)
	{
	case 0:
//		this->RefreshListView(PrepareSQL());
		this->ShowBaseInfo(SW_HIDE);
		this->ShowListChaXun(SW_SHOW);
		break;
	case 1:
		this->ShowBaseInfo(SW_SHOW);
		this->ShowListChaXun(SW_HIDE);
		if(!this->baseinfo_state)
			this->SetKey(this->m_list->GetSelectionMark());
		break;
	}
	*pResult = 0;
}

bool CBaseTabCtrl::InitBtn()
{
	CRect rect;
	this->GetClientRect(rect);
	rect.top=rect.bottom-35;
	rect.left=rect.Width()<480?rect.Width()*4/5:rect.Width()-120;
	CString str[5];
	str[0]="增加";
	str[1]="修改";
	str[2]="删除";
	str[3]="保存";
	str[4]="取消";
	for(int i=0;i<5;i++)
	{
		this->m_btn[i].Create(str[i],WS_CHILD|WS_TABSTOP,rect,this,ID_BUTTONS_1+i);
		rect.OffsetRect(-rect.Width(),0);

	}
	return true;
}

void CBaseTabCtrl::OnBaoCunClick()
{
		m_btn[0].EnableWindow(true);
		m_btn[1].EnableWindow(true);
		m_btn[2].EnableWindow(true);
		m_btn[3].EnableWindow(false);
		m_btn[4].EnableWindow(false);
		EnableBaseInfo(false);
}
BOOL CBaseTabCtrl::PreTranslateMessage(MSG* pMsg) 
{	const HWND hwnd=(pMsg!=NULL)?pMsg->hwnd:NULL;
	if(hwnd==NULL)
	{
		 goto a;
	}
	if(pMsg->message==WM_KEYDOWN&&(pMsg->wParam==13||pMsg->wParam==VK_TAB))
	{
		int i=this->GetCurSel();
		if(i==0)
		{
			this->SetListFocus(pMsg);
		}
		else if(i==1)
		{
			if(pMsg->wParam==VK_TAB)
			this->SetTheFocus()	;
			else 
			{
					int iID=::GetDlgCtrlID(hwnd);
					if(iID>200&&iID<206)
					{
						::PostMessage(this->GetSafeHwnd(),WM_COMMAND,iID,(UINT)hwnd);
						this->SetFocus();
					}
			}
			this->SetTheBaseInfoFocus();
		}
			pMsg->wParam=VK_CONTROL;
	}
a:
	return CTabCtrl::PreTranslateMessage(pMsg);
}

void CBaseTabCtrl::OnZengJiaClick()
{	
	this->baseinfo_state=ZENGJIA;
	for(int i=0;i<this->mc_iNumber;i++)
		this->m_edits[i].SetWindowText("");
	this->EnableBaseInfo(true);
		m_btn[3].EnableWindow(true);
		m_btn[0].EnableWindow(false);
		m_btn[1].EnableWindow(false);
		m_btn[2].EnableWindow(false);
		m_btn[4].EnableWindow(true);
		m_edits[0].SetFocus();

}

void CBaseTabCtrl::OnShanChuClick()
{

	this->baseinfo_state=SHANCHU;
	for(int i=0;i<this->mc_iNumber;i++)
	this->m_edits[i].SetWindowText("");
/*	this->EnableBaseInfo(true);
	CString sql;
	sql.Format("delete * from %s where %s = '%s'",m_sTable,key_field,key_value);
	m_runsql.RunSQL(sql);
	m_btn[0].EnableWindow(true);
	m_btn[1].EnableWindow(false);
	m_btn[2].EnableWindow(false);
	this->EnableBaseInfo(false);

	this->baseinfo_state=NORMAL;*/

}

void CBaseTabCtrl::OnXiuGaiClick()
{
		this->baseinfo_state=XIUGAI;
		this->EnableBaseInfo(true);
		this->m_btn[3].EnableWindow(true);
		m_btn[0].EnableWindow(false);
		m_btn[1].EnableWindow(false);
		m_btn[2].EnableWindow(false);
		m_btn[4].EnableWindow(true);
		m_edits[0].SetFocus();
}

int CBaseTabCtrl::ShowListChaXun(int show)
{
	this->m_btnchaxun.ShowWindow(show);
	this->m_check.ShowWindow(show);
	this->m_list->ShowWindow(show);
	this->m_combofields.ShowWindow(show);
	switch(this->state)
	{
	case STRINGQUERY:
		this->m_editvalue.ShowWindow(show);
		m_tcvalue.ShowWindow(SW_HIDE);
		break;
	case RQQUERY:
		this->m_tcvalue.ShowWindow(show);
		m_editvalue.ShowWindow(SW_HIDE);
		break;
	}
	this->m_combofuhao.ShowWindow(show);

	return show;
}

void CBaseTabCtrl::OnChaXun()
{
this->RefreshListView(this->PrepareSQL());
}

LRESULT CBaseTabCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CTabCtrl::WindowProc(message, wParam, lParam);
}

void CBaseTabCtrl::OnComboFieldReturn()
{

}

void CBaseTabCtrl::OnComboFuhaoReturn()
{

}

void CBaseTabCtrl::OnEditValueReturn()
{

}

void CBaseTabCtrl::OnRqValueReturn()
{

}

void CBaseTabCtrl::OnCheckClick()
{

}

void CBaseTabCtrl::SetKey(int mark)
{
	this->key_value=this->m_list->GetItemText(mark,key_index);
	for(int i=0;i<this->mc_iNumber;i++)
	{
		this->m_edits[i].SetWindowText(this->m_list->GetItemText(mark,i));
	}
	this->EnableBaseInfo(false);
	this->m_btn[3].EnableWindow(false);
	this->m_btn[4].EnableWindow(false);
	i=3;
	while(i--)
	{
		m_btn[i].EnableWindow(true);
	}

}
bool CBaseTabCtrl::RefreshListView(CString sql)
{
return true;
}

bool CBaseTabCtrl::InitValues()
{
return true;
}

CString CBaseTabCtrl::PrepareSQL()
{
return CString("");
}

bool CBaseTabCtrl::PrepareTables(CString &output, CString &input)
{
/*
	int sel=m_check.GetCheck( );
	if(sel)
	{
		output=m_sTempTables[m_iCurTable];
		input=m_sTempTables[!m_iCurTable];
		m_iCurTable=!m_iCurTable;
	}
	else
	{
		output=m_sTable;
		input=m_sTempTables[m_iCurTable];
	}
	CString sql;
	sql.Format("delete from %s",input);
	m_runsql.RunSQL(sql);*/
	return true;	
}

void CBaseTabCtrl::OnListReturn()
{
		this->SetKey(m_list->GetSelectionMark());
		this->SetCurSel(1);
//		this->ShowBaseInfo(SW_SHOW);
//		this->ShowListChaXun(SW_HIDE);
		LRESULT P;
		this->OnSelchange(NULL,&P);
		if(m_btn[0].IsWindowVisible())
		this->m_btn[0].SetFocus();
		else this->SetFocus();
}

void CBaseTabCtrl::OnCancelClick()
{
		m_btn[0].EnableWindow(true);
		m_btn[1].EnableWindow(true);
		m_btn[2].EnableWindow(true);
		m_btn[3].EnableWindow(false);
		m_btn[4].EnableWindow(false);

/*	for(int i=0;i<this->m_list->GetItemCount();i++)
	{
		if(m_list->GetItemText(i,0)==key_value)
		{
			SetKey(i);
			this->m_list->SetSelectionMark(i);
			break;
		}
	}
		this->baseinfo_state=NORMAL;*/
}

void CBaseTabCtrl::SetTheFocus()
{

}

void CBaseTabCtrl::SetTheBaseInfoFocus()
{

}
void CBaseTabCtrl::OnSelendokComboFields()
{
	CString str;
	m_combofields.GetWindowText(str);
	if(str.Find("日期")>=0)
	{
		this->state=RQQUERY;
		ShowListChaXun(SW_SHOW);
	}
	else
	{
		this->state=STRINGQUERY;
		ShowListChaXun(SW_SHOW);	
	}
/*	if(str=="大于警戒上限")
	{
		ShowListChaXun(SW_HIDE);
	}
	else
	{

	}*/
		
}

void CBaseTabCtrl::SetListFocus(MSG *pMsg)
{
	HWND hwnd=pMsg->hwnd;
				if(hwnd==this->GetSafeHwnd())
				{
					m_combofields.SetFocus();
				}
				if(hwnd==this->m_combofields.GetSafeHwnd())
				{
					if(pMsg->wParam==13)
					this->OnComboFieldReturn();

					this->m_combofuhao.SetFocus();
				}
				else if(hwnd==this->m_combofuhao.GetSafeHwnd())
				{
					if(pMsg->wParam==13)
					this->OnComboFuhaoReturn();
					switch(this->state)
					{
					case STRINGQUERY:
						this->m_editvalue.SetFocus();
						break;
					case RQQUERY:
						this->m_tcvalue.SetFocus();
						break;
					}
				}
				else if(hwnd==m_editvalue.GetSafeHwnd()||hwnd==m_tcvalue.GetSafeHwnd())
				{
				
					this->m_check.SetFocus();
				}
				else if(hwnd==this->m_check.GetSafeHwnd())
				{
					this->m_btnchaxun.SetFocus();
				}
				else if(hwnd==m_btnchaxun.GetSafeHwnd())
				{
										
					if(pMsg->wParam==13)
					{
						int iID=::GetDlgCtrlID(hwnd);
						::PostMessage(this->GetSafeHwnd(),WM_COMMAND,iID,(UINT)hwnd);
					}

					this->m_list->SetFocus();
				
				}
				else if(hwnd==m_list->GetSafeHwnd())
				{
					if(pMsg->wParam==13)
					{
					this->OnListReturn();
					}
					else
					this->m_combofields.SetFocus();
				}
}

⌨️ 快捷键说明

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