154 lines
4.7 KiB
C#
154 lines
4.7 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;
|
|
|
|
namespace Payroll.UI
|
|
{
|
|
public partial class fDailyAttnProcess : BaseFormTest
|
|
{
|
|
#region Declaration
|
|
SearchEmployee _srcEmp = null;
|
|
MonthlyWorkPlan _monthlyWorkPlan = null;
|
|
ObjectsTemplate<Shift> _shifts = null;
|
|
DailyAttnProcess _dattnProcess = null;
|
|
#endregion
|
|
|
|
#region Constructor & frm_Load
|
|
public fDailyAttnProcess()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void fDailyAttnProcess_Load(object sender, EventArgs e)
|
|
{
|
|
RefreshShift();
|
|
}
|
|
#endregion
|
|
|
|
#region Methods
|
|
private bool ValidateInput()
|
|
{
|
|
bool Valid = true;
|
|
if (ctlEmployee.SelectedEmployee == null)
|
|
{
|
|
MessageBox.Show("Please select an Employee", "Select Employee", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
Valid = false;
|
|
return Valid;
|
|
}
|
|
return Valid;
|
|
|
|
}
|
|
|
|
private void RefreshObject()
|
|
{
|
|
_dattnProcess = new DailyAttnProcess();
|
|
|
|
_dattnProcess.EmployeeID = ctlEmployee.SelectedEmployee.EmployeeID;
|
|
_dattnProcess.ShiftID = _shifts[cboShift.SelectedIndex].ID;
|
|
_dattnProcess.InTime = dtpShiftInTime.Value;
|
|
_dattnProcess.OutTime = dtpShiftOutTime.Value;
|
|
_dattnProcess.AttnDate = dtpAttnDate.Value;
|
|
_dattnProcess.Comments = txtComments.Text;
|
|
_dattnProcess.AttenType = GetAttnType();
|
|
_dattnProcess.IsManualEntry = true;
|
|
_dattnProcess.ReferenceID = ID.FromInteger(0);
|
|
|
|
}
|
|
|
|
private void RefreshValue()
|
|
{
|
|
ctlEmployee.Clear();
|
|
dtpAttnDate.Value = DateTime.Now;
|
|
txtComments.Text = "";
|
|
dtpShiftInTime.Value = _shifts[cboShift.SelectedIndex].InTime;
|
|
dtpShiftOutTime.Value = _shifts[cboShift.SelectedIndex].OutTime;
|
|
}
|
|
|
|
private EnumAttendanceType GetAttnType()
|
|
{
|
|
TimeSpan empInTime = dtpShiftInTime.Value.TimeOfDay;
|
|
TimeSpan shiftInTime = _monthlyWorkPlan.Shift.InTime.TimeOfDay;
|
|
TimeSpan ShiftInTimeLate = shiftInTime + TimeSpan.FromMinutes(_monthlyWorkPlan.Shift.LateCalcualtion);
|
|
|
|
if (empInTime > shiftInTime && empInTime < ShiftInTimeLate)
|
|
{
|
|
return EnumAttendanceType.Delay;
|
|
}
|
|
if (empInTime > ShiftInTimeLate)
|
|
{
|
|
return EnumAttendanceType.Late;
|
|
}
|
|
else
|
|
{
|
|
return EnumAttendanceType.Present;
|
|
}
|
|
//return EnumAttendanceType.Present;
|
|
}
|
|
|
|
private void RefreshShift()
|
|
{
|
|
cboShift.Items.Clear();
|
|
|
|
_shifts = Shift.Get();
|
|
foreach (Shift shift in _shifts)
|
|
{
|
|
cboShift.Items.Add(shift.ShortName);
|
|
cboShift.Tag = shift;
|
|
}
|
|
cboShift.SelectedIndex = 0;
|
|
}
|
|
#endregion
|
|
|
|
#region Btn_Event
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (!ValidateInput())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (MessageBox.Show("Do you want to Save The Data?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
RefreshObject();
|
|
_dattnProcess.Save();
|
|
MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
RefreshValue();
|
|
}
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
if (ex.InnerException == null)
|
|
MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
else
|
|
MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
|
|
#region Miscellaneous
|
|
private void cboShift_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
dtpShiftInTime.Value = _shifts[cboShift.SelectedIndex].InTime;
|
|
dtpShiftOutTime.Value = _shifts[cboShift.SelectedIndex].OutTime;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|