For my job, i need to develop an web application in order to display a list of the jobs of some bank applications. Actually, the biggest part of this application have been done but I have to include a drop down list allowing to select the type of a job. I'm totally blocked on this point.
On my Index page, I have a list where some applications and their status (Job OK, KO, ...) are listed, the user can clic on the status (which is an image) of an application to display an other page where a list more detailed is displayed containing some informations in function of 2 parameters : application and id of the bank. Here is the link in my view :
<a href="@Url.Action("PageDomaines", new { Controller = "Suivi", CR = VarCR, Appli = VarAppli[j] })">
<img src="../../Content/Images/feu_rouge.png" alt="Statut OK" border="0" /></a>
The 2 parameters CR and Appli are passed to the URL from my View to the good action, after that, I do a query on them to get the list.
The problem is when I select a value in my drop down list located in the view of the action "PageDomaiens", the parameters are not kept, displaying an empty list. I'v done some test like verify if the value selected in my drop down list is send to my controller and it works, I can display the value selected in the view of "PageDomaines" but i don't keep my parameters CR and Appli...
Here is my action "PageDomaines" with my queries :
public ActionResult PageDomaines(string CR, string Appli, string DDL)
{
string GetCR = CR;
string GetAppli = Appli;
string GetDDL = DDL;
if (GetDDL == null)
{
var items = GetDomaines();
int Var1 = DateTime.Now.Year;
int Var2 = DateTime.Now.Month;
string Var3 = "" + Var1 + Var2;
var Query = (from i in items
where i.Field<String>("CD_APPLI") == GetAppli && i.Field<String>("CD_CR") == GetCR && i.Field<Int64>("PERIODE").ToString().Contains(Var3)
select new Suivi { CD_TRT = i.Field<String>("CD_TRT"), LB_TRT = i.Field<String>("LB_TRT"), CD_CR = i.Field<String>("CD_CR"), PERIODE = i.Field<Int64>("PERIODE"), CD_APPLI = i.Field<String>("CD_APPLI"), STATUT = i.Field<String>("STATUT") }).ToList();
ViewData["CR"] = GetCR;
ViewData["Appli"] = GetAppli;
return View(Query);
}
else
{
var items = GetDomaines();
int Var1 = DateTime.Now.Year;
int Var2 = DateTime.Now.Month;
string Var3 = "" + Var1 + Var2;
ViewData["DDL"] = GetDDL;
var Query = (from i in items
where i.Field<String>("CD_APPLI") == GetAppli && i.Field<String>("CD_CR") == GetCR && i.Field<Int64>("PERIODE").ToString().Contains(Var3) && i.Field<String>("CD_TRT").Trim() == GetDDL
select new Suivi { CD_TRT = i.Field<String>("CD_TRT"), LB_TRT = i.Field<String>("LB_TRT"), CD_CR = i.Field<String>("CD_CR"), PERIODE = i.Field<Int64>("PERIODE"), CD_APPLI = i.Field<String>("CD_APPLI"), STATUT = i.Field<String>("STATUT") }).ToList();
ViewData["CR"] = GetCR;
ViewData["Appli"] = GetAppli;
return View(Query);
}
}
private List<DataRow> GetDomaines()
{
List<DataRow> liste = null;
string query = "select CD_TRT, LB_TRT, CD_CR, PERIODE, CD_APPLI, case "
+ "when (exists (select 1 from dbo.LOGS l, dbo.REF_JOB j where j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.CD_CR = cr.CD_CR and l.STATUT = 'OK' and j.JR_EXEC >= DAY(l.DT_DEB))) "
+ "and not exists (select 1 from dbo.LOGS l, dbo.REF_JOB j where j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.CD_CR = cr.CD_CR and l.PERIODE = p.PERIODE "
+ "and ((j.JR_EXEC < DAY(l.DT_DEB) and l.DT_DEB is not null) or (l.STATUT in('KO','NEXEC')))) then 'OK' "
+ "when (exists(select 1 from dbo.LOGS l, dbo.REF_JOB j where j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.CD_CR = cr.CD_CR and l.PERIODE = p.PERIODE and j.JR_EXEC < DAY(l.DT_DEB) "
+ "and DAY(l.DT_DEB) IS not null and l.STATUT = 'KO')) then 'KO' "
+ "when (exists(select 1 from dbo.LOGS l, dbo.REF_JOB j where j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.CD_CR = cr.CD_CR and l.PERIODE = p.PERIODE "
+ "and j.JR_EXEC < DAY(l.DT_DEB) and DAY(l.DT_DEB) IS not null and l.STATUT in('OK','NEXEC'))) then 'EN COURS' "
+ "when (exists(select 1 from dbo.LOGS l, dbo.REF_JOB j where j.CD_JOB = l.CD_JOB and j.CD_TRT = t.CD_TRT and l.CD_CR = cr.CD_CR and l.PERIODE = p.PERIODE "
+ "and j.JR_EXEC < DAY(l.DT_DEB) and DAY(l.DT_DEB) IS not null)) then 'EN RETARD' else 'NON INITIE' end STATUT "
+ "from dbo.REF_TRT t, dbo.REF_CR cr, (select distinct PERIODE from dbo.LOGS) p ";
string connString = "Data Source=.;Initial Catalog=SUIVI_DWH;Integrated Security=True";
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand objCommand = new SqlCommand(query, conn))
{
objCommand.CommandType = CommandType.Text;
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(objCommand);
conn.Open();
adp.Fill(dt);
if (dt != null)
{
liste = dt.AsEnumerable().ToList();
}
}
}
return liste;
}
private List<DataRow> GetPERIODE()
{
List<DataRow> liste = null;
string query = "select distinct PERIODE from dbo.LOGS";
string connString = "Data Source=.;Initial Catalog=SUIVI_DWH;Integrated Security=True";
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand objCommand = new SqlCommand(query, conn))
{
objCommand.CommandType = CommandType.Text;
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(objCommand);
conn.Open();
adp.Fill(dt);
if (dt != null)
{
liste = dt.AsEnumerable().ToList();
}
}
}
return liste;
}
And the view of "PageDomaines" :
@model IEnumerable<SUIVI_DWH.Models.Suivi>
@using SUIVI_DWH.Helpers
@{
ViewBag.Title = "PageDomaines";
}
<h2>@ViewData["CR"]
@ViewData["Appli"]
@ViewData["DDL"]
</h2>
@using (Html.BeginForm("PageDomaines", "Suivi"))
{
@Html.DropDownList("DDL", new SelectList(new[] { "MMCR", "MMCL", "MMCO", "MMSE", "MMAS" }), "--Select one--", new { onchange = "this.form.submit();" })
}
<table>
<tr>
<th>
CD_TRT
</th>
<th>
LB_TRT
</th>
<th>
PERIODE
</th>
<th>
STATUT
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.CD_TRT
</td>
<td>
@item.LB_TRT
</td>
<td>
@item.PERIODE
</td>
<td>
@if (item.STATUT == null)
{
<img src="../../Content/Images/feu_croix.png" alt="Statut null" />
}
else if (item.STATUT == "KO")
{
<a href="@Url.Action("PageLogs", new { Controller = "Suivi", CR = ViewData["CR"], Appli = ViewData["Appli"], TRT = item.CD_TRT, PERIODE = item.PERIODE })">
<img src="../../Content/Images/feu_rouge.png" alt="Statut KO" border="0" /></a>
}
else if (item.STATUT == "OK")
{
<a href="@Url.Action("PageLogs", new { Controller = "Suivi", CR = ViewData["CR"], Appli = ViewData["Appli"], TRT = item.CD_TRT, PERIODE = item.PERIODE })">
<img src="../../Content/Images/feu_vert.png" alt="Statut OK" border="0" /></a>
}
else if (item.STATUT == "EN RETARD")
{
<a href="@Url.Action("PageLogs", new { Controller = "Suivi", CR = ViewData["CR"], Appli = ViewData["Appli"], TRT = item.CD_TRT, PERIODE = item.PERIODE })">
<img src="../../Content/Images/feu_orange.png" alt="Statut en retard" border="0" /></a>
}
else if (item.STATUT == "NON INITIE")
{
<a href="@Url.Action("PageLogs", new { Controller = "Suivi", CR = ViewData["CR"], Appli = ViewData["Appli"], TRT = item.CD_TRT, PERIODE = item.PERIODE })">
<img src="../../Content/Images/feu_blanc.png" alt="Statut non initié" border="0" /></a>
}
else if (item.STATUT == "EN COURS")
{
<a href="@Url.Action("PageLogs", new { Controller = "Suivi", CR = ViewData["CR"], Appli = ViewData["Appli"], TRT = item.CD_TRT, PERIODE = item.PERIODE })">
<img src="../../Content/Images/feu_jaune.png" alt="Statut en cours" border="0" /></a>
}
</td>
</tr>
}
</table>
I hope that i haven't forgot anything.
Do you have any suggestion to resolve this problem?