private void addItem_Click(object sender, EventArgs e)
        {
            InvoiceRouteInfo routeinfo = new InvoiceRouteInfo(viewinvoices[listAllItems.SelectedIndex].number, viewroute.number, currentnumberofstops);
            mysql_invoiceroutes.AddRouteInfo(routeinfo);
            for (int i = 0; i < viewinvoices.Count; i++)
            {
                if (viewinvoices[i].addr1 == viewinvoices[listAllItems.SelectedIndex].addr1 && viewinvoices[i].city == viewinvoices[listAllItems.SelectedIndex].city&&routeinfo.invoicenumber!=viewinvoices[i].number)
                {
                    currentnumberofstops++;
                    InvoiceRouteInfo routeinfo2 = new InvoiceRouteInfo(viewinvoices[i].number, viewroute.number, currentnumberofstops);
                    mysql_invoiceroutes.AddRouteInfo(routeinfo2);
                }

            }
                RefreshData(true, 0);
        }
Beispiel #2
0
        public RouteInfo GetRouteInfo(InvoiceRouteInfo invoicerouteinfo)
        {
            try
            {
                MySqlConnection theconnection = Connect();

                MySqlDataReader rdr = Select("SELECT * FROM delivery_route_data WHERE DR_ROUTE_NUMBER=" + invoicerouteinfo.routenumber.ToString() + " ;", theconnection);
                rdr.Read();
                    RouteInfo toinsert = new RouteInfo((int)rdr[2], DateTime.Parse((String)rdr[0]), (int)rdr[1], (int)rdr[3]);

                Disconnect();
                return (toinsert);
            }
            catch
            {
                Disconnect();
                return null;
            }
        }
        void bw3_RunWorkerCompleted(object sender,
                                   RunWorkerCompletedEventArgs e)
        {
            DirectionArgs args = (DirectionArgs)e.Result;
            List<int> newsequence = new List<int>();
            //int index = 1;
            /*if ((args.address.Count - 2) != scheduledinvoices.Count)
            {
                newsequence.Add(0);
                for (int i = 1; i < args.directiondata.locationSequence.Count-1; i++)
                {
                    for (int k = 1; k < args.directiondata.locationSequence.Count - 1; k++)
                    {
                        if (args.directiondata.locationSequence[k] == i)
                        {
                            //newsequence.RemoveAt(i);
                            List<int> addsequence = new List<int>();
                            for (int j = 0; j < scheduledinvoices.Count; j++)
                            {
                                if (args.latitude[k] == scheduledinvoices[j].latitude && args.longitude[k] == scheduledinvoices[j].longitude)
                                {
                                    addsequence.Add(index);
                                    index++;
                                    //newsequence.Insert(i, j + 1);

                                }
                            }
                            newsequence.AddRange(addsequence);
                        }
                    }
                }
                newsequence.Add(newsequence.Count);
                args.directiondata.locationSequence = newsequence;
            }*/

            for (int i = 0; i < scheduledinvoices.Count; i++)
            {

                for (int k = 0; k < routes.Count; k++)
                {
                    if (routes[k].number == viewroute.number)
                    {
                        for (int j = 0; j < routes[k].invoicerouteinfo.Count; j++)
                        {
                            if (routes[k].invoicerouteinfo[j].invoicenumber == scheduledinvoices[i].number)
                            {
                                mysql_invoiceroutes.DeleteRouteInfo(routes[k].invoicerouteinfo[j],false);
                                break;

                            }
                        }
                        break;
                    }

                }

            }
            for (int i = 0; i < scheduledinvoices.Count; i++)
            {
                int index2=0;
                for (int j = 1; j < args.directiondata.locationSequence.Count-1; j++)
                {
                    if (args.directiondata.locationSequence[j ]-1  == i)
                    {
                        index2 = j-1;
                    }
                }
                InvoiceRouteInfo routeinfo = new InvoiceRouteInfo(scheduledinvoices[i].number, viewroute.number, index2);//args.directiondata.locationSequence[i + 1] - 1
                mysql_invoiceroutes.AddRouteInfo(routeinfo);
            }
            if (GlobalVar.authenticated == true)
            {
                optimizeRoute.Enabled = true;
            }
                optimizeRoute.Text = "Find Optimal Route";
            RefreshData(false,0);
        }
Beispiel #4
0
        public InvoiceRouteInfo GetRouteInfo(int ID)
        {
            try
            {
                MySqlConnection theconnection = Connect();

                MySqlDataReader rdr = Select("SELECT * FROM invoice_route_data WHERE IR_INV_NUMBER=" + ID+ " ;", theconnection);
                rdr.Read();

                    InvoiceRouteInfo input = new InvoiceRouteInfo((int)rdr[0], (int)rdr[1], (int)rdr[2]);

                Disconnect();

                return (input);
            }
            catch
            {

                Disconnect();
                return null;
            }
        }
