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

数据库系统

开发平台:

Visual C++

  1. // ReduceEquip.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Equipment.h"
  5. #include "ReduceEquip.h"
  6. #include "NumberEdit.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. extern CEquipmentApp theApp;
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CReduceEquip dialog
  15. CReduceEquip::CReduceEquip(CWnd* pParent /*=NULL*/)
  16. : CDialog(CReduceEquip::IDD, pParent)
  17. {
  18. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
  19. }
  20. void CReduceEquip::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(CReduceEquip)
  24. DDX_Control(pDX, IDC_ID, equipid);
  25. DDX_Control(pDX, IDC_REDUCEMODE, reducemode);
  26. DDX_Control(pDX, IDC_QUERYCONDITION, querycondition);
  27. DDX_Control(pDX, IDC_QUERY, query);
  28. DDX_Control(pDX, IDC_NAME, clearname);
  29. DDX_Control(pDX, IDC_CLERAERNING, clearearning);
  30. DDX_Control(pDX, IDC_CLEARREASON, clearreason);
  31. DDX_Control(pDX, IDC_CLEARECHARGE, clearcharge);
  32. DDX_Control(pDX, IDC_CLEARDATE, cleardate);
  33. DDX_Control(pDX, IDC_LIST1, list);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CReduceEquip, CDialog)
  37. //{{AFX_MSG_MAP(CReduceEquip)
  38. ON_COMMAND(ID_BUTTONREFRESH, OnButtonrefresh)
  39. ON_BN_CLICKED(IDC_QUERY, OnQuery)
  40. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  41. ON_COMMAND(ID_BUTTONDELETE, OnButtondelete)
  42. ON_COMMAND(ID_BUTTONCLOSE, OnButtonclose)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CReduceEquip message handlers
  47. void CReduceEquip::OnOK() 
  48. {
  49. // TODO: Add extra validation here
  50. }
  51. void CReduceEquip::OnCancel() 
  52. {
  53. // TODO: Add extra cleanup here
  54. CDialog::OnCancel();
  55. }
  56. BOOL CReduceEquip::OnInitDialog() 
  57. {
  58. CDialog::OnInitDialog();
  59. SetIcon(m_hIcon,true);
  60. toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
  61. toolbar.SetBitmapSize(CSize(32,32));
  62. imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
  63. for (int n =0;n<5;n++)
  64. {
  65. imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
  66. }
  67. toolbar.SetImageList(&imagelist);
  68. TBBUTTON  buttons[4];
  69. for (int i =0; i<4;i++)
  70. {
  71. CString str;
  72. int strlength;
  73. CCHAR *temp;
  74. if (i<1)
  75. buttons[i].fsStyle =TBSTYLE_SEP;
  76. else
  77. {
  78. buttons[i].fsStyle =TBSTYLE_BUTTON;
  79. }
  80. buttons[i].fsState =TBSTATE_ENABLED;
  81. buttons[i].dwData =0;
  82. if ((i ==2)|(i==3))
  83. {
  84. buttons[i].idCommand = ID_BUTTONADD+i+1;
  85. buttons[i].iBitmap = i+1;
  86. str.LoadString(ID_BUTTONADD+i+1);
  87. }
  88. else
  89. {
  90. buttons[i].idCommand = ID_BUTTONADD+i+1;
  91. buttons[i].iBitmap = i+1;
  92. str.LoadString(IDS_redusemange);//第一个按钮为分隔条
  93. }
  94. strlength = str.GetLength()+1;
  95. temp = str.GetBufferSetLength(strlength);
  96. temp[strlength]= '';
  97. temp[strlength-1]= '';
  98. buttons[i].iString = toolbar.AddStrings(temp);
  99. str.ReleaseBuffer();
  100. }
  101. toolbar.AutoSize();
  102. toolbar.AddButtons(4,buttons);
  103. toolbar.ShowWindow(SW_SHOW);
  104. list.SetExtendedStyle(LVS_REPORT|LVS_EX_FULLROWSELECT|LVS_OWNERDRAWFIXED |LVS_EX_FLATSB|LVS_SHOWSELALWAYS|LVS_EX_HEADERDRAGDROP);
  105. list.InsertColumn(100,"资产编号");
  106. list.InsertColumn(100,"资产名称");
  107. list.InsertColumn(100,"类别");
  108. list.InsertColumn(100,"增加方式");
  109. list.InsertColumn(100,"入账原值");
  110. list.InsertColumn(100,"累计折旧");
  111. for (i =0 ;i<6;i++)
  112. list.SetColumnWidth(i,100);
  113. OnButtonrefresh();
  114. return TRUE;  // return TRUE unless you set the focus to a control
  115.               // EXCEPTION: OCX Property Pages should return FALSE
  116. }
  117. void CReduceEquip::AddEquipName()
  118. {
  119. _RecordsetPtr temp;
  120. temp =theApp.datamanage->Record1; 
  121. temp->raw_Close();
  122. temp->Open("select distinct name from tb_equipmentinfo where enabled = 0",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  123. querycondition.ResetContent();
  124. while (!temp->ADOEOF)
  125. {
  126. CString str;
  127. str = temp->GetFields()->GetItem("name")->Value.bstrVal;
  128. querycondition.AddString(str);
  129. temp->MoveNext();
  130. }
  131. }
  132. void CReduceEquip::AddReduceMode()
  133. {
  134. _RecordsetPtr temp;
  135. temp =theApp.datamanage->Record1; 
  136. temp->raw_Close();
  137. temp->Open("select decreasekinds from tb_decreasekinds",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  138. reducemode.ResetContent();
  139. while (!temp->ADOEOF)
  140. {
  141. CString str;
  142. str = temp->GetFields()->GetItem("decreasekinds")->Value.bstrVal;
  143. reducemode.AddString(str);
  144. temp->MoveNext();
  145. }
  146. }
  147. void CReduceEquip::ClearText()
  148. {
  149. CWnd * temp;
  150. temp = this;
  151. for (int i= 0;i<8;i++)
  152. {
  153. temp = this->GetNextDlgTabItem(temp);
  154. temp->SetWindowText("");
  155. }
  156. //设置日期
  157. CTime t=CTime::GetCurrentTime();
  158. cleardate.SetTime(&t);
  159. list.DeleteAllItems();
  160. }
  161. bool CReduceEquip::InfoIsNull()
  162. {
  163. CWnd * temp;
  164. temp = this;
  165. for (int i= 2;i<8;i++)
  166. {
  167. temp = this->GetNextDlgTabItem(temp);
  168. CString str;
  169. temp->GetWindowText(str);
  170. if (str.IsEmpty())
  171. {
  172. return true;
  173. }
  174. }
  175. return false;
  176. }
  177. void CReduceEquip::OnButtonrefresh() 
  178. {
  179. AddEquipName();
  180. AddReduceMode();
  181. ClearText();
  182. }
  183. void CReduceEquip::OnQuery() 
  184. {
  185. CString str;
  186. querycondition.GetWindowText(str);
  187. if(!str.IsEmpty())
  188. {
  189. _RecordsetPtr temp;
  190. list.DeleteAllItems();
  191. temp =theApp.datamanage->Record1; 
  192. temp->raw_Close();
  193. CString sql;
  194. sql.Format("select * from tb_equipmentinfo where name = '%s' and enabled = 0 ",str);
  195. temp->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  196. if (temp->RecordCount>0)
  197. {
  198. int row = 0;
  199. while (!temp->ADOEOF)
  200. {
  201. list.InsertItem(row,"",0);
  202. for (int i= 0;i<6;i++)
  203. {
  204. CString str;
  205. _variant_t value;
  206. value = temp->GetFields()->GetItem((long)i)->Value;
  207. str = (TCHAR *)(_bstr_t)value;
  208. list.SetItemText(row,i,str);
  209. }
  210. row +=1;
  211. temp->MoveNext();
  212. }
  213. }
  214. else
  215. MessageBox("没有发现符合条件的数据","提示",64);
  216. }
  217. else
  218. MessageBox("请设置查询条件","提示",64);
  219. }
  220. void CReduceEquip::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
  221. {
  222. int row = list.GetSelectionMark();
  223. CString str;
  224. if (row !=-1)
  225. {
  226. str =list.GetItemText(row,0);
  227. equipid.SetWindowText(str);
  228. str =list.GetItemText(row,1);
  229. clearname.SetWindowText(str);
  230. }
  231. else
  232. {
  233. equipid.SetWindowText("");
  234. clearname.SetWindowText("");
  235. }
  236. *pResult = 0;
  237. }
  238. void CReduceEquip::OnButtondelete() 
  239. {
  240. if (!InfoIsNull())
  241. {
  242. try
  243. {
  244. theApp.datamanage->GetConn()->BeginTrans();//开始一个事务
  245. CString sql,str;
  246. equipid.GetWindowText(str);
  247. sql.Format("update tb_equipmentinfo set enabled = 1 where equipmentid = '%s'",str);
  248. theApp.datamanage->Record1->raw_Close();
  249. theApp.datamanage->Record1->Open((_variant_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
  250. CString c_id,c_mode,c_earning, c_charge,c_reason,c_date;
  251. equipid.GetWindowText(c_id);
  252. reducemode.GetWindowText(c_mode);
  253. clearearning.GetWindowText(c_earning);
  254. clearcharge.GetWindowText(c_charge);
  255. clearreason.GetWindowText(c_reason);
  256. cleardate.GetWindowText(c_date);
  257. float earning,charge;
  258. earning = atof(c_earning);
  259. charge = atof(c_charge);
  260. sql.Format("insert into tb_equipmentdecrease values ('%s','%s',%f,%f,'%s','%s')",c_id,c_mode,earning,charge,c_reason,c_date);
  261. theApp.datamanage->Record1->raw_Close();
  262. theApp.datamanage->Record1->Open((_variant_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
  263. theApp.datamanage->GetConn()->CommitTrans();//提交事务
  264. MessageBox("操作成功.","提示",64);
  265. }
  266. catch(_com_error)
  267. {
  268. theApp.datamanage->GetConn()->RollbackTrans();//出现异常,回滚事务
  269. MessageBox("系统出错.","提示",64);
  270. }
  271. OnButtonrefresh();
  272. }
  273. else
  274. {
  275. MessageBox("基础信息不能为空.","提示",64);
  276. }
  277. }
  278. BOOL CReduceEquip::PreTranslateMessage(MSG* pMsg) 
  279. {
  280. if (pMsg->message ==WM_KEYDOWN)
  281. if (pMsg->wParam ==13)
  282. pMsg->wParam = 9;
  283. return CDialog::PreTranslateMessage(pMsg);
  284. }
  285. void CReduceEquip::OnButtonclose() 
  286. {
  287. EndDialog(0);
  288. }