August 2005 - Posts

Coding Treeview di ASP Net 1.0/1.1
Wednesday, August 31, 2005 10:27 AM
 
Saya coba ke url itu ternyata masih ada. Asik asik asik.
 
Dulu saya pernah pake waktu component ini mungkin bisa jadi masukan utk pembuatan treeview di ASP.NET 1.0/1.1. Ingat kalo udah download set bagaimana menaruh image treeviewnya.
 
Private Sub BuildTreeview()

Dim oConn As SqlConnection = Nothing

Dim oSqlCommand As SqlCommand = Nothing

Dim oSqlDataReader As SqlDataReader = Nothing

Dim oSqlParameter As SqlParameter

Dim sParentID As String = ""

Dim sPSubType As String = ""

Dim sDesc As String = ""

Dim sHtml As String = ""

Dim oTree As New obout_ASPTreeView_2_NET.Tree

Try

oConn = New SqlConnection

oConn = OpenConn(ConstString)

oSqlCommand = New SqlCommand("SPD_SYSXXD01_2", oConn)

oSqlCommand.CommandType = CommandType.StoredProcedure

oSqlParameter = oSqlCommand.Parameters.Add("@SP_BUSS_CODE", SqlDbType.VarChar, 2)

oSqlParameter.Value = Session("BussCode")

oSqlParameter = oSqlCommand.Parameters.Add("@SP_CUST_CODE", SqlDbType.VarChar, 10)

oSqlParameter.Value = Session("CusHErp")

oSqlParameter = oSqlCommand.Parameters.Add("@SP_USER_IDXX", SqlDbType.VarChar, 15)

oSqlParameter.Value = Session("LgnErp")

oSqlDataReader = oSqlCommand.ExecuteReader()

oTree.AddRootNode("eDTB (Distribution System)", "ada.gif")

oTree.FolderStyle = "icons_tree"

oTree.FolderIcons = "icons_tree"

oTree.ShowIcons = True

sHtml = ""

Do While oSqlDataReader.Read()

If Trim(CType(oSqlDataReader("PSUB_CODE"), String)) = "" Or oSqlDataReader("PSUB_CODE") Is DBNull.Value Then

sParentID = "root"

sDesc = Trim(CType(oSqlDataReader("PROG_DESC"), String))

If Trim(CType(oSqlDataReader("PROG_VALU"), String)) <> "" Then

sHtml = "" & sDesc & ""

Else

sHtml = "" & sDesc & ""

End If

oTree.Add(sParentID, "id" & CType(oSqlDataReader("PROG_TYPE"), String), sHtml, oSqlDataReader("PROG_EXPX"))

Else

sParentID = "id" & CType(oSqlDataReader("PROG_TYPE"), String)

sDesc = Trim(CType(oSqlDataReader("PSUB_NAME"), String))

sPSubType = UCase(CType(oSqlDataReader("PSUB_TYPE"), String))

If sPSubType = "ENT" Then

sPSubType = "MAF16.gif"

ElseIf sPSubType = "INQ" Then

sPSubType = "search.gif"

Else

sPSubType = "aspx.gif"

End If

If Trim(CType(oSqlDataReader("PSUB_VALU"), String)) <> "" Then

sHtml = "" & sDesc & ""

Else

sHtml = "" & sDesc & ""

End If

oTree.Add(sParentID, sParentID & "sid" & CType(oSqlDataReader("PSUB_SEQN"), String), sHtml, False, sPSubType)

End If

Loop

oTreeView.Text = oTree.HTML()

oSqlDataReader.Close()

oSqlCommand.Connection.Close()

If oConn.State = ConnectionState.Open Then oConn.Close()

Catch ex As Exception

If oConn.State = ConnectionState.Open Then oConn.Close()

Response.Write(ex.Message)

Finally

oTree = Nothing

oSqlDataReader = Nothing

If Not (oSqlParameter Is Nothing) Then oSqlParameter = Nothing

If Not (oSqlCommand Is Nothing) Then oSqlCommand.Dispose()

If Not (oConn Is Nothing) Then oConn.Dispose()

End Try

End Sub

Private Sub oTreeView_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles oTreeView.Disposed

               oTreeView.Dispose()

End Sub

Tampilan:

Share this post: | | | |
by agusto | with no comments
Filed under:
Tips mewarnai datagrid row
Tuesday, August 30, 2005 10:53 PM
Mungkin rekan rekan .Net mungkin punya yang lebih bagus tolong beritahu yach....
Sebab saya juga mendapatkannya dari salah satu situs cuman saya lupa urlnya
 
1. Control ComDataGridBoolColumn.vb
 
Option Strict Off

Option Explicit On

Public Class ComDataGridBoolColumn

Inherits System.Windows.Forms.DataGridBoolColumn

Public Sub New(ByVal sMappingName As String, ByVal sHeaderText As String, ByVal iColWidth As Integer, ByVal iMaxLength As Integer, ByVal sAlignment As String, ByVal bIsReadOnly As Boolean)

MyBase.MappingName = sMappingName

MyBase.HeaderText = sHeaderText

MyBase.Width = iColWidth

MyBase.AllowNull = True

MyBase.NullValue = False

MyBase.Alignment = sAlignment

MyBase.ReadOnly = bIsReadOnly

End Sub

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)

If rowNum Mod 2 = 0 Then

backBrush = Brushes.LightGoldenrodYellow

End If

MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)

End Sub

End Class

Option Strict Off

Option Explicit On

Public Class ComDataGridBoolColumn

Inherits System.Windows.Forms.DataGridBoolColumn

Public Sub New(ByVal sMappingName As String, ByVal sHeaderText As String, ByVal iColWidth As Integer, ByVal iMaxLength As Integer, ByVal sAlignment As String, ByVal bIsReadOnly As Boolean)

MyBase.MappingName = sMappingName

MyBase.HeaderText = sHeaderText

MyBase.Width = iColWidth

MyBase.AllowNull = True

MyBase.NullValue = False

MyBase.Alignment = sAlignment

MyBase.ReadOnly = bIsReadOnly

End Sub

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)

If rowNum Mod 2 = 0 Then   ''' -> di sini bila yang genap maka di warnai dengan warna Brushes.LightGoldenrodYellow

backBrush = Brushes.LightGoldenrodYellow

End If

MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)

End Sub

End Class

2. Control ComDatagridTextBoxColumn.vb

Option Strict Off

Option Explicit On

Public Class ComDatagridTextBoxColumn

Inherits System.Windows.Forms.DataGridTextBoxColumn

Public Sub New(ByVal sMappingName As String, ByVal sHeaderText As String, ByVal iColWidth As Integer, ByVal iMaxLength As Integer, ByVal sFormat As String, ByVal sAlignment As String, ByVal bIsReadOnly As Boolean)

MyBase.MappingName = sMappingName

MyBase.HeaderText = sHeaderText

MyBase.Width = iColWidth

MyBase.TextBox.MaxLength = iMaxLength

MyBase.Format = sFormat

MyBase.Alignment = sAlignment

MyBase.ReadOnly = bIsReadOnly

MyBase.TextBox.Enabled = False

MyBase.NullText = ""

End Sub

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)

If rowNum Mod 2 = 0 Then   ''' -> di sini bila yang genap maka di warnai dengan warna Brushes.LightGoldenrodYellow

backBrush = Brushes.LightGoldenrodYellow

End If

MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)

End Sub

End Class

-------------------------------

Cara penggunaannya :

Public Sub InitData()

Dim oDpt As SqlDataAdapter = Nothing

Dim oDgts As DataGridTableStyle

Try

DataGrid1.DataSource =

oDgts.MappingName =

'Ini salah satu sample penggunaannya

oDgts.GridColumnStyles.Add(New ComDatagridTextBoxColumn("StockItemCode", "Stock Code", 80, 20, String.Empty, Convert.ToString(HorizontalAlignment.Left), False))

oDgts.GridColumnStyles.Add(New ComDatagridTextBoxColumn("ItemName", "Stock Name", 200, 20, String.Empty, Convert.ToString(HorizontalAlignment.Left), False))

Me.DataGrid1.TableStyles.Clear()

Me.DataGrid1.TableStyles.Add(oDgts)

Catch ex As Exception

MessageBox.Show(ex.Message, Me.Name & ",InitData")

Finally

oDgts = Nothing

If Not (oDpt Is Nothing) Then oDpt = Nothing

End Try

End Sub

 
 
Share this post: | | | |
by agusto | with no comments
Filed under:
Disabling the Combo Edit Box with API
Wednesday, August 24, 2005 11:42 AM
Saya  mencari cari dimana type dari combobox pada VB 6 supaya user tidak dapat mengetikkan kata di sana dan saya mendapatkan API ini yang sangat berguna buat kerjaan saya dan berhasil.
 
