Thursday, 27 April 2017

Get Current Latitude and longitude in jquery


 <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyD4IuRFVcMjWo1qWvBrS3v4uvDXcCiq_c4&sensor=false"></script>
<script type="text/javascript">
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (p) {
                alert('Latitude:' + p.coords.latitude + "<br />Longitude: " + p.coords.longitude);

            });
        }
        else {
            alert('Geo Location feature is not supported in this browser.');
        }
</script>

List data in to Json data and json date convert in to jquesry

Html google Chart
================

 <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
    google.charts.load("current", { packages: ["corechart"] });
    google.charts.setOnLoadCallback(drawChart);
    function drawChart() {

        debugger;      
        $.ajax({
            type: "post",
            url: "/DealsStatistics/selectcontryreport",
            success: function (response) {
                debugger;
                var reportdata = [];

  /*Age Chart*/
                var data = google.visualization.arrayToDataTable([
                ['Task', ''],
                ['Age 15-25', response.objreportAge.Age15to25],
                ['Age 26-35', response.objreportAge.Age26to35],
                ['Age 36-45', response.objreportAge.Age36to45],
                ['Age 45-56', response.objreportAge.Age46to55],
                ['Age upto 56', response.objreportAge.Age56]]);
                var options = {
                    title: '',
                    is3D: true,
                    legend: 'top',
                    tooltip: { isHtml: true },
                    chartArea: {
                        top: 20,
                        width: 300,
                        height: 300
                    },

                    slices: { 0: { color: '#0078d7' }, 1: { color: '#80b2da' }, 2: { color: 'red' } }
                };

                var chart = new google.visualization.PieChart(document.getElementById('idAgechart'));
                chart.draw(data, options);
   /*Age Chart End*/

   /*Gender Chart*/
                var data = google.visualization.arrayToDataTable([
                ['Task', ''],
                ['Male', response.objreportgender.male],
                ['Female', response.objreportgender.female]
                ]);

                var options = {
                    title: '',
                    is3D: true,
                    legend: 'top',
                    tooltip: { isHtml: true },
                    chartArea: {
                        top: 20,
                        width: 250,
                        height: 300
                    },

                    slices: { 0: { color: '#0078d7' }, 1: { color: '#80b2da' }, 2: { color: 'red' } }
                };

                var chart = new google.visualization.PieChart(document.getElementById('idgenderchart'));
                chart.draw(data, options);

  /*Gender Chart end*/

  /*Location Chart*/
                if (response.objreportcountrylist.length > 0) {
                    reportdata = [['Task', '']];
                    for (var i = 0; i < response.objreportcountrylist.length; i++) {
                        reportdata.push([response.objreportcountrylist[i].Country, response.objreportcountrylist[i].Countryper])
                    }
                    var data = google.visualization.arrayToDataTable(reportdata);
                    var options = {
                        title: '',
                        is3D: true,
                        legend: 'top',
                        tooltip: { isHtml: true },
                        chartArea: {
                            top: 20,
                            width: 250,
                            height: 300
                        },
                        slices: { 0: { color: '#0078d7' }, 1: { color: '#80b2da' }, 2: { color: 'red' } }
                    };
                    var chart = new google.visualization.PieChart(document.getElementById('idlocationchart'));
                    chart.draw(data, options);
                }
   /*Location end*/

                /*Bind Table*/
                if (response.objvenderreporttbllist.length > 0) {
                    reportdata = [['Task', '']];
                    var Html = '';
                    var item = 0;
                    for (var i = 0; i < response.objvenderreporttbllist.length; i++) {
                        var newdate = new Date(response.objvenderreporttbllist[i].date.match(/\d+/)[0] * 1);
                        Html = Html + "<tr><td>" + item++ + "</td><td>" + newdate + "</td><td>" + response.objvenderreporttbllist[i].male + "</td><td>" + response.objvenderreporttbllist[i].female + "</td><td>" + response.objvenderreporttbllist[i].total + "</td><td>" + response.objvenderreporttbllist[i].location + "</td></tr>"
                                          }
                    $("#tbldata").html(Html);
                }
                /*End Table*/
            }          
        });  
    }


========
C#
==========

   public ActionResult selectcontryreport()
        {
            int vendorid = 1;
            dealstaticsrepot obj = new dealstaticsrepot();          
            obj = (new vendorReport()).getvendorreport(vendorid);    
            return Json(obj);
        }


Wednesday, 26 April 2017

open Xml in sql or comma sepreted value in sql

==================
for open Xml
==================

(select  STUFF((SELECT ', ' + cast( CustomerID as nvarchar(20)) FROM UsedDealDetail WHERE cast(CouponUsedDate as date) =cast(ud.CouponUsedDate as date) FOR XML PATH('') ), 1, 2, '')) as userid


=================
for variable
=================
  declare @tmp varchar(2500),@customerid varchar(2500)
      SET @tmp = ''
      select @tmp = @tmp + Cast(CustomerID as nvarchar(10)) + ', ' from  UsedDealDetail where VendorID=@vendoeId group by CustomerID

set @customerid=SUBSTRING(@tmp, 0, LEN(@tmp))

Tuesday, 25 April 2017

convert list into jquery JsonConvert SerializeObject or jquery eval funcation

==============================
Jquery
=============================

            $(function () {

                $("#selectcountryid").change(function () {
                    debugger;
                        var selectedcountry = $(this).find("option:selected").text();
                        $.ajax({
                            type: "post",
                            url: "/Administrator/SelectState",
                            data: {'country': selectedcountry },
                            success: function (response) {
                                var item = eval("(" + response + ")");
                                if (item.length > 0) {
                                    var listitem = '<option  value="select">--Select state--</option>';
                                    for (var i = 0; i < item.length; i++) {
                                        listitem = listitem + '<option  value="' + item[i].stateid + '">' + item[i].stateName + '</option>'
                                    }                                  
                                    $('#idstate').html(listitem)
                                }
                            }
                        });
                });
 });

======================================
C# controller view
======================================
     public string SelectState(string country = null)
        {
            string listofsatate = "0";
            var objstatelist = (new pushnotification()).SelectState(country);
            if (objstatelist.Count > 0)
            {
                listofsatate = JsonConvert.SerializeObject(objstatelist);
            }
            return listofsatate;
        }
========================================

Thursday, 13 April 2017

Create a multi language Controller in mvc

HTML
=================
@{int Lid = Convert.ToInt32(Request.Cookies["LID"].Value);}
 <a class="@(Lid == 1 ? "comnBtn activelid" : "comnBtn")" id="enbtn" href="/Language/ChangeLanguage?Lang=en">English</a>
            <a class="@(Lid == 2 ? "comnBtn activelid" : "comnBtn")" id="arbtn" href="/Language/ChangeLanguage?Lang=ar">Arabic</a>


controller:
====================

        public ActionResult ChangeLanguage(string Lang)
        {
            if (Lang != null)
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Lang);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Lang);
                var cookie = new HttpCookie("Language");
                var cookieLID = new HttpCookie("LID");
                if (Lang == "en")                
                    cookieLID.Value = "1"; 
                else              
                    cookieLID.Value = "2";  

                cookie.Value = Lang;                
                Response.Cookies.Add(cookie);
                Response.Cookies.Add(cookieLID);

            }
            return Redirect(Request.UrlReferrer.ToString());
        }


Use of Cookies
======================

 [HttpGet]
        public ActionResult faq()
        {
            _FAQ obj = new _FAQ();
            int Lid = Convert.ToInt32(Request.Cookies["LID"].Value);
            obj = (new CMSdata()).faqByLID("GetbyLid", Lid);
            return View(obj);
        }

Monday, 3 April 2017

Paging in MVC

HTML
=======================================
@model wafrooBL.Models.GetMyDealList
  @if (Model.pager.EndPage > 1)
{
    <ul class="pagination">
        @if (Model.pager.CurrentPage > 1)
{
            <li>
                <a href="/customer/MyDeals/Index">First</a>
            </li>
            <li>
                <a href="/customer/MyDeals/Index?pageno=@(Model.pager.CurrentPage - 1)">Previous</a>
            </li>
}

        @for (var page = Model.pager.StartPage; page <= Model.pager.EndPage; page++)
{
            <li class="@(page == Model.pager.CurrentPage ? "active" : "")">
                <a href="/customer/MyDeals/Index?pageno=@page">@page</a>
            </li>
}

        @if (Model.pager.CurrentPage < Model.pager.TotalPages)
{
            <li>
                <a href="/customer/MyDeals/Index?pageno=@(Model.pager.CurrentPage + 1)">Next</a>
            </li>
            <li>
                <a href="/customer/MyDeals/Index?pageno=@(Model.pager.TotalPages)">Last</a>
            </li>
}
    </ul>
   }
================================================================
Controller
===========================================================
 public ActionResult Index(long? CustomerId = null, int? pageno=1)
        {
            GetMyDealList obj = null;
            int Pagesize = 5;
            int totalrecord = 0;        
            if (CustomerId != null)
            {              
                obj = new GetMyDealList(CustomerId, pageno, Pagesize);
                if(obj.list.Count>0)
                {
                    totalrecord = obj.list[0].TotalCount;
                }
                var pager = new Pager(totalrecord,pageno, Pagesize);
                obj.pager = pager;      
            }
            return View(obj);
        }
==========================================================
Bl and property
=========================================================

    public class GetMyDealList
    {
        public List<Deal> list { get; set; }
        public Pager pager { get; set; }
        BusinessLogic bl = new BusinessLogic();
        public GetMyDealList(long? CustomerId = null, int ? pageno =null, int ? Pagesize=null)
        {
            this.list = bl.GetMyDeal(CustomerId, pageno, Pagesize);
        }    
     
    }

public class Pager
    {
        public Pager(int totalItems, int? page, int pageSize)
            {
                // calculate total, start and end pages
                var totalPages = (int)Math.Ceiling((decimal)totalItems / (decimal)pageSize);
                var currentPage = page != null ? (int)page : 1;
                var startPage = currentPage - 5;
                var endPage = currentPage + 4;
                if (startPage <= 0)
                {
                    endPage -= (startPage - 1);
                    startPage = 1;
                }
                if (endPage > totalPages)
                {
                    endPage = totalPages;
                    if (endPage > 10)
                    {
                        startPage = endPage - 9;
                    }
                }

                TotalItems = totalItems;
                CurrentPage = currentPage;
                PageSize = pageSize;
                TotalPages = totalPages;
                StartPage = startPage;
                EndPage = endPage;
            }

            public int TotalItems { get; private set; }
            public int CurrentPage { get; private set; }
            public int PageSize { get; private set; }
            public int TotalPages { get; private set; }
            public int StartPage { get; private set; }
            public int EndPage { get; private set; }
    }
=======================================================
Dll get info using Stored Proceduer
============================================
ALTER procedure [dbo].[getMyDealsGk] --@CustomerId=2, @pageno=1 ,@Pagesize=40
(
 @CustomerId bigint = 0,
 @Result int =0 OUT,
 @Message nvarchar(100)=null OUT,
 @pageno int=0,
 @Pagesize int=0
)
AS
BEGIN
if(@CustomerId!=0)
begin
declare @RowSkip int
declare @TotalRecord int
set @RowSkip =(@pageno - 1) * @Pagesize

select @TotalRecord=count(1) from  [Deals-Master] DM
      where DM.[IsDelete] = 0 and  DM.CustomerId = @CustomerId

SELECT DISTINCT DM.[DealID]
      ,DM.[VendorID]
,@TotalRecord as totalrecord  
      FROM [Deals-Master] DM  
      where DM.[IsDelete] = 0 and  DM    .CustomerId = @CustomerId order by DM .CustomerId
 OFFSET @RowSkip ROWS FETCH NEXT  @Pagesize ROWS ONLY

end
END

--select @@version

--select * from [MyDeals] where



Auto fill Information in text box

HTML
===============
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<style>
    .autofillcon{
            position: absolute;
    z-index: 10000;
    background-color: white;
    cursor: pointer;
    padding: 8px 3px 8px 12px;
    border: 1px solid #dcdcdc;
    width: 100%;
    display:none;
    }
    ul li{
            padding-bottom: 4px;
    }
 ul li:hover, ul li:focus {
     /*background-color: lightgray;*/
 color:lightgray;
}
</style>

<div class="searchBar clearfix">
    <div class="container">
        <label>Search</label>
        <div class="searchBox">
            <input type="text" id="idtext" class="inputSearch"  placeholder="Search Deal By Location/Deal Name / Category" />          
            <a href="javascript:void(0)" class="SearchBtn"><img src="~/Content/images/searchIcon.jpg" alt="" /></a>  
            <ul id="autofile" class="autofillcon">  
         
            </ul>        
        </div>
    </div>
</div>
<!--End SearchBar-->
<script>
    $(document).ready(function () {
        $("#idtext").keyup(function () {
            var value = $('#idtext').val();
            var length = value.length;        
            if (length > 2)
            {
                       $.ajax({
                           type: "post",
                           url: "Home/AutofillInfo",
                           data: { 'Searchkey': value, 'searchBy': 'Autofill', },
                           success: function (response) {                                                  
                               var item = eval("(" + response + ")");
                               var HTML = '';
                               for (var i = 0; i < item.length; i++) {                            
                                   HTML = HTML + "<li onclick=\"$('#idtext').val($(this).text());  $('#autofile').hide().html();\">" + item[i].Remark + "</li>";
                               }
                               $('#autofile').show().html(HTML);
                           }
                       });
            }
         
        });
       
    });
</script>

C#====================
        public string AutofillInfo(string Searchkey, string searchBy = null)
        {
            SearchDeal searchDeal = new SearchDeal();
            string response = string.Empty;
            List<Deal> deal = searchDeal.DealList(Searchkey, searchBy);
            response = JsonConvert.SerializeObject(deal);
            return response;
        }