Imports EDSL.Entities
Imports EDSL.DAL
Partial Public Class CategoryEdit2Control
  Inherits System.Web.UI.UserControl
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    hypPage2.NavigateUrl = "~/CategoryAdmin/edit.aspx?id=" & Request.QueryString("id")

    If IsPostBack = False Then
      If Request.QueryString("id") = 0 OrElse Request.QueryString("id") = "" Then
        btnDelete.Visible = False
        If Request.QueryString("id") = "" Then
          txtParentCategory.Value = 0
        Else
          txtParentCategory.Value = Request.QueryString("cid")
        End If
      Else
        btnDelete.Visible = True
        Call GetDetails(Request.QueryString("id"))
      End If

      ' Load the repeater
            'Dim objMain As New dbMainProduct
            'Dim objMainEntity As List(Of entMainProduct) = objMain.GetAllByCategoryID(" AND mainProduct.Active = 1 ", "ORDER BY OrderBY", txtID.Value)

            'repRepeater.DataSource = objMainEntity
            'repRepeater.DataBind()
    End If
  End Sub

  Private Sub GetDetails(ByVal intCategoryID As Integer)
    Dim objMain As New dbMainCategory
    Dim objMainEntity As entmainCategory = objMain.GetItem(intCategoryID)
    txtID.Value = objMainEntity.CategoryID
    txtName.Text = objMainEntity.CategoryName
    txtParentCategory.Value = objMainEntity.ParentCategoryID
  End Sub
  Protected Sub btnDelete_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
    Dim objMain As New dbMainCategory
    Response.Redirect("Delete.aspx?id=" & txtID.Value & "&idtext=" & txtName.Text & "&id=" & txtParentCategory.Value & "&r=e")
  End Sub
  Protected Sub btnBack_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBack.Click
    Dim objMain As New dbMainCategory
    Response.Redirect("List.aspx?cid=" & txtParentCategory.Value)
  End Sub

  Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        'Dim objMainAdmin As New dbMainProduct
        'Dim intResultFromSave As Integer

        'For Each repItem As RepeaterItem In repRepeater.Items
        '  Dim intOrderBy As integer
        '  Dim intProductID As integer
        '  'Gets the value from the text box
        '  Dim txt As TextBox = TryCast(repItem.FindControl("txtOrderBy"), TextBox)
        '  intOrderBy = CInt(txt.Text.ToString())
        ' 'Now get the Product ID so an update can be made to the database with the new textbox items
        '  Dim hiddenField As HiddenField = TryCast(repItem.FindControl("txtProductID"), HiddenField)
        '  intProductID = Convert.ToInt32(hiddenField.Value.ToString())

        '  intResultFromSave = objMainAdmin.SaveOrderBy(intProductID, intOrderBy)
        '  If intResultFromSave = 1 then
        '    divErrorPanel.InnerHtml = "Error saving sort order"
        '  End if
        'Next
        'Response.Redirect("List.aspx?cid=" & txtParentCategory.Value)
  End Sub
End Class