示例#1
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;
            }
        }
示例#2
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;

            }
        }