Private Sub ExportCostSheetData() InsertRow("") InsertRow("Run 2:Export CostingSheet=========================") InsertRow("Status:System Connectting DataBase!") If ConnJWeb() = False Or ConnJWeb2() = False Then InsertRow("Status:System Connectting DataBase fialed!") AddRow("", "", "Status:System Connectting DataBase fialed!", "system") Exit Sub ' GoTo End1 End If Dim CurrentComp As Integer Dim strDestFolder As String = "\\1.1.1.1\BogartCosting\CostSheet\" Dim rsR As New ADODB.Recordset Dim Flag As String = selectValue(" select top 1 flag from CostingSheetFileInfo ", adoJWeb, 0) Try Dim strFiles() As String = Directory.GetFiles(strDestFolder) Dim strFile As String Dim AbsolutePath As String Dim strFilePresent As String rsR.Open("select * from CostingSheetFileInfo ", adoJWeb, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) For Each strFile In strFiles strFilePresent = Path.GetFileName(strFile) AbsolutePath = strDestFolder & strFilePresent Dim netCmd As New OleDb.OleDbCommand("P_DeleteRecord", netJWeb) netCmd.CommandType = CommandType.StoredProcedure netCmd.Parameters.Add("@FileName", strFilePresent) netCmd.Parameters.Add("@FileType", "Complete Costing") netCmd.ExecuteNonQuery() rsR.AddNew() rsR.Fields("FileName").Value = strFilePresent rsR.Fields("FileType").Value = "Complete Costing" rsR.Fields("AbsolutePath").Value = AbsolutePath rsR.Fields("LastUpdateDate").Value = Now() rsR.Fields("Flag").Value = IIf(Flag = 0, "1", "0") rsR.Update() InsertRow(strFilePresent & "===OK!") CurrentComp = CurrentComp + 1 Me.ProgressBar1.Value = (CurrentComp / strFiles.Length) * 100 Next rsR.Close() Catch ex As Exception SendEmail() InsertRow("===Open Folder Fail===") InsertRow("End Time:" & Now) Exit Sub End Try adoJWeb.Execute("Update CostingSheetFileInfo set flag='" & IIf(Flag = 0, "1", "0") & "' where flag is null ") adoJWeb.Execute(" delete from CostingSheetFileInfo where flag='" & Flag & "'") ' InsertRow(" Total error records:" & strFiles.r & "") InsertRow("") InsertRow("***************** System export result *******************") InsertRow("") InsertRow("End Time:" & Now) InsertRow("***************************************************************") End Sub
vinson