Sunday, 10 July 2016

How to make SQL common class.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
using TrackComm.BI;

namespace TrackComm
{
    public class SQL
    {
        #region Variables and Object Declaration
        private OleDbTransaction tranNew;
        //private SqlTransaction tranNew;
        OleDbConnection con = new OleDbConnection();
        //private SqlConnection con = new SqlConnection();
        private string strSqlConn;
        //public SqlParameter objTempParm;      
        #endregion

       //OleDbConnection conn = newOleDb.OleDbConnection(("provider=Microsoft.Jet.OLEDB.4.0; " + ("data source=C:\\myData.xls; " + "Extended Properties=Excel 8.0;")));


        #region Methods related to connection and disconnection of database

        public bool Connect()
        {
            try
            {
                //strSqlConn = "Provider="+Functions.PROVIDER+"; Data Source=" + Functions.DATASOURCE + "";
                //strSqlConn = "provider=Microsoft.Jet.OLEDB.4.0; " + ("data source=C:\\myData.xls; " + "Extended Properties=Excel 8.0";
                if (VariableInfo.mVersion == "12.0")
                {
                    strSqlConn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + VariableInfo.mDbPath;
                }
                else if (VariableInfo.mVersion == "4.0")
                {
                    strSqlConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + VariableInfo.mDbPath;
                }
                strSqlConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + VariableInfo.mDbPath;
               // strSqlConn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Application.StartupPath + "\\Bond_Printing_App.mdb";
                if (con.State == ConnectionState.Closed)
                {
                    con.ConnectionString = strSqlConn;
                    con.Open();
                    return true;
                }
                else if (con.State == ConnectionState.Open)
                {
                    con.Close();
                    con.ConnectionString = strSqlConn;
                    con.Open();
                    return true;
                }
                return false;
            }
            catch
            {
                throw;
            }
        }

        public void Disconnect()
        {
            try
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                    con.Dispose();
                }
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region Transaction related methods

        public void startTransaction()
        {
            try
            {
                if (Connect() == true)
                    tranNew = con.BeginTransaction();
                   // tranNew = con.BeginTransaction();
            }
            catch
            {

                throw;
            }
        }

        public void CommitTransaction()
        {
            try
            {
                         
                tranNew.Commit();
                tranNew.Dispose();
                Disconnect();
            }
            catch
            {
                throw;

            }
        }

        public void RollbackTransaction()
        {
            try
            {
                tranNew.Rollback();
                tranNew.Dispose();
                Disconnect();
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region ExecuteScaler methods

        public int ExecuteScalar(string qry)
        {
            try
            {
                if (Connect() == true)
                {
                    OleDbCommand cmd = new OleDbCommand(qry, con);
                    //SqlCommand cmd = new SqlCommand(qry, con);
                    cmd.CommandText = qry;
                    int i = (int)cmd.ExecuteScalar();
                    cmd.Dispose();
                    Disconnect();
                    return i;
                }
                else
                {
                    throw new Exception("database connection not found");
                }
            }
            catch
            {
                throw;
            }
        }

        public int ExecuteScalarTran(string qry)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand(qry, con, tranNew);
                //SqlCommand cmd = new SqlCommand(qry, con, tranNew);
                cmd.CommandText = qry;
                int i = (int)cmd.ExecuteScalar();
                cmd.Dispose();
                return i;

            }
            catch
            {
                throw;
            }

        }

        #endregion

        #region ExecuteNonQuery methods

        public void ExecuteNonQuery(string qry)
        {
            try
            {
                if (Connect() == true)
                {
                    OleDbCommand cmd = new OleDbCommand(qry, con);
                   // SqlCommand cmd = new SqlCommand(qry, con);
                    cmd.CommandText = qry;
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    Disconnect();
                }
                else
                {
                    throw new Exception("database connection not found");
                }
            }
            catch(Exception ex)
            {
                throw;
            }
        }

        public void ExecuteNonQueryTran(string qry)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand(qry, con, tranNew);
                //SqlCommand cmd = new SqlCommand(qry, con, tranNew);
                cmd.CommandText = qry;
                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region ExecuteDataset methods

        public DataSet ExecuteDataset(string qry)
        {
            try
            {
                if (Connect() == true)
                {
                    OleDbDataAdapter Oracleda = new OleDbDataAdapter(qry, con);
                    //SqlDataAdapter Oracleda = new SqlDataAdapter(qry, con);
                    DataSet ds = new DataSet();
                    Oracleda.Fill(ds);
                    Oracleda.Dispose();
                    ds.Dispose();
                    return ds;
                }
                else
                {
                    throw new Exception("database connection not found");
                }
            }
            catch
            {
                throw;
            }
        }

        public DataSet ExecuteDatasetTran(string qry)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand(qry, con, tranNew);
                //SqlCommand cmd = new SqlCommand(qry, con, tranNew);
                cmd.CommandText = qry;

                OleDbDataAdapter Oracleda = new OleDbDataAdapter(cmd);
               // SqlDataAdapter Oracleda = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                Oracleda.Fill(ds);

                Oracleda.Dispose();
                ds.Dispose();
                cmd.Dispose();

                return ds;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region ExecuteProcedure methods

        public string ExecuteProcedure(string Proc, SqlParameter[] param, string err)
        {

            try
            {
                if (Connect() == true)
                {
                    OleDbCommand cmd = new OleDbCommand();
                    //SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con;
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddRange(param);
                    cmd.CommandText = Proc;
                    cmd.ExecuteNonQuery();
                    Disconnect();
                    return cmd.Parameters[err].Value.ToString();

                }
                else
                {
                    throw new Exception("database connection not found");
                }

            }
            catch
            {
                throw;
            }
        }

        public string ExecuteProcedureTran(string Proc, SqlParameter[] param, string err)
        {

            try
            {
                OleDbCommand cmd = new OleDbCommand();
                //SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Transaction = tranNew;
                cmd.Parameters.AddRange(param);
                cmd.CommandText = Proc;
                cmd.ExecuteNonQuery();
                Disconnect();
                return cmd.Parameters[err].Value.ToString();
            }
            catch
            {
                throw;
            }
        }

        public string ExecuteProcedureParam(string Proc, SqlParameter[] param, string err, string result)
        {

            try
            {
                if (Connect() == true)
                {
                    OleDbCommand cmd = new OleDbCommand();
                    //SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddRange(param);
                    cmd.CommandText = Proc;
                    cmd.ExecuteNonQuery();
                    Disconnect();

                    if (cmd.Parameters[result].Value.ToString() != "")
                    {
                        return cmd.Parameters[result].Value.ToString();
                    }
                    else
                    {
                        return cmd.Parameters[err].Value.ToString();
                    }
                }
                else
                {
                    throw new Exception("database connection not found");
                }

            }
            catch
            {
                throw;
            }
        }

        #endregion

    }
}

Saturday, 7 May 2016

Bind Model in AngularJS with Example.

Creating a Module

A module is created by using the AngularJS function angular.module


Adding a Controller

Add a controller to your application, and refer to the controller with the ng-controller directive:


Example:- 

Step :- 1  --- Add HTML Page in Application.

Step :- 2  --- Add Angular JS file into  Application.

Step :- 3 --- then create path of anular.js.min file on HTML Page.


//----------AppJS Source Code-----------------

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

appUI.controller("appCtrl", function ($scope) {
    $scope.firstName = "VICKY";
    $scope.lastName = "RAJ";

});



//----------Source Code-----------------

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../AppJS/angular.min.js"></script>
    <script src="../AppJS/firstApp.js"></script>
</head>
<body ng-app="appUI" ng-controller="appCtrl">
    <div>
        <div>
            <table align="center">
                   <tr><td>Enter First Name</td><td><input type="text" ng-model="firstName" placeholder="First Name" /></td></tr>
                   <tr><td>Enter Last Name</td><td><input type="text"  ng-model="lastName" placeholder="Last Name" /></td></tr>
                  <tr><td>First Name</td><td >{{firstName}}</td></tr>
                  <tr><td>Last Name</td><td>{{lastName}}</td></tr>
            </table>
        </div>
    </div>
</body>

</html>

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





Saturday, 30 April 2016

JavaScript Function With Example

JavaScript Function


Definition :-

 In JavaScript is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces {}.

Syntax:-
----------------------------------------------
function functionName(parameters){
    statements
}

Example:-
-----------------------------------
function myFunction(a, b) {
    return a * b;
}

How to use this function in Script.

<!DOCTYPE html>
<html>
<body>

<h1>a function returns the result : </h1>

<p id="demo"></p>

<script>
function myFunction(a, b) {
    return a * b;
}
document.getElementById("demo").innerHTML = myFunction(4, 3);
</script>

</body>
</html>

Result:- 

a function returns the result: 12


Saturday, 20 February 2016

JQuery Calendar Example

JQuery Calendar Example


A Simple Calendar In html with JQuery using Date Picker.



Code:-

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"> 
    </script>
    <script type='text/javascript'>
        $(document).ready(function () {
            $("#calendar").datepicker
            ({
                defaultDate: '01/01/' + new Date().getFullYear(),
                minDate: '01/01/' + new Date().getFullYear(),
                maxDate: '12/31/' + (new Date().getFullYear() + 1),
                numberOfMonths: [2, 6],
            });
        });
    </script>
    <style>
        #header {
            background-color:#00ff21;
            height:100px;
            width:100%;
            text-align:center;
        }
        #footer {
            background-color: #808080;
            height: 100px;
            width: 100%;
            color: white;
            text-align: center;
        }
        #calendar {
            margin-left:175px;
        }
    </style>
</head>
<body>
    <div id="header">
        <h1>Calendar</h1>
    </div>
    <div id='calendar'>
    </div>
    <div id="footer">
        <h2>All Right are reserved at Dot Net By Vickypedia</h2>
    </div>
</body>
</html>


Output :- 



Saturday, 6 February 2016

First Application in AngularJS

First Application of AngularJS

Step 1 :- Start Visual Studio then  Create Empty Web Application.



Step :- Add HTML page in your Application.


Step 3 :- Add Script file / Source link in your page...

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>



Step 4:- Write Code   :--

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Hello World</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
    <div ng-app="">
        <h1>First Example of AngularJS</h1>
        <p>Please Enter "Hello World"/Text in the TextBox:
            <input type="text" ng-model="text"></p>
        <h2 ng-bind="text"></h2>
    </div>
    <div id="footer"><h3>Powered By DotNet By Vickypedia</h3></div>
</body>
</html>




Step 5 :- Run your Application ...




Factorial of a Number

Recently Viewed