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

数据库系统

开发平台:

Visual C++

  1. // ReduceKinds.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Equipment.h"
  5. #include "ReduceKinds.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. // CReduceKinds dialog
  14. CReduceKinds::CReduceKinds(CWnd* pParent /*=NULL*/)
  15. : CDialog(CReduceKinds::IDD, pParent)
  16. {
  17. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
  18. }
  19. void CReduceKinds::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CReduceKinds)
  23. DDX_Control(pDX, IDC_EDIT1, kind);
  24. DDX_Control(pDX, IDC_LIST, list);
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(CReduceKinds, CDialog)
  28. //{{AFX_MSG_MAP(CReduceKinds)
  29. ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
  30. ON_COMMAND(ID_BUTTONADD, OnButtonadd)
  31. ON_COMMAND(ID_BUTTONCLOSE, OnButtonclose)
  32. ON_COMMAND(ID_BUTTONDELETE, OnButtondelete)
  33. ON_COMMAND(ID_BUTTONREFRESH, OnButtonrefresh)
  34. ON_COMMAND(ID_BUTTONUPDATE, OnButtonupdate)
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CReduceKinds message handlers
  39. void CReduceKinds::OnOK() 
  40. {
  41. }
  42. BOOL CReduceKinds::OnInitDialog() 
  43. {
  44. CDialog::OnInitDialog();
  45. SetIcon(m_hIcon,true);
  46. //设置列表风格
  47. list.SetExtendedStyle(LVS_REPORT|LVS_EX_FULLROWSELECT|LVS_OWNERDRAWFIXED |LVS_EX_FLATSB|LVS_SHOWSELALWAYS|LVS_EX_HEADERDRAGDROP);
  48. list.InsertColumn(1,"资产减少方式");//向列表中添加列
  49. list.SetColumnWidth(0,300);//设置列宽度
  50. OnButtonrefresh();
  51. toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
  52. toolbar.SetBitmapSize(CSize(32,32));
  53. imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
  54. for (int n =0;n<5;n++)
  55. {
  56. imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
  57. }
  58. toolbar.SetImageList(&imagelist);
  59. //toolbar.AddBitmap(5,IDR_TOOLBAR2);
  60. TBBUTTON  buttons[6];
  61. for (int i =0; i<6;i++)
  62. {
  63. CString str;
  64. int strlength;
  65. CCHAR *temp;
  66. str.LoadString(ID_BUTTONADD+i-1);//第一个按钮为分隔条
  67. strlength = str.GetLength()+1;
  68. temp = str.GetBufferSetLength(strlength);
  69. temp[strlength]= '';
  70. temp[strlength-1]= '';
  71. if (i<1)
  72. buttons[i].fsStyle =TBSTYLE_SEP;
  73. else
  74. {
  75. buttons[i].fsStyle =TBSTYLE_BUTTON;
  76. }
  77. buttons[i].fsState =TBSTATE_ENABLED;
  78. buttons[i].dwData =0;
  79. buttons[i].idCommand = ID_BUTTONADD+i-1;
  80. buttons[i].iString = toolbar.AddStrings(temp);
  81. buttons[i].iBitmap = i-1;
  82. str.ReleaseBuffer();
  83. }
  84. toolbar.AutoSize();
  85. toolbar.AddButtons(6,buttons);
  86. toolbar.ShowWindow(SW_SHOW);
  87. return TRUE;  // return TRUE unless you set the focus to a control
  88.               // EXCEPTION: OCX Property Pages should return FALSE
  89. }
  90. BOOL CReduceKinds::PreTranslateMessage(MSG* pMsg) 
  91. {
  92. if (pMsg->message ==WM_KEYDOWN)
  93. if (pMsg->wParam ==13)
  94. pMsg->wParam = 9;
  95. return CDialog::PreTranslateMessage(pMsg);
  96. }
  97. bool CReduceKinds::IsRepeated(CString str)
  98. {
  99. CString sql;
  100. sql.Format("select * from tb_decreasekinds where decreasekinds = '%s'",str);
  101. theApp.datamanage->Record1->raw_Close();
  102. theApp.datamanage->Record1->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
  103. if(theApp.datamanage->Record1->RecordCount>0)
  104. return true;
  105. return false;
  106. }
  107. void CReduceKinds::OnClickList(NMHDR* pNMHDR, LRESULT* pResult) 
  108. {
  109. int currentrow = list.GetSelectionMark();//得到当前行
  110. if (currentrow!=-1)
  111. {
  112. kind.SetWindowText(list.GetItemText(currentrow,0));
  113. }
  114. else
  115. kind.SetWindowText("");
  116. *pResult = 0;
  117. }
  118. void CReduceKinds::OnButtonadd() 
  119. {
  120. CString str;
  121. kind.GetWindowText(str);
  122. if (!str.IsEmpty())
  123. {
  124. if (!IsRepeated(str))
  125. {
  126. try
  127. {
  128. CString sql;
  129. sql.Format("insert into tb_decreasekinds values ('%s')",str);
  130. theApp.datamanage->ExecSQL(sql);
  131. this->MessageBox("操作成功.","提示",64);
  132. kind.SetWindowText("");
  133. kind.SetFocus();
  134. }
  135. catch(...)
  136. {
  137. this->MessageBox("操作失败.","提示",64);
  138. kind.SetFocus();
  139. kind.SetSel(0);
  140. }
  141. OnButtonrefresh() ;
  142. }
  143. else
  144. MessageBox("该类别已存在.","提示",64);
  145. }
  146. else
  147. AfxMessageBox("基础信息不能为空.",0,0);
  148. }
  149. void CReduceKinds::OnButtonclose() 
  150. {
  151. EndDialog(0);
  152. }
  153. void CReduceKinds::OnButtondelete() 
  154. {
  155. if(MessageBox("确实要删除当前记录吗?","提示",MB_YESNO)==IDYES)
  156. if (theApp.datamanage->GetRecordset()->RecordCount>0)
  157. {
  158. int currentrow = list.GetSelectionMark();//得到当前行
  159. if (currentrow!=-1)
  160. {
  161. CString sql,olddata;
  162. olddata = list.GetItemText(currentrow,0);
  163. sql.Format("delete tb_decreasekinds where decreasekinds = '%s'",olddata);
  164. try
  165. {
  166. theApp.datamanage->ExecSQL(sql);
  167. MessageBox("操作成功.","提示",64);
  168. }
  169. catch(_com_error &e)
  170. {
  171. MessageBox("操作失败.","提示",64);
  172. }
  173. OnButtonrefresh();
  174. }
  175. else
  176. {
  177. MessageBox("请在表格中选择欲删除的数据.","提示",64);
  178. }
  179. }
  180. else
  181. MessageBox("当前没有可删除的记录.","提示");
  182. }
  183. void CReduceKinds::OnButtonrefresh() 
  184. {
  185. kind.SetWindowText("");
  186. list.DeleteAllItems();
  187. theApp.datamanage->GetRecordset()->raw_Close();
  188. theApp.datamanage->GetRecordset()->Open("select decreasekinds as 资产减少方式 from tb_decreasekinds",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  189. if (theApp.datamanage->GetRecordset()->RecordCount >0)
  190. {
  191. while (! theApp.datamanage->GetRecordset()->ADOEOF)
  192. {
  193. CString str;
  194. _variant_t temp;
  195. temp =theApp.datamanage->GetRecordset()->GetCollect((long)0);
  196. str = temp.bstrVal;
  197. list.InsertItem(0,str,0);
  198. theApp.datamanage->GetRecordset()->MoveNext();
  199. }
  200. }
  201. }
  202. void CReduceKinds::OnButtonupdate() 
  203. {
  204. if (theApp.datamanage->GetRecordset()->RecordCount >0)
  205. {
  206. if(MessageBox("确实要修改当前数据吗?","提示",MB_YESNO)==IDYES )
  207. {
  208. CString str;
  209. kind.GetWindowText(str);
  210. if (str.IsEmpty()) //判断能力基础信息是否为空
  211. {
  212. MessageBox("基础信息不能为空","提示",64);
  213. }
  214. else if (!IsRepeated(str))
  215. {
  216. int currentrow = list.GetSelectionMark();//得到当前行
  217. if (currentrow!=-1)
  218. {
  219. try
  220. {
  221. CString sql,olddata;
  222. olddata = list.GetItemText(currentrow,0);
  223. sql.Format("update tb_decreasekinds set decreasekinds = '%s' where decreasekinds = '%s'",str,olddata);
  224. theApp.datamanage->ExecSQL(sql);
  225. this->MessageBox("操作成功.","提示",64);
  226. kind.SetWindowText("");
  227. kind.SetFocus();
  228. }
  229. catch(...)
  230. {
  231. MessageBox("操作失败.","提示",64);
  232. }
  233. OnButtonrefresh() ;
  234. }
  235. else
  236. {
  237. MessageBox("当前没有可修改的数据.","提示",64);
  238. }
  239. }
  240. else
  241. MessageBox("该类别已经存在.","提示",64);
  242. }
  243. }
  244. else
  245. MessageBox("当前没有可修改的数据.","提示",64);
  246. }