Thursday, April 17, 2008

Hot To Set Property in User-Control

-------Back-End Code-----------

Partial Class UserControls_CompanyDetail
Inherits System.Web.UI.UserControl
Private _CompanyId As Integer = 0

Public Property CompanyId() As Integer
Get
Return _CompanyId
End Get
Set(ByVal value As Integer)
_CompanyId = value
DataSrcCompanyDetail.SelectParameters("Cid").DefaultValue = value
frmCompDetails.DataBind()
End Set
End Property

End Class
-----------------------------------
------Source-Code-----------------
----------------------------------
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="CompanyDetail.ascx.vb"
Inherits="UserControls_CompanyDetail" %>





DataKeyNames="CompanyId" DataSourceID="DataSrcCompanyDetail"
CellPadding="0" Width="100%" HorizontalAlign="Center" EnableViewState="false">























































<%# Eval("CompName") %>

Address:

<%# EVal("CompAddress") %>
,
<%# Eval("AreaName") %>


<%# EVal("CompCity") %>
-
<%# EVal("CompPin") %>


<%# EVal("CompState") %>

 

Telephone:

<%#Eval("CompTelNo")%>

Fax:

<%#Eval("CompFax")%>

E-mail:

<%#Eval("CompEmail")%>

 

Key Person:

<%#Eval("ContactPerson")%>

Mobile No

<%#Eval("MobileNo")%>

 

Keywords:

<%#Eval("Keywords")%>

 

Description:

<%#Eval("BriefInfo")%>




SelectMethod="GetCompanyById" TypeName="MainDatasetTableAdapters.CompanyDetailTableAdapter" EnableViewState="false">




Calender Popup Calender

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="DateUserControl.ascx.vb"
Inherits="UserControls_DateUserControl" %>









onclientClick="javascript:GetDate1('<%=txtDate.ClientId%>'




ControlToValidate="txtDate" CssClass="ErrorMessage" EnableViewState="False" Display="Dynamic">
ErrorMessage="Date not valid" Display ="Dynamic" ValidationExpression ="^((((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9]))))[\-\/\s]?\d{2}(([02468][048])|([13579][26])))|(((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))[\-\/\s]?\d{2}(([02468][1235679])|([13579][01345789]))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$">

Feed Reader/Rss Reader

Step.1:.....Path Of Rss
Private Sub ReadNews()
Dim rd As New FeedReader("http://news.google.co.in/news?hl=en&ned=in&q=surat&ie=UTF-8&as_drrb=q&as_qdr=w&as_mind=14&as_minm=11&as_maxd=21&as_maxm=11&output=rss")
'Dim rd As New FeedReader("http://www.easy-indian-food.com/Indian-cooking.xml")
'Dim rd As New FeedReader("http://content.msn.co.in/rsscache/healthfitness.rss")
DataList1.DataSource = rd.GetDataTable
DataList1.DataBind()
End Sub
--------------------------
Step.2:.....Class1
-------------------------
Imports Microsoft.VisualBasic

Public Class FeedReader
Private mvarTable As Data.DataTable
Private mvarObjColl As FeedCollection
Private mvarSourceFile As String

Sub New()
mvarObjColl = New FeedCollection
End Sub

Sub New(ByVal SourceFile As String)
Me.New()
ReadFile(SourceFile)
End Sub

Public Overloads Sub ReadFile(ByRef SourceFile As String)
mvarSourceFile = SourceFile
ReadFile()
End Sub

Public Overloads Sub ReadFile()
Dim _TmpDS As New Data.DataSet
'If System.IO.File.Exists(SourceFile) Then
_TmpDS.ReadXml(mvarSourceFile)
If Not (_TmpDS.Tables("item") Is Nothing) Then
mvarTable = _TmpDS.Tables("item")
End If
_TmpDS = Nothing
PopulateCollection()
'End If
End Sub

Private Sub PopulateCollection()
mvarObjColl.clear()
For Each _TmpRow As Data.DataRow In mvarTable.Rows
mvarObjColl.Add(New Feed(_TmpRow("title").ToString(), _TmpRow("link").ToString(), _TmpRow("pubDate").ToString, _TmpRow("description").ToString()))
Next
End Sub

Public Function GetDataTable() As Data.DataTable
Return mvarTable
End Function

Public ReadOnly Property Items() As FeedCollection
Get
Return mvarObjColl
End Get
End Property

Public Property SourceFile() As String
Get
Return mvarSourceFile
End Get
Set(ByVal value As String)
mvarSourceFile = value
End Set
End Property
End Class
---------------------------
Step.3: class2
---------------------------
Imports Microsoft.VisualBasic

Public Class FeedCollection
Private mvarObjCollection As Collection

Public Sub New()
mvarObjCollection = New Collection
End Sub

Public Overloads Sub Add(ByRef Value As Feed)
mvarObjCollection.Add(Value)
End Sub

Public ReadOnly Property Count() As Integer
Get
Return mvarObjCollection.Count
End Get
End Property

Public Sub Remove(ByVal IndexNo As Integer)
mvarObjCollection.Remove(IndexNo)
End Sub

Public ReadOnly Property Item(ByVal IndexNo As Integer) As Feed
Get
Return CType(mvarObjCollection(IndexNo), Feed)
End Get
End Property

Public Sub Clear()
mvarObjCollection.Clear()
End Sub
End Class
---------------------------------
step:3:Class 3
---------------------------------
Imports Microsoft.VisualBasic

Public Class Feed
Private mvarTitle As String
Private mvarLinkURL As String
Private mvarTime As String
Private mvarContent As String

Sub New(ByVal valTitle As String, ByVal valLinkURL As String, ByVal valPublishTime As String, ByVal valContent As String)
mvarTitle = valTitle
mvarLinkURL = valLinkURL
mvarTime = valPublishTime
mvarContent = valContent
End Sub

Public Property Title() As String
Get
Return mvarTitle
End Get
Set(ByVal value As String)
mvarTitle = value
End Set
End Property

Public Property LinkURL() As String
Get
Return mvarlinkURL
End Get
Set(ByVal value As String)
mvarlinkURL = value
End Set
End Property

Public Property PublishTime() As String
Get
Return mvarTime
End Get
Set(ByVal value As String)
mvarTime = value
End Set
End Property
Public Property Content() As String
Get
Return mvarContent
End Get
Set(ByVal value As String)
mvarContent = value
End Set
End Property
End Class

SendMail Class

Public Class SendEmail

Public Sub SendEmails(ByVal strFromAdd As String, ByVal strToAdd As String, ByVal strMessage As String, ByVal strSubject As String)
Dim sendMail As New MailMessage
sendMail.IsBodyHtml = True
sendMail.Subject = strSubject
sendMail.To.Add(strToAdd)
sendMail.From = New MailAddress(strFromAdd)
sendMail.Body = strMessage
Dim clent As New SmtpClient
clent.Host = "suratshopping.com"
'clent.Send(sendMail)
End Sub
End Class

Create Thumbnail Image

Imports Microsoft.VisualBasic
Imports System.Drawing
Imports System.Drawing.Imaging

Public Class ThumbnailCreator

Public Shared Function CreateThumbnail(ByVal lcFilename As String, ByVal lnWidth As Integer, ByVal lnHeight As Integer) As Bitmap

Dim bmpOut As System.Drawing.Bitmap = Nothing
Try

Dim loBMP As New Bitmap(lcFilename)

Dim loFormat As ImageFormat = loBMP.RawFormat

Dim lnRatio As Decimal

Dim lnNewWidth As Integer = 0

Dim lnNewHeight As Integer = 0

'If the image is smaller than a thumbnail just return it

If (loBMP.Width < lnWidth And loBMP.Height < lnHeight) Then
Return loBMP
End If

If (loBMP.Width > loBMP.Height) Then
lnRatio = CType((lnWidth / loBMP.Width), Decimal)
lnNewWidth = lnWidth

