-->

Wednesday, September 9, 2015

Login form using entity framework in windows form c#

Introduction
In this article i will give an example of login form using entity framework. We will do login from database table so first of all create database table using entity framework's code first approach. Now, Using linq query we can do this task.

Description
Sometimes anonymous user can harm our application and can change the data stored in our application. That’s why, it is often necessary to permit only authorized users to use our application. There is no predefined method to do this operation in windows forms, so we have to implement it in our way.

If we have username and password in our database then we can implement a better authentication system. So we will create a table in our database named User which will have two columns (Username and Password). Insert some records in that table to check our login control.



In click event of login button write following code:


Here in this code will show a message if user leaves the textboxes empty. First check the username in our database having exactly the same name user entered in textbox. If there is an entry then compare the password.
We can show a message box at each wrong step of user.

Download example.

Tuesday, September 8, 2015

Button work as fileupload control in JQuery

Introduction

In this article i will show you how a button control behaves as fileupload control. Example of button control working as fileupload control. In this article i taken a button and fileupload control but visibility of fileupload is hidden. Get the fileupload control by their id property in JQuery and put the accessed file path into label control. Let see the example



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script>
    $(function(){
        $("#fileupload1").change(function () {
            $("#l1").html($("#fileupload1").val().substring($("#fileupload1").val().lastIndexOf("\\") + 1));

        });
    })
</script>
</head>
<body>
    <form id="form1">
        <input type="file" style="display:none" id="fileupload1"/>
        <input type="button" id="Button1" onclick='$("#fileupload1").click()' value="upload"/>
        <label id="l1"></label>

    </form>

</body>
</html>

Code generate the following output


Button work as fileupload control in JQuery

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

© Copyright 2013 Computer Programming | All Right Reserved