/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PAM_0602.cs * 2.功能描述:工资结算 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2015/08/28 1.00 新建 *******************************************************************************/ using System; using System.Windows.Forms; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.Basics.BaseControls; using System.Data; using Dongke.IBOSS.PRD.Basics.Library; namespace Dongke.IBOSS.PRD.Client.PAMModule { /// /// 工资结算 /// public partial class F_PAM_0602 : FormBase { #region 成员变量 //单例模式 private static F_PAM_0602 _instance; // 最后选择行 private int _selecedRow; // 合算年月 private DateTime? _payrollAccountYYYYMM = null; #endregion #region 构造函数 public F_PAM_0602() { InitializeComponent(); this.Text = FormTitles.F_PAM_0602; } #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static F_PAM_0602 Instance { get { if (_instance == null) { _instance = new F_PAM_0602(); } return _instance; } } #endregion #region 事件 /// /// 窗体加载 /// private void F_PAM_0201_Load(object sender, EventArgs e) { dtpStartTime.Value = DateTime.Now; DataSet dsSystemDate = (DataSet)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.GetSettlementTime(); })); if (dsSystemDate != null && dsSystemDate.Tables[0].Rows.Count > 0) { DateTime time = Convert.ToDateTime(dsSystemDate.Tables[0].Rows[0]["datevalue"]); lblDescription.Text = string.Format("最近工资结算的会计账务日期{0}", time.Year.ToString() + (time.Month.ToString().Length < 2 ? "0" + time.Month.ToString() : time.Month.ToString())); this._payrollAccountYYYYMM = time; } } /// /// 窗体关闭事件 /// private void F_PAM_0201_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 结算按钮事件 /// /// /// private void c_Button1_Click(object sender, EventArgs e) { try { int year = dtpStartTime.Value.Year; int month = dtpStartTime.Value.Month; DateTime time = new DateTime(year, month, 1); if (time < this._payrollAccountYYYYMM) { MessageBox.Show("结算必须大于已结算的月"); return; } DateTime startTime = DateTime.Now; this.dtpStartTime.Enabled = false; int returnRow = (int)DoAsync(new BaseAsyncMethod(() => { return PAMModuleProxy.Service.SavePayPiecework(month, year); })); this.dtpStartTime.Enabled = true; if (returnRow > 0) { DateTime endTime = DateTime.Now; TimeSpan ts = endTime - startTime; System.Text.StringBuilder mes = new System.Text.StringBuilder(); mes.AppendLine("结 算 月:" + time.ToString("yyyy-MM")); mes.AppendLine("结算日期:" + dateTimePicker1.Value.ToString("yyyy-MM-dd") + "~" + dtpEndTime.Value.ToString("yyyy-MM-dd")); mes.AppendLine("操作时间:" + startTime.ToString("yyyy-MM-dd HH:mm:ss") + "~" + endTime.ToString("yyyy-MM-dd HH:mm:ss")); mes.Append("耗 时:" + ts.TotalHours.ToString("##0.00") + "小时"); // 写日志 OutputLog.Trace(LogPriority.Information, this.Text, "工资结算", mes.ToString()); MessageBox.Show("结算成功"); this.DialogResult = DialogResult.OK; } else if (returnRow == -99) { MessageBox.Show("此月已经结算"); return; } else { MessageBox.Show("结算失败"); this.DialogResult = DialogResult.No; } //DateTime endTime = DateTime.Now; //TimeSpan ts = endTime - startTime; //MessageBox.Show(ts.Days+"天"+ts.Hours+"小时"+ts.Minutes+"分钟"+ts.Seconds+"秒"); this.Close(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } #endregion private void dtpStartTime_ValueChanged(object sender, EventArgs e) { DataSet dsSystemSettings = (DataSet)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.GetSystemData(); })); if (dsSystemSettings != null && dsSystemSettings.Tables[0].Rows.Count > 0) { // 算出此月一共多少天,防止设置的值,大于当月的天数 int daysCount = DateTime.DaysInMonth(dtpStartTime.Value.Year, dtpStartTime.Value.Month); DataRow[] dr = dsSystemSettings.Tables[0].Select("SettingCode='S_CMN_0003'"); DateTime? dateStartTime = null; DateTime? dateEndTime = null; if (dr.Length > 0) { if (dr[0]["SettingValue"].ToString() == "月末") { dateStartTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, 1); dateEndTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, daysCount, 23, 59, 59); } else { // 选择的值,大于当月的天数 if (Convert.ToInt32(dr[0]["SettingValue"]) > daysCount) { dateEndTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, daysCount, 23, 59, 59); dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1); } else { dateEndTime = new DateTime(dtpStartTime.Value.Year, dtpStartTime.Value.Month, Convert.ToInt32(dr[0]["SettingValue"].ToString()), 23, 59, 59); dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1); } } dateTimePicker1.Value = Convert.ToDateTime(dateStartTime); dtpEndTime.Value = Convert.ToDateTime(dateEndTime); } } } } }