1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
Imports System.Data.SqlClient Imports System Imports Microsoft.VisualBasic.FileIO Public Class cls_torikomi Public Property p_no_filepass As String = "" Public Property p_yes_filepass As String = "" Dim struser As String Dim FileName As String Dim onegyoutobasu As Boolean ''' <summary> ''' リストを読み込む ''' </summary> ''' <param name="s1"></param> ''' <remarks></remarks> Public Sub New(ByVal s1 As List(Of String), struser2 As Object, mushi As Boolean) struser = mo_ck.str(struser2) onegyoutobasu = mushi '==通常はTRUE For Each s As String In s1 FileName = s.Substring(s.LastIndexOf("\") + 1, s.Length - (s.LastIndexOf("\") + 1)) If funOnepasskoushindekiru(s) = True Then '===csv取り込み処理を行う subCSVtorimkomi(s) p_yes_filepass = s & ControlChars.CrLf '===dekinakattamono Else p_no_filepass = s & ControlChars.CrLf '===dekinakattamono End If Next End Sub ''' <summary> ''' 更新ができるものはtrue ''' </summary> ''' <param name="strPass"></param> ''' <returns></returns> ''' <remarks></remarks> Private Function funOnepasskoushindekiru(strPass As String) As Boolean Dim b As Boolean = False Dim conn As New SqlConnection conn.ConnectionString = My.Settings.hozenIkkatuConnectionString Dim cmd As New SqlCommand cmd.CommandType = CommandType.Text cmd.Connection = conn cmd.CommandText = "SELECT COUNT(*) FROM t_torikomirireki WHERE csvName = " & mo_ck.funStrCkN_Null(FileName) Dim result As Object Dim previousConnectionState As ConnectionState = conn.State Try If conn.State = ConnectionState.Closed Then conn.Open() End If result = cmd.ExecuteScalar() Finally If previousConnectionState = ConnectionState.Closed Then conn.Close() End If End Try If mo_ck.funIntCk(result) > 0 Then b = False Else b = True funTorikonizumisyori(strPass) End If Return b End Function ''' <summary> ''' 取り込み済みへ新規追加 ''' </summary> ''' <param name="p"></param> ''' <returns></returns> ''' <remarks></remarks> Private Function funTorikonizumisyori(p As String) As Integer Dim t As New t_torikomirireki(FileName, p, Now, struser) Return t.funNewInpt(t.funidmax + 1) End Function Private Sub subCSVtorimkomi(fp As String) Dim torikomi_now As Date = Now Dim ta1 As taikei_db Using parser As New TextFieldParser(fp, System.Text.Encoding.GetEncoding("Shift_JIS")) parser.TextFieldType = FieldType.Delimited parser.SetDelimiters(",") While Not parser.EndOfData Dim r As String() = parser.ReadFields() If onegyoutobasu = False Then '===1行目飛ばさないとき '===テーブルにINPUTする処理は 別クラスtaikei_db です。 ta1 = New taikei_db(r(0), r(1), r(2), r(3), r(4), r(5), r(6), r(7), r(8), r(9), r(10), r(11), r(12), r(13), r(14), r(15), r(16), r(17), r(18), r(19), r(20), r(21), r(22), r(23), r(24), r(25), torikomi_now, FileName) ta1.funNewInpt(ta1.funintIdmax + 1) Else '===1行目飛ばすとき onegyoutobasu = False End If End While End Using End Sub ''' <summary> ''' 履歴をファイル名で消す ''' </summary> ''' <param name="t_name"></param> ''' <returns></returns> Public Shared Function funrirekidell(t_name As String) As Integer Dim conn As New SqlConnection conn.ConnectionString = My.Settings.hozenIkkatuConnectionString Dim cmd As New SqlCommand cmd.CommandType = CommandType.Text cmd.Connection = conn cmd.CommandText = "DELETE FROM t_torikomirireki WHERE csvName = " & mo_ck.funStrCkN_Null(t_name) Dim rowCount As Integer Dim previousConnectionState As ConnectionState previousConnectionState = conn.State Try If conn.State = ConnectionState.Closed Then conn.Open() End If rowCount = cmd.ExecuteNonQuery() Finally If previousConnectionState = ConnectionState.Closed Then conn.Close() End If End Try Return rowCount End Function End Class |