Monday, 22 May 2017

How to clock to show in a div by java script?

  <script type="text/javascript">
        var dayarray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
        var montharray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
        $(document).ready(function () {
            getthedate();
        });
        function getthedate() {
            var mydate = new Date()
            var year = mydate.getYear()
            if (year < 1000)
                year += 1900
            var day = mydate.getDay()
            var month = mydate.getMonth()
            var daym = mydate.getDate()
            if (daym < 10)
                daym = "0" + daym
            var hours = mydate.getHours()
            var minutes = mydate.getMinutes()
            var seconds = mydate.getSeconds()
            var dn = "AM"
            if (hours >= 12)
                dn = "PM"
            if (hours > 12) {
                hours = hours - 12
            }
            if (hours == 0)
                hours = 12
            if (minutes <= 9)
                minutes = "0" + minutes
            if (seconds <= 9)
                seconds = "0" + seconds
            //change font size here
            var cdate = "<small><font-size:13px color='#e67624' face='Arial'><b>" + dayarray[day] + ", " + montharray[month] + " " + daym + ", " + year + " " + hours + ":" + minutes + ":" + seconds + " " + dn
            + "</b></font></small>"
            if (document.all)
                document.all.clock.innerHTML = cdate
            else if (document.getElementById)
                document.getElementById("clock").innerHTML = cdate
            else
                document.write(cdate)
            setTimeout(function () {
                getthedate();
            }, 1000);
        }
     
        if (!document.all && !document.getElementById)
            getthedate()
        function goforit() {
            if (document.all || document.getElementById)
                setInterval("getthedate()", 1000)
        }
    </script>
<div id="clock"></div>

Sunday, 29 January 2017

How to enum class create and call enum data in controller?

Firstly we create a class enum.cs -:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectName.Entity
{
    public class ProjectEnum
    {
        public enum Status : int
        {
            Created = 1,
            CheckedOut = 2,
            CheckedIn = 3,
            Published = 4,
            Deleted = 5
        }

        public enum SourceType : int
        {
            SBI = 1,
           Axis = 2,
            ICICI = 3,
        }
    }
}

int type = Convert.ToInt32(ProjectName.SourceType.SBI );

How to age calculate from date in asp.net?

  private static TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
public static string GetCalcaulateAge(DateTime date)
        {
            string _age = "";
            int age = 0;
            int month = 0;
            int days = 0;
            int dobYear = Convert.ToInt32(date.Year);
            int dobMonth = Convert.ToInt32(date.Month);
            int dobDay = Convert.ToInt32(date.Day);
            age = Convert.ToInt32(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE).Year) - dobYear;
            month = Convert.ToInt32(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE).Month) - dobMonth;
            days = Convert.ToInt32(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE).Day) - dobDay;

            if (days < 0)
            {
                days = Math.Abs(days);
            }

            if (month < 0)
            {
                month = Math.Abs(month);
            }
            if (age == 0)
            {
                if (month == 0)
                {
                    _age = Convert.ToString(days) + " days";
                }
                else
                {
                    if (days == 0)
                    {
                        _age = Convert.ToString(month) + " months";
                    }
                    else
                    {
                        _age = Convert.ToString(month) + " months " + days + " days";
                    }
                }
            }
            else
            {
                if (age <= 12)
                {
                    if (days == 0)
                    {
                        _age = Convert.ToString(age) + " yrs " + Convert.ToString(month) + " months";
                    }
                    else if (month == 0)
                    {
                        _age = Convert.ToString(age) + " yrs " + days + " days";
                    }
                    else
                    {
                        _age = Convert.ToString(age) + " yrs " + Convert.ToString(month) + " months " + days + " days";
                    }
                }
                else
                {
                    _age = Convert.ToString(age) + " yrs";
                }
            }
            return _age;
        }

Saturday, 28 January 2017

How to autocomplete text box by ajax with filtering in mvc?

<link rel="stylesheet"href="//code.jquery.com/ui/1.12.1/themes/base/jqueryui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="textjavascript">
    function changeSourceType(obj) {
        debugger;
        var sourceData = [];
        var sourcetype = document.getElementById("ddlSourceType" + obj).value;
        $("#txtSource" + obj).autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '/Layout/FillSource',
                    type: "GET",
                    dataType: "JSON",
                    data: { sourcetype: sourcetype },
                    success: function(data) {
                        var array = $.map(data, function(item) {
                            return {
                                label: item.Name,
                                value: item.Name
                            };
                        });
                        //call the filter here
                        response($.ui.autocomplete.filter(array, request.term));
                    }
                });
            },
            minLength: 0,
            focus: function (event, ui) {
                $("#txtSource" + obj).val(ui.item.label);
            }
        });
    }
</script>

<div class="col-md-3">
    <label class="" for="form-first-name">Source Type</label>
       <div class="clearfix">
           <select id="ddlSourceType" class="form-control" onchange="changeSourceType()">
                 <option value="0">Select</option>
                  <option value="1">Content</option>
                   <option value="2">Folder</option>
                   <option value="3">Taxonomy</option>
            </select>
      </div>
 </div>

 <div class="col-md-3">
       <label class="" for="form-first-name">Select Source</label>
          <div class="clearfix">
               <input type="text" id="txtSource1" class="form-control">
           </div>
 </div>

AutoComplete Link -: https://jqueryui.com/autocomplete/