troubleshooting Question

C# : Display result from array in a gridview

Avatar of NerishaB
NerishaBFlag for South Africa asked on
.NET ProgrammingC#
3 Comments1 Solution358 ViewsLast Modified:
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
Navneet Hegde
Navneet (navneethegde)

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros