MVC using console program

This short article shows you how to create a MVC program using C# Console project.

MVC is a pattern that does not bound to any programming language. It belongs to neither Java nor .NET.

I modified the sample from http://congeritc.blogspot.in/2013/01/mvc-example-with-c-console-program.html to put all the classes in a single file.

Main Program

class Program

{

    static void Main(string[] args)

    {

        {

            TipCalculatorController t = new TipCalculatorController();

        }

    }

}

 

The Model

class Tip

{

    //private fields

    private double amount;

    private double tipPercent;

    //default constructor

    public Tip()

    {

        Amount = 0;

        TipPercent = 0;

    }

    //overloaded constructor

    public Tip(double amt, double percent)

    {

        Amount = amt;

        TipPercent = percent;

    }

    //public properties

    public double Amount

    {

        get { return amount; }

        set { amount = value; }

    }

    public double TipPercent

    {

        get { return tipPercent; }

        set

        {

            if (value > 1)

            {

                value /= 100;

            }

            tipPercent = value;

        }

    }

    public double CalculateTip()

    {

        //very simplistic tip calculation

        return Amount * TipPercent;

    }

    public double CalculateTotal()

    {

        //simple total calculation

        return CalculateTip() + Amount;

    }

}

 

The View

 

class Display

{

    ///

    //private fields

    private double perc;

    private double amt;

    private double total;

    private double tipAmount;

 

    //constructor

    public Display()

    {

        Percentage = 0;

        TipAmount = 0;

        Amt = 0;

        Total = 0;

        GetValues();

    }

 

    //public properties

    public double TipAmount

    {

        get { return tipAmount; }

        set { tipAmount = value; }

    }

 

 

    public double Total

    {

        get { return total; }

        set { total = value; }

    }

 

 

    public double Percentage

    {

        get { return perc; }

        set { perc = value; }

    }

 

    public double Amt

    {

        get { return amt; }

        set { amt = value; }

    }

 

    private void GetValues()

    {

        Console.WriteLine(“Enter the Amount of the meal”);

        Amt = double.Parse(Console.ReadLine());

 

        Console.WriteLine(“Enter the percent you want to tip”);

        Percentage = double.Parse(Console.ReadLine());

    }

 

    public void ShowTipandTotal()

    {

        Console.WriteLine(“Your tip is {0:C}”, TipAmount);

        Console.WriteLine(“The total will be {0:C}”, Total);

        Console.ReadKey();

    }

}

 

The Controller

 

class TipCalculatorController

{

    private Tip tip;

    private Display display;

 

    public TipCalculatorController()

    {

        display = new Display();

        tip = new Tip(display.Amt, display.Percentage);

        display.TipAmount = tip.CalculateTip();

        display.Total = tip.CalculateTotal();

        display.ShowTipandTotal();

    }

}

You can also download the source code from http://onedrive.com. The sample file name ConAppMVC.zip. My MSN ID is chanmmn@hotmail.com.

Posted in .Net, Community | Tagged , , , | Leave a comment

Windows 10 Developer Readiness

http://mvp.microsoft.com/en-us/win10mvp.aspx

We’re excited to offer a series of live webcasts that deliver first-hand guidance on how you can leverage the new Windows 10 development model. The webcasts will be presented and moderated by Microsoft MVPs around the world at no charge and are a great opportunity for you to not only learn the foundations of Universal App Development in Windows 10, but also to connect with some of the top experts in your country and/or language. Bring your Windows Store app development questions and have them answered live, by the experts, and learn how to take advantage of the great opportunities ahead in the Universal Windows Platform.
  • Each webcast will deliver the same content in different countries from June 8 – 12.
  • They will last from one to three hours, depending on the amount of community interaction.

Microsoft is empowering the MVPs with technical content and private training so every session will be fully equipped with content, demos, and up-to-date guidance.

We hope you join and connect with us for this great worldwide initiative!
Posted in .Net, Community | Tagged , | Leave a comment

Microsoft SQL Server 2016 Preview Sign Up

You can sign up for Microsoft SQL Server 2016 Preview at the below link:

http://www.microsoft.com/en-us/server-cloud/products/sql-server-2016/?CR_CC=200630682

I am still waiting for the email notification after signed up.

Posted in .Net, Community | Tagged , , | Leave a comment

WCF Interview Questions

I found few good webpages on WCF interview question.

1. Interview Questions Answers – Windows Communication Foundation (WCF)

http://www.codeproject.com/Articles/759331/Interview-Questions-Answers-Windows-Communication

2. WCF – Top 10 Interview Questions

http://www.codeproject.com/Articles/426776/WCF-Top-Interview-Questions

3. WCF Interview Questions and Answers

