Advertisement
Guest User

dobo elalvo

a guest
Jan 20th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.IO;
  8.  
  9. namespace A14
  10. {
  11. public partial class Program : System.Web.UI.Page
  12. {
  13. string targetDirectory;
  14. List<Klasz> klasa = new List<Klasz>();
  15.  
  16. public void FillDatum() {
  17. String[] Files = Directory.GetFiles(targetDirectory, "*.txt");
  18. for (int x = 0; x < Files.Length; x++)
  19. {
  20. Files[x] = Path.GetFileNameWithoutExtension(Files[x]);
  21. DropDownList1.DataSource = Files;
  22. DropDownList1.DataBind();
  23. }
  24. }
  25. public void FillOsztaly()
  26. {
  27. using (StreamReader file = new StreamReader(targetDirectory + DropDownList1.SelectedItem + ".txt"))
  28. {
  29. string line;
  30. while ((line = file.ReadLine()) != null)
  31. {
  32. Klasz obj = new Klasz();
  33. string[] lineArray = line.Split('|').Select(item => item.Trim()).ToArray();
  34. obj.Ido = lineArray[0];
  35. obj.Cim = lineArray[1];
  36. obj.Tipus = lineArray[2];
  37. obj.Kep = lineArray[3];
  38. klasa.Add(obj);
  39. }
  40. }
  41. }
  42. public void FillDD2()
  43. {
  44. List<string> DDTIpus = new List<string>();
  45. using (StreamReader file = new StreamReader(targetDirectory + DropDownList1.SelectedItem + ".txt"))
  46. {
  47. string line;
  48. while ((line = file.ReadLine()) != null)
  49. {
  50. Klasz obj = new Klasz();
  51. string[] lineArray = line.Split('|').Select(item => item.Trim()).ToArray();
  52. obj.Tipus = lineArray[2];
  53. DDTIpus.Add(obj.Tipus);
  54. }
  55. }
  56. DropDownList2.DataSource = DDTIpus.Distinct();
  57. DropDownList2.DataBind();
  58. }
  59.  
  60. protected void Page_Load(object sender, EventArgs e)
  61. {
  62. targetDirectory = Server.MapPath("~/Text/");
  63. if (!IsPostBack)
  64. {
  65. FillDatum();
  66. FillDD2();
  67. }
  68. }
  69.  
  70. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  71. {
  72. FillDD2();
  73. }
  74.  
  75. protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
  76. {
  77.  
  78. }
  79.  
  80. protected void Button1_Click(object sender, EventArgs e)
  81. {
  82. List<Klasz> eredmeny = klasa;
  83. if (DropDownList1.SelectedIndex > -1)
  84. {
  85. FillOsztaly();
  86. if (DropDownList2.SelectedIndex > -1)
  87. {
  88. eredmeny = eredmeny.FindAll(i => i.Tipus.Contains(DropDownList2.SelectedItem.ToString()));
  89. }
  90. }
  91. GridView1.DataSource = eredmeny;
  92. GridView1.DataBind();
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement