break;
– 12 –
}
case IDM_CCGL_CKDJ: { }
case IDM_CCGL_RKDJ: { }
case IDM_CCGL_CCZBB: { }
case IDM_PSGL_PSSQ: { }
case IDM_PSGL_ZTFKCX: { }
case IDM_YSGL_HCQRGL: { }
case IDM_SJGL_SJBF: { }
case IDM_ZYPX_SPJZ: {
吉林省明日科技有限公司监制
m_ToolBar.SetButtonInfo(i,IDM_CCGL_CKDJ,TBBS_BUTTON,2); break;
m_ToolBar.SetButtonInfo(i,IDM_CCGL_RKDJ,TBBS_BUTTON,3); break;
m_ToolBar.SetButtonInfo(i,IDM_CCGL_CCZBB,TBBS_BUTTON,4); break;
m_ToolBar.SetButtonInfo(i,IDM_PSGL_PSSQ,TBBS_BUTTON,5); break;
m_ToolBar.SetButtonInfo(i,IDM_PSGL_ZTFKCX,TBBS_BUTTON,6); break;
m_ToolBar.SetButtonInfo(i,IDM_YSGL_HCQRGL,TBBS_BUTTON,7); break;
m_ToolBar.SetButtonInfo(i,IDM_SJGL_SJBF,TBBS_BUTTON,8); break;
m_ToolBar.SetButtonInfo(i,IDM_ZYPX_SPJZ,TBBS_BUTTON,9); break;
}
}
}
吉林省明日科技有限公司监制
3.客户区设计
(1)在主窗口添加虚函数PreTranslateMessage,为工具栏添加快捷键。具体代码如下。
BOOL CDMain::PreTranslateMessage(MSG* pMsg) {
if( pMsg->message==WM_KEYDOWN) {
CString OPID;
OPID=ado.FieldToOtherField(\操作员信息表\用户名\操作员编号\CString sSQL;
sSQL.Format(\权限表 WHERE 操作员编号=%s\int nJCXX,nCKGL,nYSGL,nXSGL,nPSGL,nXTGL; RxRecordset rst;
rst.Open(sSQL,adCmdText); if(rst.GetRecordCount()<1) { } else { }
if(pMsg->wParam==VK_F2 && nJCXX!=0)
PostMessage(WM_COMMAND,IDM_JCXX_HPXXWH); PostMessage(WM_COMMAND,IDM_XSGL_XSKP); if(pMsg->wParam==VK_F3 && nXSGL!=0) if(pMsg->wParam==VK_F4 && nCKGL!=0)
– 13 –
nJCXX=atoi(rst.GetFieldValue(\基础信息\nCKGL=atoi(rst.GetFieldValue(\仓库管理\nYSGL=atoi(rst.GetFieldValue(\运输管理\nXSGL=atoi(rst.GetFieldValue(\销售管理\nPSGL=atoi(rst.GetFieldValue(\配送管理\nXTGL=atoi(rst.GetFieldValue(\系统管理\nJCXX=1; nCKGL=1; nYSGL=1; nXSGL=1; nPSGL=1; nXTGL=1;
PostMessage(WM_COMMAND,IDM_CCGL_CKDJ); }
}
return CDialog::PreTranslateMessage(pMsg);
if(pMsg->wParam==VK_F5 && nCKGL!=0)
PostMessage(WM_COMMAND,IDM_CCGL_RKDJ); PostMessage(WM_COMMAND,IDM_CCGL_CCZBB); PostMessage(WM_COMMAND,IDM_PSGL_PSSQ); PostMessage(WM_COMMAND,IDM_PSGL_ZTFK); PostMessage(WM_COMMAND,IDM_YSGL_HCQRGL); PostMessage(WM_COMMAND,IDM_SJGL_SJBF); PostMessage(WM_COMMAND,IDM_ZYPX_SPJZ); if(pMsg->wParam==VK_F6 && nCKGL!=0) if(pMsg->wParam==VK_F7 && nPSGL!=0) if(pMsg->wParam==VK_F8 && nPSGL!=0) if(pMsg->wParam==VK_F9)
if(pMsg->wParam==VK_F11 && nXTGL!=0) if(pMsg->wParam==VK_F12)
吉林省明日科技有限公司监制
(2)添加状态栏,代码如下。
m_StatusBar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_STATUSBAR); int xpos=::GetSystemMetrics(SM_CXSCREEN); int width[4]; width[1]=xpos*0.2; width[2]=xpos*0.74; width[3]=xpos*0.86; width[4]=xpos; CString sText;
sText=\操作员:【\】\m_StatusBar.SetParts(4,&width[1]); RxRecordset rst;
4.2 基础信息基类
1.查询模块
实现目标
查询子模块可以完成的功能如下: ? 支持按照多字段、多条件查询。 ? 支持模糊查询。
? 当用户双击表格中某记录时,调用编辑模块进行编辑。 ? 支持打印功能。
查询子模块的运行界面如图6所示。
? – 14 –
吉林省明日科技有限公司监制
图6 查询子模块的运行界面
设计步骤
向项目中添加一个新Dialog资源,资源ID为IDD_BASEQUERY。从Controls面板上向Dialog资源中添加2个Static、1个Edit、2个ComboBox、1个ListControl控件。
? 代码分析
?
(1) 根据模块所要完成的功能,抽象出CDBaseQuery的原型如下:
class CDBaseQuery : public Cdialog { public:
CDBaseQuery(Cstring sCaption,
Cstring sSQL,
//窗口标题
//SQL语句字符串
Cstring sIdentify, //由程序自动生成的惟一标识字段名 int nNumberStyle, //惟一标识字段的类型 CWnd* pParent = NULL ); // 构造函数
//{{AFX_MSG(CDBaseQuery)
protected:
virtual void Init(); //为子类提供的初始化虚函数 //}}AFX_MSG
DECLARE_MESSAGE_MAP() int m_NumberStyle; RxRecordset rst;
///惟一标识字段的类型 //记录集对象 //当前行
private:
Cstring m_Identify; //由程序自动生成的惟一标识字段名 int m_CurrentRow;
Cstring m_Caption; //对话框标题 Cstring m_DateBaseName; //数据库名称
– 15 –
};
void CDBaseQuery::OnButquery() { }
Cstring sSQL,sField,sEmblem,sCondition; this->m_ComField.GetWindowText(sField); this->m_ComEmblem.GetWindowText(sEmblem); this->m_EdtCondition.GetWindowText(sCondition); //判断查询字段的类型
if(m_ComField.m_CurrentFieldType==”数值型”) }
rst.Open(sSQL,adCmdText); m_Grid.AddCellValue(rst);
吉林省明日科技有限公司监制
(2)当用户单击“查询”按钮时,根据用户选择的字段和条件进行查询:
sSQL.Format(“SELECT * FROM (%s) DERIVEDTBL WHERE %s %s %s”,\\n m_DateBaseName,sField,sEmblem,sCondition); if(sEmblem!=”LIKE”) else
sSQL.Format(“SELECT * FROM (%s) DERIVEDTBL WHERE %s %s ?%%%s%%?”,\\n m_DateBaseName,sField,sEmblem,sCondition);
sSQL.Format(“SELECT * FROM (%s) DERIVEDTBL WHERE %s %s ?%s?”,\\n m_DateBaseName,sField,sEmblem,sCondition);
else{
(3)当用户单击“打印”按钮时,通过全局变量m_ps设置打印结构:
void CDBaseQuery::OnButprint() {
Cstring sCount;
m_ps.MainCaptionFontSize=400; m_ps.DeckCaptionFontSize=180; Cstring sText;
this->GetWindowText(sText); sText=sText.Left(sText.GetLength()-4); sText=sText+”报表”; m_ps.MainCaption=sText;
sCount.Format(“%d”,rst.GetRecordCount()); m_ps.TotalNumber=1;
m_ps.Totals[0]=”共计 “+sCount+” 条记录”; m_ps.Totals[1]=””; m_ps.Grid=&m_Grid; CmyApp* theApp;
theApp=(CmyApp*)::AfxGetApp(); – 16 –