Tinggal gunakan saya GF_DisableComboEditControl ini dalam penggunaan nya dalam form
 
Private Const EM_SETREADONLY = &HCF

Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long
  
Private Declare Function SetWindowText Lib "user32" _
   Alias "SetWindowTextA" _
  (ByVal hwnd As Long, _
   ByVal lpString As String) As Long

Private Declare Function FindWindowEx Lib "user32" _
   Alias "FindWindowExA" _
  (ByVal hWnd1 As Long, _
   ByVal hWnd2 As Long, _
   ByVal lpsz1 As String, _
   ByVal lpsz2 As String) As Long
  
Public Function GF_DisableComboEditControl(ObjCtrl As Control)
    Dim hwndEdit As Long
    hwndEdit = FindWindowEx(ObjCtrl.hWnd, 0&, vbNullString, vbNullString)
   If hwndEdit <> 0 Then
    Call SendMessage(hwndEdit, EM_SETREADONLY, 1&, ByVal 0&)
   End If
   Exit Function
 
Errhandler:
    GF_DisableComboEditControl= False
    msgbox err.number & “-“ & err.description
End Function
 
Share this post: | | | |
by agusto | with no comments
Filed under:
Stored Procedures in SQL Server
Wednesday, August 24, 2005 7:08 AM
Saya dapatkan url ini dari Mas Kiki yang ada di milis .net supaya saya tidak lupa saya simpan di e-blog ini.
 
 

Microsoft SQL Server provides the stored procedure mechanism to simplify the database development process by grouping Transact-SQL statements into manageable blocks.  

Benefits

  • Precompiled execution.  SQL Server compiles each stored procedure once and then reutilizes the execution plan.  This results in tremendous performance boosts when stored procedures are called repeatedly. 

  • Reduced client/server traffic.  If network bandwidth is a concern in your environment, you'll be happy to learn that stored procedures can reduce long SQL queries to a single line that is transmitted over the wire.

  • Efficient reuse of code and programming abstraction.  Stored procedures can be used by multiple users and client programs.  If you utilize them in a planned manner, you'll find the development cycle takes less time.

  • Enhanced security controls.  You can grant users permission to execute a stored procedure independently of underlying table permissions.

Structure

Stored procedures are extremely similar to the constructs seen in other programming languages.  They accept data in the form of input parameters that are specified at execution time.  These input parameters (if implemented) are utilized in the execution of a series of statements that produce some result.  This result is returned to the calling environment through the use of a recordset, output parameters and a return code. That may sound like a mouthful, but you'll find that stored procedures are actually quite simple.  Let's take a look at a practical example.

Example

Assume we have the following table named Inventory:

ID Product Warehouse Quantity
142

Green Beans

NY 100
214 Peas FL 200
825 Corn NY 140
512 Lima Beans NY 180
491 Corn FL 80
379 Watermelon FL 85

This information is updated in real-time and warehouse managers are constantly checking the levels of products stored at their warehouse and available for shipment.  In the past, each manager would run queries similar to the following:

SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = 'FL'

This resulted in very inefficient performance at the SQL Server.  Each time a warehouse manager executed the query, the database server was forced to recompile the query and execute it from scratch.  It also required the warehouse manager to have knowledge of SQL and appropriate  permissions to access the table information.

We can simplify this process through the use of a stored procedure.  Let's create a procedure called sp_GetInventory that retrieves the inventory levels for a given warehouse.  Here's the SQL code:

CREATE PROCEDURE sp_GetInventory
@location varchar(10)
AS
SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = @location

Our Florida warehouse manager can then access inventory levels by issuing the command

EXECUTE sp_GetInventory 'FL'

The New York warehouse manager can use the same stored procedure to access that area's inventory.

EXECUTE sp_GetInventory 'NY'

Granted, this is a simple example, but the benefits of abstraction can be seen here.  The warehouse manager does not need to understand SQL or the inner workings of the procedure.  From a performance perspective, the stored procedure will work wonders.  The SQL Sever creates an execution plan once and then reutilizes it by plugging in the appropriate parameters at execution time.

Now that you've learned the benefits of stored procedures, get out there and use them!  Try a few examples and measure the performance enhancements achieved -- you'll be amazed!

Share this post: | | | |
by agusto | with no comments
Filed under: