dimanche 15 avril 2012

Check if any string starts with any string defined in a string array

Once again, a simple problem

I want to check whether a string starts with any string in a list (it easy to make it with a character ).
My current implementation in C# is as follows, One of the easiest implementation is to create an extension method

public static class StringExtensions
        public static bool StartsWithAny(this string str,params string[] values)
            if (!string.IsNullOrEmpty(str) || values.Length > 0)
                foreach (string value in values)
                    if (str.StartsWith(value))
                        return true;
            return false;

Nothing really hard to understand I think Good work ;-)

lundi 9 avril 2012

XmlDataProvider GroupBy an item in a DataGrid (two way binding)

This post will be done in english.

I'm not reinventing the wheel but I just had to implement this a simple datagrid grouped by a certain type of value. The datasource of the datagrid come from an XmlDataProvider.

Here is the xml file sample:

<?xml version="1.0" encoding="utf-8" ?>
  <Articles nom="Telephone" value="15"  vente="500" location="60,00" />
  <Articles nom="Telephone" value="50"  vente="450" location="45,50" />
  <Articles nom="Telephone" value="250" vente="300" location="35,50" />
  <Articles nom="Television" value="15"  vente="600" location="55" />
  <Articles nom="Television" value="50"  vente="500" location="50" />
  <Articles nom="Television" value="250" vente="400" location="30" />
  <Articles nom="Tablet" value="15"  vente="475" location="40" />
  <Articles nom="Tablet" value="50"  vente="425" location="37"  />
  <Articles nom="Tablet" value="250" vente="375" location="32"  />

Here is the XAML file:

        <XmlDataProvider x:Key="xmlfile" Source="XMLtest.xml" XPath="ListeDePrix/Articles"/>
        <DataGrid AutoGenerateColumns="False">
                <CollectionViewSource x:Key="items" Source="{Binding Source={StaticResource xmlfile}}">
                        <PropertyGroupDescription PropertyName="@value" />
                <Binding Source="{StaticResource items}"/>
                <DataGridTextColumn Binding="{Binding XPath=@nom, Mode=TwoWay}" Header="nom"/>
                <DataGridTextColumn Binding="{Binding XPath=@value, Mode=TwoWay}" Header="value"/>
                <DataGridTextColumn Binding="{Binding XPath=@location, Mode=TwoWay}" Header="Renting price"/>
                <DataGridTextColumn Binding="{Binding XPath=@vente, Mode=TwoWay}" Header="Sell price"/>
                <GroupStyle />
        <Button Content="Save" Height="23" Name="button1" Width="75" HorizontalAlignment="Left" Click="button1_Click" />

I've added some code behind in order to be able to save the data into the xml file.

 private void button1_Click(object sender, RoutedEventArgs e)
            XmlDataProvider xmlfile = (XmlDataProvider)FindResource("xmlfile");

            string source = xmlfile.Source.LocalPath;

mercredi 4 avril 2012

Certification Microsoft

Voilà, le 22 mars 2012, j’ai entrepris de passer ma certification Microsoft. Celle-ci est la 70-511 : .NET Framework 4 Windows application. Je l’ai réussie et j’en suis bien heureux.