/******************************\ * Fill FileExplorer ListView * \******************************/ private void FillFileExplorerListView() { DataSet fileDataSet = new DataSet(); ; // result of DB request (get download dates). /* If not parent directory, add "Parent directory" */ if (_CurrentDirectory.Get_IsRoot() == false) { ListViewItem item = new ListViewItem(); item.SubItems[0].Text = "Parent Directory"; item.SubItems.Add("-"); item.SubItems.Add("-"); item.SubItems.Add("-"); item.ImageIndex = 2; FileExplorerListView.Items.AddRange(new ListViewItem[] { item }); } /* Fill Directories */ foreach (Directory dir in _CurrentDirectory.Get_FoldersList()) { ListViewItem item = new ListViewItem(); item.SubItems[0].Text = dir.Get_Name().Replace("%20"," "); item.SubItems.Add("-"); item.SubItems.Add("-"); item.SubItems.Add("-"); item.ImageIndex = 1; FileExplorerListView.Items.AddRange(new ListViewItem[] { item }); } /* Get eventual modification date of files */ try { FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient(); int regionID = service.Get_region_id(_ConnectedRegion.Get_RegionName()); fileDataSet = service.Get_files_download_date(regionID); service.Close(); } catch (Exception ex) { KryptonMessageBox.Show(ex.ToString()); } /* Fill files */ foreach (File file in _CurrentDirectory.Get_FilesList()) { Boolean downloaded = false; /* Set Name, size, date of modification */ ListViewItem item = new ListViewItem(); item.SubItems[0].Text = file.Get_Name().Replace("%20", " "); item.SubItems.Add(file.Get_Size().ToString() + " Ko"); item.SubItems.Add(file.Get_Timestamp().ToString()); /* Set icon */ if (file.Get_Name().Contains(".xlsx") || file.Get_Name().Contains(".xls")) item.ImageIndex = 4; else if (file.Get_Name().Replace(".ZIP",".zip").Contains(".zip") || file.Get_Name().Contains(".tar") || file.Get_Name().Contains(".7z")) item.ImageIndex = 5; else if (file.Get_Name().Contains(".rar")) item.ImageIndex = 6; else item.ImageIndex = 0; /* Check if file (with it's associated region) has already been downloaded. If yes, color it. */ foreach (DataRow row in fileDataSet.Tables[0].Rows) { if (row["name"].ToString().Equals(file.Get_Name())) { item.SubItems.Add(row["max(download_date)"].ToString()); item.BackColor = Color.LemonChiffon; downloaded = true; break; } } if (!downloaded) item.SubItems.Add("-"); FileExplorerListView.Items.AddRange(new ListViewItem[] { item }); } /* Sort by modification date */ //FileExplorerListView.ListViewItemSorter = new ListViewItemComparer(e.Column, FileExplorerListView.Sorting); FileExplorerListView.Sorting = SortOrder.Descending; FileExplorerListView.SetSortIcon(2, SortOrder.Descending); FileExplorerListView.ListViewItemSorter = new ListViewItemComparer(2, FileExplorerListView.Sorting); }
/*******************************\ * Add download historic on DB * \*******************************/ public void AddDownloadLog() { int regionID = 0; int fileID = 0; try { /* Create service */ FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient(); /* Create Timestamp of download date */ System.DateTime dateOfDownload = System.DateTime.Now; string dateOfDownloadTreated = dateOfDownload.ToString("yyyy-MM-dd HH':'mm':'ss"); /* Get region_id of downloaded file */ regionID = service.Get_region_id(_ConnectedRegion.Get_RegionName()); if (regionID == 0) throw new Exception("Region doesn't exist !"); foreach (File downloadedFile in _FilesToDownload) { /* Check if file (with it's associated region) already exists, if not, create one and get its ID. */ fileID = service.Get_file_id(downloadedFile.Get_Name(), regionID); if (fileID == 0) { service.Add_file(regionID, downloadedFile.Get_Name()); fileID = service.Get_file_id(downloadedFile.Get_Name(), regionID); } /* Add historic in DB */ service.Add_download_per_region(regionID, fileID, dateOfDownloadTreated); } /* Update FileExplorer ListView */ FileExplorerListView.Items.Clear(); FillFileExplorerListView(); /* Close service */ service.Close(); /* Reset targets paths & set labels*/ _FtpAPI.Reset_DownloadedFilesTarget(); DirFileCounterLabel.Text = _CurrentDirectory.Get_FoldersList().Count + " dir / " + _CurrentDirectory.Get_FilesList().Count + " files"; FTPBrowserHeaderGroup.ValuesPrimary.Heading = "FTP Browser (" + _ConnectedRegion.Get_RegionName() + ") :"; } catch (Exception ex) { KryptonMessageBox.Show(ex.ToString()); } }