ali raza

C#, .Net ,Asp.net and my thoughts

Monthly Archives: October 2008

how to get oracle sequence numbers in .net

hi the main Query to get sequence number is follow


select JOB_ID_SEQ.NEXTVAL from dual;

i get the required Sequence number value form following method

public int GetOracleSequenceValue(string _SequenceValue)
{
OdbcCommand _command = new OdbcCommand();
int _ItemValue = -1;
OdbcConnection _con = new OdbcConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["RCConnectionString"].ToString());
try
{
_con.Open();
_command.Connection = _con;
string _QueryString = "select "+ _SequenceValue +" from dual ";
_command.CommandText = _QueryString;
_ItemValue = Convert.ToInt32(_command.ExecuteScalar().ToString());
_con.Close();
}
catch (Exception ex)
{
Util.LogErrorToFile(ex, "MYExecuteNonQuery", "error");
}
finally
{
_con.Close();
}
return _ItemValue;
}

Chears

regular expression for email address validation

hi use this regular expression for email address validation
^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$

Regular expression validator in asp.net would be like

Chears…

Main hoon naa

How to resize image in .net

use follwing Code change image path at load event method for downloading Code

Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim WorkingDirectory As String = "c:\AliPicture"

'create a image object containing a verticel photograph
Dim imgPhotoVert As Image = Image.FromFile(WorkingDirectory + "\pravs-j-the-first-step.jpg")
Dim imgPhoto As Image = Nothing
imgPhoto = FixedSize(imgPhotoVert, 100, 100)
imgPhoto.Save(WorkingDirectory + "\imageresize_3.jpg", ImageFormat.Jpeg)
imgPhoto.Dispose()

End Sub

Private Shared Function FixedSize(ByVal imgPhoto As Image, ByVal Width As Integer, ByVal Height As Integer) As Image
Dim sourceWidth As Integer = imgPhoto.Width
Dim sourceHeight As Integer = imgPhoto.Height
Dim sourceX As Integer = 0
Dim sourceY As Integer = 0
Dim destX As Integer = 0
Dim destY As Integer = 0

Dim nPercent As Single = 0
Dim nPercentW As Single = 0
Dim nPercentH As Single = 0

nPercentW = (CSng(Width) / CSng(sourceWidth))
nPercentH = (CSng(Height) / CSng(sourceHeight))

'if we have to pad the height pad both the top and the bottom
'with the difference between the scaled height and the desired height
If nPercentH < nPercentW Then
nPercent = nPercentH
destX = CInt(((Width - (sourceWidth * nPercent)) / 2))
Else
nPercent = nPercentW
destY = CInt(((Height - (sourceHeight * nPercent)) / 2))
End If

Dim destWidth As Integer = CInt((sourceWidth * nPercent))
Dim destHeight As Integer = CInt((sourceHeight * nPercent))

Dim bmPhoto As New Bitmap(Width, Height, PixelFormat.Format24bppRgb)
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)

Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
grPhoto.Clear(Color.Red)
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic

grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)

grPhoto.Dispose()
Return bmPhoto
End Function

End Class

Pl Sql Built in Functions

hi find these build in function for orcale pl sql , These are really usefull

Function Description
String Functions
upper(s), lower(s) convert string s to upper/lower-case
initcap(s) capitalise first letter of each word
ltrim(s), rtrim(s) remove blank char. from left/right
substr(s,start,len) sub-string of length len from positionstart
length(s) length of s
Date Functions
sysdate current date (on Oracle server)
to_date(date, format) date formatting
Number Functions
round(x) round real number x to integer
mod(n,p) n modulus p
abs(x) absolute value of x
dbms_random.random() generate a random integer
Type Conversion Functions
to_char() convert to string
to_date() convert to date
to_number() convert to number
Miscellaneous Functions
user current Oracle user

Composition and Aggregation in oops

Composition and Aggregation are basically whole/part relationship.

When the lifetime of the part is dependent on or controlled by the whole, the relationship between the whole and part is Composition. 
Which simply means that the part is no more existing when the whole is destroyed.

example : car and engine.
Aggregation : 
When the lifetime of the part is not dependent on or not controlled by the whole, the relationship between the whole and part is Aggregation. 
Which simply means that the part continues to exist when the whole is destroyed.

example : car and stereo

So this typically it means that the part should be shared across multiple objects.
So if one object is destroyed , still the part is continued to be used by other objects
Association : 
Association is simply “uses” relation ship .
It is achieved by simple references in Java.

Point to note is that Aggregation is a special case of Association . OR other way to say is that Aggregation can be achieved by using Association.