Exemplo n.º 1
0
      /// <summary>
      /// Creates wells from DataRows based on ShapeReaderConfiguration
      /// </summary>
      /// <param name="DS"></param>
      /// <param name="SRC"></param>
      public static void FillInFromNovanaShape(DataRow[] DS, ShapeReaderConfiguration SRC, IWellCollection Wells, IPlantCollection Plants)
      {
        bool ReadPumpActivity = false;
        bool ReadPlants = false;
        bool ReadLayer = false;
        if (DS.First().Table.Columns.Contains(SRC.FraAArHeader) & DS.First().Table.Columns.Contains(SRC.TilAArHeader))
          ReadPumpActivity = true;

        if (DS.First().Table.Columns.Contains(SRC.LayerHeader))
          ReadLayer = true;


        if (Plants != null)
          if (DS.First().Table.Columns.Contains(SRC.PlantIDHeader))
            ReadPlants = true;

        IWell CurrentWell;
        IIntake CurrentIntake;
        foreach (DataRow DR in DS)
        {
          string wellID = DR[SRC.WellIDHeader].ToString();
          //Find the well in the dictionary
          if (Wells.Contains(wellID))
          {
            CurrentWell = Wells[wellID];
          }
          else
          {
            //Add a new well if it was not found
            CurrentWell = new Well(wellID);
            CurrentWell.UsedForExtraction = true;
            Wells.Add(CurrentWell);
          }

          int intakeno = Convert.ToInt32(DR[SRC.IntakeNumber]);

          CurrentIntake = CurrentWell.Intakes.FirstOrDefault(var => var.IDNumber == intakeno);

          if (CurrentIntake == null)
            CurrentIntake = CurrentWell.AddNewIntake(intakeno);

          if (ReadLayer)
            if (!Convert.IsDBNull(DR[SRC.LayerHeader]))
              CurrentIntake.Layer = Convert.ToInt32(DR[SRC.LayerHeader]);

          if (ReadPlants)
          {
            Plant CurrentPlant;
            int PlantID = Convert.ToInt32(DR[SRC.PlantIDHeader]);
            if (!Plants.TryGetValue(PlantID, out CurrentPlant))
            {
              CurrentPlant = new Plant(PlantID);
              Plants.Add(CurrentPlant);
            }
            PumpingIntake CurrentPumpingIntake = new PumpingIntake(CurrentIntake, CurrentPlant);
            CurrentPlant.PumpingIntakes.Add(CurrentPumpingIntake);
            if (ReadPumpActivity)
            {
              CurrentPumpingIntake.Start = new DateTime(Convert.ToInt32(DR[SRC.FraAArHeader]), 1, 1);
              CurrentPumpingIntake.End = new DateTime(Convert.ToInt32(DR[SRC.TilAArHeader]), 12, 31);
            }
          }
          CurrentWell.X = Convert.ToDouble(DR[SRC.XHeader]);
          CurrentWell.Y = Convert.ToDouble(DR[SRC.YHeader]);
          CurrentWell.Terrain = Convert.ToDouble(DR[SRC.TerrainHeader]);
          Screen CurrentScreen = new Screen(CurrentIntake);
          CurrentScreen.BottomAsKote = Convert.ToDouble(DR[SRC.BOTTOMHeader]);
          CurrentScreen.TopAsKote = Convert.ToDouble(DR[SRC.TOPHeader]);
        }
      }
