Friday, August 20, 2010

DateAdd : reusable Javascript function

 

While looking for a Javascript equivalent of DataAdd VB or SQL method, I came across this function which is working flawlessly. Please visit the forum post to view it directly and also as follow:

   1: function DateAdd(timeU,byMany,dateObj) {
   2:     var millisecond=1;
   3:     var second=millisecond*1000;
   4:     var minute=second*60;
   5:     var hour=minute*60;
   6:     var day=hour*24;
   7:     var year=day*365;
   8:  
   9:     var newDate;
  10:     var dVal=dateObj.valueOf();
  11:     switch(timeU) {
  12:         case "ms": newDate=new Date(dVal+millisecond*byMany); break;
  13:         case "s": newDate=new Date(dVal+second*byMany); break;
  14:         case "mi": newDate=new Date(dVal+minute*byMany); break;
  15:         case "h": newDate=new Date(dVal+hour*byMany); break;
  16:         case "d": newDate=new Date(dVal+day*byMany); break;
  17:         case "y": newDate=new Date(dVal+year*byMany); break;
  18:     }
  19:     return newDate;
  20: }

Tuesday, August 10, 2010

Using a Stored Procedure in Entity Framework 4

If you have worked with LINQ and added stored procedures to it, it would seem obvious to be able to it the same way in Entity framework.

In LINQ all you had to do is to drag the stored procedure from your Server Explorer respective data connection on your model diagram.

In entity framework 4, there are few steps and they are different.

1. On your entity diagram in visual studio, right click and choose Update Model from database.

2. Add your stored procedure from the wizard. What it does, it adds the proc to your diagram. Its not visible in .Net code yet.
If you go to Model Browser > {EntityModel}.Store > Stored Procedures, it should be visible in there now

3. Right click, Add > Function Import. Complete this according to your requirement, name of the proc you want to see in .Net, which stored proc it maps to and what is the collection it returns etc.

After step 3 you can access access the proc using an instance of context.

For more visual representation of the steps, please visit WebLog of Ken Cox

Wednesday, August 4, 2010

Extracting tags from xhtml content

There are two ways of doing it. One is the dirty way, using Mid function in VB.Net or IndexOf string method but the more appropriate way would be to use regular expressions.

Following code will get you title using regular expression
Regex regex = new Regex("<title>(?<title>.*?)</title>", RegexOptions.IgnoreCase);
Match titleMatch = regex.Match(html);
string title = titleMatch.Groups["title"].Value;
Following code will get you meta tag My_Meta

Regex regex = new Regex("<META +NAME=\"(?<name>My_Meta*?)\" +CONTENT=\"(?<content>.*?)\" */?>", RegexOptions.IgnoreCase);
Match metaMatch = regex.Match(html);

title = metaMatch.Groups["content"].Value;

Thursday, July 15, 2010

Saving objects using Entity framework

TableClass tableObject = new TableClass();
tableObject.property1 = "Hello";
tableObject.proeprty2 = "World";

// NOTE: make sure to use the same instance of entityContextObject which was used to populate the tableObject (e.g. updating back to database)
entityContextObject.AddToTableClass(tableObject);
entityContextObject.SaveChanges();

Minimize Outlook 2007/2010 to tray

Very easy fix but it should be a default I think. Anyways in 2 easy steps:

1. Click on outlook icon in Notification area (Beside the clock in task bar)
2. Choose Hide when minimized

How to minimize MSN Messenger to the system tray in Windows 7

Not sure why Microsoft has changed the behavior in Windows 7 but its annoying that it takes up two programs in task bar when its running. Follow the link below to see the solution.

Link: http://windows7center.com/tutorials/how-to-minimize-msn-messenger-to-the-system-tray-in-windows-7/

Monday, June 28, 2010