Beispiel #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdExecute_Click runs when the Execute button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [cnurse]	9/28/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void OnExecuteClick(object sender, EventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(txtQuery.Text))
                {
                    var connectionstring = Config.GetConnectionString(cboConnection.SelectedValue);
                    if (chkRunAsScript.Checked)
                    {
                        var strError = DataProvider.Instance().ExecuteScript(connectionstring, txtQuery.Text);
                        if (strError == Null.NullString)
                        {
                            UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("QuerySuccess", LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess);
                        }
                        else
                        {
                            UI.Skins.Skin.AddModuleMessage(this, strError, ModuleMessage.ModuleMessageType.RedError);
                        }
                    }
                    else
                    {
                        try
                        {
                            var dr = DataProvider.Instance().ExecuteSQLTemp(connectionstring, txtQuery.Text);
                            if (dr != null)
                            {
                                var tables = new List <DataTable>();
                                do
                                {
                                    var table = new DataTable {
                                        Locale = CultureInfo.CurrentCulture
                                    };
                                    table.Load(dr);
                                    tables.Add(table);
                                }while (!dr.IsClosed); // table.Load automatically moves to the next result and closes the reader once there are no more

                                ResultsRepeater.DataSource = tables;
                                ResultsRepeater.DataBind();

                                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("QuerySuccess", LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess);
                            }
                            else
                            {
                                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("QueryError", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                            }
                        }
                        catch (SqlException sqlException)
                        {
                            UI.Skins.Skin.AddModuleMessage(this, sqlException.Message, ModuleMessage.ModuleMessageType.RedError);
                            return;
                        }
                    }
                    RecordAuditEventLog(txtQuery.Text);
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var segments = Request.GetFriendlyUrlSegments();

            LibrarySystemDbContext data = new LibrarySystemDbContext();

            if (segments.Count == 0)
            {
                var results = data.Books.ToList();

                ResultsRepeater.DataSource = results;
                ResultsRepeater.DataBind();
            }
            else
            {
                var query = segments[0];

                if (query.Length > 100)
                {
                    ErrorSuccessNotifier.AddErrorMessage("Search query cannot be more than 100 characters");
                    Response.Redirect("~/");
                }

                var results = data.Books
                              .Where(x => x.Title.Contains(query) || x.Authors.Contains(query))
                              .OrderBy(x => x.Title)
                              .ThenBy(x => x.Authors)
                              .ToList();

                ResultsRepeater.DataSource = results;
                ResultsRepeater.DataBind();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int currentPage = SearchResultsManager.CurrentPage();

            bool hasNextPage = currentPage < TotalPages;

            PreviousUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(currentPage - 1)
            };

            FirstUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(0)
            };

            LastUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(TotalPages)
            };

            NextUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(currentPage + 1)
            };

            if (currentPage == 0)
            {
                FirstUrl.CssClass = PreviousUrl.CssClass = "disabled";
                FirstUrl.ItemUrl  = PreviousUrl.ItemUrl = "#";
            }

            if (!hasNextPage)
            {
                LastUrl.CssClass = NextUrl.CssClass = "disabled";
                LastUrl.ItemUrl  = NextUrl.ItemUrl = "#";
            }

            List <PaginationEntry> entries = new List <PaginationEntry>();

            for (int i = 0; i <= TotalPages; i++)
            {
                entries.Add(new PaginationEntry
                {
                    ItemUrl  = SearchResultsManager.SetPage(i),
                    Text     = (i + 1).ToString(),
                    CssClass = i == currentPage ? "active" : ""
                });
            }

            if (entries.Count > MaxPaginationEntries)
            {
                entries = CenterEntries(entries, currentPage).ToList();
            }

            ResultsRepeater.DataSource = entries;

            ResultsRepeater.DataBind();
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         ResultsRepeater.DataSource = SearchRecipies(5);
         ResultsRepeater.DataBind();
     }
 }
    private void WriteSearchModel(RecipeSearchResultModel model)
    {
        ResultsRepeater.DataSource = model.Items;
        ResultsRepeater.DataBind();

        NextBtn.Visible     = model.NextPage.HasValue;
        PreviousBtn.Visible = model.PrevPage.HasValue;

        CurrentPage.Value   = model.Page.ToString();
        PageDisplay.Text    = model.Page.ToString();
        MaxPageDisplay.Text = model.MaxPages.ToString();
        MaxPerPage.Value    = model.ResultCount.ToString();

        if (model.MaxResultCount > 0)
        {
            int a   = (int)model.MaxResultCount;
            int end = model.ResultEndIndex > a ? a : model.ResultEndIndex;
            ResultsOfDisplay.Text = string.Format("({0}-{1} of {2})", model.ResultStartIndex, end, model.MaxResultCount);
        }
        else
        {
            ResultsOfDisplay.Text = "0 results";
        }
    }