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

数据库系统

开发平台:

Visual C++

  1. // UnDepre.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Equipment.h"
  5. #include "UnDepre.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CUnDepre dialog
  13. extern CEquipmentApp theApp;
  14. CUnDepre::CUnDepre(CWnd* pParent /*=NULL*/)
  15. : CDialog(CUnDepre::IDD, pParent)
  16. {
  17. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
  18. }
  19. void CUnDepre::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CUnDepre)
  23. DDX_Control(pDX, IDC_RICHEDIT2, memo);
  24. DDX_Control(pDX, IDC_DATETIMEPICKER1, currentdate);
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(CUnDepre, CDialog)
  28. //{{AFX_MSG_MAP(CUnDepre)
  29. ON_COMMAND(ID_BUTTONDELETE, OnButtondelete)
  30. ON_COMMAND(ID_BUTTONCLOSE, OnButtonclose)
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CUnDepre message handlers
  35. void CUnDepre::OnOK() 
  36. {
  37. // TODO: Add extra validation here
  38. }
  39. void CUnDepre::OnCancel() 
  40. {
  41. // TODO: Add extra cleanup here
  42. CDialog::OnCancel();
  43. }
  44. BOOL CUnDepre::OnInitDialog() 
  45. {
  46. CDialog::OnInitDialog();
  47. SetIcon(m_hIcon,true);
  48. toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
  49. toolbar.SetBitmapSize(CSize(32,32));
  50. imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
  51. for (int n =0;n<5;n++)
  52. {
  53. imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
  54. }
  55. toolbar.SetImageList(&imagelist);
  56. TBBUTTON  buttons[3];
  57. for (int i =0; i<3;i++)
  58. {
  59. CString str;
  60. int strlength;
  61. CCHAR *temp;
  62. if (i<1)
  63. buttons[i].fsStyle =TBSTYLE_SEP;
  64. else
  65. {
  66. buttons[i].fsStyle =TBSTYLE_BUTTON;
  67. }
  68. buttons[i].fsState =TBSTATE_ENABLED;
  69. buttons[i].dwData =0;
  70. if (i == 1) 
  71. {
  72. buttons[i].idCommand = ID_BUTTONADD+2; //对应于删除
  73. buttons[i].iBitmap = 2;
  74. str.LoadString(IDS_Undepre);
  75. }
  76. else
  77. {
  78. buttons[i].idCommand = ID_BUTTONADD+4;//退出
  79. buttons[i].iBitmap = 4;
  80. str.LoadString(ID_BUTTONADD+4);
  81. }
  82. strlength = str.GetLength()+1;
  83. temp = str.GetBufferSetLength(strlength);
  84. temp[strlength]= '';
  85. temp[strlength-1]= '';
  86. buttons[i].iString = toolbar.AddStrings(temp);
  87. str.ReleaseBuffer();
  88. }
  89. toolbar.AutoSize();
  90. toolbar.AddButtons(3,buttons);
  91. toolbar.ShowWindow(SW_SHOW);
  92. CString str;
  93. str = "注意:n   本系统反计提折旧只允许对当前会计期已计提折旧的固定资产进行反计提,如果当前会计期没有计提折旧固定资产,不允许反计提.";
  94. memo.SetWindowText(str);
  95. CTime t = CTime::GetCurrentTime();
  96. currentdate.SetTime(&t);
  97. return TRUE; 
  98. }
  99. void CUnDepre::OnButtondelete() 
  100. {
  101. //查询当前会计期是否进行计提折旧
  102. if (MessageBox("确实要进行反计提管理吗?","提示",MB_YESNO)==IDYES)
  103. {
  104. CString id,sql;
  105. CTime t;
  106. currentdate.GetTime(t);
  107. id = CTime::GetCurrentTime().Format("%Y%m");
  108. _RecordsetPtr recordset;
  109. recordset = theApp.datamanage->Record1;
  110. recordset->raw_Close();
  111. sql.Format( "select tag from tb_depreciation where tag = '%s'",id);
  112. recordset->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  113. if ( recordset->RecordCount <1)
  114. {
  115. MessageBox("本期没有进行资产折旧,不能进行反计提.","提示",64);
  116. return ;
  117. }
  118. //进行反计提
  119. try
  120. {
  121. theApp.datamanage->GetConn()->BeginTrans();
  122. sql.Format("select * from tb_equipmentinfo where Enabled =0 and (equipmentid not in (select equipmentid from tb_equipmentinfo where year(regdate) = '%s' and month(regdate) = '%s')) or equipmentid in (select equipmentid from tb_equipmentdecrease where year(cleardate) = '%s' and month(cleardate) = '%s')",t.Format("%Y"),t.Format("%m"),t.Format("%Y"),t.Format("%m"));
  123. recordset->raw_Close();
  124. recordset->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  125. if (recordset->RecordCount >0)
  126. {
  127. while (!recordset->ADOEOF)
  128. {
  129. CString c_id,c_method;
  130. float premonths,months;
  131. premonths = (float)recordset->GetFields()->GetItem("preusemonth")->Value;
  132. months = (float)recordset->GetFields()->GetItem("depreciationmonth")->Value;
  133. c_id = recordset->GetFields()->GetItem("equipmentid")->Value.bstrVal;
  134. c_method = recordset->GetFields()->GetItem("depremethod")->Value.bstrVal;
  135. if (c_method == "平均年限法1")
  136. {
  137. //折旧方法  累计折旧 = 累计折旧+月折旧额
  138. recordset->GetFields()->GetItem("depreciation")->Value = (float)recordset->GetFields()->GetItem("depreciation")->Value - (float)recordset->GetFields()->GetItem("monthdeprevalue")->Value ;
  139. recordset->GetFields()->GetItem("depreciationmonth")->Value= (float)recordset->GetFields()->GetItem("depreciationmonth")->Value-1;
  140. recordset->Update();
  141. }
  142. else //平均年限法2
  143. {
  144. recordset->GetFields()->GetItem("depreciationmonth")->Value= (float)recordset->GetFields()->GetItem("depreciationmonth")->Value-1;
  145. //折旧方法  月折旧额= (入账原值 -累计折旧-预计净残值)/(预计使用月份-已计提月份)
  146. recordset->GetFields()->GetItem("monthdeprevalue")->Value= ((float)recordset->GetFields()->GetItem("sourcevalue")->Value-(float)recordset->GetFields()->GetItem("depreciation")->Value-(float)recordset->GetFields()->GetItem("prenetvalue")->Value)/((float)recordset->GetFields()->GetItem("preusemonth")->Value-(float)recordset->GetFields()->GetItem("depreciationmonth")->Value);
  147. recordset->Update();
  148. }
  149. recordset->MoveNext();
  150. }
  151. sql.Format("delete tb_depreciation where tag = '%s'",id);
  152. theApp.datamanage->ExecSQL(sql);
  153. theApp.datamanage->GetConn()->CommitTrans();
  154. MessageBox("操作成功.","提示",64);
  155. }
  156. else
  157. MessageBox("没有可折旧的固定资产.","提示",64);
  158. }
  159. catch(...)
  160. {
  161. theApp.datamanage->GetConn()->RollbackTrans();
  162. MessageBox("操作失败.","提示",64);
  163. }
  164. }
  165. }
  166. void CUnDepre::OnButtonclose() 
  167. {
  168. EndDialog(0);
  169. }