Report @ localhost

I was developing an automated report maker. Its mission is to collect data from various sources (MSSQL, Excel and Access) to create a summary of the numbers. Things hit a few bumps along the way but finally after 2 days, the collecting phase (the one I thought was hard) is complete.

On to the “easy” part…

C# is such a great environment that they could have offered you with two report solution: the standard report control that comes with the framework and Business Object’s Crystal Report. I was looking for something that could accept parameters, use that for some SQL queries and display the result with a couple groupings.

Crystal report as overtly complex for the purpose, heh, and adding parameter to the query is not that easy as it depends on the project’s datasource.

The report control is even worse. I vividly recall from the last time I worked with such reports they have three tabs in the designer for me to edit data, layout and preview the result. But to my surprise, I can’t even find the preview command anywhere after I created a report in a Winform application. Not on the toolbar, not in the menu, nowhere to be found!

After a little twiddling around, I found another kind of project dedicated to report: the report wizard from the Business Intelligence studio (I happen to have SQL Server Express installed on the development machine). Exactly what I’m looking for! I just paste in the query, choose the groupings and voilà! Report to print! And they have three tabs…

I thought to myself it was all Microsoft stuff, and maybe the report viewer back from the winform project could view this, so I copied it over, point the control to the report, and execute it.

“Data source not found” is all I get.

