Exemplo n.º 1
0
        public static ServiceDayViewModel createServiceDayForHolidayAbsence(DateTime currentDate)
        {
            //Creates a day for a holiday / absence.  May not need to complete all fields
            ServiceDayViewModel retval     = new ServiceDayViewModel();
            DayOfWeek           currentDay = currentDate.DayOfWeek;

            if (currentDay.Equals(DayOfWeek.Saturday) || currentDay.Equals(DayOfWeek.Sunday))
            {
                //We don't set it for weekends
                return(null);
            }

            //Set the items which don't change by the day
            retval.DailyReport        = "";
            retval.DtReport           = currentDate;
            retval.Mileage            = 0;
            retval.OvernightAllowance = false;
            retval.PartsSuppliedToday = "";
            retval.TravelTimeFromSite = 0;
            retval.TravelTimeToSite   = 0;

            //Day always starts at 8 am.
            TimeSpan dayStartTime     = new TimeSpan(8, 0, 0);
            DateTime dayStartDateTime = currentDate.Date + dayStartTime;
            DateTime dayEndDateTime   = new DateTime();
            int      totalTimeOnsite  = 0;

            switch (currentDay)
            {
            case DayOfWeek.Monday:
            case DayOfWeek.Tuesday:
            case DayOfWeek.Wednesday:
            case DayOfWeek.Thursday:
                totalTimeOnsite = 8;
                dayEndDateTime  = dayStartDateTime.AddHours(totalTimeOnsite);
                break;

            case DayOfWeek.Friday:
                totalTimeOnsite = 6;
                dayEndDateTime  = dayStartDateTime.AddHours(totalTimeOnsite);
                break;

            default:
                throw new Exception("Unknown day: " + currentDay.ToString());
            }

            retval.TravelStartTime   = dayStartDateTime;
            retval.ArrivalOnsiteTime = dayStartDateTime;
            retval.DepartureSiteTime = dayEndDateTime;
            retval.TravelEndTime     = dayEndDateTime;
            retval.TotalOnsiteTime   = totalTimeOnsite;
            retval.TotalTravelTime   = 0;

            return(retval);
        }
        private void removeFromMissingCalendar(ServiceDayViewModel day, Dictionary <DateTime, List <DbEmployee> > missingDays)
        {
            DateTime   currentDay    = day.DtReport;
            DbEmployee employeeFound = getEmployeeForUsername(day.ParentServiceSheetVM.Username);

            List <DbEmployee> employeeListForDay;

            if (missingDays.TryGetValue(currentDay, out employeeListForDay))
            {
                employeeListForDay.Remove(employeeFound);
                missingDays[currentDay] = employeeListForDay;
            }
        }
        private double calculateStandardHours(ServiceDayViewModel currentDay)
        {
            //Monday - Thursday are the first 8 hours onsite.
            //Friday is the first 6
            //Weekends and Bank holidays are all

            double retval      = 0;
            double hoursOnsite = currentDay.TotalOnsiteTime;

            double standardHoursLimitNormal = 8;
            double standardHoursFriday      = 6;

            DayOfWeek day = currentDay.DtReport.DayOfWeek;

            if ((DayOfWeek.Monday <= day) && (day <= DayOfWeek.Thursday))
            {
                if (hoursOnsite > standardHoursLimitNormal)
                {
                    retval = standardHoursLimitNormal;
                }
                else
                {
                    retval = hoursOnsite;
                }
            }

            if (day == DayOfWeek.Friday)
            {
                if (hoursOnsite > standardHoursFriday)
                {
                    retval = standardHoursFriday;
                }
                else
                {
                    retval = hoursOnsite;
                }
            }

            if ((day == DayOfWeek.Saturday) || (day == DayOfWeek.Sunday))
            {
                retval = 0;
            }

            return(retval);
        }
        private void addItemToActualDaysCalendar(ServiceDayViewModel day, Dictionary <DateTime, List <DbEmployee> > actualDays)
        {
            DateTime currentDate = day.DtReport;

            //Find engineer for day
            string     usernameDay   = day.ParentServiceSheetVM.Username;
            DbEmployee employeeMatch = getEmployeeForUsername(usernameDay);

            List <DbEmployee> employeeListDay;

            if (actualDays.TryGetValue(currentDate, out employeeListDay))
            {
                employeeListDay.Add(employeeMatch);
                actualDays[currentDate] = employeeListDay;
            }
            else
            {
                employeeListDay = new List <DbEmployee>();
                employeeListDay.Add(employeeMatch);
                actualDays.Add(currentDate, employeeListDay);
            }
        }
        private void addDayToTimesheet(ServiceDayViewModel currentDay, int dayCounter, bool?UkSheet)
        {
            //Add the header of the day title

            //Day number is counter plus 1
            int dayNumber = dayCounter + 1;

            Row row1Title = timesheetTable.AddRow();

            row1Title.Cells[0].MergeRight = 1;
            Paragraph jobDetailsPara = row1Title.Cells[0].AddParagraph();

            jobDetailsPara.AddFormattedText("D", "allCapsFirstLetter");
            jobDetailsPara.AddFormattedText("AY " + dayNumber, "allCapsNextLetter");
            row1Title.Cells[0].Shading.Color = timesheetDayGrey;

            //Keep the rows together
            row1Title.KeepWith = 14;

            //RT 7/9/17 - Adding USA date format
            if (UkSheet == true)
            {
                addLineToTimesheet("Date", currentDay.DtReport.ToString("dd/MM/yyyy"));
            }
            else
            {
                addLineToTimesheet("Date", currentDay.DtReport.ToString("MM/dd/yyyy"));
            }

            addLineToTimesheet("Day", currentDay.DtReport.ToString("dddd"));
            addLineToTimesheet("Travel start time", currentDay.TravelStartTime.ToShortTimeString());
            addLineToTimesheet("Arrival time onsite", currentDay.ArrivalOnsiteTime.ToShortTimeString());
            addLineToTimesheet("Departure time from site", currentDay.DepartureSiteTime.ToShortTimeString());
            addLineToTimesheet("Travel end time", currentDay.TravelEndTime.ToShortTimeString());
            addLineToTimesheet("Mileage", currentDay.Mileage.ToString());
            //RT 5/7/16 - Changing the true/false for the allowances to 1 or 0
            if (currentDay.DailyAllowance == true)
            {
                addLineToTimesheet("Daily allowance", "1");
            }
            else if (currentDay.DailyAllowance == false)
            {
                addLineToTimesheet("Daily allowance", "0");
            }
            else
            {
                new Exception("Daily allowance incorrect");
            }
            //addLineToTimesheet("Daily allowance", currentDay.DailyAllowance.ToString());

            if (currentDay.OvernightAllowance == true)
            {
                addLineToTimesheet("Overnight allowance", "1");
            }
            else if (currentDay.OvernightAllowance == false)
            {
                addLineToTimesheet("Overnight allowance", "0");
            }
            else
            {
                new Exception("Overnight allowance incorrect");
            }
            //addLineToTimesheet("Overnight allowance", currentDay.OvernightAllowance.ToString());
            //RT - If there are no barrier payments, then don't include them on the sheet
            double totalBarrierPayments = currentSheet.TotalBarrierPayments;

            if (totalBarrierPayments > 0)
            {
                //addLineToTimesheet("Barrier payment", currentDay.BarrierPayment.ToString());
                if (currentDay.BarrierPayment == true)
                {
                    addLineToTimesheet("Barrier payment", "1");
                }
                else if (currentDay.BarrierPayment == false)
                {
                    addLineToTimesheet("Barrier payment", "0");
                }
                else
                {
                    new Exception("Barrier payment incorrect");
                }
                //MessageBox.Show("Remove barrier payment!");
            }
            else
            {
                //Decrease the keepwith by 1 as we are removing a row
                row1Title.KeepWith = 13;
            }
            addLineToTimesheet("Total travel time", currentDay.TotalTravelTime.ToString());
            addLineToTimesheet("Total time onsite", currentDay.TotalOnsiteTime.ToString());
            addLineToTimesheet("Daily report", currentDay.DailyReport);
            addLineToTimesheet("Parts supplied today", currentDay.PartsSuppliedToday);
        }
Exemplo n.º 6
0
        private void createExportLineForDay(ServiceDayViewModel currentDay)
        {
            //This adds the day to the export
            DateTime travelStart = currentDay.TravelStartTime;
            csvWriterOutput.WriteField(travelStart);
            DateTime arrivalOnsite = currentDay.ArrivalOnsiteTime;
            csvWriterOutput.WriteField(arrivalOnsite);
            DateTime departureFromSite = currentDay.DepartureSiteTime;
            csvWriterOutput.WriteField(departureFromSite);
            DateTime travelEnd = currentDay.TravelEndTime;
            csvWriterOutput.WriteField(travelEnd);
            double mileage = currentDay.Mileage;
            csvWriterOutput.WriteField(mileage);
            Boolean dailyAllowance = currentDay.DailyAllowance;
            //RT 23/11/16 - Changing boolean output to 1/0
            if (dailyAllowance)
            {
                csvWriterOutput.WriteField(1);
            }
            else
            {
                csvWriterOutput.WriteField(0);
            }
            //csvWriterOutput.WriteField(dailyAllowance);

            Boolean overnightAllowance = currentDay.OvernightAllowance;
            if (overnightAllowance)
            {
                csvWriterOutput.WriteField(1);
            }
            else
            {
                csvWriterOutput.WriteField(0);
            }
            //csvWriterOutput.WriteField(overnightAllowance);


            Boolean barrierPayment = currentDay.BarrierPayment;
            if (barrierPayment)
            {
                csvWriterOutput.WriteField(1);
            }
            else
            {
                csvWriterOutput.WriteField(0);
            }
            //csvWriterOutput.WriteField(barrierPayment);
            double travelTimeToSite = currentDay.TravelTimeToSite;
            csvWriterOutput.WriteField(travelTimeToSite);
            double travelTimeFromSite = currentDay.TravelTimeFromSite;
            csvWriterOutput.WriteField(travelTimeFromSite);
            double totalTravelTime = currentDay.TotalTravelTime;
            csvWriterOutput.WriteField(totalTravelTime);
            double totalTimeOnsite = currentDay.TotalOnsiteTime;
            csvWriterOutput.WriteField(totalTimeOnsite);
            string dailyReport = currentDay.DailyReport;
            csvWriterOutput.WriteField(dailyReport);
            string partsSupplied = currentDay.PartsSuppliedToday;
            csvWriterOutput.WriteField(partsSupplied);
            DateTime dtTimesheet = currentDay.DtReport;
            csvWriterOutput.WriteField(dtTimesheet);
        }
