Imports EDSL.Entities
Imports EDSL.DAL
Partial Public Class ProductEdit1Control
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        hypPage2.NavigateUrl = "~/ProductAdmin/edit3.aspx?id=" & Request.QueryString("id")
        txtProductDesc2.BaseHref = ConfigurationManager.AppSettings("BaseHref") & "PageEdit"
        txtProductDesc2.BasePath = ConfigurationManager.AppSettings("BasePath")
        If IsPostBack = False Then
            If Request.QueryString("id") = 0 OrElse Request.QueryString("id") = "" Then
                'txtProductType.Value = "P"
                btnDelete.Visible = False
            Else
                btnDelete.Visible = True
                Call GetDetails(Request.QueryString("id"))
            End If
            If Request.QueryString("dup") = "n" Then
                lblSaveAsNew.Text = "Item saved as new copy, please edit accordingly"
            End If

        End If
    End Sub
    Private Sub GetDetails(ByVal intProductID As Integer)
        Dim objMain As New dbMainProduct
        Dim objMainEntity As entMainProduct = objMain.GetItem(intProductID)

        With objMainEntity
            txtID.Value = .ProductID
            txtProductName.Text = .ProductName
            txtProductDesc1.Text = .ProductDesc1
            txtProductDesc2.Value = .ProductDesc2

            If .Active = 1 Then
                chkActive.Checked = True
            Else
                chkActive.Checked = False
            End If

        End With
    End Sub
    Protected Sub btnDelete_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
        Dim objMain As New dbMainProduct
        Response.Redirect("Delete.aspx?id=" & txtID.Value & "&idtext=" & txtProductName.Text & "&r=e")
    End Sub
    Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExit.Click, btnSaveNext.Click
        Dim clsMisc As New miscFunctions
        Dim objGlobals As New TheGlobals
        Dim objMainAdmin As New dbMainProduct
        Dim intResultFromSave As Integer ' = @@IDENTITY
        Dim intID As Integer

        If txtID.Value = "" Then
            intID = 0
        Else
            intID = CInt(txtID.Value)
        End If

        divErrorPanel.InnerHtml = ""


        intResultFromSave = objMainAdmin.SaveItemPage1(intID, txtProductName.Text, Convert.ToDecimal("0.00"), "", 0, IIf(chkActive.Checked = True, 1, 0), Session("passover"), txtProductDesc1.Text, txtProductDesc2.Value)
        Select Case intResultFromSave
            Case 0
                divErrorPanel.InnerHtml = "Error saving product details"
                Exit Sub
            Case Else
                intID = intResultFromSave
        End Select

        Select Case intResultFromSave
            Case 0
                divErrorPanel.InnerHtml = "Error saving product categories"
                Exit Sub
            Case Else
                If sender.id = "btnBack" Or sender.id = "btnExit" Then
                    Response.Redirect("list.aspx")
                Else ' Next
                    Response.Redirect("edit3.aspx?id=" & intID)
                End If
        End Select
    End Sub

   
End Class