Exemplo n.º 2
0
    /// <summary>
    /// Read Extractions.
    /// The boolean set dates indicates whether the dates read from the DRWPLANTINTAKE table should be used as Pumpingstart
    /// and pumpingstop.
    /// </summary>
    /// <param name="Plants"></param>
    /// <param name="Wells"></param>
    public IPlantCollection ReadPlants(IWellCollection Wells)
    {
      List<Plant> Plants = new List<Plant>();
      IPlantCollection DPlants = new IPlantCollection();

      JXL.ReadPlantData();

      IIntake CurrentIntake = null;
      Plant CurrentPlant;

      List<Tuple<int, Plant>> SubPlants = new List<Tuple<int, Plant>>();


      foreach (var Anlaeg in JXL.DRWPLANT)
      {
        CurrentPlant = new Plant(Anlaeg.PLANTID);
        DPlants.Add(CurrentPlant);

        if (Anlaeg.IsPLANTNAMENull())
          CurrentPlant.Name = "<no name in database>";
        else
          CurrentPlant.Name = Anlaeg.PLANTNAME;

        CurrentPlant.Address = Anlaeg.PLANTADDRESS;

        CurrentPlant.PostalCode = Anlaeg.PLANTPOSTALCODE;

        if (!Anlaeg.IsSUPPLANTNull())
          CurrentPlant.SuperiorPlantNumber = Anlaeg.SUPPLANT;

         CurrentPlant.NewCommuneNumber = Anlaeg.MUNICIPALITYNO2007;
         CurrentPlant.OldCommuneNumber = Anlaeg.MUNICIPALITYNO;


        var cmp =Anlaeg.GetDRWPLANTCOMPANYTYPERows().LastOrDefault();
        if(cmp !=null)
         CurrentPlant.CompanyType = cmp.COMPANYTYPE;

        if (!Anlaeg.IsPERMITDATENull())
          CurrentPlant.PermitDate = Anlaeg.PERMITDATE;

        if (!Anlaeg.IsPERMITEXPIREDATENull())
          CurrentPlant.PermitExpiryDate = Anlaeg.PERMITEXPIREDATE;

        if (Anlaeg.IsPERMITAMOUNTNull())
          CurrentPlant.Permit = 0;
        else
          CurrentPlant.Permit = Anlaeg.PERMITAMOUNT;

        if (!Anlaeg.IsSUPPLANTNull())
          SubPlants.Add(new Tuple<int, Plant>(Anlaeg.SUPPLANT, CurrentPlant));

        if (!Anlaeg.IsXUTMNull())
          CurrentPlant.X = Anlaeg.XUTM;

        if (!Anlaeg.IsYUTMNull())
          CurrentPlant.Y = Anlaeg.YUTM;


        //Loop the intakes. Only add intakes from wells already in table
        foreach (var IntakeData in Anlaeg.GetDRWPLANTINTAKERows())
        {
          if (Wells.Contains(IntakeData.BOREHOLENO))
          {
            JupiterWell jw = Wells[IntakeData.BOREHOLENO] as JupiterWell;
            CurrentIntake = jw.Intakes.FirstOrDefault(var => var.IDNumber == IntakeData.INTAKENO);
            if (CurrentIntake != null)
            {
              PumpingIntake CurrentPumpingIntake = new PumpingIntake(CurrentIntake, CurrentPlant);
              CurrentPlant.PumpingIntakes.Add(CurrentPumpingIntake);

              if (!IntakeData.IsSTARTDATENull())
                CurrentPumpingIntake.StartNullable = IntakeData.STARTDATE;
              else if (jw.StartDate.HasValue)
                CurrentPumpingIntake.StartNullable = jw.StartDate;
              else if (CurrentIntake.Screens.Where(var => var.StartDate.HasValue).Count() != 0)
                CurrentPumpingIntake.StartNullable = CurrentIntake.Screens.Where(var => var.StartDate.HasValue).Min(var => var.StartDate);

              if (!IntakeData.IsENDDATENull())
                CurrentPumpingIntake.EndNullable = IntakeData.ENDDATE;
              else if (jw.EndDate.HasValue)
                CurrentPumpingIntake.EndNullable = jw.EndDate;
              else if (CurrentIntake.Screens.Where(var => var.EndDate.HasValue).Count() != 0)
                CurrentPumpingIntake.EndNullable = CurrentIntake.Screens.Where(var => var.EndDate.HasValue).Max(var => var.EndDate);
            }
          }
        }
      }
      //Now attach the subplants
      foreach (Tuple<int, Plant> KVP in SubPlants)
      {
        Plant Upper;
        if (DPlants.TryGetValue(KVP.Item1, out Upper))
        {
          if (Upper == KVP.Item2)
          {
            string l = "what";
          }
          else
          {
            Upper.SubPlants.Add(KVP.Item2);
            foreach (PumpingIntake PI in KVP.Item2.PumpingIntakes)
            {
              PumpingIntake d = Upper.PumpingIntakes.FirstOrDefault(var => var.Intake.well.ID == PI.Intake.well.ID);
              //Remove pumping intakes from upper plant if they are attached to lower plants.
              if (d != null)
                Upper.PumpingIntakes.Remove(d);
            }
          }
        }
      }

      JXL.DRWPLANT.Dispose();
      JXL.DRWPLANTINTAKE.Dispose();
      return DPlants;
    }
