-
How manage authentication in IIS and other...
-
I found nice informations about IIS authentication here...and some other useful informations from Gustavo Duarte's Blog...
Bye
Antonio
-
A little reflection helper
-
These are 2 classes that I use for control objects properties by reflection...
using
System;
using
System.Collections.Generic;
using
System.Text;namespace Utils
{
public class ReflectionHelper
{
public static string GetStringPropertyValue(object obj,string property)
{
try{ return obj.GetType().GetProperty(property).GetValue(obj, null).ToString();
}
catch(Exception){return null;
}
}
public static object GetObjectPropertyValue(object obj, string property)
{
return obj.GetType().GetProperty(property).GetValue(obj, null);
}
public static int GetIntPropertyValue(object obj, string property)
{
object tmp= obj.GetType().GetProperty(property).GetValue(obj, null);
int val=int.MinValue;if(tmp!=null)
int.TryParse(tmp.ToString(), out val);return val;
}
}
public class ReflectionHelper<T>
{
public static T GetPropertyValue(object obj, string property)
{
return (T)obj.GetType().GetProperty(property).GetValue(obj, null);
}
}
}
Antonio
-
How to map composite key in NHibernate
-
This is a little example of mapping a class in NHibernate.Table in DB is a legacy application with a composite key formed by a string and an integer:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ERP" assembly="ERP_Objects">
<class name="ERP.ItemMagazzino" table="DettaglioMagazzino">
<composite-id>
<key-property name="Magazzino" column="Magazzino" type="int">
</key-property>
<key-property name="Prodotto" column="Prodotto" type="string"></key-property>
</composite-id>
<property name="Descrizione" column="Descrizione" type="string" not-null="false" />
<property name="Giacenza" column="Giacenza" type="int" not-null="false" />
<property name ="UM" column="UM" type="string" />
</class>
</hibernate-mapping>
You can retrive your data calling this code:
ICriteria criteria = session.CreateCriteria(typeof(ItemMagazzino));
IList objs= session.CreateCriteria(typeof(ItemMagazzino)).Add("Prodotto","code").Add("Magazzino",1).List();
Bye bye
Antonio
-
A generic class for pagination
-
I need a class for pagination of some results.I post code maybe is useful...
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Collections.Generic;
using
System.Web.UI.WebControls;namespace ViewLogic{
public class Pagination<T>
{
int _PageNumber;
/// <summary>
/// Index of current page
/// </summary>
public int CurrentPageNumber
{
get { return _PageNumber; }set { _PageNumber = value; }
}
int _PageSize=8;
/// <summary>
/// Numeber of items in page
/// </summary>public int PageSize
{
get { return _PageSize; }set { _PageSize = value; }
}
IList<T> _Items=new List<T>();
/// <summary>
/// Items to paginate
/// </summary>public IList<T> Items
{
get { return _Items; }set { _Items = value; }
}
/// <summary>
/// Return data from page
/// </summary>
/// <param name="pageNumber"></param>
/// <returns></returns>public IList<T> GetDataFromPage(int pageNumber)
{
int lowerBound, upperBound;
//calcola l'indice inferiore e quello superiorelowerBound = pageNumber * this.PageSize;
upperBound=(pageNumber+1)*
this.PageSize;if(this.Items!=null)
if(this.Items.Count>=lowerBound){if (this.Items.Count > upperBound - 1)
return this.GetRange(lowerBound, upperBound - 1);else return this.GetRange(lowerBound, int.MaxValue);
}
return null;
}
/// <summary>
/// Return data
/// </summary>
/// <param name="pageNumber"></param>
/// <returns></returns>public IList<T> GetDataFromCurrentPage(int pageNumber)
{
return this.GetDataFromPage(this.CurrentPageNumber);
}
/// <summary>
/// Return a range of data/// </summary>
/// <param name="lowerBound"></param>
/// <param name="upperBound"></param>
/// <returns></returns>private IList<T> GetRange(int lowerBound,int upperBound)
{
IList<T> tmps = new List<T>();if(upperBound==int.MaxValue)
for(int i=lowerBound;i<this.Items.Count;i++)
tmps.Add(
this.Items
);
elsefor(int i=lowerBound;i<=upperBound;i++)
tmps.Add(
this.Items
);return tmps;
}
/// <summary>
/// Return range of odd items
/// </summary>
/// <param name="lowerBound"></param>
/// <param name="upperBound"></param>
/// <returns></returns>private IList<T> GetOddInRange(int lowerBound, int upperBound)
{
IList<T> tmps = new List<T>();int i;
if (upperBound == int.MaxValue){for (i = lowerBound; i < this.Items.Count; i++)
if(i%2==0)
tmps.Add(
this.Items
);
}
else{
for (i = lowerBound; i <= upperBound; i++)
if (i % 2 == 0)
tmps.Add(
this.Items
);
}
return tmps;
}
/// <summary>
/// Return a range of data in even place
/// </summary>
/// <param name="lowerBound"></param>
/// <param name="upperBound"></param>
/// <returns></returns>private IList<T> GetEvenInRange(int lowerBound, int upperBound)
{
IList<T> tmps = new List<T>();int i;
if (upperBound == int.MaxValue){
for (i = lowerBound; i < this.Items.Count; i++)
if (i % 2 != 0)
tmps.Add(
this.Items
);
}
else{
for (i = lowerBound; i <= upperBound; i++)
if (i % 2 != 0)
tmps.Add(
this.Items
);
}
return tmps;
}
/// <summary>
/// Return date for page
/// </summary>
/// <param name="pageNumber"></param>
/// <returns></returns>public IList<T> GetDataOddFromPage(int pageNumber)
{
int lowerBound, upperBound;lowerBound = pageNumber * this.PageSize;
upperBound = (pageNumber + 1) *
this.PageSize;if (this.Items != null)if (this.Items.Count >= lowerBound)
{
if (this.Items.Count > upperBound - 1)
return this.GetOddInRange(lowerBound, upperBound - 1);else return this.GetOddInRange(lowerBound, int.MaxValue);
}
return null;
}
/// <summary>
/// Return data for page
/// </summary>
/// <param name="pageNumber"></param>
/// <returns></returns>public IList<T> GetDataEvenFromPage(int pageNumber)
{
int lowerBound, upperBound;
//calculate upper and boundlowerBound = pageNumber * this.PageSize;
upperBound = (pageNumber + 1) *
this.PageSize;if (this.Items != null)if (this.Items.Count >= lowerBound)
{
if (this.Items.Count > upperBound - 1)return this.GetEvenInRange(lowerBound, upperBound - 1);else return this.GetEvenInRange(lowerBound, int.MaxValue);
}
return null;
}
}
}