Pdf vykres

This commit is contained in:
Culak-HP\Culak
2020-10-21 16:48:26 +02:00
parent 06bde98877
commit 31323587ee
17 changed files with 346923 additions and 61 deletions

View File

@@ -9,7 +9,6 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Mip
{
public partial class frmPridatVyrobok : Form
@@ -33,16 +32,18 @@ namespace Mip
private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
z += (Convert.ToSingle(0.1) * (e.Delta / Math.Abs(e.Delta)));
pictureBox1.Height = Convert.ToInt32(sizeH * z);
pictureBox1.Width = Convert.ToInt32(sizeW * z);
if (dataGridView1.RowCount != 0)
if(pictureBox1.Image != null)
{
DataGridViewRow dtrw;
dtrw = dataGridView1.CurrentRow;
groupBox1.Text = "Zobraziť výkres: " + dtrw.Cells["Nazov_suboru"].Value.ToString() + ", " + "Zoom= " + (Convert.ToSingle(pictureBox1.Width) / Convert.ToSingle(pictureBox1.Image.Width)).ToString();
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
z += (Convert.ToSingle(0.1) * (e.Delta / Math.Abs(e.Delta)));
pictureBox1.Height = Convert.ToInt32(sizeH * z);
pictureBox1.Width = Convert.ToInt32(sizeW * z);
if (dataGridView1.RowCount != 0)
{
DataGridViewRow dtrw;
dtrw = dataGridView1.CurrentRow;
groupBox1.Text = "Zobraziť výkres: " + dtrw.Cells["Nazov_suboru"].Value.ToString() + ", " + "Zoom= " + (Convert.ToSingle(pictureBox1.Width) / Convert.ToSingle(pictureBox1.Image.Width)).ToString();
}
}
}
@@ -50,6 +51,7 @@ namespace Mip
{
pomocnaDT.Columns.Add("Nazov_suboru",typeof (string));
pomocnaDT.Columns.Add("Velkost_suboru",typeof (string));
pomocnaDT.Columns.Add("Typ_suboru", typeof(string));
pomocnaDT.Columns.Add("Cesta",typeof (string));
VypisSpojenyRozmer();
classGlobal.FillCB(comboBox2, "tabpomocnychudajov", "Hodnota", "Kategoria", "Pridať iný názov");
@@ -62,28 +64,37 @@ namespace Mip
openFileDialog1.Multiselect = true;
openFileDialog1.DefaultExt = "jpg";
openFileDialog1.Filter = "Obrázky (*.BMP;*.JPG;*.JPEG;*.GIF;*.PNG;*.EXIF;*.TIFF)|*.BMP;*.JPG;*.JPEG;*.GIF;*.PNG;*.EXIF;*.TIFF|" +
"Pdf súbory (*.pdf)|*.pdf";
openFileDialog1.FilterIndex = 1;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileNames != null && openFileDialog1.FileName != "")
{
foreach (string FN in openFileDialog1.FileNames)
foreach (string Cesta in openFileDialog1.FileNames)
{
bool FNexist = false;
bool CestaExist = false;
foreach (DataRow rowCesta in pomocnaDT.Rows)
{
if (rowCesta["Cesta"].ToString() == FN.ToString()) FNexist = true;
if (rowCesta["Cesta"].ToString() == Cesta.ToString()) CestaExist = true;
}
if (!FNexist)
if (!CestaExist)
{
FileStream fileStream;
fileStream = new FileStream(FN, FileMode.Open, FileAccess.Read);
char[] help = new char[FN.Length - FN.LastIndexOf("\\") - 1];
fileStream = new FileStream(Cesta, FileMode.Open, FileAccess.Read);
//char[] help = new char[Cesta.Length - Cesta.LastIndexOf("\\") - 1];
FN.CopyTo(FN.LastIndexOf("\\") + 1, help, 0, (help.Length));
string hlp = new string(help);
pomocnaDT.Rows.Add(hlp, FN.Length.ToString(), FN);
//Cesta.CopyTo(Cesta.LastIndexOf("\\") + 1, help, 0, (help.Length));
//string hlp = new string(help);
var FileNameStart = Cesta.LastIndexOf("\\") + 1;
var FileName = Cesta.Substring(FileNameStart, Cesta.Length - FileNameStart);
var ExtensionStart = Cesta.LastIndexOf(".") + 1;
var Extension = Cesta.Substring(ExtensionStart, Cesta.Length - ExtensionStart);
pomocnaDT.Rows.Add(FileName, Cesta.Length.ToString(), Extension, Cesta);
dataGridView1.DataSource = pomocnaDT;
dataGridView1.AutoResizeColumns();
@@ -94,7 +105,7 @@ namespace Mip
}
else
{
MessageBox.Show("Súbor: " + FN + "\n už v zozname figuruje!", "Upozornenie ...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show("Súbor: " + Cesta + "\n už v zozname figuruje!", "Upozornenie ...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//MessageBox.Show(
}
@@ -167,24 +178,40 @@ namespace Mip
int fileSize;
byte[] fileData;
DataRow dRow;
dRow = pomocnaDT.Rows[index];
fs = new FileStream(dRow["Cesta"].ToString(), FileMode.Open, FileAccess.Read);
fileSize = (int)fs.Length;
fileData = new byte[fileSize];
fs.Read(fileData, 0, fileSize);
fs.Close();
Bitmap obrazok;
//using (MemoryStream stream = new MemoryStream(fileData)) obrazok = new Bitmap(stream);
MemoryStream stream = new MemoryStream(fileData);
obrazok = new Bitmap(stream);
pictureBox1.Image = obrazok;
pictureBox1.Height = obrazok.Height;
pictureBox1.Width = obrazok.Width;
sizeH = pictureBox1.Image.Size.Height;
sizeW = pictureBox1.Image.Size.Width;
z = 1;
var isPdf = dRow["Typ_suboru"].ToString() == "pdf";
if (isPdf)
{
FileStream pdfFileStream = new FileStream(dRow["Cesta"].ToString(), FileMode.Open, FileAccess.Read);
pictureBox1.Visible = false;
pdfDocumentView1.Visible = true;
pdfDocumentView1.Load(pdfFileStream);
pdfDocumentView1.ZoomMode = Syncfusion.Windows.Forms.PdfViewer.ZoomMode.FitWidth;
pdfDocumentView1.Dock = DockStyle.Fill;
}
else
{
fs = new FileStream(dRow["Cesta"].ToString(), FileMode.Open, FileAccess.Read);
fileSize = (int)fs.Length;
fileData = new byte[fileSize];
fs.Read(fileData, 0, fileSize);
fs.Close();
Bitmap obrazok;
//using (MemoryStream stream = new MemoryStream(fileData)) obrazok = new Bitmap(stream);
MemoryStream stream = new MemoryStream(fileData);
obrazok = new Bitmap(stream);
pictureBox1.Visible = true;
pictureBox1.Image = obrazok;
pictureBox1.Height = obrazok.Height;
pictureBox1.Width = obrazok.Width;
sizeH = pictureBox1.Image.Size.Height;
sizeW = pictureBox1.Image.Size.Width;
pdfDocumentView1.Visible = false;
}
z = 1;
}