Thursday, April 10, 2008

Quotation of the Day

"If you do serious Oracle Development, you will be clueless sooner or later." source

Tuesday, April 1, 2008

Edit .csproj file in Visual Studio

I bet everyone had the need to view or edit the content of .csproj file. I used to use notepad to do that. Accidentally I've discovered that it is possible to do so directly in Visual Studio. First you have to unload the project. You can use the context menu on the project in Solution Explorer to do so. Then this context menu changes so that it contains the item "Edit .csproj", by clicking which you can access and edit the content of .csproj file. Don't forget to "Reload Project" after you are finished.

Changing the size of paper in ActiveReports

I wanted to change the size of paper to A4. Thus I set the report's property PageSettings.PaperKind to System.Drawing.Printing.PaperKind.A4. The report designer reflected the change, but quite surprisingly I received the error when running the report:

Printer does not support A4 papersize. Please use PaperKind.Custom in your PageSettings or specify a papersize supported by the current printer

So I used PaperKind.Custom even though my printer supports A4 very well and specified the dimensions of A4 manually. What was my surprise when Adobe Acrobat Reader (viewer) still used the size of Letter! I searched ActiveReports' Support Forums and managed to find the idea of the solution: Document.Printer.PrinterName must be set to an empty string, after that you may specify both PageSettings.PaperKind and Document.Printer.PaperKind arbitrarily; the latter is esential for viewer.

Monday, March 31, 2008

Domain-Driven Design, the Book

I'm really looking forward to the Domain-Driven Design book. I've read the preface and part of chapter 1 so far and this book really seems worth reading.

Tuesday, February 12, 2008

Limited Formatting in Bind

You can specify not only what property you are binding to, but also the format that should be used. Example:
<asp:TextBox Text='<% Bind("SomeProperty", "{0:N2}") %>' />
to get number with two decimal digits.

The problem is that the format is applied in one-way manner. When the number is loaded, it is formatted perfectly. But the very same number (without editing) can be stored no more. (It depends on culture. I have discovered this when using non-us decimal separators.)

WebNumericEdit and Nullable<decimal>

I was binding Infragistics WebNumericEdit to a Nullable<decimal>. I had to set DataMode of control to NumericDataMode.Decimal. I set Nullable property to true since the value may be missing. (That is also the reason why we store the value as Nullable<decimal>.) It seemed working, but then I noticed that 0 is propagated to data instead of null. So it seems that Nullable<decimal> is not directly supported by WebNumericEdit.

After the short brainstorming, the decision was made to try to override the way how data are provided. Finally, this was sufficient to do:


public class WebNullableNumericEdit
: WebNumericEdit
{
public override object Value
{
get
{
return (this.Nullable &&
this.Text.Equals(this.NullText)) ?
null : base.Value;
}
set { base.Value = value; }
}
}

Wednesday, January 30, 2008

Overlapping Validation Groups and Duplication of Validators

I was solving the following problem: There are two buttons (B1 and B2) on a form and two fields (F1 and F2). B1 should trigger the validation of F1, while B2 makes both F1 and F2 validated.

The concept of validation groups as introduced in .NET 2.0 is well prepared for two logically independent forms of one page, but is quite not ready for above described situations (that are not so rare I think).

I rejected the idea of triggering the validation manually on button click. I wanted to follow the common pattern of validation as much as possible. I'm afraid you cannot share validators among several validation groups nor you can attach several validation groups to a single button. (The latter would be much preferred.) I introduced two validation groups, and there is a duplication of validators for F1 in order to make them included in both validation groups. This duplication is pretty systematic (only ValidationGroup property varies) and recognisable at first sight, but still it is a pitty to have it there.