public async void openBDTime(StorageFile fole) { string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, fole.Name); using (SqliteConnection db = new SqliteConnection($"Filename={dbpath}")) { db.Open(); SqliteCommand selectCommand = new SqliteCommand("SELECT * from Файлы", db); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { try { if (query.GetString(1).Split('_')[1] != "Test") { Debug.WriteLine(query.GetString(1)); DataColecF.Add(new ClassFileLT() { nomer = Convert.ToInt32(query.GetString(0)), nameFile = query.GetString(1), TimeOpen = query.GetString(3), TimeClose = query.GetString(4), nameRun = query.GetString(5) }); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } } }
private async void AppBarButton_Click(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".txt"); picker.FileTypeFilter.Add(".dat"); picker.FileTypeFilter.Add(".rtf"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { // Application now has read/write access to the picked file this.nameFile.Text = "Имя файла: " + file.Name; char[] rowSplitter = { '\r', '\n' }; string[] text = (await Windows.Storage.FileIO.ReadTextAsync(file)).Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < text.Length; i++) { string[] text1 = text[i].Split('\t'); try { if (text1[3] == String.Empty || text1[3] == null || text1[4] == String.Empty || text1[4] == null || text1[1].Split('_')[1] == "Test") { } else { DataColecF.Add(new ClassFileLT() { nomer = Convert.ToInt32(text1[0]), nameFile = text1[1], TimeOpen = text1[3], TimeClose = text1[4], nameRun = text1[5] }); } } catch (Exception ex) { MessageDialog messageDialog = new MessageDialog(ex.ToString()); await messageDialog.ShowAsync(); } } } else { this.nameFile.Text = "Файл не выбран"; } }
private async void AppBarButton_Click(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".txt"); picker.FileTypeFilter.Add(".dat"); picker.FileTypeFilter.Add(".rtf"); picker.FileTypeFilter.Add(".db"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { // Application now has read/write access to the picked file this.nameFile.Text = "Имя файла: " + file.Name; Debug.WriteLine(file.FileType); string err = String.Empty; char[] rowSplitter = { '\r', '\n' }; if (file.FileType != ".db") { string[] text = (await Windows.Storage.FileIO.ReadTextAsync(file)).Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < text.Length; i++) { string[] text1 = text[i].Split('\t'); try { if (text1[3] == String.Empty || text1[3] == null || text1[4] == String.Empty || text1[4] == null || text1[1].Split('_')[1] == "Test") { } else { DataColecF.Add(new ClassFileLT() { nomer = Convert.ToInt32(text1[0]), nameFile = text1[1], TimeOpen = text1[3], TimeClose = text1[4], nameRun = text1[5] }); } } catch (Exception ex) { MessageDialog messageDialog = new MessageDialog(ex.ToString()); await messageDialog.ShowAsync(); } } } else { try { StorageFile storageFile = await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting); //SqliteConnection db = new SqliteConnection("Data Source = " + file.Path); openBDTime(file); string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, file.Name); // StorageFile storageFile = await StorageFile.GetFileFromPathAsync(dbpath); // await storageFile.DeleteAsync(); } catch (Exception ex) { MessageDialog messageDialog = new MessageDialog(ex.Message); await messageDialog.ShowAsync(); } } } else { this.nameFile.Text = "Файл не выбран"; } }