Exemplo n.º 1
0
        public DataTable getChartDataForExport(DTOchart objparams, string chartName, string cultureCode, DataTable agriInfoData)
        {
            culture = cultureCode;
            objGparams = objparams;
            getPubSettings(chartName, agriInfoData);
            if (agriInfoData != null)
                dtData = getData(dsData.Tables[ChartSerie], temporalAgg, dtSource, _start, _end, true).Item1.Copy();
            else
                dtData = getData(dsData.Tables[ChartSerie], temporalAgg, dtSource, _start, _end, false).Item1.Copy();

            dtData.TableName = "ChartData";

            return dtData;
        }
Exemplo n.º 2
0
        public void getChartData(DTOchart objparams, string chartName, string cultureCode, DataTable agriInfoData)
        {
            culture = cultureCode;
            objGparams = objparams;
            cName = chartName;
            getPubSettings(chartName, agriInfoData);
            var output = new Tuple<DataTable, FeatureResponse>(null, null);
            if (agriInfoData != null && agriInfoData.Rows.Count > 0)
            {
                objServiceInfo = (ServiceInfo)HttpContext.Current.Session["serviceInfo"];
                objSvcPre.ChangeUnits(agriInfoData, objServiceInfo.Unit, objServiceInfo.WUnit);
                if (HttpContext.Current.Session["IAgriInfo"] != null)
                {
                    agriInfo = (Dictionary<string, string>)HttpContext.Current.Session["IAgriInfo"];

                }
                /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/
                //if (bool.Parse(agriInfo["IsGDD"].ToString()) && cName.ToLower() == "gdd")
                if (bool.Parse(agriInfo["IsGDD"].ToString())
                    && (cName.ToLower() == "gdd" || cName.ToLower() == "watermodel"))
                /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/
                {
                    DataTable dtCombined = null;
                    /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/
                    switch (cName.ToLower())
                    {
                        case "gdd":
                            //DataTable dtCombined = GDD.RulesetSeriesList;
                            dtCombined = GDD.RulesetSeriesList;
                            /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/

                            //If GDD includes non-gdd series for markers/shaders
                            //combine the datatable from agriinfo and the datatable
                            //returned by the GDD ruleset and fetch data using the combined datatable

                            /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/
                            break;
                        case "watermodel":
                            dtCombined = BorderWaterModel.RulesetSeriesList;
                            break;

                    }
                    /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/

                    if (dsData.Tables[ChartSerie].Rows.Count > 1)
                    {
                        for (int i = 1; i < dsData.Tables[ChartSerie].Rows.Count; i++)
                        {
                            DataRow dr = dtCombined.NewRow();
                            dr[0] = dsData.Tables[ChartSerie].Rows[i][0].ToString();
                            dtCombined.Rows.Add(dr);
                        }
                    }
                    output = getData(dtCombined, temporalAgg, dtSource, _start, _end, true);
                    dtData = output.Item1.Copy();

                }
                else
                {
                    output = getData(dsData.Tables[ChartSerie], temporalAgg, dtSource, _start, _end, true);
                    dtData = output.Item1.Copy();
                }

                /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/
                // check the data table, if there is DBNull in cell value, change it to 0

                if (objServiceInfo.ServiceName != "geotroll1")
                {
                    foreach (DataRow row in dtData.Rows)
                    {
                        for (var i = 1; i < dtData.Columns.Count; i++)
                        {
                            if (row[i] == DBNull.Value)
                                row[i] = 0;
                        }
                    }
                }
                dtData.AcceptChanges();
                //if (bool.Parse(agriInfo["IsGDD"].ToString()) && cName.ToLower() == "gdd")
                if (bool.Parse(agriInfo["IsGDD"].ToString())
                         && (cName.ToLower() == "gdd" || cName.ToLower() == "watermodel"))
                /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/
                {
                    /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/
                    switch (cName.ToLower())
                    {
                        case "gdd":
                            /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/

                            DataTable dtDataRuleset;
                            GDD.dtInput = dtData;
                            GDD.Base = Int32.Parse(agriInfo["Base"]);
                            GDD.Cap = Int32.Parse(agriInfo["Cap"]);
                            GDD.Method = agriInfo["Method"];
                            GDD.CalculateGDD();

                            dtDataRuleset = GDD.dtOutput;

                            //Merge the data returned by the ruleset columns(dtDataRuleset) and the non-gdd series(dtData)
                            DataTable targetTable = dtDataRuleset.Clone();
                            var dt2Columns = dtData.Columns.OfType<DataColumn>().Select(dc =>
                            new DataColumn(dc.ColumnName, dc.DataType, dc.Expression, dc.ColumnMapping));
                            var dt2FinalColumns = from dc in dt2Columns.AsEnumerable()
                                                  where targetTable.Columns.Contains(dc.ColumnName) == false
                                                  select dc;
                            targetTable.Columns.AddRange(dt2FinalColumns.ToArray());

                            var rowData = from row1 in dtDataRuleset.AsEnumerable()
                                          join row2 in dtData.AsEnumerable()
                                          on row1.Field<DateTime>("date") equals row2.Field<DateTime>("date")
                                          select row1.ItemArray.Concat(row2.ItemArray.Where(r2 => row1.ItemArray.Contains(r2) == false)).ToArray();
                            foreach (object[] values in rowData)
                                targetTable.Rows.Add(values);

                            dtData = targetTable;
                            dtData.Columns.Remove(GDD.RulesetSeriesList.Rows[0][0].ToString());
                            dtData.Columns.Remove(GDD.RulesetSeriesList.Rows[1][0].ToString());

                            dtData.TableName = "ChartData";
                            dsData.Tables.Add(dtData);
                            setParamGDD(dsData);

                            /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/
                            break;
                        case "watermodel":

                            BorderWaterModel.dtInput = dtData;
                            BorderWaterModel.Base = Int32.Parse(agriInfo["Base"]);
                            BorderWaterModel.Cap = Int32.Parse(agriInfo["Cap"]);
                            BorderWaterModel.Method = agriInfo["Method"];

                            double TopSoilWHC = 0.0, TopSoilDepth = 0.0, SubSoilWHC = 0.0, SubSoilDepth = 0.0;
                            if (agriInfo.ContainsKey("TopSoilWHC"))
                                TopSoilWHC = double.Parse(agriInfo["TopSoilWHC"]);
                            if (agriInfo.ContainsKey("TopSoilDepth"))
                                TopSoilDepth = double.Parse(agriInfo["TopSoilDepth"]);
                            if (agriInfo.ContainsKey("SubSoilWHC"))
                                SubSoilWHC = double.Parse(agriInfo["SubSoilWHC"]);
                            if (agriInfo.ContainsKey("SubSoilDepth"))
                                SubSoilDepth = double.Parse(agriInfo["SubSoilDepth"]);

                            if (TopSoilWHC > 0 && TopSoilDepth > 0 && SubSoilWHC > 0)
                            {
                                BorderWaterModel.GridID = wRes.FeatureResponse.FeatureResponseId;
                                BorderWaterModel.Latitude = wRes.FeatureResponse.Latitude;
                                BorderWaterModel.TopSoilDepth = TopSoilDepth;
                                BorderWaterModel.TopSoilWHC = TopSoilWHC;
                                BorderWaterModel.SubSoilDepth = SubSoilDepth;
                                BorderWaterModel.SubSoilWHC = SubSoilWHC;

                                /* UAT Issue - Data from Mar 1st & from Mar 6th, the moisture value are not correct - Jerrey - Start */
                                //BorderWaterModel.StartDate = startDate;
                                BorderWaterModel.StartDate = DateTime.Parse(agriInfo["startDate"].ToString());
                                /* UAT Issue - Data from Mar 1st & from Mar 6th, the moisture value are not correct - Jerrey - End */
                                BorderWaterModel.EndDate = DateTime.Parse(agriInfo["endDate"].ToString());

                                BorderWaterModel.CalculateBWM();

                                dtData = BorderWaterModel.dtOutput;
                                dtData.TableName = "ChartData";

                                dsData.Tables.Add(dtData);
                                setParamBWM(dsData);
                            }
                            else
                            {
                                throw new System.InvalidOperationException(Constants.AGRIINFO_HAPPLY_NOSETTINGS);
                            }
                            break;
                    }
                    /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/
                }
                else
                {
                    dtData.TableName = "ChartData";
                    dsData.Tables.Add(dtData);
                    setParamsHistory(dsData, output.Item2);
                }
            }
            else
            {
                if (HttpContext.Current != null)
                {
                    // Change in units handled here for all the tables
                    foreach (DataTable dt in dsData.Tables)
                    {
                        objServiceInfo = (ServiceInfo)HttpContext.Current.Session["serviceInfo"];
                        objSvcPre.ChangeUnits(dt, objServiceInfo.Unit, objServiceInfo.WUnit);
                    }
                }
                dtData = getData(dsData.Tables[ChartSerie], temporalAgg, dtSource, _start, _end, false).Item1.Copy();

                dtData.TableName = "ChartData";
                dsData.Tables.Add(dtData);
                setParams(dsData);
            }
        }