Beispiel #5
0
        public bool MoveUp(InvoiceRouteInfo routeinfo)
        {
            try
            {
                MySqlConnection theconnection = Connect();
                string updatequery = "UPDATE invoice_route_data SET `IR_ROUTE_STOP`=`IR_ROUTE_STOP`+1 WHERE `IR_ROUTE_NUMBER`=" + routeinfo.routenumber + " AND `IR_ROUTE_STOP`=" + (routeinfo.stop-1)+ ";";
                Update(updatequery, theconnection);
                updatequery = "UPDATE invoice_route_data SET `IR_ROUTE_STOP`=`IR_ROUTE_STOP`-1 WHERE `IR_ROUTE_NUMBER`=" + routeinfo.routenumber + " AND `IR_INV_NUMBER`=" + routeinfo.invoicenumber+ ";";
                Update(updatequery, theconnection);
                Disconnect();
                return true;
            }
            catch
            {

                Disconnect();
                return false;
            }
        }
Beispiel #6
0
        public List<InvoiceRouteInfo> GetRouteInfo(RouteInfo route)
        {
            try
            {
                MySqlConnection theconnection=Connect();

                MySqlDataReader rdr = Select("SELECT * FROM invoice_route_data WHERE IR_ROUTE_NUMBER=" + route.number + " ;", theconnection);
                List<InvoiceRouteInfo> routeinfo= new List<InvoiceRouteInfo>();
                while (rdr.Read())
                {
                    InvoiceRouteInfo input = new InvoiceRouteInfo((int)rdr[0], (int)rdr[1], (int)rdr[2]);
                    routeinfo.Add(input);
                }
                        Disconnect();

                return (routeinfo);
            }
            catch
            {

                Disconnect();
                return null;
            }
        }
Beispiel #7
0
 public bool DeleteRouteInfo(InvoiceRouteInfo routeinfo, bool flag)
 {
     try
     {
         MySqlConnection theconnection = Connect();
         string deletequery = "DELETE FROM invoice_route_data WHERE IR_INV_NUMBER=" + routeinfo.invoicenumber.ToString() +";";
         Delete(deletequery, theconnection);
         //UPDATE invoice_route_data SET `IR_ROUTE_STOP`=`IR_ROUTE_STOP`-1 WHERE `IR_ROUTE_NUMBER`=29 AND `IR_ROUTE_STOP`>-3;
         if (flag == true)
         {
             string updatequery = "UPDATE invoice_route_data SET `IR_ROUTE_STOP`=`IR_ROUTE_STOP`-1 WHERE `IR_ROUTE_NUMBER`=" + routeinfo.routenumber + " AND `IR_ROUTE_STOP`>" + routeinfo.stop + ";";
             Update(updatequery, theconnection);
         }
         Disconnect();
         return true;
     }
     catch
     {
         Disconnect();
         return false;
     }
 }
