0 Comments

There are various options to build a word document in your C# code, I choose the lightweight docx nuget package. There are some really good examples on the Codeplex website of docx http://docx.codeplex.com/ if you look at the “Advanced Examples”

The thing is that Office products tend to localize variables such as table designs:

image

I am dutch, but I cannot translate it to a value of the enum `TableDesign`

If I would translate it, it would be something like listtable 7 colorful accent 6. It is still (even after this test file) not a valid entry of the table design enumeration.

using (DocX document = DocX.Create("C:/Temp/tables.docx"))
{
    foreach (TableDesign td in (TableDesign[])Enum.GetValues(typeof(TableDesign)))
    {
        Table aTable = document.InsertTable(5, 5); // because office preview is also 5 x 5
        aTable.Design = td;
        aTable.Rows[0].Cells[0].Paragraphs.First().Append(td.ToString());
    }
    document.Save();
}

 

The “source” (all 6 lines of code, lol) is available on github https://github.com/jphellemons/DocxTables but perhaps more important is the output file. This might save you some time. https://github.com/jphellemons/DocxTables/raw/master/tables.docx

 

Good luck with this small, but awesome nuget package!

Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments

Microsoft SQL Server has the ability to format the query output to xml, which is great. I used version “Microsoft SQL Server 2008 (SP3) - 10.0.5500.0 (X64)” to output XML to have a nested data structure, but there is unfortunately no first citizen support for JSON which is big on the web these days. Perhaps it is left out on purpose to make sure that people are unable to direct output their data as JSON and are forced to build a layer in between so that it can also authenticate and add security to a request. Web API is great for this. But back to the subject: I wanted to output my nested data as JSON really quickly with the minimum amount of code.

In a nutshell, I got the data as xml and converted that to JSON and send it to the output of a generic handler (*.ashx)

Here is my source code for my easy SQL2JSON solution:

private XDocument GetProducts(string q)
{
    SqlCommand comProd = new SqlCommand(@"SELECT ProductCode, ProductEan13, CategoryName FROM PRODUCTS 
        inner join CATEGORIES on products.CategoryID = CATEGORIES.CategoryID
        WHERE ((FactoryCode LIKE @name) OR (ProductCode LIKE @name)) AND (ProductDeleted = 0) for xml raw ('Product'), ROOT ('Products');");
    comProd.Parameters.AddWithValue("name", q + "%");
    string xml = SsDb.GetScalar(comProd).ToString();
    return XDocument.Parse(xml);
}

This gave me an `XDocument` object which I still have to convert to JSON

Since I was using an generic handler I retrieved the search parameter from the query string and used it as input parameter for the `GetProducts` method.

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json";
    context.Response.Cache.SetCacheability(HttpCacheability.Public);
    context.Response.Cache.SetExpires(DateTime.Now.AddDays(1));
    context.Response.Cache.SetMaxAge(new TimeSpan(24, 0, 0));

    string q = context.Request.QueryString.Get("q");
    context.Response.Write(JsonConvert.SerializeXNode(GetProducts(q)));
}

So the most important line is the last one:

context.Response.Write(JsonConvert.SerializeXNode(GetProducts(q)));

Do not forget to use the one-nuget-package-that-rules-them-all (Install-Package Newtonsoft.Json)

using Newtonsoft.Json;

 

Now you can access your JSON data source with the C# generic handler from your JavaScript

yourHandler.ashx?q=yourproductcode

I hope this has been of any help. good luck!

Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments

The first step is of course install the remote debugging tools on the debug host http://msdn.microsoft.com/en-us/library/bt727f1t.aspx#BKMK_Installing_the_Remote_Tools 

When I fire up the Visual Studio Remote Debugging Monitor (latest version 12.0.30501.0), it says that it is already running on port 4018 so I have selected a different port. I selected 4019 and went to the “Tools” menu and then “Options (Ctrl + o) I have selected 'No authentication' and check 'allow any user to debug'. 

All there is left to do, is press play on the Visual studio side and make sure that you have the same port and no-auth set.

The other option is not to go to options but go to permissions (Ctrl + p) and add my Live ID/ Microsoft account from my developing machine, but that takes more clicks and my debugging device also forgets these settings. So you have to set it at every launch. Since I am also the admin of this tiny LAN, there is no security risk here and I can go with option 1.

screenshot taken from the interwebz

I am able to remotely debug, it's just that I have to setup the debugging every time on the client side (Lenovo Miix 2 8" tablet running win8.1) The development side does not need to be reconfigured every time.

