Subsonic Simple Select and IDataReader Magic

Simple code snippet on using Subsonic Query for selecting data back.

[code:c#]

SubSonic.Query qry = new SubSonic.Query(Usr.Schema);
qry.SetSelectList(Usr.Columns.UserPkid);
qry.QueryType = SubSonic.QueryType.Select;
qry.AddWhere(Usr.UsernameColumn.ColumnName, SubSonic.Comparison.Equals, Username);

using (IDataReader reader = qry.ExecuteReader())
{
    while (reader.Read())
    {
        userpkid = long.Parse(reader[Usr.Columns.UserPkid].ToString());
    }
}

[/code]

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

Javascript Model Window Wont Fire Page_Load

I have a page that fires a popup window and in that popup window I have some logic that I need to perform in the Page_Load.

Works great the first time as the popup window gets created, the problem is each subsequent call does not fire the Page_Load event. This is because the form is still in memory and has not disposed.

So the secret to making the form go away on close code like this;

[code:c#]

        // a script to be run in client-side
        string scriptStr = "<script>window.close();</script>";

        // send the script to output stream
        ClientScript.RegisterClientScriptBlock(typeof(string), "closing", scriptStr);

[/code]

On the ASPX page put this as the very first line (as in line #1);

[code:html]<% Response.Expires = -1;%>[/code]

Super!

Enjoy!

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

Secret sauce for Nice Looking GridView

Here is the ingredients for making the Datagrid view have a nice mouse rollover to change colors.

[code:c#]

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#EEFF00'");
        e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=this.originalstyle;");
        e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gv, "Select$" + e.Row.RowIndex);
    }
}

[/code]

So yellow when the mouse is pointing at the row then back to whatever it was before the mouse was when the mouse leaves.

 

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

Scary fast, simple and effective C# CSV Parser

Ok so this guy scares me just a little.

His CSV parser works better then any other I have seen and its succient and insane effecient.

For some reason I thought the diagram on how it works was some sort of joke, but then I looked at the code and realized – well I am kinda a nucklehead.

Enjoy!

 

VN:F [1.9.11_1134]
Rating: 4.5/10 (2 votes cast)
1 Comment more...

Neat, Quick Debug to Console Output

A very easy wayt to get Debug output for your debugging purposes:

 


  • Add the ‘System.Diagnostics’ using statement to the class.
  • use the ‘Debug.WriteLine(“Batman is totally kick butt”);’ syntax to send debug signals to any listeners
  • Add a Debug listener to your tester app; 

[code:c#]TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(myWriter);
[/code]

Enjoy!

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

OpenID, Anyone?

So I am playing around with OpenID, anyone else? Seems basically like another Passport (er, excuse me its “LiveID” now, *ahem*) type service just not MS centric. I will have to get it worked into my new project, DVDCrate.com.

Found this c# library for using authenticating users against the OpenID framework. Nifty.

Enjoy!

My OpenID Badge

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

BlogEngine makes Hulk Angry!

Gotta say getting syntax highlighting working properly in BlogEngine is a real PITA.

Working on this theory but it seems currently Code Highlighting is broken. :(

[Edit] I finally got this working, thanks to this guy. Shame on BlogEngine.NET for having such absolute crappy syntax highlighting blah!

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

Using, IDisposable and Such

I was messing with a PDF generating class (PDFSharp, an excellent free .NET PDF Toolkit for creating PDF’s) and had to create a class that will load up some images (logos, watermarks, etc.) and then use those for the PDF. The problem is that these type objects are GDI+ type objects and are unmanaged objects. This became a problem because the logos I created during the PDF generation would remain in an opended state by the PDF generation class. This prevented me from deleting the logo file and just really pissed me off.

So IDisposable to the rescue. This allows me to manually manage the disposal of the unmanaged objects and then I could implement the PDF generation class in a using and viola! I was able to delete the image file with no issues.

Here and Here are a couple of great websites with notes and hints about implementing the IDisposable interface in C#. 

The only part that got me is the Finalizer and realizing that the Finalizer is called when the object is destructed by the GC. This is not safe to assume this is at the same time that the object is being disposed (end of a Using statement). So that is why some of the examples you find will have a Dispose(false) to a Dispose method. This prevents the managed objects from being collected in the destructor as the order is unpredictable. If that makes sense to you, great!

Here is a very simple class implementing the IDisposable interface;

[code:c#]
public class PDFMaker : IDisposable 
{
    // some fields that require cleanup
    private SafeHandle handle;
    // this is the Handle to the GDI+ object     
    private bool disposed = false; 
    // to detect redundant calls      
    public PDFMaker()     
    {         
        this.handle = /*&hellip;*/;
        // Cheezy example     
    }
    public void MakePDF()  
    {   
        // Do something cool here and make a PDF    
    }
    protected virtual void Dispose(bool disposing)
    {
        if (!disposed)
        {
            if (disposing)
            {
                if (handle != null)
                    handle.Dispose();
            }
            disposed = true;
        }
    }
    public void Dispose()
    {
        Dispose(true);
    }
}
[/code]

Enjoy!

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

A GUID of by any other name?

I was mokeying around today with GUID's and had a time with the durn things returning '00000000-0000-0000-0000-000000000000' as the GUID value.

The code I was using was;

[code:c#]Guid g = new Guid();[/code]

Then that would create a new Guid and set its value to '00000000-0000-0000-0000-000000000000'. Blah.

So instead I find this;

[code:c#]Guid g = Guid.NewGuid();[/code]

This generates a proper Guid value (was '1b6d4d3c-0e6e-4967-a389-281c4fb435d3' in this case).

Geez. You figure that would do what you want, someone smarter than I am about Guid's can leave a comment to clear up the mystery.

Enjoy!

 

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

Subversion (svn) MonoDevelop on Ubuntu Hardy Heron (8.04.1)

So I tried to get the MonoDevelop release in Subversion to work with Ubuntu Hardy Heron (8.04.1) and had a heck of a time getting it to work.

Finally after much chatting on the IRC channel I did these steps;

  1. Setup badgerports as a repository
  2. Do the the 'ol 'sudo aptitude update && aptitude upgrade' 
  3. Run this; 'sudo apt-get install build-essential mono-mcs mono-gmcs mon-devel libmono-dev lipango1.0-dev libgtk2.0-dev libgtksourceview2.0-cil libgecko2.0-cil monodoc libmono-system-runtime2.0-cil gettext'
  4. Ensure you have 1.9 mono-gmcs installed; 'gmcs –version'
  5. Ensure you have 1.9 mono installed; 'mono –version'
  6. Follow the Subversion setup on the Monodevelop website, all should work now

Enjoy!

 

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)

Copyright © 1996-2010 Bits, Bytes And Burps. All rights reserved.
iDream theme by Templates Next | Powered by WordPress