Ejemplo n.º 1
0
        public void insertTrip(IKmlFolder trip, String tripNumber, TripPool t_pool)
        {
            //This will add a trip to the dataTable
            addToUndoTypeTable("Insert");
            undoTable.Rows.Add(tripNumber, "");
            DataRow row = NewRowDataTableCustom();

            row[0] = tripNumber;
            row[1] = databaseViewer.Rows[0][1];
            //The trip count will be set with the resetTripCount
            row[3] = databaseViewer.Rows[0][3];
            row[4] = databaseViewer.Rows[0][4];
            row[5] = databaseViewer.Rows[0][5];
            row[6] = databaseViewer.Rows[0][6];
            IKmlObjectList points      = trip.getFeatures().getChildNodes();
            IKmlPlacemark  startPoint  = (IKmlPlacemark)points.item(0);
            IKmlPlacemark  finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1);

            row[12] = Module.getCoordinates(startPoint)["lon"].ToString();
            row[13] = Module.getCoordinates(startPoint)["lat"].ToString();
            row[14] = Module.getCoordinates(finishPoint)["lon"].ToString();
            row[15] = Module.getCoordinates(finishPoint)["lat"].ToString();
            databaseViewer.Rows.InsertAt(row, Convert.ToInt32(tripNumber) - 1);
            DataRow newRowKML = t_pool.NewRowDataTableCustom();

            newRowKML = copyDataRowContents(row, newRowKML);
            t_pool.getTripDetails().Rows.InsertAt(newRowKML, Convert.ToInt32(tripNumber) - 1);
            completeMissingData(t_pool);
            t_pool.resetTripCount();
            resetTripCountForDay();
        }
Ejemplo n.º 2
0
        public void splitTrip(String day, String trip, IKmlPlacemark s_point, IKmlPlacemark f_point, TripPool t_pool)
        {
            //           MessageBox.Show(tripData.getFeatures().getChildNodes().getLength().ToString() + " " + point.getName() +"    "+point.getId());


            Module testModule = new Module();

            //This function will split a trip in the text file
            //First we'll need to find the day we're talking about
            for (int i = 0; i < databaseViewer.Rows.Count; ++i)
            {
                //once we have found the right day we'll go and find the right trip
                if (databaseViewer.Rows[i]["KMLTrip"].ToString() == trip)
                {
                    //Once we have found the trip we'll first have to add it to the Undo Table
                    //First we'll add the entry of what type of action was performed.
                    addToUndoTypeTable("Split");
                    addToUndotable(databaseViewer.Rows[i]);      // So we've added the whole row back into place.
                    //once we have found our trip record we'll make the further modifications
                    //Now the split point of the trip will become the finishing point of the original trip. Before we insert the new values, we should store the other values first
                    String oldFinishTime = databaseViewer.Rows[i]["Finish"].ToString();
                    String oldFinishLat  = databaseViewer.Rows[i]["fLatitude"].ToString();
                    String oldFinishLong = databaseViewer.Rows[i]["fLongitude"].ToString();
                    //Now that we've stored these values, we can safely replace these fields with the new data.
                    databaseViewer.Rows[i]["Finish"] = f_point.getName();
                    t_pool.getTripDetails().Rows[i]["Finish Time"] = f_point.getName();
                    Hashtable coords = Module.getCoordinates(f_point);
                    databaseViewer.Rows[i]["fLatitude"]  = coords["lat"];
                    databaseViewer.Rows[i]["fLongitude"] = coords["lon"];
                    t_pool.getTripDetails().Rows[i]["FinishLat"]  = coords["lat"];
                    t_pool.getTripDetails().Rows[i]["FinishLong"] = coords["long"];
                    t_pool.resetTripData("Trip_" + trip);
                    //By this time the original trip would have been modified correctly. Now we need to create a new trip and set it's fields correctly
                    //Now we need to get the details of the next point
                    //                       point = getNextPoint(tripData, point); //This should give us the next point after the split point.
                    coords = Module.getCoordinates(s_point);
                    //Now once we have all the information we'll create a new record in the table
                    DataRow newRow    = NewRowDataTableCustom();
                    DataRow newRowKML = t_pool.NewRowDataTableCustom();
                    //Most of the information will be the same as the current record
                    newRow["Day"]       = databaseViewer.Rows[i]["Day"];
                    newRow["Household"] = databaseViewer.Rows[i]["HouseHold"];
                    newRow["Person"]    = databaseViewer.Rows[i]["Person"];
                    newRow["Date"]      = databaseViewer.Rows[i]["Date"];
                    newRow["Weekday"]   = databaseViewer.Rows[i]["Weekday"];
                    newRow["Remain"]    = databaseViewer.Rows[i]["Remain"];
                    //Now we'll add the new data
                    newRow["KMLTrip"]    = (Convert.ToInt32(databaseViewer.Rows[i]["KMLTrip"]) + 1).ToString();
                    newRow["Start"]      = s_point.getName();
                    newRow["Finish"]     = oldFinishTime;
                    newRow["sLongitude"] = coords["lon"];
                    newRow["sLatitude"]  = coords["lat"];
                    newRow["fLongitude"] = oldFinishLong;
                    newRow["fLatitude"]  = oldFinishLat;
                    //Now we'll add this row in the dataTable
                    databaseViewer.Rows.InsertAt(newRow, i + 1);
                    newRowKML = copyDataRowContents(newRow, newRowKML);
                    t_pool.getTripDetails().Rows.InsertAt(newRowKML, i + 1);
                    //Now once everything is done, we'll reset the tripCount for that day
                    resetTripCountForDay();
                    t_pool.resetTripCount();
                    t_pool.resetTripData("Trip_" + (Convert.ToInt32(trip) + 1).ToString());
                    completeMissingData(t_pool);
                }
            }
        }