After spending some time on google/bing/duckduckgo I have found http://msdn.microsoft.com/en-us/library/bt727f1t%28v=vs.71%29.aspx which gives me details about launching the remote debugging monitor from the command line and give it some parameters.

I ended up with a small .bat file having these command line options:

`msvcmon -anyuser -noauth -port=4019`

Here is a good read with more info about remote debugger settings:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/174c2039-b316-455a-800e-18c0d93b74bc/visual-studio-2010-remote-debugger-settings-dont-persist?forum=vsdebug

Good luck debugging!

Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments

Apple’s keynote was yesterday and revealed the iPhone 6, iPhone 6 plus, Apple watch and Apple pay. (Note: no iPay and iWatch) But I was a bit disappointed about the iPhone 6. It is not that high end as you would expect for the price that they charge. I know that in the USA about 30% of the people have an iPhone, but in the rest of the world it is about 10% market share. iOs is at this moment the number two mobile operating system and in Italy is it nr 3. Please do not get me wrong, I really like apple products and the fact that they make a lot of not technical people think about options. Before Apple was popular in the Netherlands everybody just went with Windows and did not consider other options (mac, bsd, linux etc.) So let’s just compare the iPhone 6 with the Lumia 830:

iPhone 6Lumia 830
iOs 8Windows Phone 8.1 with Denim update
4.7 inch5 inch
4g lte4g lte
1334 x 7501280 x 720
8mp10mp
f2.2f2.2
noois
Optical image stabilization
1.2mp front cam0.9 mp front cam
no wireless chargingwireless charging
fingerprint readerno fingerprint reader
nfcnfc
16 gb16 gb
no expansionmicro sd
799 usd426 usd

A few questions you have to ask yourself

There are a few questions you have to ask yourself when you are spending at least 800 dollar.

A 64gb micro sd is available for about 26 euro and 128gb is 88 euro. Retail price that is. How much would Apple pay for the extra storage? Is it worth 100 dollar to double the storage?

The camera of the iPhone 6 or iPhone 6 plus is only 8mp. The plus has optical image stabilization, but the regular iPhone 6 has not.


If you do not want Windows Phone, you can Also consider Android (of course) 4.4 with the Samsung Galaxy S5. It has a fingerprint reader, can have wireless charging with an extra cover. has a 16mp camera and you can expend the storage with micro SD. It is (in the Netherlands) available from 450 euro. Which is almost half the price of an iPhone 6 (800 dollar minimum).</p><p>As I said before, I really like Apple products, but I believe that Apple has out priced themselves. I would have expected more hardware or lower prices or a combination of both. What do you think dear reader? Don’t compare the CPU and RAM, because that is tied to how a mobile operating system manages it and can only be “measured” by a lagging interface, which is not the case at either iPhone6, Nokia and Samsung models mentioned above. The iPhone 6 was just announced yesterday, so I do not have hands on experience and if I have missed a thing or two, let me know!
Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments

This post covers storing and retrieving settings with a WPF combobox for the UI. If you are looking for a solution to store settings across devices, for instance a Windows Surface tablet and a Windows Phone powered device, you should check out the blog of Mike Taulty. That is called roaming data storage. And if you are not working on an app for Windows RT/metro or Windows Phone but are just coding some WPF application, you should read this post from Scott Hanselman.

Let’s start with some code now that it’s clear what this post covers and what it doesn’t cover.

Here is my XAML from my userinterface:

<ComboBox x:Name="cbCountry" 
    SelectionChanged="ComboBox_SelectionChanged" 
    PlaceholderText="Select country" SelectedValuePath="Tag">
    <ComboBoxItem Content="Australia" Tag="au"/>
    <ComboBoxItem Content="New Zealand" Tag="nz"/>
</ComboBox>

Please note the ‘SelectedValuePath’ is being set to ‘Tag’, otherwise it would grab the ‘comboboxitem’ or ‘content’ like this:

var comboboxContent = ((ComboBoxItem)cbCountry.SelectedValue).Content;

With the value path set to tag, it will grab ‘au’ or ‘nz’ as selected value.

This is the constructor of the xaml page containing my settings.

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

this.InitializeComponent();

if (localSettings.Values.ContainsKey("country"))
{
    cbCountry.SelectedValue = localSettings.Values["country"];
}

and this is the code for the selectionchanged event of the combobox.

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
    localSettings.Values["country"] = cbCountry.SelectedValue;
}

Good luck with this small code sample. If this is not what you are looking for, please check the links mentioned at the start. I strongly believe that they take you to the code that you are looking for (if the code above is insufficient)

Pin on pinterest Plus on Googleplus Post on LinkedIn