20110522

I guess comparing the pixels was not enough... Damn!

 

arpan

On Aug 7, 2010 06:58 PM

 

hey can u tell me how to compare two images in c#.net ....i want to match two fingerprints

 

(http://www.dailycoding.com/Posts/convert_image_to_base64_string_and_base64_string_to_image.aspx)

 

20100503

ModalPopup SetFocus() (with MasterPage)

Today I had to create a login page. It’s not my first and the way things are going, certainly not the last. Only this time it was a complete separate administration site where nothing happened until the user logged-in. So, „please login” was the first message a user was seeing there. Based on my previous „experience” with DOCTYPEs and heights I knew I had poor chances to vertically center the „login div”, so I opted for AJAX’s modal popup extender with RepositionMode set to "RepositionOnWindowResize". So far, so good. I called modal popup extender’s „Show()” method on PageLoad() and everything worked as planned. Well, everything except focus. :D

Obviously, you can’t position the focus on a hidden control, so any attempt to do it from code-behind at loading time is doomed to failure. The only way to do it is JavaScript and because the ModalPopupExtender does not contain a property to do it by itself when the targeted panel is displayed, you have to do it YOURSELF.

On a quick search I found odd solutions like timers, intervals etc., all set to trigger the focus „a few miliseconds after” popup’s display. Ugly as hell. Here is my solution to this:  (if you find it useful please leave a „cheers” :D)

<script type="text/javascript" language="javascript" >
    'AJAX framework calls this when the page is loaded, if it exists, of course.
    function pageLoad() {
            mpeLoginBehaviourID = $find('mpeLoginBehaviourID') 'this is ModalPopupBehaviour’s BehaviorID="mpeLoginBehaviourID"
            mpeLoginBehaviourID.add_shown(SetFocus);
            mpeLoginBehaviourID.show();
        }

    function SetFocus() {
            $get('<%= txtUser.ClientID %>').focus(); 'this is the asp.TextBox I’m targetng.
        }
</script>


That’s it.

Oh, one more thing. If you have a MasterPage and the popup is somewhere else, you can still do it using the same mechanism AJAX uses to call „pageLoad()”:

1.  Define the pageLoad on MasterPage (it can be useful later ;))
2.  Call a „contentPageLoad” checking it’s exitance first:

<script type="text/javascript" language="javascript" >
    function pageLoad() {
        // Master pageLoad() code goes here.

        // If function contentPageLoad exists, execute it.
        if(typeof contentPageLoad == 'function') contentPageLoad();
    }
</script>

Of course, on the „login” page you will define the „contentPageLoad” function registering the „SetFocus” method and showing the modal popup.

Enjoy.

20100323

Call me, call me!

public static DataTable InsertUpdateInfoGallery()
{
    return InsertUpdateInfoGallery();
}

20100305

Boo-Hoo-Hoo (SQL unleashed series)

ALTER proc [dbo].[stp_tshrGetTestimonialsAdminList](
      @id varchar(100),
      @title varchar(100)
)
As

If(@ID=0)
      BEGIN
            SELECT tshrResort.Title, tshrTestimonial.*
            FROM  tshrTestimonial INNER JOIN
                  tshrResort ON tshrTestimonial.tshrResortID = tshrResort.ID
            ORDER BY tshrTestimonial.DateModified DESC
      END
ELSE IF(@id=null)
      BEGIN
            SELECT tshrResort.Title, tshrTestimonial.*
            FROM  tshrTestimonial INNER JOIN
                  tshrResort ON tshrTestimonial.tshrResortID = tshrResort.ID
            ORDER BY tshrTestimonial.DateModified DESC
      END
ELSE
      BEGIN
            SELECT tshrResort.Title, tshrTestimonial.*
            FROM  tshrTestimonial INNER JOIN
                  tshrResort ON tshrTestimonial.tshrResortID = tshrResort.ID
            WHERE tshrTestimonial.tshrResortID=@id
            ORDER BY tshrTestimonial.DateModified DESC
      END
GO

20100224

ToString() or not ToString()?

    public string GetDates(DateTime ArrivalDate)
    {
        DateTime ardate = Convert.ToDateTime(ArrivalDate.ToString());
        string arrivaldate = ardate.ToShortDateString().ToString();
        return arrivaldate;
    }

For greenhorns ('cause I got a few complains like „what the f__k are you talking about on those pages” :), the story goes like this:

Click on "next blog"!



:)

20100217

To be sure. (Ep. 2 - The strings)

You never know what may be hiding behind an innocent string...

if (body.Length> 17)
{
    try
    {
        output +=  body.Substring(0, 18) + "...";
    }
    catch (Exception ex)
    {
        output +=  body;
    }
}

"To be sure"

WARNING: Every new object must be cleaned! (You have no idea who used it before :))

        DataTable dtPackages = new DataTable();
        if (dtPackages.Rows.Count > 0 || dtPackages.Columns.Count > 0)
        {
            dtPackages.Clear();
            dtPackages.Columns.Clear();
            dtPackages.Rows.Clear();
        }

20100210

Second

Given this simple (working!) algorithm, please answer the next simple question:
What’s the number of rooms?
:)

if (RoomCount > 0)
{
    lblrooms.Text += dtGetRoomType.Rows[0]["Title"].ToString();
    for (int i = 0; i < RoomCount - 1; i++)
    {
        //int RoomCount = dtGetRoomType.Rows.Count;
        //lblrooms.Text += dtGetRoomType.Rows[i]["Title"].ToString();
        for (i = 0; i < RoomCount - 1; i++)
        {
            if (i > 0)
                lblrooms.Text += dtGetRoomType.Rows[i]["Title"].ToString();
            lblrooms.Text += " or ";
        }
        lblrooms.Text += dtGetRoomType.Rows[RoomCount - 1]["Title"].ToString();
    }
}

20100209

The First Entry!

    public class Item
    {
        string _name;
        ArrayList _subItems = new ArrayList();

        public Item(string name) { _name = name; }
        public string Name { get { return _name; } }
        public string Destination{ get { return _name; } }
        public ArrayList SubItems { get { return _subItems; } }
    }

...and they are surprised I’m calling them names.

20100204

Serialul "hai sa programam" are acum un nou format!

Numai de-as gasi mesajele cu perlele din vremea UBI... :)
Oricum, ce gasesc (sau produc - auch!) o sa postez aici. Sper sa ma ajute si corectorii de la Commoncensus, precum si vechii prieteni de suferinta.


The "Let's Go Programming" e-mailing series has a new format. If only I could find the hilarious pieces of code from the good old days when I used to work at UBI Soft / Gameloft, to have some archive to begin with...

Anyway, I will post here any funny piece of code I will find through the code I'm working on (or any dummy piece I will produce - ouch!). I hope my "checkers" from Commoncensus to help me ;), as well as the old suffering group from Ubi.