private void buttonPrint_Click(object sender, EventArgs e)
        {
            if (mapdrawn == true)
            {
                int displaycount = 0;
                int[] totals = new int[8];
            StreamWriter sw = new StreamWriter("toprint.html", false);
            sw.WriteLine("<body style=\"font-family:calibri\">");
            sw.WriteLine("<div style=\"width:21.59cm\">");
            sw.WriteLine("<strong>Scheduled Deliveries for "+viewdate.Month+"/"+viewdate.Day+"/"+viewdate.Year+":<br></strong>");
            sw.WriteLine("<TABLE border=1>");
            sw.WriteLine("<TR>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Driver Name");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Route Length");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Route Time");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Number of Stops");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Driver Cost");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Fuel Surcharge");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Maitenance Surcharge");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Total Cost");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Value of Invoices");
            sw.WriteLine("</TD>");
            sw.WriteLine("<TD>");
            sw.WriteLine("Cost Percentage");
            sw.WriteLine("</TD>");
            sw.WriteLine("</TR>");
            for (int i = 0; i < scheduleddrivers.Count; i++)
            {
                sw.WriteLine("<TR>");
                int index=0;
                for(int j=0;j<routes.Count;j++)
                {
                    if(scheduleddrivers[i].number==routes[j].drivernumber)
                    {
                        index=j;
                    }

                }
                int value=0;
                for(int j=0;j<routes[index].invoicerouteinfo.Count;j++)
                {
                    int index2=0;
                    for(int k=0;k<viewinvoices.Count;k++)
                    {
                        if(viewinvoices[k].number==routes[index].invoicerouteinfo[j].invoicenumber)
                        {index2 = k;}
                    }
                    value+=viewinvoices[index2].value;
                }

                sw.WriteLine("<TD>");
                sw.Write(scheduleddrivers[i].name);
                if (displayroute[i] == true)
                {
                    if (displaycount == 0)
                    {
                        sw.Write(" - Blue");
                    }
                    if (displaycount == 1)
                    {
                        sw.Write(" - Green");
                    }
                    if (displaycount == 2)
                    {
                        sw.Write(" - Orange");
                    }
                    if (displaycount == 3)
                    {
                        sw.Write(" - Purple");
                    }
                    if (displaycount == 4)
                    {
                        sw.Write(" - White");
                    }
                    if (displaycount == 5)
                    {
                        sw.Write(" - Yellow");
                    }
                    if (displaycount == 6)
                    {
                        sw.Write(" - Pink");
                    }
                    if (displaycount == 7)
                    {
                        sw.Write(" - Black");
                    }
                    if (displaycount == 8)
                    {
                        sw.Write(" - Brown");
                    }
                    if (displaycount == 9)
                    {
                        sw.Write(" - Red");
                    }
                    if (displaycount == 10)
                    {
                        sw.Write(" - Lime");
                    }
                    if (displaycount == 11)
                    {
                        sw.Write(" - Dark Blue");
                    }

                    displaycount++;
                }
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                sw.WriteLine(totalmilesindividual[i]+" Mi");
                totals[0]+=totalmilesindividual[i];
                sw.WriteLine("<TD>");
                sw.WriteLine(((double)totaltimeindividual[i]/(double)3600).ToString("0.00"));
                totals[1] += totaltimeindividual[i];
                sw.WriteLine(" Hours");

                sw.WriteLine("</TD>");
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                sw.WriteLine(individualstopcounter[i]);
                totals[2]+=individualstopcounter[i];
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                sw.WriteLine(DataFormat.FormatMoneyToString((int)drivercost[i]));
                totals[3] += (int)drivercost[i];
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                sw.WriteLine(DataFormat.FormatMoneyToString((int)milecost[i]));
                totals[4] += (int)milecost[i];
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                sw.WriteLine(DataFormat.FormatMoneyToString((int)maitenancecost[i]));
                totals[5] += (int)maitenancecost[i];
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                sw.WriteLine(DataFormat.FormatMoneyToString(driverestimatedcost[i]));
                totals[6]+=driverestimatedcost[i];
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                sw.WriteLine(DataFormat.FormatMoneyToString(value));
                totals[7] += value;
                sw.WriteLine("</TD>");
                sw.WriteLine("<TD>");
                double percent = driverestimatedcost[i] / (double)value;
                sw.WriteLine(percent.ToString("0.00%"));
                sw.WriteLine("</TD>");
                sw.WriteLine("</TR>");
            }
                sw.Write("<b><TR>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine("Totals");
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine(totals[0] + " Mi");
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine(((double)totals[1]/(double)3600).ToString("0.00"));
                sw.WriteLine(" Hours");
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine(totals[2]);
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine(DataFormat.FormatMoneyToString(totals[3]));
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine(DataFormat.FormatMoneyToString(totals[4]));
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine(DataFormat.FormatMoneyToString(totals[5]));
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.WriteLine(DataFormat.FormatMoneyToString(totals[6]));
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                sw.Write(DataFormat.FormatMoneyToString(totals[7]));
                sw.WriteLine("</b></TD>");
                sw.WriteLine("<TD><b>");
                double percent2 = (double)totals[6] / (double)totals[7];
                sw.WriteLine(percent2.ToString("0.00%"));
                sw.WriteLine("</b></TD>");

                sw.WriteLine("</TR>");
                sw.WriteLine("</TABLE></b>");
                sw.WriteLine("Display Delivery Map: <input type=\"checkbox\" checked name=\"mapcheck\" onClick=\"toggle(this)\" /><br>");
                StreamReader sr = new StreamReader("map.html");

                String mapstring = sr.ReadToEnd();
                mapstring = mapstring.Replace("<div id='map' style='width:420px; height:668px;'></div>", "<table><tr><td><div id='map' style='float:left; width:420px; height:500px;'></div></td><td><div id='map2' style='float:left; width:420px; height:500px;'></div></tr></td></table>");
                sw.Write(mapstring);
                mapstring=mapstring.Replace("map.", "map2.");
                mapstring=mapstring.Replace("map2.bestFit()", "center=new MQA.LatLng(41.859334,-87.610474);map2.setCenter(center);map2.setZoomLevel(7);");
                mapstring = mapstring.Replace("window.map = new MQA.TileMap(document.getElementById('map')", "window.map2 = new MQA.TileMap(document.getElementById('map2')");
                //mapstring = mapstring.Replace("<div id='map' style='float:left; width:420px; height:600px;'></div>", "<div id='map2' style='float:left; width:420px; height:600px;'></div>");
                sw.WriteLine(mapstring);
                sw.WriteLine("<script>");

                sw.WriteLine("function toggle(switchElement) {");
                sw.WriteLine("if (switchElement.checked == true)");
                sw.WriteLine("{document.getElementById('map').style.visibility = 'visible';document.getElementById('map2').style.visibility = 'visible';}");
                sw.WriteLine("else");
                sw.WriteLine("{document.getElementById('map').style.visibility = 'hidden';document.getElementById('map2').style.visibility = 'hidden';}");
                sw.WriteLine("}");

                sw.WriteLine("</script>");
                sr.Close();
                sw.Close();
                Print printwindow = new Print();
                printwindow.SetDate(viewdate);
                printwindow.Show();
                this.Close();
            }
        }
        private void buttonPrint_Click(object sender, EventArgs e)
        {
            StreamWriter sw= new StreamWriter("toprint.html", false);
            StreamReader sr=new StreamReader("map.html");
            sw.WriteLine("<style>");
            sw.WriteLine(".break { page-break-before: always; }");
            sw.WriteLine("</style>");
            sw.WriteLine("<body style=\"font-family:calibri\">");
            sw.WriteLine("<div style=\"width:21.59cm\">");
            sw.WriteLine("Driver: "+driver.name+"<br>");
            sw.WriteLine("Number of Stops: "+stopcounter+"<br>");
            sw.WriteLine("Distance: "+textTotalMiles.Text+"<br>");

            sw.WriteLine("Route Time: " + textTotalTime.Text + "<br>");
            sw.WriteLine("<head>");
            sw.WriteLine("<br><strong>Scheduled Deliveries:<br></strong>");
            sw.WriteLine("<TABLE border=1>");
            stopcounter = 1;

            for (int i = 0; i < scheduledinvoices.Count; i++)
            {
                sw.WriteLine("<TR>");

                    for (int j = 0; j < scheduledinvoices.Count; j++)
                    {
                        if (i == (scheduledinvoicesorder[j]))
                        {
                            int index = -1;
                            for (int k = 0; k < scheduledinvoices.Count; k++)
                            {
                                if ((scheduledinvoicesorder[j] - 1) == scheduledinvoicesorder[k])
                                {
                                    index = k;
                                }
                            }
                            if (index != -1)
                            {
                                if (scheduledinvoices[index].latitude == scheduledinvoices[j].latitude && scheduledinvoices[index].longitude == scheduledinvoices[j].longitude)
                                {

                                }
                                else
                                {
                                    stopcounter++;
                                }
                            }
                            else { counter++; }
                            sw.WriteLine("<TD>");
                            sw.WriteLine(stopcounter);
                            sw.WriteLine("</TD>");
                            sw.WriteLine("<TD>");
                            sw.WriteLine(scheduledinvoices[j].number);
                            sw.WriteLine("</TD>");
                            sw.WriteLine("<TD>");
                            sw.WriteLine(DataFormat.FormatMoneyToString(scheduledinvoices[j].value));
                            sw.WriteLine("</TD>");
                            sw.WriteLine("<TD>");
                            sw.WriteLine(scheduledinvoices[j].addr1+", "+scheduledinvoices[j].city+", "+scheduledinvoices[j].state+"  "+scheduledinvoices[j].zip);
                            sw.WriteLine("</TD>");
                        }
                    }

                sw.WriteLine("</TR>");
            }
            sw.WriteLine("</TABLE>");
            sw.WriteLine("<br><br>");
            String mapstring = sr.ReadToEnd();
            sw.Write(mapstring);
                sw.Write("</body>");
            sr.Close();
            sw.Close();
            Print printwindow = new Print();
            printwindow.SetDate(viewdate);
            printwindow.Show();
            this.Close();
        }