Skip to main content

Posts

Showing posts with the label How To

Oracle - How to insert a string longer than 4k using C#

And this is another PITA sponsored by our good friends of Oracle ;) After being struggling whit this issue for a whole day, I finally figure it out. There is a bunch of posts on the web saying that you should change the column type on the table from let’s say LONG to CLOB or stuff like that… but I have tried it and it has no effect if you are working with C# (maybe make sense if you are working with PL. I’m not sure, haven’t test it). The thing is even if you change the column type, you’ll still get an error saying “the string literal is too long…” The way to insert strings larger than 4K into Oracle databases is using bindings. And yes, you can insert 4k plus strings into LONG columns, there is no such 4k limit. This is how you do that: * I skip error handling, disposing objects, etc… just for brevity, of course you shouldn't ;) Another interesting thing that almost every posts got wrong is that you don’t have to specify the parameter type, the library will choose th...

How to upgrade an Acer Aspire V5 122P to SSD

Just two weeks ago I've upgrade my Acer v5 to SSD, and to my surprise, by following these tutorials, everything worked as expected ;) http://www.youtube.com/watch?v=z8OJTZGdVq4 http://www.youtube.com/watch?v=ZBJsh-lkQt8 http://www.youtube.com/watch?v=dm7xY_hviaY For those who doesn’t know about the Acer Aspire V5, I think it’s the cheapest touchscreen Win8 ultrabook on the market. I forced myself to use it as development machine (running visual studio 2012, R#, SQL Server and all that stuff) and for 450 bucks, it’s more than I expected. The touchpad is decent enough (although it can be better), the keyboard works great and by throwing another 100 for a SSD into the mix, increased the overall system performance, making the Acer a budget dev machine. The only drawbacks I found so far it’s the AMD 1GHz processor (of course you cannot change that) and the plastic case, but for the price I payed for it, I’m more than satisfied. If you are on a budget, I high...

How to get windows.external to work when using Awesomium.NET – Take 2

I got asked to provide the code from my post on How to get windows.external to work when using Awesomium.NET . Since I don’t have it (I don’t know why, but it’s gone…). I decided to create a new example, post it  on this repo at github  and hopefully don't loose it anymore ;). I’m assuming you are familiar with Awesomium.NET and just can’t figure out how to get windows.external at work (which is a must have on embedded web browser controls). I’m not going to show you what is Awesomium or how to use it, there’s a lot of good tutorials on the official site  and it has no sense I retype that here. So, enough jibber jabber, let’s go to the code. First of all, be sure you setup the right platform prior to compile the code (Last time I checked Awesomium.NET only works on x86). If you download the sample code, you will find this html file within the solution.  The whole point of _external.html_click is to marshall the function call from javascript to c#...

How to replace text with images on Word documents using C#

This post it’s a reply to a question I got from a previous post that shows how to work with Word templates from C# code . If you haven’t read it, I recommend to do so because I’m not going into details here. But basically it was about how to create a Word document from a template and perform same text manipulation. So, the question from Marcel Kieboom  was “Do you know if it would be also possible to replace one of the words with an image which is locally stored?” The answer is yes, and this is how you can do that. Based on the same convention I had used in the previous post, I should have a template like this: What I’m trying to do here is replace the text [angus-young] for an actual pic of Angus. The technique I’m using it’s pretty common on web sites and basically consist in have an image with a matching name for each keyword I want to replace and then create the image path dynamically. This is the C# code to do that. * When I execute t...

How to create MS Word documents from Office templates using C#

The OpenXML SDK allows you to do pretty much anything you want with office files such as Excel, Word, etc… While many people like this library, I found it complex, unintuitive and poorly documented, not to mention the awful xml format that uses under the hood to represent the documents, styles, etc. So I decided not to use it and build my own solution. If you, like me, don’t like that library, you will find in this post an alternative approach to build word documents from templates using c#. A neat trick to work with Office is to use the macro recorder to understand how things work. The macro recorder allows you to start a macro, do something by hand, stop it, and then take a look at the generated VBA code. Once you do this, you are pretty much set. This is how it looks the template I’am going to use. Note: save the file as a Word template (.dotx) This is the code to create Word documents from C#: By running the code, you should get a document that looks...

