Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Monday, September 15, 2008

OOP fundamentals in C#

// INHERITANCE //
public class ChildClass : ParentClass
// declare a class to inherit from another
{
public ChildClass() {} // constructor
}
// POLYMORPHISM //

public virtual void PolymorphicMethod()
{
// implementation goes here
// child classes can override the implementation
// b.c. of keyword 'virtual'
}
public override void PolymorphicMethod()

{
// used in child class to override a virtual method of a parent class
// by using keyword 'override'
}

// ENCAPSULATION //

public class MyObjectModel
{
// fields hidden from outside world by limiting scope
private string _Field1;
private string _Field2;

public void UpdateFields()
{
// class method updates private members
_Field1 = "Field1";
_Field2 = "Field2";
}
}

// ABSTRACT CLASS //

public abstract class MyAbstractClass
// abstract class can have 0 or more methods abstract
{
private string _Field1; // member variable
public string MyConcreteMethod()
// abstract class can provide concrete methods too
{ // implementation provided
}
abstract public string MyAbstractMethod();
// no implementation provided
}

public class MyConcreteClass : MyAbstractClass

// class that inherits abstract class
{
public override string MyAbstractMethod()
{ // implementation of inherited, abstract method
//(required)
}
}
// INTERFACE //

interface MyInterface
// interface must have all methods abstract
// and no member variables
{
void MyAbstractMethod1(); // no implementation provided
string MyAbstractMethod2();
}
public class MyClass : Parent Class, MyInterface

// inherits both class and interface
{
public MyClass() { } // constructor
public void MyAbstractMethod1()
{ // must provide implementation
}
public string MyAbstractMethod2()
{ // must provide implementation
}
}

Wednesday, August 13, 2008

SQL - Searching by first letter of record example

To search by the first letter of a last name in a table called Contact:

SELECT * FROM CONTACT
WHERE SUBSTRING(LASTNAME, 1, 1) = @SURNAMELETTER

Wednesday, July 16, 2008

Wednesday, July 9, 2008

Learned at work today

Enabling sorting of a gridview control (easy luckily):

Dim ds As New DataSet
'Call data method to populate dataset
ds = objData.whatever()
GridView1.DataSource = ds
If SortExpression <> "" Then
'Apply a sorting filter if applicable
Dim view As DataView = ds.Tables(0).DefaultView
view.Sort = SortExpression
GridView1.DataSource = view
End If

'Bind the data
GridView1.DataBind()

Thursday, July 3, 2008

Things I learned at work today

  1. Can pass querystring values into sql reporting services data parameters without any extra code as long as they have the same name. SQL Reporting Services tutorials
  2. Can override control properties set in skin file by using "StyleSheetTheme=" in the page directive instead of "Theme=". This assigns the same hierarchy as CSS formatting.