?? tabyg.cpp
字號:
// TabYG.cpp: implementation of the CTabYG class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "a1.h"
#include "TabYG.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTabYG::CTabYG(int e_n)
:CBaseTabCtrl(e_n)
{
}
CTabYG::~CTabYG()
{
delete [] m_statics;
delete [] m_edits;
delete m_list;
delete [] m_btn;
m_statics=NULL;
m_edits=NULL;
m_list=NULL;
m_btn=NULL;
CString sql;
sql.Format("delete from %s",m_sTempTables[0]);
m_dataYg.m_runsql.RunSQL(sql);
sql.Format("delete from %s",m_sTempTables[1]);
m_dataYg.m_runsql.RunSQL(sql);
}
BEGIN_MESSAGE_MAP(CTabYG, CBaseTabCtrl)
//{{AFX_MSG_MAP(CTabYG)
ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)//NM_DBLCLK
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_BUTTONCHAXUN,OnChaXun)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
bool CTabYG::InitList()
{
CBaseTabCtrl::InitList();
CString sub_str;
POSITION pos=this->m_dataYg.m_pstrlistFields_Names[1].GetHeadPosition();
for(int i=0;i<8;i++)
{
m_list->InsertColumn(i,m_dataYg.m_pstrlistFields_Names[1].GetNext(pos));
}
for(i=0;i<8;i++)
m_list->SetColumnWidth(i,LVSCW_AUTOSIZE_USEHEADER);
m_list->Invalidate();
m_combofields.AddString("員工編號");
m_combofields.AddString("員工姓名");
m_combofields.AddString("員工性別");
m_combofields.AddString("聘用日期");
m_combofields.AddString("備注");
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_dataYg.m_runsql.RunSQL(sql);
m_check.SetCheck(0);
sql.Format("INSERT INTO %s SELECT * FROM %s",m_sTempTables[0],m_sTable);
m_dataYg.m_runsql.RunSQL(sql);
sql.Format("select * from %s",m_sTempTables[0]);
this->m_dataYg.SelectListCtrl(this->m_list);
this->m_dataYg.RefreshListView(sql);
m_iCurTable=0;
return true;
}
bool CTabYG::InitSelf()
{
CBaseTabCtrl::InitSelf();
SetItemSize(CSize(50,20));
CTabCtrl::InsertItem(0,"員工信息查詢");
CTabCtrl::InsertItem(1,"員工信息管理");
return true;
}
bool CTabYG::InitValues()
{
m_sFuhao[0]="=";
m_sFuhao[1]=">";
m_sFuhao[2]="<";
m_sFuhao[3]=">=";
m_sFuhao[4]="<=";
m_sFuhao[5]="LIKE";
m_sTable="tabyginfo";
m_sTempTables[0]="lsyg0";
m_sTempTables[1]="lsyg1";
return true;
}
void CTabYG::OnBaoCunClick()
{
CString value;
this->GetValuesFromEdits();
if(this->baseinfo_state==ZENGJIA)
{
if(!this->m_dataYg.InsertCurValue())
{
MessageBox("增加數(shù)據(jù)錯誤","錯誤");
return;
}
}
else if(this->baseinfo_state==XIUGAI)
{
this->GetValuesFromEdits();
if(!this->m_dataYg.UpdateCurValue())
{
MessageBox("修改數(shù)據(jù)錯誤","錯誤");
return;
}
}
else
return;
CBaseTabCtrl::OnBaoCunClick();
baseinfo_state=NORMAL;
}
CString CTabYG::PrepareSQL()
{
CString field_name,field,fuhao,value,inputtable,outputtable,sql;
this->PrepareTables(outputtable,inputtable);
m_combofields.GetWindowText(field_name);
field=this->m_dataYg.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_dataYg.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_dataYg.m_runsql.RunSQL(sql);
sql.Format("select * from %s",inputtable);
}
return sql;
}
void CTabYG::OnShanChuClick()
{ CString str;
m_edits[0].GetWindowText(str);
if(str=="")
{
MessageBox("請選擇某條紀錄");
return;
}
if(MessageBox("確定要刪除嗎?刪除后不可恢復(fù),并且相關(guān)的庫存信息也將被刪除!","注意!",
MB_YESNO)!=IDYES)
return ;
this->GetValuesFromEdits();
if(!this->m_dataYg.DeleteCurValue())
return;
CBaseTabCtrl::OnShanChuClick();
this->m_dataYg.data=CDataYG::data_yg();
}
void CTabYG::OnCancelClick()
{
if(!this->SetValuesIntoEdits())
{
for(int i=0;i<mc_iNumber;i++)
{
this->m_edits[i].SetWindowText("");
}
}
EnableBaseInfo(false);
baseinfo_state=NORMAL;
CBaseTabCtrl::OnCancelClick();
}
void CTabYG::OnChaXun()
{
this->m_dataYg.RefreshListView(this->PrepareSQL());
}
void CTabYG::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
int i=this->GetCurSel();
switch(i)
{
case 0:
m_check.SetCheck(0);
this->m_dataYg.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 CTabYG::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_dataYg.m_pstrlistFields_Names[1].GetHeadPosition();
for(int i=0;i<4;i++)
{
this->m_statics[i*2].Create(m_dataYg.m_pstrlistFields_Names[1].GetNext(pos)+":",WS_CHILD,rect1,this,ID_STATICS_1+i*2);
this->m_statics[i*2+1].Create(m_dataYg.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);
}
m_edits[5].ShowWindow(SW_HIDE);
rect4.OffsetRect(0,-height*2);
rect4.right=rect4.right-153;
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 CTabYG::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);
}
m_edits[5].ShowWindow(SW_HIDE);
this->m_rq.ShowWindow(show);
return show;
}
bool CTabYG::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 CTabYG::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 CTabYG::OnZengJiaClick()
{
CBaseTabCtrl::OnZengJiaClick();
CTime t=CTime::GetCurrentTime();
m_rq.SetTime(&t);
m_edits[0].SetWindowText(this->ChanShengID());
m_edits[0].SetReadOnly();
m_edits[1].SetFocus();
}
void CTabYG::OnXiuGaiClick()
{
CString str;
m_edits[0].GetWindowText(str);
if(str=="")
{
MessageBox("請選擇某條紀錄");
return;
}
CBaseTabCtrl::OnXiuGaiClick();
m_edits[0].SetReadOnly();
m_edits[1].SetFocus();
m_edits[1].SetSel(0,-1);
}
bool CTabYG::SetValuesIntoEdits()
{
CString value;
value= this->m_dataYg.data.yg_id;if(value=="")return false; this->m_edits[0].SetWindowText(value);
value= this->m_dataYg.data.yg_name; this->m_edits[1].SetWindowText(value);
value= this->m_dataYg.data.sex; this->m_edits[2].SetWindowText(value);
value= this->m_dataYg.data.sort; this->m_edits[3].SetWindowText(value);
value= this->m_dataYg.data.position; this->m_edits[4].SetWindowText(value);
value= this->m_dataYg.data.rq; //this->m_edits[5].SetWindowText(value);
int y=0,m=0,d=0;
DateToInt(value,y,m,d);
CTime t(y,m,d,0,0,0);
this->m_rq.SetTime(&t);
value.Format("%0.2f",this->m_dataYg.data.salary); this->m_edits[6].SetWindowText(value);
value= this->m_dataYg.data.memo; this->m_edits[7].SetWindowText(value);
return true;
}
bool CTabYG::GetValuesFromEdits()
{
CString value;
this->m_edits[0].GetWindowText(value);if(value=="")return false;this->m_dataYg.data.yg_id=value;
this->m_edits[1].GetWindowText(value);this->m_dataYg.data.yg_name=value;
this->m_edits[2].GetWindowText(value);this->m_dataYg.data.sex=value;
this->m_edits[3].GetWindowText(value);this->m_dataYg.data.sort=value;
this->m_edits[4].GetWindowText(value);this->m_dataYg.data.position=value;
this->m_rq.GetWindowText(value); this->m_dataYg.data.rq=value;
this->m_edits[6].GetWindowText(value);this->m_dataYg.data.salary=atof(value);
this->m_edits[7].GetWindowText(value);this->m_dataYg.data.memo=value;
return true;
}
void CTabYG::SetTheBaseInfoFocus()
{
HWND hwnd=::GetFocus();
int iID=::GetDlgCtrlID(hwnd);
// enum{ID_EDITS_1=161};
// enum{ID_BUTTONS_1=201};
if(hwnd==this->m_rq.GetSafeHwnd())iID=166;
if(iID==160+mc_iNumber)
goto jumpbtn;
if(iID>160&&iID<160+mc_iNumber)
{
int pID=iID+1;
if(this->GetDlgItem(pID)->IsWindowEnabled())
{
CEdit* a=(CEdit*)GetDlgItem(pID);
if(pID==166)
{
this->m_rq.SetFocus();
}
else
{
a->SetFocus();
a->SetSel(0,-1);
}
return;
}
}
else return;
jumpbtn:
for(int i=0;i<5;i++)
if(this->m_btn[i].IsWindowEnabled())
{
m_btn[i].SetFocus();
break;
}
// this->SetFocus();
// if(this->m_btn[3].IsWindowEnabled())m_btn[3].SetFocus();
// else if(this->m_btn[4].IsWindowEnabled())m_btn[4].SetFocus();
// else {
// ::PostMessage(this->GetSafeHwnd(),WM_KEYDOWN,VK_TAB,0);
// }
}
void CTabYG::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 CTabYG::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_dataYg.m_runsql.RunSQL(sql);
return true;
}
CString CTabYG::ChanShengID()
{
CString sql;
sql.Format("select yg_id from tabyginfo order by yg_id asc");
if(!this->m_dataYg.m_runsql.CheckSQLResult(sql))
{
return CString("YG00001");
}
_variant_t value;int i;
CString result;
for(i=1;i<99999;i++)
{
value=m_dataYg.m_runsql.m_recordset->GetCollect("yg_id");
CString str=(char*)(_bstr_t)value;
CString sub=str.Mid(2);
int number=atoi(sub);
if(number!=i)
{
break;
}
m_dataYg.m_runsql.m_recordset->MoveNext();
if(m_dataYg.m_runsql.m_recordset->adoEOF)
{
i++;
break;
}
}
if(i==99999)
{
MessageBox("員工數(shù)量大于99999了","錯誤");
return CString("");
}
result.Format("YG%05d",i);
return result;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -