private void Btn_absenceList_Click(object sender, EventArgs e)
        {
            System.Windows.Input.Cursor oldCursor = Mouse.OverrideCursor;
            try
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                //pic_loader.Visible = true;
                //pic_loader.Image = global::WindowsFormsApplication1.Properties.Resources.loader;


                System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog();
                string pathsave = "";
                saveFileDialog.Title      = "Browse Excel Files";
                saveFileDialog.DefaultExt = "Excel";
                saveFileDialog.Filter     = "Excel files (*.xlsx)|*.xlsx";

                saveFileDialog.CheckPathExists = true;

                if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    GetdataInout getdataInout = new GetdataInout();

                    List <EmployeeAbsence> employeeAbsences = new List <EmployeeAbsence>();
                    int IDSession = GetSessionID.GetsessionID(dtpk_choose.Value);
                    List <EmployeeAbsence> employeeAbsencesDay          = getdataInout.GetEmployeeAbsencesDayShift(dtpk_choose.Value, IDSession);
                    List <EmployeeAbsence> employeeAbsencesDayNotPaiPan = getdataInout.GetEmployeeAbsencesDayShiftNotPaipan(dtpk_choose.Value, IDSession);
                    List <EmployeeAbsence> employeeAbsencesNightShift   = getdataInout.GetEmployeeAbsencesNightShift(dtpk_choose.Value, IDSession);

                    employeeAbsences.AddRange(employeeAbsencesDay);
                    employeeAbsences.AddRange(employeeAbsencesDayNotPaiPan);
                    employeeAbsences.AddRange(employeeAbsencesNightShift);

                    HRReport hRReport = new HRReport();
                    pathsave = saveFileDialog.FileName;

                    saveFileDialog.RestoreDirectory = true;
                    hRReport.ExportExcelAbsenceReport(pathsave, employeeAbsences, dtpk_choose.Value);
                    var resultMessage = MessageBox.Show("Absence Daily Report export to excel sucessful ! \n\r Do you want to open this file ?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (resultMessage == DialogResult.Yes)
                    {
                        FileInfo fi = new FileInfo(pathsave);
                        if (fi.Exists)
                        {
                            System.Diagnostics.Process.Start(pathsave);
                        }
                        else
                        {
                            MessageBox.Show("File doestn't exist !", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }

                //    WindowAbsenceList windowAbsenceList = new WindowAbsenceList(employeeAbsences);
                //windowAbsenceList.Show();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Mouse.OverrideCursor = oldCursor;
            }
        }
        public List <AttendanceDept> GetAttendanceDeptsNew(DateTime date)
        {
            List <AttendanceDept> attendanceDepts = new List <AttendanceDept>();

            try
            {
                DataTable dtGetUpCode = new DataTable();
                dtGetUpCode = GetUpCodeDept();
                GetdataInout getdataInout = new GetdataInout();
                int          IDSession    = GetSessionID.GetsessionID(date);

                List <EmployeeAbsence>    employeeAbsencesDay              = getdataInout.GetEmployeeAbsencesDayShift(date, IDSession);
                List <EmployeeAbsence>    employeeAbsencesDayNotPaiPan     = getdataInout.GetEmployeeAbsencesDayShiftNotPaipan(date, IDSession);
                List <EmployeeAbsence>    employeeAbsencesNightShift       = getdataInout.GetEmployeeAbsencesNightShift(date, IDSession);
                List <EmployeeAttendance> employeeAttendancesDay           = getdataInout.GetEmployeeAttendancesDayShift(date, IDSession);
                List <EmployeeAttendance> employeeAttendancesDayNotPaiPan  = getdataInout.GetEmployeeAttandanceDayShiftNotPaipan(date, IDSession);
                List <EmployeeAttendance> employeeAttendancesNight         = getdataInout.GetEmployeeAttendancesNightShift(date, IDSession);
                List <EmployeeAttendance> employeeAttendancesSeasonal      = getdataInout.GetEmployeeAttendancesSeasonal(date);
                List <EmployeeAttendance> employeeAttendancesSeasonalNight = getdataInout.GetEmployeeAttendancesSeasonalNight(date);
                for (int i = 0; i < dtGetUpCode.Rows.Count; i++)
                {
                    AttendanceDept attendance = new AttendanceDept();
                    attendance.BigDeptCode = dtGetUpCode.Rows[i]["Code"].ToString();
                    attendance.BigDeptName = dtGetUpCode.Rows[i]["Name"].ToString();
                    DataTable dtDeptDetail = new DataTable();
                    dtDeptDetail = GetCountEmployeeByUpcode(attendance.BigDeptCode);

                    for (int j = 0; j < dtDeptDetail.Rows.Count; j++)
                    {
                        AttendanceDept attendance1 = new AttendanceDept();
                        attendance1.BigDeptCode    = attendance.BigDeptCode;
                        attendance1.BigDeptName    = attendance.BigDeptName;
                        attendance1.DetailDeptCode = dtDeptDetail.Rows[j]["Dept"].ToString();
                        attendance1.HeadDept       = dtDeptDetail.Rows[j]["Manager"].ToString();
                        if (dtDeptDetail.Rows[j]["Note"].ToString() != "")
                        {
                            attendance1.DetailDeptName = dtDeptDetail.Rows[j]["LongName"].ToString() + " / " + dtDeptDetail.Rows[j]["Note"].ToString();
                        }
                        else
                        {
                            attendance1.DetailDeptName = dtDeptDetail.Rows[j]["LongName"].ToString();
                        }
                        attendance1.EmployeeOfDept = int.Parse(dtDeptDetail.Rows[j]["countEmployee"].ToString());

                        DataTable dtShift          = GetDataTableCountShiftbyDeptShift(attendance1.DetailDeptCode, date.Day);
                        DataTable dtGetShiftWorker = GetDataTableCountShiftbyDept(attendance1.DetailDeptCode, date.Day);
                        attendance1.DayShift          = new WorkingState();
                        attendance1.NightShift        = new WorkingState();
                        attendance1.LocalWorker       = new WorkerType();
                        attendance1.SeasonWorkerDay   = new WorkingState();
                        attendance1.SeasonWorkerNight = new WorkingState();


                        if (dtGetShiftWorker.Rows.Count == 1)
                        {
                            attendance1.LocalWorker.WorkerIndirect = int.Parse(dtGetShiftWorker.Rows[0]["CountInDirect"].ToString());
                            attendance1.LocalWorker.WorkerDirect   = attendance1.EmployeeOfDept - attendance1.LocalWorker.WorkerIndirect;
                        }

                        attendance1.LocalWorker.TotalWorker = attendance1.LocalWorker.WorkerIndirect + attendance1.LocalWorker.WorkerDirect;
                        for (int k = 0; k < dtShift.Rows.Count; k++)
                        {
                            if (dtShift.Rows[k]["Outtime"].ToString().Contains("T"))

                            {
                                attendance1.NightShift.attendance += int.Parse(dtShift.Rows[k]["EmpQty"].ToString());
                            }

                            else

                            {
                                attendance1.DayShift.attendance += int.Parse(dtShift.Rows[k]["EmpQty"].ToString());
                            }
                        }
                        int AttendanceDeptDay          = employeeAttendancesDay.Where(d => d.DeptCode == attendance1.DetailDeptCode).Count();
                        int AttendanceDeptDayNotPaipan = employeeAttendancesDayNotPaiPan.Where(d => d.DeptCode == attendance1.DetailDeptCode).Count();
                        int AbsenceDay          = employeeAbsencesDay.Where(d => d.DeptCode == attendance1.DetailDeptCode).Count();
                        int AbsenceDayNotPaiPan = employeeAbsencesDayNotPaiPan.Where(d => d.DeptCode == attendance1.DetailDeptCode).Count();
                        int AttendanceNight     = employeeAttendancesNight.Where(d => d.DeptCode == attendance1.DetailDeptCode).Count();
                        int AbsenceNight        = employeeAbsencesNightShift.Where(d => d.DeptCode == attendance1.DetailDeptCode).Count();
                        int attendanceSeasonal  = employeeAttendancesSeasonal.Count();
                        int atttenSeasonalNight = employeeAttendancesSeasonalNight.Count();
                        attendance1.NightShift.attendanceActual = AttendanceNight;
                        attendance1.DayShift.attendanceActual   = AttendanceDeptDay + AttendanceDeptDayNotPaipan;
                        attendance1.NightShift.absence          = AbsenceNight;
                        attendance1.DayShift.absence            = AbsenceDay + AbsenceDayNotPaiPan;
                        attendance1.SeannWorkerDayNotID         = attendanceSeasonal - atttenSeasonalNight;
                        attendance1.SeannWorkerNightNotID       = atttenSeasonalNight;

                        attendanceDepts.Add(attendance1);
                    }
                }
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetAttendanceDeptsNew(DateTime date)", ex.Message);
            }
            return(attendanceDepts);
        }