protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["Name"] != null) { string FileName = Path.GetFileName(Request.QueryString["Name"]); Response.Clear(); Response.AppendHeader("Content-Disposition", "inline; filename=" + FileName + ".csv"); //Response.AppendHeader("Content-Disposition", "csv; Soils.csv"); Response.Buffer = false; Response.ContentType = "application/vnd.ms-excel"; // text/plain string SoilName = Request.QueryString["Name"]; ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service(); Soil Soil = Soil.Create(SoilsDB.SoilXML(SoilName)); DataTable Data = new DataTable(); SoilDataTable.SoilToTable(Soil, Data); Response.Write(DataTableUtility.DataTableToCSV(Data, 0)); Response.Flush(); // send our content to the client browser. Response.SuppressContent = true; // stops .net from writing it's stuff. } }
public void ConvertSoilToDataTable() { Soil Soil = new Soil(); Soil.ApsoilNumber = "100"; Soil.Water.Thickness = new double[] { 150.00, 150.00, 300.00, 300.00, 300.00 }; Soil.Water.BD = new double[] { 1.02, 1.03, 1.02, 1.02, 1.06 }; Soil.Water.BDMetadata = new string[] { "Field measured and checked for sensibility", "Laboratory measured", "", "", "" }; Soil.Water.AirDry = new double[] { 0.15, 0.26, 0.29, 0.29, 0.30 }; Soil.Water.LL15 = new double[] { 0.29, 0.29, 0.29, 0.29, 0.30 }; Soil.Water.DUL = new double[] { 0.54, 0.53, 0.54, 0.54, 0.52 }; Soil.Water.SAT = new double[] { 0.59, 0.58, 0.59, 0.58, 0.57 }; Soil.Water.Crops.Add(new SoilCrop() { Name = "Barley", Thickness = new double[] { 100.00, 100.00 }, LL = new double[] { 0.29, 0.25 }, KL = new double[] { 0.10, 0.08 }, XF = new double[] { 1.00, 1.00 } }); Soil.Water.Crops.Add(new SoilCrop() { Name = "Chickpea", Thickness = new double[] { 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00 }, LL = new double[] { 0.29, 0.29, 0.36, 0.43, 0.51, 0.50, 0.50, 0.48 }, KL = new double[] { 0.10, 0.10, 0.08, 0.06, 0.04, 0.02, 0.01, 0.00 }, XF = new double[] { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.00 } }); Soil.SoilOrganicMatter.Thickness = new double[] { 200.000, 200.00 }; Soil.SoilOrganicMatter.OC = new double[] { 1.040, 0.89 }; Soil.SoilOrganicMatter.FBiom = new double[] { 0.025, 0.02 }; Soil.SoilOrganicMatter.FInert = new double[] { 0.400, 0.89 }; Soil.InitialWater = new InitialWater(); Soil.InitialWater.SetSW(0.5, InitialWater.PercentMethodEnum.FilledFromTop); Soil.SoilWater = new SoilWater(); Soil.SoilWater.SummerCona = 3.5; Soil.SoilWater.WinterCona = 3.5; Soil.Analysis.Thickness = new double[] { 100, 100, 100 }; Soil.Analysis.EC = new double[] { 1.7, double.NaN, double.NaN }; DataTable Table = new DataTable(); SoilDataTable.SoilToTable(Soil, Table); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "Thickness (mm)"), Soil.Water.Thickness, 1); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "BD (g/cc)"), Soil.Water.BD, 0.01); Assert.AreEqual(DataTableUtility.GetColumnAsStrings(Table, "BDCode")[0], "FM"); Assert.AreEqual(DataTableUtility.GetColumnAsStrings(Table, "BDCode")[1], "LM"); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "Chickpea ll (mm/mm)"), new double[] { 0.29, 0.29, 0.36, 0.43, 0.51, 0.50, 0.50, 0.48 }, 0.01); Assert.AreEqual(DataTableUtility.GetColumnAsDoubles(Table, "Chickpea xf (0-1)"), new double[] { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.00 }, 0.01); }