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

📄 tabdh.cpp

📁 这是一个信息管理系统的源代码
💻 CPP
字号:
// TabDH.cpp: implementation of the CTabDH class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "a1.h"
#include "TabDH.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTabDH::CTabDH(int s_n)
:CBaseTabCtrl(s_n)
{

}

CTabDH::~CTabDH()
{
	delete []	m_statics;
	delete []	m_edits;
	delete		m_list;
	delete []	m_btn;

	m_statics=NULL;
	m_edits=NULL;
	m_list=NULL;
	m_btn=NULL;
}
BEGIN_MESSAGE_MAP(CTabDH, CBaseTabCtrl)
	//{{AFX_MSG_MAP(CTabDH)
	ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)//NM_DBLCLK
	ON_BN_CLICKED(ID_BUTTONCHAXUN,OnChaXun)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
bool CTabDH::InitList()
{
	CBaseTabCtrl::InitList();
	CString sub_str;
	POSITION pos=this->m_dataDh.m_pstrlistFields_Names[1].GetHeadPosition();
	for(int i=0;i<mc_iNumber;i++)
	{
		CString str=m_dataDh.m_pstrlistFields_Names[1].GetNext(pos);
		m_list->InsertColumn(i,str);
		m_combofields.AddString(str);
	}

	for(i=0;i<mc_iNumber;i++)
		m_list->SetColumnWidth(i,LVSCW_AUTOSIZE_USEHEADER);

	m_list->Invalidate();
	

	m_combofields.SetCurSel(0);

	for(i=0;i<6;i++)
		m_combofuhao.AddString(m_sFuhao[i]);
	m_combofuhao.SetCurSel(5);
	
	state=STRINGQUERY;

	CString sql;
	sql.Format("delete * from  %s",m_sTempTables[0]);
	m_dataDh.m_runsql.RunSQL(sql);

	m_check.SetCheck(0);
	sql.Format("INSERT INTO %s SELECT * FROM %s",m_sTempTables[0],m_sTable);
	m_dataDh.m_runsql.RunSQL(sql);
	sql.Format("select * from %s",m_sTempTables[0]);

	this->m_dataDh.SelectListCtrl(this->m_list);
	this->m_dataDh.RefreshListView(sql);
	m_iCurTable=0;

	return true;
}
bool CTabDH::InitSelf()
{
	CBaseTabCtrl::InitSelf();
	SetItemSize(CSize(80,20));

	CTabCtrl::InsertItem(0,"全部调货信息");
	CTabCtrl::InsertItem(1,"所选调货信息");
	return true;
}
bool CTabDH::InitValues()
{
	m_sFuhao[0]="=";
	m_sFuhao[1]=">";
	m_sFuhao[2]="<";
	m_sFuhao[3]=">=";
	m_sFuhao[4]="<=";
	m_sFuhao[5]="LIKE";

	m_sTable="viewdh";
	m_sTempTables[0]="lsdhinfo0";
	m_sTempTables[1]="lsdhinfo1";

	return true;
}
CString CTabDH::PrepareSQL()
{
	CString field_name,field,fuhao,value,inputtable,outputtable,sql;
	this->PrepareTables(outputtable,inputtable);
	m_combofields.GetWindowText(field_name);
	field=this->m_dataDh.GetFieldFromName(field_name);
	m_combofuhao.GetWindowText(fuhao);
if(this->state==STRINGQUERY)	
{
	m_editvalue.GetWindowText(value);
	if(fuhao=="LIKE")value="%"+value+"%";
	sql.Format("INSERT INTO %s SELECT * FROM %s WHERE %s %s '%s'",inputtable,outputtable,field,fuhao,value);
	m_dataDh.m_runsql.RunSQL(sql);
	sql.Format("select * from %s",inputtable);
}
else
{
	m_tcvalue.GetWindowText(value);
	value="#"+value+"#";
	sql.Format("INSERT INTO %s SELECT * FROM %s WHERE %s %s %s",inputtable,outputtable,field,fuhao,value);
	m_dataDh.m_runsql.RunSQL(sql);
	sql.Format("select * from %s",inputtable);

}
	return sql;
}
void CTabDH::OnChaXun()
{
this->m_dataDh.RefreshListView(this->PrepareSQL());
}
void CTabDH::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
	int i=this->GetCurSel();
	switch(i)
	{
	case 0:
		m_check.SetCheck(0);
//		this->m_dataDh.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 CTabDH::InitBaseInfo()
{
	TRACE("InitBaseInfo\n");
	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;
	POSITION pos=NULL;
	pos=this->m_dataDh.m_pstrlistFields_Names[1].GetHeadPosition();

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

		this->m_statics[i*2].Create(m_dataDh.m_pstrlistFields_Names[1].GetNext(pos)+":",WS_CHILD,rect1,this,ID_STATICS_1+i*2);
		this->m_statics[i*2+1].Create(m_dataDh.m_pstrlistFields_Names[1].GetNext(pos)+":",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_dataDh.m_pstrlistFields_Names[1].GetNext(pos)+":",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);

	}


	rect4.OffsetRect(0,-height*2);
	rect4.right=rect4.right-160;
	rect4.top-=1;
	rect4.bottom+=1;
//	m_rq.Create(WS_CHILD,rect4,this,ID_YUANGONG_RQ);
//	CTime time=CTime::GetCurrentTime();
//	m_rq.SetTime(&time);
	baseinfo_state=NORMAL;
	return true;
}