Bending reports with NRapid

In a previous post we saw how to override report’s default format using the SetRawStyle extension method. This allows us to modify the layout and do quick fixes without touching style sheet. That’s quite handy, but if you have to add a lot of format your code will end up looking messy. In this post I’ll work with a shipping report and show you how to bend reports using the NRapid’s fluent API. So let get started. This is the first draft And the output should look something like this: As you can see we have some sort of shipping info of customer's orders. I don’t know if I've covered how to add footers in previous posts, I’ll check on that later and if I didn’t, I will. But for now, let just concentrate on formatting only. First of all I don’t like the way the footer is formatted by default. I cannot see the difference between footers and standard rows, so I’m gonna format the footer’s text to bold, just for start. Now this is the output: That’s a l...

Printing html using the embedded web browser control

In this post I’ll try to answer some questions about the web browser control and provide some workarounds for known issues involved in the printing process. I'm assuming that you have some experience with the web browser control and basic knowledge of COM and hosting APIs. So I’m not going to cover those topics. At the bottom of this page I’ve added the links to download a small library I wrote that takes care of printing HTML and a demo app so you can try it out without having to write any code by yourself. Using the code The HtmlPrinter class will allow you to print html from an URL or just passing the html as string, you can also specify the title and the number of copies you want to print. The code may look something like this: Now that we know how to use the API let get answer some questions. Why my app crashes when I try to print multiple copies of a page? Well, apparently when you send a lot of print commands to the web browser control, ther...

Working with unattended reports

In this post I‘ll show you how to create reports that NRapid will execute into an unattended mode. I strongly recommend using this kind of reports in automation scenarios only , and let the user see the print preview dialog in the rest of cases. The only difference between this reports and the standard ones, is that you will cannot make use of dialogs, the runtime will always pass in empty views to the ConfigureReport method. The ConfigureReport method will be executed, but you will have to grab the arguments from somewhere else. The execution pipeline is the same that NRapid uses for standard reports. This is the code to print out the whole list of categories in a dialogless mode. Notice that this report inherits from UnattendedReport class, this class tells to NRapid “run the report unattended”. Also notice that this class comes with a convenience method to configure the report with no arguments. You still can override the one that gets the view data but you will always ...

Nrapid, working with page breaks and report options

So far we been working with reports and exploring a couple of options on how to group data, customize dialogs and so on, but we never talk about printing. While there isn’t much to say about printing when it comes to standard reports, I mean, you execute the report, press print and you are pretty much set.  When it comes to complex reports, we have a couple of options. In this post I’m going to talk about page breaks and how they behave in reports that contain grouped data. Continuing with the categories and products example, we want to print each category in her own page (a group per page) this means that we need a page break after each group of data. By default, NRapid will not going to add page breaks after groups, because internally doesn’t knows what a group is. It just going to emit standard html based on the default style sheet or the specified raw style. The easiest way to insert page breaks, is by building the report using the “table per group” approach, ...

Raw styling reports with NRapid

Raw styling reports is s technique that allows us to override the NRapid’s default style sheet without worrying about css.  I commonly use it for quick fixes and generally work really well. But if you want to affect the global aspect of your reports, though, the way to go is modifying the nrapid-default.css file, not raw styling a report at a time.  A common scenario where you can apply this technique is when you add a table per group in your report. For instance, when you list products by category, grouped by category, you can add a table for each category (this is quite handy when it comes to printing options, more on this in futures posts) and populate that table with the corresponding group of products. So far, so good, but when you run the report you see something like this: As you may notice, the columns are not aligned across the different groups and the report looks sloppy, but don’t worry, this can be fixed with a couple of lines of code Here I...

NRapid cascade filtering take 2

In a previous post I’ve shown how to cascade filter an autocomplete's datasource.  The code looked really ugly, so I promised to take a look at the NRapid's code and see if I can do something about it. As it turns out, I can, so now you have a neat way to work with cascade filtering. This is how it works before: This is how it works now: The mayor change from the client code perspective is that now you get the whole view data in the method call responsible for filtering, instead of the object id, as it was in the previous version. And of course, you don't have to write those cryptic functions ;) You can get the source code of NRapid from  here And the sample app from  here The Northwind database is available from download at  http://www.microsoft.com/en-us/download/details.aspx?id=23654

NRapid, cascade filtering with autocompletes

When working with large sets of hierarchical data sometimes you need to provide some sort a cascade filter mechanism. For instance, in a travel agency system, you may want to be able to select a destination, like country or a region, and based on that selection, get some data sets with travel options such as hotel deals, car rentals, and so on…. Continuing with our example (products and categories) I’ll create a dialog with two autocompletes. One will give you whole list of categories and the other a filtered set of products based on the selected category. Doing this is not so hard but requires a bit of an explanation. *In this post I’ll be using a nice C#’s feature called partial application. If you don’t know what does this means, don’t worry; just look at it as a magical lambda ;). When configuring an Autocomplete it’s possible to specify a function to be executed every time the selection changes, this can be done by using the NRapid’s fluent API, and we are going to...

NRapid, customizing autocompletes take 2

In a previous post I‘ve shown you how to add columns to the autocomplete control. In that post, I used the NRapid's internal API which is a bit noisy from a syntactic perspective. In this post, I’ll show you how to do the same thing we did before, but using a cleaner syntax.  Some syntactic sugars I’ve added to the report class. (Internally it works the same way that the previous example) And as you can see, the end result is the same. On the next post, how to work with autocompletes and cascade filters. You can get the source code of NRapid from  here And the sample app from  here The Northwind database is available from download at  http://www.microsoft.com/en-us/download/details.aspx?id=23654

NRapid, customizing the autocomplete control

A while ago I got a question about the autocomplete control, “it’s possible to use records coming from different tables as an autocomplete data source?” The answer is yes, It’s possible, but requires a bit of configuration. The use case was simple, but does not fit into the NRapid default feature set. By default, autocompletes work with a data source that contains just two columns, the record id and a description field (which is used to filter records). Those two columns must come from the same table . In this case, the user wants to see additional columns coming from different tables, so the solution requires a bit of hacking. I’ll show you how to do this, by combining two tables, products and categories. Basically I’ll add the category name (from Categories) to the products autocomplete data source (which by default just has the product id and the product name, both coming from the products table). To make this thing work, we need to use the  customization f...

Working with autocompletes in NRapid

One of the main goals behind relational databases design is reduce/eliminate the amount of duplicated data. In order to do that, they split the data into multiple tables and relate them by FK. While this works really well in database terms, they don’t when it comes to searching or loading data (In highly normalized database we usually need a lot of JOINs) Continuing with an example that we were working on previous posts ( products by category ) we can see this design lines in action.  The goal of our report is allow the users to select a category, and based on that category, fetch the corresponding list of products. The problem is, if we look at the products table, the product's category is and ID (numeric), which is hard to remember and does not make any sense on his own . In this kind of scenarios, we can use the autocomplete control . This control will allows to the user to filter by description (category name) or any field that make sense to him/her and pass to ...

Working with combos in NRapid

I think that working with combos is the most complex thing that you can do with NRapid, they are hard to configure and requires a lot of plumbing code, but they are really handy when you have to work with fixed sets of options. This time I’m going to build a report that shows some employees info. The report’s dialog will allows us to filter that info based on the employees city and get smaller result sets. Cities are a fixed set of data(at least in Northwind) so combos will be a nice choice. In order to get a combo, we need to add to properties to the nested dialog. Those properties will work together to make selection works. The code may look something like this: Notice that City is annotated with the ViewIgnore attribute, this is the way to tell to engine "do not create a control for this property" . And Cities is annotated with the DispalyOptionsFor attribute pointing to City, this means that the selected option in the combo will be used to set the valu...