My shared items

 

Monday, September 10, 2007

Embeding Images into Application in C#.

 

These Methods are used To Embed Images into Applications.......

///By Ramesh.R

private Bitmap EmbedImage(string imagePath)
{
try
{
return new Bitmap(typeof(Form1), imagePath);
}
catch (Exception ex)
{
throw ex;
}
}

///(or)


public static Bitmap EmbedImage1(string imagePath)
{
try
{
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream;
stream = null;
Bitmap bmp = null;
stream = assembly.GetManifestResourceStream(imagePath);
stream.Position = 0;
bmp = (Bitmap)Bitmap.FromStream(stream);
return bmp;
}
catch (Exception ex)
{
throw ex;
}
}


Here..,

imagePath --> Path where the Image Placed..

Both Methods returns a Bitmap instance of the Image.

For this Method to work make sure the Images Property

"BuildAction : Embedded Resource"

Saturday, September 8, 2007

Master Pages Demo






Master Page Design:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Master Pages Demotitle>
head>

<body leftmargin="0" topmargin="0" scroll="no">
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%">
<tr style="height: 3%">
<td valign="top" align="right" background="Images/banner.gif">
<table width="100%" style="text-align: right">
<tr>
<td width="38%" valign="bottom">
td>
<td valign="bottom" align="right">

<%--Script_Menu--%>

td>
tr>
table>
td>
tr>
<tr height="97%">
<td align="center">
<table width="99%" height="100%">
<tr style="height: 3%">
<td align="left" bgcolor="#BDB14B" valign="top" style="font: Bold; font-family: Verdana;">

<asp:Label ID="Label1" runat="server" Text="">asp:Label>
td>
tr>
<tr style="height: 94%">
<td>
<asp:ContentPlaceHolder ID="ScreenContent" runat="server">
asp:ContentPlaceHolder>
<asp:Label ID="Label2" runat="server" Text="">asp:Label>
<asp:Label ID="Label3" runat="server" Text="">asp:Label>
td>
tr>
<tr style="height: 3%" bgcolor="#BDB14B">
<td align="center" style="font-family: Verdana; font-size: 12;">
CopyRights

td>
tr>
table>
td>
tr>
table>
div>
form>
body>
html>



Master Page Code-Behind File:

public partial class MasterPage : System.Web.UI.MasterPage
{
string pageHeadingTitle = "Header";

///
/// Property return a string
///
public string PageHeadingTitle
{
get
{
return pageHeadingTitle;
}
set
{
pageHeadingTitle = value;
}
}

///
/// Property returns a Label Object
///
public Label MasterPageLabel
{
get
{
return Label2;
}
set
{
Label2 = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Label1.Text = PageHeadingTitle;
}
}
}

Content Page Design:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Default1" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ScreenContent" Runat="Server">
asp:Content>



Content Page Code Behind File:

///Using FindControl()
this.MasterPageFile = "MasterPage.master";
MasterPage mp = (MasterPage)this.Master;

Label lbl = mp.FindControl("Label2") as Label;
if (lbl != null)
lbl.Text = "Label2";

///(Or)

(Master.FindControl("Label3") as Label).Text = "Label3";

///Using Properties Or Controls in Master Page
Master.PageHeadingTitle = "Content Page Header";
Master.MasterPageLabel.Font.Size = 25;
Master.MasterPageLabel.Text = "Label2";



Saturday, September 1, 2007

How to Get AM PM Formatted DateTime in SQL Server

The Following Function is used to Gets the AM Or PM Formatted DateTime for the Given Date


CREATE FUNCTION GetAMPMFormat(@inputDate DATETIME)
RETURNS char(25)
AS
BEGIN

DECLARE @time varchar(5)
SET @time = CONVERT(char(10), @inputDate, 108)

DECLARE @date varchar(10)
SET @date = CONVERT(char(10), @inputDate, 101)

DECLARE @hour varchar(2)
DECLARE @minute varchar(2)

SET @hour = LEFT(@time,2)
SET @minute = SUBSTRING(@time,4,2)

DECLARE @amOrPm char(2)
SET @amOrPm = 'AM'

IF CAST(@hour as int) = 0 BEGIN
SET @hour = 12
SET @amOrPm = 'AM'
END

ELSE IF CAST(@hour as int) = 12 BEGIN
SET @amOrPm = 'PM'
END

ELSE IF CAST(@hour as int) > 12 BEGIN
SET @hour = @hour - 12
SET @amOrPm = 'PM'
END

DECLARE @outputDate char(25)
SET @outputDate = @date + ' ' + @hour + ':' + @minute + ' ' + @amOrPm

RETURN @outputDate
END


For Example you maye use like

PRINT dbo.GetAMPMFormattedDateTime('01-08-2007 20:10')

it will prints
01/08/2007 8:10 PM

SQL Server DateTime Related...

CONVERT

CONVERT function explicitly converts an expression of one data type to another. CAST and CONVERT provide similar functionality.

Syntax

CAST ( expression AS data_type )

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

Arguments

expression

Is any valid Microsoft SQL Server expression.

data_type

Is the target system-supplied data type, including bigint and sql_variant. User-defined data types cannot be used.

length

Is an optional parameter of nchar, nvarchar, char, varchar, binary, or varbinary data types.

style

Is the style of date format used to convert datetime or smalldatetime data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types), or the string format when converting float, real, money, or smallmoney data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types).


yy yyyy
Standard

Input/Output
- 0 or 100
Default mon dd yyyy hh:miAM (or PM)
1 101 USA mm/dd/yy
2 102 ANSI yy.mm.dd
3 103 British/French dd/mm/yy
4 104 German dd.mm.yy
5 105 Italian dd-mm-yy
6 106 - dd mon yy
7 107 - Mon dd, yy
8 108 - hh:mm:ss
- 9 or 109
Default + milliseconds mon dd yyyy hh:mi:ss:mmmAM (or PM)
10 110 USA mm-dd-yy
11 111 JAPAN yy/mm/dd
12 112 ISO yymmdd
- 13 or 113
Europe default + milliseconds dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 or 120
ODBC canonical yyyy-mm-dd hh:mi:ss(24h)
- 21 or 121
ODBC canonical (with milliseconds) yyyy-mm-dd hh:mi:ss.mmm(24h)
- 126 ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(no spaces)
- 130 Kuwaiti dd mon yyyy hh:mi:ss:mmmAM
- 131 Kuwaiti dd/mm/yy hh:mi:ss:mmmAM

Some Other Date Related Functions...

Dateadd: Returns a new datetime value based on adding an interval to the specified date.

Syntax: DATEADD ( datepart, number, date )

Datediff: Returns the number of date and time boundaries crossed between two specified dates.

Syntax: DATEDIFF ( datepart, startdate, enddate )

Datename: Returns a character string representing the specified datepart of the specified date.

Syntax: DATENAME ( datepart, date )

Datepart: Returns an integer representing the specified datepart of the specified date.

Syntax: DATEPART ( datepart, date )

Day: Returns an integer representing the day datepart of the specified date.

Syntax: DAY ( date )

Getdate: Returns the current system date and time in the Microsoft® SQL Server™ standard internal format for datetime values.

Syntax: GETDATE ( )

Month: Returns an integer that represents the month part of a specified date.

Syntax: MONTH ( date )

Year: Returns an integer that represents the year part of a specified date.

Syntax: YEAR ( date )

Here,

datepart--> may be mm, dd, yy, yyyy, mi..etc...


Example:


PRINT DATEADD ( dd, 60, 'Sep 1 2007 10:46AM')


will prints
Oct 31 2007 10:46AM