Beispiel #1
0
        private void pictureBoxVehicleImage_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                Image    image = null;
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (files.Length == 1)
                {
                    e.Effect = DragDropEffects.Copy;
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }

                image = Image.FromFile(files[0]);

                ImageCar imageCar = new ImageCar(this.connection, this.vehicle);
                imageCar.Accident    = false;
                imageCar.Main        = true;
                imageCar.Kind        = "Public";
                imageCar.Description = "";
                imageCar.Image       = image;

                foreach (ImageCar i in this.vehicle.Pictures)
                {
                    if (i.Main)
                    {
                        i.Main = false;
                        i.Save();
                    }
                }

                MemoryStream memoryStream = new MemoryStream();
                imageCar.Image.Save(memoryStream, ImageFormat.Png);
                memoryStream.Seek(0, SeekOrigin.Begin);
                memoryStream.Close();
                imageCar.Picture = memoryStream.GetBuffer();

                this.vehicle.Pictures.Add(imageCar);
                this.pictureBoxVehicleImage.Image = image;

                if (!this.vehicle.CarId.HasValue)
                {
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            this.timerRents.Enabled = false;
            Image image     = null;
            float top       = 10;
            float ratio     = 0;
            float nHeight   = 0;
            float topOffset = 0;
            Rent  rent      = null;

            Font fontStd   = new Font("Verdana", 10f, FontStyle.Regular);
            Font fontHead  = new Font("Arial Black", 20f, FontStyle.Regular);
            Font fontLabel = new Font("Verdana", 10f, FontStyle.Bold | FontStyle.Underline);

            e.Graphics.DrawString($"Vermietungs Liste vom {DateTime.Now.ToShortDateString()}", fontHead, Brushes.Black, new PointF(20f, top));
            SizeF textSize = e.Graphics.MeasureString($"Personen Liste vom {DateTime.Now.ToShortDateString()}", fontHead);

            top += textSize.Height + 10f;
            e.Graphics.DrawLine(new Pen(Brushes.Blue, 3f), new PointF(20f, top), new PointF(e.PageSettings.PaperSize.Width - 20, top));
            top += 13f;

            for (int idx = lastIndex; idx < this.rents.Count; idx++)
            {
                rent  = this.rents[idx];
                image = ImageCar.GetMainImage(this.connection, rent.CarId);
                if (image != null)
                {
                    ratio   = (float)image.Width / 150f;
                    nHeight = (float)image.Height / ratio;
                    e.Graphics.DrawImage(image, new RectangleF(30f, top, 150, nHeight), new RectangleF(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                }
                else
                {
                    nHeight = 150f;
                }

                topOffset = 30f;
                e.Graphics.DrawString("Name: ", fontLabel, Brushes.Black, new PointF(220f, top + topOffset));
                e.Graphics.DrawString($"{rent.Name} {rent.FamilyName}", fontStd, Brushes.Black, new PointF(350f, top + topOffset));
                textSize = e.Graphics.MeasureString($"{rent.Name} {rent.FamilyName}", fontStd);

                topOffset += textSize.Height + 10f;
                e.Graphics.DrawString("Fahrzeug: ", fontLabel, Brushes.Black, new PointF(220f, top + topOffset));
                e.Graphics.DrawString($"{(rent.Brand != String.Empty ? rent.Brand : string.Empty)} {(rent.Modell != String.Empty ? rent.Modell : string.Empty)}", fontStd, Brushes.Black, new PointF(350f, top + topOffset));

                topOffset += textSize.Height + 10f;
                e.Graphics.DrawString("Vermietet: ", fontLabel, Brushes.Black, new PointF(220f, top + topOffset));
                e.Graphics.DrawString($"{(rent.Begin.HasValue ? rent.Begin.Value.ToShortDateString() : string.Empty)} {(rent.Begin.HasValue ? rent.Begin.Value.ToShortTimeString() : string.Empty)} " +
                                      $"- {(rent.End.HasValue ? rent.End.Value.ToShortDateString() : "noch offen")} {(rent.End.HasValue ? rent.End.Value.ToShortTimeString() : "")}", fontStd, Brushes.Black, new PointF(350f, top + topOffset));

                top += nHeight + 20f;


                if (top > (float)e.PageSettings.PaperSize.Height / 3f * 2f)
                {
                    lastIndex      = idx + 1;
                    e.HasMorePages = true;
                    break;
                }
            }

            this.timerRents.Enabled = true;
        }