Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using CC.XDocs.Data.Documents;
- using System;
- using System.Linq;
- using System.Data;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace XDocs
- {
- public partial class Search : System.Web.UI.Page
- {
- #region Private Fields
- // Initialize clsDDOcuments
- private clsDDocuments clsDDocuments = new clsDDocuments();
- // TODO: Implement logic for keeping the last selected item
- // for all the dropdown lists
- private int categoriesDropDownListLastSelectedIndex = 0;
- private int typesDropDownListLastSelectedIndex = 0;
- private int usersDropDownListLastSelectedIndex = 0;
- private int statusesDropDownListLastSelectedIndex = 0;
- #endregion
- #region Public Methods
- // Allows rendering the GridView without being in a form tag
- public override void VerifyRenderingInServerForm(Control control)
- {
- //base.VerifyRenderingInServerForm(control);
- }
- #endregion
- #region Protected Methods
- protected void Page_Load(object sender, EventArgs e)
- {
- LoadPage();
- }
- // Shows or hides the advanced search menu
- protected void btn_ShowAdvancedSearch_Click(object sender, EventArgs e)
- {
- if (this.btn_ShowAdvancedSearch.Text == "Show Advanced Search")
- {
- this.btn_ShowAdvancedSearch.Text = "Hide Advanced Search";
- }
- else
- {
- this.btn_ShowAdvancedSearch.Text = "Show Advanced Search";
- }
- this.advancedSearchRow2.Visible ^= true;
- this.advancedSearchRow1.Visible ^= true;
- }
- #endregion
- #region Private Methods
- private void LoadPage()
- {
- this.FillPopupMenuStatusDropDownList();
- this.FillPopupMenuCategoriesDropDownList();
- //// Fills the DropDownList with all categories and databinds them
- //this.FillCategoriesDropDownList();
- // Fills the DropDownList with all types and databinds them
- //this.FillTypesDropDownList();
- // If the page is first loaded
- if (!this.Page.IsPostBack)
- {
- // Fills the DropDownList with all Categories and databinds them
- this.FillCategoriesDropDownList();
- // Fills the DropDownList with all Users and databinds them
- this.FillUsersDropDownList();
- // Π’he advanced search menu stays hidden
- this.advancedSearchRow2.Visible = false;
- this.advancedSearchRow1.Visible = false;
- // Fills the GridView with all documents from the db when
- // the page is first loaded and no search criteria is chosen
- this.FillDocumentsGridView();
- }
- }
- //private void FillTypesDropDownList()
- //{
- // // Gets the table with all file paths
- // DataTable typesTable = this.clsDDocuments.AllTypes();
- // // Gets the files extensions as a string array
- // string[] types = this.GetFileTypes(typesTable.Rows);
- // // Binds the data source
- // this.dropDownTypes.DataSource = types;
- // this.dropDownTypes.DataBind();
- //}
- private void FillPopupMenuCategoriesDropDownList()
- {
- DataTable allCategories = clsDDocuments.AllCategories();
- string[] categories = this.ConvertToStringsFromDataRowCollection(allCategories.Rows, string.Empty);
- this.popUpDropDownCategories.DataSource = categories;
- this.popUpDropDownCategories.DataBind();
- }
- private void FillPopupMenuStatusDropDownList()
- {
- DataTable allStatuses = clsDDocuments.AllStatuses();
- string[] statuses = this.ConvertToStringsFromDataRowCollection(allStatuses.Rows, string.Empty);
- this.popUpDropDownStatuses.DataSource = statuses;
- this.popUpDropDownStatuses.DataBind();
- }
- private void FillCategoriesDropDownList()
- {
- // Gets all categories from the db
- DataTable allCategories = clsDDocuments.AllCategories();
- // Converts them as strings for the DropDownList
- string[] categories = ConvertToStringsFromDataRowCollection(allCategories.Rows, "All Categories");
- // Binds the data source
- this.dropDownCategories.DataSource = categories;
- this.dropDownCategories.DataBind();
- }
- private void FillDocumentsGridView()
- {
- // Binds the data source
- this.gridDocuments.DataSource = clsDDocuments.AllDocuments();
- this.gridDocuments.DataBind();
- }
- //TODO: make the method DataTable allUsers = clsDDocuments.AllCategories(); ->AllUsers in DDocuments;
- private void FillUsersDropDownList()
- {
- // Gets all users from the db
- DataTable allUsers = clsDDocuments.AllUsers();
- // Converts them as strings for the DropDownList
- string[] users = ConvertToStringsFromDataRowCollection(allUsers.Rows, "All Users");
- // Binds the data source
- this.dropDownUsers.DataSource = users;
- this.dropDownUsers.DataBind();
- }
- private string[] ConvertToStringsFromDataRowCollection(DataRowCollection rows, string firstRowValue)
- {
- string[] array = new string[rows.Count + 1];
- array[0] = firstRowValue;
- int index = 1;
- foreach (DataRow category in rows)
- {
- array[index++] = category.ItemArray[0].ToString();
- }
- return array;
- }
- private string[] GetFileTypes(DataRowCollection rows)
- {
- string[] types = new string[rows.Count + 1];
- types[0] = "All types";
- int index = 1;
- foreach (DataRow row in rows)
- {
- string rowString = row.ItemArray[0].ToString();
- string fileExtension = rowString.Split('.').Last();
- types[index++] = fileExtension.ToUpper();
- }
- return types.Distinct().ToArray();
- }
- #endregion
- #region OnClick Methods
- protected void btn_Search_Click(object sender, EventArgs e)
- {
- this.gridDocuments.DataSource = this.clsDDocuments.SelectedCategory(dropDownCategories.SelectedValue);
- this.gridDocuments.DataBind();
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement