Sunday, April 29, 2012

VB.NET Oracle Call Function with Parameters

WHEN we need to call Oracle Database Function from vb.net Code Using System.Data.Oracle Client we will need to Pass Function Parameters and receive Function Return Value

so this action Can be Handled by the following Code Sample
NOTE: I have db function called ENCRYPT_STR S have two input arguments and one output return value so , i declared Oracle Command and define it's type as Stored Procedure and pass command text as SchemaName.FunctionName
then deal with command to add parameters and receive Return value and return it after .
    Public Function EncriptLoginData(ByVal username As String, ByVal EncKey As String) As String
        Dim Result_Encripted As String = String.Empty
                    'define Oracle Command
        Dim cmd As New Data.OracleClient.OracleCommand
        cmd.CommandType = Data.CommandType.StoredProcedure
        cmd.CommandText = "MAIN.ENCRYPT_STR"
        cmd.Connection = OConn
        OConn.ConnectionString = ConnString
        If OConn.State <> ConnectionState.Open Then OConn.Open()
        With cmd
            .Parameters.Add("var1", OracleType.VarChar, 100).Direction = ParameterDirection.Input
            .Parameters.Add("p_key", OracleType.VarChar, 100).Direction = ParameterDirection.Input
            .Parameters.Add("encUserName", OracleType.VarChar, 4000).Direction = ParameterDirection.ReturnValue
            .Parameters("var1").Value = username
            .Parameters("p_key").Value = EncKey

        End With
        cmd.ExecuteScalar()
        Result_Encripted = cmd.Parameters("encUserName").Value.ToString()
        cmd.Dispose()
        OConn.Close()
        OConn.Dispose()
        Return Result_Encripted
    End Function

Saturday, April 28, 2012

get Client Ip Address Using Asp.net c#

to get Client Ip address use the following code
 if (Context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy
                            {
                                                              Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();  // Return real client IP.
                            }
                            else// not using proxy or can't get the Client IP
                            {
                                Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.
                            }

Tuesday, April 24, 2012

flexigrid-1.1 fix Html table Using Jquery

flexigrid-1.1 is very nice javascript and css Library to fix Html table sorting drag and drop view and hide table column

Link for Download files.

http://code.google.com/p/flexigrid/downloads/list

C++ program to rotate and capitalize sentences.

The program will start by asking the user to enter a multi-word sentence. The program will then the
program will rotate the sentence and print out the rotated sentence. Moreover, the first letter of each word of sentence must be capitalized. All other words must be in lower case.

#include "stdafx.h"
#include <iostream>
#include "conio.h"
#include "vector"
#include <sstream>

using namespace std;

int _tmain(int argc)
{
      char sentence[1000];
    bool cap_it = true;
    cout << "enter your sentence.\n";
    cin.getline(sentence, 1000);
    for (int i = 0; i < strlen(sentence); i++)
    {
        if (isalpha(sentence[i]) && cap_it == true)
        {
            sentence[i] = toupper(sentence[i]);
            cap_it = false;
        }
        else
            if (isspace (sentence[i]))
                cap_it = true;
    }

    cout << endl <<  endl;

     istringstream converter(sentence);

    vector<string> words((istream_iterator<string>(converter)),  istream_iterator<string>());

    copy(words.rbegin(), words.rend(), ostream_iterator<string>(cout, " "));
  getch();

    return 0;
}

c++ calculate the hypotenuse of a right angle triangle

A program to calculate the hypotenuse of a right angle triangle.Your program will ask the user for the lengths of the two  sides adjacent to the right angle. It will then calculate the  hypotenuse and print the result along with the input out to screen.

Solution:
#include "stdafx.h"
#include <iostream>
#include <string>
#include "math.h"
#include "conio.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    //A program to calculate the hypotenuse of a right angle triangle

        double a,b,Result;

   
        cout<<"enter the first length side "<<endl;;
        cin>>a;

        cout<<"enter the second length side " <<endl;
        cin>>b;
        Result =  sqrt((a*a)+(b*b));

        cout<<"the result of the hypotenuse  == " << Result;
    getch();
   
 return 0;

}

C++ Compute Average of two Numbers (Average Program)

The Program Compute Average for Two Numbers Entered by User

#include "stdafx.h"
#include <iostream>
#include "conio.h"
#include "vector"
#include <sstream>
using namespace std;

int _tmain(int argc)
{
    string str ;
    vector<int> vect;


     cout<<"enter the string of numbers"<<endl;
     cin >> str ;
    stringstream ss(str);
int i;
double sum = 0 ;
while (ss >> i)
{
        vect.push_back(i);

        if (ss.peek() == ',')
                ss.ignore();
}
 vector< int >::const_iterator constIterator;

   // display vector elements using const_iterator
   for ( constIterator = vect.begin();constIterator != vect.end(); ++constIterator )
   {
       sum=sum+*constIterator;
   }
   cout<<"Numbers  Sum  =  " << sum  <<endl;
   cout<<"Numbers Count   =  " << vect.size()  <<endl;
   cout<<"Numbers  Average  =  " << sum/vect.size()  <<endl;
   cout << endl;
getch();
    return 0;
}

C++ Swap Two Numbers Using Pointer

this Program to swap Two Numbers Using Pointer



#include "stdafx.h"
# include <iostream>
using namespace std;
void p_swap(int *pNum1, int *pNum2);
int main(void)
{
int num1=0, num2=0;
cout << "Enter two numbers to swap between them: " << endl << "Number (1): ";

cin >> num1;
cout << "Number (2): ";
cin >> num2;
     p_swap(&num1, &num2 );    //pass the addresses
     cout<< endl<< "After the swap, number1 is " << num1 << endl<< " number2 is " << num2 << "."<< endl;
system ("pause");
     return 0;
}

//-------------- Function to reverse two values
void p_swap(int *pNum1, int *pNum2)    // receiving addresses not values
{
     int temp;    // temporary holding variable

     temp = *pNum1;    // swap the values stored at the addresses
     *pNum1 = *pNum2;
     *pNum2 = temp;

     return;     // main( )'s variables, not copies of them, have been changed


C++ program to return input string length

the code receive line from user and print out his line characters count