Imports System.Data.SqlClient
Imports System.Data
Imports CharterDotCom.CommonEntities.Library
Imports System.Collections.Generic

Partial Class Publish
  Inherits AdminPage

  Protected Sub btnPublish_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPublish.Click
    Try
      Dim CMS As New CMS.CMSService()
      CMS.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
            CMS.PublishContent(ddlTemplate.SelectedValue, Replace(Me.User.Identity.Name, "CHTR\", ""), ddlTemplate.Items(ddlTemplate.SelectedIndex).Text)
      GridView1.DataBind()
    Catch ex As Exception
      Throw ex
    End Try

    GridView1.DataBind()
  End Sub

  Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
    If GridView1.SelectedIndex <> -1 Then

      Dim retcode As String
      Try
        Dim cmsadmin As New CMS.CMSService()
        cmsadmin.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
        retcode = cmsadmin.GetApprovedContent(GridView1.Rows(GridView1.SelectedIndex).Cells(1).Text)
        FCKeditor.Value = retcode
        FCKeditor.Visible = True
      Catch ex As Exception
        Throw ex
      Finally
      End Try
    End If
  End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    FCKeditor.Visible = False
    linkPreview.NavigateUrl = ConfigurationManager.AppSettings("PREVIEWSITE")
    If Not Page.IsPostBack Then
        '#Load data into templates drop down
        Dim templatescmsTA As DALTableAdapters.Template_CMSTableAdapter = New DALTableAdapters.Template_CMSTableAdapter
'       the value 3 here represents the roleid (ContentPublisher)
        Dim templates As DAL.Template_CMSDataTable = templatescmsTA.GetDataBy(Me.CurrentUserID, 3)
        ddlTemplate.Items.Clear()
        For Each template As DAL.Template_CMSRow In templates
            ddlTemplate.Items.Add(New ListItem(template.TemplateName, template.TemplateID))
        Next
    End If
  End Sub

    Protected Sub btnRefreshCache_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRefreshCache.Click
        Dim CMS As New CMS.CMSService()
        CMS.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
            CMS.PublishContent(ddlTemplate.SelectedValue, Replace(Me.User.Identity.Name, "CHTR\", ""), ddlTemplate.Items(ddlTemplate.SelectedIndex).Text)
    End Sub
End Class
