Monday, September 24, 2007

.NET for every-day-useful tasks :)

What do you know, it pays off to be a .NET developer :) You, of course, knew that you can develop applications for your pocket PC, but let's face it, did you ever really need to do that for your own personal pocket pc phone? Nop. There are so many freeware tools out there, that it would really be a waste of time to sit down and write them yourself. But this time... maybe it's worth it. This link describes a user scenario that we all find ourselved in all the time - the loud volume of your phone ring tone. As we walk on the street with out MP3 player in our years or in the car with the radio loud enough to cover the noisy city, we have the ring volume at the maximum level, isn't it? All good, untill we find ourselves in a meeting with the boss (and usually the rest of the colleagues) in a big or small room (size doesn't matter really). And there it goes - the phone rings.

Wouldn't it be great for our super cool phone to be as smart as us ;) ? And to adjust the volume of the ring tone according to the surrounding noises (or lack of) ? The MSDN article describes the solution.

"When .NET rocks, developers"... adjust their ring tones :)

Posted by Madalina at 16:46:34 | Permanent Link | Comments (0) |

Monday, September 17, 2007

List.FindAll

Generic lists are very powerfull 2.0 tools. If you use them, try to take advantage of every property they have. For exemple, instead of using a foreach statement to find one or more items in a list, use the Find() and FindAll() functions.

The Find All() function is used when we want to retrieve all the ietms in a list that have a certain property. Let's suppose that we the next class:

public class QuarterlyReport{

#region Private Properties

private string _complaintType;

private string _productClass;

private string _incidentGrade;

#endregion

#region Public Properties

public string ComplaintType

{ get{ return _complaintType;}}

public string ProductClass

{get { return _productClass; }}

public string IncidentGrade

{get { return _incidentGrade; }}

#endregion

...

public static List<QuarterlyReport> GetAll(...)

{ ... }

}

The GetAll() method returns all the Report objects from the database.

Sometimes you need to avoid querying the database several times. For example, the getAll() method might return objects that have diferent ComplaintType attribute values. How do you use the FindAll() method to get, from the returned list, the reports that have ComplaintType = "X" ?

First, you build a class that will serve as an implemetation of generic Predicate:

public class ReportMatcher

{

string type;

public ReportMatcher(string _type)

{

this.type = _type;

}

public bool Test(QuarterlyReport rep)

{

if (rep.ComplaintType.Equals(type) )

return true;

else

return false;

}

}

Then, all you need to do in code is to use this class as your filter:

List<QuarterlyReport> allReports = QuarterlyReport.GetAll(...);

ReportMatcher rm = new ReportMatcher("X");

List<QuarterlyReport> rep = reportErrors.FindAll(rm.Test);

If you need, you can add more preoerties to the ReportMatch class and, this way, more filters to the search.

This method also helps if you are using DataSet.Select and want to bind the result of the Select() to a data object. You can read the dataset into a generic list and then search it with FindAll().

 

Posted by Madalina at 16:04:55 | Permanent Link | Comments (0) |

Wednesday, September 05, 2007

Maintaining page vertical position at postback

If you search this in Google, you will get tons of answers that give a javascript solution - more or less complicated. If you are working on an ASP NET application, the solution can be simple and straight-forward:

Page.MaintainScrollPositionOnPostBack = true;

You can also use the SmartNavigation property, but this one is marked as deprecated.

Posted by Madalina at 11:38:11 | Permanent Link | Comments (0) |