/// <summary> /// Returns the primary id for the row in the drwplantintake table. Still sensitive to sql-injection. /// Will not yet return correct number if intake is there twice with different dates /// </summary> /// <param name="Intake"></param> /// <param name="plant"></param> /// <returns></returns> public bool TryGetPrimaryID(PumpingIntake Intake, Plant plant, out int ID) { ID = -1; string sql = "select IntakeplantId from DRWPLANTINTAKE where PLANTID=" + plant.IDNumber.ToString() + " and BOREHOLENO ='" + Intake.Intake.well.ID + "' and INTAKENO = " + Intake.Intake.IDNumber.ToString(); using (OleDbCommand command = new OleDbCommand(sql, odb)) { try { using (OleDbDataReader reader2 = command.ExecuteReader()) { reader2.Read(); if (!reader2.HasRows) { return(false); } else { ID = reader2.GetInt32(0); return(true); } } } catch (OleDbException E) { throw new Exception("Make sure that the database is in JupiterXL-format, Access 2000"); } } }
/// <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]); } }
/// <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; }
/// <summary> /// Returns the primary id for the row in the drwplantintake table. Still sensitive to sql-injection. /// Will not yet return correct number if intake is there twice with different dates /// </summary> /// <param name="Intake"></param> /// <param name="plant"></param> /// <returns></returns> public bool TryGetPrimaryID(PumpingIntake Intake, Plant plant, out int ID) { ID = -1; string sql = "select IntakeplantId from DRWPLANTINTAKE where PLANTID=" + plant.IDNumber.ToString() + " and BOREHOLENO ='" + Intake.Intake.well.ID + "' and INTAKENO = " + Intake.Intake.IDNumber.ToString(); using (OleDbCommand command = new OleDbCommand(sql, odb)) { try { using (OleDbDataReader reader2 = command.ExecuteReader()) { reader2.Read(); if (!reader2.HasRows) return false; else { ID = reader2.GetInt32(0); return true; } } } catch (OleDbException E) { throw new Exception("Make sure that the database is in JupiterXL-format, Access 2000"); } } }
public ChangeDescription RemoveIntakeFromPlant(PumpingIntake Intake, Plant plant) { return ChangeController.RemoveIntakeFromPlant(Intake, plant); }
public void GetPrimaryIDTest() { Wells.Well w = new HydroNumerics.Wells.Well("193. 125A"); w.AddNewIntake(1); Plant plant = new Plant(2065); PumpingIntake Intake = new PumpingIntake(w.Intakes.First(), plant); int actual; Assert.IsTrue(Reader.TryGetPrimaryID(Intake, plant, out actual)); Assert.AreEqual(707, actual); }
/// <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); }