int CTabDH::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(SW_HIDE);
	}
//	m_edits[5].ShowWindow(SW_HIDE);
////	this->m_rq.ShowWindow(SW_HIDE);
	return show;
}

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

void CTabDH::SetKey(int mark)
{	this->m_btn[3].EnableWindow(false);
	this->m_btn[4].EnableWindow(false);
	int i=3;
	while(i--)
	{
		m_btn[i].EnableWindow(true);
	}

	this->EnableBaseInfo(false);
	if(mark<0)return;
	for( i=0;i<this->mc_iNumber;i++)
	{
		this->m_edits[i].SetWindowText(this->m_list->GetItemText(mark,i));
	}
//	int y=0,m=0,d=0;
//	DateToInt(m_list->GetItemText(mark,5),y,m,d);
//	CTime t(y,m,d,0,0,0);
//	this->m_rq.SetTime(&t);
//	this->GetValuesFromEdits();

}
void CTabDH::SetTheBaseInfoFocus()
{	
	HWND hwnd=::GetFocus();
	int iID=::GetDlgCtrlID(hwnd);
//	enum{ID_EDITS_1=161};
	
//	enum{ID_BUTTONS_1=201};
	if(iID==160+mc_iNumber)
	{		this->SetFocus();
		return;
	}
	if(iID>160&&iID<160+mc_iNumber)
	{

			int pID=iID+1;
			if(this->GetDlgItem(pID)->IsWindowEnabled())
			{

				CEdit* a=(CEdit*)GetDlgItem(pID);

				a->SetFocus();
				a->SetSel(0,-1);

				return;
			}
	}	
	else return;
}
void CTabDH::SetTheFocus()
{
	/*
	HWND hwnd=::GetFocus();
	int iID=::GetDlgCtrlID(hwnd);
	const int theID=this->GetDlgCtrlID();

//	enum{ID_EDITS_1=161};

//	enum{ID_BUTTONS_1=201};
	if(iID==205)
	{
		this->SetFocus();return;
	}
	else if(iID==theID||(iID>200&&iID<206))
	{
		int pID=iID+1;
		if(iID==theID)pID=201;
		int n=206-pID;
		for(int i=0;i<n;i++)
		{
			if(this->GetDlgItem(pID)->IsWindowEnabled())
			{
				GetDlgItem(pID)->SetFocus();
				return;
			}
			pID++;
		}
		if(i==n)
		{
			this->SetFocus();
		}
	}*/
}

bool CTabDH::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);
	this->m_dataDh.m_runsql.RunSQL(sql);
	return true;	
}

⌨️ 快捷键说明

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