Tuesday, February 24, 2009

Google Map API sample parameter as from address & to Address

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

<title>Google Maps JavaScript API Example: Directions + Static Map</title>

<script src=" http://maps.google.com/?file=api&amp;v=2.x&amp;key=Your API Key"

type="text/javascript"></script>

<style type="text/css">

body {

font-family: Verdana, Arial, sans serif;

font-size: 11px;

margin: 2px;

}

table.directions th {

background-color:#EEEEEE;

}

img {

color: #000000;

}

</style>

<script type="text/javascript">

var map;

var gdir;

var geocoder = null;

var addressMarker;

//alert(QueryVariable);

function initialize() {

if (GBrowserIsCompatible()) {

map =

new GMap2(document.getElementById("map_canvas"));

gdir =

new GDirections(map, document.getElementById("directions"));

GEvent.addListener(gdir,

"addoverlay", onGDirectionsLoad);

GEvent.addListener(gdir,

"error", handleErrors);

var queryString = new String();

queryString = window.location.search;

queryString = queryString.substring(1);

document.getElementById(

"div1").innerHTML = queryString + "<br />";

var arr1 = new Array();

arr1 = queryString.split(

"&");

var arr2 = new Array();

var tempval;

var tempval1;

for(var i = 0; i<arr1.length; i++)

{

arr2[i] = arr1[i].toString().substring(arr1[i].toString().indexOf(

"=") + 1);

arr1[i] = arr1[i].toString().substring(0,arr1[i].toString().indexOf(

"="));

if (i==0)

{

tempval= arr2[0].toString();

}

if (i==1)

{

tempval1= arr2[1].toString();

}

}

document.getElementById(

"div1").innerHTML += arr1.concat() + "<br />";

document.getElementById(

"div1").innerHTML += arr2.concat();

document.getElementById(

"fromAddress").innerText=tempval ;

document.getElementById(

"toAddress").innerText=tempval1 ;

var fdirc=tempval;

var tdirc=tempval1;

setDirections(fdirc, tdirc,

"en_US");

}

}

function setDirections(fromAddress, toAddress, locale)

{

gdir.load(

"from: " + fromAddress + " to: " + toAddress,

{

"locale": locale });

}

function handleErrors(){

if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)

alert(

"No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)

alert(

"A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)

alert(

"The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_BAD_KEY)

alert(

"The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)

alert(

"A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

else alert("An unknown error occurred.");

}

function onGDirectionsLoad(){

var poly = gdir.getPolyline();

if (poly.getVertexCount() > 100) {

// alert("This route has too many vertices");

return;

}

var baseUrl = "http://maps.google.com/staticmap?";

var params = [];

var markersArray = [];

markersArray.push(poly.getVertex(0).toUrlValue(5) +

",greena");

markersArray.push(poly.getVertex(poly.getVertexCount()-1).toUrlValue(5) +

",greenb");

params.push(

"markers=" + markersArray.join("|"));

var polyParams = "rgba:0x0000FF80,weight:5|";

var polyLatLngs = [];

for (var j = 0; j < poly.getVertexCount(); j++) {

polyLatLngs.push(poly.getVertex(j).lat().toFixed(5) +

"," + poly.getVertex(j).lng().toFixed(5));

}

params.push(

"path=" + polyParams + polyLatLngs.join("|"));

params.push(

"size=300x300");

params.push(

"key=ABQIAAAAqIgtWyiOtP6QBTeyzVln2hQyDHt7JDG3iBXpfs6LRlLb1WavxBQ4WvuAL-v0NSB7koPUpk8oR28XeA");

baseUrl += params.join(

"&");

var extraParams = [];

extraParams.push(

"center=" + map.getCenter().lat().toFixed(6) + "," + map.getCenter().lng().toFixed(6));

extraParams.push(

"zoom=" + map.getZoom());

addImg(baseUrl +

"&" + extraParams.join("&"), "staticMapOverviewIMG");

var extraParams = [];

extraParams.push(

"center=" + poly.getVertex(0).toUrlValue(5));

extraParams.push(

"zoom=" + 15);

addImg(baseUrl +

"&" + extraParams.join("&"), "staticMapStartIMG");

var extraParams = [];

extraParams.push(

"center=" + poly.getVertex(poly.getVertexCount()-1).toUrlValue(5));

extraParams.push(

"zoom=" + 15);

addImg(baseUrl +

"&" + extraParams.join("&"), "staticMapEndIMG");

//alert(lstrDistance);

}

function

addImg(url, id) {

var img = document.createElement("img");

img.src = url;

document.getElementById(id).innerHTML =

"";

document.getElementById(id).appendChild(img);

}

</script>

</head>

<body onload="initialize()" onunload="GUnload()">

<h2>Maps API Directions Illustrated</h2>

<form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">

<table align="center">

<tr><th align="right">From:&nbsp;</th>

<td><input type="text" size="25" id="fromAddress" name="from" value="Palo Alto"/></td>

<th align="right">&nbsp;&nbsp;To:&nbsp;</th>

<td align="right"><input type="text" size="25" id="toAddress" name="to"

value="Mountain View" /></td></tr>

<tr><th>Language:&nbsp;</th>

<td colspan="3"><select id="locale" name="locale">

<option value="en" selected>English</option>

<option value="fr">French</option>

<option value="de">German</option>

<option value="ja">Japanese</option>

<option value="es">Spanish</option>

</select>

<input name="submit" type="submit" value="Get Directions!" />

<asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label></td></tr>

</table>

</form>

<br/>

<table class="directions">

<tr><th>Formatted Directions</th><th>Map</th></tr>

<tr>

<td valign="top"><div id="directions" style="width: 275px"></div></td>

<td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td>

</tr>

</table>

<

hr>

Static Maps (printable) version:

<div id="staticMapOverviewIMG"></div>

<div id="staticMapStartIMG"></div>

<div id="staticMapEndIMG"></div>

<div id="div1"></div>

<

br clear="all"/>

</body>

</

html>

Monday, February 16, 2009

Last 5 Received date in Item ledger F4111 JD Edwards



drop table jde_rk.dbo.max250date
select distinct illitm,ilmcu,max(iltrdj)iltrdj into jde_rk.dbo.max250date from proddta.f4111
where ildcto in('oh','ot') and ildct='ov' and ilkcoo=250 --and illitm='1618687'
group by illitm,ilmcu
order by iltrdj

drop table jde_rk.dbo.max250date1
select a.illitm,a.ilmcu, max(b.iltrdj)iltrdj into jde_rk.dbo.max250date1 from proddta.f4111 b
left outer join jde_rk.dbo.max250date a on a.illitm=b.illitm and a.ilmcu=b.ilmcu
where a.iltrdj >b.iltrdj
group by a.illitm,a.ilmcu
order by iltrdj desc

drop table jde_rk.dbo.max250date2
select a.illitm,a.ilmcu, max(b.iltrdj)iltrdj into jde_rk.dbo.max250date2 from proddta.f4111 b
left outer join jde_rk.dbo.max250date1 a on a.illitm=b.illitm and a.ilmcu=b.ilmcu
where a.iltrdj >b.iltrdj
group by a.illitm,a.ilmcu
order by iltrdj desc

drop table jde_rk.dbo.max250date3
select a.illitm,a.ilmcu, max(b.iltrdj)iltrdj into jde_rk.dbo.max250date3 from proddta.f4111 b
left outer join jde_rk.dbo.max250date2 a on a.illitm=b.illitm and a.ilmcu=b.ilmcu
where a.iltrdj >b.iltrdj
group by a.illitm,a.ilmcu
order by iltrdj desc

drop table jde_rk.dbo.max250date4
select a.illitm,a.ilmcu, max(b.iltrdj)iltrdj into jde_rk.dbo.max250date4 from proddta.f4111 b
left outer join jde_rk.dbo.max250date3 a on a.illitm=b.illitm and a.ilmcu=b.ilmcu
where a.iltrdj >b.iltrdj
group by a.illitm,a.ilmcu
order by iltrdj desc

Find Nth ( 2nd, 3rd max ) maximum value in SQL Server

Find Nth maximum value in SQL Server
Use Pubs
Go

Create table Employee
(
Eid int,
Name varchar(10),
Salary money
)
Go

Insert into Employee values (1,'harry',3500)
Insert into Employee values (2,'jack',2500)
Insert into Employee values (3,'john',2500)
Insert into Employee values (4,'xavier',5500)
Insert into Employee values (5,'steven',7500)
Insert into Employee values (6,'susana',2400)
Go
 
 
Select * From Employee E1 Where
    (0) = (Select Count(Distinct(E2.Salary)) From Employee E2 Where
E2.Salary > E1.Salary)
Select * From Employee E1 Where
    (1) = (Select Count(Distinct(E2.Salary)) From Employee E2 Where
E2.Salary > E1.Salary)
....

Friday, February 13, 2009

Distance Calculation Between Two Address using Free API , c#, ASP.Net 2.0

Distance calculation Between two address using API , c#,ASP.Net 2.0
 
Distance calculation Between two address using API , c#,ASP.Net 2.0
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="distcalcul.aspx.cs" Inherits="distcalcul" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table align="center">
            <tr>
                <td style="width: 100px">
                </td>
                <td style="width: 100px">
                    <asp:Label ID="Label8" runat="server" Text="From Address"></asp:Label></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                    <asp:Label ID="Label1" runat="server" Text="Address1"></asp:Label></td>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox1" runat="server">71 Fortune Drive</asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                    <asp:Label ID="Label2" runat="server" Text="City:"></asp:Label></td>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox2" runat="server">Irvine</asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                    <asp:Label ID="Label3" runat="server" Text="State"></asp:Label></td>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox3" runat="server">CA</asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px; height: 21px">
                </td>
                <td style="width: 100px; height: 21px">
                    <asp:Label ID="Label9" runat="server" Text="To Address"></asp:Label></td>
                <td style="width: 100px; height: 21px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px; height: 21px">
                    <asp:Label ID="Label4" runat="server" Text="Address:"></asp:Label></td>
                <td style="width: 100px; height: 21px">
                    <asp:TextBox ID="TextBox4" runat="server">833 W. Torrance Blvd.</asp:TextBox></td>
                <td style="width: 100px; height: 21px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                    <asp:Label ID="Label5" runat="server" Text="City"></asp:Label></td>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox5" runat="server">Torrance</asp:TextBox></td>
                <td style="width: 100px">
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                    <asp:Label ID="Label6" runat="server" Text="State"></asp:Label></td>
                <td style="width: 100px">
                    <asp:TextBox ID="TextBox6" runat="server">CA</asp:TextBox></td>
                <td style="width: 100px">
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /></td>
            </tr>
            <tr>
                <td style="width: 100px">
                    <asp:Label ID="Label10" runat="server"></asp:Label></td>
                <td style="width: 100px">
                    <asp:Label ID="Label7" runat="server" Width="76px"></asp:Label></td>
                <td style="width: 100px">
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

code Behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class distcalcul : System.Web.UI.Page
{
    double flatitude = 0;
    double flongitude = 0;
    double tlatitude = 0;
    double tlongitude = 0;
    
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string street=TextBox1.Text;
        string city = TextBox2.Text;
        string state = TextBox3.Text;
       
        fdistcal(street,city, state);
        string tstreet = TextBox4.Text;
       string tcity = TextBox5.Text;
       string tstate = TextBox6.Text;
      tdistcal(tstreet, tcity, tstate);

      distanceCal(flatitude, flongitude, tlatitude, tlongitude, 'M');
      //Response.Write(distanceCal(flatitude, flongitude, tlatitude, tlongitude, 'K') * 0.62);
      double totdist = distanceCal(flatitude, flongitude, tlatitude, tlongitude, 'K') * 0.62;
   //ToString("#0.00"));
      Label7.Text = totdist.ToString("#0.000");
      Label10.Text = "Distance(Miles)";
       
    }

    void fdistcal(string street, string city, string state)
    {
        string geocoderUri = string.Format("http://rpc.geocoder.us/service/rest?address={0},{1},{2}", street, city, state);
        XmlDocument geocoderXmlDoc = new XmlDocument();
        geocoderXmlDoc.Load(geocoderUri);
        XmlNamespaceManager nsMgr = new XmlNamespaceManager(geocoderXmlDoc.NameTable);
        nsMgr.AddNamespace("geo", @"http://www.w3.org/2003/01/geo/wgs84_pos#");
        string sLong = geocoderXmlDoc.DocumentElement.SelectSingleNode(@"//geo:long", nsMgr).InnerText;
        string sLat = geocoderXmlDoc.DocumentElement.SelectSingleNode(@"//geo:lat", nsMgr).InnerText;
        double latitude = Double.Parse(sLat);
        double longitude = Double.Parse(sLong);
    //   Response.Write("Latitude: " + latitude + "<br /> Longitude: " + longitude);
        flatitude=latitude;
        flongitude=longitude;
  
    }
    void tdistcal(string street, string city, string state)
    {
        string geocoderUri = string.Format("http://rpc.geocoder.us/service/rest?address={0},{1},{2}", street, city, state);
        XmlDocument geocoderXmlDoc = new XmlDocument();
        geocoderXmlDoc.Load(geocoderUri);
        XmlNamespaceManager nsMgr = new XmlNamespaceManager(geocoderXmlDoc.NameTable);
        nsMgr.AddNamespace("geo", @"http://www.w3.org/2003/01/geo/wgs84_pos#");
        string sLong = geocoderXmlDoc.DocumentElement.SelectSingleNode(@"//geo:long", nsMgr).InnerText;
        string sLat = geocoderXmlDoc.DocumentElement.SelectSingleNode(@"//geo:lat", nsMgr).InnerText;
        double latitude = Double.Parse(sLat);
        double longitude = Double.Parse(sLong);
        //Response.Write("Latitude: " + latitude + "<br /> Longitude: " + longitude);
        tlatitude = latitude;
        tlongitude = longitude;
       
 
    }

    private double distanceCal(double Lat1, double Long1, double Lat2, double Long2, char unit)
    {
        double dDistance = Double.MinValue;
        double dLat1InRad = Lat1 * (Math.PI / 180.0);
        double dLong1InRad = Long1 * (Math.PI / 180.0);
        double dLat2InRad = Lat2 * (Math.PI / 180.0);
        double dLong2InRad = Long2 * (Math.PI / 180.0);
        double dLongitude = dLong2InRad - dLong1InRad;
        double dLatitude = dLat2InRad - dLat1InRad;
        // Intermediate result a.
        double a = Math.Pow(Math.Sin(dLatitude / 2.0), 2.0) +Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) *Math.Pow(Math.Sin(dLongitude / 2.0), 2.0);
        // Intermediate result c (great circle distance in Radians).
        double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a));
        // Distance.
        // const Double kEarthRadiusMiles = 3956.0;
        const Double kEarthRadiusKms = 6376.5;
        dDistance = kEarthRadiusKms * c;
        return dDistance;
        //return (dist);
    }

    

}
 

Thursday, February 12, 2009

Re: Get Longitude and Latitude from an Address sample, C# asp.net 2.0,3.5


using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

System.Xml;

public

partial class Default2 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string street = "1600 Pennsylvania Ave";

string city = "Washington";

string state = "DC";

//string zip = "20500";

string geocoderUri = string.Format("http://rpc.geocoder.us/service/rest?address={0},{1},{2}", street, city, state);

XmlDocument geocoderXmlDoc = new XmlDocument();

geocoderXmlDoc.Load(geocoderUri);

XmlNamespaceManager nsMgr = new XmlNamespaceManager(geocoderXmlDoc.NameTable);

nsMgr.AddNamespace(

"geo", @"http://www.w3.org/2003/01/geo/wgs84_pos#");

string sLong = geocoderXmlDoc.DocumentElement.SelectSingleNode(@"//geo:long", nsMgr).InnerText;

string sLat = geocoderXmlDoc.DocumentElement.SelectSingleNode(@"//geo:lat", nsMgr).InnerText;

double latitude = Double.Parse(sLat);

double longitude = Double.Parse(sLong);

Response.Write(

"Latitude: " + latitude + "<br /> Longitude: " + longitude);

}

}


Wednesday, February 11, 2009

Delete duplicate records SQL-SERVER

select count(*)cnt,ibitm into jde_rk.dbo.ttt_11 from jde_rk.dbo.tttt_4102 group by ibitm  having count(*)>1


DELETE jde_rk.dbo.tttt_4102 
FROM jde_rk.dbo.tttt_4102 a, jde_rk.dbo.ttt_11 b
WHERE a.ibitm=b.ibitm
AND t1.col2 = holdkey.col2

Monday, February 2, 2009

Open Window on click (Select) on gridview asp.net c# 2.0

protected

void gridViewMaster_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

e.Row.Attributes[

"onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";

e.Row.Attributes[

"onmouseout"] = "this.style.textDecoration='none';";

e.Row.Attributes[

"onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);

//e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);

e.Row.Attributes.Add(

"onclick", "window.navigate('editrawdata.aspx?LeadID=" + DataBinder.Eval(e.Row.DataItem, "UKID") + "','myprofilewindow','width=400,height=600,toolbar=0,resizable=0');");

}

Dynamic CssClass for textbox c# code behind

 
txtOwnerFirstName.CssClass =
"txtbxrep";
 

Monday, January 26, 2009

ListView Sample - Asp.net 3.5 C# vb with datapager

When I first did program got following error:
An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server".
after google many site got help and created first ListView program using sql-server.
 
 
 
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml">

<

head runat="server">

<title>Untitled Page</title>

</

head>

<

body>

<form id="form1" runat="server">

<div>

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" ItemPlaceholderID="LeadRep">

<LayoutTemplate>

<div id="LeadRep" runat="server"></div>

</LayoutTemplate>

<ItemTemplate>

<div><%# DataBinder.Eval(Container.DataItem,"LeadType") %></div>

<div><%# DataBinder.Eval(Container.DataItem,"HomePhone") %></div>

</ItemTemplate>

</asp:ListView>

<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="5">

<

fields><asp:nextpreviouspagerfield ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" /><asp:numericpagerfield />

<

asp:nextpreviouspagerfield ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"

ShowPreviousPageButton

="False" />

</

fields>

</

asp:DataPager>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:SalesforceConnectionString %>"

SelectCommand="SELECT * FROM [SF_TranData]"></asp:SqlDataSource>

</div>

</form>

</

body>

</

html>

Thursday, January 22, 2009

Disable Mouse While Processing Data C# asp.net vb 2.0

Works fine with master file also...
<html>
<head>
   <style type="text/css">
      .LockOff {
         display: none;
         visibility: hidden;
      }

      .LockOn {
         display: block;
         visibility: visible;
         position: absolute;
         z-index: 999;
         top: 0px;
         left: 0px;
         width: 105%;
         height: 105%;
         background-color: #ccc;
         text-align: center;
         padding-top: 20%;
         filter: alpha(opacity=75);
         opacity: 0.75;
      }
   </style>

   <script type="text/javascript">
      function skm_LockScreen(str)
      {
         var lock = document.getElementById('skm_LockPane');
         if (lock)
            lock.className = 'LockOn';

         lock.innerHTML = str;
      }
   </script>
</head>
<body>
   <h2>Overlay Test Page</h2>
   <p>
      Please enter your name:
      <input type="text" name="name" />
   </p>
   <p>
      <input type="submit" value="Click Me!" onclick="skm_LockScreen('We are processing your request...');" />
   </p>

   <div id="skm_LockPane" class="LockOff"></div>
</body>
</html>