/*******************************************************************************
* 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;
namespace Dongke.IBOSS.PRD.Client.PAMModule
{
public partial class F_PAM_0605 : FormBase
{
#region 成员变量
//单例模式
private static F_PAM_0605 _instance;
// 最后选择行
//private int _selecedRow;
// 合算年月
private DateTime? _payrollAccountYYYYMM = null;
#endregion
#region 构造函数
public F_PAM_0605()
{
InitializeComponent();
this.Text = FormTitles.F_PAM_0605;
}
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_PAM_0605 Instance
{
get
{
if (_instance == null)
{
_instance = new F_PAM_0605();
}
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()));
dtpStartTime.Value = time;
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;
string yyyymm = year.ToString() + (month.ToString().Length < 2 ? "0" + month.ToString() : month.ToString());
int returnRow = (int)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.ChangePayPiecework(yyyymm);
}));
if (returnRow > 0)
{
MessageBox.Show("反结算成功");
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("反结算失败");
this.DialogResult = DialogResult.No;
}
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(dsSystemSettings.Tables[0].Rows[0]["SettingValue"]), 23, 59, 59);
dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
}
}
dateTimePicker1.Value = Convert.ToDateTime(dateStartTime);
dtpEndTime.Value = Convert.ToDateTime(dateEndTime);
}
}
}
}
}