Ejemplo n.º 3
0
        public void undoTripAction(TripPool t_pool)
        {
            //First we'll see what the last type of action was.
            String lastAction = undoTypeTable.Rows[0]["Action Type"].ToString(); // so this will bring down what the last action was.

            //We should then delete this action from the undoTypeTable
            undoTypeTable.Rows[0].Delete(); // this will delete the entry from the undoTable
            switch (lastAction)
            {
            case "Insert":
                //When the last operation was an insert
                String tripNumberInsert = undoTable.Rows[0][0].ToString();
                //Find this trip in the databaseViewer
                for (int i = 0; i != databaseViewer.Rows.Count; ++i)
                {
                    if (databaseViewer.Rows[i]["KMLTrip"].Equals(tripNumberInsert))
                    {
                        databaseViewer.Rows[i].Delete();
                        //t_pool.getTripDetails().Rows[i].Delete();
                        t_pool.resetTripCount();
                        resetTripCountForDay();
                    }
                }
                break;

            case "Delete":
                //If the last action was a delete action
                //Then we simply have to re-instate the row in the UndoTable and place it back in the databaseViewer Table
                //But before that we also need to find where exactly the row goes.
                //We will do that by finding the day and trip number of the deleted row.And then inserting the row at that position.
                String day  = undoTable.Rows[0]["Day"].ToString();
                String trip = undoTable.Rows[0]["KMLTrip"].ToString();
                //Once we have the day and trip information we will find the right place to add the row back in the database.
                if (databaseViewer.Rows.Count == 0)
                {
                    DataRow newRow = NewRowDataTableCustom();
                    newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                    databaseViewer.Rows.InsertAt(newRow, 0);
                    DataRow newRowKML = t_pool.NewRowDataTableCustom();
                    newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                    t_pool.getTripDetails().Rows.InsertAt(newRowKML, 0);
                    undoTable.Rows[0].Delete();
                    resetTripCountForDay();
                    t_pool.resetTripCount();
                    break;
                }
                else if (databaseViewer.Rows.Count < Convert.ToInt32(trip))
                {
                    DataRow newRow = NewRowDataTableCustom();
                    newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                    databaseViewer.Rows.InsertAt(newRow, databaseViewer.Rows.Count);
                    DataRow newRowKML = t_pool.NewRowDataTableCustom();
                    newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                    t_pool.getTripDetails().Rows.InsertAt(newRowKML, databaseViewer.Rows.Count);
                    undoTable.Rows[0].Delete();
                    resetTripCountForDay();
                    t_pool.resetTripCount();
                    break;
                }
                else
                {
                    for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                    {
                        if (Convert.ToInt32(databaseViewer.Rows[i]["KMLTrip"].ToString()) == Convert.ToInt32(trip))
                        {
                            //Now we'll add our trip at this location.
                            //Simply copying a row from one table to another table doesn't work. So we'll create a new DataRow to add
                            DataRow newRow = NewRowDataTableCustom();
                            newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                            databaseViewer.Rows.InsertAt(newRow, i);
                            DataRow newRowKML = t_pool.NewRowDataTableCustom();
                            newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                            t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                            resetTripCountForDay();
                            t_pool.resetTripCount();
                            // One the row has been safely added back to the database, it is safe to remove it from the undo Table
                            undoTable.Rows[0].Delete();
                            break;
                        }
                    }
                }
                break;

            case "Join":
                //If the last action was a join action
                //That means we have to re-instate the two rows that are in the undo table in their respective order.
                //First we'll find the current trip1 and delete it.
                trip = undoTable.Rows[0]["KMLTrip"].ToString();
                if (databaseViewer.Rows.Count == 0)
                {
                    DataRow newRow = NewRowDataTableCustom();
                    newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                    databaseViewer.Rows.InsertAt(newRow, 0);
                    t_pool.getTripDetails().Rows.InsertAt(newRow, 0);
                    resetTripCountForDay();
                    t_pool.resetTripCount();
                    undoTable.Rows[0].Delete();
                    break;
                }
                else if (databaseViewer.Rows.Count < Convert.ToInt32(trip))
                {
                    DataRow newRow = NewRowDataTableCustom();
                    newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                    databaseViewer.Rows.InsertAt(newRow, databaseViewer.Rows.Count);
                    t_pool.getTripDetails().Rows.InsertAt(newRow, databaseViewer.Rows.Count);
                    resetTripCountForDay();
                    t_pool.resetTripCount();
                    undoTable.Rows[0].Delete();
                    break;
                }
                else
                {
                    for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                    {
                        if (databaseViewer.Rows[i]["KMLTrip"].ToString() == trip)
                        {
                            DataRow newRow = NewRowDataTableCustom();
                            newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                            databaseViewer.Rows.InsertAt(newRow, i);
                            DataRow newRowKML = t_pool.NewRowDataTableCustom();
                            newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                            t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                            if (databaseViewer.Rows.Count > 1)
                            {
                                databaseViewer.Rows[i + 1].Delete();
                                t_pool.getTripDetails().Rows[i + 1].Delete();
                            }
                            undoTable.Rows[0].Delete();
                            resetTripCountForDay();
                            t_pool.resetTripCount();
                            break;
                        }
                    }
                }
                trip = undoTable.Rows[0]["KMLTrip"].ToString();
                if (databaseViewer.Rows.Count < Convert.ToInt32(trip))
                {
                    DataRow newRow = NewRowDataTableCustom();
                    newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                    databaseViewer.Rows.InsertAt(newRow, databaseViewer.Rows.Count);
                    DataRow newRowKML = t_pool.NewRowDataTableCustom();
                    newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                    t_pool.getTripDetails().Rows.InsertAt(newRowKML, databaseViewer.Rows.Count);
                    resetTripCountForDay();
                    t_pool.resetTripCount();
                    undoTable.Rows[0].Delete();
                    break;
                }
                else
                {
                    for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                    {
                        if (databaseViewer.Rows[i]["KMLTrip"].ToString() == trip)
                        {
                            DataRow newRow = NewRowDataTableCustom();
                            newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                            databaseViewer.Rows.InsertAt(newRow, i);
                            DataRow newRowKML = t_pool.NewRowDataTableCustom();
                            newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                            t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                            resetTripCountForDay();
                            t_pool.resetTripCount();
                            undoTable.Rows[0].Delete();
                            break;
                        }
                    }
                }
                break;

            case "Split":
                //Now if the last operation was a split operation, the undo for it will be as follows
                //We'll first find the tripNumber of the trip that was split.
                String tripNumber = undoTable.Rows[0]["KMLTrip"].ToString();
                //Now we'll find the trip with the same number in the current table. Once we've found it, we'll delete it and the row after it.
                for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                {
                    if (databaseViewer.Rows[i]["KMLTrip"].ToString().Equals(tripNumber))
                    {
                        //Now we've found the dataRow which contains the trip where our undo trip should be. So we'll delete this record entry
                        databaseViewer.Rows[i].Delete();
                        t_pool.getTripDetails().Rows[i].Delete();
                        //Once that row has been deleted, the row below it will fall into the same index as the row that deleted before. So we'll perform the delete action again
                        databaseViewer.Rows[i].Delete();
                        t_pool.getTripDetails().Rows[i].Delete();
                        //Now we'll add the dataRow from our undoTable
                        DataRow newRow = NewRowDataTableCustom();
                        copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, i);
                        DataRow newRowKML = t_pool.NewRowDataTableCustom();
                        copyDataRowContents(undoTable.Rows[0], newRowKML);
                        t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                        //Now once all the data has been deleted and added, we'll reset the tripCount
                        resetTripCountForDay();
                        t_pool.resetTripCount();
                        //And now once all the data has been successfully restored we can delete the undo Table fields
                        undoTable.Rows[0].Delete();
                        break;
                    }
                }
                break;

            case "Make Start":
                //That means that last operation was a Make Start on one of the trips
                tripNumber = undoTable.Rows[0]["KMLTrip"].ToString();
                for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                {
                    if (databaseViewer.Rows[i]["KMLTrip"].ToString().Equals(tripNumber))
                    {
                        databaseViewer.Rows[i].Delete();
                        DataRow newRow = NewRowDataTableCustom();
                        copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, i);
                        t_pool.getTripDetails().Rows[i].Delete();
                        DataRow newRowKML = t_pool.NewRowDataTableCustom();
                        copyDataRowContents(undoTable.Rows[0], newRowKML);
                        t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                        undoTable.Rows[0].Delete();
                        t_pool.removeFirstPoint("Trip_" + databaseViewer.Rows[i]["KMLTrip"]);
                        //                     undoTypeTable.Rows[0].Delete();
                    }
                }
                //I think this should be in a different place, but it's not happening at the moment, so I'll do it here
                //We should also delete the point that was created as the start point
                //So it's just going to be the start point of the trip
                break;

            case "Make Finish":
                //That means that last operation was a Make Start on one of the trips
                tripNumber = undoTable.Rows[0]["Trip"].ToString();
                for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                {
                    if (databaseViewer.Rows[i]["KMLTrip"].ToString().Equals(tripNumber))
                    {
                        databaseViewer.Rows[i].Delete();
                        DataRow newRow = NewRowDataTableCustom();
                        copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, i);
                        t_pool.getTripDetails().Rows[i].Delete();
                        DataRow newRowKML = t_pool.NewRowDataTableCustom();
                        copyDataRowContents(undoTable.Rows[0], newRowKML);
                        t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                        undoTable.Rows[0].Delete();
                        t_pool.removeLastPoint("Trip_" + databaseViewer.Rows[i]["KMLTrip"]);
                        //                     undoTypeTable.Rows[0].Delete();
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 4
0
        public void undoTripAction(TripPool t_pool)
        {
            //First we'll see what the last type of action was.
            String lastAction = undoTypeTable.Rows[0]["Action Type"].ToString(); // so this will bring down what the last action was.
            //We should then delete this action from the undoTypeTable
            undoTypeTable.Rows[0].Delete(); // this will delete the entry from the undoTable
            switch (lastAction)
            {

                case "Insert":
                    //When the last operation was an insert
                    String tripNumberInsert = undoTable.Rows[0][0].ToString();
                    //Find this trip in the databaseViewer
                    for (int i = 0; i != databaseViewer.Rows.Count; ++i)
                    {
                        if (databaseViewer.Rows[i]["KMLTrip"].Equals(tripNumberInsert))
                        {
                            databaseViewer.Rows[i].Delete();
                            //t_pool.getTripDetails().Rows[i].Delete();
                            t_pool.resetTripCount();
                            resetTripCountForDay();
                        }
                    }
                    break;

                case "Delete":
                    //If the last action was a delete action
                    //Then we simply have to re-instate the row in the UndoTable and place it back in the databaseViewer Table
                    //But before that we also need to find where exactly the row goes.
                    //We will do that by finding the day and trip number of the deleted row.And then inserting the row at that position.
                    String day = undoTable.Rows[0]["Day"].ToString();
                    String trip = undoTable.Rows[0]["KMLTrip"].ToString();
                    //Once we have the day and trip information we will find the right place to add the row back in the database.
                    if (databaseViewer.Rows.Count == 0)
                    {
                        DataRow newRow = NewRowDataTableCustom();
                        newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, 0);
                        DataRow newRowKML = t_pool.NewRowDataTableCustom();
                        newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                        t_pool.getTripDetails().Rows.InsertAt(newRowKML, 0);
                        undoTable.Rows[0].Delete();
                        resetTripCountForDay();
                        t_pool.resetTripCount();
                        break;
                    }
                    else if (databaseViewer.Rows.Count < Convert.ToInt32(trip))
                    {
                        DataRow newRow = NewRowDataTableCustom();
                        newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, databaseViewer.Rows.Count);
                        DataRow newRowKML = t_pool.NewRowDataTableCustom();
                        newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                        t_pool.getTripDetails().Rows.InsertAt(newRowKML, databaseViewer.Rows.Count);
                        undoTable.Rows[0].Delete();
                        resetTripCountForDay();
                        t_pool.resetTripCount();
                        break;
                    }
                    else
                    {
                        for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                        {
                            if (Convert.ToInt32(databaseViewer.Rows[i]["KMLTrip"].ToString()) == Convert.ToInt32(trip))
                            {
                                //Now we'll add our trip at this location.
                                //Simply copying a row from one table to another table doesn't work. So we'll create a new DataRow to add
                                DataRow newRow = NewRowDataTableCustom();
                                newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                                databaseViewer.Rows.InsertAt(newRow, i);
                                DataRow newRowKML = t_pool.NewRowDataTableCustom();
                                newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                                t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                                resetTripCountForDay();
                                t_pool.resetTripCount();
                                // One the row has been safely added back to the database, it is safe to remove it from the undo Table
                                undoTable.Rows[0].Delete();
                                break;
                            }
                        }
                    }
                    break;

                case "Join":
                    //If the last action was a join action
                    //That means we have to re-instate the two rows that are in the undo table in their respective order.
                    //First we'll find the current trip1 and delete it.
                    trip = undoTable.Rows[0]["KMLTrip"].ToString();
                    if (databaseViewer.Rows.Count == 0)
                    {
                        DataRow newRow = NewRowDataTableCustom();
                        newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, 0);
                        t_pool.getTripDetails().Rows.InsertAt(newRow, 0);
                        resetTripCountForDay();
                        t_pool.resetTripCount();
                        undoTable.Rows[0].Delete();
                        break;
                    }
                    else if ( databaseViewer.Rows.Count < Convert.ToInt32(trip) )
                    {
                        DataRow newRow = NewRowDataTableCustom();
                        newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, databaseViewer.Rows.Count);
                        t_pool.getTripDetails().Rows.InsertAt(newRow, databaseViewer.Rows.Count  );
                        resetTripCountForDay();
                        t_pool.resetTripCount();
                        undoTable.Rows[0].Delete();
                        break;
                    }
                    else
                    {
                        for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                        {
                            if (databaseViewer.Rows[i]["KMLTrip"].ToString() == trip)
                            {
                                DataRow newRow = NewRowDataTableCustom();
                                newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                                databaseViewer.Rows.InsertAt(newRow, i);
                                DataRow newRowKML = t_pool.NewRowDataTableCustom();
                                newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                                t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                                if (databaseViewer.Rows.Count > 1)
                                {
                                    databaseViewer.Rows[i + 1].Delete();
                                    t_pool.getTripDetails().Rows[i + 1].Delete();
                                }
                                undoTable.Rows[0].Delete();
                                resetTripCountForDay();
                                t_pool.resetTripCount();
                                break;
                            }
                        }
                    }
                    trip = undoTable.Rows[0]["KMLTrip"].ToString();
                    if (databaseViewer.Rows.Count < Convert.ToInt32(trip))
                    {
                        DataRow newRow = NewRowDataTableCustom();
                        newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                        databaseViewer.Rows.InsertAt(newRow, databaseViewer.Rows.Count);
                        DataRow newRowKML = t_pool.NewRowDataTableCustom();
                        newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                        t_pool.getTripDetails().Rows.InsertAt(newRowKML, databaseViewer.Rows.Count);
                        resetTripCountForDay();
                        t_pool.resetTripCount();
                        undoTable.Rows[0].Delete();
                        break;
                    }
                    else
                    {
                        for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                        {
                            if (databaseViewer.Rows[i]["KMLTrip"].ToString() == trip)
                            {
                                DataRow newRow = NewRowDataTableCustom();
                                newRow = copyDataRowContents(undoTable.Rows[0], newRow);
                                databaseViewer.Rows.InsertAt(newRow, i);
                                DataRow newRowKML = t_pool.NewRowDataTableCustom();
                                newRowKML = copyDataRowContents(undoTable.Rows[0], newRowKML);
                                t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                                resetTripCountForDay();
                                t_pool.resetTripCount();
                                undoTable.Rows[0].Delete();
                                break;
                            }
                        }
                    }
                    break;

                case "Split":
                    //Now if the last operation was a split operation, the undo for it will be as follows
                    //We'll first find the tripNumber of the trip that was split.
                    String tripNumber = undoTable.Rows[0]["KMLTrip"].ToString();
                    //Now we'll find the trip with the same number in the current table. Once we've found it, we'll delete it and the row after it.
                    for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                    {
                        if (databaseViewer.Rows[i]["KMLTrip"].ToString().Equals(tripNumber))
                        {
                            //Now we've found the dataRow which contains the trip where our undo trip should be. So we'll delete this record entry
                            databaseViewer.Rows[i].Delete();
                            t_pool.getTripDetails().Rows[i].Delete();
                            //Once that row has been deleted, the row below it will fall into the same index as the row that deleted before. So we'll perform the delete action again
                            databaseViewer.Rows[i].Delete();
                            t_pool.getTripDetails().Rows[i].Delete();
                            //Now we'll add the dataRow from our undoTable
                            DataRow newRow = NewRowDataTableCustom();
                            copyDataRowContents(undoTable.Rows[0], newRow);
                            databaseViewer.Rows.InsertAt(newRow, i);
                            DataRow newRowKML = t_pool.NewRowDataTableCustom();
                            copyDataRowContents(undoTable.Rows[0], newRowKML);
                            t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                            //Now once all the data has been deleted and added, we'll reset the tripCount
                            resetTripCountForDay();
                            t_pool.resetTripCount();
                            //And now once all the data has been successfully restored we can delete the undo Table fields
                            undoTable.Rows[0].Delete();
                            break;
                        }
                    }
                    break;

                case "Make Start":
                    //That means that last operation was a Make Start on one of the trips
                    tripNumber = undoTable.Rows[0]["KMLTrip"].ToString();
                    for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                    {
                        if ( databaseViewer.Rows[i]["KMLTrip"].ToString().Equals(tripNumber) )
                        {
                            databaseViewer.Rows[i].Delete();
                            DataRow newRow = NewRowDataTableCustom();
                            copyDataRowContents(undoTable.Rows[0], newRow);
                            databaseViewer.Rows.InsertAt(newRow, i);
                            t_pool.getTripDetails().Rows[i].Delete();
                            DataRow newRowKML = t_pool.NewRowDataTableCustom();
                            copyDataRowContents(undoTable.Rows[0], newRowKML);
                            t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                            undoTable.Rows[0].Delete();
                            t_pool.removeFirstPoint("Trip_"+databaseViewer.Rows[i]["KMLTrip"]);
               //                     undoTypeTable.Rows[0].Delete();
                        }
                    }
                    //I think this should be in a different place, but it's not happening at the moment, so I'll do it here
                    //We should also delete the point that was created as the start point
                    //So it's just going to be the start point of the trip
                    break;

                case "Make Finish":
                    //That means that last operation was a Make Start on one of the trips
                    tripNumber = undoTable.Rows[0]["Trip"].ToString();
                    for (int i = 0; i < databaseViewer.Rows.Count; ++i)
                    {
                        if (databaseViewer.Rows[i]["KMLTrip"].ToString().Equals(tripNumber))
                        {
                            databaseViewer.Rows[i].Delete();
                            DataRow newRow = NewRowDataTableCustom();
                            copyDataRowContents(undoTable.Rows[0], newRow);
                            databaseViewer.Rows.InsertAt(newRow, i);
                            t_pool.getTripDetails().Rows[i].Delete();
                            DataRow newRowKML = t_pool.NewRowDataTableCustom();
                            copyDataRowContents(undoTable.Rows[0], newRowKML);
                            t_pool.getTripDetails().Rows.InsertAt(newRowKML, i);
                            undoTable.Rows[0].Delete();
                            t_pool.removeLastPoint("Trip_" + databaseViewer.Rows[i]["KMLTrip"]);
                            //                     undoTypeTable.Rows[0].Delete();
                        }
                    }
                    break;

                default:
                    break;

            }
        }
