Showing posts with label Problems ans solutions. Show all posts
Showing posts with label Problems ans solutions. Show all posts

Wednesday, February 3, 2010

To change the colour of TAB control in .Net


To change the color of Tab control
 
Add this event handler
 
  1. DrawMode property to OwnerDrawFixed.
  2. Override the DrawItem event handler definition.
 
tabControl2.DrawItem += new DrawItemEventHandler(OnDrawItem);
 
 
step 2
 
 
 
 
 
 
private void OnDrawItem(object sender, DrawItemEventArgs e)
        {
           
            TabPage CurrentTab = tabControl2.TabPages[e.Index];
            Rectangle ItemRect = tabControl2.GetTabRect(e.Index);
            SolidBrush FillBrush = new SolidBrush(Color.Red);
            SolidBrush TextBrush = new SolidBrush(Color.White);
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
 
            //If we are currently painting the Selected TabItem we'll
            //change the brush colors and inflate the rectangle.
            if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
            {
                FillBrush.Color = Color.PaleTurquoise;
                TextBrush.Color = Color.Red;
                ItemRect.Inflate(2, 2);
            }
 
            //Set up rotation for left and right aligned tabs
            if (tabControl2.Alignment == TabAlignment.Left || tabControl2.Alignment == TabAlignment.Right)
            {
                float RotateAngle = 90;
                if (tabControl2.Alignment == TabAlignment.Left)
                    RotateAngle = 270;
                PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 2), ItemRect.Top + (ItemRect.Height / 2));
                e.Graphics.TranslateTransform(cp.X, cp.Y);
                e.Graphics.RotateTransform(RotateAngle);
                ItemRect = new Rectangle(-(ItemRect.Height / 2), -(ItemRect.Width / 2), ItemRect.Height, ItemRect.Width);
            }
 
            //Next we'll paint the TabItem with our Fill Brush
            e.Graphics.FillRectangle(FillBrush, ItemRect);
 
            //Now draw the text.
            e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);
 
            //Reset any Graphics rotation
            e.Graphics.ResetTransform();
 
            //Finally, we should Dispose of our brushes.
            FillBrush.Dispose();
            TextBrush.Dispose();
        }
 

Displaying the controls of page


Diplaying the controls
 
