public PDFContentView(int cIsso, int n) { InitializeComponent(); Title = $"ИССО №{cIsso}. Просмотр схемы"; using (var connection = new SqliteConnection(ConnectionClass.NewDatabasePath)) { try { var command = connection.CreateCommand(); command.CommandText = $"select * from I_SXEMA where C_ISSO={cIsso} and N={n} and SXEMA is not null order by N"; command.CommandTimeout = 30; command.CommandType = CommandType.Text; connection.Open(); using (var datareader = command.ExecuteReader()) { if (datareader.HasRows) { datareader.Read(); // Берем данные по фотографии var photo = Convert.FromBase64String(datareader.GetString(datareader.GetOrdinal("SXEMA"))); // Записываем файл в папку var newPath = $"{ConnectionClass.PathToSchemes}/{CommonStaffUtils.RandomNumber(1, 9999999)}.pdf"; if (!Directory.Exists(ConnectionClass.PathToSchemes)) { Directory.CreateDirectory(ConnectionClass.PathToSchemes); } File.WriteAllBytes(newPath, photo); //if (Device.RuntimePlatform == Device.Android) // PdfDocView.Source = $"file:///android_asset/pdfjs/web/viewer.html?file={WebUtility.UrlEncode(newPath)}"; //else // PdfDocView.Source = newPath; PdfDocView.Uri = newPath; } datareader.Dispose(); } command.Dispose(); } catch (Exception ex) { Debug.WriteLine($"Произошла ошибка в БД: {ex.Message} \nStackTrace: {ex.StackTrace}"); } finally { connection.Close(); } } }
private void AddPhotosAsync(int cIsso) { _dataInformation.Clear(); var page = new LoadingPopupPage("Подождите, идет загрузка фотографий...", true); Navigation.PushPopupAsync(page, false); Task.Factory.StartNew(() => { // Вытаскиваем информацию using (var connection = new SqliteConnection(ConnectionClass.NewDatabasePath)) { _dataInformation = new List <DataInformation>(); var command = connection.CreateCommand(); command.CommandText = $"select * from I_FOTO where C_ISSO={cIsso} and FOTO is not null order by N"; command.CommandTimeout = 30; command.CommandType = System.Data.CommandType.Text; connection.Open(); using (var datareader = command.ExecuteReader()) { if (datareader.HasRows) { while (datareader.Read()) { // Берем данные по фотографии var photo = DependencyService.Get <IMediaService>() .ResizeImage( Convert.FromBase64String(datareader.GetString(datareader.GetOrdinal("FOTO"))), CommonStaffUtils.StandardImageWidth, CommonStaffUtils.StandardImageHeight); var date = datareader["FOTO_DATE"] != DBNull.Value ? datareader.GetInt64(datareader.GetOrdinal("FOTO_DATE")) : 0; var info = datareader["TITR"] != DBNull.Value ? datareader.GetString(datareader.GetOrdinal("TITR")) : ""; var n = datareader["N"] != DBNull.Value ? datareader.GetInt32(datareader.GetOrdinal("N")) : 0; var newPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Personal)}/ISSO-I/{CommonStaffUtils.RandomNumber(1, 9999999)}"; if (!Directory.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Personal)}/ISSO-I")) { Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.Personal)}/ISSO-I"); } using (var fileStream = new FileStream(newPath, FileMode.OpenOrCreate, FileAccess.Write)) { fileStream.Write(photo, 0, photo.Length); } _dataInformation.Add(new DataInformation(info, date, photo, newPath, n)); } } datareader.Dispose(); } command.Dispose(); connection.Close(); } Device.BeginInvokeOnMainThread(() => { lv_photos.ItemsSource = _dataInformation; if (_dataInformation.Count <= 0) { Content = new Label { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, Text = "Фотографии данного сооружения отсутствуют." }; } Navigation.PopPopupAsync(); }); //// Добавляем контролы в StackLayout //foreach (DataInformation information in Data_Information) //{ // // Создаем ContentView // StackLayout contentViewPhoto = new StackLayout // { // VerticalOptions = LayoutOptions.Fill, // HorizontalOptions = LayoutOptions.Fill, // Orientation = StackOrientation.Vertical // }; // Image image = new Image // { // Margin = new Thickness(10, 10, 10, 0), // VerticalOptions = LayoutOptions.FillAndExpand, // HorizontalOptions = LayoutOptions.FillAndExpand, // Source = ImageSource.FromStream(() => new MemoryStream(information.Array)), // ClassId = String.Format("{0}", Data_Information.IndexOf(information)) // }; // var date_str = information.Date != 0 ? new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(information.Date).ToString("dd.MM.yyyy") : ""; // Label label = new Label // { // VerticalOptions = LayoutOptions.Start, // HorizontalOptions = LayoutOptions.Fill, // VerticalTextAlignment = TextAlignment.Start, // HorizontalTextAlignment = TextAlignment.Center, // Text = !date_str.Equals("") ? String.Format("{0}\n{1}", date_str, information.Info) : information.Info, // Margin = new Thickness(0, 10) // }; // var tap = new TapGestureRecognizer(); // tap.Tapped += (sender, e) => // { // ShowPictures(Convert.ToInt32((sender as View).ClassId)); // }; // image.GestureRecognizers.Add(tap); // BoxView boxView = new BoxView // { // HeightRequest = 1, // Margin = 1, // Opacity = 0.8, // BackgroundColor = Color.FromHex("Accent") // }; // // Добавляем в stacklayout наши фотографии с описанием // contentViewPhoto.Children.Add(image); // contentViewPhoto.Children.Add(label); // //contentViewPhoto.Children.Add(boxView); // Device.BeginInvokeOnMainThread(() => { image_container.Children.Add(contentViewPhoto); }); //} // Добавляем данные //Device.BeginInvokeOnMainThread(() => //{ // int index = 0; // foreach(StackLayout layout in image_container.Children) // { // var date_str = Data_Information[index].Date != 0 ? new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(Data_Information[index].Date).ToString("dd.MM.yyyy") : ""; // (layout.Children[0] as Image).Source = ImageSource.FromStream(() => new MemoryStream(Data_Information[index].Array)); // (layout.Children[1] as Label).Text = !date_str.Equals("") ? String.Format("{0}\n{1}", date_str, Data_Information[index].Info) : Data_Information[index].Info; // index++; // } //}); //Device.BeginInvokeOnMainThread(() => { OnSizeAllocated(App.Current.MainPage.Width, scroll_view_photo.Height); Navigation.PopPopupAsync(); }); }); }
private void AddThumbnailsAsync(int cIsso) { // Вытаскиваем информацию Task.Factory.StartNew(() => { var pathToDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/ISSO-I/"; // Чистим предыдущие фотки if (Directory.Exists(pathToDir)) { DependencyService.Get <ILocalFileProvider>().DeleteFilesFromDir(pathToDir); } using (var connection = new SqliteConnection(ConnectionClass.NewDatabasePath)) { try { _dataInformation = new List <DataInformation>(); var command = connection.CreateCommand(); command.CommandText = $"select * from I_SXEMA where C_ISSO={cIsso} and SXEMA is not null order by N"; command.CommandTimeout = 30; command.CommandType = System.Data.CommandType.Text; connection.Open(); using (var datareader = command.ExecuteReader()) { if (datareader.HasRows) { while (datareader.Read()) { // Берем данные по фотографии var photo = DependencyService.Get <IMediaService>() .ResizeImage( Convert.FromBase64String(datareader.GetString(datareader.GetOrdinal("PREVIEW"))), CommonStaffUtils.StandardImageWidth, CommonStaffUtils.StandardImageHeight); var date = datareader["SXEMA_DATE"] != DBNull.Value ? datareader.GetInt64(datareader.GetOrdinal("SXEMA_DATE")) : 0; var info = datareader["TITR"] != DBNull.Value ? datareader.GetString(datareader.GetOrdinal("TITR")) : ""; var n = datareader["N"] != DBNull.Value ? datareader.GetInt32(datareader.GetOrdinal("N")) : 0; var newPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Personal)}/ISSO-I/{CommonStaffUtils.RandomNumber(1, 9999999)}"; if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/ISSO-I/")) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/ISSO-I/"); } using (var fileStream = new FileStream(newPath, FileMode.OpenOrCreate, FileAccess.Write)) { fileStream.Write(photo, 0, photo.Length); } _dataInformation.Add(new DataInformation(info, date, photo, newPath, n)); } } datareader.Dispose(); } command.Dispose(); } catch (Exception ex) { Debug.WriteLine($"Произошла ошибка в БД: \n{ex.Message} \nStackTrace: {ex.StackTrace}"); } finally { connection.Close(); } } Device.BeginInvokeOnMainThread(() => { lv_schemes.ItemsSource = _dataInformation; if (_dataInformation.Count <= 0) { Content = new Label { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, Text = "Схемы для данного сооружения отсутствуют." }; } Navigation.PopPopupAsync(); }); // Добавляем данные в StackLayout //foreach (DataInformation information in dataInformation) //{ // // Создаем ContentView // StackLayout contentViewPhoto = new StackLayout // { // VerticalOptions = LayoutOptions.FillAndExpand, // HorizontalOptions = LayoutOptions.FillAndExpand, // Orientation = StackOrientation.Vertical, // }; // Image image = new Image // { // Margin = new Thickness(10, 10, 10, 0), // VerticalOptions = LayoutOptions.FillAndExpand, // HorizontalOptions = LayoutOptions.FillAndExpand, // Source = ImageSource.FromStream(() => new MemoryStream(information.Array)), // ClassId = String.Format("{0}", information.Image_source) // }; // var date_str = information.Date != 0 ? new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(information.Date).ToString("dd.MM.yyyy") : ""; // Label label = new Label // { // VerticalOptions = LayoutOptions.Start, // HorizontalOptions = LayoutOptions.Fill, // VerticalTextAlignment = TextAlignment.Start, // HorizontalTextAlignment = TextAlignment.Center, // Text = !date_str.Equals("") ? String.Format("{0}\n{1}", date_str, information.Info) : information.Info, // Margin = new Thickness(0, 10) // }; // var tap = new TapGestureRecognizer(); // tap.Tapped += (sender, e) => // { // ShowPDF(Convert.ToInt32((sender as View).ClassId)); // }; // image.GestureRecognizers.Add(tap); // BoxView boxView = new BoxView // { // HeightRequest = 1, // Margin = 1, // Opacity = 0.8, // BackgroundColor = Color.FromHex("Accent") // }; // // Добавляем в stacklayout наши фотографии с описанием // contentViewPhoto.Children.Add(image); // contentViewPhoto.Children.Add(label); // //contentViewPhoto.Children.Add(boxView); // Device.BeginInvokeOnMainThread(() => { thumb_container.Children.Add(contentViewPhoto); }); //} //Device.BeginInvokeOnMainThread(() => { OnSizeAllocated(App.Current.MainPage.Width, scroll_thumb.Height); Navigation.PopPopupAsync(); }); }); }