Imports EDSL.Entities
Imports EDSL.DAL
Public Partial Class UserEdit2Control
  Inherits System.Web.UI.UserControl
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Request.QueryString("n") = 1 then
      hypPage1.NavigateUrl = "~/UserAdmin/edit.aspx?id=" & Request.QueryString("id") & "&n=1"
    else
      hypPage1.NavigateUrl = "~/UserAdmin/edit.aspx?id=" & Request.QueryString("id")
    end if
    divErrorList.Visible = False
    If IsPostBack = False then
      If Request.QueryString("id") = 0 orelse Request.QueryString("id") = "" Then
      else
        call GetDetails(Request.QueryString("id"))
      End If
    End If
  End Sub
  Private sub GetDetails(byval intLoginID As Integer)
    Dim objMain As new dbmainUser
    Dim objMainEntity As entMainLoginDetails = objMain.GetItem(intLoginID)
    txtID.Value = objMainEntity.LoginID
    txtName.Text = objMainEntity.LoginName
  End sub
  'Protected Sub btnDelete_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
  '  Dim objMain As new dbmainUser
  '  Response.Redirect("Delete.aspx?id=" & txtID.Value & "&idtext=" & txtName.Text & "&r=e")
  'End Sub
  Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
    If txtPassword.Text = "" and txtPassword2.Text = "" then
      If Request.QueryString("n") = 1 then
        divErrorList.Visible = True 
        divErrorList.InnerHtml = "You must enter a password before the user will be able to log in"
      else
        Response.Redirect("List.aspx")
      end if
    else
      If txtPassword.Text <> txtPassword2.Text then
        divErrorList.Visible = true
        divErrorList.InnerHtml = "The password and re-entered password must match"
      Else
        Dim objMainAdmin As new dbmainUser
        Dim intResultFromSave As Integer

        intResultFromSave = objMainAdmin.SaveItemPassword(cint(txtID.Value), txtPassword.Text)
        Select Case intResultFromSave 
          Case 0
            Response.Redirect("List.aspx")
          Case 1
            divErrorList.Visible = true
            divErrorList.InnerHtml = "Error saving password"
          Case Else
            Response.Redirect("List.aspx")
        End Select
      End If
   End If
  End Sub
  Protected Sub btnBack_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBack.Click
    If Request.QueryString("n") = 1 then
      divErrorList.Visible = true
      divErrorList.InnerHtml = "You must enter a password before the user will be able to log in"
    else
      Response.Redirect("edit.aspx?id=" & Request.QueryString("id"))
    End If
  End Sub

  Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    If Request.QueryString("n") = 1 then
      divErrorList.Visible = True 
      divErrorList.InnerHtml = "You must enter a password before the user will be able to log in"
    else
      Response.Redirect("list.aspx")
    End If
  End Sub
End Class