F_PAM_0602.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PAM_0602.cs
  5. * 2.功能描述:工资结算
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/08/28 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Windows.Forms;
  12. using Dongke.IBOSS.PRD.Client.CommonModule;
  13. using Dongke.IBOSS.PRD.Basics.BaseResources;
  14. using Dongke.IBOSS.PRD.WCF.Proxys;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using System.Data;
  17. using Dongke.IBOSS.PRD.Basics.Library;
  18. namespace Dongke.IBOSS.PRD.Client.PAMModule
  19. {
  20. /// <summary>
  21. /// 工资结算
  22. /// </summary>
  23. public partial class F_PAM_0602 : FormBase
  24. {
  25. #region 成员变量
  26. //单例模式
  27. private static F_PAM_0602 _instance;
  28. // 最后选择行
  29. private int _selecedRow;
  30. // 合算年月
  31. private DateTime? _payrollAccountYYYYMM = null;
  32. #endregion
  33. #region 构造函数
  34. public F_PAM_0602()
  35. {
  36. InitializeComponent();
  37. this.Text = FormTitles.F_PAM_0602;
  38. }
  39. #endregion
  40. #region 单例模式
  41. /// <summary>
  42. /// 单例模式,防止重复创建窗体
  43. /// </summary>
  44. public static F_PAM_0602 Instance
  45. {
  46. get
  47. {
  48. if (_instance == null)
  49. {
  50. _instance = new F_PAM_0602();
  51. }
  52. return _instance;
  53. }
  54. }
  55. #endregion
  56. #region 事件
  57. /// <summary>
  58. /// 窗体加载
  59. /// </summary>
  60. private void F_PAM_0201_Load(object sender, EventArgs e)
  61. {
  62. dtpStartTime.Value = DateTime.Now;
  63. DataSet dsSystemDate = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  64. {
  65. return SystemModuleProxy.Service.GetSettlementTime();
  66. }));
  67. if (dsSystemDate != null && dsSystemDate.Tables[0].Rows.Count > 0)
  68. {
  69. DateTime time = Convert.ToDateTime(dsSystemDate.Tables[0].Rows[0]["datevalue"]);
  70. lblDescription.Text = string.Format("最近工资结算的会计账务日期{0}", time.Year.ToString() + (time.Month.ToString().Length < 2 ? "0" + time.Month.ToString() : time.Month.ToString()));
  71. this._payrollAccountYYYYMM = time;
  72. }
  73. }
  74. /// <summary>
  75. /// 窗体关闭事件
  76. /// </summary>
  77. private void F_PAM_0201_FormClosed(object sender, FormClosedEventArgs e)
  78. {
  79. _instance = null;
  80. }
  81. /// <summary>
  82. /// 结算按钮事件
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. private void c_Button1_Click(object sender, EventArgs e)
  87. {
  88. try
  89. {
  90. int year = dtpStartTime.Value.Year;
  91. int month = dtpStartTime.Value.Month;
  92. DateTime time = new DateTime(year, month, 1);
  93. if (time < this._payrollAccountYYYYMM)
  94. {
  95. MessageBox.Show("结算必须大于已结算的月");
  96. return;
  97. }
  98. DateTime startTime = DateTime.Now;
  99. this.dtpStartTime.Enabled = false;
  100. int returnRow = (int)DoAsync(new BaseAsyncMethod(() =>
  101. {
  102. return PAMModuleProxy.Service.SavePayPiecework(month, year);
  103. }));
  104. this.dtpStartTime.Enabled = true;
  105. if (returnRow > 0)
  106. {
  107. DateTime endTime = DateTime.Now;
  108. TimeSpan ts = endTime - startTime;
  109. System.Text.StringBuilder mes = new System.Text.StringBuilder();
  110. mes.AppendLine("结 算 月:" + time.ToString("yyyy-MM"));
  111. mes.AppendLine("结算日期:" + dateTimePicker1.Value.ToString("yyyy-MM-dd") + "~" + dtpEndTime.Value.ToString("yyyy-MM-dd"));
  112. mes.AppendLine("操作时间:" + startTime.ToString("yyyy-MM-dd HH:mm:ss") + "~" + endTime.ToString("yyyy-MM-dd HH:mm:ss"));
  113. mes.Append("耗 时:" + ts.TotalHours.ToString("##0.00") + "小时");
  114. // 写日志
  115. OutputLog.Trace(LogPriority.Information, this.Text, "工资结算", mes.ToString());
  116. MessageBox.Show("结算成功");
  117. this.DialogResult = DialogResult.OK;
  118. }
  119. else if (returnRow == -99)
  120. {
  121. MessageBox.Show("此月已经结算");
  122. return;
  123. }
  124. else
  125. {
  126. MessageBox.Show("结算失败");
  127. this.DialogResult = DialogResult.No;
  128. }
  129. //DateTime endTime = DateTime.Now;
  130. //TimeSpan ts = endTime - startTime;
  131. //MessageBox.Show(ts.Days+"天"+ts.Hours+"小时"+ts.Minutes+"分钟"+ts.Seconds+"秒");
  132. this.Close();
  133. }
  134. catch (Exception ex)
  135. {
  136. // 对异常进行共通处理
  137. ExceptionManager.HandleEventException(this.ToString(),
  138. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  139. }
  140. }
  141. #endregion
  142. private void dtpStartTime_ValueChanged(object sender, EventArgs e)
  143. {
  144. DataSet dsSystemSettings = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  145. {
  146. return SystemModuleProxy.Service.GetSystemData();
  147. }));
  148. if (dsSystemSettings != null && dsSystemSettings.Tables[0].Rows.Count > 0)
  149. {
  150. // 算出此月一共多少天,防止设置的值,大于当月的天数
  151. int daysCount = DateTime.DaysInMonth(dtpStartTime.Value.Year, dtpStartTime.Value.Month);
  152. DataRow[] dr = dsSystemSettings.Tables[0].Select("SettingCode='S_CMN_0003'");
  153. DateTime? dateStartTime = null;
  154. DateTime? dateEndTime = null;
  155. if (dr.Length > 0)
  156. {
  157. if (dr[0]["SettingValue"].ToString() == "月末")
  158. {
  159. dateStartTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, 1);
  160. dateEndTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, daysCount, 23, 59, 59);
  161. }
  162. else
  163. {
  164. // 选择的值,大于当月的天数
  165. if (Convert.ToInt32(dr[0]["SettingValue"]) > daysCount)
  166. {
  167. dateEndTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, daysCount, 23, 59, 59);
  168. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  169. }
  170. else
  171. {
  172. dateEndTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, Convert.ToInt32(dr[0]["SettingValue"].ToString()), 23, 59, 59);
  173. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  174. }
  175. }
  176. dateTimePicker1.Value = Convert.ToDateTime(dateStartTime);
  177. dtpEndTime.Value = Convert.ToDateTime(dateEndTime);
  178. }
  179. }
  180. }
  181. }
  182. }