//---------------------------------------------------------------------------------------------- //Static //---------------------------------------------------------------------------------------------- #region static public static List <ImageCar> GetList(NpgsqlConnection connection, Vehicle vehicle) { List <ImageCar> images = new List <ImageCar>(); if (vehicle.CarId.HasValue) { NpgsqlCommand command = new NpgsqlCommand($"Select image_id, picture, kind, main, description, accident from {TABLE} where car_id = :cid", connection); command.Parameters.AddWithValue("cid", vehicle.CarId.Value); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ImageCar imageCar = new ImageCar(connection, vehicle); imageCar.ImageId = reader.GetInt64(0); imageCar.Picture = reader.IsDBNull(1) ? null : (byte[])reader.GetValue(1); imageCar.Kind = reader.IsDBNull(2) ? null : reader.GetString(2); imageCar.Main = reader.IsDBNull(3) ? false : reader.GetBoolean(3); imageCar.Description = reader.IsDBNull(4) ? null : reader.GetString(4); imageCar.Accident = reader.IsDBNull(5) ? false : reader.GetBoolean(5); MemoryStream memoryStream = new MemoryStream(imageCar.Picture); imageCar.Image = Image.FromStream(memoryStream); memoryStream.Close(); images.Add(imageCar); } reader.Close(); } return(images); }
public static ImageCar GetMain(NpgsqlConnection connection, long?CarId) { ImageCar image = null; if (CarId.HasValue) { NpgsqlCommand command = new NpgsqlCommand($"Select image_id, picture, kind, main, description from {TABLE} where car_id = :cid and main = true", connection); command.Parameters.AddWithValue("cid", CarId.Value); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { image = new ImageCar(connection); image.ImageId = reader.GetInt64(0); image.Picture = reader.IsDBNull(1) ? null : (byte[])reader.GetValue(1); image.Kind = reader.IsDBNull(2) ? null : reader.GetString(2); image.Main = reader.IsDBNull(3) ? false : reader.GetBoolean(3); image.Description = reader.IsDBNull(4) ? null : reader.GetString(4); image.Accident = reader.IsDBNull(5) ? false : reader.GetBoolean(5); MemoryStream memoryStream = new MemoryStream(image.Picture); image.Image = Image.FromStream(memoryStream); memoryStream.Close(); } reader.Close(); } return(image); }
public static void ExportToPdfQuerMitPic(List <Rent> rents, string filepath, NpgsqlConnection connection) { Document document = new Document(); document.SetPageSize(PageSize.A4.Rotate()); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream($"{filepath}", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 12); iTextSharp.text.Font fontHeader = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 20); PdfPTable table = new PdfPTable(8); PdfPRow row = null; table.HorizontalAlignment = 0; table.WidthPercentage = 100; PdfPCell cell = new PdfPCell(new Phrase(("Vermietungen"), fontHeader)); cell.Colspan = 8; cell.HorizontalAlignment = 1; table.AddCell(cell); cell.Colspan = 8; iTextSharp.text.Image image = null; foreach (Rent r in rents) { if (rents.Count > 0) { System.Drawing.Image pic = ImageCar.GetMainImage(connection, r.CarId); if (pic != null) { image = iTextSharp.text.Image.GetInstance(pic, ImageFormat.Jpeg); PdfPCell imageCell = new PdfPCell(image); imageCell.Colspan = 1; imageCell.Border = 0; table.AddCell(image); } else { table.AddCell(new Phrase("", font5)); } table.AddCell(new Phrase(r.RentNo, font5)); } } document.Add(table); document.Close(); }