Imports AcggDoc.Acgg.dbClass

Namespace Acgg

    Public Class AddDoc
        Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Protected WithEvents Label17 As System.Web.UI.WebControls.Label
        Protected WithEvents Label18 As System.Web.UI.WebControls.Label
        Protected WithEvents Textbox1 As System.Web.UI.WebControls.TextBox
        Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile
        Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton
        Protected WithEvents lblError As System.Web.UI.WebControls.Label
        Protected WithEvents txtDesc As System.Web.UI.WebControls.TextBox
        Protected WithEvents lnkClose As System.Web.UI.WebControls.LinkButton

        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region

        Dim sConnString As String

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            'sConnString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=" & Server.MapPath("AcggDoc.mdb") & ";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False"
            'lnkClose.Attributes.Add("onclick", "javascript:window.opener.location.reload();window.close();")
            lnkClose.Attributes.Add("onclick", "javascript:window.opener.document.location=window.opener.document.location.href;javascript:window.close();")

        End Sub

        Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick
            If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 And Trim(txtDesc.Text) <> "" Then

                Dim objDBClass As New Acgg.dbClass
                Dim objRead As OleDb.OleDbDataReader
                Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)

                '-------------************** It should be changed *****************--------------
                Dim SaveLocation As String = Server.MapPath("Acggdoc\Orders") & "\" & fn
                'Dim SaveLocation As String = "d:\Orders" & "\" & fn
                '-------------************** It should be changed *****************--------------

                'Dim SaveLocation As String = Server.MapPath(Request("FileNo")) & "\" & fn
                Dim strSQL As String
                Dim OrdId As Integer

                Try

                    File1.PostedFile.SaveAs(SaveLocation)
                    lblError.ForeColor = System.Drawing.Color.Green
                    lblError.Text = "The following file has been uploaded - " & fn

                    strSQL = "SELECT OrdId FROM NewOrders WHERE FileNo='" & Request("FileNo") & "'"
                    objDBClass.OpenDB()
                    objRead = objDBClass.retReader(strSQL)
                    If objRead.HasRows Then
                        objRead.Read()
                        OrdId = objRead("OrdId")
                    End If
                    objRead.Close()

                    OrdId = Request.QueryString("FileNo")

                    '---- insert into Doc table ---
                    strSQL = "INSERT INTO Doc(FileNo,[Desc],Location,[Date],PubBy,OrdId) VALUES('" & fn & "','" & txtDesc.Text & "','" & "AcggDoc\Orders\" & fn & "',Now(),'A-000001'," & OrdId & ")"
                    objDBClass.boolManipulateData(strSQL)
                    '------------------------------
                    txtDesc.Text = ""
                    objDBClass.CloseDB()

                Catch Exc As Exception
                    lblError.ForeColor = System.Drawing.Color.Red
                    lblError.Text = lblError.Text & "Error: " & Exc.Message
                Finally
                    objRead = Nothing
                    objDBClass = Nothing
                End Try
            Else
                lblError.ForeColor = System.Drawing.Color.Red
                lblError.Text = "Please select a file to upload.Also provide some file description"
            End If
        End Sub


    End Class
End Namespace