Imports EDSL.Entities
Imports EDSL.DAL
Public Partial Class ValueEdit
  Inherits BasePage
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim objMainPage As New dbmainPage
    Dim objMainPageEntity As New entMainPage

    objMainPageEntity = objMainPage.GetPageDetails("ValueAdminEdit")
    Me.Title = ConfigurationManager.AppSettings("BrowserTitleCompanyName") & objMainPageEntity.PageTitle
    divContent.InnerHtml = objMainPageEntity.PageContent
    Me.MetaName = objMainPageEntity.PageMetaName
    Me.MetaContent = objMainPageEntity.PageMetaContent

    If IsPostBack = False then
      If Request.QueryString("id") = 0 orelse Request.QueryString("id") = "" Then
        txtValueName.Enabled = True
      else
        txtValueName.Enabled = False
        call GetDetails(Request.QueryString("id"))
      End If
    End If

End Sub
  Private sub GetDetails(byval intID As Integer)
    Dim objMain As New dbMainValue
    Dim objMainEntity As entMainValue = objMain.GetItem(intID)
    txtID.Value = objMainEntity.ValueID
    txtValueName.Text = objMainEntity.ValueDesc
    txtValueText.Text = objMainEntity.ValueText
  End sub
  Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
    Dim objMainAdmin As New dbMainValue
    Dim intResultFromSave As Integer
    Dim intID As Integer
    If txtID.Value = "" then
      intID = 0
    else 
      intID = cint(txtID.Value)
    End If
    
    intResultFromSave = objMainAdmin.SaveItem(intID, txtValueText.Text, session("passover"))
    Select Case intResultFromSave 
      Case 0
        Response.Redirect("List.aspx")
      Case 1
        divErrorPanel.InnerHtml = "Error saving Value"
      Case 2
        divErrorPanel.InnerHtml = "Valuename already exists"
      Case Else
        Response.Redirect("List.aspx")
    End Select
  End Sub
  Protected Sub btnBack_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBack.Click
    Response.Redirect("List.aspx")
  End Sub
End Class
