314 lines
12 KiB
C#
314 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
//using MySql.Data.MySqlClient;
|
|
using System.IO;
|
|
using System.Drawing.Printing;
|
|
using System.Drawing.Imaging;
|
|
|
|
namespace Mip
|
|
{
|
|
public partial class frmShowVykres : Form
|
|
{
|
|
Point poinPosition;
|
|
Single z;
|
|
Single zMin = 0.1F;
|
|
int sizeH;
|
|
int sizeW;
|
|
string Zakaznik, Vyrobok;
|
|
int AktualnyVykres,PočetVykresov,IDVyrobok;
|
|
DataTable frmdatatable = new DataTable();
|
|
|
|
public frmShowVykres(string _Zakaznik, string _Vyrobok)
|
|
{
|
|
InitializeComponent();
|
|
Zakaznik = _Zakaznik; Vyrobok = _Vyrobok;
|
|
classSQL.SQL(@"SELECT * FROM `pohladvykresy` WHERE `Zakaznik` = '" + Zakaznik + "' AND `NazovVyrobku`='" + Vyrobok + "' ORDER BY `IndexVykresu` ASC;", out frmdatatable);
|
|
AktualnyVykres = 1; PočetVykresov = frmdatatable.Rows.Count;
|
|
|
|
if (PočetVykresov > 1) btnRight.Enabled = true;
|
|
else btnRight.Enabled = false;
|
|
|
|
pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
|
|
|
|
}
|
|
|
|
public frmShowVykres(string _Zakaznik, Int32 _IDVyrobok)
|
|
{
|
|
InitializeComponent();
|
|
Zakaznik = _Zakaznik; IDVyrobok = _IDVyrobok;
|
|
classSQL.SQL(@"SELECT * FROM `pohladvykresy` WHERE `Zakaznik` = '" + Zakaznik + "' AND `IDVyrobok`='" + IDVyrobok.ToString() + "' ORDER BY `IndexVykresu` ASC;", out frmdatatable);
|
|
AktualnyVykres = 1; PočetVykresov = frmdatatable.Rows.Count;
|
|
|
|
if (PočetVykresov > 1) btnRight.Enabled = true;
|
|
else btnRight.Enabled = false;
|
|
|
|
pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
|
|
|
|
}
|
|
|
|
public frmShowVykres(byte[] _FileData)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.Width = (int)(Screen.PrimaryScreen.WorkingArea.Width - 10);
|
|
this.Height = (int)(Screen.PrimaryScreen.WorkingArea.Height - 10);
|
|
this.Location = new Point(5, 5);
|
|
|
|
AktualnyVykres = 1; PočetVykresov = 1;
|
|
if (PočetVykresov > 1) btnRight.Enabled = true;
|
|
else btnRight.Enabled = false;
|
|
|
|
MemoryStream ms = new MemoryStream(_FileData);
|
|
|
|
int origImageSizeH = Image.FromStream(ms).Size.Height + 3;
|
|
int origImageSizeW = Image.FromStream(ms).Size.Width + 3;
|
|
|
|
zMin = (float)panel1.Size.Height / (float)origImageSizeH;
|
|
if (((float)panel1.Size.Width / (float)origImageSizeW) < zMin) zMin = (float)panel1.Size.Width / (float)origImageSizeW;
|
|
z = zMin;
|
|
|
|
sizeH = Image.FromStream(ms).Size.Height;
|
|
sizeW = Image.FromStream(ms).Size.Width;
|
|
|
|
pictureBox1.Image = Image.FromStream(ms);
|
|
|
|
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
|
|
pictureBox1.Size = new Size(Convert.ToInt32(sizeW * z), Convert.ToInt32(sizeH * z));
|
|
|
|
pictureBox1.Location = new Point(1, 1);
|
|
this.Text = Zakaznik + ": " + Vyrobok + "-" + AktualnyVykres.ToString() + "/" + PočetVykresov.ToString();
|
|
|
|
pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
|
|
}
|
|
|
|
|
|
private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
|
|
{
|
|
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
|
|
|
|
if (z > zMin) { if (e.Delta != 0) z += (Convert.ToSingle(0.1) * (e.Delta / Math.Abs(e.Delta))); }
|
|
else { if (e.Delta > 0) z += (Convert.ToSingle(0.1) * (e.Delta / Math.Abs(e.Delta))); }
|
|
|
|
pictureBox1.Size = new Size(Convert.ToInt32(sizeW * z), Convert.ToInt32(sizeH * z));
|
|
label3.Text = "zoom:" + z.ToString() + " Šírka:" + pictureBox1.Width.ToString() + " Výška:" + pictureBox1.Height.ToString();
|
|
|
|
}
|
|
|
|
private void frmShowVykres_Load(object sender, EventArgs e)
|
|
{
|
|
if (frmdatatable.Rows.Count > 0)
|
|
{
|
|
this.Width = (int)(Screen.PrimaryScreen.WorkingArea.Width - 10);
|
|
this.Height = (int)(Screen.PrimaryScreen.WorkingArea.Height - 10);
|
|
this.Location = new Point(5, 5);
|
|
nacitajaktualnyvykres();
|
|
}
|
|
|
|
}
|
|
|
|
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
poinPosition = e.Location;
|
|
}
|
|
}
|
|
|
|
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
Point changePoint = new Point(e.Location.X - poinPosition.X, e.Location.Y - poinPosition.Y);
|
|
panel1.AutoScrollPosition = new Point(-panel1.AutoScrollPosition.X - changePoint.X, -panel1.AutoScrollPosition.Y - changePoint.Y);
|
|
}
|
|
|
|
if (e.Button == MouseButtons.None)
|
|
{
|
|
int citlivost=20;
|
|
|
|
if ((e.Location.X < btnLeft.Location.X + citlivost + btnLeft.Width + panel1.HorizontalScroll.Value) && AktualnyVykres !=1) btnLeft.Visible = true;
|
|
else btnLeft.Visible = false;
|
|
|
|
if ((e.Location.X > btnRight.Location.X - citlivost + panel1.HorizontalScroll.Value) && AktualnyVykres != PočetVykresov ) btnRight.Visible = true;
|
|
else btnRight.Visible = false;
|
|
}
|
|
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnLeft_Click(object sender, EventArgs e)
|
|
{
|
|
AktualnyVykres--;
|
|
if (AktualnyVykres == 0) AktualnyVykres = 1;
|
|
else nacitajaktualnyvykres();
|
|
}
|
|
|
|
private void btnRight_Click(object sender, EventArgs e)
|
|
{
|
|
AktualnyVykres++;
|
|
if (AktualnyVykres == PočetVykresov + 1) AktualnyVykres = PočetVykresov;
|
|
else nacitajaktualnyvykres();
|
|
}
|
|
|
|
private void nacitajaktualnyvykres()
|
|
{
|
|
DataRow dtrw = frmdatatable.Rows[AktualnyVykres - 1];
|
|
MemoryStream ms = new MemoryStream((byte[])dtrw["VykresData"]);
|
|
|
|
int origImageSizeH = Image.FromStream(ms).Size.Height+3;
|
|
int origImageSizeW = Image.FromStream(ms).Size.Width+3;
|
|
|
|
zMin = (float)panel1.Size.Height / (float)origImageSizeH;
|
|
if (((float)panel1.Size.Width / (float)origImageSizeW) < zMin) zMin = (float)panel1.Size.Width / (float)origImageSizeW;
|
|
z = zMin;
|
|
|
|
sizeH = Image.FromStream(ms).Size.Height;
|
|
sizeW = Image.FromStream(ms).Size.Width;
|
|
|
|
//Image.FromStream(ms).RotateFlip(RotateFlipType.Rotate90FlipNone);
|
|
|
|
pictureBox1.Image = Image.FromStream(ms);
|
|
|
|
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
|
|
pictureBox1.Size = new Size(Convert.ToInt32(sizeW * z), Convert.ToInt32(sizeH * z));
|
|
|
|
pictureBox1.Location = new Point(1, 1);
|
|
this.Text = Zakaznik + ": " + Vyrobok + "-" + AktualnyVykres.ToString() + "/" + PočetVykresov.ToString();
|
|
}
|
|
|
|
private void frmShowVykres_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void panel1_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.None)
|
|
{
|
|
int citlivost = 20;
|
|
|
|
if ((e.Location.X < btnLeft.Location.X + citlivost + btnLeft.Width + panel1.HorizontalScroll.Value) && AktualnyVykres != 1) btnLeft.Visible = true;
|
|
else btnLeft.Visible = false;
|
|
|
|
if ((e.Location.X > btnRight.Location.X - citlivost + panel1.HorizontalScroll.Value) && AktualnyVykres != PočetVykresov) btnRight.Visible = true;
|
|
else btnRight.Visible = false;
|
|
|
|
}
|
|
}
|
|
|
|
private void frmShowVykres_Resize(object sender, EventArgs e)
|
|
{
|
|
btnLeft.Location = new Point(btnLeft.Location.X, (this.Height / 2) - (btnLeft.Height / 2));
|
|
btnRight.Location = new Point(btnRight.Location.X, (this.Height / 2) - (btnRight.Height / 2));
|
|
}
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
{
|
|
if (keyData == Keys.Left) btnLeft_Click(null, null);
|
|
if (keyData == Keys.Right) btnRight_Click(null, null);
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
}
|
|
|
|
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == System.Windows.Forms.MouseButtons.Right)
|
|
{
|
|
int x = 0; int y= 0;
|
|
|
|
if (e.X + panel2.Width + 50 > Screen.PrimaryScreen.WorkingArea.Width) x = e.X - panel2.Width;
|
|
else x = e.X;
|
|
if (e.Y + panel2.Height + 70 > Screen.PrimaryScreen.WorkingArea.Height) y = e.Y-panel2.Height;
|
|
else y = e.Y;
|
|
panel2.Location = new Point(x,y);
|
|
label1.BackColor = Color.Empty;
|
|
label2.BackColor = Color.Empty;
|
|
panel2.Visible = true;
|
|
}
|
|
}
|
|
|
|
private void label1_MouseEnter(object sender, EventArgs e) { label1.BackColor = Color.Orange; }
|
|
private void label1_MouseLeave(object sender, EventArgs e) { label1.BackColor = Color.Empty; }
|
|
private void label2_MouseEnter(object sender, EventArgs e) { label2.BackColor = Color.Orange; }
|
|
private void label2_MouseLeave(object sender, EventArgs e) { label2.BackColor = Color.Empty; }
|
|
private void label4_MouseEnter(object sender, EventArgs e) { label4.BackColor = Color.Orange; }
|
|
private void label4_MouseLeave(object sender, EventArgs e) { label4.BackColor = Color.Empty; }
|
|
|
|
private void label4_Click(object sender, EventArgs e)
|
|
{
|
|
SaveFileDialog sfd = new SaveFileDialog();
|
|
sfd.Filter = "JPEG Image (.jpeg)|*.jpeg |Png Image (.png)|*.png";
|
|
|
|
if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != "")
|
|
{
|
|
if(sfd.FilterIndex == 1) pictureBox1.Image.Save(sfd.FileName, ImageFormat.Jpeg);
|
|
if (sfd.FilterIndex == 2) pictureBox1.Image.Save(sfd.FileName, ImageFormat.Png);
|
|
}
|
|
else { MessageBox.Show("Neplatná cesta alebo názov súboru! Obrázok nebol uložený!"); }
|
|
|
|
panel2.Visible = false;
|
|
}
|
|
|
|
|
|
|
|
private void label2_Click(object sender, EventArgs e)
|
|
{
|
|
panel2.Visible = false;
|
|
}
|
|
|
|
|
|
private void label1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
PrintDocument printDocument1 = new PrintDocument();
|
|
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
|
|
|
|
PrintPreviewDialog printPrevDialog = new PrintPreviewDialog();
|
|
if (pictureBox1.Image.Width >= pictureBox1.Image.Height) printDocument1.DefaultPageSettings.Landscape = true;
|
|
else printDocument1.DefaultPageSettings.Landscape = false;
|
|
printDocument1.DefaultPageSettings.Margins = new Margins(10, 10, 10, 10);
|
|
|
|
printPrevDialog.Document = printDocument1;
|
|
|
|
((Form)printPrevDialog).StartPosition = FormStartPosition.CenterScreen;
|
|
((Form)printPrevDialog).WindowState = FormWindowState.Maximized;
|
|
|
|
printPrevDialog.ShowDialog();
|
|
|
|
panel2.Visible = false;
|
|
}
|
|
|
|
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
|
|
{
|
|
|
|
Image imageSource = pictureBox1.Image;
|
|
Rectangle hraniceTlace = e.MarginBounds;
|
|
/*
|
|
if ((double)imageSource.Width / (double)imageSource.Height > (double)hraniceTlace.Width / (double)hraniceTlace.Height) // image is wider
|
|
{
|
|
hraniceTlace.Height = (int)((double)imageSource.Height / (double)imageSource.Width * (double)hraniceTlace.Width);
|
|
}
|
|
else
|
|
{
|
|
hraniceTlace.Width = (int)((double)imageSource.Width / (double)imageSource.Height * (double)hraniceTlace.Height);
|
|
}
|
|
*/
|
|
e.Graphics.DrawImage(imageSource, hraniceTlace);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|