2009年5月2日 星期六

The published solution uses the Session object as storage for the currently selected culture. This will be initialized during Session_Start method that is part of the global.asax file.

If a culture change is requested by the user (through a dropdownlist for example), the MasterPage changes the stored culture in the Session object.

In a BasePage that inherits from Page, the method InitializeCulture is overriden and sets the appropriate culture information stored in the session object to the current thread. Therefore, every Web Form needs to derive from this BasePage.

Step 1. Creating a base page

Under the App_code folder create a new codefile and name it BasePage. This is my code:

Imports Microsoft.VisualBasic
Imports System.Threading
Imports System.Globalization

”’


”’ Custom base page used for all web forms.
”’

Public Class BasePage
Inherits System.Web.UI.Page
Protected Overrides Sub InitializeCulture()

‘Set the UICulture and the Culture with a value stored in a Session-object. I called mine “MyCulture”
Thread.CurrentThread.CurrentUICulture = New CultureInfo(Session(”MyCulture”).ToString)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Session(”MyCulture”).ToString)
End Sub
End Class

Step 2: Let all pages derive from the BasePage

For every page where you want the localization to work, change Inherits System.Web.UI.Page to Inherits BasePage in the codefile (ex. YourPage.aspx.vb).

For example:

Partial Class Your_Class
Inherits BasePage

End Class

Instead of:

Partial Class Your_Class
Inherits System.Web.UI.Page

End Class

Step 3: Create a Global.asax file

Create a file under the root-folder and name it: Global.asax
Remove all the code and type: <%@ Application CodeBehind=”Global.asax.vb” Inherits=”Global2″ Language=”VB” %>

Under the App_Code folder create a file and name it Global.asax.vb.
Some remarks about the code:
- Use Global2 as classname because Global is a reserved word.
- Only the Session_Start method is necessary.
- I use a cookie (otmData) to store the users’ preference which is put in a Sessionvariable called MyCulture

‘Global.asax.vb codebehind file

Imports System.Web
Imports System.Web.SessionState
Imports System.Threading
Imports System.Globalization

Public Class Global2
Inherits System.Web.HttpApplication

Sub Session_Start(ByVal Sender As Object, ByVal E As EventArgs)

If Not Request.Cookies(”otmData”) Is Nothing Then
‘If a cookie exists, set the session-object with the data from the cookie.
Session(”MyCulture”) = Server.HtmlEncode(Request.Cookies(”otmData”)(”languagePref”))
Else
‘If the cookie doen’t exist (user visits the website for the first time) set the session-object to the default value, in this case English. And ‘create the cookie.
Session(”MyCulture”) = “en”
Dim aCookie As New HttpCookie(”otmData”)
aCookie.Values(”languagePref”) = Session(”MyCulture”)
aCookie.Expires = System.DateTime.Now.AddDays(21)
Response.Cookies.Add(aCookie)
End If
End Sub
End Class

Step 4: Dropdownlist on the masterpage

In my masterpage I created a dropdownlist which is populated with data from a sql-database. You can of course add items to the ddl manualy.
Make sure that the AutoPostBack-value is set to True.

The needed code for the selectedIndexChanged method:

Protected Sub ddlLanguage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlLanguage.SelectedIndexChanged
‘if the session differs from the value in the ddl, the session-object is changed and the cookie is created
If Not Session(”MyCulture”) = ddlLanguage.SelectedValue Then
Session(”MyCulture”) = ddlLanguage.SelectedValue
Dim aCookie As New HttpCookie(”otmData”)
aCookie.Values(”languagePref”) = Session(”MyCulture”)
aCookie.Expires = System.DateTime.Now.AddDays(21)
Response.Cookies.Add(aCookie)
End If

‘Reload the page
Response.Redirect(Request.Url.ToString)
End Sub

2009年4月1日 星期三

Smart Applicants Matching System

Tools to automate resumes handling process

A single multilingual user interface for the user to analyze resumes received and exchange of data for wide range of common data sources. The process includes determination of job that the applicants looking for and their­­ qualifications. 

Download@:

2009年2月18日 星期三

c# : dataset

            // Navigate Dataset
            foreach (DataTable table in dataset.Tables)
            {
                temp += "TableName = " + table.TableName;
                temp += "---------";
                temp += "Columns ...\r\n";

                foreach (DataColumn column in table.Columns)
                {
                    //Console.Write("{0,-22}", column.ColumnName);
                    temp += column.ColumnName + "\t";
                }
                temp += "\n";
                temp += "\r\nNumber of rows = " + table.Rows.Count.ToString();
                temp += "Rows ...\r\n";

                foreach (DataRow row in table.Rows)
                {
                    foreach (Object value in row.ItemArray)
                    {
                        temp += value.ToString() + "\t";
                    }
                    temp += "\n";
                }
                temp += "\n";
            }

2009年2月3日 星期二

c# window application-- Change locale dynamically

CultureInfo objCI = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = objCI;
Thread.CurrentThread.CurrentUICulture = objCI;                

//localization code
this.Controls.Clear();
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
InitializeComponent();

this.lbTime.Text = DateTime.Now.ToLongDateString().ToString();

2009年1月21日 星期三

GPON

GPON(Gigabit-capable PON)
是基于ITU-TG.984.x标准的最新一代宽带无源光综合接入标准,具有高带宽,高效率,大覆盖范围,用户接口丰富等众多优点,被大多数运营商视为实现接入网业务宽带化,综合化改造的理想技术。本文结合 GPON技术产品的应用实践,提出了GPON技术在中国市场的基本应用模式。

2009年1月18日 星期日

PHP: Generate random password

function generatePassword ($length = 8)
{

// start with a blank password
$password = "";

// define possible characters
$possible = "0123456789bcdfghjkmnpqrstvwxyz";

// set up a counter
$i = 0;

// add random characters to $password until $length is reached
while ($i < $length) {

// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);

// we don't want this character if it's already in the password
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}

}

// done!
return $password;

}

2009年1月14日 星期三

Resource Description Framework (RDF)

  • based upon the idea of making statements about resources
  • in the form of subject-predicate-object expressions, called triples
    -subject ->denotes the resource
    -predicate-> denotes traits or aspects of the resource and expresses a relationship between the subject and the object
  • e.g. The sky has the color blue
    subject-> the sky
    predicate->has the color
    object->blue
  • persisted in relational database or native representations also called Triple stores, or Quad stores if context (i.e. the named graph) is also persisted for each RDF triple