📄 customermanageview.cpp
字号:
_RecordsetPtr m_pADOSet;
CString strSQL;
int Index = 0;
try
{
m_pADOSet.CreateInstance(__uuidof(Recordset));
strSQL = "select ID,客户类型 from CustomerType";
m_pADOSet = theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
while(!m_pADOSet->adoEOF)
{
Index = m_type.AddString((LPCSTR)(_bstr_t)m_pADOSet->GetCollect("客户类型"));
m_type.SetItemData(Index,m_pADOSet->GetCollect("ID").intVal);
m_pADOSet->MoveNext();
}
m_pADOSet->Close();
}
catch(_com_error e)
{
MessageBox(e.Description(),MB_OK);
return;
}
m_type.SetCurSel(0);
}
#include "ustomerTypeDlg.h"
void CCustomerManageView::OnCustomerTypeSet()
{
// TODO: Add your command handler code here
CustomerTypeDlg dlg;
dlg.DoModal();
}
#include "ustomerTractSetDlg.h"
void CCustomerManageView::OnCustomerTractSet()
{
// TODO: Add your command handler code here
CustomerTractSetDlg dlg;
dlg.DoModal();
}
LRESULT CCustomerManageView::OnInsertDataToTreeCtrl(WPARAM wParam,LPARAM lParam)
{
m_list.DeleteAllItems();
int ID = (int)lParam;
int nCount = 0;
int Index = 0;
CString strSQL;
_RecordsetPtr m_pADOSet;
try
{
m_pADOSet.CreateInstance(__uuidof(Recordset));
switch (ID)
{
case -100:
{
CString stime;
COleDateTime time = COleDateTime::GetCurrentTime();
stime = time.Format("%Y-%m-%d");
strSQL.Format("select C.*,T.所属地域,Y.客户类型 from CustomerInfo C \
,CustomerTract T,CustomerType Y where C.到期时间<#%s# and \
Y.ID=C.客户类型 and T.ID=C.所属地域",stime);
break;
}
case -110:
{
CString stime;
COleDateTime time = COleDateTime::GetCurrentTime();
stime = time.Format("%Y-%m-%d");
strSQL.Format("select C.*,T.所属地域,Y.客户类型 from CustomerInfo C \
,CustomerTract T,CustomerType Y where C.到期时间>=#%s# and \
Y.ID=C.客户类型 and T.ID=C.所属地域",stime);
break;
}
case -1:
{
strSQL= "select C.*,T.所属地域,Y.客户类型 from CustomerInfo C \
,CustomerTract T,CustomerType Y where \
Y.ID=C.客户类型 and T.ID=C.所属地域";
break;
}
default:
{
strSQL.Format("%s%d","select C.*,T.所属地域,Y.客户类型 from CustomerInfo C \
,CustomerTract T,CustomerType Y where C.所属地域=T.ID and \
Y.ID=C.客户类型 and C.所属地域=",ID);
break;
}
}
m_pADOSet = theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
_variant_t Query;
while(!m_pADOSet->adoEOF)
{
Index = m_list.GetItemCount();
m_list.InsertItem(Index,"");
m_list.SetItemText(Index,0,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("姓名"));
m_list.SetItemText(Index,1,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("简称"));
m_list.SetItemText(Index,2,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("电话"));
m_list.SetItemText(Index,3,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("地址"));
m_list.SetItemText(Index,4,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("IP"));
// m_list.SetItemText(Index,5,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("掩码"));
// m_list.SetItemText(Index,6,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("网关"));
m_list.SetItemText(Index,5,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("MAC"));
m_list.SetItemText(Index,6,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("入网时间"));
m_list.SetItemText(Index,7,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("到期时间"));
m_list.SetItemText(Index,8,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("Y.客户类型"));
m_list.SetItemText(Index,9,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("T.所属地域"));
m_list.SetItemText(Index,10,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("备注"));
m_list.SetItemText(Index,11,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("ID"));
m_pADOSet->MoveNext();
nCount++;
}
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
if(pFrame != NULL)
pFrame->SendMessage(WM_SET_STATUES_INFO,0,(LPARAM)nCount);
m_pADOSet->Close();
}
catch(_com_error e)
{
MessageBox(e.Description(),MB_OK);
return 0;
}
return 1;
}
void CCustomerManageView::InsertListViewData()
{
CString strSQL;
int nCount = 0;
int Index = 0;
_RecordsetPtr m_pADOSet;
try
{
m_pADOSet.CreateInstance(__uuidof(Recordset));
strSQL.Format("%s","select C.*,T.所属地域,Y.客户类型 from CustomerInfo C \
,CustomerTract T,CustomerType Y where C.所属地域=T.ID and \
Y.ID=C.客户类型");
m_pADOSet = theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
while(!m_pADOSet->adoEOF)
{
Index = m_list.GetItemCount();
m_list.InsertItem(Index,"");
m_list.SetItemText(Index,0,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("姓名"));
m_list.SetItemText(Index,1,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("简称"));
m_list.SetItemText(Index,2,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("电话"));
m_list.SetItemText(Index,3,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("地址"));
m_list.SetItemText(Index,4,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("IP"));
//m_list.SetItemText(Index,5,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("掩码"));
//m_list.SetItemText(Index,6,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("网关"));
m_list.SetItemText(Index,5,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("MAC"));
m_list.SetItemText(Index,6,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("入网时间"));
m_list.SetItemText(Index,7,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("到期时间"));
m_list.SetItemText(Index,8,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("Y.客户类型"));
m_list.SetItemText(Index,9,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("T.所属地域"));
m_list.SetItemText(Index,10,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("备注"));
m_list.SetItemText(Index,11,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("ID"));
m_pADOSet->MoveNext();
nCount++;
}
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
if(pFrame != NULL)
pFrame->SendMessage(WM_SET_STATUES_INFO,0,(LPARAM)nCount);
m_pADOSet->Close();
}
catch(_com_error e)
{
MessageBox(e.Description(),MB_OK);
return;
}
}
#include "ustomerInfoSetDlg.h"
#include "resource.h"
void CCustomerManageView::OnSetCustomerInfo()
{
// TODO: Add your command handler code here
CustomerInfoSetDlg dlg;
dlg.DoModal();
}
CString CCustomerManageView::GetSearchCondition()
{
CString strSQL;
int Index = 0;
Index = m_condition.GetCurSel();
CString Value;
m_values.GetWindowText(Value);
switch(m_field.GetCurSel())
{
case 0:
if(Index == 0)
strSQL = "姓名='" + Value + "'";
else
strSQL = "姓名 like '%" + Value +"%'";
break;
case 1:
if(Index == 0)
strSQL = "简称='" + Value + "'";
else
strSQL = "简称 like '%" + Value + "%'";
break;
case 2:
if(Index == 0)
strSQL = "电话='" + Value + "'";
else
strSQL = "电话 like '%" + Value + "%'";
break;
case 3:
if(Index == 0)
strSQL = "地址='" + Value + "'";
else
strSQL = "地址 like '%" + Value + "%'";
break;
case 4:
if(Index == 0)
strSQL = "IP='" + Value + "'";
else
strSQL = "IP like '%" + Value + "%'";
strSQL = "IP";
break;
case 5:
if(Index == 0)
strSQL = "MAC='" + Value + "'";
else
strSQL = "MAC like '%" + Value + "%'";
strSQL = "MAC";
break;
case 6:
{
COleDateTime time = COleDateTime::GetCurrentTime();
COleDateTime time1 = COleDateTime::GetCurrentTime();
m_stimectrl.GetTime(time);
m_etimectrl.GetTime(time1);
strSQL = "入网时间>#" + time.Format("%Y-%m-%d") + "# and 入网时间<#" + time1.Format("%Y-%m-%d") + "#";
break;
}
case 7:
{
COleDateTime time = COleDateTime::GetCurrentTime();
COleDateTime time1 = COleDateTime::GetCurrentTime();
m_stimectrl.GetTime(time);
m_etimectrl.GetTime(time1);
strSQL = "到期时间>#" + time.Format("%Y-%m-%d") + "# and 到期时间<#" + time1.Format("%Y-%m-%d") + "#";
break;
}
break;
case 8:
strSQL.Format("C.客户类型=%d",m_type.GetItemData(m_type.GetCurSel()));
break;
}
strSQL = "select C.*, T.客户类型,Y.所属地域 from CustomerInfo C,CustomerType T,CustomerTract Y\
where " + strSQL + " and C.客户类型=T.ID and C.所属地域=Y.ID ";
return strSQL;
}
void CCustomerManageView::DeleteListItem(CString sID)
{
for(int i=0;i<m_list.GetItemCount();i++)
{
if(m_list.GetItemText(i,11) == sID)
{
m_list.DeleteItem(i);
break;
}
}
}
void CCustomerManageView::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_CUSTOMER_MANAGE_VIEW)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
void CCustomerManageView::OnDeleteCurrentCustomer()
{
// TODO: Add your command handler code here
int nSelect = -1;
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
if(MessageBox("你真的要删除吗?","提示",MB_YESNO) == IDYES)
{
while(pos)
{
nSelect = m_list.GetNextSelectedItem(pos);
CString sID;
sID = m_list.GetItemText(nSelect,11);
CString strSQL;
strSQL.Format("delete from CustomerInfo where ID=%s",sID);
try
{
theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
}
catch(_com_error e)
{
MessageBox(e.Description(),MB_OK);
return;
}
m_list.DeleteItem(nSelect);
pos = m_list.GetFirstSelectedItemPosition();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -