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

数据库系统

开发平台:

Visual C++

  1. // Depre.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Equipment.h"
  5. #include "Depre.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. // CDepre dialog
  14. CDepre::CDepre(CWnd* pParent /*=NULL*/)
  15. : CDialog(CDepre::IDD, pParent)
  16. {
  17. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
  18. }
  19. void CDepre::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CDepre)
  23. DDX_Control(pDX, IDC_RICHEDIT2, memo);
  24. DDX_Control(pDX, IDC_EDIT1, currentdate);
  25. DDX_Control(pDX, IDC_DATETIMEPICKER1, date);
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(CDepre, CDialog)
  29. //{{AFX_MSG_MAP(CDepre)
  30. ON_COMMAND(ID_BUTTONDELETE, OnButtondelete)
  31. ON_COMMAND(ID_BUTTONCLOSE, OnButtonclose)
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CDepre message handlers
  36. void CDepre::OnOK() 
  37. {
  38. // TODO: Add extra validation here
  39. }
  40. void CDepre::OnCancel() 
  41. {
  42. // TODO: Add extra cleanup here
  43. CDialog::OnCancel();
  44. }
  45. BOOL CDepre::OnInitDialog() 
  46. {
  47. CDialog::OnInitDialog();
  48. SetIcon(m_hIcon,true);
  49. toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
  50. toolbar.SetBitmapSize(CSize(32,32));
  51. imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
  52. for (int n =0;n<5;n++)
  53. {
  54. imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
  55. }
  56. toolbar.SetImageList(&imagelist);
  57. TBBUTTON  buttons[3];
  58. for (int i =0; i<3;i++)
  59. {
  60. CString str;
  61. int strlength;
  62. CCHAR *temp;
  63. if (i<1)
  64. buttons[i].fsStyle =TBSTYLE_SEP;
  65. else
  66. {
  67. buttons[i].fsStyle =TBSTYLE_BUTTON;
  68. }
  69. buttons[i].fsState =TBSTATE_ENABLED;
  70. buttons[i].dwData =0;
  71. if (i == 1) 
  72. {
  73. buttons[i].idCommand = ID_BUTTONADD+2; //对应于删除
  74. buttons[i].iBitmap = 2;
  75. str.LoadString(IDS_Depremanage);
  76. }
  77. else
  78. {
  79. buttons[i].idCommand = ID_BUTTONADD+4;//退出
  80. buttons[i].iBitmap = 4;
  81. str.LoadString(ID_BUTTONADD+4);
  82. }
  83. strlength = str.GetLength()+1;
  84. temp = str.GetBufferSetLength(strlength);
  85. temp[strlength]= '';
  86. temp[strlength-1]= '';
  87. buttons[i].iString = toolbar.AddStrings(temp);
  88. str.ReleaseBuffer();
  89. }
  90. toolbar.AutoSize();
  91. toolbar.AddButtons(3,buttons);
  92. toolbar.ShowWindow(SW_SHOW);
  93. CString str;
  94. str = "注意:n   本系统计提折旧按照会计制度中对资产计提折旧的有关规定处理,本期增加的固定资产,本期不计提折旧,下期计提折旧,本期减少的固定资产,本期继续计提折旧,下期停止计提折旧.";
  95. memo.SetWindowText(str);
  96. CTime t = CTime::GetCurrentTime();
  97. date.SetTime(&t);
  98. str = t.Format("%Y-%m-%d");
  99. currentdate.SetWindowText(str);
  100. return TRUE;  
  101. }
  102. void CDepre::OnButtondelete() 
  103. {
  104. //判断折旧时间是否大于系统当前时间
  105. CTime t,t1;
  106. CTimeSpan temp;
  107. date.GetTime(t);
  108. CString c_date;
  109. currentdate.GetWindowText(c_date);
  110. t1 = theApp.StrToTime(c_date);
  111. temp = t-t1;
  112. if (temp.GetDays()>=1)
  113. {
  114. MessageBox("折旧日期不能大于系统当前日期.","提示",64);
  115. return ;
  116. }
  117. //判断本期是否进行了折旧
  118. CString id,sql;
  119. id = CTime::GetCurrentTime().Format("%Y%m");
  120. _RecordsetPtr recordset;
  121. recordset = theApp.datamanage->Record1;
  122. recordset->raw_Close();
  123. sql.Format( "select tag from tb_depreciation where tag = '%s'",id);
  124. recordset->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  125. if ( recordset->RecordCount >0)
  126. {
  127. MessageBox("本期已进行了资产折旧.","提示",64);
  128. return ;
  129. }
  130. //进行计提折旧
  131. try
  132. {
  133. theApp.datamanage->GetConn()->BeginTrans();
  134. 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"));
  135. recordset->raw_Close();
  136. recordset->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
  137. if (recordset->RecordCount >0)
  138. {
  139. while (!recordset->ADOEOF)
  140. {
  141. CString c_id,c_method;
  142. float premonths,months;
  143. premonths = (float)recordset->GetFields()->GetItem("preusemonth")->Value;
  144. months = (float)recordset->GetFields()->GetItem("depreciationmonth")->Value;
  145. if (months < premonths) //已计提月份小于预计使用月份
  146. {
  147. c_id = recordset->GetFields()->GetItem("equipmentid")->Value.bstrVal;
  148. c_method = recordset->GetFields()->GetItem("depremethod")->Value.bstrVal;
  149. if (c_method == "平均年限法1")
  150. {
  151. //折旧方法  累计折旧 = 累计折旧+月折旧额
  152. recordset->GetFields()->GetItem("depreciation")->Value = (float)recordset->GetFields()->GetItem("depreciation")->Value + (float)recordset->GetFields()->GetItem("monthdeprevalue")->Value ;
  153. recordset->GetFields()->GetItem("depreciationmonth")->Value= (float)recordset->GetFields()->GetItem("depreciationmonth")->Value+1;
  154. recordset->Update();
  155. }
  156. else if (c_method == "平均年限法2")
  157. {
  158. recordset->GetFields()->GetItem("depreciationmonth")->Value= (float)recordset->GetFields()->GetItem("depreciationmonth")->Value+1;
  159. //折旧方法  月折旧额= (入账原值 -累计折旧-预计净残值)/(预计使用月份-已计提月份)
  160. 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);
  161. recordset->Update();
  162. }
  163. }
  164. recordset->MoveNext();
  165. }
  166. sql.Format("insert into tb_depreciation values ('%s' ,'%s')",id,t.Format("%Y-%m-%d"));
  167. theApp.datamanage->ExecSQL(sql);
  168. theApp.datamanage->GetConn()->CommitTrans();
  169. MessageBox("操作成功.","提示",64);
  170. }
  171. else
  172. MessageBox("没有可折旧的固定资产.","提示",64);
  173. }
  174. catch(...)
  175. {
  176. theApp.datamanage->GetConn()->RollbackTrans();
  177. MessageBox("操作失败.","提示",64);
  178. }
  179. }
  180. void CDepre::OnButtonclose() 
  181. {
  182. EndDialog(0);
  183. }