Private: MY Note


datetime globalization

Posted in .NET by dev1 on the January 30, 2008

Imports System.Globalization

site level –

<configuration>
 <system.web>
  <globalization
    requestencoding=”utf-8″
    responseencoding=” utf-8″
    fileencoding=” utf-8″
    culture=”de-DE”
    uiculture=”en” />
 </system.web>
</configuration>

/////////////////////////////////////////////////////////////////////////////////////////////

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(DateTime.Now.ToString(”ddd/MMM/yyyy”, New CultureInfo(”zh-CN”)))
End Sub

———————————————————————————————-

Response.Write(“Current Culture is “ + CultureInfo.CurrentCulture.EnglishName);

//////////////////////////////////////////////////////

page level –

<%@Page Culture=”fr-FR” Language=”C#” %>
<% @Import Namespace=”System.Globalization” %>
<html>
   <head>
   </head>
      <script runat=server>
      public void Page_Load()
      {
         Response.Write (”Current Culture is ” + CultureInfo.CurrentCulture.EnglishName);
      }
      </script>

   <body></body>
</html>

DataView to DataTable

Posted in .NET by dev1 on the January 9, 2008

DataView dvView = dtTabla.DefaultView;

dvView .RowFilter = “filter”;

DataTable dtFiltered = dvView.ToTable();

Comparing two objects ( == instead of .equals)

Posted in .NET, .NET 2.0 by dev1 on the December 17, 2007

Here’s the correct way to compare two strings.

String abc = “abc”; String def = “def”;

// Bad way
if ( (abc + def) == “abcdef” )
{
    ……
}
// Good way
if ( (abc + def).equals(”abcdef”) )
{
   …..
}

optimize data from calling webservice

Posted in .NET, .NET 2.0, ASP.NET by dev1 on the November 26, 2007

                DataTable HrDt = mHRTxnSAPData.ListDetail_OF_SentDocToSAP(comp_code, module, start_sap_date, end_sap_date
                                   , start_doc_date, end_doc_date, crem_type, Process_name, success, type);
                             
                foreach (DataRow dr in HrDt.Rows)
                {
                    //save to arrayList
                    strPin = dr[TableManager.WFCremation.PIN].ToString();
                    if (mList.IndexOf(strPin) == -1)
                    {
                        mList.Add(strPin);

                        if (type == “CR”)
                        {
                            strPin = dr[TableManager.WFCremation.HR_PIN].ToString();
                            if (mList.IndexOf(strPin) == -1)
                                mList.Add(strPin);
                        }
                    }

                    //save to hash(org info) –
                    strOrgInfo = dr[TableManager.WFCremation.NEAR_ORG_ID].ToString();
                    if (strOrgInfo != string.Empty)
                    {
                        if (!hashOrgInfo.ContainsKey(strOrgInfo))
                        {
                            OrgDs = mOMEHRService.GetOrgInfobyOrgCode(strOrgInfo);
                            if (OrgDs.Tables[0].Rows.Count > 0)
                                hashOrgInfo[strOrgInfo] = OrgDs.Tables[0].Rows[0][TableManager.Employee.ORG_DESC].ToString();
                        }
                    }

                }

                for (int a = 0; a < mList.Count; a++)
                {
                    if (strPin != string.Empty)
                        strPin = strPin + “,”;

                    strPin = strPin + mList[a].ToString();
                }

                //call ws for employee profile –
                dsProfile = mOMEHRService.ListEmployeeProfileByPIN(strPin);

———- calling  ——————

DataRow[] drProfile;

drProfile = dsProfile.Tables[0].Select(” PIN=’” + HrDr[TableManager.WFCremation.PIN].ToString() + “‘”);if (drProfile.Length != 0){

Pin_name = drProfile[0]["THFIRSTNAME"].ToString() + ” “ + drProfile[0]["THLASTNAME"].ToString();Position = drProfile[0][

TableManager.Employee.POSI_DESC].ToString();}

Dynamic array with ArrayList –> array

Posted in .NET, .NET 2.0 by dev1 on the November 10, 2007

public string[] GetFoo() {
  System.Collections.ArrayList al = new ArrayList();
  // Connect to the database and create a data reader (myReader)
  while (myReader.Read()) {
    // Do some cools stuff here
    al.Add((string) myReader["name"]);
  }
  return (string[]) al.ToArray(typeof(string));
}

Creating paging user control + store procedure

Posted in .NET, .NET 2.0, ASP.NET by dev1 on the October 29, 2007

