-->

Monday, September 7, 2015

Create Database in c# using code first approach

Introduction

In this article i will show you how to create database in windows form c# using code first approach. Example of code first approach to create database. Entity Framework is an open source object-relational (ORM) framework for ADO.NET. It allows user to create a model by writing code in EF designer. The releases are improving from entity framework 3.5 and onwards. Entity Framework 5 is the stable version for visual studio 2010 and 2012 and updated soon with the latest features.

The main advantages of using Entity Framework 5 are:
  • Speed - You do not have to worry about creating a DB you just start coding. Good for developers coming from a programming background without much DBA experience.
  • Simple - you do not have a edmx model to update or maintain.
Entity framework 5 released with some advanced features like enum support, table-valued functions and performance improvements. In this article we will create a database using entity framework 5 code first approach.

Steps of Creating Database through Entity Framework
  • Create a Project ClassLibrary in Visual Studio.
  • Install EntityFramework from Package Manager Console (required internet connection) using
    • PM> install-package entityframework 
  • Remove InBuilt Class i.e "Class1".
  • Add a new class “Student”.
  • Add another class DataContext (Name may be change) inherited by DbContext
    • DbContext is in System.Data.Entity Namespace.
  • Write the below code in DataContext class 
j
public DataContext()
          :base("Database Name")
{
    if(!Database.Exists("Database Name"))
        Database.SetInitializer(new DropCreateDatabaseAlways<DataContext>());
}
public DbSet<Student> Student { get; set; }


  •  Add a new project2 (Window Form Application) that will be used to execute constructor of DataContext class.
  • Install Entity Framework 5 in this new project also.
  • Create an object of DataContext class in Form1 Constructor.
  • Now run project2 and your Database has been created.
When we will execute the given command to install entity framework, it will execute the stable version i.e. entity framework 5.

Download code file

Insert foreign key in database

Online polling project in asp.net free download

Introduction:
Today i will give a web based polling system, through this you can put your vote online. Free download polling project in asp.net with report. Online polling system is a web based solution.It removes traditional polling system problems such as :
  • Take more time and human resources
  • Does not give instant poll result
  • False voter
  •  Inefficient

Online voting system project



Those problem are major problem in traditional system . If you want to remove such types of problem in traditional system then you will use web-based solution.

Features of Online voting system:
  • Detect false voter
  • Instant poll result
  • Easy method for vote count
  • keep global information
System Requirements : 
  • Visual studio 2010 
  • SqlServer 2008
  • Internet connection
  • Mail_id
 How to run this project :

  • Open website folder in Visual studio 2010
  • Run your project by selecting green triangle button
  • Open voter register page 
  • Fill some required filled and click on submit button
  • Login in Admin panel by username and password
  • Approve Voter by changing flag bit (0 to 1)
  • After approval login in your mail id and copy your secure code
  • Login in voter login panel and fill some required filled(voter-id , securecode , email )
  • After login you can vote now of your desired candidate .
  • Count total vote by admin
  • Show result by admin
If you want to purchase this please contact me on :  narenkumar851@gmail.com

Project Demo

Sunday, September 6, 2015

Select box validation using JQuery

Introduction
In this article i will show you how to validate select box using JQuery. Example of select box validation using JQuery. First to get the id of the select box then get the value of it.

Source Code

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.10.2.js"></script>
    <script>
        $(function () {
            $("#Button1").click(function () {
                var a = $("#d1").val();
                if(a=="0")
                {
                    alert("Please select");
                }

            });


        })
    </script>
</head>
<body>
    <select name="d11" id="d1">
        <option value="0" >Select</option>
        <option value="1">Apple</option>
    </select>
    <input id="Button1" type="button" value="button" />
</body>
</html>

Code generate the following output

Select box validation using JQuery

JQuery TextBox validation when it empty

Introduction


In this article i will show you, how to check whether textbox is empty or not. If textbox is empty then get alert message on browser screen. I display this  message in different style like if TextBox is display this  message in different style like if TextBox is empty then get border color of TextBox is red or get alert message on screen. Both things we will do in the example on button click or focusout.

Description
 In previous article i explained get radio button and CheckBox value, Show popup on page load, Text zoomIn or ZoomOut using JQuery.


Source code: If TextBox is empty then get alert message and cursor focus to TextBox

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script>
        $(function () {

            $("#Button1").click(function () {        
                    var textval = $("input[name='t1']").val();
                    if (textval == '')
                        alert("TextBox empty");
                   $("#Text1").focus();
             
                });        

        })
    </script>
</head>
<body>

    Enter Name : <input id="Text1" type="text" value="" name="t1" /><br/>
    <input id="Button1" type="button" value="validate" />

</body>
</html>

Source Code : If Textbox is empty and user want to focus out the box

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script>
        $(function () {
                $("#Text1").focusout(function () {
                    var textval = $("input[name='t1']").val();
                    if (textval == '')
                        alert("TextBox empty");
                    $("#Text1").focus();
                });

        })
    </script>
</head>
<body>
    Enter Name : <input id="Text1" type="text" value="" name="t1" /><br/>
    <input id="Button1" type="button" value="validate" />

</body>
</html>

Source Code : If TextBox is empty then change the border color of TextBox

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script>
        $(function () {

            //$("#Button1").click(function () {
                $("#Text1").focusout(function () {
                    var textval = $("input[name='t1']").val();
                    if (textval == '')
                        alert("TextBox empty");
                    //$("#Text1").focus();
                    $("#Text1").css("border-color", "red");
                });
            //});

        })
    </script>
</head>
<body>
    Enter Name : <input id="Text1" type="text" value="" name="t1" /><br/>
    <input id="Button1" type="button" value="validate" />
</body>
</html>

Retrieve selected Radio button and checkbox value using JQuery

Introduction
In this article i will show you, how to get the value of radio button and checkbox using JQuery. First of all in this article i will get the control after then check the selected control. If selected then retrieve the value of it. Let take a simple example
Description
In previous article i explained TextBox example in JQuery, Accept only numbers JQuery Validation. So lots of example cover in JQuery.


Source code for Radio Button

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="radioandcheck.aspx.cs" Inherits="radioandcheck" %>

<!DOCTYPE html>
<html>
<head>

<title>jQuery Get Selected Radio Button Value</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#getv").click(function () {
            var radioValue = $("input[name='gender']:checked").val();
            if (radioValue) {
                alert("Your are a - " + radioValue);
            }
        });

    });
</script>
</head>
<body>    <form id="form1" runat="server">
    <h4>Please select your gender.</h4>
    <p>
       <input type="radio" name="gender" value="male">Male
        <input type="radio" name="gender" value="female">Female
    </p>
    <p><input type="button" value="Get Value" id="getv"></p>
    </form>
</body>
</html>

Code Generate the following output

Retrieve selected Radio button  value using JQuery

Source code for checkbox

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="radioandcheck.aspx.cs" Inherits="radioandcheck" %>

<!DOCTYPE html>
<html>
<head>

<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#getv").click(function () {
            var radioValue = $("input[name='gender']:checked").val();
            if (radioValue) {
                alert("Your are a - " + radioValue);
            }
        });

    });
</script>
</head>
<body>    <form id="form1" runat="server">
    <h4>Please select your gender.</h4>
    <p>
       <input type="radio" name="gender" value="male">Male
        <input type="radio" name="gender" value="female">Female
    </p>
    <p><input type="button" value="Get Value" id="getv"></p>
    </form>
</body>
</html>
Code Generate the following output

Retrieve selected checkbox value using JQuery

Saturday, September 5, 2015

Add items to dropdownlist using TextBox in ASP.NET

In this article i will show you how to add items in DropdownList with value. In general way if we add items in the list then you can add only add Text in the list. Like
Dropdownlist1.Items.add(string Text);
But you want to add text with value from Textbox in Dropdownlist then check the below example:



Source

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        ENTER ITEMS :
        <asp:TextBox ID="TextBox1" runat="server" Width="209px"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="ADD ITEMS" />
        <br />
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    </form>
 
     

</body>
</html>

Code Behind
 protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim()!="")
        {
            DropDownList1.Items.Add(new ListItem(TextBox1.Text, TextBox1.Text));
        }
    }

Friday, September 4, 2015

How to use WPF Ribbon with example

Ribbon Introduction

You know about ribbon, its a container of controls or text items like you ms-word menu bar. In MS-Word home tab contains lots of sub items like Text formatting, headings etc. These all things are possible through Ribbon in WPF.



In this video tutorial i will show you how to add reference to create ribbon in wpf. Using System.windows.controls.Ribbon namespace we can create a ribbon in WPF. Also show you how to add namespace for ribbon in xaml file. So lot of things i included in this video. 
© Copyright 2013 Computer Programming | All Right Reserved