RSS

Monthly Archives: April 2012

Undo committed changes using TortoiseSVN

How to undo mistaken/unwanted changes in codes that have already been committed to SVN server? The example below demonstrates how to accomplish it using TortoiseSVN:

1. Right-click on the file we want to undo the changes and press TortoiseSVN->Merge.

Read the rest of this entry »

 
Leave a comment

Posted by on April 27, 2012 in SVN, Version control

 

Dependency Injection

I’d like to refactor a simple code sample to demonstrate what dependency injection is. Here I have a MessageSender class to send messages. To send a TextMessage it needs a TextMessage instance.

public class MessageSender
{
    public void SendMessage()
    {
        TextMessage myTextMessage = new TextMessage();
        myTextMessage.Send();
    }
}

public class TextMessage
{
    public void Send()
    {
        // Implements Send()
    }
}

This way the MessageSender depends completely on TextMessage. What if there’s another type named ImageMessage to be sent? I’ll have to modify the SendMessage() method like this:

Read the rest of this entry »

 
Leave a comment

Posted by on April 17, 2012 in .NET, C#, Design Pattern

 

Tags: , , , ,

Commit/Rollback in Oracle

How to do a transaction using commit and rollback in Oracle:

begin
  -- statement 1
  delete from [TableName];
  -- the savepoint used for later rollback
  savepoint [SavePointName];

  begin
    -- statement 2
    insert into [TableName]
      ([Column1],... )
    values
      ([Value1],... );
    -- statement 3
    insert into [TableName]
      ([Column1],... )
    values
      ([Value1],... );

  exception
    when others then
      -- rollback if either statement 2 or 3 fails
      rollback to [SavePointName];
  end;

  commit;

end;

Reference: Howto use Rollback/Commit in Oracle SQL

 
Leave a comment

Posted by on April 12, 2012 in Oracle, SQL

 

How to validate Windows Form user input

Here are a couple notes taken from the MSDN User Input Validation in Windows Forms article.

Where to place the validation logic :
Validating event. If the Control.CausesValidation property is set to false, the Validating and Validated events of that control will not fire.

When does the validating event execute :
1. By Form.AutoValidate property. It specifies whether the control is validated on focus change by the AutoValidate enumerated value. (Implicit validation)
2. By calling Validate or ValidateChildren. (Explicit validation)

How to close the form when validation failed using AutoValidate :
There’s no problem closing the form if AutoValidate is set to Disable or EnableAllowFocusChange. If not, set e.Cancel to false in the Form.Closing event.

Read the rest of this entry »

 
Leave a comment

Posted by on April 5, 2012 in .NET, VB, Winform

 

Tags:

Custom Dialog Box example : ChooseDateDialog

Here’s a complete example on how to show dialog box and retrieve user input. More details on Dialog Box from Dialog Boxes in Windows Forms. The ChooseDateDialog is a simple custom dialog box which is used to prompt for a date. Its functionality is like this:

First, use a simple button to call ChooseDateDialog:

Read the rest of this entry »

 
Leave a comment

Posted by on April 5, 2012 in .NET, VB, Winform

 

Tags:

VB6 Command() equivalent in .NET Framework

How to get command-line arguments in .NET:

Use the Environment.CommandLine Property to get the command-line arguments as a string.

Use the Environment.GetCommandLineArgs Method to get them as a string array.

 
Leave a comment

Posted by on April 2, 2012 in .NET, VB

 

Tags: