Thursday, May 29, 2008

Gridview- Pagging

--------------Step-1----------
Add Folowing code in .aspx page in asp:gridview paging templete
------------------------------


EnableViewState="false" Text="Previous" CommandName="page" CommandArgument="prev">

 | 
EnableViewState="false" Text="Next" CommandName="page" CommandArgument="next">

  
Text=' SSLib.GetPosition(gvOrderList)'>



-----------------------------------------------
---------------------step-2-------------------
in back-side-aspx.vb page add following
----------------------------------------------
Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
Dim Paging As New GridViewPaging
Paging.GridViewPaging(gvClientList)
End Sub
-------------------------------------------------
---------------------step-3------------------
-------------------------------------------
add following 2-class in project------------
-------------------------------------------
Class1=
-------
Public Class GridViewPaging
Function GridViewPaging(ByVal GridViewId As GridView) As Boolean
Dim pagetoprow As GridViewRow = GridViewId.TopPagerRow
Dim pagerbotomrow As GridViewRow = GridViewId.BottomPagerRow
If Not (IsNothing(pagerbotomrow)) Then
If (GridViewId.PageIndex) = 0 Then
CType(GridViewId.BottomPagerRow.FindControl("lbPrevious"), LinkButton).Enabled = False
CType(GridViewId.BottomPagerRow.FindControl("lbPrevious"), LinkButton).CssClass = "DisableLink"
End If
If (GridViewId.PageIndex + 1) = GridViewId.PageCount Then
CType(GridViewId.BottomPagerRow.FindControl("lbNext"), LinkButton).Enabled = False
CType(GridViewId.BottomPagerRow.FindControl("lbNext"), LinkButton).CssClass = "DisableLink"
End If
End If
If Not (IsNothing(pagetoprow)) Then
If (GridViewId.PageIndex) = 0 Then
CType(GridViewId.TopPagerRow.FindControl("lbPrevious"), LinkButton).Enabled = False
CType(GridViewId.TopPagerRow.FindControl("lbPrevious"), LinkButton).CssClass = "DisableLink"
End If
If (GridViewId.PageIndex + 1) = GridViewId.PageCount Then
CType(GridViewId.TopPagerRow.FindControl("lbNext"), LinkButton).Enabled = False
CType(GridViewId.TopPagerRow.FindControl("lbNext"), LinkButton).CssClass = "DisableLink"
End If
End If
End Function
---------------------------------------
------class2-----------
--------------------------------------
Public Shared Function GetPosition(ByVal gv As GridView) As String
Return "( " & (gv.PageIndex + 1).ToString & " of " & gv.PageCount & " )"
End Function

Public Shared Function GetPosition(ByVal fv As FormView) As String
Return "( " & (fv.PageIndex + 1).ToString & " of " & fv.PageCount & " )"
End Function

Public Shared Function GetPageIndex(ByVal idx As Integer) As Integer
Return idx + (CInt(HttpContext.Current.Request("Pg")) * 12)
End Function

Javascript-Auto call function

onLoad=window.setTimeout("StartText(25)",100);
var y
var timerID = 0;
function StartText(x)
{
document.getElementById ('AdOrCon').style .fontSize =x+"px";
if (x==40)
{y=1;}
else{
y=x+1;}
clearTimeout(timerID);
timerID=0;
timerID=setTimeout("StartText(y)",100);
}
function showTab(x)
{
document.getElementById('Div1').style.display="none";
document.getElementById('Div2').style.display="none";
document.getElementById('Div3').style.display="none";
document.getElementById('Div4').style.display="none";
document.getElementById('Div5').style.display="none";
document.getElementById('Div'+x).style.display="";
if (x==5)
{ y=1 ;}
else
{ y=x+1; }
clearTimeout(timerID);
timerID=0;
timerID = setTimeout("showTab(y)", 10000);

}

Javascript-window open

window.open(('ZoomImage.aspx?Categoryid=' + catid + '&pageIndex=' + curpg + '&RowPerPage=100&RowCnt=0&PgCnt=0&PgInfo=0'),'zoomimage','status=no,width=550,height=500, resizable= no, scrollbars=Yes, toolbar=no,location=no,menubar=no,left=200,top=20','');

Wednesday, May 21, 2008

Shopping Cart With Session

Imports System.Data
Partial Class ViewCart
Inherits System.Web.UI.Page
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow
Public Total As Decimal

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Session("StartCart") = Nothing Then
makeCart()
AddToCart(Nothing, Nothing)
GetItemTotal()
Else
objDT = Session("Cart")
Dim itemCount As String = objDT.Rows.Count
Dim sessICount() As String = Session.Item("Product").Split(",")
If itemCount <> sessICount.Length Then
'--------
Dim i As Integer = 0
For i = (itemCount) To sessICount.Length - 1
'Dim Product = a(i)
Dim adp_CartPrd As New ViewCartDsTableAdapters.Product_MasterTableAdapter
Dim tb_CartPrd As New ViewCartDs.Product_MasterDataTable
adp_CartPrd.FillProductByPId(tb_CartPrd, sessICount(i))
objDR = objDT.NewRow
objDR("Quantity") = 1
objDR("Image") = tb_CartPrd.Rows(0).Item("ProdImage")
objDR("Product") = tb_CartPrd.Rows(0).Item("ProdName")
objDR("Cost") = Decimal.Parse(123.5)
objDR("ProdId") = tb_CartPrd.Rows(0).Item("ProdId")
objDT.Rows.Add(objDR)
Session("Cart") = objDT
gvCart.DataSource = objDT
gvCart.DataBind()
GetItemTotal()
Next
'---------
Else
gvCart.DataSource = objDT
gvCart.DataBind()
GetItemTotal()
End If

End If
Else
Dim i As Integer
i = 0
makeCart()
For i = 0 To gvCart.Rows.Count - 1
Dim sess As String = Session("Product")
Dim a() As String = sess.Split(",")
Dim Product = a(i)
Dim adp_CartPrd As New ViewCartDsTableAdapters.Product_MasterTableAdapter
Dim tb_CartPrd As New ViewCartDs.Product_MasterDataTable
adp_CartPrd.FillProductByPId(tb_CartPrd, a(i))
objDR = objDT.NewRow
objDR("Quantity") = CType(gvCart.Rows(i).FindControl("textQuantity"), TextBox).Text
objDR("Image") = tb_CartPrd.Rows(0).Item("ProdImage")
objDR("Product") = tb_CartPrd.Rows(0).Item("ProdName")
objDR("Cost") = Decimal.Parse(123.5)
objDR("ProdId") = tb_CartPrd.Rows(0).Item("ProdId")
objDT.Rows.Add(objDR)
Next
Session("Cart") = objDT
gvCart.DataSource = objDT
gvCart.DataBind()
GetItemTotal()
End If
End Sub
Sub AddToCart(ByVal s As Object, ByVal e As EventArgs)
Dim sess As String = Session("Product")
Dim a() As String = sess.Split(",")
Dim i As Integer
i = 0
objDT = Session("Cart")
Session("StartCart") = "Start"
For i = 0 To a.Length - 1
Dim Product = a(i)
Dim adp_CartPrd As New ViewCartDsTableAdapters.Product_MasterTableAdapter
Dim tb_CartPrd As New ViewCartDs.Product_MasterDataTable
adp_CartPrd.FillProductByPId(tb_CartPrd, a(i))
objDR = objDT.NewRow
objDR("Quantity") = 1
objDR("Image") = tb_CartPrd.Rows(0).Item("ProdImage")
objDR("Product") = tb_CartPrd.Rows(0).Item("ProdName")
objDR("Cost") = Decimal.Parse(123.5)
objDR("ProdId") = tb_CartPrd.Rows(0).Item("ProdId")
objDT.Rows.Add(objDR)
Session("Cart") = objDT
gvCart.DataSource = objDT
gvCart.DataBind()
Next
End Sub
Function makeCart()
objDT = New System.Data.DataTable("Cart")
'objDT.Columns.Add("ID", GetType(Integer))
'objDT.Columns("ID").AutoIncrement = True
'objDT.Columns("ID").AutoIncrementSeed = 1
objDT.Columns.Add("ProdId", GetType(String))
objDT.Columns.Add("Image", GetType(String))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Cost", GetType(Decimal))
Session("Cart") = objDT
Return ""
End Function
Function GetItemTotal() As Decimal
Dim intCounter As Integer
Dim decRunningTotal As Decimal
For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("Cost") * objDR("Quantity"))
Next
Total = decRunningTotal
Return decRunningTotal
End Function

Friday, May 16, 2008

Auto Table hight/width increment

--

Image split in multiple part in asp.net

-------step-1------------
Put asp:button and file uploder tool in .aspx pages
-------Step-2------------
Importt two class in aspx.vb page
-------------------------
Imports System.Web.UI.WebControls.Unit
Imports System.Drawing

-------Step-3------------
Now On code behind on button click event write following
------------------------
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As Image
obj = Drawing.Image.FromFile("C:\Documents and Settings\user2\Desktop\1m.jpg")
SplitImage(obj, 3, 1)
' fun1(obj, 3)
End Sub
-------Step-4------------
Now On code behind on Call Function(SplitImage()) write following
-------------------------
Private Function SplitImage(ByVal wholeImage As Image, ByVal rows As Integer, ByVal columns As Integer) As Image()
Dim cellWidth As Single = CType(wholeImage.Width / columns, Single)
Dim cellHeight As Single = CType(wholeImage.Height / rows, Single)

' Create an array of RectangleF to hold the RectangleFs

' that define parts (cells) of the wholeImage.
Dim rectangleFs((rows * columns) - 1) As Drawing.RectangleF

' Fill RectangleFs array with RectangleF objects.
Dim currentRow As Single = 0

Dim currentColumn As Single = 0
Dim rectangleFIndex As Integer = 0

For currentRow = 0 To rows - 1
For currentColumn = 0 To columns - 1
Dim newRectangleF As New Drawing.RectangleF()

newRectangleF.X = currentColumn * cellWidth

newRectangleF.Y = currentRow * cellHeight

newRectangleF.Width = cellWidth

newRectangleF.Height = cellHeight

rectangleFs(rectangleFIndex) = newRectangleF

rectangleFIndex += 1

Next

Next

' Create an array of Images to contain the images

' that will be created from the wholeImage.
Dim images(rectangleFs.GetLength(0)) As Image

' Fill images array with Images.
Dim i As Integer = 0

For i = 0 To rectangleFs.GetUpperBound(0)
Dim newBitMap As New Drawing.Bitmap(CType(cellWidth, Integer), CType(cellHeight, Integer))
Dim bitMapGraphics As Drawing.Graphics = Graphics.FromImage(newBitMap)

bitMapGraphics.Clear(Color.Blue)

bitMapGraphics.DrawImage(wholeImage, newBitMap.GetBounds(GraphicsUnit.Pixel), rectangleFs(i), GraphicsUnit.Pixel)

images(i) = newBitMap

newBitMap.Save("C:\Documents and Settings\user2\Desktop\" + i.ToString() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

Next
Return images
End Function

Thursday, May 15, 2008

Crystal Report by specific id

------------1st-Step-----------
Put Crystal Report Page in Project
than add your Select Database column without any Filter(like query:select * from abc)
add column as you want
------------2nd-step-----------
Put on Page(.asp) with dropdown,crystal report viewer,with crystal report datasource
------------3rd-step----------
write following code in behind
------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim path As String = Server.MapPath("~\CrystalRepot\CrystalReportById.rpt")

Dim datatbl As New Data.DataTable
Dim constr As String = "Data Source=dynaserver\webdb;Initial Catalog=SuratShopping;User ID=sa;Password=saadmin"
Dim conn As SqlConnection = New SqlConnection(constr)
Dim adp As SqlDataAdapter
Dim ds As DataSet
conn.Open()
'Dim state As String = DropDownList1.SelectedValue
adp = New SqlDataAdapter("select * from CompanyImages where CompanyId='" & DropDownList1.SelectedValue & "' ", conn)
ds = New DataSet()
adp.Fill(ds, "CompanyImages")

rpt.Load(path)
CrystalReportSource1.DataBind()

CrystalReportViewer1.ReportSource = rpt
rpt.SetDataSource(ds.Tables("CompanyImages"))
End Sub

Create Thumbnail Image By File Uplod

Dim objImage, objThumbnail As System.Drawing.Image
Dim strServerPath, strFileName As String
Dim shtWidth, shtHeight As Short
'get image folder path on server
strServerPath = "C:\Documents and Settings\user2\Desktop\1m.jpg"
'retrive name of file to resize from query string
strFileName = "C:\Documents and Settings\user2\Desktop\1m.jpg"
'retrive file ,or error.gif if not available
Try
objImage = Drawing.Image.FromFile(strFileName)
Catch
objImage = Drawing.Image.FromFile(strServerPath)
End Try
'retrive width
shtWidth = 50
'work out a proportion height from widht
shtHeight = objImage.Height / (objImage.Width / shtWidth)
'Create Thumbnail
objThumbnail = objImage.GetThumbnailImage(shtWidth, shtHeight, Nothing, System.IntPtr.Zero)
'send down to client show image in browser
Response.ContentType = "image/Jpeg"
'objThumbnail.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
objThumbnail.Save("C:\Documents and Settings\user2\Desktop\" + "ddc.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
'Tidy up
objImage.Dispose()
objThumbnail.Dispose()

Tuesday, May 13, 2008

DataList Paging Store Procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[usp_GetCategoryProduct]

@CategoryId int,
@PageIndex int,
@RowsPerPage int,
@RowCount int OutPut,
@PageCount int Output,
@PageInfo varchar(250) Output

AS

Declare @StartRowIndex int;
Set @StartRowIndex = (@PageIndex * @RowsPerpage) + 1;

DECLARE @TempItems TABLE
(
ID int IDENTITY,
ProdId int
)

INSERT INTO @TempItems (ProdId)
SELECT Product_Master.ProdId
FROM Product_Master inner join companycategory
on product_master.prodcateid=companycategory.prodcateid
where categoryid=@Categoryid

Select @RowCount = count(*) from @TempItems;
Set @PageCount = @RowCount / @RowsPerPage;

if @PageIndex > @PageCount
raiserror ('Out of Page Index', 16,1) ;


Select @PageInfo =
'Showing ' +
ltrim(str(@startRowIndex)) + ' - ' +
case
when (@RowCount > (@startRowIndex + @RowsPerPage) - 1)
then ltrim(str(@startRowIndex + @RowsPerPage) - 1)
else
ltrim(str(@RowCount))
end
+ ' of ' +
ltrim(str(@RowCount));


Select *

FROM @TempItems t
Inner Join Product_Master ON Product_Master.ProdId = t.ProdId
Where t.ID between @startRowIndex AND (@startRowIndex + @RowsPerPage) - 1;

Monday, May 12, 2008

Auto Changed Image/Data

<%@ Page Language="VB" MasterPageFile="~/UserMaster.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Welcome To Surat Online Retail Store" %>






























Div1 Div2 Div3 Div4 Div5


Div1







Wednesday, May 7, 2008

Trigger

*************Insert Trigger*******************
USE [CustomerCare]
GO
/****** Object: Trigger [tri_ClientInqDtl] Script Date: 04/26/2008 12:06:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [tri_ClientInqDtl]
on [dbo].[ClientInqDtl]
AFTER INSERT
AS
Declare @ClientPrdId int,
@EmployeeId int,
@ClientInquiryDtl int

select @ClientInquiryDtl=ClientInquiryDtl from inserted
select @ClientPrdId=ClientPrdId from inserted
select @EmployeeId=EmployeeId from ClientPrdMaster where ClientPrdId=@ClientPrdId


BEGIN
Update ClientInqDtl set EmployeeId=@EmployeeId where ClientInquiryDtl=@ClientInquiryDtl
End
***************Delete Trigger*********************
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [tri_DeletePrdVersion]
ON [dbo].[ProductMaster]
AFTER DELETE
AS
Declare @ProductId int

select @ProductId=ProductId from Deleted
BEGIN
delete ProductVersion where Productid=@ProductId
END