2010-ta uspješna bloging godina


Još nekoliko sati dijeli nas od nove godine, u kojoj svi očekujemo da bude bolja od prethodne, po pitanju svih sfera života: poslovne, životne, i svake druge. Posebno u Bosni i Hercegovini ljudi isčekuju poboljšanje prije svega političke, a onda i ekonomske situacije, otvaranje radnih mjesta, i boljeg života. Ali to zasigurno jos nećemo dočekati ma koliko to priželjkivali.

2010 godina za blog je pravi procvat. Kao nikad do sada ljudi su dolazili na blog i čitali postove koje sam pisao. A ove godine pisao sam ne samo o .NET tehnologijama i programskom jeziku C#, nego i drugim temama, poput društvenih mreža, reportaža sa ICT konferencija, i sl, tako da je i oficijelna WordPress ocjena sljedeća:

Healthy blog!
Blog-Health-o-Meter™ ocjena  Wow.

Preko 22.000 puta blog je otvorio neko na webu. U 2010 godini napisao sam 82 nova posta, tako da je arhiva narasla na 152 blog posta, dovoljna da se napišu dvije knjige. Najprometniji dan bio je 7. juli sa 205 pregleda.

Stranice s kojih je najviše dolazilo čitalaca je google.com, twitter.com, facebook.comgpdotnet.codeplex.commscommunity.ba .

Pored nedvojbene statistike bhrnjica.wordpress.com blog se uvrstio u prvih 15 blogova u BiH, a poredak se redovno ažurira na Prvom BH blog direktoriju: http://www.bhblog.ba

Ove godine sam konačno objavio nedovršeni tekst iz 1996 godine iz matematike, koji se dosta puno čitao na blogu. Napisao sam 4 blog posta u kojoim sam sumirao cjelokupni tekst a na kraju kad sam ga iz rukopisa pretvorio u digitalnu formu i objavio.

GPdotNET open source projekt takodjer se puno čitao i posjećivao. Ljudi iz cijelog svijeta većinom profesori javljali su se mailom da upitaju i pohvale projekat, kao i da postave pitanje ili problem na koji su nailazili. Poprilično je posjećen na codeplex stranici obzirom da je projekat vezan za uska područja modeliranja i evolucijskih algoritama.

2010 godine počela je saradnja i sa prvim ITPro elektronskim magazinom u BiH za IC Tehnologije. Objavljeno je nekoliko članaka koje sam pisao, a još nekoliko će se objaviti u skoroj budućnosti.

Ove godine osnovao sam i pokrenuo Bihac .NET user grupu koja je već održala 5 sastanaka i preko 120 ljudi prisustvovalo sastancima. Odziv za grupu je vrlo dobar i u narednom periodu očekujem još veću popularnost.

Druga polovina godine na profesionalnom planu bilježi veću angažiranost na Silverlight i Windows Phone 7 tehnologijama. U toku je realizacija jednog Silverlight projekta na kojem intenzivno radim. Otud i 4 nastavka blog posta iz teme Rzvoja Silverlight poslovnih aplikacija.

I na kraju da objavim statistiku mojih načitanijih blog postova u 2010 godini, a da ne bi bilo štele biće prikazan screenshot statistike:

Kao što se može vidjeti najčitaniji blog post je WinForms Chart kontrola, iza nje je Matematička indukcija i slijede ostalih 20 blog postova i stranica na blogu.

Stranica sa najviše komentara je GPdotNET sa 23 komentara.

Sretna nova godina!
Happy new year!

Advertisement

Silverlight 4 Business Application Part 4 od n


Implementation of the DBNavigation control in Silvelright 4

naslovThis is 4th part of the series of Silverlight Business Application development, which I am writing. Today we will try to implement DBNavigator control.

With Silverlight 4 and RIA services you can develop full business application with backend SQL database on the similar way as you can do in Windows Forms and Windows Presentation Foundation. In the previous posts we have seen how easy connect database to your Silverlight application, and also how to use some patterns in Silvelright aplication like MVVM.
I this post we will see how to implement Database Navigation control like BindingNavigator from Windows Forms. On the other hand we will also see how to extend functionality of the existing Silverlight control by developing custom control derived from existing one, as well as the procedure how to create Silverlight User control.

Our Tutorial will start from the previous blog post, so you need to download source code sample, and start our today’s tutorial. When you download source code, open it in Visual Studio 2010.

 

  • Right click on the solution and chose  Add->New  Project
  • Select Silvelright Class Library project template, give it the name SLCustomCtrl, and click OK button.

sl1

Now that you have the new Silverlit Class Library project in your solution, you have to add reference to your main Silverlight project.

  • Right click on References of theSLDemoPart2 project,  and chose Add->Reference, click Project Tab in the new dialog, and chose SLCustomCtrl project.

Implementation of Custom Control

If you want to extent functionality from the existing Silverlight control you have to add the new Silverlight Templated Control, and starting extend the new functionality from the existing one.

  • Right click on the SLCustomCtrl project, chose Add->New Item, and choose Silverlight Templated Control, name it SLDBNavigator.cs, and hit Add button.

sl2Open SLDBNavigator.cs and put the following source code:

public class DBNavigationBaseCtrl : Grid
{
    public event RoutedEventHandler AddNew;
    public event RoutedEventHandler DeleteCurrent;
    public event RoutedEventHandler DomainDataChanged;

    public DBNavigationBaseCtrl()
    {

    }
    public DomainDataSource DomainData
    {
        get { return (DomainDataSource)GetValue(DomainDataProperty); }
        set
        {
            SetValue(DomainDataProperty, value);
            OnDomainDataChanged(new RoutedEventArgs());

        }
    }

    private void OnDomainDataChanged(RoutedEventArgs e)
    {
        if (DomainDataChanged != null)
            DomainDataChanged(new object(),e);
    }

    public static readonly DependencyProperty DomainDataProperty =
        DependencyProperty.Register("DomainData", typeof(DomainDataSource), typeof(DBNavigationBaseCtrl), new PropertyMetadata(null));
    public bool IsCustomDelete
    {
        get { return (bool)GetValue(IsCustomDeleteProperty); }
        set { SetValue(IsCustomDeleteProperty, value); }
    }

    public static readonly DependencyProperty IsCustomDeleteProperty =
        DependencyProperty.Register("IsCustomDelete", typeof(bool), typeof(bool), new PropertyMetadata(false));

    protected void OnEventAddNew(RoutedEventArgs e)
    {
        if (AddNew != null)
            AddNew(new object(), e);
    }
    protected void OnEventDeleteCurrent(RoutedEventArgs e)
    {
        if (DeleteCurrent != null)
            DeleteCurrent(new object(), e);
    }
}

Implementation of the previous source code contains the three Routed Event Handlers, and two properties. The source code is very simple so you can see very quickly what’s going on in the source code.

Implementation of User Control

Now that we have base custom control for manipulation database tables and views, we need to implement custom Silvelright control derived from it  to expose implemented properties and events from the base class in to XML.

  • Right click on SLCustmCtrls project, chose Add->New Item, select Silverlight User Control, name it DBNavigatorCtrl.xaml, and click Add button.

sl3

Implementation is achieved with putting  several buttons in to controls and subscribe to corresponded click events. The implementation of the DBNavigationCtrl is in the following two listing:

<!--DB Navigator-->
    <StackPanel Margin="2" Orientation="Horizontal" HorizontalAlignment="Center" >
        <Button Content="&lt;|" Height="Auto" Name="btnFirst"  Width="30" Click="btnFirst_Click" />
        <Button Content="&lt;" Height="Auto"  Name="btnPrev"   Width="30" Click="btnPrev_Click" />
        <TextBlock Width="70" Name="textCurrentItem" Text="" TextAlignment="Center" VerticalAlignment="Center"></TextBlock>
        <Button Content="&gt;" Height="Auto"  Name="btnNext"  Width="30" Click="btnNext_Click" />
        <Button Content="|&gt;" Height="Auto" Name="btnLast"  Width="30" Click="btnLast_Click" />
        <Button Content="+" Height="Auto"  Name="btnAdd"  Width="30" Click="btnAdd_Click" />
        <Button Content="-" Height="Auto" Name="btnDelete"  Width="30" Click="btnDelete_Click" />
    </StackPanel>
public partial class DBNavigatorCtrl : DBNavigationBaseCtrl
{
    public DBNavigatorCtrl()
    {
        InitializeComponent();
        this.DomainDataChanged += new RoutedEventHandler(DBNavigatorCtrl_Loaded);

    }

    void DBNavigatorCtrl_Loaded(object sender, RoutedEventArgs e)
    {
        if (DomainData != null)
        {
            DomainData.DataView.CurrentChanged += (ss, ee) =>
            {
                var dds = ss as DomainDataSourceView;

                if (dds != null)
                    textCurrentItem.Text = (dds.IndexOf(dds.CurrentItem) + 1).ToString() + "/" + dds.Count.ToString();
                else
                    textCurrentItem.Text = "0/0";
            };
        }
    }

    private void btnFirst_Click(object sender, RoutedEventArgs e)
    {

        if (DomainData != null)
            DomainData.DataView.MoveCurrentToFirst();
    }

    private void btnPrev_Click(object sender, RoutedEventArgs e)
    {
        if (DomainData != null)
            if (DomainData.DataView.CurrentPosition > 0)
                DomainData.DataView.MoveCurrentToPrevious();
    }

