using System; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Collections.Generic; using System.Collections; //using System.Windows.Forms; using GCE.Framework.Contexte; using GCE.Framework.Exceptions; using GCE.ODSCHARC.Dialogue.ProxySynthese; using System.Collections.Specialized; public partial class Pages_Synthese : Page { //protected void Page_PreInit(object sender, EventArgs e) //{ // if (!IsPostBack) // { // Response.Write("Page_PreInit
"); // } // else // { // Response.Write("Page_PreInit IsPostBack
"); // } //} //protected void Page_Init(object sender, EventArgs e) //{ // Response.Write("Page_Init
"); //} /// /// Initialisation de la page /// /// /// /// protected void Page_Load(object sender, EventArgs e) { //Response.Write("Page_Load
"); btEffacer.Attributes["OnClick"] = EffacerJScript(); if (!IsPostBack) { if (ContexteManager.Requete["CritereRecherchePeriode"] != null && ContexteManager.Requete["CritereRechercheFlux"] != null) { // Cas qui correspond à un retour sur la page recherche après une consultation. // On récupère les critères de recherche et l'OdsPrescripteur relance la méthode Recherche pour afficher // le même résultat. lstPeriode.SelectedValue = ContexteManager.Requete["CritereRecherchePeriode"].ToString(); lstFlux.SelectedValue = ContexteManager.Requete["CritereRechercheFlux"].ToString(); } } } //protected void Page_UnLoad(object sender, EventArgs e) //{ // gvSynthese.DataSourceID = String.Empty; // fvSynthese.DataSourceID = String.Empty; //} #region Gestion ObjectDataSource protected void ods_Selected(object sender, EventArgs e) { Response.Write("ods_Selected " + odsSynthese.SelectParameters[2].DefaultValue + "
"); } protected void ods_CatchException(object sender, ObjectDataSourceStatusEventArgs e) { Exception exception = e.Exception; if (exception != null) { if (exception.InnerException is MetierException) { usrZoneMessageListe.Libelle = exception.InnerException.Message; e.ExceptionHandled = true; } } } #endregion #region Gestion GridView protected void GridView_Init(object sender, EventArgs e) { gvSynthese.DataSourceID = "odsSynthese"; } /// /// Méthode utilisée pour déterminer le nombre d'enregistrements, /// contenus dans la gridView. /// /// /// protected void GridView_DataBound(object sender, EventArgs e) { lblResultats.Text = Tools.ChaineResultatsGridView(gvSynthese, Page.IsPostBack); } /// /// A la création de chauq eligne du gridView, regarde si'il s'agit d'un Synthese /// et dans ce cas, permet l'édition de l'item. Dans le cas contraire, s'il s'git d'une synthese Attendue, /// déactive l'option d'édition sur l'item /// /// /// protected void GridView_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { SyntheseInfo _monObjet = (SyntheseInfo)e.Row.DataItem; if (_monObjet.Id == 0) { ImageButton _image = (ImageButton)e.Row.Cells[0].FindControl("btSelect"); _image.ImageUrl = "~/_FrameworkUI/_Images/Defaut/actVoirDetailInactif.png"; _image.Style.Add(HtmlTextWriterStyle.Cursor, "default"); _image.Enabled = false; } } // Use the RowType property to determine whether the // row being created is the header row. if (e.Row.RowType == DataControlRowType.Header) { // Call the GetSortColumnIndex helper method to determine // the index of the column being sorted. int sortColumnIndex = Tools.GetSortColumnIndex(gvSynthese); if (sortColumnIndex != -1) { // Call the AddSortImage helper method to add // a sort direction image to the appropriate // column header. Tools.AddSortImage(gvSynthese.SortDirection, sortColumnIndex, e.Row); } } } protected void GridView_Sorting(object sender, GridViewSortEventArgs e) { Response.Write(odsSynthese.SelectParameters[2].DefaultValue + "
"); if (odsSynthese.SelectParameters[2].DefaultValue == null || odsSynthese.SelectParameters[2].DefaultValue.IndexOf(e.SortExpression) == -1) { odsSynthese.SelectParameters[2].DefaultValue = e.SortExpression + " ASC"; } else if (odsSynthese.SelectParameters[2].DefaultValue.IndexOf(e.SortExpression) != -1) { odsSynthese.SelectParameters[2].DefaultValue = e.SortExpression + " DESC"; } //We have to do this or we will get an this exception //The data source 'odsSynthese' does not support sorting with IEnumerable data. Automatic sorting is only supported with DataView, DataTable, and DataSet. e.Cancel = true; Response.Write(odsSynthese.SelectParameters[2].DefaultValue + "
"); Cache.Remove(odsSynthese.CacheKeyDependency); gvSynthese.DataBind(); } protected void GridView_PageIndexChanging(object sender, EventArgs e) { fvSynthese.PageIndex = -1; fvSynthese.ChangeMode(FormViewMode.ReadOnly); gvSynthese.SelectedIndex = -1; } /// /// Récupère la ligne sélectionnée. /// Ouvre le formView en mode édition sur l'item sélectionné. /// /// /// protected void GridView_SelectedIndexChanged(object sender, EventArgs e) { fvSynthese.PageIndex = gvSynthese.SelectedIndex + (gvSynthese.PageIndex * gvSynthese.PageSize); fvSynthese.ChangeMode(FormViewMode.Edit); System.Web.UI.WebControls.Button _submit = (System.Web.UI.WebControls.Button)fvSynthese.FindControl("btModifier"); if (_submit != null) { _submit.Attributes["OnClick"] = UpdateJScript(); } //Scroll(); } #endregion #region Gestion FormView protected void FormView_Init(object sender, EventArgs e) { fvSynthese.DataSourceID = "odsSynthese"; } protected void FormView_RowUpdating(object sender, FormViewUpdateEventArgs e) { Boolean _isValid = true; if (!String.IsNullOrEmpty(e.NewValues[0].ToString())) { try { e.NewValues[0] = Convert.ToDateTime(e.NewValues[0].ToString()); } catch (Exception) { _isValid = false; usrZoneMessageDetail.Libelle += "La date de l'audio doit avoir comme format jj/mm/aaaa
"; } } else { e.NewValues[0] = null; } if (!_isValid) { e.Cancel = true; } } /// /// Après la Maj d'un item dans le formView, retour au mode par défaut pour le formView /// et désélection de l'item dans le gridView /// /// /// protected void FormView_RowUpdated(object sender, EventArgs e) { fvSynthese.PageIndex = -1; fvSynthese.ChangeMode(FormViewMode.ReadOnly); gvSynthese.SelectedIndex = -1; } #endregion #region Gestion Click bouton /// /// Lance la recherche. /// /// /// protected void btRechercher_Click(object sender, EventArgs e) { // le fonctionnement de l'application repose sur les ODS (répertoire App_Code). // l'ODS est configuré pour lancer la méthode Select par défaut. // le bouton Recherche ne provoque qu'un postback. l'ODS lance la méthode Select et // la gridview effectue le databind. fvSynthese.PageIndex = -1; fvSynthese.ChangeMode(FormViewMode.ReadOnly); gvSynthese.SelectedIndex = -1; } /// /// Annule la modification d'un item du griedView /// /// /// protected void btAnnuler_Click(object sender, EventArgs e) { fvSynthese.PageIndex = -1; fvSynthese.ChangeMode(FormViewMode.ReadOnly); gvSynthese.SelectedIndex = -1; } /// /// Méthode associé au contrôle ImageFeu pour gérer le lien vers le détail Synthese. /// /// /// protected void btRedirect_Click(object sender, CommandEventArgs e) { if (e.CommandName == "Image_Clicked") { GridViewRow row = gvSynthese.SelectedRow; ContexteManager.Requete["CritereRecherchePeriode"] = lstPeriode.SelectedValue; ContexteManager.Requete["CritereRechercheFlux"] = lstFlux.SelectedValue; ContexteManager.Requete["idSynthese"] = "2"; Server.Transfer("SyntheseDetail.aspx"); } } #endregion #region Script JavaScript /// /// Génére le script client pour le bouton Effacer. /// /// private string EffacerJScript() { StringBuilder script = new StringBuilder(); script.Append("var param1 = document.getElementById('" + lstPeriode.IDClient + "');"); script.Append("if (param1)"); script.Append("{param1.selectedIndex = 0;}"); script.Append("var param2 = document.getElementById('" + lstFlux.IDClient + "');"); script.Append("if (param2)"); script.Append("{param2.value = '';}"); script.Append("return false;"); return script.ToString(); } private string UpdateJScript() { StringBuilder script = new StringBuilder(); Validation _newFeu = (Validation)fvSynthese.FindControl("txtValidation"); SyntheseInfo _itemSelect = (SyntheseInfo)fvSynthese.DataItem; script.Append("function btModifier_Click()" + "\n"); script.Append("{" + "\n"); /*Amélioration à apporter pour rendre l'écriture de la fonction javascript * compatible avec des évolutions du contrôle Validation. Nombre d'item non figé */ script.Append("var radio1 = document.getElementById('" + _newFeu.IDClient + "_0');" + "\n"); script.Append("var radio2 = document.getElementById('" + _newFeu.IDClient + "_1');" + "\n"); script.Append("var radio3 = document.getElementById('" + _newFeu.IDClient + "_2');" + "\n"); try { script.Append("if (radio1.checked && radio1.value != " + _itemSelect.Validation.ToString() + ") {" + "\n"); script.Append("return confirm('Voulez-vous vraiment modifier la validation?');" + "\n"); script.Append("}" + "\n"); script.Append("if (radio2.checked && radio2.value != " + _itemSelect.Validation.ToString() + ") {" + "\n"); script.Append("return confirm('Voulez-vous vraiment modifier la validation?');" + "\n"); script.Append("}" + "\n"); script.Append("if (radio3.checked && radio3.value != " + _itemSelect.Validation.ToString() + ") {" + "\n"); script.Append("return confirm('Voulez-vous vraiment modifier la validation?');" + "\n"); script.Append("}" + "\n"); script.Append("return true;" + "\n"); } catch (Exception) { script.Append("return confirm('Voulez-vous vraiment modifier la validation?');" + "\n"); } script.Append("}"+"\n"); this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "btModifierScript", script.ToString(), true); return "btModifier_Click();"; } //private void Scroll() //{ // StringBuilder script = new StringBuilder(); // script.Append("var param1 = document.getElementById('" + fvSynthese.ClientID + "');"+ "\n"); // script.Append("if (param1)"+ "\n"); // script.Append("{this.scrollTop = calculeOffset(param1,\"offsetTop\")}" + "\n"); // this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ScrollPage", script.ToString(), true); //} #endregion }