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]);
            }

Csharp program to print a Rhombus:

for (int i = 1; i <= 5; i++)
            {
                for (int j = i - 1; j > 1; j--)
                {
                    Console.Write(j);
                }
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
            for (int i = 4; i > 0; i--)
            {
                for (int j = i - 1; j > 1; j--)
                {
                    Console.Write(j);
                }
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }

output : 

1
212
32123
4321234
32123
212
1

Csharp program to print Rhombus of numbers:

 int nu = 5;
            for (int i = 1; i <= nu; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    Console.Write(j);
                }
                for (int j = i - 2; j > 0; j--)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }

Output :
1
121
12321
1234321

Pattern-1:

output:

    1
   121
  12321
 1234321
123454321

Code:

            int nu = 5;
            for (int i = 1; i <= nu; i++)
            {
                int kk = ((nu-i) +(nu - i)) / 2;
                for (int y = 0; y < kk; y++)
                {
                    Console.Write(" ");
                }

                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }
                for (int j = i - 1; j > 0; j--)
                {
                    Console.Write(j);
                }

                for (int y = 0; y < kk; y++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine();
            }

Tuesday, September 11, 2018

Export HTML to Excel In window application c#.


 string str = @" <table>
                                    <thead>
                                      <tr>
                                        <th>Firstname</th>
                                        <th>Lastname</th>
                                        <th>Email</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <tr>
                                        <td>John</td>
                                        <td>Doe</td>
                                        <td>john@example.com</td>
                                      </tr>
                                      <tr>
                                        <td>Mary</td>
                                        <td>Moe</td>
                                        <td>mary@example.com</td>
                                      </tr>
                                      <tr>
                                        <td>July</td>
                                        <td>Dooley</td>
                                        <td>july@example.com</td>
                                      </tr>
                                    </tbody>
                                  </table>";
                File.WriteAllText(filename,str);

Friday, September 7, 2018

Value Type:

Value type contain it's own value .
for example:
int i=100;
Refrence Value Example: