Click here to Skip to main content
15,913,854 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSource code Prunning Pin
axid3j1al11-Mar-04 21:35
axid3j1al11-Mar-04 21:35 
GeneralRe: Source code Prunning Pin
Steve S12-Mar-04 0:25
Steve S12-Mar-04 0:25 
Generaldo you use new()?please instruct me! Pin
vividtang11-Mar-04 21:31
vividtang11-Mar-04 21:31 
GeneralRe: do you use new()?please instruct me! Pin
toxcct11-Mar-04 21:48
toxcct11-Mar-04 21:48 
GeneralRe: do you use new()?please instruct me! Pin
jhwurmbach11-Mar-04 22:15
jhwurmbach11-Mar-04 22:15 
GeneralRe: do you use new()?please instruct me! Pin
vividtang12-Mar-04 0:22
vividtang12-Mar-04 0:22 
GeneralRe: do you use new()?please instruct me! Pin
jhwurmbach12-Mar-04 0:24
jhwurmbach12-Mar-04 0:24 
GeneralRe: do you use new()?please instruct me! Pin
vividtang12-Mar-04 16:21
vividtang12-Mar-04 16:21 
jhwurmbach ,thank you again.please help me
below it is my "MainFrm.h"
#include "TheChildFrame.h"

#if !defined(AFX_MAINFRM_H__72AAD2C8_6374_49B1_907D_7CA96509F1F8__INCLUDED_)
#define AFX_MAINFRM_H__72AAD2C8_6374_49B1_907D_7CA96509F1F8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CMainFrame : public CMDIFrameWnd
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();

// Attributes
public:

CTheChildFrame *m_pAdd,*m_pChange; // 指向三个功能窗口
BOOL m_bLogin; // 登录状态
BOOL m_bItemAdd,m_bItemChange; // 相应的菜单项及工具栏按钮是否可用
// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;

// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnUpdateSystemConnect(CCmdUI* pCmdUI);
afx_msg void OnUpdateSystemDisconnect(CCmdUI* pCmdUI);
afx_msg void OnUpdateManageAdd(CCmdUI* pCmdUI);
afx_msg void OnSystemConnect();
afx_msg void OnSystemDisconnect();
afx_msg void OnDestroy();
afx_msg void OnManageAdd();
afx_msg void OnUpdateManagerChange(CCmdUI* pCmdUI);
afx_msg void OnManagerChange();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINFRM_H__72AAD2C8_6374_49B1_907D_7CA96509F1F8__INCLUDED_)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
below it is my "MainFrm.cpp"
#include "stdafx.h"
#include "Personnel3.h"
#include "LoginDlg.h"
#include "AddView.h"
#include "ChangeView.h"
#include "MainFrm.h"
//#include "TheChildFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//include "TheChildFrame.h"
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
extern CDatabase db;
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_SYSTEM_CONNECT, OnUpdateSystemConnect)
ON_UPDATE_COMMAND_UI(ID_SYSTEM_DISCONNECT, OnUpdateSystemDisconnect)
ON_UPDATE_COMMAND_UI(ID_MANAGE_ADD, OnUpdateManageAdd)
ON_COMMAND(ID_SYSTEM_CONNECT, OnSystemConnect)
ON_COMMAND(ID_SYSTEM_DISCONNECT, OnSystemDisconnect)
ON_WM_DESTROY()
ON_COMMAND(ID_MANAGE_ADD, OnManageAdd)
ON_UPDATE_COMMAND_UI(ID_MANAGER_CHANGE, OnUpdateManagerChange)
ON_COMMAND(ID_MANAGER_CHANGE, OnManagerChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
ID_SEPARATOR,
//ID_INDICATOR_LOGIN,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
m_bLogin=FALSE; // 缺省未登录
m_bItemAdd=FALSE; // "增加新员工"功能缺省为不可用
m_bItemChange=FALSE; // "人事变动"功能缺省为不可用
//m_bItemSearch=FALSE; // "查询修改"功能缺省为不可用
m_pAdd=m_pChange=NULL;
// 初始化为空

}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}

// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);

return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnUpdateSystemConnect(CCmdUI* pCmdUI)
{ pCmdUI->Enable(!m_bLogin);

}

void CMainFrame::OnUpdateSystemDisconnect(CCmdUI* pCmdUI)
{ pCmdUI->Enable(m_bLogin);

}

void CMainFrame::OnUpdateManageAdd(CCmdUI* pCmdUI)
{ pCmdUI->Enable(m_bItemAdd);

}

void CMainFrame::OnUpdateManagerChange(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bItemChange);

}


void CMainFrame::OnSystemConnect()
{
CLoginDlg dlg;

if(dlg.DoModal()==IDOK)
{
m_bLogin=TRUE; // 已登录
m_bItemAdd=TRUE; // 开放"增加新员工"功能
m_bItemChange=TRUE; // 开放"人事变动"功能
// m_bItemSearch=TRUE; // 开放"查询修改"功能

}
}

void CMainFrame::OnSystemDisconnect()
{
db.Close(); // 关闭数据库
// 关闭所有子框架窗口
if(m_pAdd) m_pAdd->DestroyWindow();
if(m_pChange) m_pChange->DestroyWindow();
//if(m_pSearch) m_pSearch->DestroyWindow();

m_bLogin=FALSE; // 未登录
m_bItemAdd=FALSE; // 禁止"增加新员工"功能
m_bItemChange=FALSE; // 禁止"人事变动"功能
//m_bItemSearch=FALSE; // 禁止"查询修改"功能
// 改变状态栏
//m_wndStatusBar.SetPaneText(1, "尚未登录数据库!请按F2登录");

}




void CMainFrame::OnDestroy()
{
CMDIFrameWnd::OnDestroy();

if(db.IsOpen()) db.Close();
}
void CMainFrame::OnManageAdd()
{
// 创建新子框架和视
m_pAdd=new CTheChildFrame(); /*
CCreateContext context;
context.m_pNewViewClass=RUNTIME_CLASS(CAddView);
if(!m_pAdd->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,this, &context )) return;
m_pAdd->InitialUpdateFrame(NULL,TRUE);

m_bItemAdd=FALSE; // 禁止"增加新员工"功能*/
}



void CMainFrame::OnManagerChange()
{
// 创建新子框架和视
// m_pChange = new MainFrmame();
/* CCreateContext context;
context.m_pNewViewClass=RUNTIME_CLASS(CChangeView);
if(!m_pChange->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,this, &context )) return;
m_pChange->InitialUpdateFrame(NULL,TRUE);

m_bItemChange=FALSE; // 禁止"人事变动"功能 */
}
below it is "AddView.cpp"
#include "stdafx.h"
#include "Personnel3.h"
#include "AddView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAddView
extern CDatabase db;
IMPLEMENT_DYNCREATE(CAddView, CFormView)

CAddView::CAddView()
: CFormView(CAddView::IDD)
{
//{{AFX_DATA_INIT(CAddView)
m_strDepartment = _T("");
m_strEdulevel = _T("");
m_strJob = _T("");
m_strBirthday = _T("");
m_strEmail = _T("");
m_strID = _T("");
m_strMemo = _T("");
m_strName = _T("");
m_strPasswd = _T("");
m_strSpecialty = _T("");
m_strAddress = _T("");
m_strTel = _T("");
//}}AFX_DATA_INIT
}

CAddView::~CAddView()
{
}

void CAddView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddView)
DDX_Control(pDX, IDC_ADD_CMB_JOB, m_cJob);
DDX_Control(pDX, IDC_ADD_CMB_EDULEVEL, m_cEdulevel);
DDX_Control(pDX, IDC_ADD_CMB_DEPARTMENT, m_cDepartment);
DDX_CBString(pDX, IDC_ADD_CMB_DEPARTMENT, m_strDepartment);
DDX_CBString(pDX, IDC_ADD_CMB_EDULEVEL, m_strEdulevel);
DDX_CBString(pDX, IDC_ADD_CMB_JOB, m_strJob);
DDX_Text(pDX, IDC_ADD_EDT_BIRTHDAY, m_strBirthday);
DDX_Text(pDX, IDC_ADD_EDT_EMAIL, m_strEmail);
DDX_Text(pDX, IDC_ADD_EDT_ID, m_strID);
DDX_Text(pDX, IDC_ADD_EDT_MEMO, m_strMemo);
DDX_Text(pDX, IDC_ADD_EDT_NAME, m_strName);
DDX_Text(pDX, IDC_ADD_EDT_PASSWD, m_strPasswd);
DDX_Text(pDX, IDC_ADD_EDT_SPECIALTY, m_strSpecialty);
DDX_Text(pDX, IDC_ADD_EDT_ADDRESS, m_strAddress);
DDX_Text(pDX, IDC_ADD_EDT_TEL, m_strTel);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddView, CFormView)
//{{AFX_MSG_MAP(CAddView)
ON_BN_CLICKED(IDC_ADD_BTN_ADD, OnAddBtnAdd)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddView diagnostics

#ifdef _DEBUG
void CAddView::AssertValid() const
{
CFormView::AssertValid();
}

void CAddView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAddView message handlers
void CAddView::Init()
{
// 清空成员变量
m_strID = _T("");
m_strPasswd = _T("");
m_strName = _T("");
m_strBirthday = _T("");
m_strDepartment = _T("");
m_cDepartment.SetCurSel(-1);
m_strJob = _T("");
m_cJob.SetCurSel(-1);
m_strEdulevel = _T("");
m_cEdulevel.SetCurSel(-1);
m_strSpecialty = _T("");
m_strAddress = _T("");
m_strTel = _T("");
m_strEmail = _T("");
m_strMemo = _T("");

// 生成员工号
CString str;
int counter; // 用于计数
CRecordset rs(&db); // 数据集
rs.Open(CRecordset::forwardOnly,
"select COUNTER_VALUE from COUNTER where ID='P'");
rs.GetFieldValue("COUNTER_VALUE", str);
sscanf(str, "%d", &counter); // 获取计数值
rs.Close();
str.Format("P%05d", counter); // 产生标准格式的编号
m_strID=str; // 自动产生员工号
m_strPasswd=str; // 默认密码为员工号

// 设置缺省性别为男
((CButton*)GetDlgItem(IDC_ADD_RADIO_MALE))->SetCheck(TRUE);

UpdateData(FALSE); // 更新界面数据
}

void CAddView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit(FALSE);

GetParentFrame()->SetWindowText("增加新员工"); // 设置标题

CRecordset rs(&db); // 数据集
CString str;
// 设置部门下拉框所取的值为DEPARTMENT表中的值
rs.Open(CRecordset::forwardOnly, "select NAME from DEPARTMENT");
while(!rs.IsEOF())
{
rs.GetFieldValue("NAME", str);
m_cDepartment.AddString(str);
rs.MoveNext();
}
rs.Close();

// 设置职务下拉框所取的值为JOB表中的值
rs.Open(CRecordset::forwardOnly, "select DESCRIPTION from JOB");
while(!rs.IsEOF())
{
rs.GetFieldValue("DESCRIPTION", str);
m_cJob.AddString(str);
rs.MoveNext();
}
rs.Close();

// 设置受教育水平下拉框所取的值为EDU_LEVEL表中的值
rs.Open(CRecordset::forwardOnly, "select DESCRIPTION from EDU_LEVEL");
while(!rs.IsEOF())
{
rs.GetFieldValue("DESCRIPTION", str);
m_cEdulevel.AddString(str);
rs.MoveNext();
}
rs.Close();

Init(); // 调用初始化函数

}

void CAddView::OnAddBtnAdd()
{ CString str,strSQL;
int counter; // 用于计数
CRecordset rs(&db); // 数据集

UpdateData(); // 更新数据
if(m_strName.IsEmpty()) // 姓名为空则返回
{
AfxMessageBox("姓名不能为空!");
return;
}

// 累加员工编号计数器
rs.Open(CRecordset::forwardOnly,"select COUNTER_VALUE from COUNTER where ID='P'");
rs.GetFieldValue("COUNTER_VALUE", str);
sscanf(str, "%d", &counter); // 获取计数值
rs.Close(); // 关闭数据集
counter++; // 计数值加1
str.Format("%d", counter); // 转换为字符串
strSQL="update COUNTER set COUNTER_VALUE=" + str + " where ID='P'"; // 设置SQL语句
db.ExecuteSQL(strSQL); // 执行
// 增加员工个人信息记录
CString strPasswd,strSex,strDepID,strJobID,strEduID;
// 判断生日是否为空
if(m_strBirthday.IsEmpty()) m_strBirthday="1900-1-1"; // 缺省值
// 加密密码
strPasswd=m_strPasswd;
// 判断性别
if(((CButton*)GetDlgItem(IDC_ADD_RADIO_MALE))->GetCheck()) strSex="M";
else strSex="F";
// 得到部门ID
rs.Open(CRecordset::forwardOnly,
"select ID from DEPARTMENT where NAME='" + m_strDepartment +"'");
rs.GetFieldValue("ID", strDepID);
rs.Close();
// 得到职务代码
rs.Open(CRecordset::forwardOnly,
"select CODE from JOB where DESCRIPTION='" + m_strJob +"'");
rs.GetFieldValue("CODE", strJobID);
rs.Close();
// 得到受教育水平代码
rs.Open(CRecordset::forwardOnly,
"select CODE from EDU_LEVEL where DESCRIPTION='" + m_strEdulevel +"'");
rs.GetFieldValue("CODE", strEduID);
rs.Close();
// 写SQL语句
strSQL="insert into PERSON(ID,PASSWD,NAME,SEX,\
BIRTHDAY,DEPARTMENT,JOB,EDU_LEVEL,SPECIALTY,\
ADDRESS,TEL,EMAIL,REMARK) \
values('"
+ m_strID + "','" // ID
+ strPasswd + "','" // PASSWD
+ m_strName + "','" // NAME
+ strSex + "','" // SEX
+ m_strBirthday + "','" // BIRTHDAY
+ strDepID + "','" // DEPARTMENT
+ strJobID + "','" // JOB
+ strEduID + "','" // EDU_LEVEL
+ m_strSpecialty + "','" // SPECIALTY
+ m_strAddress + "','" // ADDRESS
+ m_strTel + "','" // TEL
+ m_strEmail + "','" // EMAIL
+ m_strMemo + "')"; // REMARK
db.ExecuteSQL(strSQL); // 执行
// 获取人事变动记录号并累加
rs.Open(CRecordset::forwardOnly,
"select COUNTER_VALUE from COUNTER where ID='C'");
rs.GetFieldValue("COUNTER_VALUE", str);
sscanf(str, "%d", &counter); // 获取计数值
rs.Close(); // 关闭数据集
counter++; //计数值加1
str.Format("%d", counter); // 转换为字符串
strSQL="update COUNTER set COUNTER_VALUE=" + str + " where ID='C'"; // 设置SQL语句
db.ExecuteSQL(strSQL); // 执行
// 追加人事变动记录
str.Format("%d",counter); // 计数值转换为字符串
CTime time=CTime::GetCurrentTime();
CString strNow=time.Format("%Y-%m-%d %H:%M:%S");
// 写SQL语句
strSQL="insert into PERSONNEL(ID,PERSON,CHANGE,\
RECORD_TIME,DESCRIPTION)\
values("
+ str + ",'" // ID
+ m_strID + "','" // PERSON
+ "0" + "','" // CHANGE - 加入公司代码
+ strNow + "','" // RECORD_TIME
+ "加入公司')"; // DESCRIPTION
db.ExecuteSQL(strSQL);

// 重新初始化窗口
Init();

}

void CAddView::OnDestroy()
{
CFormView::OnDestroy();

((CMainFrame*)AfxGetMainWnd())->m_bItemAdd=TRUE; // 开放"增加新员工"功能
((CMainFrame*)AfxGetMainWnd())->m_pAdd=NULL; // 清空窗口指针

}
GeneralRe: do you use new()?please instruct me! Pin
vividtang12-Mar-04 16:33
vividtang12-Mar-04 16:33 
GeneralTAPI Pin
chen_chen121211-Mar-04 20:51
chen_chen121211-Mar-04 20:51 
GeneralRe: TAPI Pin
Michael P Butler11-Mar-04 21:29
Michael P Butler11-Mar-04 21:29 
GeneralLanguage bar like app (IME) help pls Pin
Bagoj11-Mar-04 20:38
Bagoj11-Mar-04 20:38 
GeneralA question about asycfilt.dll Pin
Atif Mushtaq11-Mar-04 20:11
Atif Mushtaq11-Mar-04 20:11 
GeneralAccess Violation during Excel Automation Pin
Ajay Mudgal11-Mar-04 19:52
Ajay Mudgal11-Mar-04 19:52 
GeneralPlugin Frameworks Pin
Tarundeep Singh Kalra11-Mar-04 19:46
Tarundeep Singh Kalra11-Mar-04 19:46 
GeneralRe: Plugin Frameworks Pin
Florin Ochiana11-Mar-04 23:27
Florin Ochiana11-Mar-04 23:27 
GeneralRe: Plugin Frameworks Pin
Roger Allen12-Mar-04 1:05
Roger Allen12-Mar-04 1:05 
GeneralCCriticalSection Object frezee Pin
Do Manh Hung11-Mar-04 19:40
Do Manh Hung11-Mar-04 19:40 
GeneralRe: CCriticalSection Object frezee Pin
Neville Franks11-Mar-04 22:19
Neville Franks11-Mar-04 22:19 
GeneralRe: CCriticalSection Object frezee Pin
Do Manh Hung11-Mar-04 22:30
Do Manh Hung11-Mar-04 22:30 
GeneralRe: CCriticalSection Object frezee Pin
Neville Franks12-Mar-04 11:48
Neville Franks12-Mar-04 11:48 
Questionhow to hide a shortcut from desktop window? Pin
shoma11-Mar-04 18:24
shoma11-Mar-04 18:24 
AnswerRe: how to hide a shortcut from desktop window? Pin
Alexander M.,12-Mar-04 5:28
Alexander M.,12-Mar-04 5:28 
GeneralRe: how to hide a shortcut from desktop window? Pin
shoma14-Mar-04 15:57
shoma14-Mar-04 15:57 
Generalabout TAPI Pin
denly11-Mar-04 17:23
denly11-Mar-04 17:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.