It turned out that the world isn’t all pink like Microsoft thought (see the “just rename your file and it’ll work, we are Microsoft!” article). The business intelligence’s report is to be and only to be deployed on a report server, which is really not convenience for me since my version of SQL is Express and does not include the report server :(. From a winform application, the report viewer control will just ignore the queries you spent hours crafted in the .rdl report when you rename it to .rdlc (Because they name it report for different meanings on different tiers – A total solution on the server and a mere viewer on the client). They say you have to rebind the datasource. Easy for them to say when they aren’t binding a lot of queries together – by hand since Microsoft’s great data designer won’t allow you to create a new table with schema based on your queries, the situation is even worse for parameterized queries! =__=

Queries are naughty, so no rows for you!

I'm too lazy to parse that text (the same query run just fine from SSMS)

Folks on the ‘net have not been helpful this time. All they did was point back to the article, It’s surprising to see that something not impossible as viewing .rdl locally is impossible to do with what Microsoft allow you to use. (Yes, they allow you to preview the report locally just fine but they hid the damn report viewer!)

Who needs Microsoft when we have the Apache license? 😛

Somebody did it the hard way: they created a new parser and render the report from scratch. It have evolved for sometime: 0.5 from the like above to 4.0 latest. But still I does have limitations: some attributes are yet to be parsed and are ignored (for example, tables will not expand to accomodate the records) so the report may look a little off, but that could be fixed with a simple moving of parts. After all, this is open source software: if you wanted it to be better, dig in! 🙂

Anyways, it gets the job done. My reports are displaying expected numbers and passing parameters are painless. Cheers to the author!

RDL reports being viewed locally

Latest version of project RDL is available at FYIReporting’s homepage.

UPDATE: And don’t think you can just bind your data with the dataset designer, it won’t tell you anything when you choose the data set as the data source, but when you run it you get an ugly “not bind to an instance” error. In the end you’ll have to do things manually with Microsoft.
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(
                new ReportDataSource("Table name", new DataSetName.TableAdapter().GetData(Parameters))
);

Local browsing with CoolIris

UPDATE: You can simply use CoolIris 1.10 for the same purpsose

Full-Screen, 3D — Cooliris transforms your browser into a lightning fast, cinematic way to browse online photos and videos. Our “3D Wall” lets you fly through thousands of items in the blink of an eye on an infinitely expandable wall. To enjoy Cooliris on Google Images, Facebook, YouTube, Flickr, and hundreds of other sites, click the Cooliris icon that appears when you mouse over media on the supported site. Or enjoy Cooliris anytime by clicking the browser toolbar icon. See http://www.cooliris.com/product for details.

I was looking for an app that let me browse through my image gallery Apple style – PhotoFlip, but there seems to be none, unless I download Safari :-/. I don’t want a new browser right now, so I turned to the next best thing: CoolIris. Somehow I vividly recall this is a project started from Microsoft Research but I can’t find any trace of Microsoft there. Maybe the Cooliris team doesn’t like Microsoft in the end. 😛

Well, at least I expected it to be able to automatically detect links to picture on a page and then let me view them. It supported Flickr and Google Images off-screen loading, which is much more complicated than a list.

What a shame it doesn’t.

I’m not the only person looking for a “standalone CoolIris” to view my files, the CoolIris forum is filled with similar requests but the best response they can give is “wait” and an “CoolIris Lite” in which the effect is much simple and you seems to have to add files manually.

No problem, I can fix that.

I tried the “quick” option from the developer’s site but that turned out to be the more complicated option since I have to generate both the expression and the gallery for it to work, so I tried the full option: I created a C# application that will read files from the directory you want, write two files “media.htm” and “media.rss” to the output directory.

  • Media.htm contains one picture to activate the CoolIris icon on the toolbar, links to media.rss.
  • Media.rss is the feed that lists the files which will let CoolIris know the full list of images.

The core part of the application follows

            // Read jpg and jpeg from target directory
            string[] Files = Directory.GetFiles(textBox1.Text, "*.jp*");
            // Prepare the feed
            StreamWriter writer = new StreamWriter(textBox2.Text + "media.rss");
            writer.WriteLine("<?xml version="1.0" encoding="UTF-8" standalone="yes"?>");
            writer.WriteLine("<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss" xmlns:atom="http://www.w3.org/2005/Atom">");
            writer.WriteLine("<channel>");
            writer.WriteLine("<title>Generated photos</title>");
	        writer.WriteLine("<link>file:///" + textBox2.Text.Replace("\","/") + "</link>");
            writer.WriteLine("<description>Photos from my trip to Africa.</description>");
            int Counter = 1;
            foreach (string FileName in Files)
            {
                FileInfo Item = new FileInfo(FileName);
                writer.WriteLine("<item>");
                writer.WriteLine("		<title>" + Item.Name + "</title>");
                writer.WriteLine("		<link>" + "file:///" + FileName.Replace("\","/") + "</link>");
                writer.WriteLine("		<guid>img " + Counter.ToString() + "</guid>");
                writer.WriteLine("		<media:description>" + Item.Name + "</media:description>");
                writer.WriteLine("		<media:thumbnail url="file:///" + FileName.Replace("\","/") + "" />");
                writer.WriteLine("		<media:content url="file:///" + FileName.Replace("\","/") + "" type="image/jpeg" />");
                writer.WriteLine("	</item>");
                writer.WriteLine("");
            }
            writer.WriteLine("</channel>");
            writer.WriteLine("</rss>");
            writer.Close();
            //Prepare the HTML file
            writer = new StreamWriter(textBox2.Text + "media.htm");
            writer.WriteLine("<html>");
            writer.WriteLine("  <head>");
            writer.WriteLine("    <link rel="alternate" href="media.rss" type="application/rss+xml" title="" id="gallery" />");
            writer.WriteLine("  </head>");
            writer.WriteLine("  <body>");
            foreach (string FileName in Files)
            {
                FileInfo Item = new FileInfo(FileName);
                writer.WriteLine("<a href="" + "file:///" + FileName.Replace("\", "/") + "">");
                writer.WriteLine("<img alt="[Image]" src="" + "file:///" + FileName.Replace("\", "/") + "" class="photo">");
                writer.WriteLine("</a>");
                break;
            }
            writer.WriteLine("  </body>");
            writer.WriteLine("<html>");
            writer.Close();
            //Open the HTML file with the default browser, hopefully it's the one with CoolIris installed
            System.Diagnostics.Process.Start(textBox2.Text + "media.htm");

Application interface

Fill in the directory containing the pictures you want to view in the first text box, the second could be your temp directory. Click generate to generate the files mentioned above and open them in your default browser, click the CoolIris to activate CoolIris (this extra step is required because I don’t know how to call CoolIris on a file directly; the “Launch CoolIris” application seems to open Cooliris.com only).

I also made a command line interface with which you can call the app with 2 parameters. The first will go to “Directory” and the second to “Output”. If you run the app this way it will generate, open the file and then close itself.


Result

Download the application

Requirements:

  • .NET Framework 2.0
  • CoolIris enabled browser

Mikrypto

Splash screen

Is the name of my latest school project in cryptography; possibly the fastest project ever: only 10 hours from concept to realization with all the functionality in place. It would be great if I were in the mood to document it. But unfortunately that is not the case right now. Other than some problem with XML Serialization (specifically serialization order control and serialize to stream), the project went smoothly. The version below is a little more polished than the version I turned in.

So what does this do? In short: It let you encrypt files and send to friends who also used this application. Upon account creation, you are given a key pair (which you can access using the export function); you are free to give your key to others and vice versa. If you want to send a file to someone, just encrypt the files choosing that one as the recipient, send the file to (s) he, the receiver logins to his/her account, hit decrypt and BOOM! Files appear!

Though the process is simple, way too simple that you don’t even have to enter a password to encrypt files, it is still not cryptographically feasible for anyone to decrypt the encrypted file. Even you, the one who encoded that file(s) to send wouldn’t be able to decode it without knowing the recipient’s account detail.

If that sounds interesting, give it a try

(If you are confused, read the Vietnamese usage instruction in the PDF file)

Splash screen in C#

How come every time I build something small, no matter how trivial it could be, I wanted to share it? :-/

This afternoon, i was asked on how to do a splash screen in C#. The guy already tried threads to display they screen and and that threw an ugly exception at the user’s face. I guess it is not that simple to guess 😛

The splash screen is just a form. You can either show it on the foreground and allow your application to load on the background with thread, or just build another application and execute it with some function in the System.Diagnostic namespace, I will demo how to make a splash screen for the later since it’s easier to debug and you can show as many of them as once as you like 😛

First, you need a form, splash screen doesn’t have title bar and stuff, so change the FormBorderStyle property to none, insert a picture box and fill-docking it to the form. Why a picture box and not just the form’s background you ask? Well, the picture box is designed to host pictures and you can scale it, provide an error image for it etc. If you simply use the form itself, you’ll have to scale the picture by hand.

Next change the image attribute of the picture box to your splash bitmap. Alternatively, if you want to reuse the program without having to recompile the project, have it read the splash bitmap in the application’s directory with:

String strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6);
Bitmap img = new Bitmap(strPath + System.IO.Path.DirectorySeparatorChar + "splash.bmp");
pictureBox1.Image = img;

Put that in the Form_Load() event. The first line get the application’s directory; the Substring() is there to remove the file:// part form the returned path. The second line’s Bitmap constructor doesn’t like that 🙂

For the final touch, add a timer, set it to enabled, set your desired splash duration for interval, add a Tick event and type in

this.Close();

That’s it, F5 and you have a Splash screen to go

Splash screen

Download the source (dynamically load a bitmap)
Download the source (embedded bitmap in picturebox)

PS: That’s my actual Eclipse splash, I photoshopped it for personal use since I can’t stand the stock splash xD. But since I’m releasing this I guess I’ll have to add the source: I took it from here.

PPS: Argh, byet hosts are not compatible with WordPress’s integrated picture management T__T