Aug 2 2007

ASP.NET ListView

Category:Bil@l @ 10:43

Have a look at this nice video by Dan Wahlin on the new ASP.NET control included in the Orcas release: ASP.NET ListView, which combines the features of the GridView and Repeater in addition to having paging, update, etc ...

http://blogs.interfacett.com/dan-wahlins-blog/2007/8/2/video-using-the-new-aspnet-listview-control.html

Hope you enjoy it!
Regards

Tags:

Aug 1 2007

Windows Forms inside Windows Service

Category:Bil@l @ 12:28

In a windows service that I was creating, I needed to show a Windows Form at some point and that was not working since the Windows Service operates on a background thread other than the one handling the desktop applications.

So the way to go in order to allow Windows Forms inside a Windows Service is to follow these steps:

  1. Go to Start -> Settings -> Control Panel -> Administrative Tools -> Services
  2. Open Services window
  3. Locate your running service, right click, click on the Logon Tab, then select checkbox (Allow service to interact with Desktop).

Now to fire a Windows Form inside your Windows Service, here is the code:

 Process myProcess = new Process();

        try
        {
            // Get the path that stores user documents.
            string myDocumentsPath =
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            myProcess.StartInfo.FileName = myDocumentsPath + "\\MyForm.exe";
            myProcess.Start();
        }
        catch (Win32Exception ex)
        {
            if (ex.NativeErrorCode == ERROR_FILE_NOT_FOUND)
            {
                Console.WriteLine(ex.Message + ". Check the path.");
            }

            else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
            {
                Console.WriteLine(ex.Message +
                    ". You do not have permission to access this file.");
            }
        }

Make sure to include those two constants:

        const int ERROR_FILE_NOT_FOUND =2;
        const int ERROR_ACCESS_DENIED = 5;

Also add reference to the following namespaces:

using System.Diagnostics;
using System.ComponentModel;

 

Hope this posts helped you up!
Regards

 

 

Tags:

Aug 1 2007

LEFT OUTER JOIN in LINQ To SQL

Category: C# 3.0 | DLinq | LinqBil@l @ 11:06

I was practicing a little bit on using Linq to Sql, and had this scenario:

Customers and Orders tables in Northwind Database. I added a new customer with no records, I wanted to apply a left outer join to get customers whose CustomerID starts with letter B such that, even if the Customer had no record in the Orders table, I wanted his/record to be present in the result.

The easiest way to go is to use LEFT OUTER JOIN between Customers' table and Orders' table so that I get all Customers that pass the filter expression and even have no records in the Order table, here is the Query Expression:

        NorthwindDataContext db= new NorthwindDataContext();
        var query=  from c in db.Customers
                    where c.CustomerID.StartsWith("B")
                    join o in db.Orders on c.CustomerID equals o.CustomerID into sr
                    from x in sr.DefaultIfEmpty()
                    select new {CustomerID= c.CustomerID, ContactName=c.ContactName, OrderID = x.OrderID == null ? -1 : x.OrderID};   

As you can see I used the join into operator in Query Expression which results in the LEFT OUTER JOIN, I added my filter expression in the where clause and finally, I returned an anonymous type containing CustomerID, ContactName, and OrderID which is -1 in case there is a null Order record for the Customer otherwise returns the OrderID.

The T-SQL representation of the above is as follows:

SELECT [t0].[CustomerID], [t0].[ContactName],
    (CASE
        WHEN [t1].[OrderID] IS NULL THEN @p1
        ELSE [t1].[OrderID]
     END) AS [value]
FROM [dbo].[Customers] AS [t0]
LEFT OUTER JOIN [dbo].[Orders] AS [t1] ON [t0].[CustomerID] = [t1].[CustomerID]
WHERE [t0].[CustomerID] LIKE @p0

Notice how the LEFT OUTER JOIN appears, notice how the CASE appears which reflect the if/else that I have added in the above Query Expression.

Hope this helps you!
Regards

 


You can make your own ringtones, for your cell phones; if those already set on your phones doesn’t suite you. You can download handy soft wares from electronics websites that help you make customized ringtones. These procedures carry very simple instructions still if you find some difficulty, you can use printers to print the instructions.

Tags: , ,

Aug 1 2007

Automatic Proeprties

Category: C# 3.0Bil@l @ 08:06

In every 3-tier application we develop, there is always a need for model objects, which are nothing but classes we use to pass between DataAccess, Business, and UI layers. These classes contain only
simple properties that represent the columns of a Data Table that are retrieved from the database. As you can see, those objects need not any validation logic, dummy proeprties! We can use code
generation tools like CodeSmith, or even develop ower own tools too. But with C# 3.0, no need for any code generation tools anymore!!

A new feature of C# 3.0 is the Automatic Properties, you can write model classes in a more compact way and with less code! And the rest is left to the C# 3.0 compiler!

An example makes things clear:

  public class Customer {
  public int ID {get; set;}
  public string Name {get; set;}
  public Address Address {get; set;}
    }

 public class Address {
         public string City {get; set;}
         public string Building {get; set;}
         public string Phone {get; set;}
 }

As you can see I have written a class with minimal code. What happens at compile time is that, the C# 3.0 compiler will generate a full class including private fields and this way you can use the
Customer/Address classes are any normal class with one exception, we have written fewer lines of code and the rest was on C# 3.0 compiler that generates the full class for us!

Hope this helps,
Regards

Tags: