Techaray

Shailendra Saxena's Technical Blog

Java.lang.UnsupportedClassVersionError: com/android/dx/command/Main Unsupported major.minor version 52.0

clock October 8, 2016 21:59 by author ShailendraSaxena

Hello,

 

In My Xamarin Visual Studio. While build the project I was getting below error.

java.lang.UnsupportedClassVersionError: com/android/dx/command/Main  :  Unsupported major.minor version 52.0 

 
Environment:
 
I was using visual studio 2015.
 
 
Resolution:
 
1. Install Latest JDK Version
 
2. Go to Visual Studio --> Tools --> Xamarin  and change the JDK location to latest version installed.
 
 
Thanks


Javascript Function2

clock March 13, 2016 19:26 by author ShailendraSaxena

document.writeln('Hello, world!');

//object declaration in javascript 1.

var stooge = {

    "first-name": "Jerome",

    "last-name": "Howard"

};

 

//object declaration in javascript 2.

var flight = {

    airline: "Oceanic",

    number: 815,

    departure: {

        IATA: "SYD",

        time: "2004-09-22 14:55",

        city: "Sydney"

    },

    arrival: {

        IATA: "LAX",

        time: "2004-09-23 10:42",

        city: "Los Angeles"

    }

};

 

document.writeln(stooge["first-name"]);

document.writeln(flight.airline);

 

stooge['first-name'] = 'Jerome22';

 

document.writeln(stooge["first-name"]);

 

var x = stooge;

x.nickname = 'Curly';

document.writeln(stooge["nickname"]);

stooge.profession = 'actor';

 

document.writeln('number' + '  ' + typeof flight.number);

 

var another_stooge = Object.create(stooge);

another_stooge['first-name'] = 'Harry';

another_stooge['middle-name'] = 'Moses';

another_stooge.nickname = 'Moe';

stooge.profession = 'actor';

delete another_stooge.nickname;

var name;

for (name in another_stooge) {

    if (typeof another_stooge[name] !== 'function') {

        document.writeln(name + ': ' + another_stooge[name]);

    }

}

//Global Abatement

//JavaScript makes it easy to define global variables that can hold all of the assets of

//your application. Unfortunately, global variables weaken the resiliency of programs

//and should be avoided.

//One way to minimize the use of global variables is to create a single global variable

//for your application:

var MYAPP = {};

 

 

//That variable then becomes the container for your application:

 

MYAPP.stooge = {

"first-name": "Joe",

"last-name": "Howard"

};

MYAPP.flight = {

    airline: "Oceanic",

    number: 815,

    departure: {

    IATA: "SYD",

    time: "2004-09-22 14:55",

    city: "Sydney"

},

    arrival: {

    IATA: "LAX",

    time: "2004-09-23 10:42",

    city: "Los Angeles"

}

};

 

//Function in Javascript.

//A function encloses a set of statements. Functions are the fundamental modular unit

//of JavaScript. They are used for code reuse, information hiding, and composition.

//Functions are used to specify the behavior of objects. Generally, the craft of programming

//is the factoring of a set of requirements into a set of functions and data

//structures.

 

var add = function (a, b) {

    return a + b;

};

 

//Function Objects

//Functions in JavaScript are objects. Objects are collections of name/value pairs having

//a hidden link to a prototype object. Objects produced from object literals are

//linked to Object.prototype. Function objects are linked to Function.prototype

//(which is itself linked to Object.prototype). Every function is also created with two

//additional hidden properties: the function’s context and the code that implements

//the function’s behavior.

 

 

 

//The Method Invocation Pattern

//When a function is stored as a property of an object, we call it a method. When a

//method is invoked, this is bound to that object. If an invocation expression contains

//a refinement (that is, a . dot expression or [subscript] expression), it is     invoked as a method:

    // Create myObject. It has a value and an increment

    // method. The increment method takes an optional

    // parameter. If the argument is not a number, then 1

    // is used as the default.

        var myObject = {

            value: 0,

            increment: function (inc) {

                this.value += typeof inc === 'number' ? inc : 1;

            }

        };

    myObject.increment( );

    document.writeln(myObject.value); // 1

    myObject.increment(1);

    document.writeln(myObject.value); // 1

    myObject.increment(2);

    document.writeln(myObject.value); // 3

 

 

    (function () {

        var a = b = 3;

    })();

 

    document.writeln("a defined? " + (typeof a !== 'undefined'));

    document.writeln("b defined? " + (typeof b !== 'undefined'));

 

 

    function foo1() {

        return { bar: "hello"};

    }

 

    function foo2() {

        return

        {

            bar11: "ahello"

        };

    }

 

    document.writeln("foo1 returns:");

    document.writeln(foo1());

    document.writeln("foo2 returns:");

    document.writeln(foo2());

 

function sumDigits(num) {

     var i, sum = 0;                  // can declare two variables at once

 

     for (i = 1; i <= num; i++) {

             sum += i;              // add each number to sum (ie, 1 + 2 + ...+ num)

     }

 

     // Display result

     alert("The sum of the digits from 1 to "+ num + " is:\n\n\t " + sum);

}

 

 

 



JavaScript in ASP.Net

clock March 13, 2016 19:20 by author ShailendraSaxena

ADD Function Like this in <head>of html.

<script type="text/JavaScript" language="JavaScript">
function ValidateForm()
{
    var ret = true;
    if (document.getElementById("txtFirstName").value == "")
    {
        document.getElementById("lblFirstName").innerText = "First Name is required";
        ret = false;
    }
    else
    {
        document.getElementById("lblFirstName").innerText = "";
    }
 
    if (document.getElementById("txtLastName").value == "")
    {
        document.getElementById("lblLastName").innerText = "Last Name is required";
        ret = false;
    }
    else
    {
        document.getElementById("lblLastName").innerText = "";
    }
 
    if (document.getElementById("txtEmail").value == "")
    {
        document.getElementById("lblEmail").innerText = "Email is required";
        ret = false;
    }
    else
    {
        document.getElementById("lblEmail").innerText = "";
    }
 
    return ret;
}
</script>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" 
    OnClientClick="return ValidateForm()" onclick="btnSubmit_Click" />




Dependency Injection with AutoFac 2

clock March 13, 2016 18:29 by author ShailendraSaxena

3. UserController

publicclassUserController : Controller

    {

 

        IUserRepository _userrepos;

 

        public UserController( IUserRepository _repository)

        {

            _userrepos = _repository;

        }

 

        // GET: User

        publicActionResult Index()

        {

            var data = _userrepos.GetUserList();

            return View(data);

        }

 

        // GET: User/Details/5

        publicActionResult Details(int id)

        {

            var data = _userrepos.GetUser(id);

            return View(data);

        }

 

        // GET: User/Create

        publicActionResult Create()

        {

            return View();

        }

 

        // POST: User/Create

        [HttpPost]

        publicActionResult Create(User user)

        {

            try

            {

                _userrepos.Add(user);

                _userrepos.SaveChanges();

                return RedirectToAction("Index");

            }

            catch

            {

 

            }

            return View();

        }

 

        // GET: User/Edit/5

        publicActionResult Edit(int id)

        {

            return View();

        }

 

        // POST: User/Edit/5

        [HttpPost]

        //public ActionResult Edit(int id, FormCollection collection)

        publicActionResult Edit(int id, User usr)

        {

            try

            {

                usr.UserId = id;

                // TODO: Add update logic here

                _userrepos.Update(usr);

                _userrepos.SaveChanges();

                return RedirectToAction("Index");

            }

            catch

            {

                return View();

            }

        }

 

        // GET: User/Delete/5

        publicActionResult Delete(int id)

        {

            return View();

        }

 

        // POST: User/Delete/5

        [HttpPost]

        publicActionResult Delete(int id, FormCollection collection)

        {

            try

            {

                // TODO: Add delete logic here

                return RedirectToAction("Index");

            }

            catch

            {

                return View();

            }

        }

    }

4. Autofac install (autofac + autofacMVC)

5. Global.asax.

  protectedvoid Application_Start()

        {

            AreaRegistration.RegisterAllAreas();

            GlobalConfiguration.Configure(WebApiConfig.Register);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            RouteConfig.RegisterRoutes(RouteTable.Routes);

            BundleConfig.RegisterBundles(BundleTable.Bundles);

 

            var builder = newContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            builder.RegisterType(typeof(UserRepository)).AsImplementedInterfaces();

            //builder.RegisterType(typeof(CustomerRepository)).AsImplementedInterfaces();

            var container = builder.Build();

            DependencyResolver.SetResolver(newAutofacDependencyResolver(container));

 

 

 

        }



Dependency Injection with AutoFac

clock March 13, 2016 18:27 by author ShailendraSaxena

 

1.       1. Interface

publicinterfaceIUserRepository

    {

        void Add(User user);

        void Update(User user);

        void Delete(int Id);

        User GetUser(int Id);

        IEnumerable<User> GetUserList();

        void SaveChanges();

    }

2. Repository

publicclassUserRepository : IUserRepository

    {

        readonlyDataContext _context;

        public UserRepository()

        {

            _context = newDataContext();

        }

        publicvoid Add(User user)

        {

            _context.User.Add(user);

            _context.SaveChanges();

        }

        publicvoid Delete(int Id)

        {

            User usr = _context.User.Find(Id);

            _context.User.Remove(usr);

        }

        publicUser GetUser(int Id)

        {

            User usr = _context.User.Find(Id);

            return usr;

        }

        publicIEnumerable<User> GetUserList()

        {

            return _context.User.ToList();

        }

        publicvoid SaveChanges()

        {

            _context.SaveChanges();

        }

        publicvoid Update(User user)

        {

            _context.Entry(user).State = EntityState.Modified;

        }

 



How to show/hide a anchor tag on the basis of Web.config in ASP.NET

clock March 9, 2015 13:16 by author ShailendraSaxena

Hi,

In appsetting section of web.config I make element.then on Action method I wrote those property in cookie and then read it on javascript.

below is the sample code for it.

 

  $(document).ready(function () {

        var mktShow = getCookie("mktShow");
        if (mktShow != "yes") {
            $("#ss").hide();
        } else {
                var mktShowhref = getCookie("mktImagelnk");
                var mktImage = getCookie("mktImage");
                var mydiv = document.getElementById("ss");
                var aTag = document.createElement('a');
                aTag.setAttribute('href', mktShowhref);
                aTag.setAttribute('id', "sms");
                aTag.setAttribute('style', 'width: 728px;height: 90px;background-image: url('+ mktImage +');padding: 0px;display: block; margin-left: auto; margin-right: auto; margin-bottom: 10px; ');
                mydiv.appendChild(aTag);
                $("#ss").show();
        }
      
    });



How to Show Enum Dropdown List in MVC4

clock May 14, 2014 05:03 by author ShailendraSaxena

 

 

This example shows you how to create a Enum Dropdown in ASP.Net MVC4.

We need to show Sex as Male or Female in Employee Screen

Step1:

Create a Class which contains the Enumlist under a Folder Enums.

 

namespace MVCApp.Enums

{

    public class MyEnums

    {

 

        public enum Gender

        {

            Male=0,

            Female=1

        }

    }

}

Step2.

Create a Employee Model as below.

using MVCApp.Enums;

 

 

namespace MVCApp.Models

{

    public class Employee

    {

               

        public int ID { get; set; }

        public string Name { get; set; }

 

        public MyEnums.Gender Sex { get; set; }

 

        public string Post { get; set; }

 

        public decimal Salary { get; set; }

 

        public string City { get; set; }

    }

}

 

Step 3.

In Create.CSHTML define as below

<divclass="form-group">

            @Html.LabelFor(model => model.Sex, new { @class = "control-label col-md-2" })

            <divclass="col-md-10">

               @Html.DropDownListFor(model => model.Sex,newSelectList(Enum.GetValues(typeof(MVCApp.Enums.MyEnums.Gender))))

                @Html.ValidationMessageFor(model => model.Sex)

            </div>

        </div>

 



Restrictions on Views

clock May 8, 2014 10:14 by author ShailendraSaxena

 

Views have a number of restrictions, such as the following:

  •  You cannot add an ORDER BY to the SELECT statement in a view. A view must appear

just like a table, and tables in a relational database contain sets of rows. Sets by themselves

are not ordered, although you can apply an order to a result set using ORDER

BY. Similarly, tables and views in SQL Server do not have a logical order to their rows,

though you can apply one by adding an ORDER BY to the outermost SELECT statement

when you access the view.

  • You cannot pass parameters to views.
  • Similarly, a view cannot reference a variable inside the SELECT statement. See the

section “Inline Functions” for information on how to use functions to simulate passing

parameters to a view.

  •  A view cannot create a table, whether permanent or temporary. In other words, you

cannot use the SELECT/INTO syntax in a view.

  •  A view can reference only permanent tables; a view cannot reference a temporary

table.



Derived Table V/S Sub Query V/S CTE

clock May 7, 2014 08:41 by author ShailendraSaxena

 

Derived Table

Sub Query

CTE

derived tables are used in the FROM clause

 

sub queries are used in the WHERE clause, but can also

be used to select from one table and insert into

another as we showed above

 

A common table expression (CTE) is a similar concept to a derived table in the sense that it’s

a named table expression that is visible only to the statement that defines it. Like a query

against a derived table, a query against a CTE involves three main parts:

■ The inner query

■ The name you assign to the query and its columns

■ The outer query

select employee_name

from employee

where employee_salary >

 (select avg(employee_salary)

        from employee)

 

select max(age)

from (

select age from table

) as Age  

 

 

With C As

(

SELECT empid, firstname, lastname, country, region, city

FROM HR.Employees

WHERE country = 'USA'

)

Select empid, firstname, lastname, country from c

 

 

 

 

 

 



SQL SERVER String Functions

clock May 6, 2014 09:50 by author ShailendraSaxena

 

SUBSTRING Function

The SQL Server (Transact-SQL) SUBSTRING functions allows you to extract a substring from a string.

EX. SELECT SUBSTRING('Techaray.com', 1, 4);

Result: 'Tech'

LEFT

LEFT function starts BEFORE the left-most character of a string and moves to the right.

SELECT LEFT('Techaray.com', 3)

Result :’Tec’

RIGHT

RIGHT function starts AFTER the right-most character and moves inwards to the left.

SELECT RIGHT('Techaray.com', 3)

Result: ‘com’

CHARINDEX

Searches an expression for another expression and returns its starting position if found.

SELECT CHARINDEX('aray', 'Techaray.com');

Result :5

LEN

The LEN function returns the length of an input string in terms of the number of characters.

SELECT LEN('XYZ')

Result:3

DATALENGTH

The DATALENGTH function returns the length of the input in terms of number of bytes.

Result:6

REPLACE

REPLACE function, you can replace in an input string provided as the first argument

all occurrences of the string provided as the second argument, with the string provided

as the third argument. For example, the expression REPLACE('.1.2.3.', '.', '/') substitutes all occurrences

of a dot (.) with a slash (/), returning the string '/1/2/3/'.

 

REPLICATE

The REPLICATE function allows you to replicate an input string a requested number of

times. For example, the expression REPLICATE('0', 10) replicates the string '0' ten times, returning

'0000000000'.

STUFF

The STUFF function operates on an input string provided as the first argument; then, from

the character position indicated as the second argument, deletes the number of characters

indicated by the third argument. Then it inserts in that position the string specified as the

fourth argument. For example, the expression STUFF(',x,y,z', 1, 1, '') removes the first character

from the input string, returning 'x,y,z'.



Search

Calendar

<<  July 2017  >>
SuMoTuWeThFrSa
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

Archive

Tags

Categories


Visitors

FlagCounter

Flag Counter

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Sign In