DeleteEquipment.cpp
上传用户:latoyin
上传日期:2017-10-19
资源大小:2882k
文件大小:6k
源码类别:

数据库系统

开发平台:

Visual C++

  1. // DeleteEquipment.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Equipment.h"
  5. #include "DeleteEquipment.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. extern CEquipmentApp theApp;
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDeleteEquipment dialog
  14. CDeleteEquipment::CDeleteEquipment(CWnd* pParent /*=NULL*/)
  15. : CDialog(CDeleteEquipment::IDD, pParent)
  16. {
  17. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
  18. currentrow = -1;
  19. //{{AFX_DATA_INIT(CDeleteEquipment)
  20. // NOTE: the ClassWizard will add member initialization here
  21. //}}AFX_DATA_INIT
  22. }
  23. void CDeleteEquipment::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CDeleteEquipment)
  27. DDX_Control(pDX, IDC_QUERYCONDITION, querycondition);
  28. DDX_Control(pDX, IDC_QUERY, query);
  29. DDX_Control(pDX, IDC_LIST1, list);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CDeleteEquipment, CDialog)
  33. //{{AFX_MSG_MAP(CDeleteEquipment)
  34. ON_COMMAND(ID_BUTTONREFRESH, OnButtonrefresh)
  35. ON_BN_CLICKED(IDC_QUERY, OnQuery)
  36. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  37. ON_COMMAND(ID_BUTTONDELETE, OnButtondelete)
  38. ON_COMMAND(ID_BUTTONCLOSE, OnButtonclose)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CDeleteEquipment message handlers
  43. void CDeleteEquipment::OnOK() 
  44. {
  45. // TODO: Add extra validation here
  46. }
  47. void CDeleteEquipment::OnCancel() 
  48. {
  49. // TODO: Add extra cleanup here
  50. CDialog::OnCancel();
  51. }
  52. BOOL CDeleteEquipment::OnInitDialog() 
  53. {
  54. CDialog::OnInitDialog();
  55. SetIcon(m_hIcon,true);
  56. toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
  57. toolbar.SetBitmapSize(CSize(32,32));
  58. imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
  59. for (int n =0;n<5;n++)
  60. {
  61. imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
  62. }
  63. toolbar.SetImageList(&imagelist);
  64. TBBUTTON  buttons[4];
  65. for (int i =0; i<4;i++)
  66. {
  67. CString str;
  68. int strlength;
  69. CCHAR *temp;
  70. if (i<1)
  71. buttons[i].fsStyle =TBSTYLE_SEP;
  72. else
  73. {
  74. buttons[i].fsStyle =TBSTYLE_BUTTON;
  75. }
  76. buttons[i].fsState =TBSTATE_ENABLED;
  77. buttons[i].dwData =0;
  78. if ((i ==2)|(i==3))
  79. {
  80. buttons[i].idCommand = ID_BUTTONADD+i+1;
  81. buttons[i].iBitmap = i+1;
  82. str.LoadString(ID_BUTTONADD+i+1);
  83. }
  84. else
  85. {
  86. buttons[i].idCommand = ID_BUTTONADD+i+1;
  87. buttons[i].iBitmap = i+1;
  88. str.LoadString(ID_BUTTONADD+i+1);//第一个按钮为分隔条
  89. }
  90. strlength = str.GetLength()+1;
  91. temp = str.GetBufferSetLength(strlength);
  92. temp[strlength]= '';
  93. temp[strlength-1]= '';
  94. buttons[i].iString = toolbar.AddStrings(temp);
  95. str.ReleaseBuffer();
  96. }
  97. toolbar.AutoSize();
  98. toolbar.AddButtons(4,buttons);
  99. toolbar.ShowWindow(SW_SHOW);
  100. list.SetExtendedStyle(LVS_EX_ONECLICKACTIVATE|LVS_REPORT|LVS_EX_FULLROWSELECT|LVS_OWNERDRAWFIXED |LVS_EX_FLATSB|LVS_SHOWSELALWAYS|LVS_EX_HEADERDRAGDROP);
  101. list.InsertColumn(100,"资产编号");
  102. list.InsertColumn(100,"资产名称");
  103. list.InsertColumn(100,"类别");
  104. list.InsertColumn(100,"增加方式");
  105. list.InsertColumn(100,"入账原值");
  106. list.InsertColumn(100,"累计折旧");
  107. for (i =0 ;i<6;i++)
  108. list.SetColumnWidth(i,100);
  109. OnButtonrefresh();
  110. return TRUE;  
  111. }
  112. void CDeleteEquipment::AddEquipName()
  113. {
  114. _RecordsetPtr temp;
  115. temp =theApp.datamanage->Record1; 
  116. temp->raw_Close();
  117. temp->Open("select distinct name from tb_equipmentinfo",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  118. querycondition.ResetContent();
  119. while (!temp->ADOEOF)
  120. {
  121. CString str;
  122. str = temp->GetFields()->GetItem("name")->Value.bstrVal;
  123. querycondition.AddString(str);
  124. temp->MoveNext();
  125. }
  126. }
  127. void CDeleteEquipment::OnButtonrefresh() 
  128. {
  129. AddEquipName();
  130. list.DeleteAllItems();
  131. }
  132. void CDeleteEquipment::OnQuery() 
  133. {
  134. CString str;
  135. querycondition.GetWindowText(str);
  136. if(!str.IsEmpty())
  137. {
  138. _RecordsetPtr temp;
  139. list.DeleteAllItems();
  140. temp =theApp.datamanage->Record1; 
  141. temp->raw_Close();
  142. CString sql;
  143. sql.Format("select * from tb_equipmentinfo where name = '%s'",str);
  144. temp->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  145. if (temp->RecordCount>0)
  146. {
  147. int row = 0;
  148. while (!temp->ADOEOF)
  149. {
  150. list.InsertItem(row,"",0);
  151. for (int i= 0;i<6;i++)
  152. {
  153. CString str;
  154. _variant_t value;
  155. value = temp->GetFields()->GetItem((long)i)->Value;
  156. str = (TCHAR *)(_bstr_t)value;
  157. list.SetItemText(row,i,str);
  158. }
  159. row +=1;
  160. temp->MoveNext();
  161. }
  162. }
  163. else
  164. MessageBox("没有发现符合条件的数据","提示",64);
  165. }
  166. else
  167. MessageBox("请设置查询条件","提示",64);
  168. }
  169. void CDeleteEquipment::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
  170. {
  171. // // TODO: Add your control notification handler code here
  172. currentrow = list.GetSelectionMark(); 
  173. *pResult = 0;
  174. }
  175. void CDeleteEquipment::OnButtondelete() 
  176. {
  177. if (MessageBox("确实要删除当前数据吗?","提示",MB_YESNO)==IDYES)
  178. {
  179. if (currentrow!=-1)
  180. {
  181. CString id;
  182. id = list.GetItemText(currentrow,0); //获得资产编号
  183. try
  184. {
  185. CString sql;
  186. sql.Format("delete from tb_equipmentinfo where equipmentid = '%s'",id);
  187. theApp.datamanage->ExecSQL(sql);
  188. MessageBox("操作成功.","提示",64);
  189. }
  190. catch(...)
  191. {
  192. MessageBox("操作失败.","提示",64);
  193. }
  194. OnButtonrefresh();
  195. currentrow = -1;
  196. }
  197. else
  198. {
  199. MessageBox("请选择欲删除的数据.","提示",64);
  200. }
  201. }
  202. }
  203. void CDeleteEquipment::OnButtonclose() 
  204. {
  205. EndDialog(0);
  206. }