UseState.cpp
资源名称:Equipment.rar [点击查看]
上传用户:latoyin
上传日期:2017-10-19
资源大小:2882k
文件大小:7k
源码类别:
数据库系统
开发平台:
Visual C++
- // 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]= ' ';
- temp[strlength-1]= ' ';
- 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 (theApp.datamanage->GetRecordset()->RecordCount>0)
- {
- int currentrow = list.GetSelectionMark();//得到当前行
- if (currentrow !=-1)
- {
- CString sql,olddata;
- olddata = list.GetItemText(currentrow,0);
- sql.Format("delete tb_usestate where usestate = '%s'",olddata);
- try
- {
- theApp.datamanage->ExecSQL(sql);
- MessageBox("操作成功.","提示",64);
- }
- catch(...)
- {
- MessageBox("操作失败.","提示",64);
- }
- OnButtonrefresh() ;
- }
- else
- {
- MessageBox("请在表格中选择欲删除的数据.","提示",64);
- }
- }
- else
- MessageBox("当前没有可删除的记录.","提示");
- }
- void CUseState::OnButtonrefresh()
- {
- kind.SetWindowText("");
- list.DeleteAllItems();
- theApp.datamanage->GetRecordset()->raw_Close();
- theApp.datamanage->GetRecordset()->Open("select usestate as 使用状况 from tb_usestate",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
- if (theApp.datamanage->GetRecordset()->RecordCount >0)
- {
- while (! theApp.datamanage->GetRecordset()->ADOEOF)
- {
- CString str;
- _variant_t temp;
- temp =theApp.datamanage->GetRecordset()->GetCollect((long)0);
- str = temp.bstrVal;
- list.InsertItem(0,str,0);
- theApp.datamanage->GetRecordset()->MoveNext();
- }
- }
- }
- void CUseState::OnButtonupdate()
- {
- if (theApp.datamanage->GetRecordset()->RecordCount >0)
- {
- if(MessageBox("确实要修改当前数据吗?","提示",MB_YESNO)==IDYES )
- {
- CString str;
- kind.GetWindowText(str);
- if (str.IsEmpty()) //判断能力基础信息是否为空
- {
- MessageBox("基础信息不能为空","提示",64);
- }
- else if (!IsRepeated(str))
- {
- int currentrow = list.GetSelectionMark();//得到当前行
- if (currentrow!=-1)
- {
- try
- {
- CString sql,olddata;
- olddata = list.GetItemText(currentrow,0);
- sql.Format("update tb_usestate set usestate = '%s' where usestate = '%s'",str,olddata);
- theApp.datamanage->ExecSQL(sql);
- MessageBox("操作成功.","提示",64);
- kind.SetWindowText("");
- kind.SetFocus();
- }
- catch(...)
- {
- MessageBox("操作失败.","提示",64);
- }
- OnButtonrefresh() ;
- }
- else
- {
- MessageBox("当前没有可修改的数据.","提示",64);
- }
- }
- else
- MessageBox("该类别已经存在.","提示",64);
- }
- }
- else
- MessageBox("当前没有可修改的数据.","提示",64);
- }