Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports System.IO
Imports SpectrumWiki.BusinessComponent
Partial Public Class AddEditPicture
Inherits System.Web.UI.Page
Dim wiki_text_id As Integer = 0
Dim arrayList As New ArrayList()
Dim countArray As Integer
Dim fileName As String
Dim temp_text_id As Integer = 0
Dim update_wiki_text_id = 0
Dim edit As Integer = 0
Dim eguid As String
Dim EditWikiId As Integer
#Region "Private Member Variables"
Private _imgPath As String = "~/wiki/Graphics/"
Private _thumbNailPath As String = "~/wiki/GraphicsThumbnail/"
'Private _thumbNailHeight As Integer = Convert.ToInt32(ConfigurationManager.AppSettings("ThumbnailHeight"))
'Private _thumbNailWidth As Integer = Convert.ToInt32(ConfigurationManager.AppSettings("ThumbnailWidth"))
Private _thumbNailHeight As Integer
Private _thumbNailWidth As Integer
Private _validPhotoFormats As String() = New String(9) {}
Private _photoformat As String = ConfigurationSettings.AppSettings("validPhotoFormats")
Private _seperator As Char() = {","c}
Private _seperatorSlash As Char() = {"/"c}
Private _split As Char() = {"."c}
Private _imagename As String() = New String(5) {}
Private _isflag As Boolean
Private _dbPath As String
Dim orgID As Integer = 0
Private Const Lx = 100 ' max width for thumbnails
Private Const Ly = 140 ' max height for thumbnails
Dim l2
#End Region
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If String.IsNullOrEmpty(SessionWrapper.UserName) Then
Response.Redirect("~/wiki/Login.aspx")
End If
If Not IsPostBack Then
Dim lnkUserName As LinkButton = Master.FindControl("lnkUserName")
lnkUserName.Text = SessionWrapper.UserName
End If
Session.Remove("nb")
temp_text_id = Convert.ToInt32(Request.QueryString("TempWikiId"))
wiki_text_id = Convert.ToInt32(Request.QueryString("WikiId"))
orgID = Convert.ToInt32(Request.QueryString("OrgId"))
' If Not String.IsNullOrEmpty(Session("update_wiki_text_id")) Then
'BindGridFromOrg(CInt(Session("update_wiki_text_id")))
'Else
edit = Convert.ToInt32(Request.QueryString("Edit"))
eguid = Request.QueryString("eguid")
ViewState("FileCategory") = Nothing
'End If
'If Not IsPostBack Then
' If Convert.ToInt32(Request.QueryString("EditWikiId")) > 0 Then
' Try
' WikiGraphicsBLL.InsertWikiGraphicsTemp(Convert.ToInt32(Request.QueryString("EditWikiId")), temp_text_id)
' Catch ex As Exception
' If ex.InnerException Is Nothing Then
' Logger.WriteToErrorLog(ex.Message)
' Else
' Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
' End If
' End Try
' End If
'End If
If Request.QueryString("physicalfilename") IsNot Nothing Then
Dim physical_file_name As String = Request.QueryString("physicalfilename")
BindGridByPhysicalFileName(physical_file_name)
UploadMsg.ForeColor = Color.Red
UploadMsg.Text = "Uploading a new file will replace the original file."
Else
BindGrid(temp_text_id)
End If
End Sub
'Bind grid by using Physical_file_name
Protected Sub BindGridByPhysicalFileName(ByVal physical_file_name As String)
Try
gvAddEditPicture.DataSource = WikiGraphicsBLL.WikiGraphicGetImage(physical_file_name)
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
gvAddEditPicture.DataBind()
End Sub
'Bind from Original database
Protected Sub BindGridFromOrg(ByVal wiki_text_id As Integer)
Try
gvAddEditPicture.DataSource = WikiGraphicsBLL.GetWikiGraphics(wiki_text_id)
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
gvAddEditPicture.DataBind()
End Sub
'Bind from Temp database
Protected Sub BindGrid(ByVal wiki_text_id As Integer)
Try
gvAddEditPicture.DataSource = WikiGraphicsBLL.GetTempWikiGraphics(wiki_text_id)
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
gvAddEditPicture.DataBind()
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
If Request.QueryString("physicalfilename") IsNot Nothing Then
Dim physical_file_name As String = Request.QueryString("physicalfilename").ToString()
Dim dtGetWikiGraphicId As DataTable = WikiGraphicsBLL.WikiGraphicGetImage(physical_file_name)
Dim GraphicId As Integer = dtGetWikiGraphicId.Rows(0)("wiki_graphic_id").ToString()
Dim wikiId As Integer = dtGetWikiGraphicId.Rows(0)("wiki_text_id").ToString()
ViewState("EditWikiId") = Nothing
ViewState("EditWikiId") = wikiId
UpdateImageByPhysicalFileName(physical_file_name, GraphicId)
Else
'Response.Redirect("WikiId")
If (temp_text_id > 0) Then
'Response.Redirect("~/wiki/New.aspx?TempWikiId=" & temp_text_id)
Session("TempWikiID") = temp_text_id
Dim file As HttpPostedFile
Dim fileNameDB As String
Dim fileExt As String
Dim caption As String
Dim replace As String
Dim image_guid As String
wiki_text_id = temp_text_id
'wiki_text_id = Convert.ToInt32(Request.QueryString("WikiId"))
Dim i As Integer = 0
For Each key As String In Request.Files.Keys
file = Request.Files(key)
If file IsNot Nothing AndAlso file.ContentLength > 0 Then
i = i + 1
fileName = Path.GetFileName(file.FileName)
_imagename = fileName.Split(_split)
'fileNameDB = _imagename(0)
fileNameDB = Path.GetFileNameWithoutExtension(file.FileName)
If (i = 1) Then
caption = txt1.Value
Else
replace = key.Replace("file", String.Empty)
'counter = Integer.Parse(replace.Replace("}", String.Empty))
caption = Request.Form("txtDescription" & replace.ToString())
End If
_validPhotoFormats = _photoformat.Split(_seperator)
fileExt = System.IO.Path.GetExtension(file.FileName)
For Each ext As String In _validPhotoFormats
If ext = fileExt Then
_isflag = True
Exit For
Else
_isflag = False
End If
Next
If _isflag = True Then
image_guid = Guid.NewGuid.ToString()
file.SaveAs(Server.MapPath(_imgPath & image_guid & fileExt))
Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & image_guid & fileExt)
Using img As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(_imgPath & image_guid & fileExt))
Dim thbWidth As Integer = img.Width
Dim thbHeight As Integer = img.Height
If thbWidth > thbHeight Then
_thumbNailWidth = 100
_thumbNailHeight = ((thbHeight * 100) / thbWidth)
ElseIf thbHeight > thbWidth Then
_thumbNailHeight = 100
_thumbNailWidth = ((thbWidth * 100) / thbHeight)
ElseIf thbHeight = thbWidth Then
_thumbNailHeight = 100
_thumbNailWidth = 100
End If
'Dim originalimg As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(_imgPath & image_guid & fileExt))
'If (originalimg.Width / Lx) > (originalimg.Width / Ly) Then
' l2 = originalimg.Width
' _thumbNailWidth = Lx
' _thumbNailHeight = originalimg.Height * (Lx / l2)
' If _thumbNailHeight > Ly Then
' _thumbNailWidth = _thumbNailWidth * (Ly / _thumbNailHeight)
' _thumbNailHeight = Ly
' End If
'Else
' l2 = originalimg.Height
' _thumbNailHeight = Ly
' _thumbNailWidth = originalimg.Width * (Ly / l2)
' If _thumbNailWidth > Lx Then
' _thumbNailHeight = _thumbNailHeight * (Lx / _thumbNailWidth)
' _thumbNailWidth = Lx
' End If
'End If
Using ImgThnail As System.Drawing.Image = New Bitmap(img, _thumbNailWidth, _thumbNailHeight)
ImgThnail.Save(thumbNailPath, img.RawFormat)
ImgThnail.Dispose()
End Using
img.Dispose()
End Using
Dim wikiGraphics As WikiGraphic = New WikiGraphic()
wikiGraphics.FileName = fileNameDB
wikiGraphics.PhysicalFileName = image_guid
wikiGraphics.FileExtension = fileExt
wikiGraphics.Caption = caption
wikiGraphics.WikiTextId = wiki_text_id
For Each ext As String In _validPhotoFormats
If ext = fileExt Then
wikiGraphics.FileFormat = "Image files"
End If
Next
Try
WikiGraphicsBLL.tempInsertWikiGraphics(wikiGraphics, True)
lblStatusMessage.CssClass = "success"
lblStatusMessage.Text = "Pictures saved successfully"
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
Else
arrayList.Add(fileName)
countArray = arrayList.Count
If file1.PostedFile.ContentLength > 0 Then
Try
image_guid = Guid.NewGuid.ToString()
file.SaveAs(Server.MapPath(_imgPath & image_guid & fileExt))
Dim wikiGraphics As WikiGraphic = New WikiGraphic()
wikiGraphics.FileName = fileNameDB
wikiGraphics.PhysicalFileName = image_guid
wikiGraphics.FileExtension = fileExt
wikiGraphics.Caption = caption
wikiGraphics.WikiTextId = wiki_text_id
wikiGraphics.FileFormat = FileFormat(fileExt)
Try
WikiGraphicsBLL.tempInsertWikiGraphics(wikiGraphics, True)
lblStatusMessage.CssClass = "success"
lblStatusMessage.Text = "File saved successfully"
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
'lblStatusMessage.Text = "file Uploaded Successfully."
Catch ex As Exception
lblStatusMessage.Text = "Error Saving file."
End Try
End If
End If
End If
Next
'If countArray > 0 Then
' lblStatusMessage.CssClass = "failure"
' Dim arrayValue As String
' Dim stringBuilder As StringBuilder = New StringBuilder()
' For Each arrayValue In arrayList
' stringBuilder.Append(arrayValue + "
")
' Next
' lblStatusMessage.Text = ("Failed to Save Pictures, Invalid Format - Following pictures are not saved, because of invalid format:
" & stringBuilder.ToString() & "Valid formats are: " & ConfigurationManager.AppSettings("validPhotoFormats"))
'End If
'BindGrid(wiki_text_id)
txt1.Value = String.Empty
'Response.Redirect("~/wiki/New.aspx")
Else
'Session("id") = wiki_text_id
'Response.Redirect("~/wiki/New.aspx?WikiId=" & wiki_text_id)
' Response.Redirect("~/wiki/New.aspx")
End If
'Dim file As HttpPostedFile
'Dim fileNameDB As String
'Dim fileExt As String
'Dim caption As String
'Dim replace As String
'Dim image_guid As String
'wiki_text_id = Convert.ToInt32(Request.QueryString("WikiId"))
'Dim i As Integer = 0
'For Each key As String In Request.Files.Keys
' file = Request.Files(key)
' If file IsNot Nothing AndAlso file.ContentLength > 0 Then
' i = i + 1
' fileName = Path.GetFileName(file.FileName)
' _imagename = fileName.Split(_split)
' 'fileNameDB = _imagename(0)
' fileNameDB = Path.GetFileNameWithoutExtension(file.FileName)
' If (i = 1) Then
' caption = txt1.Value
' Else
' replace = key.Replace("file", String.Empty)
' 'counter = Integer.Parse(replace.Replace("}", String.Empty))
' caption = Request.Form("txtDescription" & replace.ToString())
' End If
' _validPhotoFormats = _photoformat.Split(_seperator)
' fileExt = System.IO.Path.GetExtension(file.FileName)
' For Each ext As String In _validPhotoFormats
' If ext = fileExt Then
' _isflag = True
' Exit For
' Else
' _isflag = False
' End If
' Next
' If _isflag = True Then
' file.SaveAs(Server.MapPath(_imgPath & fileName))
' Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & fileName)
' Using img As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(_imgPath & fileName))
' Using ImgThnail As System.Drawing.Image = New Bitmap(img, _thumbNailWidth, _thumbNailHeight)
' ImgThnail.Save(thumbNailPath, img.RawFormat)
' ImgThnail.Dispose()
' End Using
' img.Dispose()
' End Using
' Dim wikiGraphics As WikiGraphic = New WikiGraphic()
' image_guid = Guid.NewGuid.ToString()
' wikiGraphics.FileName = fileNameDB
' wikiGraphics.PhysicalFileName = image_guid
' wikiGraphics.FileExtension = fileExt
' wikiGraphics.Caption = caption
' wikiGraphics.WikiTextId = wiki_text_id
' Try
' WikiGraphicsBLL.tempInsertWikiGraphics(wikiGraphics)
' lblStatusMessage.CssClass = "success"
' lblStatusMessage.Text = "Pictures saved successfully"
' Catch ex As Exception
' If ex.InnerException Is Nothing Then
' Logger.WriteToErrorLog(ex.Message)
' Else
' Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
' End If
' End Try
' Else
' arrayList.Add(fileName)
' countArray = arrayList.Count
' If file1.PostedFile.ContentLength > 0 Then
' Try
' file.SaveAs(Server.MapPath(_imgPath & fileName))
' 'file1.PostedFile.SaveAs(("D:\Staffs\Jeyachandran\Training_exercise\Project1\Upload_file\Upload_file\uploadfiles\" & file1.Value))
' Dim wikiGraphics As WikiGraphic = New WikiGraphic()
' image_guid = Guid.NewGuid.ToString()
' wikiGraphics.FileName = fileNameDB
' wikiGraphics.PhysicalFileName = image_guid
' wikiGraphics.FileExtension = fileExt
' wikiGraphics.Caption = caption
' wikiGraphics.WikiTextId = wiki_text_id
' Try
' WikiGraphicsBLL.InsertWikiGraphics(wikiGraphics)
' lblStatusMessage.CssClass = "success"
' lblStatusMessage.Text = "File saved successfully"
' Catch ex As Exception
' If ex.InnerException Is Nothing Then
' Logger.WriteToErrorLog(ex.Message)
' Else
' Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
' End If
' End Try
' 'lblStatusMessage.Text = "file Uploaded Successfully."
' Catch ex As Exception
' lblStatusMessage.Text = "Error Saving file."
' End Try
' End If
' End If
' End If
'Next
''If countArray > 0 Then
'' lblStatusMessage.CssClass = "failure"
'' Dim arrayValue As String
'' Dim stringBuilder As StringBuilder = New StringBuilder()
'' For Each arrayValue In arrayList
'' stringBuilder.Append(arrayValue + "
")
'' Next
'' lblStatusMessage.Text = ("Failed to Save Pictures, Invalid Format - Following pictures are not saved, because of invalid format:
" & stringBuilder.ToString() & "Valid formats are: " & ConfigurationManager.AppSettings("validPhotoFormats"))
''End If
BindGrid(temp_text_id)
End If
'txt1.Value = String.Empty
End Sub
Protected Sub btnReturn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReturn.Click
'Response.Redirect("WikiId")
If (temp_text_id > 0) Then
'Response.Redirect("~/wiki/New.aspx?TempWikiId=" & temp_text_id)
Session("TempWikiID") = temp_text_id
Dim file As HttpPostedFile
Dim fileNameDB As String
Dim fileExt As String
Dim caption As String
Dim replace As String
Dim image_guid As String
wiki_text_id = temp_text_id
Try
WikiGraphicsBLL.UpdateTempWikiGraphicsNotSave(wiki_text_id, False)
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
'wiki_text_id = Convert.ToInt32(Request.QueryString("WikiId"))
Dim i As Integer = 0
For Each key As String In Request.Files.Keys
file = Request.Files(key)
If file IsNot Nothing AndAlso file.ContentLength > 0 Then
i = i + 1
fileName = Path.GetFileName(file.FileName)
_imagename = fileName.Split(_split)
'fileNameDB = _imagename(0)
fileNameDB = Path.GetFileNameWithoutExtension(file.FileName)
If (i = 1) Then
caption = txt1.Value
Else
replace = key.Replace("file", String.Empty)
'counter = Integer.Parse(replace.Replace("}", String.Empty))
caption = Request.Form("txtDescription" & replace.ToString())
End If
_validPhotoFormats = _photoformat.Split(_seperator)
fileExt = System.IO.Path.GetExtension(file.FileName)
For Each ext As String In _validPhotoFormats
If ext = fileExt Then
_isflag = True
Exit For
Else
_isflag = False
End If
Next
If _isflag = True Then
image_guid = Guid.NewGuid.ToString()
file.SaveAs(Server.MapPath(_imgPath & image_guid & fileExt))
Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & image_guid & fileExt)
Using img As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(_imgPath & image_guid & fileExt))
'Dim originalimg As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(_imgPath & image_guid & fileExt))
'If (originalimg.Width / Lx) > (originalimg.Width / Ly) Then
' l2 = originalimg.Width
' _thumbNailWidth = Lx
' _thumbNailHeight = originalimg.Height * (Lx / l2)
' If _thumbNailHeight > Ly Then
' _thumbNailWidth = _thumbNailWidth * (Ly / _thumbNailHeight)
' _thumbNailHeight = Ly
' End If
'Else
' l2 = originalimg.Height
' _thumbNailHeight = Ly
' _thumbNailWidth = originalimg.Width * (Ly / l2)
' If _thumbNailWidth > Lx Then
' _thumbNailHeight = _thumbNailHeight * (Lx / _thumbNailWidth)
' _thumbNailWidth = Lx
' End If
'End If
Dim thbWidth As Integer = img.Width
Dim thbHeight As Integer = img.Height
If thbWidth > thbHeight Then
_thumbNailWidth = 100
_thumbNailHeight = ((thbHeight * 100) / thbWidth)
ElseIf thbHeight > thbWidth Then
_thumbNailHeight = 100
_thumbNailWidth = ((thbWidth * 100) / thbHeight)
ElseIf thbHeight = thbWidth Then
_thumbNailHeight = 100
_thumbNailWidth = 100
End If
Using ImgThnail As System.Drawing.Image = New Bitmap(img, _thumbNailWidth, _thumbNailHeight)
ImgThnail.Save(thumbNailPath, img.RawFormat)
ImgThnail.Dispose()
End Using
img.Dispose()
End Using
Dim wikiGraphics As WikiGraphic = New WikiGraphic()
wikiGraphics.FileName = fileNameDB
wikiGraphics.PhysicalFileName = image_guid
wikiGraphics.FileExtension = fileExt
wikiGraphics.Caption = caption
wikiGraphics.WikiTextId = wiki_text_id
For Each ext As String In _validPhotoFormats
If ext = fileExt Then
wikiGraphics.FileFormat = "Image files"
End If
Next
Try
WikiGraphicsBLL.tempInsertWikiGraphics(wikiGraphics, False)
lblStatusMessage.CssClass = "success"
lblStatusMessage.Text = "Pictures saved successfully"
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
Else
arrayList.Add(fileName)
countArray = arrayList.Count
If file1.PostedFile.ContentLength > 0 Then
Try
image_guid = Guid.NewGuid.ToString()
file.SaveAs(Server.MapPath(_imgPath & image_guid & fileExt))
'file1.PostedFile.SaveAs(("D:\Staffs\Jeyachandran\Training_exercise\Project1\Upload_file\Upload_file\uploadfiles\" & file1.Value))
Dim wikiGraphics As WikiGraphic = New WikiGraphic()
wikiGraphics.FileName = fileNameDB
wikiGraphics.PhysicalFileName = image_guid
wikiGraphics.FileExtension = fileExt
wikiGraphics.Caption = caption
wikiGraphics.WikiTextId = wiki_text_id
wikiGraphics.FileFormat = FileFormat(fileExt)
Try
WikiGraphicsBLL.tempInsertWikiGraphics(wikiGraphics, False)
lblStatusMessage.CssClass = "success"
lblStatusMessage.Text = "File saved successfully"
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
'lblStatusMessage.Text = "file Uploaded Successfully."
Catch ex As Exception
lblStatusMessage.Text = "Error Saving file."
End Try
End If
End If
End If
Next
'If countArray > 0 Then
' lblStatusMessage.CssClass = "failure"
' Dim arrayValue As String
' Dim stringBuilder As StringBuilder = New StringBuilder()
' For Each arrayValue In arrayList
' stringBuilder.Append(arrayValue + "
")
' Next
' lblStatusMessage.Text = ("Failed to Save Pictures, Invalid Format - Following pictures are not saved, because of invalid format:
" & stringBuilder.ToString() & "Valid formats are: " & ConfigurationManager.AppSettings("validPhotoFormats"))
'End If
'BindGrid(wiki_text_id)
txt1.Value = String.Empty
'Response.Redirect("~/wiki/New.aspx")
Response.Redirect("~/wiki/New.aspx?Id=" & temp_text_id & "&nbCount=" & Request.QueryString("nbCount") & "&nbpCount=" & Request.QueryString("nbpCount") & "&nfCount=" & Request.QueryString("nfCount") & "&nfpCount=" & Request.QueryString("nfpCount") & "&ncCount=" & Request.QueryString("ncCount") & "&ncpCount=" & Request.QueryString("ncpCount") & "&nbcCount=" & Request.QueryString("nbcCount") & "&nbcpCount=" & Request.QueryString("nbcpCount") & "&Edit=" & edit & "&OrgId=" & orgID & "&eguid=" & eguid)
Else
If Request.QueryString("physicalfilename") IsNot Nothing Then
Dim physical_file_name As String = Request.QueryString("physicalfilename").ToString()
Dim dtGetWikiId As DataTable
Try
dtGetWikiId = WikiGraphicsBLL.WikiGraphicGetImage(physical_file_name)
'EditWikiId = dtGetWikiId.Rows(0)("wiki_text_id").ToString()
If dtGetWikiId.Rows.Count > 0 Then
EditWikiId = dtGetWikiId.Rows(0)("wiki_text_id").ToString()
Else
EditWikiId = ViewState("EditWikiId").ToString()
End If
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
Response.Redirect("~/wiki/New.aspx?EditWikiId=" & EditWikiId)
Else
'Session("id") = wiki_text_id
Response.Redirect("~/wiki/New.aspx?WikiId=" & wiki_text_id & "&nbCount=" & Request.QueryString("nbCount") & "&nbpCount=" & Request.QueryString("nbpCount") & "&nfCount=" & Request.QueryString("nfCount") & "&nfpCount=" & Request.QueryString("nfpCount") & "&ncCount=" & Request.QueryString("ncCount") & "&ncpCount=" & Request.QueryString("ncpCount") & "&nbcCount=" & Request.QueryString("nbcCount") & "&nbcpCount=" & Request.QueryString("nbcpCount") & "&Edit=" & edit & "&OrgId=" & orgID & "&eguid=" & eguid)
' Response.Redirect("~/wiki/New.aspx")
End If
End If
End Sub
Protected Sub gvAddEditPicture_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvAddEditPicture.RowDataBound
'If (e.Row.RowType = DataControlRowType.DataRow) Then
' Dim fileName As String = DataBinder.Eval(e.Row.DataItem, "file_name").ToString()
' Dim fileExt As String = DataBinder.Eval(e.Row.DataItem, "file_extension").ToString()
' Dim pictureId As String = DataBinder.Eval(e.Row.DataItem, "wiki_graphic_id").ToString()
' 'Dim imageFile As System.Web.UI.WebControls.Image = CType(e.Row.FindControl("imgPicture"), System.Web.UI.WebControls.Image)
' Dim lblFileCategory As System.Web.UI.WebControls.Label = CType(e.Row.FindControl("lblFileCategory"), System.Web.UI.WebControls.Label)
' Dim strval As String = DirectCast(lblFileCategory, Label).Text
' Dim title As String = DirectCast(ViewState("FileCategory"), String)
' If title = strval Then
' lblFileCategory.Visible = False
' lblFileCategory.Text = String.Empty
' Else
' title = strval
' ViewState("FileCategory") = title
' lblFileCategory.Visible = True
' lblFileCategory.Text = title
' End If
'End If
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim fileName As String = DataBinder.Eval(e.Row.DataItem, "file_name").ToString()
Dim fileExt As String = DataBinder.Eval(e.Row.DataItem, "file_extension").ToString()
Dim pictureId As String = DataBinder.Eval(e.Row.DataItem, "wiki_graphic_id").ToString()
Dim img_guid As String = DataBinder.Eval(e.Row.DataItem, "physical_file_name").ToString()
'Dim lnkImage As System.Web.UI.WebControls.Image = CType(e.Row.FindControl("lnkImage"), System.Web.UI.WebControls.Image)
Dim lnkImage As System.Web.UI.WebControls.HyperLink = CType(e.Row.FindControl("lnkImage"), System.Web.UI.WebControls.HyperLink)
Dim lblFileCategory As System.Web.UI.WebControls.Label = CType(e.Row.FindControl("lblFileCategory"), System.Web.UI.WebControls.Label)
Dim imgview As System.Web.UI.WebControls.Image = CType(e.Row.FindControl("imgview"), System.Web.UI.WebControls.Image)
_validPhotoFormats = _photoformat.Split(_seperator)
For Each ext As String In _validPhotoFormats
If ext = fileExt Then
_isflag = True
Exit For
Else
_isflag = False
End If
Next
If _isflag = True Then
imgview.ImageUrl = _thumbNailPath.ToString() + img_guid.ToString() + fileExt.ToString()
Else
imgview.ImageUrl = String.Empty
imgview.Style.Add("display", "none")
End If
lnkImage.NavigateUrl = "~\wiki\ViewPicture.aspx?PictureId=" & img_guid.ToString() & "&Extn=" & fileExt.ToString()
Dim strval As String = DirectCast(lblFileCategory, Label).Text
Dim title As String = DirectCast(ViewState("FileCategory"), String)
If title = strval Then
lblFileCategory.Visible = False
lblFileCategory.Text = String.Empty
Else
title = strval
ViewState("FileCategory") = title
lblFileCategory.Visible = True
lblFileCategory.Text = title
End If
' imageFile.ImageUrl = _thumbNailPath & fileName + fileExt
End If
End Sub
Protected Sub gvAddEditPicture_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvAddEditPicture.RowCommand
'If Not String.IsNullOrEmpty(Session("update_wiki_text_id")) Then
' If e.CommandName = "RemovePicture" Then
' Dim wikiGraphicId As Integer = Convert.ToInt32(gvAddEditPicture.DataKeys(Convert.ToInt32(e.CommandArgument)).Value.ToString())
' Dim wikiGraphic As WikiGraphic = Nothing
' Try
' wikiGraphic = WikiGraphicsBLL.GetByWikiGraphicId(wikiGraphicId)
' WikiGraphicsBLL.DeleteWikiGraphics(wikiGraphicId)
' Catch ex As Exception
' 'TODO: Show user friendly error here
' ' Log here
' If ex.InnerException IsNot Nothing Then
' Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
' Else
' Logger.WriteToErrorLog(ex.Message)
' End If
' End Try
' If wikiGraphic IsNot Nothing Then
' Dim fileName As String = wikiGraphic.FileName
' Dim fileExtension As String = wikiGraphic.FileExtension
' Dim imagePath As String = Server.MapPath(_imgPath & fileName + fileExtension)
' Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & fileName + fileExtension)
' If System.IO.File.Exists(imagePath) Then
' System.IO.File.Delete(imagePath)
' End If
' If System.IO.File.Exists(thumbNailPath) Then
' System.IO.File.Delete(thumbNailPath)
' End If
' End If
' ElseIf e.CommandName = "Download" Then
' Dim wikiGraphicId As Integer = Convert.ToInt32(gvAddEditPicture.DataKeys(Convert.ToInt32(e.CommandArgument)).Value.ToString())
' Dim wikiGraphic As WikiGraphic = Nothing
' Try
' wikiGraphic = WikiGraphicsBLL.GetByWikiGraphicId(wikiGraphicId)
' Catch ex As Exception
' 'TODO: Show user friendly error here
' ' Log here
' If ex.InnerException IsNot Nothing Then
' Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
' Else
' Logger.WriteToErrorLog(ex.Message)
' End If
' End Try
' Dim fileName As String = wikiGraphic.FileName
' Dim fileExtension As String = wikiGraphic.FileExtension
' Dim imagePath As String = Server.MapPath(_imgPath & fileName + fileExtension)
' Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & fileName + fileExtension)
' If System.IO.File.Exists(imagePath) Then
' ' System.IO.File.Delete(imagePath)
' 'End If
' 'If System.IO.File.Exists(thumbNailPath) Then
' ' System.IO.File.Delete(thumbNailPath)
' Dim strRequest As String = imagePath '-- if something was passed to the file querystring
' If strRequest <> "" Then 'get absolute path of the file
' 'Dim path As String = Server.MapPath(strRequest) 'get file object as FileInfo
' Dim file As System.IO.FileInfo = New System.IO.FileInfo(strRequest) '-- if the file exists on the server
' If file.Exists Then 'set appropriate headers
' Response.Clear()
' Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
' Response.AddHeader("Content-Length", file.Length.ToString())
' Response.ContentType = ReturnExtension(file.Extension.ToLower())
' Response.WriteFile(file.FullName)
' Response.End() 'if file does not exist
' Else
' Response.Write("This file does not exist.")
' End If 'nothing in the URL as HTTP GET
' Else
' Response.Write("Please provide a file to download.")
' End If
' End If
' End If
'Else
If e.CommandName = "RemovePicture" Then
Dim wikiGraphicId As Integer = Convert.ToInt32(gvAddEditPicture.DataKeys(Convert.ToInt32(e.CommandArgument)).Values(0).ToString())
Dim d_physical_file_name As String = gvAddEditPicture.DataKeys(Convert.ToInt32(e.CommandArgument)).Values(1).ToString()
Try
WikiGraphicsBLL.DeleteWikiGraphicsPhysicalfilename(d_physical_file_name)
Catch ex As Exception
'TODO: Show user friendly error here
' Log here
If ex.InnerException IsNot Nothing Then
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
Else
Logger.WriteToErrorLog(ex.Message)
End If
End Try
Dim wikiGraphic As WikiGraphic = Nothing
Try
wikiGraphic = WikiGraphicsBLL.GetByTempWikiGraphicId(wikiGraphicId)
WikiGraphicsBLL.TempDeleteWikiGraphicsbyGraphicID(wikiGraphicId)
Catch ex As Exception
'TODO: Show user friendly error here
' Log here
If ex.InnerException IsNot Nothing Then
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
Else
Logger.WriteToErrorLog(ex.Message)
End If
End Try
If wikiGraphic IsNot Nothing Then
Dim fileName As String = wikiGraphic.FileName
Dim fileExtension As String = wikiGraphic.FileExtension
Dim physicalFileName As String = wikiGraphic.PhysicalFileName
Dim imagePath As String = Server.MapPath(_imgPath & physicalFileName + fileExtension)
Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & physicalFileName + fileExtension)
'If System.IO.File.Exists(imagePath) Then
' System.IO.File.Delete(imagePath)
'End If
'If System.IO.File.Exists(thumbNailPath) Then
' System.IO.File.Delete(thumbNailPath)
'End If
End If
ElseIf e.CommandName = "Download" Then
Dim wikiGraphicId As Integer = Convert.ToInt32(gvAddEditPicture.DataKeys(Convert.ToInt32(e.CommandArgument)).Value.ToString())
Dim wikiGraphic As WikiGraphic = Nothing
Try
If Request.QueryString("physicalfilename") IsNot Nothing Then
wikiGraphic = WikiGraphicsBLL.GetByWikiGraphicId(wikiGraphicId)
Else
wikiGraphic = WikiGraphicsBLL.GetByTempWikiGraphicId(wikiGraphicId)
End If
Catch ex As Exception
'TODO: Show user friendly error here
' Log here
If ex.InnerException IsNot Nothing Then
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
Else
Logger.WriteToErrorLog(ex.Message)
End If
End Try
Dim fileName As String = wikiGraphic.FileName
Dim fileExtension As String = wikiGraphic.FileExtension
Dim physicalFileName As String = wikiGraphic.PhysicalFileName
Dim imagePath As String = Server.MapPath(_imgPath & physicalFileName + fileExtension)
Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & physicalFileName + fileExtension)
If System.IO.File.Exists(imagePath) Then
' System.IO.File.Delete(imagePath)
'End If
'If System.IO.File.Exists(thumbNailPath) Then
' System.IO.File.Delete(thumbNailPath)
Dim strRequest As String = imagePath '-- if something was passed to the file querystring
If strRequest <> "" Then 'get absolute path of the file
'Dim path As String = Server.MapPath(strRequest) 'get file object as FileInfo
Dim file As System.IO.FileInfo = New System.IO.FileInfo(strRequest) '-- if the file exists on the server
If file.Exists Then 'set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment;filename=""" & fileName & fileExtension & """")
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = ReturnExtension(file.Extension.ToLower())
Response.WriteFile(file.FullName)
Response.End() 'if file does not exist
Else
Response.Write("This file does not exist.")
End If 'nothing in the URL as HTTP GET
Else
Response.Write("Please provide a file to download.")
End If
End If
End If
'End If
'If Not String.IsNullOrEmpty(Session("update_wiki_text_id")) Then
'BindGridFromOrg(CInt(Session("update_wiki_text_id")))
'Else
BindGrid(temp_text_id)
'End If
End Sub
Private Function ReturnExtension(ByVal fileExtension As String) As String
Select Case fileExtension
Case ".htm", ".html", ".log"
Return "text/HTML"
Case ".txt"
Return "text/plain"
Case ".doc"
Return "application/ms-word"
Case ".tiff", ".tif"
Return "image/tiff"
Case ".png", ".png"
Return "image/png"
Case ".asf"
Return "video/x-ms-asf"
Case ".avi"
Return "video/avi"
Case ".zip"
Return "application/zip"
Case ".xls", ".csv"
Return "application/vnd.ms-excel"
Case ".gif"
Return "image/gif"
Case ".jpg", ".JPG", "jpeg"
Return "image/jpeg"
Case ".bmp"
Return "image/bmp"
Case ".wav"
Return "audio/wav"
Case ".mp3"
Return "audio/mpeg3"
Case ".mpg", "mpeg"
Return "video/mpeg"
Case ".rtf"
Return "application/rtf"
Case ".asp"
Return "text/asp"
Case ".pdf"
Return "application/pdf"
Case ".fdf"
Return "application/vnd.fdf"
Case ".ppt"
Return "application/mspowerpoint"
Case ".dwg"
Return "image/vnd.dwg"
Case ".msg"
Return "application/msoutlook"
Case ".xml", ".sdxl"
Return "application/xml"
Case ".xdp"
Return "application/vnd.adobe.xdp+xml"
Case Else
Return "application/octet-stream"
End Select
End Function
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
Try
WikiGraphicsBLL.DeleteTempWikiGraphicsByNotSave(temp_text_id)
'WikiGraphicsBLL.TempDeleteWikiGraphics(temp_text_id)
Catch ex As Exception
'TODO: Show user friendly error here
' Log here
If ex.InnerException IsNot Nothing Then
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
Else
Logger.WriteToErrorLog(ex.Message)
End If
End Try
'Session.RemoveAll()
'Session.Abandon()
Session("TempWikiID") = temp_text_id
'Response.Redirect("~/wiki/New.aspx?Id=" & temp_text_id)
If temp_text_id > 0 Then
Response.Redirect("~/wiki/New.aspx?Id=" & temp_text_id & "&nbCount=" & Request.QueryString("nbCount") & "&nbpCount=" & Request.QueryString("nbpCount") & "&nfCount=" & Request.QueryString("nfCount") & "&nfpCount=" & Request.QueryString("nfpCount") & "&ncCount=" & Request.QueryString("ncCount") & "&ncpCount=" & Request.QueryString("ncpCount") & "&nbcCount=" & Request.QueryString("nbcCount") & "&nbcpCount=" & Request.QueryString("nbcpCount") & "&Edit=" & edit & "&OrgId=" & orgID & "&eguid=" & eguid)
Else
'Session("id") = wiki_text_id
Response.Redirect("~/wiki/New.aspx?WikiId=" & wiki_text_id & "&nbCount=" & Request.QueryString("nbCount") & "&nbpCount=" & Request.QueryString("nbpCount") & "&nfCount=" & Request.QueryString("nfCount") & "&nfpCount=" & Request.QueryString("nfpCount") & "&ncCount=" & Request.QueryString("ncCount") & "&ncpCount=" & Request.QueryString("ncpCount") & "&nbcCount=" & Request.QueryString("nbcCount") & "&nbcpCount=" & Request.QueryString("nbcpCount") & "&Edit=" & edit & "&OrgId=" & orgID & "&eguid=" & eguid)
' Response.Redirect("~/wiki/New.aspx")
End If
End Sub
Private Function FileFormat(ByVal fileExtension As String) As String
Select Case fileExtension
Case ".htm", ".html", ".log"
Return "Text files"
Case ".txt"
Return "Text files"
Case ".doc", ".docx"
Return "Word documents"
Case ".tiff", ".tif"
Return "Image files"
Case ".png", ".png"
Return "Image files"
Case ".asf"
Return "Video files"
Case ".avi"
Return "Audio/video files"
Case ".zip"
Return "zip files"
Case ".xls", ".xlsx", ".csv"
Return "Excel files"
Case ".gif"
Return "Image files"
Case ".jpg", ".JPG", "jpeg"
Return "Image files"
Case ".bmp"
Return "Image files"
Case ".wav"
Return "Audio files"
Case ".wma"
Return "Audio files"
Case ".mp3"
Return "Audio files"
Case ".mpg", "mpeg"
Return "video files"
Case ".rtf"
Return "Rich Text files"
Case ".asp"
Return "Text files"
Case ".pdf"
Return "PDF files"
Case ".fdf"
Return "application/vnd.fdf"
Case ".ppt", ".pptx"
Return "PowerPoint files"
Case ".dwg"
Return "Image files"
Case ".msg"
Return "msoutlook"
Case ".xml", ".sdxl"
Return "Xml files"
Case ".xdp"
Return "application/vnd.adobe.xdp+xml"
Case Else
Return "Other files"
End Select
End Function
Protected Sub UpdateImageByPhysicalFileName(ByVal physical_file_name As String, ByVal graphicId As Integer)
Dim file As HttpPostedFile
Dim fileNameDB As String
Dim fileExt As String
Dim caption As String
'Dim replace As String
Dim image_guid As String
Dim i As Integer = 0
For Each key As String In Request.Files.Keys
file = Request.Files(key)
If file IsNot Nothing AndAlso file.ContentLength > 0 Then
i = i + 1
fileName = Path.GetFileName(file.FileName)
_imagename = fileName.Split(_split)
'fileNameDB = _imagename(0)
fileNameDB = Path.GetFileNameWithoutExtension(file.FileName)
caption = txt1.InnerText.ToString()
'If (i = 1) Then
' caption = txt1.InnerText.ToString()
'Else
' replace = key.Replace("file", String.Empty)
' 'counter = Integer.Parse(replace.Replace("}", String.Empty))
' caption = Request.Form("txtDescription" & replace.ToString())
'End If
_validPhotoFormats = _photoformat.Split(_seperator)
fileExt = System.IO.Path.GetExtension(file.FileName)
For Each ext As String In _validPhotoFormats
If ext = fileExt Then
_isflag = True
Exit For
Else
_isflag = False
End If
Next
If _isflag = True Then
image_guid = Guid.NewGuid.ToString()
file.SaveAs(Server.MapPath(_imgPath & image_guid & fileExt))
Dim thumbNailPath As String = Server.MapPath(_thumbNailPath & image_guid & fileExt)
Using img As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(_imgPath & image_guid & fileExt))
Dim thbWidth As Integer = img.Width
Dim thbHeight As Integer = img.Height
If thbWidth > thbHeight Then
_thumbNailWidth = 100
_thumbNailHeight = ((thbHeight * 100) / thbWidth)
ElseIf thbHeight > thbWidth Then
_thumbNailHeight = 100
_thumbNailWidth = ((thbWidth * 100) / thbHeight)
ElseIf thbHeight = thbWidth Then
_thumbNailHeight = 100
_thumbNailWidth = 100
End If
Using ImgThnail As System.Drawing.Image = New Bitmap(img, _thumbNailWidth, _thumbNailHeight)
ImgThnail.Save(thumbNailPath, img.RawFormat)
ImgThnail.Dispose()
End Using
img.Dispose()
End Using
Dim wikiGraphics As WikiGraphic = New WikiGraphic()
wikiGraphics.FileName = fileNameDB
wikiGraphics.PhysicalFileName = image_guid
wikiGraphics.FileExtension = fileExt
wikiGraphics.Caption = caption
wikiGraphics.WikiTextId = graphicId
For Each ext As String In _validPhotoFormats
If ext = fileExt Then
wikiGraphics.FileFormat = "Image files"
End If
Next
Try
WikiGraphicsBLL.UpdateWikiGraphicsImageByPhysicalFileName(wikiGraphics)
lblStatusMessage.CssClass = "success"
lblStatusMessage.Text = "Picture Updated successfully"
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
Else
arrayList.Add(fileName)
countArray = arrayList.Count
If file1.PostedFile.ContentLength > 0 Then
Try
image_guid = Guid.NewGuid.ToString()
file.SaveAs(Server.MapPath(_imgPath & image_guid & fileExt))
Dim wikiGraphics As WikiGraphic = New WikiGraphic()
wikiGraphics.FileName = fileNameDB
wikiGraphics.PhysicalFileName = image_guid
wikiGraphics.FileExtension = fileExt
wikiGraphics.Caption = caption
wikiGraphics.WikiTextId = wiki_text_id
wikiGraphics.FileFormat = FileFormat(fileExt)
Try
WikiGraphicsBLL.tempInsertWikiGraphics(wikiGraphics, True)
lblStatusMessage.CssClass = "success"
lblStatusMessage.Text = "File updated successfully"
Catch ex As Exception
If ex.InnerException Is Nothing Then
Logger.WriteToErrorLog(ex.Message)
Else
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
End If
End Try
Catch ex As Exception
lblStatusMessage.Text = "Error Saving file."
End Try
End If
End If
End If
Next
ShowUpdatedImage(graphicId)
End Sub
Protected Sub ShowUpdatedImage(ByVal wiki_graphic_id As Integer)
Dim dtUpdatedImage As DataTable
Try
dtUpdatedImage = WikiGraphicsBLL.WikiGraphicsGetImageByGraphicId(wiki_graphic_id)
gvAddEditPicture.DataSource = dtUpdatedImage
Catch ex As Exception
If ex.InnerException IsNot Nothing Then
Logger.WriteToErrorLog(ex.Message, ex.InnerException.Message)
Else
Logger.WriteToErrorLog(ex.Message)
End If
End Try
gvAddEditPicture.DataBind()
End Sub
End Class