Buongiorno,
mi sto avvicinando ora alla programmazione ad oggetti, ma ho qualche difficoltà generale ad applicare la teoria e nell'uso degli oggetti.
Devo creare un programma che mi visualizzi in una listbox o Listview una serie di etichette corrispondenti a dei file nominati come annomesegiorno.sep, che mi dia la possibilità di selezionarli e copiarli in una cartella di destinazione.
Es. Nome dei file: 20110423.sep
Ex. Nome delle etichette nella Listbox o Listview: 23 Aprile 2011
Quando li seleziono sella listbox o Listview per copiarli però avrei necessità che si selezionasse il file e non l'etichetta da me creata.
Devo prima creare due array con in uno i nomi dei file e nell'altro le etichette corrispondenti e linkarli in qualche modo?Creo un dataset?o come posso gestirli?
Procedura estrapolazione giorno mese anno dal nome file senza estensione(strYearMonthDay):
Procedura popolamento lista con nomi etichette(strYearMonthDayFull):codice:Public Shared Function DayConvert(ByVal strYearMonthDay, ByRef strYearMonthDayFull) Dim strDay As String Dim strMonth As String Dim strYear As String 'recupera anno, mese e giorno e compone la stringa "23 Aprile 2011" strYear = strYearMonthDay.Substring(0, 4) strMonth = strYearMonthDay.Substring(4, 2) strDay = strYearMonthDay.Substring(6, 2) strYearMonthDayFull = strDay & " " & MonthName(strMonth) & " " & strYear Return strYearMonthDayFull End Function
Procedura copia File:codice:Public Shared Sub AddLst(ByVal strPathSource, ByVal strFileExtension, ByVal lstFileSep, _ ByVal lstWFileSep, ByVal strYearMonthDay, ByVal strYearMonthDayFull, ByRef strToday) 'Apri la cartella di origine ed elenca i file Dim strExtension As String 'ESTENSIONE dei file nella cartella 'Analizza ciascun file e se ha l'estensione corretta popola la lista For Each strFiles As String In My.Computer.FileSystem.GetFiles(strPathSource) strExtension = System.IO.Path.GetExtension(strFiles) If strExtension = "." & strFileExtension Then ' Se sono file SEP mostrali nella lista strYearMonthDay = System.IO.Path.GetFileNameWithoutExtension(strFiles) 'Richiama la funzione per convertire il nome file in data ClassOperazioni.DayConvert(strYearMonthDay, strYearMonthDayFull) 'Converte i file in stringa giorno Mese anno es. 23 Settembre 2011 lstFileSep.Items.Add(strYearMonthDayFull) 'ClassOperazioni.oggi() 'ClassOperazioni.colora(lstWFileSep, strToday, strYearMonthDay, strYearMonthDayFull) lstWFileSep.Items.Add(strYearMonthDayFull) End If Next End Sub
Un altro quesito che avrei è:codice:Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCopyFile.Click Dim i As Integer 'variabile contatore ' assegna TOTALE file selezionati (lstFileSep.SelectedIndices.Count) intTotFilesSelected = lstFileSep.SelectedItems.Count 'Se la lista contiene file selezionati procede alla copia If intTotFilesSelected > 0 Then For i = 0 To intTotFilesSelected - 1 MsgBox("intTotFilesSelected: " & intTotFilesSelected) 'inizializza la variabile con gli elementi selezionati - uno alla volta strFileSelected = lstFileSep.SelectedItems(i) 'MsgBox("strFileSelected: " & strFileSelected) 'preleva l'indice dell'oggetto selezionato strFileSelectedIndices = lstFileSep.SelectedIndices(i) 'MsgBox("strFileSelectedindices: " & strFileSelectedIndices) 'preleva il nome del file strFileSelectedName = System.IO.Path.GetFileName(strFileSelected) 'MsgBox("strFileSelectedName: " & strFileSelectedName) 'Fa la copia del file Nella cartella di destinazione My.Computer.FileSystem.CopyFile(strFileSelectedName, strPathDestination) '& strFileName) _ 'FileIO.UIOption.AllDialogs, _ 'FileIO.UICancelOption.DoNothing) Next MsgBox("File COPIATI correttamente...") 'richiama funzione pulisci la lista classGestioneLista.ClearLst(lstFileSep, lstWFileSep) 'richiama funzione popola la lista classGestioneLista.AddLst(strPathSource, strFileExtension, lstFileSep, lstWFileSep, strYearMonthDay, strYearMonthDayFull, strToday) End If End Sub
Prelevo le impostazioni del programma da un file XML; per caricare le impostazioni è preferibile usare un dataset, un array o altro?
Grazie
Paolo

Rispondi quotando
il tuo codice per ciclare gli elementi selezionati nella listbox, il resto lo prelevo dal dataset in base all' indice dell' elemento della listbox.
