323 lines
12 KiB
C#
323 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Model;
|
|
using System.Threading;
|
|
|
|
namespace Payroll.UI
|
|
{
|
|
public partial class fLeaveProcess : BaseFormTest
|
|
{
|
|
LeaveYear _leaveYear;
|
|
LeaveProcess _oLeaveProcess = null;
|
|
LeaveParameter oparam = new LeaveParameter();
|
|
List<LeaveYear> _oLeaveYears = new List<LeaveYear>();
|
|
delegate void DefaultDelegate(string line);
|
|
delegate void UpdateButtonEnableStatus(bool IsEnable);
|
|
delegate void ProgressBarDelegate(EnumProcessStatus statusvalue);
|
|
private EnumProcessStatus _processStatus;
|
|
private Thread _salaryProcess;
|
|
public fLeaveProcess()
|
|
{
|
|
InitializeComponent();
|
|
_processStatus = EnumProcessStatus.Start;
|
|
}
|
|
private void UpdateStatus(string status)
|
|
{
|
|
if (lblProcessdes.InvokeRequired)
|
|
{
|
|
DefaultDelegate d = new DefaultDelegate(UpdateStatus);
|
|
lblProcessdes.Invoke(d, new object[] { status });
|
|
}
|
|
else
|
|
{
|
|
lblProcessdes.Text = Convert.ToString(status);
|
|
lblProcessdes.Refresh();
|
|
if (_processStatus == EnumProcessStatus.End) throw new ServiceException("Process stoped forcely");
|
|
}
|
|
}
|
|
private void ProgressBarUpdate(EnumProcessStatus pstatus)
|
|
{
|
|
if (pbSalary.InvokeRequired)
|
|
{
|
|
ProgressBarDelegate d = new ProgressBarDelegate(ProgressBarUpdate);
|
|
pbSalary.Invoke(d, new object[] { pstatus });
|
|
}
|
|
else
|
|
{
|
|
if (pstatus == EnumProcessStatus.Start)
|
|
{
|
|
pbSalary.Value = 0;
|
|
pbSalary.ResetText();
|
|
pbSalary.Maximum = 8000;
|
|
pbSalary.Minimum = 0;
|
|
pbSalary.Step = 1;
|
|
}
|
|
else if (pstatus == EnumProcessStatus.PerformStep)
|
|
{
|
|
pbSalary.PerformStep();
|
|
}
|
|
pbSalary.Refresh();
|
|
}
|
|
}
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnProcess_Click(object sender, EventArgs e)
|
|
{
|
|
if (cboLeaveYear.SelectedIndex == -1)
|
|
{
|
|
MessageBox.Show("Select a Leave Year.", "Leave Year", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
cboLeaveYear.Focus();
|
|
return;
|
|
}
|
|
|
|
LeaveYear oLeaveYear = _oLeaveYears[cboLeaveYear.SelectedIndex];
|
|
_leaveYear = oLeaveYear;
|
|
if (oLeaveYear.IsEnded == true)
|
|
{
|
|
MessageBox.Show("Selected leave year already processed and year end completed", "Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
|
|
LeaveYear oPreYear = LeaveYear.LastLeaveYear(oLeaveYear);
|
|
if (oPreYear != null)
|
|
{
|
|
if (!oPreYear.IsEnded)
|
|
{
|
|
MessageBox.Show("Leave year end of " + oPreYear.StartDate + "-" + oPreYear.EndDate + " is not done yet." + Environment.NewLine
|
|
+ "You cannot do leave process of " + oLeaveYear.StartDate + "-" + oLeaveYear.EndDate, "Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
//return;
|
|
}
|
|
}
|
|
|
|
_oLeaveProcess = LeaveProcess.GetByYearID(oLeaveYear.ID.Integer);
|
|
if (_oLeaveProcess != null)
|
|
{
|
|
if (MessageBox.Show("Selected leave year already processed, Do you want to do process again?", "Leave Process", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
_oLeaveProcess = new LeaveProcess();
|
|
_oLeaveProcess.ProcessDate = DateTime.Now.Date;
|
|
_oLeaveProcess.LeaveYearID = oLeaveYear.ID.Integer;
|
|
_oLeaveProcess.ProcessYearDescription = oLeaveYear.Name;
|
|
|
|
string msg = string.Empty;
|
|
try
|
|
{
|
|
if (_processStatus == EnumProcessStatus.Start)
|
|
{
|
|
btnSave.Enabled = false;
|
|
btnUndo.Enabled = false;
|
|
btnProcess.Text = "&Stop";
|
|
//MessageBox.Show("Start Process");
|
|
_salaryProcess = new Thread(new ThreadStart(Process));
|
|
_salaryProcess.Start();
|
|
_processStatus = EnumProcessStatus.PerformStep;
|
|
}
|
|
else
|
|
{
|
|
_processStatus = EnumProcessStatus.End;
|
|
btnProcess.Text = "&Process";
|
|
btnProcess.Enabled = false;
|
|
}
|
|
}
|
|
catch (ThreadAbortException ex)
|
|
{
|
|
_processStatus = EnumProcessStatus.Start;
|
|
MessageBox.Show("Salary Process forcely stoped. reason:" + ex.Message, "Salary Process forcely stoped.", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_processStatus = EnumProcessStatus.Start;
|
|
MessageBox.Show(ex.Message, "Failed to start Process", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
//this.Cursor = Cursors.WaitCursor;
|
|
//try
|
|
//{
|
|
// _oLeaveProcess.Process(oLeaveYear,pbSalary);
|
|
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// this.Cursor = Cursors.Default;
|
|
// // pgrsbarProcessTotal.Visible = false;
|
|
// if (ex.InnerException == null)
|
|
// MessageBox.Show(ex.Message, "Failed to process", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
// else
|
|
// MessageBox.Show(ex.InnerException.Message, "Failed to process", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
// return;
|
|
//}
|
|
|
|
//this.Cursor = Cursors.Default;
|
|
//MessageBox.Show("Leave Process is done", "Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
//btnProcess.Enabled = false;
|
|
//btnUndo.Enabled = !btnProcess.Enabled;
|
|
//RefreshLeave();
|
|
|
|
}
|
|
private void Process()
|
|
{
|
|
//LeaveYear oLeaveYear = _oLeaveYears[cboLeaveYear.SelectedIndex];
|
|
try
|
|
{
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
_processStatus = EnumProcessStatus.PerformStep;
|
|
|
|
//_oLeaveProcess = new LeaveProcess();
|
|
_oLeaveProcess.ProcessStatus += new Payroll.BO.ProcessStatus(this.UpdateStatus);
|
|
_oLeaveProcess.ProgressStatus += new Payroll.BO.ProgressStatus(this.ProgressBarUpdate);
|
|
_oLeaveProcess.Process(_leaveYear);
|
|
//if (_oLeaveProcess.ErrorList.Count > 0)
|
|
//{
|
|
// fPayslip errorlist = new fPayslip();
|
|
// errorlist.ShowDlg(_oLeaveProcess.ErrorList);
|
|
// return;
|
|
//}
|
|
_processStatus = EnumProcessStatus.End;
|
|
UpdtSaveBtnEnable(true);
|
|
// UpdtPrcBtnEnable(false);
|
|
Cursor.Current = Cursors.Default;
|
|
MessageBox.Show("Leave process completed successfully.", "Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
//MessageBox.Show("End Process");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
_processStatus = EnumProcessStatus.Start;
|
|
UpdtPrcBtnEnable(true);
|
|
UpdtCancelBtnEnable(true);
|
|
//UpdtSearchBtnEnable(true);
|
|
Cursor.Current = Cursors.Default;
|
|
}
|
|
|
|
}
|
|
private void UpdtPrcBtnEnable(bool IsEnable)
|
|
{
|
|
if (lblProcessdes.InvokeRequired)
|
|
{
|
|
UpdateButtonEnableStatus d = new UpdateButtonEnableStatus(UpdtPrcBtnEnable);
|
|
btnProcess.Invoke(d, new object[] { IsEnable });
|
|
}
|
|
else
|
|
{
|
|
btnProcess.Enabled = IsEnable;
|
|
btnProcess.Refresh();
|
|
}
|
|
}
|
|
private void UpdtCancelBtnEnable(bool IsEnable)
|
|
{
|
|
if (lblProcessdes.InvokeRequired)
|
|
{
|
|
UpdateButtonEnableStatus d = new UpdateButtonEnableStatus(UpdtCancelBtnEnable);
|
|
btnCancel.Invoke(d, new object[] { IsEnable });
|
|
}
|
|
else
|
|
{
|
|
btnCancel.Enabled = IsEnable;
|
|
btnCancel.Refresh();
|
|
}
|
|
}
|
|
private void UpdtSaveBtnEnable(bool IsEnable)
|
|
{
|
|
if (lblProcessdes.InvokeRequired)
|
|
{
|
|
UpdateButtonEnableStatus d = new UpdateButtonEnableStatus(UpdtSaveBtnEnable);
|
|
btnSave.Invoke(d, new object[] { IsEnable });
|
|
}
|
|
else
|
|
{
|
|
btnSave.Enabled = IsEnable;
|
|
btnSave.Refresh();
|
|
}
|
|
}
|
|
|
|
|
|
private void fLeaveProcess_Load(object sender, EventArgs e)
|
|
{
|
|
_leaveYear = new LeaveYear();
|
|
_leaveYear = LeaveYear.GetCurrentYear();
|
|
|
|
RefreshLeave();
|
|
}
|
|
private void RefreshLeave()
|
|
{
|
|
_oLeaveYears = LeaveYear.Get();
|
|
cboLeaveYear.Items.Clear();
|
|
foreach (LeaveYear leaveYear in _oLeaveYears)
|
|
cboLeaveYear.Items.Add(leaveYear.Name.ToString());
|
|
if (_oLeaveYears.Count > 0)
|
|
cboLeaveYear.SelectedIndex = 0;
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
LeaveYear oLeaveYear = _oLeaveYears[cboLeaveYear.SelectedIndex];
|
|
|
|
if (oLeaveYear.IsEnded == true)
|
|
{
|
|
MessageBox.Show("Selected leave year already processed and year end completed", "Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
_oLeaveProcess.PayrollTypeID = Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer;
|
|
_oLeaveProcess.Save();
|
|
MessageBox.Show("Leave information saved successfully", "Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
btnUndo.Enabled = true;
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
MessageBox.Show(exp.Message);
|
|
}
|
|
}
|
|
|
|
private void btnUndo_Click(object sender, EventArgs e)
|
|
{
|
|
this.Cursor = Cursors.WaitCursor;
|
|
if (cboLeaveYear.SelectedIndex==-1)
|
|
{
|
|
this.Cursor = Cursors.Default;
|
|
MessageBox.Show("Please select a year");
|
|
return;
|
|
}
|
|
LeaveProcess oProcess = LeaveProcess.GetByYearID(_oLeaveYears[cboLeaveYear.SelectedIndex].ID.Integer);
|
|
if (oProcess == null)
|
|
{
|
|
this.Cursor = Cursors.Default;
|
|
return;
|
|
}
|
|
|
|
if (oProcess.IsYearEnd)
|
|
{
|
|
this.Cursor = Cursors.Default;
|
|
MessageBox.Show("Year End Process is done for this year.", "Undo Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
if (MessageBox.Show("Do you want to Undo Leave Process?", "Undo Leave Process", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
|
|
{
|
|
oProcess.Delete();
|
|
oProcess.UpadteLeaveYearStatus();
|
|
btnUndo.Enabled = false;
|
|
btnProcess.Enabled = !btnUndo.Enabled;
|
|
this.Cursor = Cursors.Default;
|
|
MessageBox.Show("Undo Leave Process is done successfully.", "Undo Leave Process", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
this.Cursor = Cursors.Default;
|
|
}
|
|
}
|
|
}
|