Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. using CC.XDocs.Data.Documents;
  2. using System;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace XDocs
  9. {
  10. public partial class Search : System.Web.UI.Page
  11. {
  12. #region Private Fields
  13.  
  14. // Initialize clsDDOcuments
  15. private clsDDocuments clsDDocuments = new clsDDocuments();
  16.  
  17. // TODO: Implement logic for keeping the last selected item
  18. // for all the dropdown lists
  19. private int categoriesDropDownListLastSelectedIndex = 0;
  20. private int typesDropDownListLastSelectedIndex = 0;
  21. private int usersDropDownListLastSelectedIndex = 0;
  22. private int statusesDropDownListLastSelectedIndex = 0;
  23.  
  24. #endregion
  25.  
  26. #region Public Methods
  27.  
  28. // Allows rendering the GridView without being in a form tag
  29. public override void VerifyRenderingInServerForm(Control control)
  30. {
  31. //base.VerifyRenderingInServerForm(control);
  32. }
  33.  
  34. #endregion
  35.  
  36. #region Protected Methods
  37.  
  38. protected void Page_Load(object sender, EventArgs e)
  39. {
  40. LoadPage();
  41. }
  42.  
  43. // Shows or hides the advanced search menu
  44. protected void btn_ShowAdvancedSearch_Click(object sender, EventArgs e)
  45. {
  46. if (this.btn_ShowAdvancedSearch.Text == "Show Advanced Search")
  47. {
  48. this.btn_ShowAdvancedSearch.Text = "Hide Advanced Search";
  49. }
  50. else
  51. {
  52. this.btn_ShowAdvancedSearch.Text = "Show Advanced Search";
  53. }
  54. this.advancedSearchRow2.Visible ^= true;
  55. this.advancedSearchRow1.Visible ^= true;
  56. }
  57. #endregion
  58.  
  59. #region Private Methods
  60.  
  61. private void LoadPage()
  62. {
  63. this.FillPopupMenuStatusDropDownList();
  64. this.FillPopupMenuCategoriesDropDownList();
  65.  
  66. //// Fills the DropDownList with all categories and databinds them
  67. //this.FillCategoriesDropDownList();
  68.  
  69. // Fills the DropDownList with all types and databinds them
  70. //this.FillTypesDropDownList();
  71.  
  72. // If the page is first loaded
  73. if (!this.Page.IsPostBack)
  74. {
  75. // Fills the DropDownList with all Categories and databinds them
  76. this.FillCategoriesDropDownList();
  77.  
  78. // Fills the DropDownList with all Users and databinds them
  79. this.FillUsersDropDownList();
  80.  
  81. // Π’he advanced search menu stays hidden
  82. this.advancedSearchRow2.Visible = false;
  83. this.advancedSearchRow1.Visible = false;
  84.  
  85. // Fills the GridView with all documents from the db when
  86. // the page is first loaded and no search criteria is chosen
  87. this.FillDocumentsGridView();
  88. }
  89.  
  90.  
  91. }
  92.  
  93. //private void FillTypesDropDownList()
  94. //{
  95. // // Gets the table with all file paths
  96. // DataTable typesTable = this.clsDDocuments.AllTypes();
  97.  
  98. // // Gets the files extensions as a string array
  99. // string[] types = this.GetFileTypes(typesTable.Rows);
  100.  
  101. // // Binds the data source
  102. // this.dropDownTypes.DataSource = types;
  103. // this.dropDownTypes.DataBind();
  104. //}
  105.  
  106. private void FillPopupMenuCategoriesDropDownList()
  107. {
  108. DataTable allCategories = clsDDocuments.AllCategories();
  109.  
  110. string[] categories = this.ConvertToStringsFromDataRowCollection(allCategories.Rows, string.Empty);
  111.  
  112. this.popUpDropDownCategories.DataSource = categories;
  113. this.popUpDropDownCategories.DataBind();
  114. }
  115.  
  116. private void FillPopupMenuStatusDropDownList()
  117. {
  118. DataTable allStatuses = clsDDocuments.AllStatuses();
  119.  
  120. string[] statuses = this.ConvertToStringsFromDataRowCollection(allStatuses.Rows, string.Empty);
  121.  
  122. this.popUpDropDownStatuses.DataSource = statuses;
  123. this.popUpDropDownStatuses.DataBind();
  124. }
  125.  
  126. private void FillCategoriesDropDownList()
  127. {
  128. // Gets all categories from the db
  129. DataTable allCategories = clsDDocuments.AllCategories();
  130.  
  131. // Converts them as strings for the DropDownList
  132. string[] categories = ConvertToStringsFromDataRowCollection(allCategories.Rows, "All Categories");
  133.  
  134. // Binds the data source
  135. this.dropDownCategories.DataSource = categories;
  136. this.dropDownCategories.DataBind();
  137. }
  138.  
  139. private void FillDocumentsGridView()
  140. {
  141. // Binds the data source
  142. this.gridDocuments.DataSource = clsDDocuments.AllDocuments();
  143. this.gridDocuments.DataBind();
  144. }
  145.  
  146. //TODO: make the method DataTable allUsers = clsDDocuments.AllCategories(); ->AllUsers in DDocuments;
  147. private void FillUsersDropDownList()
  148. {
  149. // Gets all users from the db
  150. DataTable allUsers = clsDDocuments.AllUsers();
  151.  
  152. // Converts them as strings for the DropDownList
  153. string[] users = ConvertToStringsFromDataRowCollection(allUsers.Rows, "All Users");
  154.  
  155. // Binds the data source
  156. this.dropDownUsers.DataSource = users;
  157. this.dropDownUsers.DataBind();
  158. }
  159.  
  160.  
  161.  
  162. private string[] ConvertToStringsFromDataRowCollection(DataRowCollection rows, string firstRowValue)
  163. {
  164. string[] array = new string[rows.Count + 1];
  165.  
  166. array[0] = firstRowValue;
  167.  
  168. int index = 1;
  169. foreach (DataRow category in rows)
  170. {
  171. array[index++] = category.ItemArray[0].ToString();
  172. }
  173.  
  174. return array;
  175. }
  176.  
  177. private string[] GetFileTypes(DataRowCollection rows)
  178. {
  179. string[] types = new string[rows.Count + 1];
  180.  
  181. types[0] = "All types";
  182.  
  183. int index = 1;
  184. foreach (DataRow row in rows)
  185. {
  186. string rowString = row.ItemArray[0].ToString();
  187. string fileExtension = rowString.Split('.').Last();
  188.  
  189. types[index++] = fileExtension.ToUpper();
  190. }
  191.  
  192. return types.Distinct().ToArray();
  193. }
  194.  
  195. #endregion
  196.  
  197. #region OnClick Methods
  198. protected void btn_Search_Click(object sender, EventArgs e)
  199. {
  200. this.gridDocuments.DataSource = this.clsDDocuments.SelectedCategory(dropDownCategories.SelectedValue);
  201. this.gridDocuments.DataBind();
  202. }
  203. #endregion
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement