protected void btn_report_Click(object sender, EventArgs e)
 {
     btnExport.Visible = true;
     ManageReports objManageReports = new ManageReports();
     TimeSpan relaxationTime = new TimeSpan();
     relaxationTime = TimeSpan.Parse(ddlRelaxation.SelectedValue.ToString());
     int EmployeeId = 0;
     Int32.TryParse(txtEmployeeId.Text, out EmployeeId);
     MonthlyReportOfEmployee objMonthlyReportOfEmployee = new MonthlyReportOfEmployee();
     var data = objManageReports.GetDataForMonthlyAttendanceReportByEmployeeId(EmployeeId, Calendar1.SelectedDate.Date, Calendar2.SelectedDate.Date, relaxationTime, out objMonthlyReportOfEmployee);
     grid_monthly_attendanceDetailed.DataSource = data;
     grid_monthly_attendanceDetailed.DataBind();
     if (data.Count != 0)
     {
         lblName.Text = "Name : " + data[0].Name;
     }
     else
     {
         lblName.Text = "No Data";
     }
     lblTotalDuration.Text = "TotalDuration : " + objMonthlyReportOfEmployee.TotalDuration.ToString();
     lblPresentDays.Text = "PresentDays : " + objMonthlyReportOfEmployee.PresentDays.ToString();
     lblLeaves.Text = "Leaves : " + objMonthlyReportOfEmployee.Leaves.ToString();
     lblHolidays.Text = "Holidays : " + objMonthlyReportOfEmployee.Holidays.ToString();
     lblAbsentDays.Text = objMonthlyReportOfEmployee.AbsentDays.ToString();
     lblAbsentDays.Text = "AbsentDays : " + objMonthlyReportOfEmployee.AbsentDays.ToString();
     lblWeeklyOff.Text = "WeeklyOff : " + objMonthlyReportOfEmployee.WeeklyOff.ToString();
 }
 protected void btn_report_Click(object sender, EventArgs e)
 {
     btnExport.Visible = true;
     ManageReports objManageReports = new ManageReports();
     TimeSpan relaxationTime = new TimeSpan();
     relaxationTime = TimeSpan.Parse(ddlRelaxation.SelectedValue.ToString());
     int EmployeeId = 0;
     //Int32.TryParse(txtEmployeeId.Text, out EmployeeId);
     ManageEmployees objEmployee = new ManageEmployees();
     lstEmployees = objEmployee.GetAllEmployees();
     EmployeeId = lstEmployees.Where(y => y.Name == txtEmployeeId.Text).Select(x => x.Id).FirstOrDefault();
     DateTime StartDate = DateTime.Parse(txtStartDate.Text);
     DateTime EndDate = DateTime.Parse(txtEndDate.Text);
     MonthlyReportOfEmployee objMonthlyReportOfEmployee = new MonthlyReportOfEmployee();
     var data = objManageReports.GetMonthlyAttendanceDetailedReport(EmployeeId, StartDate,EndDate, relaxationTime, out objMonthlyReportOfEmployee);
     grid_monthly_attendanceBasic.DataSource = data;
     grid_monthly_attendanceBasic.DataBind();
     if (data.Count != 0)
     {
         lblName.Text = "Name : " + data[0].Name;
         lblDepartment.Text = "Department : " + data[0].DepartmentName;
     }
     else
     {
         lblName.Text = "No Data";
     }
     lblTotalDuration.Text = "TotalDuration : " + objMonthlyReportOfEmployee.TotalDuration.ToString();
     lblPresentDays.Text = "PresentDays : " + objMonthlyReportOfEmployee.PresentDays.ToString();
     lblLeaves.Text = "Leaves : " + objMonthlyReportOfEmployee.Leaves.ToString();
     lblHolidays.Text = "Holidays : " + objMonthlyReportOfEmployee.Holidays.ToString();
     lblAbsentDays.Text = objMonthlyReportOfEmployee.AbsentDays.ToString();
     lblAbsentDays.Text = "AbsentDays : " + objMonthlyReportOfEmployee.AbsentDays.ToString();
     lblWeeklyOff.Text = "WeeklyOff : " + objMonthlyReportOfEmployee.WeeklyOff.ToString();
 }
    protected void btn_report_Click(object sender, EventArgs e)
    {
        btnExport.Visible = true;
        ManageReports objManageReports = new ManageReports();
        TimeSpan      relaxationTime   = new TimeSpan();

        relaxationTime = TimeSpan.Parse(ddlRelaxation.SelectedValue.ToString());
        int             EmployeeId  = 0;
        ManageEmployees objEmployee = new ManageEmployees();

        lstEmployees = objEmployee.GetAllEmployees();
        EmployeeId   = lstEmployees.Where(y => y.Name == txtEmployeeId.Text).Select(x => x.Id).FirstOrDefault();

        DateTime StartDate = DateTime.Parse(txtStartDate.Text);
        DateTime EndDate   = DateTime.Parse(txtEndDate.Text);

        MonthlyReportOfEmployee objMonthlyReportOfEmployee = new MonthlyReportOfEmployee();
        var data = objManageReports.GetMonthlyAttendanceDetailedReport(EmployeeId, StartDate, EndDate, relaxationTime, out objMonthlyReportOfEmployee);

        grid_monthly_attendanceDetailed.DataSource = data;
        grid_monthly_attendanceDetailed.DataBind();
        if (data.Count != 0)
        {
            lblName.Text = "Name : " + data[0].Name;
        }
        else
        {
            lblName.Text = "No Data";
        }
        lblTotalDuration.Text = "TotalDuration : " + objMonthlyReportOfEmployee.TotalDuration.ToString();
        lblPresentDays.Text   = "PresentDays : " + objMonthlyReportOfEmployee.PresentDays.ToString();
        lblLeaves.Text        = "Leaves : " + objMonthlyReportOfEmployee.Leaves.ToString();
        lblHolidays.Text      = "Holidays : " + objMonthlyReportOfEmployee.Holidays.ToString();
        lblAbsentDays.Text    = objMonthlyReportOfEmployee.AbsentDays.ToString();
        lblAbsentDays.Text    = "AbsentDays : " + objMonthlyReportOfEmployee.AbsentDays.ToString();
        lblWeeklyOff.Text     = "WeeklyOff : " + objMonthlyReportOfEmployee.WeeklyOff.ToString();
    }
    public List<DailyAttendanceReportViewModel> GetDataForMonthlyAttendanceReportByEmployeeId(int EmployeeId, DateTime StartDate, DateTime EndDate, TimeSpan relaxation, out MonthlyReportOfEmployee objMonthlyReportOfEmployee)
    {
        List<DailyAttendanceReportViewModel> lstDailyAttendanceReportViewModel = new List<DailyAttendanceReportViewModel>();
        for (DateTime date = StartDate.Date; date.Date <= EndDate.Date; date = date.AddDays(1))
        {
            List<DailyAttendanceReportViewModel> varLst = GetDataForDailyAttendanceByEmployeeId(EmployeeId, date, relaxation);

            lstDailyAttendanceReportViewModel = lstDailyAttendanceReportViewModel.Concat(varLst).ToList();
        }
        objMonthlyReportOfEmployee = new MonthlyReportOfEmployee();
        foreach (DailyAttendanceReportViewModel item in lstDailyAttendanceReportViewModel)
        {
            objMonthlyReportOfEmployee.TotalDuration += item.Duration;
            DayStatus daystatus = GetStatusOfDay(item.Date, EmployeeId);
            if (daystatus == DayStatus.Active)
            {
                if (item.Status == Status.Present || item.Status == Status.PresentWithNoOutPunch)
                {
                    objMonthlyReportOfEmployee.PresentDays++;
                }
                else
                {
                    objMonthlyReportOfEmployee.AbsentDays++;
                }
            }
            else if (daystatus == DayStatus.WeeklyOff)
            {
                if (item.Status == Status.Present)
                {
                    item.Status = Status.WeeklyOffPresent;
                    objMonthlyReportOfEmployee.PresentDays++;
                }
                else if (item.Status == Status.PresentWithNoOutPunch)
                {
                    item.Status = Status.WeeklyOffPresentWithNoOutPunch;
                    objMonthlyReportOfEmployee.PresentDays++;
                }
                else
                {
                    item.Status = Status.WeeklyOff;
                }
            }
            else //Holiday
            {
                objMonthlyReportOfEmployee.Holidays++;
                item.Status = Status.Holiday;
            }
        }
        return lstDailyAttendanceReportViewModel;
    }
    public List<DailyAttendanceReportViewModel> GetMonthlyAttendanceDetailedReport(int employeeId, DateTime startDate, DateTime endDate, TimeSpan relaxation, out MonthlyReportOfEmployee objMonthlyReportOfEmployee)// aspx file mai check kar lena ki startDate < endDate
    {
        List<DailyAttendanceReportViewModel> lstMonthlyAttendanceReportViewModel = new List<DailyAttendanceReportViewModel>();
        objMonthlyReportOfEmployee = new MonthlyReportOfEmployee();
        for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
        {
            DailyAttendanceReportViewModel objMonthlyAttendanceReportViewModel = new DailyAttendanceReportViewModel();
            objMonthlyAttendanceReportViewModel = GetDataForReportEmployeeWise(employeeId, date, relaxation);
            objMonthlyAttendanceReportViewModel.Date = date;
            lstMonthlyAttendanceReportViewModel.Add(objMonthlyAttendanceReportViewModel);
        }

        foreach (var item in lstMonthlyAttendanceReportViewModel)
        {
            objMonthlyReportOfEmployee.TotalDuration += item.Duration;
            DayStatus daystatus = GetStatusOfDay(item.Date, employeeId);
            if (daystatus == DayStatus.Active)
            {
                if (item.Status == Status.Present || item.Status == Status.PresentWithNoOutPunch)
                {
                    objMonthlyReportOfEmployee.PresentDays++;
                }
                else
                {
                    objMonthlyReportOfEmployee.AbsentDays++;
                }
            }
            else if (daystatus == DayStatus.WeeklyOff)
            {
                if (item.Status == Status.Present)
                {
                    item.Status = Status.WeeklyOffPresent;
                    objMonthlyReportOfEmployee.PresentDays++;
                }
                else if (item.Status == Status.PresentWithNoOutPunch)
                {
                    item.Status = Status.WeeklyOffPresentWithNoOutPunch;
                    objMonthlyReportOfEmployee.PresentDays++;
                }
                else
                {
                    item.Status = Status.WeeklyOff;
                    objMonthlyReportOfEmployee.WeeklyOff++;
                }
            }
            else //Holiday
            {
                objMonthlyReportOfEmployee.Holidays++;
                item.Status = Status.Holiday;
            }
        }
        return lstMonthlyAttendanceReportViewModel;
    }