Link to home
Start Free TrialLog in
Avatar of NerishaB
NerishaBFlag for South Africa

asked on

C# : Display result from array in a gridview

Hi,

I have created a query to a SQL database, and put the results of my table in an array.  Now, I want to perform calculations based on the data in the array, and display the results in a gridview, so that I may see what the result looks like  Can anyone help me do this?

My code is below:
string[,] HrsWorkedTable = new string[qry.TotalRows, 24];
for (qryRows = 0; qryRows < qry.TotalRows; qryRows++)
  {
      double HoursWorkedDuringBreak = 0.00;
      DateTime ClockInOutTime = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 8).FieldValue));
      DateTime DefShiftStartTime = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 4).FieldValue));
      DateTime DefShiftEndTime = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 5).FieldValue));
      DateTime BreakStart = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 21).FieldValue));
      DateTime BreakEnd = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 22).FieldValue));

if ((ClockInOutTime.TimeOfDay < DefShiftStartTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
       {
         DateTime ClockIn = ClockInOutTime;
         TimeSpan ResultBeforeShift = DefShiftStartTime.TimeOfDay - ClockInOutTime.TimeOfDay;
         double WorkHoursBeforeShift = ResultBeforeShift.TotalSeconds / 60.0;
        }
        else if ((ClockInOutTime.TimeOfDay > DefShiftStartTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
        {
                    DateTime ClockIn = ClockInOutTime;
                    TimeSpan ResultLateStart = ClockInOutTime.TimeOfDay - DefShiftStartTime.TimeOfDay;
                    double HoursWorkedLateStart = ResultLateStart.TotalSeconds / 60.0;
                }

                if ((ClockInOutTime.TimeOfDay < BreakStart.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutBreak = ClockInOutTime;
                    TimeSpan ResultEarlyBreak = BreakStart.TimeOfDay - ClockInOutTime.TimeOfDay;
                    double HoursEarlyBreak = ResultEarlyBreak.TotalSeconds / 60.0;
                }
                else if ((ClockInOutTime.TimeOfDay > BreakStart.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutBreak = ClockInOutTime;
                    TimeSpan ResultWorkBreak = ClockInOutTime.TimeOfDay - BreakStart.TimeOfDay;
                    HoursWorkedDuringBreak = ResultWorkBreak.TotalSeconds / 60.0;
                }

                if ((ClockInOutTime.TimeOfDay < BreakEnd.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
                {
                    DateTime ClockInEarlyBreak = ClockInOutTime;
                    TimeSpan ResultEndBreakEarly = BreakEnd.TimeOfDay - ClockInOutTime.TimeOfDay;
                    HoursWorkedDuringBreak += (ResultEndBreakEarly.TotalSeconds / 60.0);
                }
                else if ((ClockInOutTime.TimeOfDay > BreakEnd.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
                {
                    DateTime ClockInAfterBreak = ClockInOutTime;
                    TimeSpan ResultAfterBreak = ClockInOutTime.TimeOfDay - BreakEnd.TimeOfDay;
                    double ExtraBreakTime = ResultAfterBreak.TotalSeconds / 60.0;
                }

                if ((ClockInOutTime.TimeOfDay <= DefShiftEndTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutEndOfDay = ClockInOutTime;
                    TimeSpan ResultEarlyLeave = DefShiftEndTime.TimeOfDay - ClockInOutTime.TimeOfDay;
                    double TimeLeftEarly = ResultEarlyLeave.TotalSeconds / 60.0;
                }
                else if ((ClockInOutTime.TimeOfDay >= DefShiftEndTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutAfterShiftEnd = ClockInOutTime;
                    TimeSpan ResultAfterShift = ClockInOutTime.TimeOfDay - DefShiftEndTime.TimeOfDay;
                    double HoursWorkedAfterShift = ResultAfterShift.TotalSeconds / 60.0;
                }
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Navneet Hegde
Navneet Hegde
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NerishaB

ASKER

Can you please give me an example on how to do this?  I am very new to this.
I am closing the question as no other responses arrived.