Arjuna Aircraft Ident.: F-MBSD | Voici mon code complet :
(affichage sous forme HTML, ou génération d'un fichier Excel, au choix)
-- code de kosovar inside --
Je génère un CSV par contre, because chez ce client il y a encore des gense sous Office 97 et Windows 95... Evidement, générer de l'XSL à partir d'un fichier HTML c'est pas possible...
Autre solution qui aurait été bien, c'est d'installer Excel sur le serveur, et générer "proprement" un vrai document XLS en utilisant le moteur d'Excel programmatiquement.
ProductList.aspx
Code :
- <%@ Page language="c#" Codebehind="ProductList.aspx.cs" AutoEventWireup="false" Inherits="bci.ProductList" %>
- <%@ Register TagPrefix="uc1" TagName="Banner" Src="Controls/Banner.ascx" %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
- <HTML>
- <HEAD>
- <title>Product List</title>
- <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
- <meta name="CODE_LANGUAGE" Content="C#">
- <meta name="vs_defaultClientScript" content="JavaScript">
- <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
- <link href="medias/default.css" media="all" rel="stylesheet">
- </HEAD>
- <body MS_POSITIONING="GridLayout">
- <form id="Form1" method="post" runat="server">
- <asp:Label id="frm" Runat="server">
- <uc1:Banner runat="server" ID="Banner1" NAME="Banner1"></uc1:Banner>
- <table>
- <tr>
- <td><asp:Literal runat="server" ID="titProductCode" /></td>
- <td><asp:TextBox id="txtCodpro" runat="server"></asp:TextBox></td>
- </tr>
- <tr>
- <td><asp:Label id="txtFou" Runat="server"></asp:Label></td>
- <td><asp:TextBox id="txtSigtie" runat="server"></asp:TextBox></td>
- </tr>
- <tr>
- <td><asp:Literal runat="server" ID="titCollection" /></td>
- <td><asp:TextBox id="txtSsfpro" runat="server"></asp:TextBox></td>
- </tr>
- <tr>
- <td><asp:Literal runat="server" ID="titFurnitureType" /></td>
- <td><asp:ListBox id="lstSfapro" Runat="server" Rows="1"></asp:ListBox></td>
- </tr>
- <tr>
- <td><asp:Literal runat="server" ID="titWarehouse" /></td>
- <td><asp:ListBox id="lstSigdep" Runat="server" Rows="1"></asp:ListBox></td>
- </tr>
- <tr>
- <td colspan="2"><asp:Button ID="btnValidate" Runat="server"></asp:Button> <asp:Button ID="btnExcel" Runat="server"></asp:Button></td>
- </tr>
- </table>
- <br/>
- <br/>
- </asp:Label>
- <center>
- <asp:Repeater ID="rptProducts" Runat="server">
- <HeaderTemplate>
- <table class="collectionList tableauListe" border="2" cellspacing="0" bordercolor="#660000"
- bgcolor="#F5AC50">
- <tr class="title">
- <th>
- <asp:Literal Runat="server" ID="titProduct" /></th>
- <th>
- <asp:Label ID="titleSigfou" Runat="server"></asp:Label>
- </th>
- <th>
- <asp:Label id="titleNomfou" Runat="server"></asp:Label>
- </th>
- <th>
- <asp:Literal Runat="server" ID="titWarehouse2" /></th>
- <th>
- <asp:Literal Runat="server" ID="titCollection2" /></th>
- <th>
- <asp:Literal Runat="server" ID="titFurnitureType2" /></th>
- <th>
- <asp:Literal Runat="server" ID="titDesignation" /></th>
- <th>
- <asp:Literal Runat="server" ID="titFinalStock" /></th>
- <th>
- <asp:Literal Runat="server" ID="titPhysicalStock" /></th>
- <th>
- <asp:Literal Runat="server" ID="titReservedStock" /></th>
- <th>
- <asp:Literal Runat="server" ID="titPreparationStock" /></th>
- <th>
- <asp:Literal Runat="server" ID="titStatus" /></th>
- <th>
- <asp:Label ID="titleVtar" Runat="server"></asp:Label>
- </th>
- <th>
- <asp:Label ID="titleAtar" Runat="server"></asp:Label>
- </th>
- <th>
- <asp:Label ID="titleRtar" Runat="server"></asp:Label>
- </th>
- </tr>
- </HeaderTemplate>
- <ItemTemplate>
- <tr class="even">
- <td><%# DataBinder.Eval(Container.DataItem, "codpro" ) %></td>
- <td><asp:Label ID="valSigfou" Runat="server"></asp:Label></td>
- <td><asp:Label ID="valNomfou" Runat="server"></asp:Label></td>
- <td><%# DataBinder.Eval(Container.DataItem, "sigdep" ) %></td>
- <td><%# DataBinder.Eval(Container.DataItem, "libfam1" ) %></td>
- <td><%# DataBinder.Eval(Container.DataItem, "libfam2" ) %></td>
- <td><%# DataBinder.Eval(Container.DataItem, "design1" ) %></td>
- <td class="typeNumber"><%# DataBinder.Eval(Container.DataItem, "stk" ) %></td>
- <td class="typeNumber"><%# DataBinder.Eval(Container.DataItem, "phy" ) %></td>
- <td class="typeNumber"><%# DataBinder.Eval(Container.DataItem, "resa" ) %></td>
- <td class="typeNumber"><%# DataBinder.Eval(Container.DataItem, "prepa" ) %></td>
- <td><%# DataBinder.Eval(Container.DataItem, "codblocage" ) %></td>
- <td class="typeNumber"><asp:Label id="valVtar" Runat="server"></asp:Label></td>
- <td class="typeNumber"><asp:Label id="valAtar" Runat="server"></asp:Label></td>
- <td class="typeNumber"><asp:Label id="valRtar" Runat="server"></asp:Label></td>
- </tr>
- </ItemTemplate>
- <FooterTemplate>
- </table>
- </FooterTemplate>
- </asp:Repeater>
- </center>
- </form>
- </body>
- </HTML>
|
ProductList.aspx.cs
Code :
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace bci
- {
- /// <summary>
- /// Summary description for ProductList.
- /// </summary>
- public class ProductList : System.Web.UI.Page
- {
- protected System.Web.UI.WebControls.TextBox txtCodpro;
- protected System.Web.UI.WebControls.TextBox txtSigtie;
- protected System.Web.UI.WebControls.TextBox txtSsfpro;
- protected System.Web.UI.WebControls.ListBox lstSfapro;
- protected System.Web.UI.WebControls.ListBox lstSigdep;
- protected System.Web.UI.WebControls.TextBox txtSfapro;
- protected System.Web.UI.WebControls.TextBox txtSigdep;
- protected System.Web.UI.WebControls.Label txtFou;
- protected System.Web.UI.WebControls.Label frm;
- protected Label titleSigfou;
- protected Label titleNomfou;
- protected Label titleVtar;
- protected Label titleAtar;
- protected Label titleRtar;
- protected Literal titProductCode;
- protected Literal titCollection;
- protected Literal titFurnitureType;
- protected Literal titWarehouse;
- protected System.Web.UI.WebControls.Repeater rptProducts;
- protected System.Web.UI.WebControls.Button btnValidate;
- protected System.Web.UI.WebControls.Button btnExcel;
- private Queries commander;
- private language lan;
- private void Page_Load(object sender, System.EventArgs e)
- {
- if (Session.Count == 0 || Session["login"] == null || Session["typtie"] == null || Session["codsoc"] == null)
- {
- Session.Clear();
- Response.Redirect("Default.aspx", true);
- }
- commander = new Queries(string.Format((string) Application["cnxString"], (string) Application["dbLogin"], (string) Application["dbPass"], (string) Application["dbTNS"]));
- lan = new language((string)Session["codlan"], Server.MapPath("." ));
- titProductCode.Text = lan.GetMessage("titProductCode" );
- txtFou.Text = lan.GetMessage("titSupplier" );
- titCollection.Text = lan.GetMessage("titCollection" );
- titFurnitureType.Text = lan.GetMessage("titFurnitureType" );
- titWarehouse.Text = lan.GetMessage("titWarehouse" );
- btnValidate.Text = lan.GetMessage("btnValidate" );
- btnExcel.Text = lan.GetMessage("btnExcel" );
- if (!(
- habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.supplier) &&
- habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.vtar) &&
- habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.atar) &&
- habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.rtar)
- ))
- {
- btnExcel.Visible = false;
- }
- if (Page.IsPostBack)
- {
- if (Request.Form["btnExcel"] != null)
- {
- Response.Clear();
- Response.ContentType = "text/csv";
- Response.ContentEncoding = System.Text.Encoding.ASCII;
- Response.AddHeader("Content-Disposition", "attachement; filename=\"resultat.csv\"" );
- Response.Write("Produit,Sigle,Fournisseur,Depot,Collection,Type de mobilier,Designation,A terme,Physique,Reserve,Preparation,Etat,Prix de vente,Monnaie,Prix d'achat,Monnaie,Prix de revient,Monnaie\n" );
- DataTable dt = commander.LoadProductList((decimal) Session["codsoc"], txtCodpro.Text, txtSigtie.Text, txtSsfpro.Text, lstSfapro.SelectedValue, lstSigdep.SelectedValue);
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- for (int j = 0; j < dt.Columns.Count; j++)
- {
- Response.Write("\"" + dt.Rows[i].ItemArray[j] + "\"" );
- if (j == dt.Columns.Count - 1)
- {
- Response.Write("\n" );
- }
- else
- {
- Response.Write("," );
- }
- }
- }
- commander.webLog(Session["codsoc"], Session["typtie"], Session["login"], Request.ServerVariables["http_host"], Request.FilePath, Session["sigdep"], Session["codpro"]);
- Response.End();
- }
- else
- {
- Click();
- }
- }
- else
- {
- InitPage();
- }
- commander.webLog(Session["codsoc"], Session["typtie"], Session["login"], Request.ServerVariables["http_host"], Request.FilePath, Session["sigdep"], Session["codpro"]);
- }
- public void InitPage()
- {
- // Check connection to Generix is available
- if (commander.RunTestQuery() && Session["login"] != null && Session["password"] != null)
- {
- DataTable dt = commander.LoadTypeMobilier((decimal) Session["codsoc"], true);
- lstSfapro.Items.Clear();
- if (dt.Rows.Count > 0)
- {
- lstSfapro.DataSource = dt;
- lstSfapro.DataTextField = "libfam";
- lstSfapro.DataValueField = "codesfa";
- lstSfapro.DataBind();
- }
- DataTable dt2 = commander.LoadWarehouse((decimal) Session["codsoc"], true);
- lstSigdep.Items.Clear();
- if (dt2.Rows.Count > 0)
- {
- lstSigdep.DataSource = dt2;
- lstSigdep.DataTextField = "nomtie";
- lstSigdep.DataValueField = "sigtie";
- lstSigdep.DataBind();
- }
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.supplier))
- {
- txtFou.Visible = true;
- txtSigtie.Visible = true;
- }
- else
- {
- txtFou.Visible = false;
- txtSigtie.Visible = false;
- }
- }
- }
- private void Page_Unload(object sender, System.EventArgs e)
- {
- lan = null;
- try{commander.Close();}
- catch {};
- commander = null;
- }
- protected void Click()
- {
- DataTable dt = commander.LoadProductList((decimal) Session["codsoc"], txtCodpro.Text, txtSigtie.Text, txtSsfpro.Text, lstSfapro.SelectedValue, lstSigdep.SelectedValue);
- rptProducts.DataSource = dt;
- rptProducts.DataBind();
- }
- private void rptProducts_ItemDataBound(object sender, RepeaterItemEventArgs e)
- {
- if(e.Item.ItemType == ListItemType.Header)
- {
- ((Literal)e.Item.FindControl("titProduct" )).Text = lan.GetMessage("titProduct" );
- ((Label)e.Item.FindControl("titleSigfou" )).Text = lan.GetMessage("titleSigfou" );
- ((Label)e.Item.FindControl("titleNomfou" )).Text = lan.GetMessage("titleNomfou" );
- ((Literal)e.Item.FindControl("titWarehouse2" )).Text = lan.GetMessage("titWarehouse" );
- ((Literal)e.Item.FindControl("titCollection2" )).Text = lan.GetMessage("titCollection" );
- ((Literal)e.Item.FindControl("titFurnitureType2" )).Text = lan.GetMessage("titFurnitureType" );
- ((Literal)e.Item.FindControl("titDesignation" )).Text = lan.GetMessage("titDesignation" );
- ((Literal)e.Item.FindControl("titFinalStock" )).Text = lan.GetMessage("titFinalStock" );
- ((Literal)e.Item.FindControl("titPhysicalStock" )).Text = lan.GetMessage("titPhysicalStock" );
- ((Literal)e.Item.FindControl("titReservedStock" )).Text = lan.GetMessage("titReservedStock" );
- ((Literal)e.Item.FindControl("titPreparationStock" )).Text = lan.GetMessage("titPreparationStock" );
- ((Literal)e.Item.FindControl("titStatus" )).Text = lan.GetMessage("titStatus" );
- ((Label)e.Item.FindControl("titleVtar" )).Text = lan.GetMessage("titleVtar" );
- ((Label)e.Item.FindControl("titleAtar" )).Text = lan.GetMessage("titleAtar" );
- ((Label)e.Item.FindControl("titleRtar" )).Text = lan.GetMessage("titleRtar" );
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.supplier))
- {
- ((Label)e.Item.FindControl("titleSigfou" )).Visible = true;
- ((Label)e.Item.FindControl("titleNomfou" )).Visible = true;
- }
- else
- {
- ((Label)e.Item.FindControl("titleSigfou" )).Visible = false;
- ((Label)e.Item.FindControl("titleNomfou" )).Visible = false;
- }
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.vtar))
- {
- ((Label)e.Item.FindControl("titleVtar" )).Visible = true;
- }
- else
- {
- ((Label)e.Item.FindControl("titleVtar" )).Visible = false;
- }
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.atar))
- {
- ((Label)e.Item.FindControl("titleAtar" )).Visible = true;
- }
- else
- {
- ((Label)e.Item.FindControl("titleAtar" )).Visible = false;
- }
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.rtar))
- {
- ((Label)e.Item.FindControl("titleRtar" )).Visible = true;
- }
- else
- {
- ((Label)e.Item.FindControl("titleRtar" )).Visible = false;
- }
- }
- if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
- {
- DataRowView dr = ((DataRowView) e.Item.DataItem);
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.supplier))
- {
- ((Label)e.Item.FindControl("valSigfou" )).Text = (string)dr["sigtie"];
- ((Label)e.Item.FindControl("valNomfou" )).Text = (string)dr["nomtie"];
- }
- else
- {
- ((Label)e.Item.FindControl("valSigfou" )).Text = "";
- ((Label)e.Item.FindControl("valNomfou" )).Text = "";
- }
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.vtar))
- {
- if (dr != null)
- {
- ((Label)e.Item.FindControl("valVtar" )).Text = (string)dr["vtar"] + " " + ToolBox.CoddevToSymbol((string)dr["coddevv"]);
- }
- else
- {
- ((Label)e.Item.FindControl("valVtar" )).Text = "-";
- }
- }
- else
- {
- ((Label)e.Item.FindControl("valVtar" )).Text = "";
- }
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.atar))
- {
- if (dr != null)
- {
- ((Label)e.Item.FindControl("valAtar" )).Text = (string)dr["atar"] + " " + ToolBox.CoddevToSymbol((string)dr["coddeva"]);
- }
- else
- {
- ((Label)e.Item.FindControl("valAtar" )).Text = "-";
- }
- }
- else
- {
- ((Label)e.Item.FindControl("valAtar" )).Text = "";
- }
- if (habilitation.getHabilitation((string)Session["habilitation"], habilitation.Habilitations.rtar))
- {
- if (dr != null)
- {
- ((Label)e.Item.FindControl("valRtar" )).Text = (string)dr["rev"] + " " + ToolBox.CoddevToSymbol((string)dr["coddevr"]);
- }
- else
- {
- ((Label)e.Item.FindControl("valRtar" )).Text = "-";
- }
- }
- else
- {
- ((Label)e.Item.FindControl("valRtar" )).Text = "";
- }
- }
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.Unload += new System.EventHandler(this.Page_Unload);
- this.Load += new System.EventHandler(this.Page_Load);
- this.rptProducts.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.rptProducts_ItemDataBound);
- }
- #endregion
- }
- }
|
|