【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-UseState.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// UseState.cpp : implementation file
//
#include "stdafx.h"
#include "Equipment.h"
#include "UseState.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CEquipmentApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CUseState dialog
CUseState::CUseState(CWnd* pParent /*=NULL*/)
: CDialog(CUseState::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
}
void CUseState::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUseState)
DDX_Control(pDX, IDC_EDIT1, kind);
DDX_Control(pDX, IDC_LIST, list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUseState, CDialog)
//{{AFX_MSG_MAP(CUseState)
ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
ON_COMMAND(ID_BUTTONADD, OnButtonadd)
ON_COMMAND(ID_BUTTONCLOSE, OnButtonclose)
ON_COMMAND(ID_BUTTONDELETE, OnButtondelete)
ON_COMMAND(ID_BUTTONREFRESH, OnButtonrefresh)
ON_COMMAND(ID_BUTTONUPDATE, OnButtonupdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUseState message handlers
void CUseState::OnOK()
{
// TODO: Add extra validation here
}
void CUseState::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CUseState::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon,true);
toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
toolbar.SetBitmapSize(CSize(32,32));
imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
for (int n =0;n<5;n++)
{
imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
}
toolbar.SetImageList(&imagelist);
TBBUTTON buttons[6];
for (int i =0; i<6;i++)
{
CString str;
int strlength;
CCHAR *temp;
str.LoadString(ID_BUTTONADD+i-1);//第一个按钮为分隔条
strlength = str.GetLength()+1;
temp = str.GetBufferSetLength(strlength);
temp[strlength]= '\0';
temp[strlength-1]= '\0';
if (i<1)
buttons[i].fsStyle =TBSTYLE_SEP;
else
{
buttons[i].fsStyle =TBSTYLE_BUTTON;
}
buttons[i].fsState =TBSTATE_ENABLED;
buttons[i].dwData =0;
buttons[i].idCommand = ID_BUTTONADD+i-1;
buttons[i].iString = toolbar.AddStrings(temp);
buttons[i].iBitmap = i-1;
str.ReleaseBuffer();
}
toolbar.AutoSize();
toolbar.AddButtons(6,buttons);
toolbar.ShowWindow(SW_SHOW);
list.SetExtendedStyle(LVS_REPORT|LVS_EX_FULLROWSELECT|LVS_OWNERDRAWFIXED |LVS_EX_FLATSB|LVS_SHOWSELALWAYS|LVS_EX_HEADERDRAGDROP);
list.InsertColumn(1,"资产使用状况");//向
列表中添加列
list.SetColumnWidth(0,340);//设置列宽度
OnButtonrefresh();
return TRUE;
}
bool CUseState::IsRepeated(CString str)
{
CString sql;
sql.Format("select * from tb_usestate where usestate = '%s'",str);
theApp.datamanage->Record1->raw_Close();
theApp.datamanage->Record1->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if(theApp.datamanage->Record1->RecordCount>0)
return true;
return false;
}
void CUseState::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
int currentrow = list.GetSelectionMark();//得到当前行
if (currentrow!=-1)
{
kind.SetWindowText(list.GetItemText(currentrow,0));
}
else
kind.SetWindowText("");
*pResult = 0;
}
void CUseState::OnButtonadd()
{
CString str;
kind.GetWindowText(str);
if (!str.IsEmpty())
{
if (!IsRepeated(str))
{
try
{
CString sql;
sql.Format("insert into tb_usestate values ('%s')",str);
theApp.datamanage->ExecSQL(sql);
MessageBox("操作成功.","提示",64);
kind.SetWindowText("");
kind.SetFocus();
}
catch(...)
{
MessageBox("操作失败.","提示",64);
kind.SetFocus();
kind.SetSel(0);
}
OnButtonrefresh() ;
}
else
MessageBox("该类别已存在.","提示",64);
}
else
AfxMessageBox("基础信息不能为空.",0,0);
}
void CUseState::OnButtonclose()
{
EndDialog(01);
}
void CUseState::OnButtondelete()
{
if(MessageBox("确实要删除当前记录吗?","提示",MB_YESNO)==IDYES)
if (theAp