Linked Questions

Popular Questions

Is there any way to find Rows that don't have a match? or Null?

Asked by At

I am currently creating an Attendance application but I am having a hard time matching a schedule where there is no logs to mark it as absent.

As of the moment this is how my table looks like

Current Table Current Table

As of the moment, the table will only show which schedule has attendance logs on it. So I can't see if there is a schedule which the employee hasn't shown up which s/he is absent.

I have tried matching it with null, but it ends up not showing anything.

This is my code to populate the table

public void Main()
        {
            // works but not the midnight cross stuff
            var final = (from a1 in EmployeeAttendanceLogs
                         join a2 in EmployeeAttendanceLogs on a1.ID equals a2.ID
                         join t1 in EmployeeScheduleList on a1.ID equals t1.ID
                         join t2 in EmployeeScheduleList on a2.ID equals t2.ID
                         join d1 in EmployeeDetails on t1.ID equals d1.EmployeeID
                         where ((a1.LogStatus == 0 && t1.In == t2.In) && (((((a1.ActualLog - t1.In ).Ticks) > TimeSpan.FromHours(1).Ticks) || t1.In.Date == a1.ActualLog.Date) && t1.In.Date == a1.ActualLog.Date )) && (a2.LogStatus == 1 && t1.Out == t2.Out && (t2.Out.Date == a2.ActualLog.Date) )
                         select new
                         {
                             User_ID = t1.ID,
                             Name = d1.EmployeeName,
                             Scheduled_In = t1.In,
                             Actual_Login = a1.ActualLog,
                             Scheduled_Out = t2.Out,
                             Actual_Out = a2.ActualLog
                         }).Distinct(). ToList();

            tbContainer = StaticClasses.ToDataTable(final);

            dgvAttendance.ItemsSource = emp.CalculateEmployeeAttendance(tbContainer);
        }

And these are my sources of data

Employee Schedule File

Employee Schedule

Employee Attendance Logs File

Attendance Logs

As based from the logs Employee 5 has no record and this is the output to the grid

Output

So it doesn't show, but I have also tried to set my class to have a logic

Employee Schedule Class

public class EmployeeSchedule
{
    public int ID { get; set; }
    private string _name;
    public string Name
    { get
        {
            if (_name == null)
            {
                _name = "";
            }
            return _name;
        }
        set { _name = value; }
    }

    public string scheduleeIn { get; set; }

    private string _actualIn;
    public string actualIn
    {
        get
        {
            if (_actualIn == null) 
            {
                _actualIn = "Absent";
            }
            return _actualIn;
        }
        set { _actualIn = value; }

    }

    public string scheduleOut { get; set; }

    public string _actualOut;
    public string actualOut
    {
        get
        {
            if (_actualOut == null)
            {
                _actualOut = "Absent";
            }
            return _actualOut;
        }
        set { _actualOut = value; }

    }

    private string _tardiness;
    public string tardiness
    {
        get
        {
            if (_tardiness == null) 
            {
                _tardiness = "Absent";
            }
            return _tardiness;
        }
        set { _tardiness = value; }
    }

    private string _workHours;
    public string workHours
    {
        get
        {
            if (_workHours == null) 
            {
                _workHours = "Absent";
            }
            return _workHours;
        }
        set { _workHours = value; }
    }    
}

It's been a day already I have tried figuring it out but it doesn't seem to show up or to mark the schedule as absent.

Any ideas or suggestion would be of great help. Thanks

Edit : Sources of Data

Here is the source of data for my Attendance Logs

Attendance Logs

public class Actual
    {
        public int ID { get; set; }
        public DateTime ActualLog { get; set; }
        public int LogStatus { get; set; }
        public DateTime date { get; set; }
    }

Employee Schedule

public class Emp1
{
    public int ID { get; set; }
    public DateTime In { get; set; }
    public DateTime Out { get; set; }
}

Related Questions