Monday, September 19, 2016

Console Application For Get Api Consumer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
namespace ConsumeAPI
{
    class Program
    {
        static void Main(string[] args)
        {
         
            HttpClient cons = new HttpClient();
            cons.BaseAddress = new Uri("http://localhost:61011/");
            cons.DefaultRequestHeaders.Accept.Clear();
            cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            MyAPIGet(cons).Wait();
        }
        static async Task MyAPIGet(HttpClient cons)
        {
            using (cons)
            {
                HttpResponseMessage res = await cons.GetAsync("api/Login");
                res.EnsureSuccessStatusCode();
                if (res.IsSuccessStatusCode)
                {
                    dto[] tag = await res.Content.ReadAsAsync<dto[]>();
                    Console.WriteLine("\n");
                    Console.WriteLine("---------------------Calling Get Operation------------------------");
                    Console.WriteLine("\n");
                    Console.WriteLine("tagId    tagName          tagDescription");
                    Console.WriteLine("-----------------------------------------------------------");
                    Console.WriteLine("{0}\t{1}", tag[0].ID, tag[0].Name);
                    Console.ReadLine();
                }
            }
        }
    }
}








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

namespace ConsumeAPI
{
    public class dto
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}

Wednesday, September 7, 2016

C# gmail smtp server mailing

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

namespace email_try
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("vadivelan.udayakumar@gmail.com", "password"),
                EnableSsl = true
               
        };

            client.Send("vadivelan.udayakumar@gmail.com", "vadivelan.recepient@gmail.com", "test", "testbody");
            Console.WriteLine("Sent");
            Console.ReadLine();

        }
    }
}



Then goto:

https://www.google.com/settings/security/lesssecureapps

and turn it on for the sender account.







Sunday, March 6, 2016

Listening to incoming msg in android

package com.smarthome;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;


public class test extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);


        IntentFilter i=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
        BroadcastReceiver b=new sms();
        registerReceiver(b,i);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_test, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
class sms extends BroadcastReceiver {

    // Get the object of SmsManager
    final SmsManager sms = SmsManager.getDefault();

    public void onReceive(Context context, Intent intent) {

        // Retrieves a map of extended data from the intent.
        final Bundle bundle = intent.getExtras();

        try {

            if (bundle != null) {

                final Object[] pdusObj = (Object[]) bundle.get("pdus");

                for (int i = 0; i < pdusObj.length; i++) {

                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                    String phoneNumber = currentMessage.getDisplayOriginatingAddress();

                    String senderNum = phoneNumber;
                    String message = currentMessage.getDisplayMessageBody();

                    Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message);


                    // Show Alert
                    int duration = Toast.LENGTH_LONG;
                    Toast toast = Toast.makeText(context,"senderNum: "+ senderNum + ", message: " + message, duration);
                    toast.show();

                } // end for loop
            } // bundle is null

        } catch (Exception e) {
            Log.e("SmsReceiver", "Exception smsReceiver" +e);

        }
    }
}
















vadivelan:



package com.smarthome;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;


public class HomeLoader extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_loader);
        IntentFilter i=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");

        class received extends BroadcastReceiver
        {

            @Override
            public void onReceive(Context context, Intent intent) {
                Uri u=Uri.parse("content://sms/inbox");
                Cursor c=getContentResolver().query(u,null,null,null,null);
                if(c.moveToFirst())
                {
                    Toast.makeText(context,c.getString(2),Toast.LENGTH_LONG).show();
                }
            }
        }


        BroadcastReceiver b=new received();
        registerReceiver(b,i);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_home_loader, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Monday, November 30, 2015

Dynamically populating Grid View

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection s1;
    protected void Page_Load(object sender, EventArgs e)
    {
        string ss = @"Data Source=VMB-PC\SQLEXPRESS;Initial Catalog=website;Integrated Security=True";
        s1 = new SqlConnection(ss);
        try
        {
            s1.Open();
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Rollno", typeof(int)),
                            new DataColumn("Name", typeof(string)),
                            new DataColumn("Department",typeof(string)),
            new DataColumn("Batch",typeof(string)),
            new DataColumn("Section",typeof(string))});
            dt.Rows.Add(1, "h", "a", "s","c");
            GridView1.DataSource = dt;
            GridView1.DataBind();

        }
        catch (Exception excep)
        {
           
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string s = GridView1.SelectedRow.Cells[1].Text;
        Label1.Text = s;

    }
}










<%@ 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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <AlternatingRowStyle BackColor="White" />
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
    </body>
</html>

Thursday, November 26, 2015

Dynamically populating DropDown List in asp.net C#

string ss = @"Data Source=VMB-PC\SQLEXPRESS;Initial Catalog=website;Integrated Security=True";
        s = new SqlConnection(ss);
     
        s.Open();
        SqlCommand cmd = new SqlCommand("select *from departments",s);
        SqlDataReader d = cmd.ExecuteReader();
        for (int i = 0; d.Read(); i++)
        {

            DropDownList1.Items.Insert(i, d.GetString(0));
        }

Disable BACK button in asp.net c#

  1. <head>
  2. <script type ="text/javascript">  
  3.   
  4.     window.onload = window.history.forward(0);  
  5.     
  6. </script>

  1. </head>

Tuesday, November 24, 2015

Creating Alert In Asp.net C#

protected void but1(object sender, EventArgs e)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<script type = 'text/javascript'>");
        sb.Append("window.onload=function(){");
        sb.Append("alert('");
        sb.Append("Message to be displayed");
        sb.Append("')};");
        sb.Append("</script>");
        ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
     
    }