コード例 #1
0
ファイル: TextFileEditor.cs プロジェクト: mtswiss/UniWork
        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);
                    }

            }
        }