Dim lnTemp As Decimal = loBMP.Height * lnRatio
lnNewHeight = CInt(lnTemp)
Else
lnRatio = CType((lnHeight / loBMP.Height), Decimal)

lnNewHeight = lnHeight

Dim lnTemp As Decimal = loBMP.Width * lnRatio
lnNewWidth = CInt(lnTemp)
End If

bmpOut = New Bitmap(lnNewWidth, lnNewHeight)

Dim g As Graphics = Graphics.FromImage(bmpOut)

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight)

g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight)

loBMP.Dispose()


Catch
Return Nothing
End Try
Return bmpOut
End Function


End Class

Check Image Resolution In Asp.net

Imports Microsoft.VisualBasic
Public Class CheckImage
Public Function CheckImage(ByVal File As FileUpload, ByVal Size As Integer, ByVal width As Integer, ByVal Height As Integer, ByVal ImgOf As String) As Boolean
Dim sizes As String = File.PostedFile.ContentLength
Dim sizeKb As String = sizes / 1024
If ImgOf <> "Advertise" Then
Dim uploadimage As System.Drawing.Image = System.Drawing.Image.FromStream(File.PostedFile.InputStream)
Dim uploadimagewidth As String = uploadimage.PhysicalDimension.Width
Dim uploadimageheight As String = uploadimage.PhysicalDimension.Height
If ImgOf = "ShopImage" Then
If sizeKb <= Size And uploadimagewidth <= width And uploadimageheight <= Height Then
Return True
Else
Return False
End If
ElseIf ImgOf = "ProductImg" Then
If sizeKb <= Size And uploadimageheight <= Height Then
Return True
Else
Return False
End If
ElseIf ImgOf = "offer" Then
If sizeKb <= Size And uploadimagewidth <= width And uploadimageheight <= Height Then
Return True
Else
Return False
End If
End If
ElseIf ImgOf = "Advertise" Then
Return True
End If
End Function
End Class

Image store to Web-Folder Class

Imports Microsoft.VisualBasic
Public Class StoreToFolder
Function WebFolderImg(ByVal FileUploadId As FileUpload, ByVal FolderName As String, ByVal FileName As String, ByVal Operation As String) As String
If Operation = "Insert" Then
Dim NewFileName As String = ""
Dim File As String = System.IO.Path.GetFileName((FileUploadId).PostedFile.FileName)
Dim extension As String = System.IO.Path.GetExtension((FileUploadId).PostedFile.FileName)
'*** Add File To Web-Folder
NewFileName = Format(Now(), "ddMMyyHHmmss") + extension
Dim Path As String
Path = HttpContext.Current.Server.MapPath("..\" + FolderName + "\") + NewFileName
FileUploadId.SaveAs(Path)
Return NewFileName
ElseIf Operation = "InsertProduct" Then
Dim NewFileName As String = ""
Dim File As String = System.IO.Path.GetFileName((FileUploadId).PostedFile.FileName)
Dim extension As String = System.IO.Path.GetExtension((FileUploadId).PostedFile.FileName)
'*** Add File To Web-Folder
NewFileName = FileName + Format(Now(), "ddMMyyHHmmss") + extension
Dim Path As String
Path = HttpContext.Current.Server.MapPath("..\" + FolderName + "\") + NewFileName
FileUploadId.SaveAs(Path)
Return NewFileName
ElseIf Operation = "Delete" Then
Dim DeletedFile As String = HttpContext.Current.Server.MapPath("..\" + FolderName + "\" + FileName)
System.IO.File.Delete(DeletedFile)
End If
Return ""
End Function
End Class

Select Insert Update Delete By Store Procedurr

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER PROCEDURE [dbo].[MyStoreProcedure]
-- Add the parameters for the stored procedure here
--<@Param1, sysname, @p1> = ,
--<@Param2, sysname, @p2> =
@Operation int,
@Parameter varchar(2),
@Uname varchar(10) ,
@Passoword int,
@RegisterStatus int,
@RegisterStatus1 int
AS
BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
if @Operation=1
begin
Select * from ddc order by Uname
end
if @Operation=2
-- Insert statements for procedure here
begin
insert into ddc ([Uname],[Passoword],[RegisterStatus],[RegisterStatus1])values(@Uname,@Passoword,@RegisterStatus,@RegisterStatus1)
end
if @Operation=3
begin
delete from ddc where Uname=@Uname
end
if @Operation=4
begin
Update [ddc] set [Uname]=@Uname,[Passoword]=@Passoword,[RegisterStatus]=@RegisterStatus,[RegisterStatus1]=@RegisterStatus where ([Uname]=@Uname)
end
END

Get 3-table data without Inner-Join

select AdvertisementMst.*,AdPosition.PageId,AdPosition.Position,PageMaser.PageName
from AdvertisementMst,AdPosition,PageMaser
where AdvertisementMst.AdPositionId=AdPosition.AdPositionId and
AdvertisementMst.AdvertisementMstId=@AdvertisementMstId

My Sql ServerQuery

--BetweenStatment
select CompName,OfferValidity from CompanyMaster where Offervalidity between '04/19/2008' and '04/21/2008' order by compname
--DistinceStatement
select distinct offerValidity from CompanyMaster
select AdvertisementMst.*,AdPosition.PageId,Adposition.Position,PageMaser.PageName
from AdvertisementMst,AdPosition,PageMaser
where AdvertisementMst.AdvertisementMstId=AdPosition.AdPositionId
--In StateMent
select * from CompanyMaster Where CompName In('2Much','Dhaval Super Store')
--LikeOrSearchKeyWord StateMent
select * from CompanyMaster where CompName like ('%2Much%')
--SoundEx Search StateMent
select * from CompanyMaster Where SoundEx(compname)= soundex('2Much')
--OrderBy Statement
--Assending Order
select * from CompanyMaster order by CompName asc
--Desending Order
select * from CompanyMaster order by CompName desc
--Count statement with Join Statement
select count(ProductMaster.ProductId) TotalProduct ,CompanyMaster.CompName from CompanyMaster,ProductMaster where CompanyMaster.companyId=35 and CompanyMaster.CompanyId=ProductMaster.Companyid group by CompanyMaster.CompName
--Alias StateMent
select tbl .CompName from CompanyMaster tbl
--Outer Join State ment
SELECT A1.store_name, SUM(A2.Sales) SALES
FROM Geography A1, Store_Information A2
WHERE A1.store_name = A2.store_name (+)
GROUP BY A1.store_name
--Concate Statement :Get Two ColumnData In On Column
select CompCity+''+CompName companyNameWithCity from CompanyMaster
--SubString Statement:Get Data of column with Specific Char limit
select Substring(CompName,1,3) CompPrefix from companyMaster
--Create View Statement: Get Data of Two Table in diffrent Column
create view Company_Product as select count(productMaster.ProductId) ProductCount,companyMaster.Compname CompanyName from companymaster,productmaster where companymaster.companyId=productmaster.companyId group by companymaster.compname
--Create index statement:
create index CompanyIndex on companyMaster(Compname,CompanyId)
--Alter Table
ALTER table customer add Gender char(1)
--Drop Table
DROP TABLE customer
--Truncat Table(Data only deleted from table
TRUNCATE TABLE customer
--Update statement
UPDATE Store_Information
SET Sales = 500
WHERE store_name = "Los Angeles"
AND Date = "Jan-08-1999"
--Delete statement
DELETE FROM Store_Information
WHERE store_name = "Los Angeles"

Regulare Expression For Calender(2001-2099)

runat ="server"
ControlToValidate ="txtDate"
SetFocusOnError ="true"
ErrorMessage="Date not Valid"
Display ="Dynamic"
ValidationExpression ="^((((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9]))))[\-\/\s]?\d{2}(([02468][048])|([13579][26])))|(((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))[\-\/\s]?\d{2}(([02468][1235679])|([13579][01345789]))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$">