    private void btnNext_Click(object sender, RoutedEventArgs e)
    {
        if (DomainData != null)
            if (DomainData.DataView.CurrentPosition + 1 < DomainData.DataView.Count)
                DomainData.DataView.MoveCurrentToNext();
    }

    private void btnLast_Click(object sender, RoutedEventArgs e)
    {
        if (DomainData != null)
            DomainData.DataView.MoveCurrentToLast();
    }

    private void btnAdd_Click(object sender, RoutedEventArgs e)
    {
        if (DomainData == null)
            return;
        RoutedEventArgs e1 = new RoutedEventArgs();
        OnEventAddNew(e1);
    }

    private void btnDelete_Click(object sender, RoutedEventArgs e)
    {
        if (DomainData == null)
            return;
        if (IsCustomDelete)
        {
            RoutedEventArgs e1 = new RoutedEventArgs();
            OnEventDeleteCurrent(e1);
            return;
        }
        if (MessageBox.Show("Confirm delete by clicking the OK button",
                              "Deleting a record ...", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
        {
            DomainData.DataView.Remove(DomainData.DataView.CurrentItem);
        }
    }
}

Using DBNavigaorCtrl in Silvelright project

When we have DBNavigatorCtrl control, it is very easy to use it. Just put the control in to XAML, and in code behind assign it to domain data source of the Main Page.
Now select the main Silverlight project,and open MainPage.XAML, from the toolbox windows select DBNavigationCtrl item and drag and drop to mainpage, similar as picture shows below. If you don’t see DBNavigationCtrl in the ToolBox you have Rebuild the solution.

sl4

The result of our tutorial looks likes on the following picture:

sl5

The source code for this tutorial can be downloaded from here.
Implementation of the DBNavigation control in Silvelright 4

Silverlight 4 Business Application Part 3 of n


Implementation of the Login Dialog in Silverlight application by using MVVM pattern

imageIn the third article, of the series of the Silvelright Business application development, I will present Login dialog implementation by applying  MVVM pattern. Problems looks very simple but if you want to implement in MVVM fashion you could encounter some problems. MVVM pattern became very popular in Silverlight and WPF application development and it seams to be standard development pattern. More information about the pattern can be found on various blogs, internet sites and forums.  One of the first and the best article about MVVM patern is MSND article about MVVM patern by Josh Smith and it can be found here.

This tutorial assume that you know basic principles of the MVVM pattern as well as Silverlight application.

In tis tutorial we will use the MVVM toolkit the implementation of the MVVM pattern developed by Laurent Bugnion, which you can download at http://mvvmlight.codeplex.com/. Before we start the tutorial, download the toolkit and install it as it decribed on the codeplex site.

The idea of the Login dialog, presented here, not depends of the MVVM light toolkit, so it can be easily implemented with other MVVM pattern, like PRISM and others.

Start Visual Studio 2010, and select File->New –>Project, select Silverlight Application in the same way we implemented in Part 2. Instead of Silverlight Aplication, select MvvmLight (SL4) template as picture below shows. After we choose the template, and click OK, Visual Studio designer created Silverlight application which support MVVM pattern.

The picture below shows The New Project dialog window:

image

As you can see Visual Studio created Silverlight application, but not the ASP.NET web application project. For this tutorial we don’t need it.

image

The picture above shows project files and how files are arranged in the project. The folder ViewModel contains the ViewModels implementations. Lets create View folder, it will contain Views implementation.

Implementation of MainView and MainViewModel

MainViewContent will be our main content for the Silverlight application. It will be shown after we logged in.

1. Right Click on the recently created View folder, and choose Add->New Item

2. Select Silverlight User Control and give it name MainViewContent.xaml

image

3. In the XAML file put the following code:

<Grid x:Name="LayoutRoot" Background="White">
        <TextBlock Text="MAIN CONTENT OF THE SILVERLIGHT APPLICATION"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Top"
                   FontSize="16" FontFamily="Arial Black" />
</Grid>

Implementation is simple. Just TextBlox with some text.

Now we need to create MainViewModelContent:

4. Right Click on the ViewModel folder, and choose Add->New Class

5. Name it MainViewModelContent.cs

Implementation of the MainViewModelContent is in the following listing:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight;

namespace SLPart3MvvmLoginDialog.ViewModel
{
    public class MainViewModelContent : ViewModelBase
    {

    }
}

The implementation is empty cause we want the empty view model without interaction with the view .

Implementation of LoginView and LoginViewModel

Similar as previous we create LoginView.Xaml and LoginViewModel.cs.

Xaml implementation of the LoginView contains controls and layout depicted in the first picture of the article. Here is the main xaml code:

<Border BorderThickness="1" BorderBrush="Black">
        <Grid x:Name="LayoutRoot1" Background="White">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="120" />
                <ColumnDefinition Width="120" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition Height="30" />
                <RowDefinition Height="28" />
                <RowDefinition Height="28" />
                <RowDefinition Height="40" />
                <RowDefinition Height="28" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Rectangle x:Name="rectangle1" Stroke="Black" StrokeThickness="1" Fill="#FFDE8836" Grid.ColumnSpan="4" />
            <TextBlock Grid.Row="2" x:Name="textBlock2" Text="User Name:" Padding="5" HorizontalAlignment="Right"
                       VerticalAlignment="Center" Grid.Column="1" Margin="0,9" />
            <TextBlock x:Name="textBlock3" Text="Password:" Grid.Row="3" Padding="5" HorizontalAlignment="Right"
                       VerticalAlignment="Center" Grid.Column="1" Margin="0,9" />
            <TextBox Grid.Column="2" Grid.Row="2" x:Name="textBox1" Margin="2" Text="{Binding UserName, Mode=TwoWay}" />
            <PasswordBox Grid.Column="2" Grid.Row="3" x:Name="passwordBox1" Margin="2"  Password="{Binding Password, Mode=TwoWay}"/>

            <Button Content="Cancel" Grid.Column="1" Grid.Row="5" x:Name="radButton1" Margin="5,2" />
            <Button Content="Login" x:Name="radButton2" Grid.Column="2" Grid.Row="5" Margin="5,2" >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <mvvmcmd:EventToCommand Command="{Binding LoginCommand, Mode=OneWay}"
                                CommandParameter="{Binding Main, Source={StaticResource Locator}}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <TextBlock x:Name="textBlock1" Text="Login Dialog" VerticalAlignment="Center" HorizontalAlignment="Center"
                       Grid.ColumnSpan="2" Margin="10,5,5,12" Grid.Column="1" FontFamily="Portable User Interface"
                       FontSize="20" FontStretch="SemiCondensed" FontWeight="SemiBold" Foreground="Black"/>
        </Grid>
</Border>

The main part of this xaml code above is that the MainViewModel is passed as a parameter of the Login button EventToCommand, and if the login is correct, the LoginModelView change IsLoggedIn property to true. Then main page switch the visibility property of the LoginView to Collapsed, and MainContentView to Visible.

Implementation of the LoginViewModel.cs is show on the next listing:

//Constructor
public LoginViewModel()
  {
    this.LoginCommand = new RelayCommand<object>(this.OnLogging, this.CanLogging);
  }
//Wnen the user click Login button in LoginView
private void OnLogging(object arg)
  {
   var vm = arg as MainViewModel;
   if (vm == null)
      return;

   //proces of logging
   vm.IsLogged = true;
   }

private bool CanLogging(object arg)
   {

     return true;
   }

ModelView coresponding classes is always derived from the ModelViewBase.

Putting all together in MainPage and ManViewModel

Now, when you implemented Login  and MainContent, we need put these objects in to MainPage. The MainPage is responsible of showing and hiding these views.

Implementation of the MainPage.xaml

<Grid x:Name="LayoutRoot">

        <my:MainViewContent Visibility="{Binding Main.IsLogged,
                      ConverterParameter=mainView,
                      Converter={StaticResource MainPageBoolLoginToVisibilityConverter1},
                      Source={StaticResource Locator}}"/>
            <my:LoginView Visibility="{Binding Main.IsLogged,
            ConverterParameter=loginView,
            Converter={StaticResource MainPageBoolLoginToVisibilityConverter1},
            Source={StaticResource Locator}}" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>

Implementation of the MainViewModel

public const string IsLoggedPropertyName = "IsLogged";
private bool _islogged;
public bool IsLogged
 {
   get
    {
      return _islogged;
    }
   set
    {
      if (value != _islogged)
      {
        _islogged = value;
        RaisePropertyChanged(IsLoggedPropertyName);
      }
    }
  }

public MainViewModel()
  {
    if (IsInDesignMode)
    {
     // Code runs in Blend --> create design time data.
    }
    else
    {
     // Code runs "for real"
    }
}

As you can see we implemented IsLogged property, which is the switch between Login and MainViewContent. With BoolToVisibilityConverter class, we were implemented changing visibility of the Views. The converter class is in the source code of the project attached with this tutorial.
Now at the end we have to implement LoginVieModel and MainContentViewModel in to Locator class.
The implementation is very simple and you can see it in the sourcecode project. Now run the application and clik the Login button, The MainContentView appears.

Summary

This article present the simple technique you can easily implement in your Silverlight application with full fashion of the MVVM pattern.

The source code can be download from  here.