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

        txtCaseStudySummary.BaseHref = ConfigurationManager.AppSettings("BaseHref") & "CaseStudyAdmin"
        txtCaseStudySummary.BasePath = ConfigurationManager.AppSettings("BasePath")
        If IsPostBack = False Then
            'Call PopulateddlStatus()
            If Request.QueryString("id") = "" OrElse Request.QueryString("id") = 0 Then
                btnDelete.Visible = False
                hypPage2.Enabled = False

            Else
                btnDelete.Visible = True
                Call GetDetails(Request.QueryString("id"))
            End If

            If Request.QueryString("id") <> "" Then
                Dim objChoices As New System.Web.UI.WebControls.ListItemCollection
                Dim objSelected As New System.Web.UI.WebControls.ListItemCollection
                Dim objMainSelector As New dbMainSelectorBox
                'objChoices = objMainSelector.GetChoices("mainCategory", "CategoryID", "CategoryName")
                'objSelected = objMainSelector.GetSelected("mainLinkCategoryProduct", "LinkCategoryProductID", "ProductID", "CategoryID", Request.QueryString("id"), objChoices, "mainCategory", "CategoryID", "CategoryName")

                'ctlSelectorBoxControl.TheChoices = objChoices
                'ctlSelectorBoxControl.TheSelected = objSelected
            End If
        End If
        'ctlSelectorBoxControl.WidthOfBox = 300
        ' ctlSelectorBoxControl.HeightOfBox = 100
    End Sub
    Private Sub GetDetails(ByVal intCaseStudyID As Integer)
        Dim objMain As New dbMainCaseStudy
        Dim objMainEntity As entMainCaseStudy = objMain.GetItem(intCaseStudyID)
        txtID.Value = objMainEntity.CaseStudyID
        txtCaseStudyHeadline.Text = objMainEntity.CaseStudyHeadline
        txtCaseStudySummary.Value = objMainEntity.CaseStudySummary
        txtDate.Text = objMainEntity.CaseStudyDate
        'ddlCaseStudyType.SelectedValue = objMainEntity.CaseStudyType
        If objMainEntity.Active = 1 Then
            chkActive.Checked = True
        Else
            chkActive.Checked = False
        End If
    End Sub
    Protected Sub btnDelete_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
        Dim objMain As New dbMainCaseStudy
        Response.Redirect("Delete.aspx?id=" & txtID.Value & "&idtext=" & txtCaseStudyHeadline.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 dbMainCaseStudy
        Dim intResultFromSave As Integer ' = @@IDENTITY
        Dim intID As Integer
        Dim strCaseStudySummary As String = txtCaseStudySummary.Value.ToString

        If Len(strCaseStudySummary) <= 0 Then
            CustomValidator1.IsValid = False
            CustomValidator1.ErrorMessage = "Case study summary - can not be blank"
            Exit Sub
        End If

        strCaseStudySummary = Replace(strCaseStudySummary, "<p>", "")
        strCaseStudySummary = Replace(strCaseStudySummary, "</p>", "")

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

        divErrorPanel.InnerHtml = ""

        'intResultFromSave = objMainAdmin.SaveItemPage1(intID, txtCaseStudyHeadline.Text, strCaseStudySummary, txtDate.Text, IIf(chkActive.Checked = True, 1, 0), Session("passover"), Convert.ToInt32(ddlCaseStudyType.SelectedValue.ToString()))
        intResultFromSave = objMainAdmin.SaveItemPage1(intID, txtCaseStudyHeadline.Text, strCaseStudySummary, txtDate.Text, IIf(chkActive.Checked = True, 1, 0), Session("passover"), 0)
        Select Case intResultFromSave
            Case 0
                divErrorPanel.InnerHtml = "Error saving case study"
                Exit Sub
            Case Else
                Dim func As New miscFunctions
                Call func.BuildCaseStudyXMLFile()
                intID = intResultFromSave
        End Select

        'intResultFromSave = objMainAdmin.SaveItemPage1Categories(intID, Session("passover"))
        Select Case intResultFromSave
            Case 0
                divErrorPanel.InnerHtml = "Error saving case study categories"
                Exit Sub
            Case Else
                If sender.id = "btnBack" Or sender.id = "btnExit" Then
                    Response.Redirect("list.aspx")
                Else ' Next
                    Response.Redirect("edit2.aspx?id=" & intID)
                End If
        End Select
    End Sub
    'Private Sub PopulateddlStatus()
    '    Dim objMain As New dbMainFunctions
    '    Dim objDDLItems As List(Of entMainDropDown) = objMain.GetDropDownReference(9)

    '    'Call ddlStatus.Items.Clear()
    '    Dim objListitemTop As New ListItem
    '    objListitemTop.Text = ""
    '    objListitemTop.Value = ""
    '    ddlCaseStudyType.Items.Add(objListitemTop)

    '    For Each objDDL As entMainDropDown In objDDLItems
    '        Dim objListitem As New ListItem
    '        objListitem.Text = objDDL.TextDisplay
    '        objListitem.Value = objDDL.DropDownValue
    '        ddlCaseStudyType.Items.Add(objListitem)
    '    Next

    'End Sub
End Class