http://www.dotnetfunda.com/interviews/cat/73/wcf

4. Top WCF interview questions and answers job interview tips http://www.slideshare.net/wcftutorial/top-wcf-interview-questions-and-answers-job-interview-tips

Posted in .Net, Community | Tagged , , , | Leave a comment

WPF Interview Questions

I found few good webpages on WPF interview question.

1. WPF Interview questions with answers – CodeProject

http://www.codeproject.com/Articles/744082/WPF-Interview-questions-with-answers

2. WPF Interview Questions

http://www.wpfsharp.com/learning/wpf-interview-questions/

3. Top wpf interview questions and answers job interview tips

http://www.slideshare.net/wpftutorial/top-wpf-interview-questions-and-answers-job-interview-tips

4. WPF Interview Questions and Answers

http://www.dotnetfunda.com/interviews/cat/72/wpf

Posted in .Net, Community | Tagged , , | Leave a comment

Binding Dataset to GridView using SqlDataSource

This short article shows you how to bind GridView to Dataset using SqlDataSource.

Refer back to the article . That article is using C# code to bind Dataset to GridView. You can also bind Dataset to GridView with using C# code but SqlDataSource.

You still need a web.config like below.

<?xml version=1.0 encoding=utf-8?>

<!–

  For more information on how to configure your ASP.NET application, please visit

  http://go.microsoft.com/fwlink/?LinkId=169433

  –>

<configuration>

  <system.web>

    <compilation debug=true targetFramework=4.5 />

    <httpRuntime targetFramework=4.5 />

  </system.web>

 

<connectionStrings>

      <add name=NorthWindConnectionString connectionString=data source=.\SQLEXPRESS;initial catalog=northwind;integrated security=True providerName=System.Data.SqlClient />

   

    </connectionStrings>

</configuration>

The aspx page with SqlDataSource as below.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”WebForm1.aspx.cs” Inherits=”WebAppGridView.WebForm1″ %>

 

<!DOCTYPE html>

 

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head runat=”server”>

    <title></title>

</head>

<body>

    <form id=”form1″ runat=”server”>

    <div>

      <h3>GridView DataBind Example</h3>

      <asp:label id=”Message”

        forecolor=”Red”

        runat=”server”/>

      <br/>   

      <asp:gridview id=”AuthorsGridView”

        autogeneratecolumns=”False”

        runat=”server” DataKeyNames=”CustomerID” DataSourceID=”SqlDataSource1″>

          <Columns>

              <asp:BoundField DataField=”CustomerID” HeaderText=”CustomerID” ReadOnly=”True” SortExpression=”CustomerID” />

              <asp:BoundField DataField=”CompanyName” HeaderText=”CompanyName” SortExpression=”CompanyName” />

              <asp:BoundField DataField=”ContactName” HeaderText=”ContactName” SortExpression=”ContactName” />

              <asp:BoundField DataField=”ContactTitle” HeaderText=”ContactTitle” SortExpression=”ContactTitle” />

              <asp:BoundField DataField=”Address” HeaderText=”Address” SortExpression=”Address” />

              <asp:BoundField DataField=”City” HeaderText=”City” SortExpression=”City” />

              <asp:BoundField DataField=”Region” HeaderText=”Region” SortExpression=”Region” />

              <asp:BoundField DataField=”PostalCode” HeaderText=”PostalCode” SortExpression=”PostalCode” />

              <asp:BoundField DataField=”Country” HeaderText=”Country” SortExpression=”Country” />

              <asp:BoundField DataField=”Phone” HeaderText=”Phone” SortExpression=”Phone” />

              <asp:BoundField DataField=”Fax” HeaderText=”Fax” SortExpression=”Fax” />

          </Columns>

      </asp:gridview>  

        <asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:NorthWindConnectionString %> SelectCommand=”SELECT * FROM [Customers]”></asp:SqlDataSource>

    </div>

    </form>

</body>

</html>

There is no code behind for this method.

You can also download the source code from http://onedrive.com. The sample file name WebAppGridViewDataSource.zip. My MSN ID is chanmmn@hotmail.com.

Posted in .Net, Community | Tagged , , , | Leave a comment

Run Visual Studio in Mac OS and Linux

This short article shows you how to run C# code in Mac OS and Linux.

Microsoft announces a tool call Visual Studio Code. You can download the tool here https://code.visualstudio.com/.

Watch the video, the video is showing running this tool in Mac with Mac OS (not someone using Mac to run Windows).

But … for me I hit error when I try to run it.

 VSCode

VSCode1

I am still looking at how to run a simple html page in it.

Posted in .Net, Community, Operating System | Tagged , , , , | Leave a comment