Exemplo n.º 3
0
    public int FillInExtractionWithCount(IPlantCollection Plants)
    {
      JXL.ReadExtractionTables();

      Plant CurrentPlant;
      //Loop the extractions
      foreach (var Ext in JXL.WRRCATCHMENT)
      {
        if (Plants.TryGetValue(Ext.PLANTID, out CurrentPlant))
        {
          if (!Ext.IsAMOUNTNull())
            CurrentPlant.Extractions.Items.Add(new TimeSpanValue(Ext.STARTDATE,Ext.ENDDATE, Ext.AMOUNT));
          if (!Ext.IsSURFACEWATERVOLUMENull())
            CurrentPlant.SurfaceWaterExtrations.Items.Add(new TimeSpanValue(Ext.STARTDATE, Ext.ENDDATE, Ext.SURFACEWATERVOLUME));
        }
      }


      //In ribe amt extractions are in another table

      foreach (var IntExt in JXL.INTAKECATCHMENT)
      {
        if (Plants.TryGetValue(IntExt.DRWPLANTINTAKERow.PLANTID, out CurrentPlant))
        {
          //It would be possible to store this on the intake instead of the plant.
          //We are throwing away information!

          if (!IntExt.IsVOLUMENull())
          {
            CurrentPlant.Extractions.Items.Add(new TimeSpanValue(IntExt.STARTDATE, IntExt.ENDDATE, IntExt.VOLUME));
            //if (IntExt.ENDDATE.Year != IntExt.STARTDATE.Year)
            //  throw new Exception("Volume cover period longer than 1 year)");

            //var E = CurrentPlant.Extractions.Items.FirstOrDefault(var => var.StartTime.Year == IntExt.ENDDATE.Year);
            //if (E == null)
            //  CurrentPlant.Extractions.AddSiValue (new TimeSeriesEntry(IntExt.ENDDATE, IntExt.VOLUME));
            //else
            //  E.Value += IntExt.VOLUME;
          }
        }
      }
      int toreturn = JXL.INTAKECATCHMENT.Count + JXL.WRRCATCHMENT.Count;
      JXL.INTAKECATCHMENT.Dispose();
      JXL.WRRCATCHMENT.Dispose();
      return toreturn;
    }
    /// <summary>
    /// Applies the change in the description to a plant or a well.
    /// Returns true if the change could be applied. 
    /// No checks on previous values or dates.
    /// </summary>
    /// <param name="plants"></param>
    /// <param name="wells"></param>
    /// <param name="cd"></param>
    /// <returns></returns>
    public bool ApplySingleChange(IPlantCollection plants, IWellCollection wells, ChangeDescription cd)
    {
      string wellid = "";
      int plantid;
      int intakeno = -1;

      IWell CurrentWell;

      bool succeded = false;

      switch (cd.Table)
      {
        case JupiterTables.BOREHOLE:
          wellid = cd.PrimaryKeys["BOREHOLENO"];
          if (wells.TryGetValue(wellid, out CurrentWell))
          {
            foreach (var c in cd.ChangeValues)
            {
              switch (c.Column.ToUpper())
              {
                case "XUTM":
                  CurrentWell.X = double.Parse(c.NewValue);
                  succeded = true;
                  break;
                case "YUTM":
                  CurrentWell.Y = double.Parse(c.NewValue);
                  succeded = true;
                  break;
                case "ELEVATION":
                  CurrentWell.Terrain = double.Parse(c.NewValue);
                  succeded = true;
                  break;
                default:
                  break;
              }
            }
          }
          break;
        case JupiterTables.SCREEN:
          wellid = cd.PrimaryKeys["BOREHOLENO"];
          if (wells.TryGetValue(wellid, out CurrentWell))
          {
            int screenNumber = int.Parse(cd.PrimaryKeys["SCREENNO"]);
            if (cd.Action == TableAction.EditValue)
            {
              var screen = CurrentWell.Intakes.SelectMany(var => var.Screens).FirstOrDefault(var2 => var2.Number == screenNumber);
              if (screen != null)
              {
                foreach (var cv in cd.ChangeValues)
                {
                  if (cv.Column == "TOP")
                    screen.DepthToTop = double.Parse(cv.NewValue);
                  else if (cv.Column == "BOTTOM")
                    screen.DepthToBottom = double.Parse(cv.NewValue);
                  succeded = true;
                }
              }
            }
            else if (cd.Action == TableAction.InsertRow)
            {
              intakeno = int.Parse(cd.ChangeValues.Single(var => var.Column == "INTAKENO").NewValue);
              IIntake CurrentIntake = CurrentWell.Intakes.Single(var => var.IDNumber == intakeno);
              if (CurrentIntake != null)
              {
                Screen sc = new Screen(CurrentIntake);
                sc.DepthToTop = double.Parse(cd.ChangeValues.Single(var => var.Column == "TOP").NewValue);
                sc.DepthToBottom = double.Parse(cd.ChangeValues.Single(var => var.Column == "BOTTOM").NewValue);
                succeded = true;
              }
            }
          }
          break;
        case JupiterTables.DRWPLANTINTAKE:
          if (cd.Action == TableAction.EditValue || cd.Action == TableAction.DeleteRow)
          {
            int tableid;
            if (int.TryParse(cd.PrimaryKeys.First().Value, out tableid))
            {
              if (DataBaseConnection.TryGetPlant(tableid, out plantid, out wellid, out intakeno))
                succeded = true;
            }
            else //No ID Change of a change
            {
              if (cd.Action == TableAction.EditValue)
              {
                if (int.TryParse(cd.ChangeValues[0].NewValue, out plantid))
                {
                  wellid = cd.ChangeValues[1].NewValue;
                  if (int.TryParse(cd.ChangeValues[2].NewValue, out intakeno))
                    succeded = true;
                }
              }
              else
                if (int.TryParse(cd.ChangeValues[0].OldValue, out plantid))
                {
                  wellid = cd.ChangeValues[1].OldValue;
                  if (int.TryParse(cd.ChangeValues[2].OldValue, out intakeno))
                    succeded = true;
                }

            }

            if (succeded)
            {
              var pi = plants[plantid].PumpingIntakes.FirstOrDefault(var => var.Intake.well.ID == wellid & var.Intake.IDNumber == intakeno);

              if (pi != null)
              {
                if (cd.Action == TableAction.DeleteRow)
                  plants[plantid].PumpingIntakes.Remove(pi);
                else
                {
                  var start = cd.ChangeValues.SingleOrDefault(var => var.Column == "STARTDATE");
                  if (start != null)
                    pi.StartNullable = DateTime.Parse(start.NewValue);
                  var end = cd.ChangeValues.SingleOrDefault(var => var.Column == "ENDDATE");
                  if (end != null)
                    pi.EndNullable = DateTime.Parse(end.NewValue);
                }
                succeded = true;
              }
            }
          }
          else //insertrow
          {
            plantid = int.Parse(cd.ChangeValues.First(var => var.Column == "PLANTID").NewValue);
            Plant p;
            if (plants.TryGetValue(plantid, out p))
            {
              wellid = cd.ChangeValues.First(var => var.Column == "BOREHOLENO").NewValue;
              IWell w;
              if (wells.TryGetValue(wellid, out w))
              {
                intakeno = int.Parse(cd.ChangeValues.First(var => var.Column == "INTAKENO").NewValue);
                IIntake I = w.Intakes.First(var => var.IDNumber == intakeno);
                if (I != null)
                {
                  PumpingIntake pi = new PumpingIntake(I, p);
                  var s = cd.ChangeValues.FirstOrDefault(var => var.Column == "STARTDATE");
                  if (s != null)
                    pi.StartNullable = DateTime.Parse(s.NewValue);
                  s = cd.ChangeValues.FirstOrDefault(var => var.Column == "ENDDATE");
                  if (s != null)
                    pi.EndNullable = DateTime.Parse(s.NewValue);
                  p.PumpingIntakes.Add(pi);
                  succeded = true;
                }
              }
            }
          }
          break;
        case JupiterTables.WATLEVEL:
          wellid = cd.PrimaryKeys["BOREHOLENO"];
          if (wells.TryGetValue(wellid, out CurrentWell))
          {
            DateTime TimeOfMeasure;
            int WatlevelNo = int.Parse(cd.PrimaryKeys["WATLEVELNO"]);
            if (DataBaseConnection.TryGetIntakeNoTimeOfMeas(CurrentWell, WatlevelNo, out intakeno, out TimeOfMeasure))
            {
              IIntake CurrentIntake = CurrentWell.Intakes.SingleOrDefault(var => var.IDNumber == intakeno);
              if (CurrentIntake != null)
              {
                var item = CurrentIntake.HeadObservations.Items.FirstOrDefault(var => var.Time == TimeOfMeasure);
                if (item != null)
                {
                  CurrentIntake.HeadObservations.Items.Remove(item);
                  succeded = true;
                }
              }
            }
          }
          break;

        default:
          break;
      }
      return succeded;
    }
Exemplo n.º 5
0
        /// <summary>
        /// Creates wells from DataRows based on ShapeReaderConfiguration
        /// </summary>
        /// <param name="DS"></param>
        /// <param name="SRC"></param>
        public static void FillInFromNovanaShape(DataRow[] DS, ShapeReaderConfiguration SRC, IWellCollection Wells, IPlantCollection Plants)
        {
            bool ReadPumpActivity = false;
            bool ReadPlants       = false;
            bool ReadLayer        = false;

            if (DS.First().Table.Columns.Contains(SRC.FraAArHeader) & DS.First().Table.Columns.Contains(SRC.TilAArHeader))
            {
                ReadPumpActivity = true;
            }

            if (DS.First().Table.Columns.Contains(SRC.LayerHeader))
            {
                ReadLayer = true;
            }


            if (Plants != null)
            {
                if (DS.First().Table.Columns.Contains(SRC.PlantIDHeader))
                {
                    ReadPlants = true;
                }
            }

            IWell   CurrentWell;
            IIntake CurrentIntake;

            foreach (DataRow DR in DS)
            {
                string wellID = DR[SRC.WellIDHeader].ToString();
                //Find the well in the dictionary
                if (Wells.Contains(wellID))
                {
                    CurrentWell = Wells[wellID];
                }
                else
                {
                    //Add a new well if it was not found
                    CurrentWell = new Well(wellID);
                    CurrentWell.UsedForExtraction = true;
                    Wells.Add(CurrentWell);
                }

                int intakeno = Convert.ToInt32(DR[SRC.IntakeNumber]);

                CurrentIntake = CurrentWell.Intakes.FirstOrDefault(var => var.IDNumber == intakeno);

                if (CurrentIntake == null)
                {
                    CurrentIntake = CurrentWell.AddNewIntake(intakeno);
                }

                if (ReadLayer)
                {
                    if (!Convert.IsDBNull(DR[SRC.LayerHeader]))
                    {
                        CurrentIntake.Layer = Convert.ToInt32(DR[SRC.LayerHeader]);
                    }
                }

                if (ReadPlants)
                {
                    Plant CurrentPlant;
                    int   PlantID = Convert.ToInt32(DR[SRC.PlantIDHeader]);
                    if (!Plants.TryGetValue(PlantID, out CurrentPlant))
                    {
                        CurrentPlant = new Plant(PlantID);
                        Plants.Add(CurrentPlant);
                    }
                    PumpingIntake CurrentPumpingIntake = new PumpingIntake(CurrentIntake, CurrentPlant);
                    CurrentPlant.PumpingIntakes.Add(CurrentPumpingIntake);
                    if (ReadPumpActivity)
                    {
                        CurrentPumpingIntake.Start = new DateTime(Convert.ToInt32(DR[SRC.FraAArHeader]), 1, 1);
                        CurrentPumpingIntake.End   = new DateTime(Convert.ToInt32(DR[SRC.TilAArHeader]), 12, 31);
                    }
                }
                CurrentWell.X       = Convert.ToDouble(DR[SRC.XHeader]);
                CurrentWell.Y       = Convert.ToDouble(DR[SRC.YHeader]);
                CurrentWell.Terrain = Convert.ToDouble(DR[SRC.TerrainHeader]);
                Screen CurrentScreen = new Screen(CurrentIntake);
                CurrentScreen.BottomAsKote = Convert.ToDouble(DR[SRC.BOTTOMHeader]);
                CurrentScreen.TopAsKote    = Convert.ToDouble(DR[SRC.TOPHeader]);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Applies the change in the description to a plant or a well.
        /// Returns true if the change could be applied.
        /// No checks on previous values or dates.
        /// </summary>
        /// <param name="plants"></param>
        /// <param name="wells"></param>
        /// <param name="cd"></param>
        /// <returns></returns>
        public bool ApplySingleChange(IPlantCollection plants, IWellCollection wells, ChangeDescription cd)
        {
            string wellid = "";
            int    plantid;
            int    intakeno = -1;

            IWell CurrentWell;

            bool succeded = false;

            switch (cd.Table)
            {
            case JupiterTables.BOREHOLE:
                wellid = cd.PrimaryKeys["BOREHOLENO"];
                if (wells.TryGetValue(wellid, out CurrentWell))
                {
                    foreach (var c in cd.ChangeValues)
                    {
                        switch (c.Column.ToUpper())
                        {
                        case "XUTM":
                            CurrentWell.X = double.Parse(c.NewValue);
                            succeded      = true;
                            break;

                        case "YUTM":
                            CurrentWell.Y = double.Parse(c.NewValue);
                            succeded      = true;
                            break;

                        case "ELEVATION":
                            CurrentWell.Terrain = double.Parse(c.NewValue);
                            succeded            = true;
                            break;

                        default:
                            break;
                        }
                    }
                }
                break;

            case JupiterTables.SCREEN:
                wellid = cd.PrimaryKeys["BOREHOLENO"];
                if (wells.TryGetValue(wellid, out CurrentWell))
                {
                    int screenNumber = int.Parse(cd.PrimaryKeys["SCREENNO"]);
                    if (cd.Action == TableAction.EditValue)
                    {
                        var screen = CurrentWell.Intakes.SelectMany(var => var.Screens).FirstOrDefault(var2 => var2.Number == screenNumber);
                        if (screen != null)
                        {
                            foreach (var cv in cd.ChangeValues)
                            {
                                if (cv.Column == "TOP")
                                {
                                    screen.DepthToTop = double.Parse(cv.NewValue);
                                }
                                else if (cv.Column == "BOTTOM")
                                {
                                    screen.DepthToBottom = double.Parse(cv.NewValue);
                                }
                                succeded = true;
                            }
                        }
                    }
                    else if (cd.Action == TableAction.InsertRow)
                    {
                        intakeno = int.Parse(cd.ChangeValues.Single(var => var.Column == "INTAKENO").NewValue);
                        IIntake CurrentIntake = CurrentWell.Intakes.Single(var => var.IDNumber == intakeno);
                        if (CurrentIntake != null)
                        {
                            Screen sc = new Screen(CurrentIntake);
                            sc.DepthToTop    = double.Parse(cd.ChangeValues.Single(var => var.Column == "TOP").NewValue);
                            sc.DepthToBottom = double.Parse(cd.ChangeValues.Single(var => var.Column == "BOTTOM").NewValue);
                            succeded         = true;
                        }
                    }
                }
                break;

            case JupiterTables.DRWPLANTINTAKE:
                if (cd.Action == TableAction.EditValue || cd.Action == TableAction.DeleteRow)
                {
                    int tableid;
                    if (int.TryParse(cd.PrimaryKeys.First().Value, out tableid))
                    {
                        if (DataBaseConnection.TryGetPlant(tableid, out plantid, out wellid, out intakeno))
                        {
                            succeded = true;
                        }
                    }
                    else //No ID Change of a change
                    {
                        if (cd.Action == TableAction.EditValue)
                        {
                            if (int.TryParse(cd.ChangeValues[0].NewValue, out plantid))
                            {
                                wellid = cd.ChangeValues[1].NewValue;
                                if (int.TryParse(cd.ChangeValues[2].NewValue, out intakeno))
                                {
                                    succeded = true;
                                }
                            }
                        }
                        else
                        if (int.TryParse(cd.ChangeValues[0].OldValue, out plantid))
                        {
                            wellid = cd.ChangeValues[1].OldValue;
                            if (int.TryParse(cd.ChangeValues[2].OldValue, out intakeno))
                            {
                                succeded = true;
                            }
                        }
                    }

                    if (succeded)
                    {
                        var pi = plants[plantid].PumpingIntakes.FirstOrDefault(var => var.Intake.well.ID == wellid & var.Intake.IDNumber == intakeno);

                        if (pi != null)
                        {
                            if (cd.Action == TableAction.DeleteRow)
                            {
                                plants[plantid].PumpingIntakes.Remove(pi);
                            }
                            else
                            {
                                var start = cd.ChangeValues.SingleOrDefault(var => var.Column == "STARTDATE");
                                if (start != null)
                                {
                                    pi.StartNullable = DateTime.Parse(start.NewValue);
                                }
                                var end = cd.ChangeValues.SingleOrDefault(var => var.Column == "ENDDATE");
                                if (end != null)
                                {
                                    pi.EndNullable = DateTime.Parse(end.NewValue);
                                }
                            }
                            succeded = true;
                        }
                    }
                }
                else //insertrow
                {
                    plantid = int.Parse(cd.ChangeValues.First(var => var.Column == "PLANTID").NewValue);
                    Plant p;
                    if (plants.TryGetValue(plantid, out p))
                    {
                        wellid = cd.ChangeValues.First(var => var.Column == "BOREHOLENO").NewValue;
                        IWell w;
                        if (wells.TryGetValue(wellid, out w))
                        {
                            intakeno = int.Parse(cd.ChangeValues.First(var => var.Column == "INTAKENO").NewValue);
                            IIntake I = w.Intakes.First(var => var.IDNumber == intakeno);
                            if (I != null)
                            {
                                PumpingIntake pi = new PumpingIntake(I, p);
                                var           s  = cd.ChangeValues.FirstOrDefault(var => var.Column == "STARTDATE");
                                if (s != null)
                                {
                                    pi.StartNullable = DateTime.Parse(s.NewValue);
                                }
                                s = cd.ChangeValues.FirstOrDefault(var => var.Column == "ENDDATE");
                                if (s != null)
                                {
                                    pi.EndNullable = DateTime.Parse(s.NewValue);
                                }
                                p.PumpingIntakes.Add(pi);
                                succeded = true;
                            }
                        }
                    }
                }
                break;

            case JupiterTables.WATLEVEL:
                wellid = cd.PrimaryKeys["BOREHOLENO"];
                if (wells.TryGetValue(wellid, out CurrentWell))
                {
                    DateTime TimeOfMeasure;
                    int      WatlevelNo = int.Parse(cd.PrimaryKeys["WATLEVELNO"]);
                    if (DataBaseConnection.TryGetIntakeNoTimeOfMeas(CurrentWell, WatlevelNo, out intakeno, out TimeOfMeasure))
                    {
                        IIntake CurrentIntake = CurrentWell.Intakes.SingleOrDefault(var => var.IDNumber == intakeno);
                        if (CurrentIntake != null)
                        {
                            var item = CurrentIntake.HeadObservations.Items.FirstOrDefault(var => var.Time == TimeOfMeasure);
                            if (item != null)
                            {
                                CurrentIntake.HeadObservations.Items.Remove(item);
                                succeded = true;
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }
            return(succeded);
        }