Beispiel #8
0
        public bool AddRouteInfo(InvoiceRouteInfo routeinfo)
        {
            try
            {

                MySqlConnection theconnection = Connect();
                DeleteRouteInfo(routeinfo, false);
                string insertquery = "INSERT INTO invoice_route_data (`IR_INV_NUMBER`, `IR_ROUTE_NUMBER`, `IR_ROUTE_STOP`) VALUES (" + routeinfo.invoicenumber + ", " + routeinfo.routenumber + ", "+routeinfo.stop+");";
                Insert(insertquery, theconnection);
                Disconnect();
                return true;
            }
            catch
            {
                Disconnect();
                return false;
            }
        }
        void bw1_RunWorkerCompleted(object sender,
                           RunWorkerCompletedEventArgs e)
        {
            try
            {
                OptimizeArgs args = (OptimizeArgs)e.Result;
                if (args.output.IndexOf("Default routes length violation:") > 0)
                {
                    Regex regex = new Regex(@"Default routes length violation: (\d*)");
                    MatchCollection result = regex.Matches(args.output);
                    int minimumdistance = 0;
                    for (int i = 0; i < result.Count; i++)
                    {
                        int value = Int32.Parse(result[i].Groups[1].Value) + 1;
                        if (value > minimumdistance)
                        {
                            minimumdistance = value;
                        }
                    }
                    listRoutes.Enabled = true;
                    listDrivers.Enabled = true;
                    checkBox1.Enabled = true;
                    buttonOptimization.Enabled = true;
                    buttonOptimization.Text = "Run Optimization";
                    button1.Enabled = true;
                    currentstatus = "";
                    if (checkBox1.Checked == true)
                    {
                        currentstatus = "Route length violation: At least one delivery point requires a minimimum distance contraint of " + minimumdistance + " miles.";
                    }
                    else
                    {

                        currentstatus = "Route time violation: At least one delivery point requires a minimimum driving time of " + DataFormat.FormatTimeToString((long)minimumdistance);
                    }
                    optimizationrunning = false;
                    return;
                }
                else if (args.output.IndexOf("Solution for problem input") > 0)
                {

                    Regex regex = new Regex(@"Route \d\d\d\d\(routenum=(\d)\).*\n(.*)\n");
                    MatchCollection result = regex.Matches(args.output);

                    List<List<int>> order = new List<List<int>>();
                    for (int i = 0; i < result.Count; i++)
                    {
                        order.Add(new List<int>());
                        string orderstring = result[i].Groups[2].Value;
                        string[] array = orderstring.Split('-');
                        for (int j = 0; j < array.Length; j++)
                        {
                            order[i].Add(Int32.Parse(array[j]));
                        }

                    }
                    optimizedroutes = new List<List<InvoiceRouteInfo>>();
                    listRoutes.Items.Clear();
                    listDrivers.Items.Clear();

                    for (int i = 0; i < order.Count; i++)
                    {
                        optimizedroutes.Add(new List<InvoiceRouteInfo>());
                        listRoutes.Items.Add("Route " + (i + 1));
                        int index = 0;
                        for (int j = 1; j < (order[i].Count - 1); j++)
                        {

                            for (int k = 0; k < viewinvoices.Count; k++)
                            {
                                if (viewinvoices[k].latitude == args.latitudein[order[i][j] - 2] && viewinvoices[k].longitude == args.longitudein[order[i][j] - 2])
                                {
                                    InvoiceRouteInfo toinsert = new InvoiceRouteInfo(viewinvoices[k].number, i, index);
                                    index++;
                                    optimizedroutes[i].Add(toinsert);
                                }
                            }
                        }
                    }
                    button1.Enabled = true;
                    _bw3 = new BackgroundWorker
                    {
                        WorkerReportsProgress = true,
                        WorkerSupportsCancellation = true
                    };
                    _bw3.DoWork += bw3_DoWork;

                    _bw3.RunWorkerCompleted += bw3_RunWorkerCompleted;
                    _bw3.RunWorkerAsync(order);
                    return;
                }
            }
            catch {
                listRoutes.Enabled = true;
                listDrivers.Enabled = true;
                checkBox1.Enabled = true;
                buttonOptimization.Enabled = true;
                buttonOptimization.Text = "Run Optimization";
                currentstatus = "";
                optimizationrunning = false;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //DialogResult result = MessageBox.Show("Saving changes will remove all configured routes for the current day and replace them with optimized routes.  Are you sure?", "Warning", MessageBoxButtons.YesNo);
                //if (result == DialogResult.Yes)
                //{

                   // for (int i = 0; i < driverassignments.Count; i++)
                    //{
                     //   mysql_routes.DeleteRouteInfo(companydrivers[driverassignments[i]].number, viewdate);
                    //}
                    for (int i = 0; i < driverassignments.Count; i++)
                    {
                        RouteInfo toadd = new RouteInfo(0, viewdate, companydrivers[driverassignments[i]].number, distances[i]);
                        mysql_routes.AddRouteInfo(toadd);
                    }
                    List<RouteInfo> currentroutes = mysql_routes.GetRouteInfo(viewdate);

                    for (int i = 0; i < driverassignments.Count; i++)
                    {
                        int routenumber = 0;
                        for (int j = 0; j < currentroutes.Count; j++)
                        {
                            if (currentroutes[j].drivernumber == companydrivers[driverassignments[i]].number)
                            {
                                routenumber = currentroutes[j].number;
                            }
                        }
                        for (int j = 0; j < optimizedroutes[i].Count; j++)
                        {
                            optimizedroutes[i][j].routenumber = routenumber;
                            InvoiceRouteInfo toadd = new InvoiceRouteInfo(optimizedroutes[i][j].invoicenumber, optimizedroutes[i][j].routenumber, optimizedroutes[i][j].stop);
                            mysql_invoiceroutes.AddRouteInfo(toadd);
                        }

                    }
                    DeliverySchedule deliveryschedule = new DeliverySchedule();
                    deliveryschedule.SetDate(viewdate,0);
                    deliveryschedule.Show();
                    this.Close();
                }
            //}
            catch { }
        }