Exemplo n.º 7
0
        //RT 28/11/16 - Rewriting this to use the MVVM pattern
        //private void loadDayForSubmission(string[] row, ServiceSheetViewModel currentSubmission)
        //{
        //    string dateFormatMinutes = "d/M/yyyy HH:mm";
        //    string dateFormatSeconds = "d/M/yyyy H:mm:ss";

        //    //Need to set the submission on the service day
        //    ServiceDayViewModel currentDay = new ServiceDayViewModel(currentSubmission);
        //    //The times may be with / without the date, depending on when they were imported.
        //    //Need to load the service date first, in case we need it for the times
        //    string serviceDate = row[40];
        //    currentDay.DtReport = DateTime.ParseExact(serviceDate, "d/M/yyyy", CultureInfo.InvariantCulture);

        //    string travelStartTime = row[26];
        //    try
        //    {
        //        currentDay.TravelStartTime = DateTime.ParseExact(travelStartTime, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.TravelStartTime = DateTime.ParseExact(travelStartTime, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string travelStartIncDate = serviceDate + " " + travelStartTime;
        //            currentDay.TravelStartTime = DateTime.ParseExact(travelStartIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    string arrivalTimeOnsite = row[27];
        //    try
        //    {
        //        currentDay.ArrivalOnsiteTime = DateTime.ParseExact(arrivalTimeOnsite, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.ArrivalOnsiteTime = DateTime.ParseExact(arrivalTimeOnsite, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string arrivalOnsiteIncDate = serviceDate + " " + arrivalTimeOnsite;
        //            currentDay.ArrivalOnsiteTime = DateTime.ParseExact(arrivalOnsiteIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    string departureTime = row[28];
        //    try
        //    {
        //        currentDay.DepartSiteTime = DateTime.ParseExact(departureTime, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.DepartSiteTime = DateTime.ParseExact(departureTime, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string departureIncDate = serviceDate + " " + departureTime;
        //            currentDay.DepartSiteTime = DateTime.ParseExact(departureIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    string travelEndTime = row[29];
        //    try
        //    {
        //        currentDay.TravelEndTime = DateTime.ParseExact(travelEndTime, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.TravelEndTime = DateTime.ParseExact(travelEndTime, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string travelEndIncDate = serviceDate + " " + travelEndTime;
        //            currentDay.TravelEndTime = DateTime.ParseExact(travelEndIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    currentDay.Mileage = Convert.ToInt32(row[30]);
        //    //try
        //    //{
        //    //    currentDay.ServiceDay.DailyAllowance = Convert.ToBoolean(row[31]);
        //    //}
        //    //catch
        //    //{
        //    //If this fails, then it nust be an integer
        //    //    int dailyAllowance = Convert.ToInt32(row[31]);
        //    //    if (dailyAllowance == 1)
        //    //    {
        //    //        currentDay.ServiceDay.DailyAllowance = true;
        //    //    }
        //    //    else
        //    //    {
        //    //        currentDay.ServiceDay.DailyAllowance = false;
        //    //    }
        //    ////}

        //    currentDay.DailyAllowance = Convert.ToBoolean(row[31]);

        //    //try
        //    //{
        //    //    currentDay.ServiceDay.OvernightAllowance = Convert.ToBoolean(row[32]);
        //    //}
        //    //catch
        //    //{
        //    //    //If this fails, then it nust be an integer
        //    //    int overnightAllowance = Convert.ToInt32(row[32]);
        //    //    if (overnightAllowance == 1)
        //    //    {
        //    //        currentDay.ServiceDay.OvernightAllowance = true;
        //    //    }
        //    //    else
        //    //    {
        //    //        currentDay.ServiceDay.OvernightAllowance = false;
        //    //    }
        //    //}
        //    currentDay.OvernightAllowance = Convert.ToBoolean(row[32]);
        //    //try
        //    //{
        //    //    currentDay.ServiceDay.BarrierPayment = Convert.ToBoolean(row[33]);
        //    //}
        //    //catch
        //    //{
        //    //    //If this fails, then it nust be an integer
        //    //    int barrierPayment = Convert.ToInt32(row[33]);
        //    //    if (barrierPayment == 1)
        //    //    {
        //    //        currentDay.ServiceDay.BarrierPayment = true;
        //    //    }
        //    //    else
        //    //    {
        //    //        currentDay.ServiceDay.BarrierPayment = false;
        //    //    }
        //    //}
        //    currentDay.BarrierPayment = Convert.ToBoolean(row[33]);

        //    currentDay.TravelTimeToSite = Convert.ToDouble(row[34]);
        //    currentDay.TravelTimeFromSite = Convert.ToDouble(row[35]);
        //    currentDay.TotalTravelTime = Convert.ToDouble(row[36]);
        //    currentDay.TotalTimeOnsite = Convert.ToDouble(row[37]);
        //    currentDay.DailyReport = row[38];
        //    currentDay.PartsSupplied = row[39];

        //    //RT 16/8/16 - Saving the timesheet
        //    //currentSubmission.AllServiceDayVMs.
        //}
        private void loadDayForSubmission(string[] row, ServiceSheetViewModel currentSubmission)
        {
            //RT 6/12/16 - If the first date is blank, then we are loading a csv created with this application
            bool serviceReaderCsv = false;
            string startDateStr = row[0];
            if (String.IsNullOrEmpty(startDateStr))
            {
                serviceReaderCsv = true;
            }

            string dateFormatMinutes = "d/M/yyyy HH:mm";
            //RT 6/12/16 - varable no longer needed.  Added by accident
            //string dateFormatSeconds = "d/M/yyyy H:mm:ss";

            //Need to set the submission on the service day
            //ServiceDayViewModel currentDay = new ServiceDayViewModel(currentSubmission);
            //The times may be with / without the date, depending on when they were imported.
            //Need to load the service date first, in case we need it for the times
            string serviceDate = row[40];
            //RT 6/12/16 - From canvas csv, this is a date, datetime from service reader
            DateTime dtReport;
            if (serviceReaderCsv)
            {
                dtReport = DateTime.ParseExact(serviceDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            else
            {
                dtReport = DateTime.ParseExact(serviceDate, "d/M/yyyy", CultureInfo.InvariantCulture);
            }

            string travelStartTime = row[26];

            //RT 6/12/16 - Canvas created csv's are time only.  Service Reader ones include 
            DateTime dtTravelStart;
            if (serviceReaderCsv)
            {
                dtTravelStart = DateTime.ParseExact(travelStartTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            else
            {
                string travelStartIncDate = serviceDate + " " + travelStartTime;
                dtTravelStart = DateTime.ParseExact(travelStartIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            //try
            //{
            //    dtTravelStart = DateTime.ParseExact(travelStartTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtTravelStart = DateTime.ParseExact(travelStartTime, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string travelStartIncDate = serviceDate + " " + travelStartTime;
            //        dtTravelStart = DateTime.ParseExact(travelStartIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            string arrivalTimeOnsite = row[27];
            DateTime dtArrivalOnsite;
            if (serviceReaderCsv)
            {
                dtArrivalOnsite = DateTime.ParseExact(arrivalTimeOnsite, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            else
            {
                string arrivalOnsiteIncDate = serviceDate + " " + arrivalTimeOnsite;
                dtArrivalOnsite = DateTime.ParseExact(arrivalOnsiteIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }

            //try
            //{
            //    dtArrivalOnsite = DateTime.ParseExact(arrivalTimeOnsite, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtArrivalOnsite = DateTime.ParseExact(arrivalTimeOnsite, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string arrivalOnsiteIncDate = serviceDate + " " + arrivalTimeOnsite;
            //        dtArrivalOnsite = DateTime.ParseExact(arrivalOnsiteIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            string departureTime = row[28];
            DateTime dtDeparture;
            if (serviceReaderCsv)
            {
                dtDeparture = DateTime.ParseExact(departureTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            else
            {
                string departureIncDate = serviceDate + " " + departureTime;
                dtDeparture = DateTime.ParseExact(departureIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            //try
            //{
            //    dtDeparture = DateTime.ParseExact(departureTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtDeparture = DateTime.ParseExact(departureTime, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string departureIncDate = serviceDate + " " + departureTime;
            //        dtDeparture = DateTime.ParseExact(departureIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            string travelEndTime = row[29];
            DateTime dtTravelEnd;
            if (serviceReaderCsv)
            {
                dtTravelEnd = DateTime.ParseExact(travelEndTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            else
            {
                string travelEndIncDate = serviceDate + " " + travelEndTime;
                dtTravelEnd = DateTime.ParseExact(travelEndIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            //try
            //{
            //    dtTravelEnd = DateTime.ParseExact(travelEndTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtTravelEnd = DateTime.ParseExact(travelEndTime, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string travelEndIncDate = serviceDate + " " + travelEndTime;
            //        dtTravelEnd = DateTime.ParseExact(travelEndIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            int mileage = Convert.ToInt32(row[30]);
            //RT 6/12/16  - The allowances are 1/0.  Need to convert to bool
            string daStr = row[31];
            bool dailyAllowance;
            if (daStr.Equals("1"))
            {
                dailyAllowance = true;
            }
            else
            {
                dailyAllowance = false;
            }
            //bool dailyAllowance = Convert.ToBoolean(row[31]);
            bool overnightAllowance;
            string onStr = row[32];
            if (onStr.Equals("1"))
            {
                overnightAllowance = true;
            }
            else
            {
                overnightAllowance = false;
            }
            //bool overnightAllowance = Convert.ToBoolean(row[32]);
            bool barrierPayment;
            string bpStr = row[33];
            if (bpStr.Equals("1"))
            {
                barrierPayment = true;
            }
            else
            {
                barrierPayment = false;
            }
            //bool barrierPayment = Convert.ToBoolean(row[33]);
            double travelTimeToSite = Convert.ToDouble(row[34]);
            double travelTimeFromSite = Convert.ToDouble(row[35]);
            double totalTravelTime = Convert.ToDouble(row[36]);
            double totalTimeOnsite = Convert.ToDouble(row[37]);
            string dailyReport = row[38];
            string partsSupplied = row[39];
            //Now create the serviceDayVM
            ServiceDayViewModel retval = new ServiceDayViewModel(dtTravelStart, dtArrivalOnsite, dtDeparture, dtTravelEnd, mileage, dailyAllowance, overnightAllowance, barrierPayment,
                travelTimeToSite, travelTimeFromSite, totalTravelTime, totalTimeOnsite, dailyReport, partsSupplied, dtReport, currentSubmission);
            currentSubmission.AddServiceDayViewModel(retval);
            //This doesn't need to return anything, as the day has been set on the submission.
        }
 public void AddServiceDay(ServiceDayViewModel sdToAdd)
 {
     AllServiceDayVMs.Add(sdToAdd);
 }
Exemplo n.º 9
0
        private void addDayToTimesheet(ServiceDayViewModel currentDay, int dayCounter)
        {
            //Add the header of the day title

            //Day number is counter plus 1
            int dayNumber = dayCounter + 1;

            Row row1Title = timesheetTable.AddRow();
            row1Title.Cells[0].MergeRight = 1;
            Paragraph jobDetailsPara = row1Title.Cells[0].AddParagraph();
            jobDetailsPara.AddFormattedText("D", "allCapsFirstLetter");
            jobDetailsPara.AddFormattedText("AY " + dayNumber, "allCapsNextLetter");
            row1Title.Cells[0].Shading.Color = timesheetDayGrey;

            //Keep the rows together
            row1Title.KeepWith = 14;    

            addLineToTimesheet("Date", currentDay.DtReport.ToShortDateString());
            addLineToTimesheet("Day", currentDay.DtReport.ToString("dddd"));
            addLineToTimesheet("Travel start time", currentDay.TravelStartTime.ToShortTimeString());
            addLineToTimesheet("Arrival time onsite", currentDay.ArrivalOnsiteTime.ToShortTimeString());
            addLineToTimesheet("Departure time from site", currentDay.DepartureSiteTime.ToShortTimeString());
            addLineToTimesheet("Travel end time", currentDay.TravelEndTime.ToShortTimeString());
            addLineToTimesheet("Mileage", currentDay.Mileage.ToString());
            //RT 5/7/16 - Changing the true/false for the allowances to 1 or 0
            if (currentDay.DailyAllowance == true)
            {
                addLineToTimesheet("Daily allowance", "1");
            }
            else if (currentDay.DailyAllowance == false)
            {
                addLineToTimesheet("Daily allowance", "0");
            }
            else
            {
                new Exception("Daily allowance incorrect");
            }
            //addLineToTimesheet("Daily allowance", currentDay.DailyAllowance.ToString());

            if (currentDay.OvernightAllowance == true)
            {
                addLineToTimesheet("Overnight allowance", "1");
            }
            else if (currentDay.OvernightAllowance == false)
            {
                addLineToTimesheet("Overnight allowance", "0");
            }
            else
            {
                new Exception("Overnight allowance incorrect");
            }
            //addLineToTimesheet("Overnight allowance", currentDay.OvernightAllowance.ToString());
            //RT - If there are no barrier payments, then don't include them on the sheet
            double totalBarrierPayments = currentSheet.TotalBarrierPayments;
            if (totalBarrierPayments > 0)
            {
                //addLineToTimesheet("Barrier payment", currentDay.BarrierPayment.ToString());
                if (currentDay.BarrierPayment == true)
                {
                    addLineToTimesheet("Barrier payment", "1");
                }
                else if (currentDay.BarrierPayment == false)
                {
                    addLineToTimesheet("Barrier payment", "0");
                }
                else
                {
                    new Exception("Barrier payment incorrect");
                }
                //MessageBox.Show("Remove barrier payment!");
            }
            else
            {
                //Decrease the keepwith by 1 as we are removing a row
                row1Title.KeepWith = 13;
            }
            addLineToTimesheet("Total travel time", currentDay.TotalTravelTime.ToString());
            addLineToTimesheet("Total time onsite", currentDay.TotalOnsiteTime.ToString());
            addLineToTimesheet("Daily report", currentDay.DailyReport);
            addLineToTimesheet("Parts supplied today", currentDay.PartsSuppliedToday);
        }
Exemplo n.º 10
0
        //public static ServiceSheetViewModel createSubmissionForXml(XElement submissionXml)
        //{
        //    ServiceSheetViewModel retval = new ServiceSheetViewModel();
        //    ServiceSheet serviceSheetReturn = new ServiceSheet();
        //    serviceSheetReturn.SubmissionNumber = Int32.Parse(submissionXml.Element(SUBMISSION_NUMBER).Value);
        //    //RT 11/8/16 - Adding in the response id
        //    serviceSheetReturn.CanvasResponseId = submissionXml.Element(RESPONSE_ID).Value;
        //    //Adding response date time
        //    string responseDateStr = submissionXml.Element(RESPONSE_DATE_TIME).Value;
        //    serviceSheetReturn.DtResponse = Convert.ToDateTime(responseDateStr);
        //    //Adding device date
        //    string deviceDateStr = submissionXml.Element(DEVICE_DATE_TIME).Value;
        //    serviceSheetReturn.DtDevice = Convert.ToDateTime(deviceDateStr);
        //    //Submission version is in the form element
        //    XElement formDetailsXml = submissionXml.Element(FORM);
        //    serviceSheetReturn.SubmissionFormVersion = Int32.Parse(formDetailsXml.Element(SUBMISSION_VERSION).Value);
        //    serviceSheetReturn.Username = submissionXml.Element(USERNAME).Value;
        //    serviceSheetReturn.UserFirstName = submissionXml.Element(FIRST_NAME).Value;
        //    serviceSheetReturn.UserSurname = submissionXml.Element(SURNAME).Value;

        //    XElement sectionsXml = submissionXml.Element(SECTIONS);
        //    // Loop through the sections
        //    foreach (XElement sectionXml in sectionsXml.Elements())
        //    {
        //        string sectionName = sectionXml.Element(SECTION_NAME).Value;
        //        if (sectionName.Equals(JOB_DETAILS))
        //        {
        //            XElement screensXml = sectionXml.Element(SCREENS);
        //            XElement screenXml = screensXml.Element(SCREEN);
        //            XElement responsesXml = screenXml.Element(RESPONSES);
        //            //Parse the job details

        //            serviceSheetReturn.Customer = xmlResult(CUSTOMER, responsesXml);
        //            serviceSheetReturn.AddressLine1 = xmlResult(ADDRESS_1, responsesXml);
        //            serviceSheetReturn.AddressLine2 = xmlResult(ADDRESS_2, responsesXml);
        //            serviceSheetReturn.TownCity = xmlResult(TOWN_CITY, responsesXml);
        //            serviceSheetReturn.Postcode = xmlResult(POSTCODE, responsesXml);
        //            serviceSheetReturn.CustomerContact = xmlResult(CUSTOMER_CONTACT, responsesXml);
        //            serviceSheetReturn.CustomerPhoneNo = xmlResult(CUSTOMER_PHONE, responsesXml);
        //            serviceSheetReturn.MachineMakeModel = xmlResult(MACHINE_MAKE_MODEL, responsesXml);
        //            //RT 11/8/16 - Adding serial number
        //            serviceSheetReturn.MachineSerial = xmlResult(SERIAL_NUMBER, responsesXml);

        //            serviceSheetReturn.CncControl = xmlResult(MACHINE_CONTROL, responsesXml);
        //            string jobStartStr = xmlResult(JOB_START_DATE, responsesXml);
        //            serviceSheetReturn.DtJobStart = Convert.ToDateTime(jobStartStr);
        //            serviceSheetReturn.CustomerOrderNo = xmlResult(CUSTOMER_ORDER, responsesXml);
        //            serviceSheetReturn.MttJobNumber = xmlResult(MTT_JOB_NO, responsesXml);
        //            serviceSheetReturn.JobDescription = xmlResult(JOB_DESC, responsesXml);

        //        }
        //        else if (sectionName.Equals(TIME_SHEET))
        //        {
        //            XElement screensXml = sectionXml.Element(SCREENS);
        //            XElement screenXml = screensXml.Element(SCREEN);
        //            XElement responseGroupsXml = screenXml.Element(RESPONSE_GROUPS);
        //            //retval.ServiceTimesheets = ServiceDay.createDays(responseGroupsXml);
        //            serviceSheetReturn.ServiceDays= createDays(responseGroupsXml);
        //        }
        //        else if (sectionName.Equals(JOB_SIGNOFF))
        //        {
        //            XElement screensXml = sectionXml.Element(SCREENS);
        //            XElement screenXml = screensXml.Element(SCREEN);
        //            XElement responsesXml = screenXml.Element(RESPONSES);

        //            serviceSheetReturn.JobTotalTimeOnsite = Convert.ToDouble(xmlResult(JOB_TOTAL_TIME_ONSITE, responsesXml));
        //            serviceSheetReturn.JobTotalTravelTime = Convert.ToDouble(xmlResult(TOTAL_TRAVEL_TIME, responsesXml));

        //            //RT 13/10/16 - Mileage, daily/overnight and BP are int, although canvas returns a string like a double.  There will never be a decimal point in them
        //            double mileageRead = Convert.ToDouble(xmlResult(TOTAL_MILEAGE, responsesXml));
        //            serviceSheetReturn.JobTotalMileage = (int)mileageRead;
        //            double totalDaRead = Convert.ToDouble(xmlResult(TOTAL_DAILY_ALLOWANCES, responsesXml));
        //            serviceSheetReturn.TotalDailyAllowances = (int)totalDaRead;
        //            double totalOaRead = Convert.ToDouble(xmlResult(TOTAL_OVERNIGHT_ALLOWANCES, responsesXml));
        //            serviceSheetReturn.TotalOvernightAllowances = (int)totalOaRead;
        //            double totalBpRead = Convert.ToDouble(xmlResult(TOTAL_BARRIER_PAYMENTS, responsesXml));
        //            serviceSheetReturn.TotalBarrierPayments = (int)totalBpRead;
        //            serviceSheetReturn.JobStatus = xmlResult(JOB_STATUS, responsesXml);
        //            serviceSheetReturn.FinalJobReport = xmlResult(FINAL_JOB_REPORT, responsesXml);
        //            serviceSheetReturn.AdditionalFaults = xmlResult(ADDITIONAL_FAULTS_FOUND, responsesXml);
        //            serviceSheetReturn.QuoteRequired = Convert.ToBoolean(xmlResult(QUOTE_REQUIRED, responsesXml));
        //            serviceSheetReturn.FollowUpPartsRequired = xmlResult(FOLLOWUP_PARTS, responsesXml);
        //            serviceSheetReturn.Image1Url = xmlResult(IMAGE_1_URL, responsesXml);
        //            serviceSheetReturn.Image2Url = xmlResult(IMAGE_2_URL, responsesXml);
        //            serviceSheetReturn.Image3Url = xmlResult(IMAGE_3_URL, responsesXml);
        //            serviceSheetReturn.Image4Url = xmlResult(IMAGE_4_URL, responsesXml);
        //            serviceSheetReturn.Image5Url = xmlResult(IMAGE_5_URL, responsesXml);
        //            serviceSheetReturn.CustomerSignatureUrl = xmlResult(CUSTOMER_SIGNATURE, responsesXml);
        //            serviceSheetReturn.CustomerName = xmlResult(CUSTOMER_NAME, responsesXml);
        //            serviceSheetReturn.DtSigned = Convert.ToDateTime(xmlResult(DATE_SIGNED, responsesXml));
        //            serviceSheetReturn.MttEngSignatureUrl = xmlResult(MTT_ENG_SIGNATURE, responsesXml);
        //        }
        //        else
        //        {
        //            new Exception("Unknown Canvas Data Section");
        //        }

        //    }
        //    retval.ServiceSubmission = serviceSheetReturn;
        //    return retval;
        //}

        //RT 29/11/16 - Rewiting to use new MVVM methods
        public static AllServiceDayViewModels createDays(XElement allDays)
        {
            AllServiceDayViewModels retval = new AllServiceDayViewModels();

            foreach (XElement responseGroupXml in allDays.Elements())
            {
                string dtServiceStr = xmlResult(DATE, responseGroupXml);
                DateTime dtReport = Convert.ToDateTime(dtServiceStr);
                XElement sectionXml = responseGroupXml.Element(SECTION);
                XElement screensXml = sectionXml.Element(SCREENS);
                XElement screenXml = screensXml.Element(SCREEN);
                XElement responsesXml = screenXml.Element(RESPONSES);

                string travelStartStr = xmlResult(TRAVEL_START, responsesXml);
                DateTime TravelStartTime = Convert.ToDateTime(dtServiceStr + " " + travelStartStr);
                string arrivalOnsiteStr = xmlResult(ARRIVE_ONSITE, responsesXml);
                DateTime ArrivalOnsiteTime = Convert.ToDateTime(dtServiceStr + " " + arrivalOnsiteStr);
                string departSiteStr = xmlResult(DEPART_SITE, responsesXml);
                DateTime DepartureSiteTime = Convert.ToDateTime(dtServiceStr + " " + departSiteStr);
                string travelEndStr = xmlResult(TRAVEL_END, responsesXml);
                DateTime TravelEndTime = Convert.ToDateTime(dtServiceStr + " " + travelEndStr);
                int Mileage = Convert.ToInt32(xmlResult(MILEAGE, responsesXml));
                string currentXmlResult = xmlResult(DAILY_ALLOWANCE, responsesXml);
                int DailyAllowance = Convert.ToInt32(currentXmlResult);
                bool da;
                if (DailyAllowance == 1)
                {
                    da = true;
                }
                else
                {
                    da = false;
                }
                currentXmlResult = xmlResult(OVERNIGHT_ALLOWANCE, responsesXml);
                int OvernightAllowance = Convert.ToInt32(currentXmlResult);
                bool oN;
                if (OvernightAllowance == 1)
                {
                    oN = true;
                }
                else
                {
                    oN = false;
                }
                currentXmlResult = xmlResult(BARRIER_PAYMENT, responsesXml);
                int BarrierPayment = Convert.ToInt32(currentXmlResult);
                bool bP;
                if (BarrierPayment == 1)
                {
                    bP = true;
                }
                else
                {
                    bP = false;
                }
                double TravelToSiteTime = Convert.ToDouble(xmlResult(TRAVEL_TO_SITE, responsesXml));
                double TravelFromSiteTime = Convert.ToDouble(xmlResult(TRAVEL_FROM_SITE, responsesXml));
                double TotalTravelTime = Convert.ToDouble(xmlResult(TOTAL_TRAVEL, responsesXml));
                double TotalOnsiteTime = Convert.ToDouble(xmlResult(TOTAL_TIME_ONSITE, responsesXml));
                string DailyReport = xmlResult(DAILY_REPORT, responsesXml);
                string PartsSuppliedToday = xmlResult(PARTS_SUPPLIED, responsesXml);

                ServiceDayViewModel sd = new ServiceDayViewModel(TravelStartTime, ArrivalOnsiteTime, DepartureSiteTime, TravelEndTime, Mileage, da, oN,
                    bP, TravelToSiteTime, TravelFromSiteTime, TotalTravelTime, TotalOnsiteTime, DailyReport, PartsSuppliedToday, dtReport, null);

                retval.AddServiceDay(sd);
            }

            //Need to sort the observable collection
            ObservableCollection<ServiceDayViewModel> sortedDays = new ObservableCollection<ServiceDayViewModel>(retval.AllServiceDayVMs.OrderBy(a => a.DtReport));
            retval.AllServiceDayVMs = sortedDays;

            return retval;
        }
 public void AddServiceDayViewModel(ServiceDayViewModel serviceDayToAdd)
 {
     AllServiceDays.AddServiceDay(serviceDayToAdd);
 }
        private void createExportLineForDay(ServiceDayViewModel currentDay)
        {
            //This adds the day to the export
            DateTime travelStart = currentDay.TravelStartTime;

            csvWriterOutput.WriteField(travelStart.ToShortTimeString());
            DateTime arrivalOnsite = currentDay.ArrivalOnsiteTime;

            csvWriterOutput.WriteField(arrivalOnsite.ToShortTimeString());
            DateTime departureFromSite = currentDay.DepartureSiteTime;

            csvWriterOutput.WriteField(departureFromSite.ToShortTimeString());
            DateTime travelEnd = currentDay.TravelEndTime;

            csvWriterOutput.WriteField(travelEnd.ToShortTimeString());
            double mileage = currentDay.Mileage;

            csvWriterOutput.WriteField(mileage);
            Boolean dailyAllowance = currentDay.DailyAllowance;

            //RT 23/11/16 - Changing boolean output to 1/0
            if (dailyAllowance)
            {
                csvWriterOutput.WriteField(1);
            }
            else
            {
                csvWriterOutput.WriteField(0);
            }
            //csvWriterOutput.WriteField(dailyAllowance);

            Boolean overnightAllowance = currentDay.OvernightAllowance;

            if (overnightAllowance)
            {
                csvWriterOutput.WriteField(1);
            }
            else
            {
                csvWriterOutput.WriteField(0);
            }
            //csvWriterOutput.WriteField(overnightAllowance);


            Boolean barrierPayment = currentDay.BarrierPayment;

            if (barrierPayment)
            {
                csvWriterOutput.WriteField(1);
            }
            else
            {
                csvWriterOutput.WriteField(0);
            }
            //csvWriterOutput.WriteField(barrierPayment);
            double travelTimeToSite = currentDay.TravelTimeToSite;

            csvWriterOutput.WriteField(travelTimeToSite);
            double travelTimeFromSite = currentDay.TravelTimeFromSite;

            csvWriterOutput.WriteField(travelTimeFromSite);
            double totalTravelTime = currentDay.TotalTravelTime;

            csvWriterOutput.WriteField(totalTravelTime);
            double totalTimeOnsite = currentDay.TotalOnsiteTime;

            csvWriterOutput.WriteField(totalTimeOnsite);
            string dailyReport = currentDay.DailyReport;

            csvWriterOutput.WriteField(dailyReport);
            string partsSupplied = currentDay.PartsSuppliedToday;

            csvWriterOutput.WriteField(partsSupplied);
            DateTime dtTimesheet = currentDay.DtReport;

            csvWriterOutput.WriteField(dtTimesheet);
        }
Exemplo n.º 13
0
        //RT 28/11/16 - Rewriting this to use the MVVM pattern
        //private void loadDayForSubmission(string[] row, ServiceSheetViewModel currentSubmission)
        //{
        //    string dateFormatMinutes = "d/M/yyyy HH:mm";
        //    string dateFormatSeconds = "d/M/yyyy H:mm:ss";

        //    //Need to set the submission on the service day
        //    ServiceDayViewModel currentDay = new ServiceDayViewModel(currentSubmission);
        //    //The times may be with / without the date, depending on when they were imported.
        //    //Need to load the service date first, in case we need it for the times
        //    string serviceDate = row[40];
        //    currentDay.DtReport = DateTime.ParseExact(serviceDate, "d/M/yyyy", CultureInfo.InvariantCulture);

        //    string travelStartTime = row[26];
        //    try
        //    {
        //        currentDay.TravelStartTime = DateTime.ParseExact(travelStartTime, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.TravelStartTime = DateTime.ParseExact(travelStartTime, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string travelStartIncDate = serviceDate + " " + travelStartTime;
        //            currentDay.TravelStartTime = DateTime.ParseExact(travelStartIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    string arrivalTimeOnsite = row[27];
        //    try
        //    {
        //        currentDay.ArrivalOnsiteTime = DateTime.ParseExact(arrivalTimeOnsite, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.ArrivalOnsiteTime = DateTime.ParseExact(arrivalTimeOnsite, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string arrivalOnsiteIncDate = serviceDate + " " + arrivalTimeOnsite;
        //            currentDay.ArrivalOnsiteTime = DateTime.ParseExact(arrivalOnsiteIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    string departureTime = row[28];
        //    try
        //    {
        //        currentDay.DepartSiteTime = DateTime.ParseExact(departureTime, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.DepartSiteTime = DateTime.ParseExact(departureTime, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string departureIncDate = serviceDate + " " + departureTime;
        //            currentDay.DepartSiteTime = DateTime.ParseExact(departureIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    string travelEndTime = row[29];
        //    try
        //    {
        //        currentDay.TravelEndTime = DateTime.ParseExact(travelEndTime, dateFormatMinutes, CultureInfo.InvariantCulture);
        //    }
        //    catch
        //    {
        //        try
        //        {
        //            currentDay.TravelEndTime = DateTime.ParseExact(travelEndTime, dateFormatSeconds, CultureInfo.InvariantCulture);
        //        }
        //        catch
        //        {
        //            string travelEndIncDate = serviceDate + " " + travelEndTime;
        //            currentDay.TravelEndTime = DateTime.ParseExact(travelEndIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
        //        }
        //    }

        //    currentDay.Mileage = Convert.ToInt32(row[30]);
        //    //try
        //    //{
        //    //    currentDay.ServiceDay.DailyAllowance = Convert.ToBoolean(row[31]);
        //    //}
        //    //catch
        //    //{
        //    //If this fails, then it nust be an integer
        //    //    int dailyAllowance = Convert.ToInt32(row[31]);
        //    //    if (dailyAllowance == 1)
        //    //    {
        //    //        currentDay.ServiceDay.DailyAllowance = true;
        //    //    }
        //    //    else
        //    //    {
        //    //        currentDay.ServiceDay.DailyAllowance = false;
        //    //    }
        //    ////}

        //    currentDay.DailyAllowance = Convert.ToBoolean(row[31]);

        //    //try
        //    //{
        //    //    currentDay.ServiceDay.OvernightAllowance = Convert.ToBoolean(row[32]);
        //    //}
        //    //catch
        //    //{
        //    //    //If this fails, then it nust be an integer
        //    //    int overnightAllowance = Convert.ToInt32(row[32]);
        //    //    if (overnightAllowance == 1)
        //    //    {
        //    //        currentDay.ServiceDay.OvernightAllowance = true;
        //    //    }
        //    //    else
        //    //    {
        //    //        currentDay.ServiceDay.OvernightAllowance = false;
        //    //    }
        //    //}
        //    currentDay.OvernightAllowance = Convert.ToBoolean(row[32]);
        //    //try
        //    //{
        //    //    currentDay.ServiceDay.BarrierPayment = Convert.ToBoolean(row[33]);
        //    //}
        //    //catch
        //    //{
        //    //    //If this fails, then it nust be an integer
        //    //    int barrierPayment = Convert.ToInt32(row[33]);
        //    //    if (barrierPayment == 1)
        //    //    {
        //    //        currentDay.ServiceDay.BarrierPayment = true;
        //    //    }
        //    //    else
        //    //    {
        //    //        currentDay.ServiceDay.BarrierPayment = false;
        //    //    }
        //    //}
        //    currentDay.BarrierPayment = Convert.ToBoolean(row[33]);

        //    currentDay.TravelTimeToSite = Convert.ToDouble(row[34]);
        //    currentDay.TravelTimeFromSite = Convert.ToDouble(row[35]);
        //    currentDay.TotalTravelTime = Convert.ToDouble(row[36]);
        //    currentDay.TotalTimeOnsite = Convert.ToDouble(row[37]);
        //    currentDay.DailyReport = row[38];
        //    currentDay.PartsSupplied = row[39];

        //    //RT 16/8/16 - Saving the timesheet
        //    //currentSubmission.AllServiceDayVMs.
        //}
        private void loadDayForSubmission(string[] row, ServiceSheetViewModel currentSubmission)
        {
            //RT 6/12/16 - If the first date is blank, then we are loading a csv created with this application
            bool   serviceReaderCsv = false;
            string startDateStr     = row[0];

            if (String.IsNullOrEmpty(startDateStr))
            {
                serviceReaderCsv = true;
            }

            string dateFormatMinutes = "d/M/yyyy HH:mm:ss";
            //RT 6/12/16 - varable no longer needed.  Added by accident
            //string dateFormatSeconds = "d/M/yyyy H:mm:ss";

            //Need to set the submission on the service day
            //ServiceDayViewModel currentDay = new ServiceDayViewModel(currentSubmission);
            //The times may be with / without the date, depending on when they were imported.
            //Need to load the service date first, in case we need it for the times
            string serviceDate = row[40];
            //RT 6/12/16 - From canvas csv, this is a date, datetime from service reader
            DateTime dtReport;

            if (serviceReaderCsv)
            {
                dtReport = DateTime.ParseExact(serviceDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            else
            {
                dtReport = DateTime.ParseExact(serviceDate, "d/M/yyyy", CultureInfo.InvariantCulture);
            }

            string travelStartTime = row[26];

            //RT 6/12/16 - Canvas created csv's are time only.  Service Reader ones include
            DateTime dtTravelStart;

            if (serviceReaderCsv)
            {
                dtTravelStart = DateTime.ParseExact(travelStartTime, "HH:mm", CultureInfo.InvariantCulture);
            }
            else
            {
                string travelStartIncDate = serviceDate + " " + travelStartTime;
                dtTravelStart = DateTime.ParseExact(travelStartIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            //try
            //{
            //    dtTravelStart = DateTime.ParseExact(travelStartTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtTravelStart = DateTime.ParseExact(travelStartTime, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string travelStartIncDate = serviceDate + " " + travelStartTime;
            //        dtTravelStart = DateTime.ParseExact(travelStartIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            string   arrivalTimeOnsite = row[27];
            DateTime dtArrivalOnsite;

            if (serviceReaderCsv)
            {
                dtArrivalOnsite = DateTime.ParseExact(arrivalTimeOnsite, "HH:mm", CultureInfo.InvariantCulture);
            }
            else
            {
                string arrivalOnsiteIncDate = serviceDate + " " + arrivalTimeOnsite;
                dtArrivalOnsite = DateTime.ParseExact(arrivalOnsiteIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }

            //try
            //{
            //    dtArrivalOnsite = DateTime.ParseExact(arrivalTimeOnsite, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtArrivalOnsite = DateTime.ParseExact(arrivalTimeOnsite, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string arrivalOnsiteIncDate = serviceDate + " " + arrivalTimeOnsite;
            //        dtArrivalOnsite = DateTime.ParseExact(arrivalOnsiteIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            string   departureTime = row[28];
            DateTime dtDeparture;

            if (serviceReaderCsv)
            {
                dtDeparture = DateTime.ParseExact(departureTime, "HH:mm", CultureInfo.InvariantCulture);
            }
            else
            {
                string departureIncDate = serviceDate + " " + departureTime;
                dtDeparture = DateTime.ParseExact(departureIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            //try
            //{
            //    dtDeparture = DateTime.ParseExact(departureTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtDeparture = DateTime.ParseExact(departureTime, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string departureIncDate = serviceDate + " " + departureTime;
            //        dtDeparture = DateTime.ParseExact(departureIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            string   travelEndTime = row[29];
            DateTime dtTravelEnd;

            if (serviceReaderCsv)
            {
                dtTravelEnd = DateTime.ParseExact(travelEndTime, "HH:mm", CultureInfo.InvariantCulture);
            }
            else
            {
                string travelEndIncDate = serviceDate + " " + travelEndTime;
                dtTravelEnd = DateTime.ParseExact(travelEndIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            }
            //try
            //{
            //    dtTravelEnd = DateTime.ParseExact(travelEndTime, dateFormatMinutes, CultureInfo.InvariantCulture);
            //}
            //catch
            //{
            //    try
            //    {
            //        dtTravelEnd = DateTime.ParseExact(travelEndTime, dateFormatSeconds, CultureInfo.InvariantCulture);
            //    }
            //    catch
            //    {
            //        string travelEndIncDate = serviceDate + " " + travelEndTime;
            //        dtTravelEnd = DateTime.ParseExact(travelEndIncDate, dateFormatMinutes, CultureInfo.InvariantCulture);
            //    }
            //}

            int mileage = Convert.ToInt32(row[30]);
            //RT 6/12/16  - The allowances are 1/0.  Need to convert to bool
            string daStr = row[31];
            bool   dailyAllowance;

            if (daStr.Equals("1"))
            {
                dailyAllowance = true;
            }
            else
            {
                dailyAllowance = false;
            }
            //bool dailyAllowance = Convert.ToBoolean(row[31]);
            bool   overnightAllowance;
            string onStr = row[32];

            if (onStr.Equals("1"))
            {
                overnightAllowance = true;
            }
            else
            {
                overnightAllowance = false;
            }
            //bool overnightAllowance = Convert.ToBoolean(row[32]);
            bool   barrierPayment;
            string bpStr = row[33];

            if (bpStr.Equals("1"))
            {
                barrierPayment = true;
            }
            else
            {
                barrierPayment = false;
            }
            //bool barrierPayment = Convert.ToBoolean(row[33]);
            double travelTimeToSite   = Convert.ToDouble(row[34]);
            double travelTimeFromSite = Convert.ToDouble(row[35]);
            double totalTravelTime    = Convert.ToDouble(row[36]);
            double totalTimeOnsite    = Convert.ToDouble(row[37]);
            string dailyReport        = row[38];
            string partsSupplied      = row[39];
            //Now create the serviceDayVM
            ServiceDayViewModel retval = new ServiceDayViewModel(dtTravelStart, dtArrivalOnsite, dtDeparture, dtTravelEnd, mileage, dailyAllowance, overnightAllowance, barrierPayment,
                                                                 travelTimeToSite, travelTimeFromSite, totalTravelTime, totalTimeOnsite, dailyReport, partsSupplied, dtReport, currentSubmission);

            currentSubmission.AddServiceDayViewModel(retval);
            //This doesn't need to return anything, as the day has been set on the submission.
        }
        //public static ServiceSheetViewModel createSubmissionForXml(XElement submissionXml)
        //{
        //    ServiceSheetViewModel retval = new ServiceSheetViewModel();
        //    ServiceSheet serviceSheetReturn = new ServiceSheet();
        //    serviceSheetReturn.SubmissionNumber = Int32.Parse(submissionXml.Element(SUBMISSION_NUMBER).Value);
        //    //RT 11/8/16 - Adding in the response id
        //    serviceSheetReturn.CanvasResponseId = submissionXml.Element(RESPONSE_ID).Value;
        //    //Adding response date time
        //    string responseDateStr = submissionXml.Element(RESPONSE_DATE_TIME).Value;
        //    serviceSheetReturn.DtResponse = Convert.ToDateTime(responseDateStr);
        //    //Adding device date
        //    string deviceDateStr = submissionXml.Element(DEVICE_DATE_TIME).Value;
        //    serviceSheetReturn.DtDevice = Convert.ToDateTime(deviceDateStr);
        //    //Submission version is in the form element
        //    XElement formDetailsXml = submissionXml.Element(FORM);
        //    serviceSheetReturn.SubmissionFormVersion = Int32.Parse(formDetailsXml.Element(SUBMISSION_VERSION).Value);
        //    serviceSheetReturn.Username = submissionXml.Element(USERNAME).Value;
        //    serviceSheetReturn.UserFirstName = submissionXml.Element(FIRST_NAME).Value;
        //    serviceSheetReturn.UserSurname = submissionXml.Element(SURNAME).Value;

        //    XElement sectionsXml = submissionXml.Element(SECTIONS);
        //    // Loop through the sections
        //    foreach (XElement sectionXml in sectionsXml.Elements())
        //    {
        //        string sectionName = sectionXml.Element(SECTION_NAME).Value;
        //        if (sectionName.Equals(JOB_DETAILS))
        //        {
        //            XElement screensXml = sectionXml.Element(SCREENS);
        //            XElement screenXml = screensXml.Element(SCREEN);
        //            XElement responsesXml = screenXml.Element(RESPONSES);
        //            //Parse the job details

        //            serviceSheetReturn.Customer = xmlResult(CUSTOMER, responsesXml);
        //            serviceSheetReturn.AddressLine1 = xmlResult(ADDRESS_1, responsesXml);
        //            serviceSheetReturn.AddressLine2 = xmlResult(ADDRESS_2, responsesXml);
        //            serviceSheetReturn.TownCity = xmlResult(TOWN_CITY, responsesXml);
        //            serviceSheetReturn.Postcode = xmlResult(POSTCODE, responsesXml);
        //            serviceSheetReturn.CustomerContact = xmlResult(CUSTOMER_CONTACT, responsesXml);
        //            serviceSheetReturn.CustomerPhoneNo = xmlResult(CUSTOMER_PHONE, responsesXml);
        //            serviceSheetReturn.MachineMakeModel = xmlResult(MACHINE_MAKE_MODEL, responsesXml);
        //            //RT 11/8/16 - Adding serial number
        //            serviceSheetReturn.MachineSerial = xmlResult(SERIAL_NUMBER, responsesXml);

        //            serviceSheetReturn.CncControl = xmlResult(MACHINE_CONTROL, responsesXml);
        //            string jobStartStr = xmlResult(JOB_START_DATE, responsesXml);
        //            serviceSheetReturn.DtJobStart = Convert.ToDateTime(jobStartStr);
        //            serviceSheetReturn.CustomerOrderNo = xmlResult(CUSTOMER_ORDER, responsesXml);
        //            serviceSheetReturn.MttJobNumber = xmlResult(MTT_JOB_NO, responsesXml);
        //            serviceSheetReturn.JobDescription = xmlResult(JOB_DESC, responsesXml);

        //        }
        //        else if (sectionName.Equals(TIME_SHEET))
        //        {
        //            XElement screensXml = sectionXml.Element(SCREENS);
        //            XElement screenXml = screensXml.Element(SCREEN);
        //            XElement responseGroupsXml = screenXml.Element(RESPONSE_GROUPS);
        //            //retval.ServiceTimesheets = ServiceDay.createDays(responseGroupsXml);
        //            serviceSheetReturn.ServiceDays= createDays(responseGroupsXml);
        //        }
        //        else if (sectionName.Equals(JOB_SIGNOFF))
        //        {
        //            XElement screensXml = sectionXml.Element(SCREENS);
        //            XElement screenXml = screensXml.Element(SCREEN);
        //            XElement responsesXml = screenXml.Element(RESPONSES);

        //            serviceSheetReturn.JobTotalTimeOnsite = Convert.ToDouble(xmlResult(JOB_TOTAL_TIME_ONSITE, responsesXml));
        //            serviceSheetReturn.JobTotalTravelTime = Convert.ToDouble(xmlResult(TOTAL_TRAVEL_TIME, responsesXml));

        //            //RT 13/10/16 - Mileage, daily/overnight and BP are int, although canvas returns a string like a double.  There will never be a decimal point in them
        //            double mileageRead = Convert.ToDouble(xmlResult(TOTAL_MILEAGE, responsesXml));
        //            serviceSheetReturn.JobTotalMileage = (int)mileageRead;
        //            double totalDaRead = Convert.ToDouble(xmlResult(TOTAL_DAILY_ALLOWANCES, responsesXml));
        //            serviceSheetReturn.TotalDailyAllowances = (int)totalDaRead;
        //            double totalOaRead = Convert.ToDouble(xmlResult(TOTAL_OVERNIGHT_ALLOWANCES, responsesXml));
        //            serviceSheetReturn.TotalOvernightAllowances = (int)totalOaRead;
        //            double totalBpRead = Convert.ToDouble(xmlResult(TOTAL_BARRIER_PAYMENTS, responsesXml));
        //            serviceSheetReturn.TotalBarrierPayments = (int)totalBpRead;
        //            serviceSheetReturn.JobStatus = xmlResult(JOB_STATUS, responsesXml);
        //            serviceSheetReturn.FinalJobReport = xmlResult(FINAL_JOB_REPORT, responsesXml);
        //            serviceSheetReturn.AdditionalFaults = xmlResult(ADDITIONAL_FAULTS_FOUND, responsesXml);
        //            serviceSheetReturn.QuoteRequired = Convert.ToBoolean(xmlResult(QUOTE_REQUIRED, responsesXml));
        //            serviceSheetReturn.FollowUpPartsRequired = xmlResult(FOLLOWUP_PARTS, responsesXml);
        //            serviceSheetReturn.Image1Url = xmlResult(IMAGE_1_URL, responsesXml);
        //            serviceSheetReturn.Image2Url = xmlResult(IMAGE_2_URL, responsesXml);
        //            serviceSheetReturn.Image3Url = xmlResult(IMAGE_3_URL, responsesXml);
        //            serviceSheetReturn.Image4Url = xmlResult(IMAGE_4_URL, responsesXml);
        //            serviceSheetReturn.Image5Url = xmlResult(IMAGE_5_URL, responsesXml);
        //            serviceSheetReturn.CustomerSignatureUrl = xmlResult(CUSTOMER_SIGNATURE, responsesXml);
        //            serviceSheetReturn.CustomerName = xmlResult(CUSTOMER_NAME, responsesXml);
        //            serviceSheetReturn.DtSigned = Convert.ToDateTime(xmlResult(DATE_SIGNED, responsesXml));
        //            serviceSheetReturn.MttEngSignatureUrl = xmlResult(MTT_ENG_SIGNATURE, responsesXml);
        //        }
        //        else
        //        {
        //            new Exception("Unknown Canvas Data Section");
        //        }

        //    }
        //    retval.ServiceSubmission = serviceSheetReturn;
        //    return retval;
        //}

        //RT 29/11/16 - Rewiting to use new MVVM methods
        public static List <ServiceDayViewModel> createDays(XElement allDays)
        {
            List <ServiceDayViewModel> retval = new List <ServiceDayViewModel>();

            foreach (XElement responseGroupXml in allDays.Elements())
            {
                string   dtServiceStr = xmlResult(DATE, responseGroupXml);
                DateTime dtReport     = Convert.ToDateTime(dtServiceStr);
                XElement sectionXml   = responseGroupXml.Element(SECTION);
                XElement screensXml   = sectionXml.Element(SCREENS);
                XElement screenXml    = screensXml.Element(SCREEN);
                XElement responsesXml = screenXml.Element(RESPONSES);

                string   travelStartStr    = xmlResult(TRAVEL_START, responsesXml);
                DateTime TravelStartTime   = Convert.ToDateTime(dtServiceStr + " " + travelStartStr);
                string   arrivalOnsiteStr  = xmlResult(ARRIVE_ONSITE, responsesXml);
                DateTime ArrivalOnsiteTime = Convert.ToDateTime(dtServiceStr + " " + arrivalOnsiteStr);
                string   departSiteStr     = xmlResult(DEPART_SITE, responsesXml);
                DateTime DepartureSiteTime = Convert.ToDateTime(dtServiceStr + " " + departSiteStr);
                string   travelEndStr      = xmlResult(TRAVEL_END, responsesXml);
                DateTime TravelEndTime     = Convert.ToDateTime(dtServiceStr + " " + travelEndStr);
                int      Mileage           = Convert.ToInt32(xmlResult(MILEAGE, responsesXml));
                string   currentXmlResult  = xmlResult(DAILY_ALLOWANCE, responsesXml);
                int      DailyAllowance    = Convert.ToInt32(currentXmlResult);
                bool     da;
                if (DailyAllowance == 1)
                {
                    da = true;
                }
                else
                {
                    da = false;
                }
                currentXmlResult = xmlResult(OVERNIGHT_ALLOWANCE, responsesXml);
                int  OvernightAllowance = Convert.ToInt32(currentXmlResult);
                bool oN;
                if (OvernightAllowance == 1)
                {
                    oN = true;
                }
                else
                {
                    oN = false;
                }
                currentXmlResult = xmlResult(BARRIER_PAYMENT, responsesXml);
                int  BarrierPayment = Convert.ToInt32(currentXmlResult);
                bool bP;
                if (BarrierPayment == 1)
                {
                    bP = true;
                }
                else
                {
                    bP = false;
                }
                double TravelToSiteTime   = Convert.ToDouble(xmlResult(TRAVEL_TO_SITE, responsesXml));
                double TravelFromSiteTime = Convert.ToDouble(xmlResult(TRAVEL_FROM_SITE, responsesXml));
                double TotalTravelTime    = Convert.ToDouble(xmlResult(TOTAL_TRAVEL, responsesXml));
                double TotalOnsiteTime    = Convert.ToDouble(xmlResult(TOTAL_TIME_ONSITE, responsesXml));
                string DailyReport        = xmlResult(DAILY_REPORT, responsesXml);
                string PartsSuppliedToday = xmlResult(PARTS_SUPPLIED, responsesXml);

                ServiceDayViewModel sd = new ServiceDayViewModel(TravelStartTime, ArrivalOnsiteTime, DepartureSiteTime, TravelEndTime, Mileage, da, oN,
                                                                 bP, TravelToSiteTime, TravelFromSiteTime, TotalTravelTime, TotalOnsiteTime, DailyReport, PartsSuppliedToday, dtReport, null);

                retval.Add(sd);
            }

            //Need to sort the observable collection
            List <ServiceDayViewModel> sortedDays = new List <ServiceDayViewModel>(retval.OrderBy(a => a.DtReport));

            retval = sortedDays;

            return(retval);
        }
Exemplo n.º 15
0
        private double calculateStandardHours(ServiceDayViewModel currentDay)
        {
            //Monday - Thursday are the first 8 hours onsite.
            //Friday is the first 6
            //Weekends and Bank holidays are all

            double retval = 0;
            double hoursOnsite = currentDay.TotalOnsiteTime;

            double standardHoursLimitNormal = 8;
            double standardHoursFriday = 6;

            DayOfWeek day = currentDay.DtReport.DayOfWeek;
            if ((DayOfWeek.Monday <= day) && (day <= DayOfWeek.Thursday))
            {
                if (hoursOnsite > standardHoursLimitNormal)
                {
                    retval = standardHoursLimitNormal;
                }
                else
                {
                    retval = hoursOnsite;
                }
            }

            if (day == DayOfWeek.Friday)
            {
                if (hoursOnsite > standardHoursFriday)
                {
                    retval = standardHoursFriday;
                }
                else
                {
                    retval = hoursOnsite;
                }
            }

            if ((day == DayOfWeek.Saturday) || (day == DayOfWeek.Sunday))
            {
                retval = 0;
            }

            return retval;
        }