Search This Blog

Friday, November 30, 2012

How to change colums color to RadGridView (VB.NET)

Telerik > RadGridView > Cell Formatting

CellFormatting event is used to add formatting to grid cells

Because of UI virtualization in RadGridView, cell elements are created only for currently visible cells.
To prevent applying the formatting to other columns' cell elements all customization should be reset for the rest of the cell elements.
          
Example:
Change Forecolor in CellFormating Events
 

Imports Telerik.WinControls.UI
Imports Telerik.WinControls

Private Sub grd_CellFormatting(sender As System.Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles grd.CellFormatting
 
 If e.CellElement.ColumnInfo.Name = "total" Then
  e.CellElement.ForeColor = Color.Blue
 Else
  e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
 End If

End Sub






Wednesday, November 28, 2012

Cursor SQL Server

SQL Server > Data Types > Cursor

SQL Server statements produce a complete result set, but there are times when the results are best processed one row at a time. Opening a cursor on a result set allows processing the result set one row at a time. You can assign a cursor to a variable or parameter with a cursor data type.

Permissions default to any user that has SELECT permissions;

Syntax:

DECLARE cursor_name CURSOR [ LOCAL | GLOBAL ]
     [ FORWARD_ONLY | SCROLL ]
     [ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
     [ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]
     [ TYPE_WARNING ]
     FOR select_statement
     [ FOR UPDATE [ OF column_name [ ,...n ] ] ]

Example:

create table #temp
(id int)
declare @p int = 0
while @p < 10
begin
       insert into #temp
       values(@p)
       set @p = @p + 1
end

select * from #temp -- return all rows
DECLARE @id int
DECLARE c CURSOR FOR
select
   id
from
  #temp
OPEN c
FETCH NEXT FROM c INTO @id
WHILE @@FETCH_STATUS = 0
BEGIN
   print @id -- scroll row by row
    FETCH NEXT FROM c INTO @id
END
CLOSE c;
DEALLOCATE c;
drop table #temp






Find Last Day of Previous Month SQL Server

SQL Server > Built-in Functions > DATEADD Find Last Day of Previous Month

SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))






Google’s Romanian Domain Gets Taken Down By Algerian Hacker MCA-CRB



That’s not an empty threat, it seems. MCA-DRB, according to Zone-h’s registry of hacked sites, has been responsible for 5,530 site hacks and defacements to date, with many of them appearing to cover government and public services sites from countries across Asia, Africa, Europe, Australia and the Americas

By MCA-CRB



Algerian Hacker




S thanks = Mr-AdeL & i-Hmx & Lagripe-Dz All Members Sec

To Be Continued ....

Handle events for dynamic run-time controls - VB.NET

VB.NET > Statements > AddHandler > Add event to dynamic control

Use AddHandler and AddressOf to add event to dynamic control

Example

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System

Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  Dim btn = New Button() //add dynamic control to form
  btn.Text = "Click here"
  btn.Size = New System.Drawing.Size(100, 100)
  btn.Location = New System.Drawing.Point(50, 50)
  AddHandler btn.Click, AddressOf Button1_Click  //add event to control
  Me.Controls.Add(btn)
End Sub

Protected Sub Button1_Click(sender As System.Object, e As System.EventArgs)
  Dim btn As Button = sender
  MsgBox(btn.Text)
End Sub

End Class




Tuesday, November 27, 2012

readonly c#

C# > Modifiers > readonly

Readonly prevents a field to be changed.

When a field declaration includes a readonly modifier, assignments to the field introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.

Readonly fields can be initialized at runtime, unlike const.

Example 1:
            public readonly int x = 10;

Example 2:
    public partial class Form1 : Form
        {
            public class Stack
            {
                readonly int m_Size;
                public Stack()
                    : this(20)
                { }
                public Stack(int size)
                {
                    m_Size = size;
                }
            }
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                Stack st = new Stack();
            }
        }






Monday, November 26, 2012

Math.Round

C#  > System > Math class > Round

Rounds a double-precision floating-point value to a specified number of fractional digits.

Example:

using System;

public class Round
{
   public static void Main()
   {
      double value = 4.254;
      Console.WriteLine("{0} => {1}", value, Math.Round(value, 0));
   }
}
// Result
// 4.254 --> 4