We help IT Professionals succeed at work.
Get Started

C# : Display result  from array in a gridview

NerishaB
NerishaB asked
on
355 Views
Last Modified: 2013-12-16
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

Comment
Watch Question
.Net Full Stack Developer
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE