Sunday, May 1, 2011

Defining and Accessing Oracle Connection in app.cong

Step 1:- Add a app.conf file to your windows project.

a) To do this go to solution explorer, right click over the project sln to add a new item, a Add New Item Dialog box appear in fort of you.

b) from Add New Item Dialog box choose Application Configuration File.

Step 2:- In app.conf file define Oracle Connection.

Ex:-








Step 3:- Code for accessing this define connection string in .cs page.

Ex:-
using System.Data.OracleClient;
OracleConnection con = new OracleConnection ( System.Configuration. ConfigurationManager.AppSettings["OracleConnection"].ToString());

Saturday, January 8, 2011

JavaScript to Find Position of element in form

function findPosX(obj)
{
var curleft = 0;
if(obj.offsetParent)
while(1)
{
curleft += obj.offsetLeft;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
while(1)
{
curtop += obj.offsetTop;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.y)
curtop += obj.y;
return curtop;
}

Monday, January 3, 2011

Encryption and Decryption Function in JavaScript

function Decrypt(val)
{
val=unescape(val);
var len=val.length;
var newchar="";
var con=1;
var changer=10;
for(var i=0;i {
if(con%3==0)
changer=parseInt(changer)+2;
con++;
var ch=val.charCodeAt(i);
ch=parseInt(ch)-parseInt(changer);
newchar+=String.fromCharCode(ch);
}
return newchar;
}

function EncrptyData(Textval)
{
var a=Textval;
var newChar="";
var len=a.length;
var con=1;
var changer=10;
for(var k=0;k {
if(con%3==0)
changer=parseInt(changer)+2;
con++;
var ch=a.charCodeAt(k);
ch=parseInt(ch)+parseInt(changer);
newChar+=String.fromCharCode(ch);
}
return escape(newChar);
}

Javascript to add,delete and get browser cookie

//Javascript function to set browser Cookie at client side. The parameters are
c_name :- name of the cookie by which it is identified in browser.
value :- the value of the cookie to set in browser.
expiredays :- number of days to maintain the cookie in browser.

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

//Javascript function to get browser cookie at client side. The parameters are
c_name :- name of the cookie to get from browser.


function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1)
c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}

//Javascript funtion to delete browser cookie. The parameters are
cookie_name :- name of the cookie to be deleted from the browser.

function delete_cookie(cookie_name)
{
var cookie_date = new Date();
cookie_date.setTime(cookie_date.getTime()-1);
document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

Sunday, September 26, 2010

Detecting Tab Control on the textBox in window application in C#

private void Form1_Load(object sender, EventArgs e)
{
textBox1.Multiline = true;
}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
MessageBox.Show("Tab Key is Pressed");
}
}

Friday, May 14, 2010

Resolving Datagrid View Scroll Problem while calling in thread

datagridview1.scrollBars=ScrollBars.None;
datagridview1.scrollBars=ScrollBars.Both;

Adding Checkbox in Column Header of DataGridView in .net using C#

private void Form_Load(object sender, EventArgs e)
{
c1 = new DataGridViewCheckBoxColumn();
c1.Name = " selection";
c1.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
this.dataGridView1.Columns.Add(c1);

this.dataGridView1.Rows.Add();
this.dataGridView1.Rows.Add();
this.dataGridView1.Rows.Add();
this.dataGridView1.Rows.Add();

ckBox = new CheckBox();
//Get the column header cell bounds
Rectangle rect =
this.dataGridView1.GetCellDisplayRectangle(0, -1, true);
ckBox.Size = new Size(16, 16);
//Change the location of the CheckBox to make it stay on the header
ckBox.Location = rect.Location;
ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
//Add the CheckBox into the DataGridView
this.dataGridView1.Controls.Add(ckBox);
}

void ckBox_CheckedChanged(object sender, EventArgs e)
{
for (int j = 0; j < this.dataGridView1.RowCount; j++)
{
this.dataGridView1[0, j].Value = this.ckBox.Checked;
}
this.dataGridView1.EndEdit();
}