Advertisement
Guest User

Untitled

a guest
Oct 19th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. /* View för sök*/
  2. @using System.Data;
  3.  
  4. @{
  5. ViewBag.Title = "PUCKO";
  6. }
  7.  
  8. <div id=wrapper>
  9. <div id=header>
  10. <h1>Pucko</h1>
  11. <a href="@Url.Action("index", "Home")">Hem</a> <a href="@Url.Action("index", "Alien")">Aliens</a> <a href="@Url.Action("index", "Ras")">Raser</a> <a href="@Url.Action("index", "Vapen")">Vapen</a> <a class="active">Sök</a>
  12. </div>
  13.  
  14. <h2>Sök efter alien</h2>
  15. <form action="@Url.Action("Sokres", "Sok")" method="post">
  16. <input name="SokAlien" type="text" />
  17. <input type="submit" value="Sök" />
  18. </form>
  19.  
  20. <h2>Sök efter vapen</h2>
  21. <form action="@Url.Action("SokVapen", "Sok")" method="post">
  22. <input name="SokVapen" type="text" />
  23. <input type="submit" value="Sök" />
  24. </form>
  25.  
  26. </div>
  27.  
  28. /*View för resultat*/
  29.  
  30. @{
  31. ViewBag.Title = "Search result";
  32. }
  33.  
  34. <h2>Search result</h2>
  35. @if(ViewBag.SokAlienRes!=null && ((System.Data.DataTable)ViewBag.SokAlienRes).Rows.Count>0){
  36. <table>
  37. <tr>
  38. @foreach(var dataColumn in ViewBag.SokAlienRes.Columns){
  39. <th>@dataColumn.ColumnName</th>
  40. }
  41. </tr>
  42. @foreach (var alienRow in ViewBag.SokAlienRes.Rows)
  43. {
  44. <tr>
  45. @for (int i = 0; i < ViewBag.SokAlienRes.Columns.Count; ++i)
  46. {
  47. <td>@alienRow[i]</td>
  48. }
  49.  
  50. </tr>
  51. }
  52. </table>
  53. } else {
  54. <p>No search results found</p>
  55. }
  56.  
  57. @Html.ActionLink("<-- Back", "Index", "Home", null, new { title = "Go back to search form" })
  58.  
  59. /*Model*/
  60.  
  61. public DataTable SokAlienRes(string IDKod, string Rasnamn, string Farlighet)
  62. {
  63. MySqlConnection dbcon = new MySqlConnection(connectionString);
  64. dbcon.Open();
  65. MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM Alien WHERE IDKod LIKE @IDKod or Rasnamn LIKE @Rasnamn or Farlighet LIKE @Farlighet;", dbcon);
  66. adapter.SelectCommand.Parameters.AddWithValue("@IDKod", IDKod);
  67. adapter.SelectCommand.Parameters.AddWithValue("@Rasnamn", Rasnamn);
  68. adapter.SelectCommand.Parameters.AddWithValue("@Farlighet", Farlighet);
  69. DataSet ds = new DataSet();
  70. adapter.Fill(ds, "result");
  71. DataTable SokAlienTable = ds.Tables["result"];
  72. dbcon.Close();
  73. return SokAlienTable;
  74. }
  75.  
  76. /*Controller*/
  77. using System.Web.Mvc;
  78. using dbsk4.Models;
  79.  
  80. namespace dbsk4.Controllers
  81. {
  82. public class SokController : Controller
  83. {
  84. //
  85. // GET: /Home/
  86.  
  87. public ActionResult Index()
  88. {
  89. HomeModel sm = new HomeModel("cbserver.iit.his.se");
  90. ViewBag.AllVapenTable = sm.GetAllVapen();
  91. ViewBag.AllAlienTable = sm.GetAllAliens();
  92. ViewBag.AllRasTable = sm.GetAllRas();
  93.  
  94. return View();
  95. }
  96.  
  97. public ActionResult SokAlienRes(string IDKod, string Rasnamn, string Farlighet)
  98. {
  99. HomeModel sm = new HomeModel("cbserver.iit.his.se");
  100. ViewBag.SokAlienRes = sm.SokAlienRes(IDKod, Rasnamn, Farlighet);
  101. return View();
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement