Friday, 27 January 2017

How to send SMS using C# and ASP.NET

We can send SMS to any phone no and anywhere in the world using Twilio.
what is Twilio?

Twilio allows to make and receive phone calls and send and receive text messages using its APIs. Programmers can implement Twilio APIs in their code and create all sort of applications involving phone calls and SMS. It’s services are accessed over HTTP and are billed based on usage. It can be used easily in our application for creating features like SMS authentication, OTP, SMS marketing and more.

STEP 1:- Create your account in Twilio to get API credentials.
STEP 2: – Reference the Twilio.Api.dll file in your website.
For adding the reference .We need to install nuget Package in Visual Studio.
After install nuget package.
click on Tool-->Nuget Package Manager-->package Manager Console.->Type ‘Install-Package Twilio’ and press enter key..
-------------------Default.aspx---------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function msg() {
            alert("Thank you for Showing Your interest");
        }

    </script>
    <style type="text/css">
        #text {
            width: 300px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <table>
            <tr>
                <td>
                    <label>First Name</label></td>
                <td>
                    <input type="text" id="txtfName" required="required" class="text" runat="server" /></td>
            </tr>
            <tr>
                <td>
                    <label>Last Name</label></td>
                <td>
                    <input type="text" id="txlName" class="text" required="required" runat="server" /></td>
            </tr>
            <tr>
                <td>
                    <label>Email ID</label></td>
                <td>
                    <input type="email" id="txt" required="required" class="text" runat="server" /></td>
            </tr>
            <tr>
                <td>
                    <label>Phone</label></td>
                <td>
                    <input type="tel" id="txtphone" required="required" class="text" runat="server" /></td>
            </tr>
            <tr>
                <td>
                    <label>Your Requirement </label>
                </td>
                <td>
                    <textarea rows="2" id="txtReq" class="text" runat="server">

</textarea></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <asp:Button ID="btnsend" runat="server" Text="Send" OnClick="btnsend_Click" />
                </td>
            </tr>

        </table>

    </form>
</body>
</html>
---------------------------------------------------Default.aspx.cs----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

using Twilio;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnsend_Click(object sender, EventArgs e)
    {
        string number = txtphone.Value.Trim();
        string msg = txtReq.Value.Trim().ToString();
        string AccountSid = "******";
        string AuthToken = "***********";
        var twilio = new TwilioRestClient(AccountSid, AuthToken);
        var message = twilio.SendMessage("From number", number, msg, ""); 
       
        ClientScript.RegisterStartupScript(this.GetType(), "Alert", "msg()", true);

    }
}

Note:- 1)Add using Twilio in code behind .
2)For Account Sid,AuthToken and From number we need to register your self on https://www.twilio.com/.


Saturday, 14 January 2017

Abstract in c#

ABSTRACT :-The purpose of abstract class is to provide a common definition of based class that multiple derived classes can share, and can be used only as a based class and never want to create the object of this class.Any class can be convert in abstract class by adding abstract modifier to to.

Some key point of  an abstract class and method are:-

  1. An abstract class can not be instantiate.
  2.  An Abstract class can have access modifiers like public, protected, internal with class members. But abstract members cannot have private access modifier.
  3. An abstract class must have an abstract method.
  4. An abstract method is implicitly a virtual method.
  5. The class containing at least one abstract method must be declared abstract.
The purpose of an abstract class is to provide basic functionalities that multiple derived classes can share and override.
  
Example:-
       class Program
    {
        public abstract class university
        {
            public abstract void MCA();
            public abstract void MBA();
            public void Durination()
            {
                Console.WriteLine("Post Graduate fees Structure");
            }

        }
        public class WBTU:university 
        {
            public override void MCA()
            {
                Console.WriteLine("Fees is 250000");
            }
            public override void MBA()
            {
                Console.WriteLine("Fees is 5000000");
            }

        }
        public class BHU : university
        {
            public override void MCA()
            {
                Console.WriteLine("Fees is 350000");
            }
            public override void MBA()
            {
                Console.WriteLine("Fees is 450000");
            }
        }
            static void Main(string[] args)
        {
            university objUni = new WBTU();
            objUni.Durination();
            objUni.MBA();
            objUni.MCA();
            objUni = new BHU();
            objUni.MBA();
            objUni.MCA();
            Console.ReadLine();
            

        }
    }

Note:-From above example we have make one abstract class university and two abstract methods MCA and MBA. WBTU and BHU both are override university course fee.
University course common for both WBTU and BHU so university method MCA and MBA is abstract.
WBTU and BHU inherited abstract method so university method must be override here.

Thursday, 12 January 2017

Fibonacci Series using for loop in C#

