Wednesday, September 19, 2018

Autocmplete Text Box in mvc using entity framework with some extra information.


On View:

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/start/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 () {
        $("#customer").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "/AppointmentList/customerlist",
                    type: "POST",
                    dataType: "json",
                    data: { searchtxt: request.term },
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item.Name, value: item.Name, id: item.CustomerID };
                           
                        }))

                    }
                })
            },
            messages: {
                noResults: "",
                results: function (count) {
                    return count + (count > 1 ? ' results' : ' result ') + ' found';
                }
            },
            select: function (e, i) {
                $("#ContactPerson").val(i.item.id);
            }
        });
    })
</script>

On Controller:

 [HttpPost]


        public JsonResult customerlist(string searchtxt)
       {
            var customerlist = crmapp.customers.Where(x => x.Name.StartsWith(searchtxt.ToLower()));
            return Json(customerlist, JsonRequestBehavior.AllowGet);
        }

Monday, September 17, 2018

Swap two Number without using 3rd variable in c#:

            int a = 1, b = 2;
            Console.WriteLine("Before Swapping :"+a + "," + b);
            a = a + b;
            b = a - b;
            a = a - b;
            Console.WriteLine("After Swapping :" + a + "," + b);

Swap neighbor character in string in c#:

            string str = "TAPAN";
            Console.WriteLine("Before Swaping :"+str);
            string str1 = "";
            Console.Write("After Swaping :");
            for (int i = 0; i < str.Length; i = i + 2)
            {
                int j = 0;
                if (str.Length % 2 != 0 && i == str.Length - 1) { j = 1; }
                str1 += j == 0 ? str[i + 1].ToString() : "";
                str1 += str[i].ToString();
            }
            Console.WriteLine(str1);

check number is Prime or not Prime in c#.

            int number = 13;
            int pr = 0;
            for (int i = 2; i < number; i++)
            {
                if (number % i == 0)
                {
                    pr++;
                }
            }
            if (pr > 0)
            {
                Console.WriteLine("No is not Prime");
            }
            else
            {
                Console.WriteLine("No is Prime");
            }

Fibonacci series in c# :

            int kk = 1, jj = 0, yy = 0;
            Console.Write(yy);
            for (int i = 0; i < 10; i++)
            {
                jj = kk;
                kk = yy;
                yy = kk + jj;
                Console.Write("," + yy);
            }

Factorial Of Given Number in c#:

            int factnumber = 6;
            int fact = 1;
            for (int i = factnumber; i > 0; i--)
            {
                fact = fact * i;
            }
            Console.WriteLine("\nFact :" + fact);

1. Sum OF Given number c#.

2. Reverse  a number c#.

3. Count 1 in given number c#.

string getnumber = "";
            int sum = 0;
            Console.Write("Enter No :");
            getnumber = Console.ReadLine();
            int one = 0;
            for (int i = 0; i < getnumber.Length; i++)
            {
                string s = getnumber[i].ToString();
                if (s == "1")
                {
                    one++;
                }
                sum = sum + Convert.ToInt32(s);
            }

            Console.WriteLine("Sum Of Digits Of No :"+sum);
            Console.WriteLine("No of One :" + one);
            Console.Write("Reverse No.");
            for (int i = getnumber.Length - 1; i >= 0; i--)
            {
                Console.Write(getnumber[i]);
            }