Mini-guide NHibernate (theServerSide.NET)
http://www.theserverside.net/news/thread.tss?thread_id=46642&asrc=EM_NLN_2112248&uid=5231204
commenter cet article …
[Cycle de progression] Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions
Mini-guide NHibernate (theServerSide.NET)
http://www.theserverside.net/news/thread.tss?thread_id=46642&asrc=EM_NLN_2112248&uid=5231204
<%@ Page Language="C#" MasterPageFile="~/maquette.master" Trace="true" AutoEventWireup="true" CodeFile="MaintainScrollPositionOnPostbackDemo.aspx.cs" Inherits="MaintainScrollPositionOnPostbackDemo" Title="Untitled Page" MaintainScrollPositionOnPostback="true" %> <asp:Content ID="Content1" ContentPlaceHolderID="cphContenu" Runat="Server"> </asp:Content> |
<%@ Page Language="C#" MasterPageFile="~/maquette.master" Trace="true" AutoEventWireup="true" CodeFile="MaintainScrollPositionOnPostbackDemo.aspx.cs" Inherits="MaintainScrollPositionOnPostbackDemo" Title="Untitled Page" MaintainScrollPositionOnPostback="true" %> <asp:Content ID="Content1" ContentPlaceHolderID="cphContenu" Runat="Server"> </asp:Content> |
<system.web> <trace enabled="true" traceMode="SortByCategory" localOnly="true"/> |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections; namespace ControlLibrary { [ToolboxData("<{0}:SimpleDataBoundColumn runat=server></{0}:SimpleDataBoundColumn>")] public class SimpleDataBoundColumn : DataBoundControl { public string DataTextField { get { object o = ViewState["DataTextField"]; return ((o == null) ? string.Empty : (string)o); } set { ViewState["DataTextField"] = value; if (Initialized) { OnDataPropertyChanged(); } } } protected override void PerformSelect() { // si DataSourceID du control n'est pas définie if (!IsBoundUsingDataSourceID) this.OnDataBinding(EventArgs.Empty); GetData().Select(CreateDataSourceSelectArguments(),this.OnDataSourceViewSelectCallback); RequiresDataBinding = false; MarkAsDataBound(); // declenchement evenement databound OnDataBound(EventArgs.Empty); } private void OnDataSourceViewSelectCallback(IEnumerable retrievedData) { // DataSourceID du control est définie if (IsBoundUsingDataSourceID) OnDataBinding(EventArgs.Empty); PerformDataBinding(retrievedData); } protected override void PerformDataBinding(IEnumerable retrievedData) { base.PerformDataBinding(retrievedData); int index = 0; if (retrievedData != null) { Table table = new Table(); table.BorderWidth = 1; foreach (object dataItem in retrievedData) { TableRow row = new TableRow(); if (DataTextField.Length > 0) { TableCell cell = new TableCell(); cell.Text = DataBinder.GetPropertyValue(dataItem, DataTextField, null); row.Cells.Add(cell); } else { PropertyDescriptorCollection propertyDescriptors = TypeDescriptor.GetProperties(dataItem); // création du header if (index == 0) { TableRow headerRow = new TableRow(); headerRow.BackColor = System.Drawing.Color.LightGray; foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors) { TableCell cell = new TableCell(); cell.Text = propertyDescriptor.Name; headerRow.Cells.Add(cell); } table.Rows.Add(headerRow); index += 1; } // création des lignes de données if (propertyDescriptors.Count >= 1) { foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors) { if (propertyDescriptor.GetValue(dataItem) != null) { TableCell cell = new TableCell(); cell.Text = propertyDescriptor.GetValue(dataItem).ToString(); row.Cells.Add(cell); } } } } table.Rows.Add(row); } this.Controls.Add(table); } } } } |
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="ControlLibrary" Namespace="ControlLibrary" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Page sans titre</title> </head> <body> <form id="form1" runat="server"> <div> <cc1:SimpleDataBoundColumn ID="SimpleDataBoundColumn1" runat="server" DataSourceID="SqlDataSource1" DataTextField="" /> <br /> <br /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ContactDBConnectionString %>" SelectCommand="SELECT [ContactID], [ContactName], [ContactFirstName], [ContactAge], [ContactCategoryID] FROM [Contact]"> </asp:SqlDataSource> <br /> <br /> </div> </form> |
protected override void Render(HtmlTextWriter writer) { // 1 approche "objet" writer.AddAttribute(HtmlTextWriterAttribute.Style, "font-size:XX-Large"); writer.RenderBeginTag(HtmlTextWriterTag.Span); HttpUtility.HtmlEncode(_text, writer); writer.RenderEndTag(); // 2 writer.WriteBeginTag("Span"); //<Span writer.WriteAttribute("style", "font-size:XX-Large");// Style="font-size:XX-Large" writer.Write(">"); // ou writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(_text); // le texte writer.WriteEndTag("Span");// </Span> } |
"Concepts you can see in practice with this sample include:
Open XML - Création de fichiers XML ouverts Office et
Open XML et les schémas métier : un aperçu
1 - Création de fichiers XML ouverts Office
bien que les exemples de codes soient en VB.NET,ils sont plutot interessants : visionneuse de package,exemples de documents(templates,..),generation de docx,generation de lettre
un article donc tres bien pour decouvrir Open XML (avec word)
http://msdn.microsoft.com/msdnmag/issues/07/02/officespace/default.aspx?loc=fr
2 - Open XML et les schémas métier : un aperçu
http://msdn2.microsoft.com/fr-fr/library/880C55B0-BEB3-48f1-A3D8-ED5BB63B5023.aspx
// resultat = condition? valeur retour condition vraie : valeur retour condition fausse // ex: int int i=11; int nResult = (i > 10) ? i * 2 : i; |
Priority priority = Priority.Normal; // exemple : retourne "Normal" string result = System.Enum.Format(typeof(Priority), priority, "D"); //G ou g renvoie le nom (ex:"Normal"),D ou d renvoie la valeur (ex "2") string name = System.Enum.GetName(typeof(Priority), priority);//retourne "Normal // retourne les noms dans un tableau de string string[] priorities = System.Enum.GetNames(typeof(Priority)); bool isDefined = System.Enum.IsDefined(typeof(Priority),"High");// retourne true // ... voir les autres membres public enum Priority |
private delegate void doActionEventHandler(); private doActionEventHandler doAction; private void Form1_Load(object sender, EventArgs e) { //doAction +=new doActionEventHandler(DoFirstAction); //doAction +=new doActionEventHandler(DoSecondAction); // OU (inference de type) doAction += DoFirstAction; doAction += DoSecondAction; System.Delegate[] delegatesOfDoAction = doAction.GetInvocationList(); // appeler un delegue de maniere asynchrone , attention le delegue ne doit avoir qu'une seule cible dans ce cas doAction.BeginInvoke(null, null); } public void DoFirstAction() { } public void DoSecondAction() { } |
public class SqlDependencyExpiration : ICacheItemExpiration { private bool isExpired; public SqlDependencyExpiration(SqlCommand command) { SqlDependency.Stop(command.Connection.ConnectionString); SqlDependency.Start(command.Connection.ConnectionString); command.Notification = null; SqlDependency sqlDependency = new SqlDependency(command); sqlDependency.OnChange += new OnChangeEventHandler(OnChanged); if (command.Connection.State == ConnectionState.Closed) command.Connection.Open(); command.ExecuteReader(CommandBehavior.CloseConnection); } void OnChanged(object sender, SqlNotificationEventArgs e) { SqlDependency sqlDependency = sender as SqlDependency; sqlDependency.OnChange -= OnChanged; isExpired = true; } #region ICacheItemExpiration Membres public bool HasExpired() { return isExpired; } #endregion } |
private void button1_Click(object sender, EventArgs e) { DataTable dataTable = new DataTable(); if (manager.Get("1") != null) { dataTable =(DataTable) manager.Get("1").Value; label1.Text = "from cache"; } else { SqlCommand sqlCommand = new SqlCommand("Select ContactID,Contactname from dbo.[Contact]", new SqlConnection("Data Source=.;Initial Catalog=ContactDB;Integrated Security=SSPI;")); sqlCommand.Connection.Open(); dataTable.Load(sqlCommand.ExecuteReader()); label1.Text = "from sql server"; manager.Add("1", dataTable, new ICacheItemExpiration[] { new SqlDependencyExpiration(sqlCommand) }); } dataGridView1.DataSource = dataTable; } |
public class PollTimer :IDisposable { private System.Threading.Timer timer; public void StartPolling(TimerCallback callbackMethod, int period) { if (callbackMethod == null) throw new ArgumentNullException("callbackMethod"); if (period <= 0) throw new Exception("period"); timer = new System.Threading.Timer(callbackMethod, null, 1000, period); } public void StopPolling() { if (timer == null) throw new InvalidOperationException(""); Dispose(); } #region IDisposable Membres public void Dispose() { timer.Dispose(); timer = null; } #endregion } |
PollTimer pollTimer = new PollTimer(); private void button1_Click(object sender, EventArgs e) { pollTimer.StartPolling(Message, 1000); } public void Message(object obj) { MessageBox.Show("now"); } |