<%@ Control Language=C# AutoEventWireup=true CodeFile=paging1.ascx.cs Inherits=Controls_Paging_paging1 %>
<div class=”PagingStyle”>
<table border=”0″ cellpadding=”0″ cellspacing=”0″ width=”100%”>
<tr>
<td align=”left”>
<asp:Label ID=”lblPageOf” CssClass=”PageOf” meta:resourceKey=”lblPageOf” runat=”Server”>หน้าที่ {0} ของ {1}</asp:Label>
</td>
<td align=”right”>
<asp:LinkButton ID=”lnkFirst” CssClass=”FirstPage” Text=”lnkFirst หน้าแรก” runat=”Server” meta:resourceKey=”lnkFirst” OnClick=”lnkFirst_Click” CausesValidation=”False”></asp:LinkButton> 
<asp:LinkButton ID=”lnkPrevious” CssClass=”PreviousPage” Text=”lnkPrevious หน้าที่แล้ว” runat=”Server” meta:resourceKey=”lnkPrevious” OnClick=”lnkPrevious_Click” CausesValidation=”False”></asp:LinkButton> 
<asp:Repeater ID=”rptPageNumbers” runat=”server” OnItemCommand=”rptPageNumbers_ItemCommand” OnItemDataBound=”rptPageNumbers_ItemDataBound”>
<ItemTemplate>
<asp:LinkButton ID=”lnkPageNumber” CssClass=”PageNumber” CommandName=”Selected” runat=”Server” CausesValidation=”False”></asp:LinkButton>
</ItemTemplate>
</asp:Repeater> 
<asp:LinkButton ID=”lnkNext” CssClass=”NextPage” Text=”lnkNext” runat=”Server” meta:resourceKey=”lnkNext” OnClick=”lnkNext_Click” CausesValidation=”False”></asp:LinkButton> 
<asp:LinkButton ID=”lnkLast” CssClass=”LastPage” Text=”lnkLast” runat=”Server” meta:resourceKey=”lnkLast” OnClick=”lnkLast_Click” CausesValidation=”False”></asp:LinkButton> 
</td>
</tr>
</table>
</div>


(more…)

ความรู้เกี่ยวกับการทำ Object Serialization และ Deserialization

Posted in .NET, .NET 2.0, ASP.NET by dev1 on the October 29, 2007

http://www.thaiwebdev.com/forums/index.php?showtopic=31&mode=threaded

How to call SQL Server stored procedures in ASP.NET

Posted in .NET, .NET 2.0, ASP.NET by dev1 on the October 29, 2007

private void Button1_Click(object sender, System.EventArgs e)
{

            //Create a connection to the SQL Server; modify the connection string for your environment.

            SqlConnection MyConnection = new SqlConnection(”server=(local);database=pubs;UID=sa;PWD=;”);

            //Create a DataAdapter, and then provide the name of the stored procedure.

            SqlDataAdapter MyDataAdapter = new SqlDataAdapter(”GetAuthorsByLastName”, MyConnection);

            //Set the command type as StoredProcedure.

            MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

            //Create and add a parameter to Parameters collection for the stored procedure.

            MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(”@au_lname”, SqlDbType.VarChar, 40));

            //Assign the search value to the parameter.

            MyDataAdapter.SelectCommand.Parameters["@au_lname"].Value = (TextBox1.Text).Trim();

            //Create and add an output parameter to the Parameters collection.

            MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter(”@RowCount”, SqlDbType.Int, 4));

            //Set the direction for the parameter. This parameter returns the Rows that are returned.

            MyDataAdapter.SelectCommand.Parameters["@RowCount"].Direction = ParameterDirection.Output;

            //Create a new DataSet to hold the records.

            DataSet DS = new DataSet();

           

            //Fill the DataSet with the rows that are returned.

            MyDataAdapter.Fill(DS, “AuthorsByLastName”);

            //Get the number of rows returned, and assign it to the Label control.

            //Label2.Text = DS.Tables(0).Rows.Count().ToString() & ” Rows Found!”

            Label2.Text = MyDataAdapter.SelectCommand.Parameters[1].Value + ” Rows Found!”;

            //Set the data source for the DataGrid as the DataSet that holds the rows.

            DataGrid1.DataSource = DS.Tables["AuthorsByLastName"].DefaultView;

            //NOTE: If you do not call this method, the DataGrid is not displayed!

            DataGrid1 .DataBind();

            MyDataAdapter.Dispose(); //Dispose the DataAdapter.

            MyConnection.Close(); //Close the connection.

}
 

DataBinder.Eval() in C# Question

Posted in .NET, .NET 2.0 by dev1 on the October 25, 2007

If have i a funtion below:-
Protected Function CheckUnit(Units As Object) As String

‘—————————————–
‘ If the Units returned equals to Zero,
‘ a message of “Out of Units” will be displayed.
‘ Otherwise, displayed the original value
‘—————————————–

If Integer.Parse(Units) = 0 Then
Return “Out Of Units”
Else
Return Units.ToString()
End If

End Function

I use :- <%# CheckUnit(Container.DataItem(”Units”)) %>
to display the value of the function.
But in C sharp it gives error so i used

<%# DataBinder.Eval(Container.DataItem, “Units”) %>
and it works!!

whats the right code when using C# to dislpay the value using

<%# DataBinder.Eval(Container.DataItem, “Units”) %>
with the CheckUnit Function???

How to display a totals line in the GridView & DataGrid footer

Posted in .NET, ASP.NET by dev1 on the October 10, 2007

‘Case Gridview

Dim
dTotal As Decimal = 0

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
dTotal
+= Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, price))
End If
If e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(
1).Text = Totals:
e.Row.Cells(
2).Text = dTotal.ToString(c)
e.Row.Cells(
1).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(
2).HorizontalAlign = HorizontalAlign.Right
e.Row.Font.Bold
= True
End If
End Sub

‘Case DataGrid

Dim dTotal As Double = 0Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
 
If e.Item.ItemType = ListItemType.Item Then
dTotal
= dTotal + Convert.ToDouble(e.Item.Cells(0))
End If
If e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(
1).Text = dTotal.ToString()
End If
End Sub

Next Page »