Ejemplo n.º 5
0
        public void splitTrip(String day, String trip, IKmlPlacemark s_point, IKmlPlacemark f_point, TripPool t_pool)
        {
            //           MessageBox.Show(tripData.getFeatures().getChildNodes().getLength().ToString() + " " + point.getName() +"    "+point.getId());

            Module testModule = new Module();
            //This function will split a trip in the text file
            //First we'll need to find the day we're talking about
            for (int i = 0; i < databaseViewer.Rows.Count; ++i)
            {
                    //once we have found the right day we'll go and find the right trip
                    if (databaseViewer.Rows[i]["KMLTrip"].ToString() == trip)
                    {
                        //Once we have found the trip we'll first have to add it to the Undo Table
                        //First we'll add the entry of what type of action was performed.
                        addToUndoTypeTable("Split");
                        addToUndotable(databaseViewer.Rows[i]);  // So we've added the whole row back into place.
                        //once we have found our trip record we'll make the further modifications
                        //Now the split point of the trip will become the finishing point of the original trip. Before we insert the new values, we should store the other values first
                        String oldFinishTime = databaseViewer.Rows[i]["Finish"].ToString();
                        String oldFinishLat = databaseViewer.Rows[i]["fLatitude"].ToString();
                        String oldFinishLong = databaseViewer.Rows[i]["fLongitude"].ToString();
                        //Now that we've stored these values, we can safely replace these fields with the new data.
                        databaseViewer.Rows[i]["Finish"] = f_point.getName();
                        t_pool.getTripDetails().Rows[i]["Finish Time"] = f_point.getName();
                        Hashtable coords = Module.getCoordinates(f_point);
                        databaseViewer.Rows[i]["fLatitude"] = coords["lat"];
                        databaseViewer.Rows[i]["fLongitude"] = coords["lon"];
                        t_pool.getTripDetails().Rows[i]["FinishLat"] = coords["lat"];
                        t_pool.getTripDetails().Rows[i]["FinishLong"] = coords["long"];
                        t_pool.resetTripData("Trip_"+ trip);
                        //By this time the original trip would have been modified correctly. Now we need to create a new trip and set it's fields correctly
                        //Now we need to get the details of the next point
             //                       point = getNextPoint(tripData, point); //This should give us the next point after the split point.
                        coords = Module.getCoordinates(s_point);
                        //Now once we have all the information we'll create a new record in the table
                        DataRow newRow = NewRowDataTableCustom();
                        DataRow newRowKML = t_pool.NewRowDataTableCustom();
                        //Most of the information will be the same as the current record
                        newRow["Day"] = databaseViewer.Rows[i]["Day"];
                        newRow["Household"] = databaseViewer.Rows[i]["HouseHold"];
                        newRow["Person"] = databaseViewer.Rows[i]["Person"];
                        newRow["Date"] = databaseViewer.Rows[i]["Date"];
                        newRow["Weekday"] = databaseViewer.Rows[i]["Weekday"];
                        newRow["Remain"] = databaseViewer.Rows[i]["Remain"];
                        //Now we'll add the new data
                        newRow["KMLTrip"] = (Convert.ToInt32(databaseViewer.Rows[i]["KMLTrip"])+1).ToString();
                        newRow["Start"] = s_point.getName();
                        newRow["Finish"] = oldFinishTime;
                        newRow["sLongitude"] = coords["lon"];
                        newRow["sLatitude"] = coords["lat"];
                        newRow["fLongitude"] = oldFinishLong;
                        newRow["fLatitude"] = oldFinishLat;
                        //Now we'll add this row in the dataTable
                        databaseViewer.Rows.InsertAt(newRow, i+1);
                        newRowKML = copyDataRowContents(newRow, newRowKML);
                        t_pool.getTripDetails().Rows.InsertAt(newRowKML, i + 1);
                        //Now once everything is done, we'll reset the tripCount for that day
                        resetTripCountForDay();
                        t_pool.resetTripCount();
                        t_pool.resetTripData("Trip_" + (Convert.ToInt32(trip)+1).ToString());
                        completeMissingData(t_pool);
                    }

            }
        }
