Terje Isaksen Developer blog

2017-02-16 (Thursday)

Useful links

Filed under: Developing — Terje Isaksen @ 14:48
Tags: , , , , , , ,

ASP.Net and  Entity Framework

http://www.c-sharpcorner.com/uploadfile/raj1979/building-Asp-Net-mvc-web-applications-using-ado-net-entity-data-model/

http://www.entityframeworktutorial.net/articles/create-model-with-entity-developer.aspx

MVC

https://www.codeproject.com/articles/986730/learn-mvc-project-in-days-day

Angular

https://www.w3schools.com/angular/default.asp

Bootstrap

http://getbootstrap.com/

Advertisements

2011-06-23 (Thursday)

600+ different programming languages

Filed under: Developing — Terje Isaksen @ 12:58
Tags:

http://99-bottles-of-beer.net/

Every language from A+ to ZZT

One C# version is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _99Bottlez
{
    class Program
    {
        static void Main(string[] args)
        {
            int countOfBottles = 10;
            string lineTemplate = @"{X} bottles of beer on the wall, {X} bottles 
                                  of beer. Take one down and pass it around, {Y} 
                                  bottles of beer on the wall.";

            string lastLine =  @"No more bottles of beer on the wall, no more   
                               bottles of beer.Go to the store and buy some 
                               more, {X} bottles of beer on the wall.";

            List<string> songLines = new List<string> ();
            Enumerable.Range(1, countOfBottles)
                .Reverse()
                .ToList()
                .ForEach
                 (c => songLines.Add(lineTemplate.Replace("{X}", 
                 c.ToString()).Replace("{Y}", (c-1)!=0?(c - 1).ToString():@" No 
                 more bottles of beer on the wall.")));

            //Add the last line
            songLines.Add(lastLine.Replace("{X}", countOfBottles.ToString()));

            songLines.ForEach(c => Console.WriteLine(c));
            Console.ReadLine();
        }
    }
}

2010-09-08 (Wednesday)

C#: String formats.

Filed under: Developing — Terje Isaksen @ 14:50
Tags:

Excellent overview at:
http://blog.stevex.net/string-formatting-in-csharp/

2010-05-05 (Wednesday)

Facebook: How to develop applications

Filed under: Developing — Terje Isaksen @ 11:49
Tags: ,
This is icon for social networking website. Th...

Image via Wikipedia

See informative text on:
Stevetrefethens blog

Also:
http://wiki.developers.facebook.com/index.php/User:C_Sharp

http://www.softwaredeveloper.com/features/develop-facebook-app-072607/

2010-05-04 (Tuesday)

WPF: Missing tag gives exception “Items collection must be empty before using ItemsSource.”

Filed under: Developing — Terje Isaksen @ 14:14
Tags: , , ,

If you have a datagrid with columns and misses to use the tag <toolkit:DataGrid.Columns> – then you will get the exception “Items collection must be empty before using ItemsSource.”

Wrong:

<toolkit:DataGrid >
     <toolkit:DataGridTemplateColumn >
        <toolkit:DataGridTemplateColumn.CellTemplate>
           <DataTemplate>
               <StackPanel>
                  <toolkit:DatePicker  SelectedDate="{Binding Date, Mode=Twoway, StringFormat=yyyy-MM-dd, UpdateSourceTrigger=PropertyChanged}" />
                </StackPanel>
           </DataTemplate>
        </toolkit:DataGridTemplateColumn.CellTemplate>
     </toolkit:DataGridTemplateColumn>
</toolkit:DataGrid> 

Correct:

<toolkit:DataGrid >
  <toolkit:DataGrid.Columns>
     <toolkit:DataGridTemplateColumn >
        <toolkit:DataGridTemplateColumn.CellTemplate>
           <DataTemplate>
               <StackPanel>
                  <toolkit:DatePicker  SelectedDate="{Binding Date, Mode=Twoway, StringFormat=yyyy-MM-dd, UpdateSourceTrigger=PropertyChanged}" />
                </StackPanel>
           </DataTemplate>
        </toolkit:DataGridTemplateColumn.CellTemplate>
     </toolkit:DataGridTemplateColumn>
  </toolkit:DataGrid.Columns>
</toolkit:DataGrid> 

2010-02-14 (Sunday)

Projects: WPF Artist Phase One

Filed under: Developing,Project — Terje Isaksen @ 00:08
Tags: , , , ,

There is an artform which basically is when people throw paint, (“Abstract Expressionist – Kinetic Abstraction”, example: http://www.ecomall.com/zatar/) and this of course can be done with a computer as well.

Sample

"Art" made by this piece of code



WPF:

<Window x:Class="Graph.Window1"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Title="Window1" >
 <DockPanel LastChildFill="True">
 <StackPanel DockPanel.Dock="Top" Orientation="Horizontal"></StackPanel>
 <Grid x:Name="deGrid" DockPanel.Dock="Bottom" Background="AntiqueWhite" Height="800" Width="1600">

 </Grid>
 </DockPanel>
</Window>

Code behind:

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Graph
{
 /// <summary>
 /// Interaction logic for Window1.xaml
 /// </summary>
 public partial class Window1 : Window
 {
 DispatcherTimer timer = new DispatcherTimer();
 Random R = new Random(  );
 bool running = false;

 public Window1() {
 InitializeComponent();
 timer.Interval = TimeSpan.FromMilliseconds( 500 );
 timer.Tick += new EventHandler( timer_Tick );
 timer.Start();
 }

 private void timer_Tick( object sender , EventArgs e ) {
 Polyline imgNew = GetDrawing();
 this.deGrid.Children.Add( imgNew );
 this.deGrid.UpdateLayout();
 }

 Byte RandomByte() {
 Byte u = 0;  bool b = byte.TryParse( R.Next( 255 ).ToString() , out u );
 return u;
 }

 Color GetColor()  {
 byte A = RandomByte(); byte R = RandomByte();  byte G = RandomByte();   byte B = RandomByte();
 return Color.FromArgb( A , R , G , B );
 }

 Polyline GetDrawing(  ) {
 Color drawColor = GetColor();
 Brush drawBrush =  new SolidColorBrush(drawColor);
 Polyline u = new Polyline();
 u.StrokeThickness = R.Next(10);
 u.Stroke = drawBrush;

 double x0 = R.NextDouble() * deGrid.Width ;
 double y0 = R.NextDouble() * deGrid.Height ;
 double I = R.NextDouble() * 10000 ;

 for (int i=0; i<I; i++) {
 Point p = new Point( x0 , y0 );  u.Points.Add(p);

 x0 = x0 + R.Next( R.Next(10) ) - R.Next( R.Next(10) );
 if (x0<0) { x0 = 0; }  if (x0>deGrid.Width ) { x0 = deGrid.Width; }

 y0 = y0 + R.Next( R.Next(10) ) - R.Next( R.Next(10) );
 if (y0<0) { y0 = 0; }  if (y0>deGrid.Height) { y0 = deGrid.Height;}
 }
 u.ClipToBounds = true;
 return u;
 }

 }
}

If you become a well known artist using this software, please let me know. 😀

2010-02-11 (Thursday)

WPF Menus in code

Filed under: Developing — Terje Isaksen @ 12:14
Tags: , ,

A menu is created in XAML with

<Menu Height="22" Name="menu1" VerticalAlignment="Top" >
            <MenuItem Header="Alfa" ><MenuItem>
</Menu>

To do this in code:

public MenuItem MakeMenu()  {
        MenuItem mmm1 = new MenuItem();    mmm1.Header = "Subsubmenu";
        mmm1.Click += new RoutedEventHandler( mmm1_Click );
        MenuItem mm1 = new MenuItem();        mm1.Header = "Submenu";        mm1.Items.Add( mmm1 );
        MenuItem m1 = new MenuItem();        m1.Header = "Menu";        m1.Items.Add( mm1 );

return m1;
}
void mmm1_Click( object sender , RoutedEventArgs e )     {         MessageBox.Show( "Hepp" );        }

and then in the constructor of the window:

 public Window1()        {
         InitializeComponent();
         menu1.Items.Add( MakeMenu() );
}

2010-02-03 (Wednesday)

Mask on Textbox

Filed under: Developing — Terje Isaksen @ 17:16
Tags: , ,

Ruben Hakopian shows us how it is done:
http://rubenhak.com/?p=8

2009-11-24 (Tuesday)

Numeric to string

Filed under: Developing — Terje Isaksen @ 17:25
Tags: ,

Binding a textbox to a numeric source and formatting it is done by

<TextBox Text="{Binding Path=Fieldname, StringFormat=formatstring}"/>

where “formatstring” can for example be any of following:

Fn – fixed point number  – where n= number of decimals
Pn – percentage (value is multiplied with 100 and displayed with a %-symbol) – where n = number of decimals
Dn – integer – where n= number of digits
Nn – number with decimals and group separators, where n=number of decimals
Xn – hexadecimal integer – where n= number of digits

It can also be a string of custom numeric format characters inside a pair of single quotes which for example can be:

0 – zero placeholder, gives a digit if present – zero otherwise
# – digit placeholder, gives a digit if present, nothing otherwise
. – decimal point – determines where the decimal seperator should be
, – group separator – gives the localized group separator. Can also be used at the end to divide the number with 1000 for each comma
% – percentage placeholder – if at the end – multiplies number with 100 and gives percentage symbol at end

See more at:

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

http://blogs.msdn.com/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx


2009-11-12 (Thursday)

C# App.Config and static classes

Filed under: Developing — Terje Isaksen @ 17:40
Tags: , ,

To make the application configurable, so one can avoid to rewrite and recompile is to use App.Config.

<Configuration>
<appSettings>
    <add key = "MySetting" value="1223"/>
 </appSettings>
</Configuration>

To access this – add an reference to System.Configuration and then in the code write

string x = System.Configuration.ConfigurationSettings.AppSettings.Get("MySetting")

Now, this is a little long to write, if it is to be used in many places. The solution is to encapsulate it in a static class.

A static class is a class that don´t needs to be instanciated. The values of the properties are set at start, and cannot be changed. Perfect for config-settings.

using System;
using System.Configuration;

namespace Something
{
 public static class AppResources
 {
 public static string MySetting =  System.Configuration.ConfigurationSettings.AppSettings.Get( "MySetting" );
 }
}

No need for set or get here.

And it is used like this:

string x = AppResources.MySetting;

And no () after the property name, of course.

Blog at WordPress.com.