Public Sub DisplayControlName(ByVal oControl As Control, ByVal strPageName As String)
 
        Dim txtBox As TextBox
        Dim ddlLst As DropDownList
        Dim rdBtn As RadioButton
        Dim rdBtnLst As RadioButtonList
        Dim chkBx As CheckBoxList
        Dim chkBx1 As CheckBox
        Dim lblVal As System.Web.UI.WebControls.Label
        Dim htmTbl As System.Web.UI.HtmlControls.HtmlTable
        Dim btnVal As System.Web.UI.WebControls.Button
 
 
        ' Checks for all the WebBased Control in the web page
 
                Select Case oControl.GetType.ToString
 
 
 
                    'Case "System.Web.UI.WebControls.TextBox" ' for textbox control
                    '    txtBox = oControl.FindControl(oControl.ID)
                    '    If Not txtBox.ID Is Nothing Then
                    '        If Not txtBox.Text.ToString() Is Nothing Then
                    '            If txtBox.Text.Length > 0 Then
                    '                ArrayLst.Add(New String() {strPageName & "_" & txtBox.ID & "_" & "TextBox" & "_" & "N/A", txtBox.Text.ToString()})
                    '            End If
                    '        End If
                    '    End If
 
                    Case  MultiLang_DropDownListControl ' for Dropdownlist control
                        ddlLst = oControl.FindControl(oControl.ID)
                        If Not ddlLst Is Nothing Then
 
                        End If
 
                    Case  MultiLang_RadioButtonControl ' for radio button control
                        rdBtn = oControl.FindControl(oControl.ID)
                        If Not rdBtn Is Nothing Then
                            ArrayLst.Add(New String() {strPageName & "_" & rdBtn.ID & "_" MultiLang_RadioButton & "_" & MultiLang_NA, rdBtn.Text.ToString()})
                        End If
                    Case  MultiLang_RadioButtonListControl ' for radio button control
                        rdBtnLst = oControl.FindControl(oControl.ID)
                        If Not rdBtnLst Is Nothing Then
                            Dim MyItem As ListItem
                            For Each MyItem In rdBtnLst.Items
                                ArrayLst.Add(New String() {strPageName & "_" & rdBtnLst.ID & "_" &  MultiLang_RadioButtonList & "_" & MyItem.Value & "_" &  MultiLang_NA, MyItem.Text.ToString()})
                            Next
                        End If
                    Case  MultiLang_CheckBoxListControl
                        chkBx = oControl.FindControl(oControl.ID)
                        If Not chkBx Is Nothing Then
                            Dim MyItem As ListItem
                            For Each MyItem In chkBx.Items
                                ArrayLst.Add(New String() {strPageName & "_" & chkBx.ID & "_" &  MultiLang_CheckBoxList &"_" & MyItem.Value & "_" &  MultiLang_NA, MyItem.Text.ToString()})
                            Next
                        End If
                    Case  MultiLang_CheckBoxControl ' for checkbox control
                        Try
                            'Dim strVal As Object
                            If Not TypeOf oControl.NamingContainer Is CheckBoxList Then
                                chkBx1 = oControl.FindControl(oControl.ID)
                                If Not chkBx1 Is Nothing Then
                                    If Not chkBx1.Text.Equals(""Then
                                        ArrayLst.Add(New String() {strPageName & "_" & chkBx1.ID & "_" &  MultiLang_CheckBox & "_" &  MultiLang_NA, chkBx1.Text.ToString()})
                                    End If
                                End If
                            End If
                        Catch ex As Exception
 
                        End Try
 
                    Case  MultiLang_LabelControl ' for label control
                        Try
                            lblVal = oControl.FindControl(oControl.ID)
                            ' HttpContext.Current.Response.Write("
" & "Label:- " & lblVal.Text)
                            If Not lblVal Is Nothing Then
                                If Not lblVal.Text.Equals(""Then
                                    ArrayLst.Add(New String() {strPageName & "_" & lblVal.ID & "_" &  MultiLang_Label & "_" &  MultiLang_NA, lblVal.Text.ToString()})
                                End If
                            End If
                        Catch ex As Exception
 
                        End Try
 
 
                    Case  MultiLang_HtmlTableControl ' for fetching table control
 
                        htmTbl = oControl.FindControl(oControl.ID)
                        Dim MyRow As System.Web.UI.HtmlControls.HtmlTableRow
                        Dim mycell As System.Web.UI.HtmlControls.HtmlTableCell
                        Try
                            ' Travesing each row in the table and then traversing the cells
                            For Each MyRow In htmTbl.Rows
                                For Each mycell In MyRow.Cells
                                    If mycell.Controls(0).GetType().ToString().Equals( MultiLang_LiteralControl) Then
                                        ' If mycell.InnerText.Length > 0 Then
                                        If Not mycell.ID Is Nothing Then
                                            If Not mycell.InnerText.ToString() Is Nothing Then
                                                If mycell.InnerText.Length > 0 Then
                                                    ArrayLst.Add(New String() {strPageName & "_" & mycell.ID & "_" &  MultiLang_td & "_" &  MultiLang_NA, mycell.InnerText.ToString()})
                                                End If
                                            End If
                                        End If
                                        'End If
                                    End If
                                Next
                            Next
                        Catch ex As Exception
 
                        End Try
 
                    Case  MultiLang_ButtonControl ' for fetching button control
                        btnVal = oControl.FindControl(oControl.ID)
                        If Not btnVal Is Nothing Then
                            ArrayLst.Add(New String() {strPageName & "_" & btnVal.ID & "_" &  MultiLang_Button & "_" &  MultiLang_NA, btnVal.Text.ToString()})
                        End If
                End Select
 

Creating a Dll(asembly dynamically) + vb.net


CREATING DLL DYNAMICALLY
you need to complie this code
Public Function CreateResourceAssembly() As Boolean
        Dim currentpageHashVal As Hashtable = New Hashtable()
        Dim intArrIndx As Integer
        Dim strTextVal As String
        Dim blnIsSuccess As Boolean
        Dim strAsmFileName As String = FetchTest.resources.dll
        Dim strPathAssmbly As String = strAppPath + FetchTest.resources.dll"
 
        Dim appdomain As AppDomain = Thread.GetDomain()
        Dim asmName As New AssemblyName()
        Dim strVersion As String = Nothing
        Dim strKey As String = Nothing
        Dim hashResPage As Hashtable = New Hashtable()
        Dim ItemEnumeratorPage As System.Collections.IDictionaryEnumerator
        Dim blnIdExist As Boolean = False
 
        asmName.Name = Wpms.resources.dl
 
        Dim resourceName As String = Wpms.resources"
        asmName.CodeBase = strPath
        Dim strDate As String
        strDate = Date.Now.ToString("dd/MM/yyyy").Replace("/""")
        intBuild = CType(strDate, Integer)
        intRev = intRev + 1
        strVersion = "1.0.0" & "." & CType(intRev, String)
        asmName.Version = New Version(1, 0, 0, intRev)
        asmName.CultureInfo = New CultureInfo(strLang)
 
        Dim asmBuilder As AssemblyBuilder = appdomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave, strPath)
        Dim modulebuilder As ModuleBuilder = asmBuilder.DefineDynamicModule(strAsmFileName, strAsmFileName)
        Dim resWriter As System.Resources.IResourceWriter
        Dim blnGenEngRes As Boolean = True
        resWriter = modulebuilder.DefineResource(resourceName, "MyDescription", ResourceAttributes.Public)
 
‘ writing in resource file below is a n example ….
   Dim ItemEnumerator As System.Collections.IDictionaryEnumerator
ItemEnumerator = resHastable.GetEnumerator()
   Do While ItemEnumerator.MoveNext
                    resWriter.AddResource(CType(ItemEnumerator.Key, String), CType(ItemEnumerator.Value, String))
                Loop
 
                asmBuilder.Save(strAsmFileName) ‘ SAVING ASSEMBLY
Return blnIsSuccess
 
End Function

Fecting Page controls Dynamically + vb.net


How to fetch Page controls of web form Dynamically in vb.net

To Find the Page Controls in a Web Page
 
Public Function FindPageControl(ByVal oControlCollection As ControlCollection, ByVal strPageName As StringAsArrayList
        ' Traverses all the controls in the page
        For Each oControl As Control In oControlCollection
            DisplayControlName(oControl, strPageName)
            FindPageControl(oControl.Controls, strPageName)
        Next
        Return ArrayLst
    End Function
How to call this function
 
FindPageControl(Page.Controls, strPgName)

Iterating through controls in form + vb.net


Looop through the controls...

Private

SetTooltip(oControl, strToolTip)
FindToolTipControl(oControl.Controls, strToolTip)

Sub FindToolTipControl(ByVal oControlCollection As ControlCollection, ByVal strToolTip As String)For Each oControl AsControl In oControlCollectionNext

......................



Private Sub SetTooltip(ByVal oControl As Control, ByVal strToolTip As String)Select CaseoControl.GetType.ToStringCase "System.Web.UI.WebControls.TextBox"

Response.Write(

Dim otxt As TextBox = oControl.FindControl(oControl.ID)"
"
 & "TextBox:- " & otxt.Text.ToString())Case"System.Web.UI.WebControls.DropDownList"

Response.Write(

Dim oDdl As DropDownList = oControl.FindControl(oControl.ID)"
"
 & "DropDown :- " & oDdl.Text.ToString())Case"System.Web.UI.WebControls.RadioButton"

Response.Write(

Dim oRdbtn As RadioButton = oControl.FindControl(oControl.ID)"
"
 & "RadioButton:- " & oRdbtn.Text.ToString())Case "System.Web.UI.WebControls.CheckBox"


Dim oChkbx As CheckBoxList = oControl.FindControl(oControl.ID)'Response.Write("
" & "Ckeckboxloist" & oChkList.Items.Count.ToString())


Response.Write(

Dim MyItem As ListItemFor Each MyItem In oChkbx.Items"
"
 & "Ckeckbox:- " & MyItem.Text.ToString())Next

Case "System.Web.UI.WebControls.Label"

Response.Write(

Dim oLabel As Label = oControl.FindControl(oControl.ID)"
"
 & "Label:- " & oLabel.Text)Case"System.Web.UI.WebControls.CheckBoxList"


Dim oChkList As CheckBoxList = oControl.FindControl(oControl.ID)'Response.Write("
" & "Ckeckboxloist" & oChkList.Items.Count.ToString())


Response.Write(

Dim MyItem As ListItemFor Each MyItem In oChkList.Items"
"
 & "Ckeckboxlist:- " & MyItem.Text.ToString())Next

Case "System.Web.UI.HtmlControls.HtmlTableRow"


Dim oTbrw As HtmlTableRow = oControl.FindControl(oControl.ID)'Response.Write("
" & "Table row:- " & oTbrw.InnerText.ToString())

End Select

End Sub
End Sub

Count No of Procedure in Database

Count Procedure

select  count(*) from sysobjects where xtype='P'

other option is below

select CASE(XType) WHEN 'C' THEN 'CHECK constraint'
WHEN 'D' THEN 'Default or DEFAULT constraint'
WHEN 'F' THEN 'FOREIGN KEY constraint'
WHEN 'L' THEN 'Log'
WHEN 'FN' THEN 'Scalar function'
WHEN 'IF' THEN 'Inlined table-function'
WHEN 'P' THEN 'Stored procedure'
WHEN 'PK' THEN 'PRIMARY KEY constraint (type is K)'
WHEN 'RF' THEN 'Replication filter stored procedure'
WHEN 'S' THEN 'System table'
WHEN 'TF' THEN 'Table function'
WHEN 'TR' THEN 'Trigger'
WHEN 'U' THEN 'User table'
WHEN 'UQ' THEN 'UNIQUE constraint (type is K)'
WHEN 'V' THEN 'View'
WHEN 'X' THEN 'Extended stored procedure' END Type
, Count(*) as total from sysObjects
GROUP BY xtype

How to change the ower of tables in Microsoft SQL Server database


To do this, execute the following command on every table
exec sp_changeobjectowner '?????', 'DBO' - where ????? is the name of your database table.
Also below is the stored procedure through which you can change the owner for every table inthe database.
EXEC sp_changeobjectowner @oldownerplusobject, @new
create procedure J_ChangeObjectOwner (@type varchar(1),@old varchar(20),@new
varchar(20))
as
declare @ObjectName varchar(100)
declare @oldownerplusobject varchar(50) begin declare Cursor_Object cursor for select [name] from sysobjects where type=@type and xtype=@type open Cursor_Object FETCH NEXT FROM Cursor_Object INTO @ObjectName WHILE @@FETCH_STATUS = 0 begin
set @oldownerplusobject=@old+'.'+@ObjectName
EXEC sp_changeobjectowner @oldownerplusobject, @new
print 'Permission Changed for ' + @oldownerplusobject +' to ' + @new + ' :
Process Done'
FETCH NEXT FROM Cursor_Object INTO @ObjectName end close Cursor_Object deallocate Cursor_Object end
exec J_ChangeObjectOwner 'p','xxx','yyy'


Also below is the procedure you can first create and then execute 

if exists (select * from sysobjects where id = object_id(N'[dbo].[chObjOwner]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[chObjOwner]
GO

SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON
GO

CREATE proc chObjOwner( @usrName varchar(20), @newUsrName varchar(50))
as
-- @usrName is the current user
-- @newUsrName is the new user

set nocount on
declare @uid int                   -- UID of the user
declare @objName varchar(50)       -- Object name owned by user
declare @currObjName varchar(50)   -- Checks for existing object owned by new user
declare @outStr varchar(256)       -- SQL command with 'sp_changeobjectowner'
set @uid = user_id(@usrName)

declare chObjOwnerCur cursor static
for
select name from sysobjects where uid = @uid

open chObjOwnerCur
if @@cursor_rows = 0
begin
  print 'Error: No objects owned by ' + @usrName
  close chObjOwnerCur
  deallocate chObjOwnerCur
  return 1
end

fetch next from chObjOwnerCur into @objName

while @@fetch_status = 0
begin
  set @currObjName = @newUsrName + "." + @objName
  if (object_id(@currObjName) > 0)
    print 'WARNING *** ' + @currObjName + ' already exists ***'
  set @outStr = "sp_changeobjectowner '" + @usrName + "." + @objName + "','" + @newUsrName + "'"
  print @outStr
  print 'go'
  fetch next from chObjOwnerCur into @objName
end

close chObjOwnerCur
deallocate chObjOwnerCur
set nocount off
return 0


GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON
GO

then execute
exec chObjOwner 'test','dbo'

the result provided can be copy pasted and then executed 

Clear Project List from Start Page


Here is a nice tips to clear the Recent project list or File list from Visual Studio .Net
Run--> RegEdit  and navigate to
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\\ProjectMRUList delete unnecessary list.
similarly for FileMRuList.
Make sure not disturb other key from the registry.

How to Execute Javascript on Server Control for ASP.NET 2.0


//// Code Snippet

<form id="form1" runat="server">
    <div>
      <h3>To Exceute Client Click Eventh3>
     
      <asp:Button ID="Button1"
                  OnClientClick='javascript:alert("You Just Clicked ME!")'
                  OnClick="Button1_Click"
                  Text="Click Me!"
                  runat="server" />
     
    div>
form>

blog hints