public void AddMeteostation(MeteoStation meteoStation) { MeteoStationDBContext msdbc = new MeteoStationDBContext(); if (meteoStation.Name == null) throw new NoNamedStationException("Stacja nie ma nazwy!"); else { msdbc.MeteoStation.Add(meteoStation); msdbc.SaveChanges(); } }
private Pressure SetPressure(string pressureValue, string unit, DateTime timeOfMeasurement, MeteoStation stationOfMeausement) { Pressure p = new Pressure() { Value = Convert.ToDouble(pressureValue), DateOfMeasuement = timeOfMeasurement, MeteoStationOfMeasurement = stationOfMeausement, Unit = unit }; return p; }
//--------------------------------------------------------------------------------------------------------------------------------------- //Dodawanie stacji private MeteoStation CreateStation(string nazwa, string miasto, string wojewodztwo, DateTime dataInstalacji) { MeteoStation ms = new MeteoStation { LocationOfInstalation = new Location() {City = miasto, Province = wojewodztwo}, Name = nazwa, DateOfInstalation = dataInstalacji }; return ms; }
/// <summary> /// Pobiera pomiary dla podanej stacji, zapisując je do podanego Containera /// </summary> /// <param name="meteoStation"></param> /// <param name="dc"></param> public void GetMeasurementsOfStation(MeteoStation meteoStation, DataContainer dc) { var pressures = from p in GetPressures() where p.MeteoStationOfMeasurement.Id == meteoStation.Id select p; var temperatures = from p in GetTemperatures() where p.MeteoStationOfMeasurement.Id == meteoStation.Id select p; var wetneses = from p in GetWetneses() where p.MeteoStationOfMeasurement.Id == meteoStation.Id select p; SaveMeasurementsToContainer(temperatures.ToList(), pressures.ToList(), wetneses.ToList(), dc ); }
public void AddMeteoStationNameTest() { DataContainer dc = new DataContainer(); MeteoStation ms = new MeteoStation(); //{Name = "Stacyjka", LocationOfInstalation = new Location {City = "Poznan", Province = "Kaszubskie"}}; try { dc.AddMeteostation(ms); Assert.Fail("Stacja powinna byc zawsze nazwana"); } catch (NoNamedStationException) { Assert.Pass(); } catch(Exception e) { Assert.Fail(e.Message); } }
public void AddMeteoStationLocationTest() { DataContainer dc = new DataContainer(); MeteoStation ms = new MeteoStation {Name = "Stacyjka"}; try { dc.AddMeteostation(ms); Assert.Fail("Stacja powinna miec lokalizacje"); } catch (NonLocatedStationException) { Assert.Pass(); } catch (Exception e) { Assert.Fail(e.Message); } }
//Dodawanie pomiarów private Temperature SetTemperature(string temperatureValue, string unit, DateTime timeOfMeasurement, MeteoStation stationOfMeausement) { Temperature t = new Temperature() { Value = Convert.ToDouble(temperatureValue), DateOfMeasuement = timeOfMeasurement, MeteoStationOfMeasurement = stationOfMeausement, Unit = unit }; return t; }
private Wetness SetWetness(string wetnessValue, string unit, DateTime timeOfMeasurement, MeteoStation stationOfMeausement) { Wetness w = new Wetness() { Value = Convert.ToDouble(wetnessValue), DateOfMeasuement = timeOfMeasurement, MeteoStationOfMeasurement = stationOfMeausement, Unit = unit }; return w; }
public static void ExportStation(MeteoStation station) { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); if (xlApp == null) { Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct."); return; } xlApp.Visible = false; Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); Sheets worksheets = wb.Worksheets; Worksheet meteoSheet = (Worksheet)worksheets.Add(worksheets[1], Type.Missing, Type.Missing, Type.Missing); //(Worksheet)wb.Worksheets[1]; meteoSheet.Name = "MeteoStation"; meteoSheet.Cells[1, 1] = "Id"; meteoSheet.Cells[1, 2] = "Name"; meteoSheet.Cells[1, 3] = "DateOfInstalation"; meteoSheet.Cells[2, 1] = station.Id; meteoSheet.Cells[2, 2] = station.Name; meteoSheet.Cells[2, 3] = station.DateOfInstalation; Worksheet locationSheet = (Worksheet)worksheets.Add(worksheets[2], Type.Missing, Type.Missing, Type.Missing); locationSheet.Name = "Location"; locationSheet.Cells[1, 1] = "Id"; locationSheet.Cells[1, 2] = "City"; locationSheet.Cells[1, 3] = "Province"; locationSheet.Cells[2, 1] = station.LocationOfInstalation.Id; locationSheet.Cells[2, 2] = station.LocationOfInstalation.City; locationSheet.Cells[2, 3] = station.LocationOfInstalation.Province; Worksheet temperatureSheet = (Worksheet)worksheets.Add(worksheets[3], Type.Missing, Type.Missing, Type.Missing); temperatureSheet.Name = "Temperature"; int i = 2; temperatureSheet.Cells[1, 1] = "Id"; temperatureSheet.Cells[1, 2] = "DateOfMeasuement"; temperatureSheet.Cells[1, 3] = "Unit"; temperatureSheet.Cells[1, 4] = "Value"; foreach (var item in station.TemperatureMeasurements) { temperatureSheet.Cells[i, 1] = item.Id; temperatureSheet.Cells[i, 2] = item.DateOfMeasuement; temperatureSheet.Cells[i, 3] = item.Unit; temperatureSheet.Cells[i, 4] = item.Value; i++; } Worksheet pressureSheet = (Worksheet)worksheets.Add(worksheets[4], Type.Missing, Type.Missing, Type.Missing); pressureSheet.Name = "Pressure"; i = 2; pressureSheet.Cells[1, 1] = "Id"; pressureSheet.Cells[1, 2] = "DateOfMeasuement"; pressureSheet.Cells[1, 3] = "Unit"; pressureSheet.Cells[1, 4] = "Value"; foreach (var item in station.PressureMeasurements) { pressureSheet.Cells[i, 1] = item.Id; pressureSheet.Cells[i, 2] = item.DateOfMeasuement; pressureSheet.Cells[i, 3] = item.Unit; pressureSheet.Cells[i, 4] = item.Value; i++; } Worksheet wetnessSheet = (Worksheet)worksheets.Add(worksheets[5], Type.Missing, Type.Missing, Type.Missing); wetnessSheet.Name = "Wetness"; i = 2; wetnessSheet.Cells[1, 1] = "Id"; wetnessSheet.Cells[1, 2] = "DateOfMeasuement"; wetnessSheet.Cells[1, 3] = "Unit"; wetnessSheet.Cells[1, 4] = "Value"; foreach (var item in station.WetnessMeasurements) { wetnessSheet.Cells[i, 1] = item.Id; wetnessSheet.Cells[i, 2] = item.DateOfMeasuement; wetnessSheet.Cells[i, 3] = item.Unit; wetnessSheet.Cells[i, 4] = item.Value; i++; } wb.SaveAs(station.Name); wb.Close(); }
public void RemoveStation(MeteoStation meteoStation, DataRepository dr) { removeMeasurementsByStationDeletion(meteoStation, dr); dr.meteoStationDbContext.MeteoStation.Remove(meteoStation); dr.meteoStationDbContext.SaveChanges(); }
/// <summary> /// Usuwa pomiar dla zadanej stacji. Obiekt DataRepository musi być ten sam, który został użyty do pobrania stacji, wiec należy go podać w parametrze. /// </summary> /// <param name="meteoStation"></param> /// <param name="dr"></param> private void removeMeasurementsByStationDeletion(MeteoStation meteoStation, DataRepository dr) { List<Measurement> list = new List<Measurement>(); dr.GetMeasurementsOfStation(meteoStation, this); foreach (var measurement in this.PressureList) { dr.meteoStationDbContext.Pressure.Remove(measurement); } foreach (var measurement in this.TemperatureList) { dr.meteoStationDbContext.Temperature.Remove(measurement); } foreach (var measurement in this.WetnessList) { dr.meteoStationDbContext.Wetness.Remove(measurement); } dr.meteoStationDbContext.SaveChanges(); }