Ejemplo n.º 6
0
 public void insertTrip(IKmlFolder trip, String tripNumber, TripPool t_pool)
 {
     //This will add a trip to the dataTable
     addToUndoTypeTable("Insert");
     undoTable.Rows.Add(tripNumber, "");
     DataRow row = NewRowDataTableCustom();
     row[0] = tripNumber;
     row[1] = databaseViewer.Rows[0][1];
     //The trip count will be set with the resetTripCount
     row[3] = databaseViewer.Rows[0][3];
     row[4] = databaseViewer.Rows[0][4];
     row[5] = databaseViewer.Rows[0][5];
     row[6] = databaseViewer.Rows[0][6];
     IKmlObjectList points = trip.getFeatures().getChildNodes();
     IKmlPlacemark startPoint = (IKmlPlacemark)points.item(0);
     IKmlPlacemark finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1);
     row[12] = Module.getCoordinates(startPoint)["lon"].ToString();
     row[13] = Module.getCoordinates(startPoint)["lat"].ToString();
     row[14] = Module.getCoordinates(finishPoint)["lon"].ToString();
     row[15] = Module.getCoordinates(finishPoint)["lat"].ToString();
     databaseViewer.Rows.InsertAt(row, Convert.ToInt32(tripNumber)-1);
     DataRow newRowKML = t_pool.NewRowDataTableCustom();
     newRowKML = copyDataRowContents(row, newRowKML);
     t_pool.getTripDetails().Rows.InsertAt(newRowKML, Convert.ToInt32(tripNumber)-1);
     completeMissingData(t_pool);
     t_pool.resetTripCount();
     resetTripCountForDay();
 }