Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* View för sök*/
- @using System.Data;
- @{
- ViewBag.Title = "PUCKO";
- }
- <div id=wrapper>
- <div id=header>
- <h1>Pucko</h1>
- <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>
- </div>
- <h2>Sök efter alien</h2>
- <form action="@Url.Action("Sokres", "Sok")" method="post">
- <input name="SokAlien" type="text" />
- <input type="submit" value="Sök" />
- </form>
- <h2>Sök efter vapen</h2>
- <form action="@Url.Action("SokVapen", "Sok")" method="post">
- <input name="SokVapen" type="text" />
- <input type="submit" value="Sök" />
- </form>
- </div>
- /*View för resultat*/
- @{
- ViewBag.Title = "Search result";
- }
- <h2>Search result</h2>
- @if(ViewBag.SokAlienRes!=null && ((System.Data.DataTable)ViewBag.SokAlienRes).Rows.Count>0){
- <table>
- <tr>
- @foreach(var dataColumn in ViewBag.SokAlienRes.Columns){
- <th>@dataColumn.ColumnName</th>
- }
- </tr>
- @foreach (var alienRow in ViewBag.SokAlienRes.Rows)
- {
- <tr>
- @for (int i = 0; i < ViewBag.SokAlienRes.Columns.Count; ++i)
- {
- <td>@alienRow[i]</td>
- }
- </tr>
- }
- </table>
- } else {
- <p>No search results found</p>
- }
- @Html.ActionLink("<-- Back", "Index", "Home", null, new { title = "Go back to search form" })
- /*Model*/
- public DataTable SokAlienRes(string IDKod, string Rasnamn, string Farlighet)
- {
- MySqlConnection dbcon = new MySqlConnection(connectionString);
- dbcon.Open();
- MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM Alien WHERE IDKod LIKE @IDKod or Rasnamn LIKE @Rasnamn or Farlighet LIKE @Farlighet;", dbcon);
- adapter.SelectCommand.Parameters.AddWithValue("@IDKod", IDKod);
- adapter.SelectCommand.Parameters.AddWithValue("@Rasnamn", Rasnamn);
- adapter.SelectCommand.Parameters.AddWithValue("@Farlighet", Farlighet);
- DataSet ds = new DataSet();
- adapter.Fill(ds, "result");
- DataTable SokAlienTable = ds.Tables["result"];
- dbcon.Close();
- return SokAlienTable;
- }
- /*Controller*/
- using System.Web.Mvc;
- using dbsk4.Models;
- namespace dbsk4.Controllers
- {
- public class SokController : Controller
- {
- //
- // GET: /Home/
- public ActionResult Index()
- {
- HomeModel sm = new HomeModel("cbserver.iit.his.se");
- ViewBag.AllVapenTable = sm.GetAllVapen();
- ViewBag.AllAlienTable = sm.GetAllAliens();
- ViewBag.AllRasTable = sm.GetAllRas();
- return View();
- }
- public ActionResult SokAlienRes(string IDKod, string Rasnamn, string Farlighet)
- {
- HomeModel sm = new HomeModel("cbserver.iit.his.se");
- ViewBag.SokAlienRes = sm.SokAlienRes(IDKod, Rasnamn, Farlighet);
- return View();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement