Sunday 23 December 2018

Get Data Through Ajax || Ajax with asp.net mvc in hindi/urdu





<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script src="~/Scripts/jquery-1.10.2.js"></script>

<div class="container">



    <table class="table table-responsive table-striped">

        <thead>

            <tr>

                <th>ID</th>

                <th>NAME</th>

                <th>EMAIL</th>

                <th>ADDRESS</th>



            </tr>

        </thead>



        <tbody id="ListData">





        </tbody>



    </table>







</div>









<script>



    $(document).ready(function () {

        GetData();



        function GetData()

        {



            var html = '';



            $.ajax({



                type: 'GET',

                url: '/Home/GetAllEmployee',

                success: function (response)

                {



                    $.each(response, function (key, item)

                    {



                        html += "<tr> <td>" + item.Id + " <td>  <td>" + item.Name + " <td> <td>" + item.Email + " <td>  <td>" + item.Address + " <td></tr>";

                    });



                    $("#ListData").append(html);



                }



            });







        }













    });









</script>

Thursday 13 December 2018

How to pass data from asp.net mvc to angularJS || step by step in Hindi...





module:

var myapp;
(function () {
    myapp = angular.module('my-employees', []);
}
)();

service:

myapp.service('employeeService', function ($http)
{


    this.getAllEmployees = function ()
    {
        return $http.get('/Home/GetAllEmployee');
    }
   

});

controller:

myapp.controller('employee-controller', function ($scope, employeeService)
{


    //Loads all Employee records when page loads
    loadEmployees();
    
    function loadEmployees()
    {
        var EmployeeRecords = employeeService.getAllEmployees();



        EmployeeRecords.then(function (d)
        {
            $scope.Employees = d.data;
        },
        function ()
        {
            alert("Error occured while fetching employee list...");

        });



    }



});

Index:


<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular.js"></script>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />

<div class="container" ng-app="my-employees" ng-controller="employee-controller">
    <div class="row">
        <br />
        <br />

<input type="search"  ng-model="search" class="form-control"/>


    </div>

    <table class="table table-responsive table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>NAME</th>
                <th>SALARY</th>
                <th>DEPARTMENT</th>

            </tr>
        </thead>


        <tbody>
            <tr ng-repeat="x in Employees|filter:search">
                <td>{{x.emp_id}}</td>
                <td>{{x.emp_name|uppercase}}</td>
                <td>{{x.emp_salary |currency}}</td>
                <td>{{x.dep_name}}</td>

            </tr>


        </tbody>



    </table>



</div>


<script src="~/AngularJSapp/Module.js"></script>
<script src="~/AngularJSapp/Service.js"></script>
<script src="~/AngularJSapp/controller.js"></script>

Wednesday 12 December 2018

Update a Record by using Primary key ||Pay Roll Management System in net...







Click here to download the source code

How to Encrypt Url in asp net mvc C# PART 1 || Learn asp.net mvc in hind...



 public static string Encrypt(string toEncrypt, bool useHashing)

        {

            byte[] keyArray;

            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);



            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();

            // Get the key from config file

            string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));

            //System.Windows.Forms.MessageBox.Show(key);

            if (useHashing)

            {

                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();

                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));

                hashmd5.Clear();

            }

            else

                keyArray = UTF8Encoding.UTF8.GetBytes(key);



            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

            tdes.Key = keyArray;

            tdes.Mode = CipherMode.ECB;

            tdes.Padding = PaddingMode.PKCS7;



            ICryptoTransform cTransform = tdes.CreateEncryptor();

            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            tdes.Clear();

            return Convert.ToBase64String(resultArray, 0, resultArray.Length);

        }

Friday 7 December 2018

Add Data in table through Form in angular js ||Basics of Angular JS || P...





<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">



<head>



    <title></title>



    <link href="Content/bootstrap.css" rel="stylesheet" />



    <link href="Content/bootstrap.min.css" rel="stylesheet" />



    <script src="Scripts/angular.js"></script>



    <script src="Scripts/angular.min.js"></script>



    <style>

        ul li {

            list-style-type: none;

        }

    </style>







</head>



<body ng-app="myapp" ng-controller="myctrl">



    <h1>To do List</h1>



    <div class="row">

        <div class="container">

            <form ng-submit="todoAdd()">







                <table>

                    <tr>

                        <td>Name</td>

                        <td><input type="text" class="form-control" placeholder="Enter name here...." ng-model="txtname" /></td>

                    </tr>



                    <tr>

                        <td>Email</td>

                        <td><input type="text" class="form-control" placeholder="Enter Email here...." ng-model="txtemail" /></td>

                    </tr>



                    <tr>

                        <td>Date of Birth</td>

                        <td><input type="date" class="form-control" placeholder="Enter Email here...." ng-model="txtdob" /></td>

                    </tr>







                    <tr>

                        <td>

                            <input type="submit" value="Add" class="btn btn-success" />

                        </td>

                        <td>

                            <input type="button" value="Delete" class="btn btn-danger" ng-click="remove()" />

                        </td>



                    </tr>







                </table>





             



             

             





            </form>





        </div>











        <div class="container">



            <table class="table table-dark table-responsive">

                <thead>

                    <tr>

                        <th>Name</th>



                        <th>Email</th>



                        <th>Date of Birth</th>



                        <th>Remove</th>



                    </tr>



                </thead>

               

                <tbody>

                    <tr ng-repeat="x in todoList">

                        <td>{{x.name}}</td>

                        <td>{{x.email}}</td>

                        <td>{{x.dob}}</td>

                        <td>

                            <input type="checkbox" ng-model="x.done" />



                        </td>



                    </tr>





                </tbody>









            </table>







        </div>





























    </div>

 









 

   







 



















</body>



</html>



<script>



    var app = angular.module("myapp", []);







    app.controller("myctrl", function ($scope)



    {







        $scope.todoList = [{ name: 'salman masood',email:'theideassolution@gmail.com',dob:'1991-01-12' ,done: false }];







        $scope.todoAdd = function ()



        {

            if ($scope.txtname != "" && $scope.txtemail != "" && $scope.txtdob != "")

            {

                $scope.todoList.push({ name: $scope.txtname, email: $scope.txtemail, dob: $scope.txtdob, done: false });



                $scope.txtname = "";

                $scope.txtemail = "";

                $scope.txtdob = "";

            }

         

        };







        $scope.remove = function ()



        {



            var oldList = $scope.todoList;



            $scope.todoList = [];



            angular.forEach(oldList, function (x)



            {



                if (!x.done) $scope.todoList.push(x);



            });



        };















    });











</script>

Wednesday 5 December 2018

Pay Roll Management System in net Application C# 5







Click here to download the source code


CREATE VIEW VW_GETEMPLOYEE
AS
select  e.emp_id as 'ID',e.emp_name as 'Name',d.dept_name as 'Department',e.emp_cnic as 'CNIC',E.emp_dob as 'Date of Birth',
e.emp_email as 'Email',e.emp_hiredate as 'Hire Date',s.status_year as 'Year', s.status_basicsalary as 'Basic Salary',s.status_bonus as 'Annual Bonus',s.status_medical as 'Medical Allownace', s.status_casualleaves as 'Annual Casual Leaves',s.status_sickleaves as 'Sick Leaves',s.status_annualleaves as  'Annual Leaves'
 from tbl_employee e inner join TBL_EMPLOYEEWORKINGSTATUS s on e.emp_id = s.status_emp_fk
 inner join tbl_departments d on d.dept_id=s.status_dep_fk


 SELECT * FROM VW_GETEMPLOYEE

How to store input values in an array in Angular|| Basics of Angular JS ...





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

    <style>



        ul li{

            list-style-type:none;

        }



    </style>



</head>

<body ng-app="myapp" ng-controller="myctrl">

    <h1>To do List</h1>

    <form ng-submit="todoAdd()">



        <input type="text" class="form-control" placeholder="Enter name here...." ng-model="todoInput" />

        <input type="submit" value="Add" class="btn btn-success" />



    </form>

    <input type="button" value="Delete" class="btn btn-danger" ng-click="remove()" />



    <div class="form-control">



        <ul ng-repeat="x in todoList">

            <li>

                <input type="checkbox" ng-model="x.done" /> <span>{{x.todoText}}</span>

            </li>



        </ul>



    </div>

 







</body>

</html>

<script>

    var app = angular.module("myapp", []);



    app.controller("myctrl", function ($scope)

    {



        $scope.todoList = [{ todoText: 'salman masood', done: false }];



        $scope.todoAdd = function ()

        {

            $scope.todoList.push({ todoText: $scope.todoInput, done: false });

            $scope.todoInput = "";

        };



        $scope.remove = function ()

        {

            var oldList = $scope.todoList;

            $scope.todoList = [];

            angular.forEach(oldList, function (x)

            {

                if (!x.done) $scope.todoList.push(x);

            });

        };







    });







</script>

How to store input values in an array in Angular|| Basics of Angular JS ...





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

    <style>



        ul li{

            list-style-type:none;

        }



    </style>



</head>

<body ng-app="myapp" ng-controller="myctrl">

    <h1>To do List</h1>

    <form ng-submit="todoAdd()">



        <input type="text" class="form-control" placeholder="Enter name here...." ng-model="todoInput" />

        <input type="submit" value="Add" class="btn btn-success" />



    </form>

    <input type="button" value="Delete" class="btn btn-danger" ng-click="remove()" />



    <div class="form-control">



        <ul ng-repeat="x in todoList">

            <li>

                <input type="checkbox" ng-model="x.done" /> <span>{{x.todoText}}</span>

            </li>



        </ul>



    </div>

 







</body>

</html>

<script>

    var app = angular.module("myapp", []);



    app.controller("myctrl", function ($scope)

    {



        $scope.todoList = [{ todoText: 'salman masood', done: false }];



        $scope.todoAdd = function ()

        {

            $scope.todoList.push({ todoText: $scope.todoInput, done: false });

            $scope.todoInput = "";

        };



        $scope.remove = function ()

        {

            var oldList = $scope.todoList;

            $scope.todoList = [];

            angular.forEach(oldList, function (x)

            {

                if (!x.done) $scope.todoList.push(x);

            });

        };







    });







</script>

Monday 3 December 2018

$HTTP Service in angular js || Basics of Angular JS || Part-8



<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>





    <title>

        Directives

    </title>

    <script src="Scripts/angular.min.js"></script>

    <script src="Scripts/angular.js"></script>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

</head>

<body ng-app="myApp" ng-controller="myCtrl">







    <table class="table table-responsive">





        <thead>

            <tr>

                <th>ID</th>

                <th>Name</th>

                <th>City</th>

                <th>salary</th>



            </tr>

        </thead>

        <tbody>



            <tr ng-repeat="x in names">

                <td>{{x.id}}</td>

                <td>{{x.Name}}</td>

                <td>{{x.City}}</td>

                <td>{{x.salary|currency:"PKR":3}}</td>







            </tr>





        </tbody>





    </table>









    <script>



        var app = angular.module('myApp', []);

        app.controller('myCtrl', function ($scope, $http) {

            $http.get("myfile.html").then(function (response) {

                $scope.names = response.data.records;

            });

        });





    </script>



</body>



</html>

----------------------------------------------------------------------
MYFILE.HTML....................................................................
{
  "records": [
    {
       "id":"101",
      "Name": "ali ahmed",
      "City": "karachi",
"salary":"100"
    },

 {
       "id":"102",
      "Name": "salman masood",
      "City": "karachi",
"salary":"5000"
    }


  ]
}

Sorting Filters in Angular JS || Basics of Angular JS || Part-6





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />





</head>

<body ng-app="myapp" ng-controller="myctrl">

    <div class="container">



        <button class="btn btn-danger" ng-click="orderByMe('name')">Order by Name </button>

        <button class="btn btn-info" ng-click="orderByMe('country')">Order by Country </button>



        <table class="table table-responsive">



            <thead>

                <tr>

                    <th>ID</th>

                    <th>nAME</th>

                    <th>Country</th>



                </tr>

            </thead>



            <tbody>



                <tr ng-repeat="x in names | orderBy:myOrderBy">



                    <td>{{x.id}}</td>

                    <td>{{x.name}}</td>

                    <td>{{x.country}}</td>





                </tr>



            </tbody>





        </table>

    </div>



</body>

</html>





<script>

    var app = angular.module("myapp", []);

    app.controller("myctrl", function ($scope) {



        $scope.names = [

       { id: 108, name: 'ali', country: 'Norway' },

       { id: 107, name: 'ahmed', country: 'Sweden' },

       { id: 106, name: 'sami', country: 'England' },

       { id: 105, name: 'hassan', country: 'Norway' },

       { id: 104, name: 'haris', country: 'Denmark' },

       { id: 103, name: 'faris', country: 'Sweden' },

       { id: 102, name: 'faris', country: 'Sweden' },



        ];

        $scope.orderByMe = function (x)

        {

            $scope.myOrderBy = x;



        };







    }); //controller end.................







</script>

Wednesday 28 November 2018

Filters in Angular JS|| Basics of Angular JS || Part-6





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>



    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

</head>

<body ng-app="myapp">

    <div ng-controller="myctrl">



     <h1 style="text-align:center"> {{Message}}</h1> 





        <select>

            <option ng-repeat="x in city">{{x}}</option>



        </select>



        <input type="text" ng-model="test" />



        <br />

        <br />

        <br />



        <table class="table table-responsive">



            <thead>

                <tr>

                    <th>id</th>

                    <th>Name</th>

                    <th>Department</th>

                </tr>

            </thead>

            <tbody>

                <tr ng-repeat="y in employee |filter:test">



                    <td>{{y.id}}</td>

                    <td>{{y.name | lowercase}} </td>

                    <td>{{y.Department}}</td>

                </tr>







            </tbody>







        </table>





    </div>



 





</body>

</html>

<script>

    var app = angular.module("myapp", []);

    app.controller("myctrl", function ($scope) {



        $scope.Message = "Hello to Angular JS";

        $scope.city = ["karachi", "Lahore", "Islamabad"];

        $scope.employee = [{ id: 101, name: 'Ali', Department: 'CS' }, { id: 102, name: 'AHMED', Department: 'MATHS' }, { id: 103, name: 'SALMAN', Department: 'CS' }];



    });







</script>

Scopes in Anguls JS





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>



    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

</head>

<body ng-app="myapp">

    <div ng-controller="myctrl">



     <h1 style="text-align:center"> {{Message}}</h1> 





        <select>

            <option ng-repeat="x in city">{{x}}</option>



        </select>





        <table class="table table-responsive">



            <thead>

                <tr>

                    <th>id</th>

                    <th>Name</th>

                    <th>Department</th>

                </tr>

            </thead>

            <tbody>

                <tr ng-repeat="y in employee">



                    <td>{{y.id}}</td>

                    <td>{{y.name}}</td>

                    <td>{{y.Department}}</td>

                </tr>







            </tbody>







        </table>





    </div>



 





</body>

</html>

<script>

    var app = angular.module("myapp", []);

    app.controller("myctrl", function ($scope) {



        $scope.Message = "Hello to Angular JS";

        $scope.city = ["karachi", "Lahore", "Islamabad"];

        $scope.employee = [{ id: 101, name: 'Ali', Department: 'CS' }, { id: 102, name: 'AHMED', Department: 'MATHS' }, { id: 103, name: 'SALMAN', Department: 'CS' }];



    });







</script>

Scopes in Anguls JS





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>



    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

</head>

<body ng-app="myapp">

    <div ng-controller="myctrl">



     <h1 style="text-align:center"> {{Message}}</h1> 





        <select>

            <option ng-repeat="x in city">{{x}}</option>



        </select>





        <table class="table table-responsive">



            <thead>

                <tr>

                    <th>id</th>

                    <th>Name</th>

                    <th>Department</th>

                </tr>

            </thead>

            <tbody>

                <tr ng-repeat="y in employee">



                    <td>{{y.id}}</td>

                    <td>{{y.name}}</td>

                    <td>{{y.Department}}</td>

                </tr>







            </tbody>







        </table>





    </div>



 





</body>

</html>

<script>

    var app = angular.module("myapp", []);

    app.controller("myctrl", function ($scope) {



        $scope.Message = "Hello to Angular JS";

        $scope.city = ["karachi", "Lahore", "Islamabad"];

        $scope.employee = [{ id: 101, name: 'Ali', Department: 'CS' }, { id: 102, name: 'AHMED', Department: 'MATHS' }, { id: 103, name: 'SALMAN', Department: 'CS' }];



    });







</script>

Monday 26 November 2018

Data Annotation in ASP NET MVC C# || Code First Approach Entity Framewor...





using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.ComponentModel.DataAnnotations;

using System.ComponentModel.DataAnnotations.Schema;





namespace WebApplication1.Models

{

    [Table("tbl_user")]

    public class User

    {

        [Key]

        public int UserId { get; set; }





        [Display(Name="Name")]

        [Required(ErrorMessage="*")]

        [StringLength(50,ErrorMessage="Name should contain Atmost 50 characters")]

        [MinLength(3,ErrorMessage="Name should contain Atleast 3 characters")]

        [RegularExpression("^[a-z -']+$",ErrorMessage="Invalid Name")]

        public string Username { get; set; }





        [Display(Name = "Email")]

        [Required(ErrorMessage = "*")]

        [StringLength(50, ErrorMessage = "Email should contain Atmost 50 characters")]

        [MinLength(15, ErrorMessage = "Name should contain Atleast 15 characters")]

        [RegularExpression(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", ErrorMessage = "Invalid Email")]

        public string UserEmail { get; set; }



        [Display(Name = "Date of Birth")]

        [Required(ErrorMessage = "*")]

        [DataType(DataType.Date)]

        public string Userdob { get; set; }





        [Display(Name = "Password")]

        [Required(ErrorMessage = "*")]

        [StringLength(50, ErrorMessage = "Password should contain Atmost 50 characters")]

        [MinLength(6, ErrorMessage = "Password should contain Atleast  6 characters")]

     

        public string userpassword { get; set; }



        [Display(Name = "Confrim Password")]

        [Required(ErrorMessage = "*")]

        [Compare("userpassword",ErrorMessage="Password Does not match...")]

        public string usercpassword { get; set; }





   

   

   

   

   

    }



}

More Directives in Angular JS || Basics of Angular JS || Part-3





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

</head>

<body ng-app="">



    <div ng-init="Checked=true;Checked1=true;Checked2=true;Checked3=true">



        Header<input type="checkbox" ng-model="Checked" />

        Section<input type="checkbox" ng-model="Checked1" />

        Footer<input type="checkbox" ng-model="Checked2" />

        Read Only<input type="checkbox" ng-model="Checked3" />

        <header ng-if="Checked" style="background-color:#b6ff00;width:100%;height:200px; margin:0 auto;"></header>



        <section ng-if="Checked1" style="background-color: #ffd800;width:100%;height:700px; margin:0 auto;">



            <div class="container">



                <input type="text" ng-readonly="Checked3" class="form-control" />

                <br />

                <input type="text" ng-disabled="Checked3" class="form-control" />



                <br />



                <div class="container">

                    <div ng-init="employee=[{ID:1001,name:'ali',Department:'IT'} ,{ID:1002,name:'AHMED',Department:'MANAGER'},{ID:1003,name:'BASIT',Department:'HR'},{ID:1004,name:'salman',Department:'Software'}]">



                        <table class="table table-responsive">

                            <thead>

                                <tr>

                                    <th>ID</th>

                                    <th>NAME</th>

                                    <th>DEPARTMENT</th>



                                </tr>



                            </thead>

                            <tbody>

                                <tr ng-repeat="x in employee">

                                    <td>{{x.ID}}</td>

                                    <td>{{x.name}}</td>

                                    <td>{{x.Department}}</td>



                                </tr>





                            </tbody>







                        </table>











                    </div>

                    </div>















            </div>

        </section>



        <footer ng-if="Checked2" style="background-color:#ff0000;width:100%;height:200px; margin:0 auto;"></footer>













    </div>











</body>

</html>


Wednesday 21 November 2018

Encrypt a Column In database , Asp.net mvc Quiz Application part-6





Download the source code

Sql query to update table schema:

alter table tbl_categroy
add cat_encyptedstring nvarchar(max)
Encryption method:

 public static string Encrypt(string toEncrypt, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            // Get the key from config file
            string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
            //System.Windows.Forms.MessageBox.Show(key);
            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.Clear();
            }
            else
                keyArray = UTF8Encoding.UTF8.GetBytes(key);

            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = keyArray;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = tdes.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            tdes.Clear();
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }

Friday 9 November 2018

Delete Data In ASP.NET MVC using AJAX and POP UP MODAL



CONTROLLER CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication30.Models;

namespace WebApplication30.Controllers
{
    public class HomeController : Controller
    {
        dbsalmanEntities db = new dbsalmanEntities();
        public ActionResult Index()
        {

            return View(db.tbl_student.Where(x=>x.std_isactive==true).ToList());
        }
        public JsonResult DeleteEmployee(int EmployeeId)
        {
            bool result = false;
            tbl_student s = db.tbl_student.Where(x => x.std_id == EmployeeId).SingleOrDefault();
            if (s!=null)
            {
                s.std_isactive = false;
                db.SaveChanges();
                result = true;
            }

            return Json(result, JsonRequestBehavior.AllowGet);
        }
        //
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}

Index.cshtml CODE:

@model IEnumerable<WebApplication30.Models.tbl_student>
@{
    ViewBag.Title = "Index";
}


<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.min.js"></script>
<h2>Delete Data</h2>

<div class="" style="width:40%;margin-top:2%">


    <table class="table table-responsive">

        <thead>
            <tr>
                <th>ID</th>
                <th>NAME</th>
                <th>ADMISSION DATE</th>

            </tr>
        </thead>

        <tbody>
            @foreach (var item in Model)
            {
                <tr id="row_@item.std_id">
                    <td>@item.std_id</td>
                    <td>@item.std_name</td>
                    <td>@item.std_admissiondate</td>
                    <td><a class="btn btn-danger" onclick="ConfirmDelete(@item.std_id)">Delete <i class="glyphicon-trash"></i>  </a></td>
                </tr>

            }

        </tbody>

    </table>



    <div class="modal fade" id="myModal">
        <div class="modal-dialog">
            <div class="modal-content">
                
                
                <div class="modal-header">
                    <a href="#" class="close" data-dismiss="modal">&times;</a>
                    <h3 class="modal-title">Delete Employee</h3>
                </div>
                <div class="modal-body">
                    <h4>Are you sure ? You want to delete this. </h4>

                    <div style="text-align:center;display:none" id="loaderDiv">

                        <img src="~/Content/img/2xkV.gif"  style="height:200px;width:200px"/>
                    </div>

                </div>
                <div class="modal-footer">
                    <a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>
                    <a href="#" class="btn btn-success" onclick="DeleteEmployee()">Confirm</a>
                </div>

            </div>

        </div>

    </div>

    <input type="hidden" id="hiddenEmployeeId" />

</div>



<script>

    var ConfirmDelete = function (EmployeeId)
    {

        $("#hiddenEmployeeId").val(EmployeeId);
        $("#myModal").modal('show');

    }

    var DeleteEmployee = function ()
    {

        $("#loaderDiv").show();

        var empId = $("#hiddenEmployeeId").val();

        $.ajax({

            type: "POST",
            url: "/Home/DeleteEmployee",
            data: { EmployeeId: empId },
            success: function (result) {
                $("#loaderDiv").hide();
                $("#myModal").modal("hide");
                $("#row_" + empId).remove();

            }

        })

    }
</script>

Wednesday 7 November 2018

Making Admin Panel in Online Quiz Application Asp.net MVC C#








Click here to download the source code

Loading Progress Bar in asp.net mvc using ajax,jquery and Bootstrap Modal





@model WebApplication28.Models.tbl_employee

@{

    ViewBag.Title = "Home Page";

}



<script src="~/Scripts/jquery-1.10.2.min.js"></script>

<link href="~/Content/bootstrap.min.css" rel="stylesheet" />

<script src="~/Scripts/bootstrap.min.js"></script>



<style>

    td{

        padding:10px;

    }

</style>

<div class="container">

    <br />

    <a href="#" class="btn btn-block btn-success" data-toggle="modal" data-target="#myModal">Add a new Record</a>



    <div class="modal fade" id="myModal">

        <div class="modal-dialog">

            <div class="modal-content">



                <div class="modal-header">

                    <a href="#" class="close" data-dismiss="modal">&times;</a>

                    <h3 class="modal-title">Add a new Record! </h3>



                </div>



                <div class="modal-body">



                    <form id="myForm">



                        <table >

                            <tr>

                                <td>Name: </td>

                                <td>@Html.TextBoxFor(x => x.emp_name, new {@class="form-control" }) </td>

                            </tr>



                            <tr>

                                <td>Contact: </td>

                                <td>@Html.TextBoxFor(x => x.emp_contact, new { @class = "form-control" }) </td>

                            </tr>





                        </table>







                        </form>



                    <div style="text-align:center;display:none" id="loaderDiv">

                        <img src="~/Content/img/tenor.gif" />



                    </div>



                    </div>









                <div class="modal-footer">



                    <a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>

                    <input type="reset" value="Submit" class="btn btn-success" id="btnSubmit" />



                </div>



            </div>



        </div>

    </div>

</div>







<script>



    $(document).ready(function () {





        $("#btnSubmit").click(function () {



            $("#loaderDiv").show();



            var myformdata = $("#myForm").serialize();



            $.ajax({



                type: "POST",

                url: "/Home/Index",

                data: myformdata,

                success: function ()

                {

                    $("#loaderDiv").hide();

                    $("#myModal").modal("hide");



                }



            })

        })



    })





</script>

Monday 5 November 2018

Quiz application in asp net mvc part 1







Download the source code

Ajax with MVC (Insert data using ajax in asp.net mvc)







<script src="~/Scripts/jquery-1.10.2.min.js"></script>



<script>



    $(document).ready(function () {



        $("#btnSubmit").click(function () {



            $("#loaderDiv").show();



            var data = $("#myForm").serialize();



            $.ajax({



                type: "POST",

                url: "/Home/Index",

                data: data,

                success: function (response) {

                    $("#loaderDiv").hide();

                    alert("Question Successfully inserted......");

                }



            })

        })





    })





</script>


Wednesday 24 October 2018

Upload and Save Image in database , asp net mvc 5



public string uploadimage(HttpPostedFileBase file)

        {

            Random r = new Random();

            string path = "-1";

            int random = r.Next();

            if (file != null && file.ContentLength > 0)

            {

                string extension = Path.GetExtension(file.FileName);

                if (extension.ToLower().Equals(".jpg") || extension.ToLower().Equals(".jpeg") || extension.ToLower().Equals(".png"))

                {

                    try

                    {



                        path = Path.Combine(Server.MapPath("~/Content/upload"), random + Path.GetFileName(file.FileName));

                        file.SaveAs(path);

                        path = "~/Content/upload/" + random + Path.GetFileName(file.FileName);



                        //    ViewBag.Message = "File uploaded successfully";

                    }

                    catch (Exception ex)

                    {

                        path = "-1";

                    }

                }

                else

                {

                    Response.Write("<script>alert('Only jpg ,jpeg or png formats are acceptable....'); </script>");

                }

            }



            else

            {

                Response.Write("<script>alert('Please select a file'); </script>");

                path = "-1";

            }







            return path;

        }


Friday 19 October 2018

Pagination in asp net mvc





Action code:



public ActionResult Index(int? page)

        {

            int pagesize = 6, pageindex = 1;

            pageindex = page.HasValue ? Convert.ToInt32(page) : 1;

            var list = db.tbl_services.OrderByDescending(x => x.s_id).ToList();

            IPagedList<tbl_services> stu = list.ToPagedList(pageindex, pagesize);



            return View(stu);

        }

View code:

@using PagedList.Mvc

@model  PagedList.IPagedList<WebApplication1.Models.tbl_services>







@{

    ViewBag.Title = "Home Page";

}



<div class="row">



    @foreach (var item in Model)

    {

        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">

            <img  src="@Url.Content(item.s_img)" style="width:200px; height:200px;"/>

            <h1 style="text-align:center"> @item.s_name</h1>



        </div>



    }

   





</div>

   

    <div>



        <div class="pagination" style="margin-left: 400px">

            Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)

            of @Model.PageCount   @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))

        </div>







    </div>


Wednesday 17 October 2018

Crystal Report in C# Winforms





create database dbcrytalreport

use dbcrytalreport



create table tbl_employee

(

emp_id int identity primary key,

emp_name nvarchar(20) not null,

emp_salary int not null,

emp_contact nvarchar(20)

)



insert into tbl_employee

values('ali',50000,'03432145678')

insert into tbl_employee

values('ahmed',40000,'03421145678')

insert into tbl_employee

values('bilal',30000,'03412145678')

insert into tbl_employee

values('basit',50000,'03442145678')





select * from tbl_employee

---------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {//Data Source=.;Initial Catalog=dbcrytalreport;User ID=sa;Password=***********
        ReportDocument rd = new ReportDocument(); 
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=dbcrytalreport;User ID=sa;Password=aptech");
            SqlDataAdapter da = new SqlDataAdapter("select * from tbl_employee", conn);
            conn.Open();
            DataSet ds = new DataSet();
            da.Fill(ds,"employee");
            rd.Load(@"C:\Users\salman\documents\visual studio 2013\Projects\WindowsFormsApplication1\WindowsFormsApplication1\CrystalReport1.rpt");
            rd.SetDataSource(ds);
            crystalReportViewer1.ReportSource = rd;


        }
    }
}

--------------------------------------------------------------------------------------------------

Monday 1 October 2018

CRUD OPERATION IN ASP NET WEB FORM PART 2



create proc sp_getdata
as
begin
select d_name as 'Name',d_contact as 'Contact',d_email as 'Email' from tbl_doctor

end

Click here to download the source code

Friday 28 September 2018

CRUD OPERATION IN ASP.NET WEB FORM PART 1





use clinicalmanagementsystem

create table tbl_doctor

(

d_id int primary key identity,

d_name nvarchar(50) not null,

d_contact nvarchar(50) not null unique,

d_email nvarchar(50) unique,

d_dateofbirth date



)



create proc sp_insert_doctor

(

@d_name nvarchar(50) ,

@d_contact nvarchar(50) ,

@d_email nvarchar(50) ,

@d_dateofbirth date

)

AS

BEGIN

INSERT INTO tbl_doctor VALUES(

@d_name ,

@d_contact ,

@d_email ,

@d_dateofbirth



)

END





select * from tbl_doctor


CRUD OPERATION IN PHP WITH MYSQLI PART 3









<!doctype html>

<html>

<head>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">



<style type="text/css">



table,th

{

text-align: center;



}

td

{

padding: 10px;

}



</style>



</head>



<body>



<div class="col-lg-12 col-md-12 col-sm-12"  style="height: 200px;">



<form method="post">



<table>



<tr>

<td> Book Name</td>

<td> <input type="text" name="book" class="form-control" placeholder="Book Name"></td>



</tr>





<tr>

<td> Book Price</td>

<td> <input type="text" name="price" class="form-control" placeholder="Book Price"></td>



</tr>





<tr>

<td> <input type="submit" name="btnAdd" class="btn btn-info"> </td>



</tr>





</table>





</form>



</div>











<?php

include 'includes/connection.php';



if (isset($_POST['btnAdd']))

{

$book=$_POST['book'];

$price= $_POST['price'];



$sql      ="INSERT INTO `tbl_book`( `BOOK_NAME`, `BOOK_pirce`) VALUES (?,?)";



$stmt=$conn->prepare($sql);



if (!$stmt)

{

echo "<script>alert('failed to insert data.....'); </script>";

}

else

{

$stmt->bind_param('ss',$book,$price);



$stmt->execute();

$stmt->close();







}





} // button event ends here.........................................................















$sqlquery="SELECT * FROM `tbl_book` ";



if($result=mysqli_query($conn,$sqlquery))

{

echo '<table class="table table-bordered table-responsive table-striped">';

echo "<thead>

<tr>

<th>ID </th>

<th>NAME </th>

<th>PRICE </th>







 </tr>

 </thead> ";



while ($row= mysqli_fetch_assoc($result))

{



echo "<tr> <td>". $row["BOOK_ID"]." </td>  <td>". $row["BOOK_NAME"]."  </td> <td>".$row["BOOK_pirce"]." </td> </tr>";



}

echo "</table>";





 mysqli_free_result($result);





}

else 

{

# code...





}



mysqli_close($conn);



 ?>









</body>





</html>


Wednesday 29 August 2018

regular expression in C# Windows Form







using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Text.RegularExpressions;

using System.Net.Mail;



namespace regular_expression

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }



        private void button1_Click(object sender, EventArgs e)

        {

            if (!Regex.Match(textBox1.Text,"^[a-z -']+$").Success)

            {

                MessageBox.Show("Invalid name", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                textBox1.Text = " ";

            }

            else

            {

                MessageBox.Show("Data added....");

            }



     try

{      

     

  var email = new MailAddress(textBox2.Text);

}

catch (Exception)

{

        MessageBox.Show("Invalid Email", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

        textBox2.Text = " ";



}

 



           

        }

    }

}


Tuesday 28 August 2018

Inheritance in PHP





<!doctype html>



<html>



<head>



<meta charset="utf-8">



<title>OOP-2</title>



</head>







<body>



<?PHP



class books



{

var $title; // member variable.....

var $price ; // member variable.....



function setTitle($para)

{

$this->title=$para;

} //set method.....



function getTitle()



{

echo $this->title."<br/>";

} //get method.............



//...............................................







function setPrice($para)

{

$this->price=$para;

} //set method.....







function getPrice()

{

echo $this->price."<br/>";

} //get method.............



} //class end...................



class Novel extends books

{

var $publisher;



function setPublisher($para)

{

$this->publisher=$para;

}



function getPublisher()

{

echo $this->publisher."<br>";

}





}





$obj=new Novel;

$obj->setTitle("Learn programming C#");

$obj->setPrice(500);

$obj->setPublisher("C# CORNER");



//------------------------------------------------

$obj->getTitle();

$obj->getPublisher();

$obj->getPrice();









?>



















</body>



</html>

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...