using System;


    class Fibonacci
    {
        static void Main()
        {
            Console.WriteLine("Enter First No");
            int num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter Second No");
            int num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter no of iteration you need");
            int range = Convert.ToInt32(Console.ReadLine());
            int result = 0;
            Console.WriteLine(num1);
            Console.WriteLine(num2);
            for (int i = 0; i <= range; i++)
            {

                result = num1 + num2;
                Console.WriteLine(result);
                num1 = num2;
                num2 = result;
            }
            Console.ReadLine();

        }
    }
 Dry run: 
DRY RUN
NOI=10 num1=1 num2=2
No Of Iteration num1 num2 Result
1 1 2 3
2 2 3 5
3 3 5 8
4 5 8 13
5 8 13 21
6 13 21 34
7 21 34 55
8 34 55 89
9 55 89 144
10 89 144 233
 Output:-Enter First No
1
Enter Second No
2
Enter no of iteration you need
10
1
2
3
5
8
13
21
34
55
89
144
233
377

Loop: - Loop is mechanism which used to execute your statement till the condition become false.
Further loop can categories into two. 1)Range Based and 2)Condition Based.




                                                                                                                                          

Range Based:- In this case user/developer must aware range of iteration.  
Iteration 0 to 10.in this scenario we will go for loop.
For Loop:- This loop repeatedly executes  a group of  statements as long as a condition not become false.
Syntax:-for( int i=0;i<10;i++ or--)
{ Operation
}
For loop consist three importance parts.
1)      Initialization
2)      Condition
3)      Increment/ decrement.
Eg:-
( int i=0;i<10;i++ or--)
1       2            3


 .

















Tuesday, 10 January 2017

Check Whether an Alphabet is Vowel or Consonant using C#

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

namespace SwitchCase
{
    class Switch
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a Character");
            char ch = Convert.ToChar(Console.ReadLine());
            switch (ch)
            {
                case 'a':
                    Console.WriteLine("Vowel");
                    break;
                case 'e':
                    Console.WriteLine("vowel");
                    break;
                case 'i':
                    Console.WriteLine("Vowel");
                    break;
                case 'o':
                    Console.WriteLine("Vowel");
                    break;
                case 'u':
                    Console.WriteLine("Vowel");
                    break;
                default:
                    Console.WriteLine("consonant");
                    break;
                             
                    }
            Console.ReadLine();
        }
    }
}

Wednesday, 28 December 2016

Data validation using Java script with event handling.

HTML
--------------------------------------------------------------------------------------------------------------------
<html>

<head>
    <title>Registration</title>
    <link rel="stylesheet" href="Custom.css">
</head>

<body>
    <h1 class="heading">Our Financial Status</h1>

    <table class="frm">

        <tr>
            <td>
                   First Name  
            </td>
            <td>
                <input type="text" placeholder="First Name" id="txtFirstName">
            </td>
        </tr>


        <tr>
            <td>
                   Last Name  
            </td>
            <td>
                <input type="text" placeholder="Last Name" id="txtLastName">
            </td>
        </tr>


        <tr>
            <td>
                   Email Id  
            </td>
            <td>
                <input type="text" placeholder="Email" id="txtEmail">
            </td>
        </tr>


        <tr>
            <td>
                    Password  
            </td>
            <td>
                <input type="password" placeholder="Password" id="txtPassword">
            </td>
        </tr>


        <tr>
            <td>
                    Mobile No  
            </td>
            <td>
                <input type="text" placeholder="Mobile" id="txtMobileNo">
            </td>
        </tr>


        <tr>
            <td>
                    Pan Card No  
            </td>
            <td>
                <input type="text" placeholder="PanCard" id="txtPancard">
            </td>
        </tr>


        <tr>
            <td>
                   Aadhar Card No  
            </td>
            <td>
                <input type="text" placeholder="Aadhar Card" id="txtAadharCard">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="Submit" id="btnSubmit"  class="button">
            </td>
        </tr>
    <table>
          <script src="Registraion.js"></script>
</body>

</html>
----------------------------------------------------------------------------------------------------
CSS
------
body {
  font: 14px/20px 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: #404040;
  background: #2d4259;
}
.heading
{
width: 270px;
  line-height: 43px;
  margin: 50px auto 20px;
  font-size: 19px;
  font-weight: 500;
  color: white;
  color: rgba(white, .95);
  text-align: center;
  text-shadow: 0 1px rgba(black, .3);
  background: #d7604b;
  border-radius: 3px;
 }
 .frm{
  margin: 0 auto;
  width: 375px;
  padding: 20px;
  background: #f4f4f4;
  border-radius: 3px;
 }
 .input{
      display: block;
  width: auto;
  height: 50px;
  margin-top: 2px;
  font-weight: 500;
  background: none;
  border: 0;
  border-bottom: 1px solid #d8d8d8;
 }
 .label {
  float: left;
  width: 50%;
  line-height: 32px;
  color: white;
  text-align: center;
   cursor: pointer;
 }
.button {
  display: block;
  width: 100%;
  height: 42px;
  margin-top: 25px;
  font-size: 16px;
  font-weight: bold;
  color: #494d59;
  text-align: center;
  text-shadow: 0 1px rgba(white, .5);
  background: #fcfcfc;
  border: 1px solid;
  border-color: #d8d8d8 #d1d1d1 #c3c3c3;
  border-radius: 2px;
  cursor: pointer;

  }
---------------------------------------------------------------------------------------------------------------
Java Script
----------------------
function dataValidation()
{
    var firstName=document.getElementById("txtFirstName");
    var lastName=document.getElementById("txtLastName");
    var emailID=document.getElementById("txtEmail");
    var passward=document.getElementById("txtPassword")
    var mobileNo=document.getElementById("txtMobileNo");
    var panCard=document.getElementById("txtPanCard");
    var aadharCard=document.getElementById("txtAadharCard");
    var btnSubmit=document.getElementById("btnSubmit");
    btnSubmit.addEventListener("click",UserRegistration);
    firstName.addEventListener("keypress",alphabet);
    lastName.addEventListener("keypress",alphabet);
    emailID.addEventListener("keypress",alphanumeric);
    passward.addEventListener("keypress",alphanumeric);
    mobileNo.addEventListener("keypress",numeric);
    panCard.addEventListener("keypress",alphanumeric);
    aadharCard.addEventListener("keypress",numeric);
}
function UserRegistration()
{
  console.log(this);
}
function alphabet(evnt)
{
 console.log(this);
 console.log(evnt);
 var dataLength = this.value.length;
 console.log(dataLength);
    if((evnt.keyCode>=65 && evnt.keyCode<=90) ||
        (evnt.keyCode>=97 && evnt.keyCode<=122)){

    }
    else{
        alert("only alphabet[a-z or A-Z]");
        evnt.preventDefault();
    }

}
function numeric(evnt)
{
 var dataLength = this.value.length;
if((evnt.keyCode >=48 && evnt.keyCode<=57)&&(this.value.length !=10))
    {

    }        
       else
       {
            alert("only number and not than 10 digits");
      evnt.preventDefault();
         }
        }

function alphanumeric(evnt)
{

if(((evnt.keyCode >=65 && evnt.keyCode <=90) ||
   (evnt.keyCode >=48 && evnt.keyCodeode<=57) 
    &&(thi.value.length !=10)))
 {

   }
   else{
       alert("It allow not capital letter, [0-9 ] and not greather than 10 character");
        evnt.preventDefault();
   }
}

function alphnumericWithspecialcharacters(evnt)
{
        
        if(((
        (evnt.keyCode>=65 && evnt.keyCode<=90) ||
        (evnt.keyCode>=97 && evnt.keyCode<=122)||
        (evnt.keyCode >=48 && evnt.keyCodeode<=57)&&
        (this.value.length<=10 || this.value.length>=20)
       
        )))
        {

        }
        else{
             alert("It allow not [A-Z, a-z,0-9 ] and not <10 || >20 character");
             evnt.preventDefault();
        }
//Note: I want add following Special Characters in this function.
//  Ascii Value
//  45      -
//  46      .
//  64      @
//  95      _
}
dataValidation();  



Please give your comment

Tuesday, 27 December 2016

armstrong number in c

#include<stdio.h>
int main()
{
     int num, sum = 0;
         

    printf("Please enter a number: ");      
    scanf("%d",&num);

     for (int i = num; i > 0;)
            {
                sum += (i % 10) * (i % 10) * (i % 10);
                i = i / 10;

            }
 if ( sum==num)
        printf("%d is an armstrong number.",num);
    else
        printf("%d is not an armstrong number.",num);

    return 0;
}

Check Armstrong Number using C#

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
                       int num, sum = 0;
            num = Convert.ToInt32(Console.ReadLine());
            for (int i = num; i > 0;)
            {
                sum += (i % 10) * (i % 10) * (i % 10);
                i = i / 10;

            }
            if(sum==num)
                {
                    Console.WriteLine("No is armstrong");
                }
                else
                {
                    Console.WriteLine("No is not armstrong ");
                }
                Console.ReadLine();
            }

            }
}

Secure and Unsecure configuration in Dynamics CRM 365.

Overview : In Dynamics CRM, when we create a plugin, we sometimes need to pass data to that plugin, instead of writing this data inside the ...