Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // local variables
        int DtDays = 365;
        DateTime endDate = DateTime.Now.Date;
        DateTime startDate = endDate.AddDays(-DtDays);

        string chartUrl;
        string chartTitle;

        if ( !( Page.IsPostBack ) )
        {
            // initialize control values
            this.initialize();

            DataManager manager = new DataManager();

            // validate user input
            PageUrlValidator validator = new PageUrlValidator(Context.Request.QueryString, manager);
            validator.Validate();

            endDate = this.ResolveDate();
            startDate = this.SetPeriod(endDate);
            TimeInterval interval = new TimeInterval(startDate, endDate);

            //input is valid - get station and variable
            if ( validator.IsValidVariable )
            {
                SetupVariable(validator.Variable);
                // set values of StationListLink URL
                this.SetStationListUrl(validator.Variable);

                if ( validator.IsValidStation )
                {
                    SetupStation(validator.Station);
                }
            }

            //chart title..
            chartTitle = this.createChartTitle(validator, startDate, endDate);
            Master.PageTitle = chartTitle;

            // get station and variable (might not be valid)
            Variable varInfo = validator.Variable;
            Station stInfo = validator.Station;

            // set right url of the language hyperlink
            string LangPath = this.CreateLanguageLink(varInfo);
            Master.LanguageUrl = LangPath;

            // decide if we should use hourly or daily precipitation
            if ( varInfo.VarEnum == VariableEnum.Precip && interval.Length.TotalDays < 11)
            {

                if ( CheckHourlyPrecipAvailable(varInfo, stInfo, startDate, endDate, manager) )
                {
                    varInfo.VarEnum = VariableEnum.PrecipHour;
                }
            }

            // assign image url to the chart image
            chartUrl = this.createChartUrl(varInfo.ShortName, stInfo.StationId, startDate, endDate);
            nplot_image.Attributes["src"] = chartUrl;

            nplot_image.Attributes["alt"] = chartTitle;
            nplot_image.Attributes["title"] = chartTitle;

            // create the "statistics" window
            if ( validator.IsValid )
            {
                CreateStatistics(varInfo, stInfo, startDate, endDate, manager);
            }
        }
    }
Example #2
0
    // creates the string for page title and chart alternative text and meta-description
    private string createChartTitle(PageUrlValidator validator, DateTime start, DateTime end)
    {
        string varStr = "";
        string outStr = "";
        string noStationVariable = "";
        string errorMsg = "";
        CultureInfo cultInfo = Thread.CurrentThread.CurrentCulture;

        if ( validator.IsValidStation )
        {
            Station stInfo = validator.Station;
            Variable varInfo = validator.Variable;
            string stFullName = stInfo.Name;
            string stFullName2 = stInfo.Name;
            try
            {
                if (stInfo.River != null)
                {
                    if (stInfo.River.Name.Length > 0)
                    {
                        stFullName = stInfo.River + " - " + stFullName;
                        stFullName2 = stInfo.River + ", " + stFullName2;
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                stFullName2 = stFullName;
                //this is an exception
            }
            varStr = varInfo.Name;

            //check if it's a valid station-variable combination

            if (!validator.IsValidStationVariable)
            {
                noStationVariable = ( cultInfo.Name == "cs-CZ" ? " (chybí mìøení)" : " (no data)" );
                errorMsg = validator.ErrorMessage;
            }

            outStr = String.Format(@"{0}: {1}, {2} - {3} {4}",
                    varStr, stFullName, start.ToString(cultInfo.DateTimeFormat.ShortDatePattern,
                    cultInfo.DateTimeFormat),
                    end.ToString(cultInfo.DateTimeFormat.ShortDatePattern,
                    cultInfo.DateTimeFormat),
                    noStationVariable);

            // create main page heading ...
            H1.Text = string.Format("{0} - {1} {2}", varStr, stFullName2, noStationVariable);

            string stMetaName = ( cultInfo.Name == "cs-CZ" ? "ve stanici" : "in" );
            string riverName = "";
            string riverMetaName = "";
            if ( varInfo.VarEnum == VariableEnum.Stage | varInfo.VarEnum == VariableEnum.Discharge )
            {
                if ( stInfo.River != null )
                {
                    riverName = stInfo.River.Name;
                    riverMetaName = ( cultInfo.Name == "cs-CZ" ? "na øece " : "on the river " ) + riverName;
                }
            }

            // add meta content-language tag...
            Master.MetaLanguage =
                String.Format("\n<meta http-equiv='content-language' content='{0}' />\n",
                cultInfo.TwoLetterISOLanguageName);

            // add the meta description ...
            Master.MetaDescription =
                String.Format("<meta name='description' content='{0} {3} {1} {2}' />\n",
                varStr, stMetaName, stInfo.Name, riverMetaName);

            // add meta keywords ...
            Master.MetaKeywords =
                String.Format("<meta name='keywords' content='{0}, {1}, {2}' />\n",
                varStr, stInfo.Name, riverName);
        }
        else if ( validator.IsValidVariable )
        {
            // UNKNOWN station - STATION NOT FOUND .......

            errorMsg = validator.ErrorMessage;
            // create main page heading ...
            varStr = validator.Variable.Name;
            // create main page heading ...
            string noStationFound = ( cultInfo.Name == "cs-CZ" ? " (stanice nebyla nalezena)" : " (no station found)" );
            H1.Text = string.Format("{0} {1}", varStr, noStationVariable);

            outStr = String.Format(@"{0}: {1} {2}",
                    varStr, validator.Station.Name, noStationFound);

            // add meta content-language tag...
            Master.MetaLanguage =
                String.Format("\n<meta http-equiv='content-language' content='{0}' />\n",
                cultInfo.TwoLetterISOLanguageName);

            // add the meta description ...
            Master.MetaDescription =
                String.Format("<meta name='description' content='{0} {1} {2}' />\n",
                varStr, validator.Station.Name, noStationFound);

            // add meta keywords ...
            Master.MetaKeywords =
                String.Format("<meta name='keywords' content='{0}, {1}' />\n",
                varStr, noStationFound);

        }
        else
        {
            H1.Text = "ERROR - Bad variable specified!";
            outStr = validator.ErrorMessage;
        }
        return outStr;
    }