Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports ModCommon

Partial Class ProductImageWindow
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not IsPostBack Then
                If Request.QueryString("StID") <> Nothing Then
                    Session("ProductCode") = Request.QueryString("StID").ToString
                End If

                Dim imgPath As String
                con.Close()
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                Dim dt As DataTable = ReturnDataTable("SELECT     Product_Master.Product_Image, Product_Master.Product_Name, Product_Master.Product_ModelNo, Category_Master.Category_Name FROM    Product_Master INNER JOIN  Category_Master ON Product_Master.Product_CategoryId = Category_Master.Category_Kid where product_kid='" & Session("ProductCode").ToString & "'")
                con.Open()
                If dt.Rows.Count > 0 Then
                    Dim img2 As Image = Nothing
                    If Session("strmain") = "bearings" Then
                        img1.ImageUrl = ResolveUrl("~/Upload Image/Bearings/") & dt.Rows(0).Item("Category_Name").ToString.ToLower.Replace(" ", "-") & ".jpg"
                        imgPath = ResolveUrl(Server.MapPath("~/Upload Image/Bearings/" & dt.Rows(0).Item("Category_Name").ToString.ToLower.Replace(" ", "-") & ".jpg"))
                    Else
                        img1.ImageUrl = "~/Upload Image/Product Image/UploadImages/" & dt.Rows(0).Item("Product_Image").ToString
                        imgPath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.Rows(0).Item("Product_Image").ToString)
                    End If


                    img2 = System.Drawing.Image.FromFile(imgPath)
                    Dim x As Long = img2.Width
                    Dim y As Long = img2.Height

                    If x > 550 And y > 450 Then
                        KeepAspectRatioNew(img1, imgPath, 550, 450)
                    ElseIf (x > 550 Or x < 300) And (y > 450 Or y < 200) Then
                        KeepAspectRatioNew(img1, imgPath, 450, 350)
                    ElseIf (x >= 300 Or x <= 100) And (y >= 250 Or y <= 100) Then
                        KeepAspectRatioNew(img1, imgPath, 400, 400)
                    Else                   'If (x > 450 Or x < 150) And (y > 350 Or y < 100) Then
                        KeepAspectRatioNew(img1, imgPath, 450, 450)
                    End If

                    lblprdname.Text = "<b>Product : </b>" & dt.Rows(0).Item("Product_Name").ToString
                    lblprdmno.Text = "<b>Model No. : </b>" & dt.Rows(0).Item("Product_ModelNo").ToString
                    'Dim imgs As Drawing.Image = Drawing.Image.FromStream(New System.IO.MemoryStream("img1"))
                End If
                con.Close()
                zoomIn.Attributes.Add("onclick", "return imageSizeIncrease();")
                zoomOut.Attributes.Add("onclick", "return imageSizeDecrease();")
            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString & "<br/>May your session has been expired, So please close the window and reload parent window.")
        End Try
    End Sub

    
End Class
