diff --git a/.vs/Mip_v1/v16/.suo b/.vs/Mip_v1/v16/.suo index f74a83e..a14906b 100644 Binary files a/.vs/Mip_v1/v16/.suo and b/.vs/Mip_v1/v16/.suo differ diff --git a/Mip/frmPridatVyrobok.Designer.cs b/Mip/frmPridatVyrobok.Designer.cs index cd3b9dd..a3cce02 100644 --- a/Mip/frmPridatVyrobok.Designer.cs +++ b/Mip/frmPridatVyrobok.Designer.cs @@ -28,10 +28,10 @@ /// private void InitializeComponent() { - Syncfusion.Windows.Forms.PdfViewer.MessageBoxSettings messageBoxSettings1 = new Syncfusion.Windows.Forms.PdfViewer.MessageBoxSettings(); - Syncfusion.Windows.PdfViewer.PdfViewerPrinterSettings pdfViewerPrinterSettings1 = new Syncfusion.Windows.PdfViewer.PdfViewerPrinterSettings(); + Syncfusion.Windows.Forms.PdfViewer.MessageBoxSettings messageBoxSettings2 = new Syncfusion.Windows.Forms.PdfViewer.MessageBoxSettings(); + Syncfusion.Windows.PdfViewer.PdfViewerPrinterSettings pdfViewerPrinterSettings2 = new Syncfusion.Windows.PdfViewer.PdfViewerPrinterSettings(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPridatVyrobok)); - Syncfusion.Windows.Forms.PdfViewer.TextSearchSettings textSearchSettings1 = new Syncfusion.Windows.Forms.PdfViewer.TextSearchSettings(); + Syncfusion.Windows.Forms.PdfViewer.TextSearchSettings textSearchSettings2 = new Syncfusion.Windows.Forms.PdfViewer.TextSearchSettings(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.label1 = new System.Windows.Forms.Label(); this.textBox7 = new System.Windows.Forms.TextBox(); @@ -105,7 +105,7 @@ this.groupBox3.Controls.Add(this.label3); this.groupBox3.Location = new System.Drawing.Point(236, 7); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(247, 148); + this.groupBox3.Size = new System.Drawing.Size(251, 148); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = "Tvar a rozmery výrobku"; @@ -113,7 +113,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(120, 121); + this.label1.Location = new System.Drawing.Point(125, 123); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(93, 13); this.label1.TabIndex = 15; @@ -121,7 +121,7 @@ // // textBox7 // - this.textBox7.Location = new System.Drawing.Point(216, 118); + this.textBox7.Location = new System.Drawing.Point(221, 120); this.textBox7.Name = "textBox7"; this.textBox7.Size = new System.Drawing.Size(25, 20); this.textBox7.TabIndex = 16; @@ -141,7 +141,7 @@ // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(7, 121); + this.label8.Location = new System.Drawing.Point(7, 123); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(32, 13); this.label8.TabIndex = 2; @@ -159,7 +159,7 @@ // // textBox5 // - this.textBox5.Location = new System.Drawing.Point(38, 118); + this.textBox5.Location = new System.Drawing.Point(40, 120); this.textBox5.Name = "textBox5"; this.textBox5.Size = new System.Drawing.Size(83, 20); this.textBox5.TabIndex = 3; @@ -188,7 +188,7 @@ // this.textBox1.Location = new System.Drawing.Point(7, 94); this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(234, 20); + this.textBox1.Size = new System.Drawing.Size(238, 20); this.textBox1.TabIndex = 10; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // @@ -282,7 +282,7 @@ this.dataGridView1.ShowCellToolTips = false; this.dataGridView1.ShowEditingIcon = false; this.dataGridView1.ShowRowErrors = false; - this.dataGridView1.Size = new System.Drawing.Size(347, 106); + this.dataGridView1.Size = new System.Drawing.Size(599, 106); this.dataGridView1.TabIndex = 4; this.dataGridView1.DataMemberChanged += new System.EventHandler(this.dataGridView1_DataMemberChanged); this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); @@ -292,7 +292,7 @@ // btnAddVykres // this.btnAddVykres.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnAddVykres.Location = new System.Drawing.Point(173, 121); + this.btnAddVykres.Location = new System.Drawing.Point(425, 121); this.btnAddVykres.Name = "btnAddVykres"; this.btnAddVykres.Size = new System.Drawing.Size(56, 23); this.btnAddVykres.TabIndex = 5; @@ -308,7 +308,7 @@ this.groupBox1.Controls.Add(this.panel1); this.groupBox1.Location = new System.Drawing.Point(2, 151); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(919, 421); + this.groupBox1.Size = new System.Drawing.Size(1180, 421); this.groupBox1.TabIndex = 7; this.groupBox1.TabStop = false; this.groupBox1.Text = "Zobraziť výkres"; @@ -324,7 +324,7 @@ this.panel1.Controls.Add(this.pictureBox1); this.panel1.Location = new System.Drawing.Point(4, 17); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(909, 398); + this.panel1.Size = new System.Drawing.Size(1170, 398); this.panel1.TabIndex = 9; // // pdfDocumentView1 @@ -337,16 +337,16 @@ this.pdfDocumentView1.IsTextSearchEnabled = true; this.pdfDocumentView1.IsTextSelectionEnabled = true; this.pdfDocumentView1.Location = new System.Drawing.Point(36, 3); - messageBoxSettings1.EnableNotification = true; - this.pdfDocumentView1.MessageBoxSettings = messageBoxSettings1; + messageBoxSettings2.EnableNotification = true; + this.pdfDocumentView1.MessageBoxSettings = messageBoxSettings2; this.pdfDocumentView1.MinimumZoomPercentage = 50; this.pdfDocumentView1.Name = "pdfDocumentView1"; this.pdfDocumentView1.PageBorderThickness = 1; - pdfViewerPrinterSettings1.PageOrientation = Syncfusion.Windows.PdfViewer.PdfViewerPrintOrientation.Auto; - pdfViewerPrinterSettings1.PageSize = Syncfusion.Windows.PdfViewer.PdfViewerPrintSize.ActualSize; - pdfViewerPrinterSettings1.PrintLocation = ((System.Drawing.PointF)(resources.GetObject("pdfViewerPrinterSettings1.PrintLocation"))); - pdfViewerPrinterSettings1.ShowPrintStatusDialog = true; - this.pdfDocumentView1.PrinterSettings = pdfViewerPrinterSettings1; + pdfViewerPrinterSettings2.PageOrientation = Syncfusion.Windows.PdfViewer.PdfViewerPrintOrientation.Auto; + pdfViewerPrinterSettings2.PageSize = Syncfusion.Windows.PdfViewer.PdfViewerPrintSize.ActualSize; + pdfViewerPrinterSettings2.PrintLocation = ((System.Drawing.PointF)(resources.GetObject("pdfViewerPrinterSettings2.PrintLocation"))); + pdfViewerPrinterSettings2.ShowPrintStatusDialog = true; + this.pdfDocumentView1.PrinterSettings = pdfViewerPrinterSettings2; this.pdfDocumentView1.ReferencePath = null; this.pdfDocumentView1.ScrollDisplacementValue = 0; this.pdfDocumentView1.ShowHorizontalScrollBar = true; @@ -354,10 +354,10 @@ this.pdfDocumentView1.Size = new System.Drawing.Size(150, 150); this.pdfDocumentView1.SpaceBetweenPages = 8; this.pdfDocumentView1.TabIndex = 10; - textSearchSettings1.CurrentInstanceColor = System.Drawing.Color.FromArgb(((int)(((byte)(127)))), ((int)(((byte)(255)))), ((int)(((byte)(171)))), ((int)(((byte)(64))))); - textSearchSettings1.HighlightAllInstance = true; - textSearchSettings1.OtherInstanceColor = System.Drawing.Color.FromArgb(((int)(((byte)(127)))), ((int)(((byte)(254)))), ((int)(((byte)(255)))), ((int)(((byte)(0))))); - this.pdfDocumentView1.TextSearchSettings = textSearchSettings1; + textSearchSettings2.CurrentInstanceColor = System.Drawing.Color.FromArgb(((int)(((byte)(127)))), ((int)(((byte)(255)))), ((int)(((byte)(171)))), ((int)(((byte)(64))))); + textSearchSettings2.HighlightAllInstance = true; + textSearchSettings2.OtherInstanceColor = System.Drawing.Color.FromArgb(((int)(((byte)(127)))), ((int)(((byte)(254)))), ((int)(((byte)(255)))), ((int)(((byte)(0))))); + this.pdfDocumentView1.TextSearchSettings = textSearchSettings2; this.pdfDocumentView1.ThemeName = "Default"; this.pdfDocumentView1.VerticalScrollOffset = 0; this.pdfDocumentView1.VisualStyle = Syncfusion.Windows.Forms.PdfViewer.VisualStyle.Default; @@ -387,7 +387,7 @@ // this.btnVymazVykres.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnVymazVykres.Enabled = false; - this.btnVymazVykres.Location = new System.Drawing.Point(287, 121); + this.btnVymazVykres.Location = new System.Drawing.Point(539, 121); this.btnVymazVykres.Name = "btnVymazVykres"; this.btnVymazVykres.Size = new System.Drawing.Size(61, 23); this.btnVymazVykres.TabIndex = 8; @@ -423,9 +423,9 @@ this.groupBox4.Controls.Add(this.btnAddVykres); this.groupBox4.Controls.Add(this.button4); this.groupBox4.Controls.Add(this.btnVymazVykres); - this.groupBox4.Location = new System.Drawing.Point(485, 7); + this.groupBox4.Location = new System.Drawing.Point(489, 7); this.groupBox4.Name = "groupBox4"; - this.groupBox4.Size = new System.Drawing.Size(351, 148); + this.groupBox4.Size = new System.Drawing.Size(603, 148); this.groupBox4.TabIndex = 11; this.groupBox4.TabStop = false; this.groupBox4.Text = "Načítané výkresy"; @@ -434,7 +434,7 @@ // this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button4.Enabled = false; - this.button4.Location = new System.Drawing.Point(230, 121); + this.button4.Location = new System.Drawing.Point(482, 121); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(56, 23); this.button4.TabIndex = 14; @@ -479,7 +479,7 @@ // // textBox6 // - this.textBox6.Location = new System.Drawing.Point(85, 18); + this.textBox6.Location = new System.Drawing.Point(82, 17); this.textBox6.Name = "textBox6"; this.textBox6.Size = new System.Drawing.Size(118, 20); this.textBox6.TabIndex = 6; @@ -489,7 +489,7 @@ // comboBox2 // this.comboBox2.FormattingEnabled = true; - this.comboBox2.Location = new System.Drawing.Point(85, 44); + this.comboBox2.Location = new System.Drawing.Point(82, 42); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(118, 21); this.comboBox2.TabIndex = 5; @@ -497,7 +497,7 @@ // label9 // this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(15, 47); + this.label9.Location = new System.Drawing.Point(15, 46); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(53, 13); this.label9.TabIndex = 4; @@ -507,7 +507,7 @@ // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(5, 21); + this.label7.Location = new System.Drawing.Point(2, 20); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(79, 13); this.label7.TabIndex = 0; @@ -516,7 +516,7 @@ // button3 // this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.button3.Location = new System.Drawing.Point(837, 128); + this.button3.Location = new System.Drawing.Point(1098, 128); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(84, 23); this.button3.TabIndex = 13; @@ -528,7 +528,7 @@ // this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button5.Enabled = false; - this.button5.Location = new System.Drawing.Point(837, 99); + this.button5.Location = new System.Drawing.Point(1098, 99); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(84, 23); this.button5.TabIndex = 15; @@ -539,9 +539,9 @@ // button6 // this.button6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.button6.Location = new System.Drawing.Point(117, 130); + this.button6.Location = new System.Drawing.Point(117, 125); this.button6.Name = "button6"; - this.button6.Size = new System.Drawing.Size(51, 19); + this.button6.Size = new System.Drawing.Size(51, 24); this.button6.TabIndex = 16; this.button6.Text = "Zoom +"; this.button6.UseVisualStyleBackColor = true; @@ -550,9 +550,9 @@ // button7 // this.button7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.button7.Location = new System.Drawing.Point(174, 130); + this.button7.Location = new System.Drawing.Point(174, 125); this.button7.Name = "button7"; - this.button7.Size = new System.Drawing.Size(51, 19); + this.button7.Size = new System.Drawing.Size(51, 24); this.button7.TabIndex = 17; this.button7.Text = "Zoom -"; this.button7.UseVisualStyleBackColor = true; @@ -563,7 +563,7 @@ this.radioButton1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.radioButton1.AutoSize = true; this.radioButton1.Checked = true; - this.radioButton1.Location = new System.Drawing.Point(837, 12); + this.radioButton1.Location = new System.Drawing.Point(1096, 12); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(71, 17); this.radioButton1.TabIndex = 18; @@ -575,7 +575,7 @@ // this.radioButton2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.radioButton2.AutoSize = true; - this.radioButton2.Location = new System.Drawing.Point(837, 35); + this.radioButton2.Location = new System.Drawing.Point(1096, 35); this.radioButton2.Name = "radioButton2"; this.radioButton2.Size = new System.Drawing.Size(90, 17); this.radioButton2.TabIndex = 19; @@ -586,7 +586,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(923, 574); + this.ClientSize = new System.Drawing.Size(1184, 574); this.Controls.Add(this.radioButton2); this.Controls.Add(this.radioButton1); this.Controls.Add(this.groupBox3); diff --git a/Mip/frmPridatVyrobok.cs b/Mip/frmPridatVyrobok.cs index e4359a2..f03f3b5 100644 --- a/Mip/frmPridatVyrobok.cs +++ b/Mip/frmPridatVyrobok.cs @@ -8,6 +8,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; +using Syncfusion.Pdf.Parsing; +using System.Drawing.Imaging; + namespace Mip { @@ -53,6 +56,8 @@ namespace Mip pomocnaDT.Columns.Add("Velkost_suboru",typeof (string)); pomocnaDT.Columns.Add("Typ_suboru", typeof(string)); pomocnaDT.Columns.Add("Cesta",typeof (string)); + pomocnaDT.Columns.Add("Data", typeof(string)); + pomocnaDT.Columns.Add("Valid", typeof(int)); VypisSpojenyRozmer(); classGlobal.FillCB(comboBox2, "tabpomocnychudajov", "Hodnota", "Kategoria", "Pridať iný názov"); @@ -60,16 +65,13 @@ namespace Mip private void btnAddVykres_Click(object sender, EventArgs e) { - - 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.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 Cesta in openFileDialog1.FileNames) @@ -84,45 +86,72 @@ namespace Mip { FileStream fileStream; fileStream = new FileStream(Cesta, FileMode.Open, FileAccess.Read); - //char[] help = new char[Cesta.Length - Cesta.LastIndexOf("\\") - 1]; + var fileSize = (int)fileStream.Length; + var VykresData = new byte[fileSize]; + fileStream.Read(VykresData, 0, fileSize); - - //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); + pomocnaDT.Rows.Add(FileName, Cesta.Length.ToString(), Extension, Cesta, VykresData.ToString(), Convert.ToInt32(IsFileValid(VykresData, Extension))); dataGridView1.DataSource = pomocnaDT; - dataGridView1.AutoResizeColumns(); - dataGridView1.AutoResizeRows(); + StyleGridView(); dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true; obrazok_Refresh(dataGridView1.Rows.Count - 1); - if (dataGridView1.Rows.Count > 4) dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 4; + if (dataGridView1.Rows.Count > 5) dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 5; } else { MessageBox.Show("Súbor: " + Cesta + "\n už v zozname figuruje!", "Upozornenie ...", MessageBoxButtons.OK, MessageBoxIcon.Warning); - //MessageBox.Show( - } - pictureBox1.Visible = true; - } - - - } if (textBox6.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && dataGridView1.Rows.Count != 0) button5.Enabled = true; else button5.Enabled = false; //kontrola naplnenia povinných dát } + private void StyleGridView() + { + dataGridView1.Columns["Data"].Visible = false; + + dataGridView1.AutoResizeColumns(); + dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; + dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; + dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; + dataGridView1.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; + dataGridView1.AutoResizeRows(); + } + + private bool IsFileValid(byte[] vykresData, string extension) + { + try + { + switch (extension) + { + case "pdf": + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(vykresData); + Bitmap pdfToJpeg = loadedDocument.ExportAsImage(0); + loadedDocument.Close(true); + return true; + default: + var memoryStream = new MemoryStream(vykresData); + Bitmap image = new Bitmap(memoryStream); + return true; + } + } + catch (Exception) + { + //MessageBox.Show($"Súbor '{Cesta}' nie je obrázok ani pdf"); + return false; + } + } private void btnVymazVykres_Click(object sender, EventArgs e) { @@ -181,33 +210,42 @@ namespace Mip dRow = pomocnaDT.Rows[index]; var isPdf = dRow["Typ_suboru"].ToString() == "pdf"; + var isValid = dRow["Valid"].ToString() == "1"; - if (isPdf) + if(isValid) { - 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; + 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; + } } 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; + pictureBox1.Visible = false; pdfDocumentView1.Visible = false; } @@ -501,13 +539,44 @@ namespace Mip byte[] VykresData; dtrw=pomocnaDT.Rows[p1]; - fs = new FileStream(dtrw["Cesta"].ToString(), FileMode.Open, FileAccess.Read); - fileSize = (int)fs.Length; - VykresData = new byte[fileSize]; - fs.Read(VykresData, 0, fileSize); - fs.Close(); + var isValid = dtrw["Valid"].ToString() == "1"; - classSQL.SaveVykresToSQL(IDVyrobok, p1 + 1, VykresData); + if(isValid) + { + fs = new FileStream(dtrw["Cesta"].ToString(), FileMode.Open, FileAccess.Read); + fileSize = (int)fs.Length; + VykresData = new byte[fileSize]; + fs.Read(VykresData, 0, fileSize); + + var fileToSave = new byte[fileSize]; + + switch (dtrw["Typ_suboru"].ToString()) + { + case "pdf": + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(VykresData); + Bitmap pdfToJpeg = loadedDocument.ExportAsImage(0); + loadedDocument.Close(true); + + fileToSave = SaveAsJpeg(pdfToJpeg); + break; + + case "jpg": + fileToSave = VykresData; + break; + + default: + Bitmap imageToJpeg = new Bitmap(fs); + fileToSave = SaveAsJpeg(imageToJpeg); + break; + } + + fs.Close(); + classSQL.SaveVykresToSQL(IDVyrobok, p1 + 1, fileToSave); + } + else + { + MessageBox.Show($"Výkres '{dtrw["Cesta"]}' nie je validný obrázok alebo pdf! {Environment.NewLine} Preto nebol uložený do databázy."); + } } MessageBox.Show("Výrobok úspešne pridaný!"); @@ -520,6 +589,17 @@ namespace Mip } + private byte[] SaveAsJpeg(Bitmap image) + { + byte[] returnImageData; + using (var stream = new MemoryStream()) + { + image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); + returnImageData = stream.ToArray(); + } + + return returnImageData; + } private void textBox6_TextChanged(object sender, EventArgs e) { diff --git a/Mip/frmPridatVyrobok.resx b/Mip/frmPridatVyrobok.resx index 5c16971..df9c36e 100644 --- a/Mip/frmPridatVyrobok.resx +++ b/Mip/frmPridatVyrobok.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0 dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJh diff --git a/Mip/obj/Debug/Mip.Properties.Resources.resources b/Mip/obj/Debug/Mip.Properties.Resources.resources index 8fd6c05..1017756 100644 Binary files a/Mip/obj/Debug/Mip.Properties.Resources.resources and b/Mip/obj/Debug/Mip.Properties.Resources.resources differ diff --git a/Mip/obj/Debug/Mip.csproj.ResolveComReference.cache b/Mip/obj/Debug/Mip.csproj.ResolveComReference.cache index 2f029d9..4b9db25 100644 Binary files a/Mip/obj/Debug/Mip.csproj.ResolveComReference.cache and b/Mip/obj/Debug/Mip.csproj.ResolveComReference.cache differ diff --git a/Mip/obj/Debug/Mip.frmPridatVyrobok.resources b/Mip/obj/Debug/Mip.frmPridatVyrobok.resources index c35c614..89f860d 100644 Binary files a/Mip/obj/Debug/Mip.frmPridatVyrobok.resources and b/Mip/obj/Debug/Mip.frmPridatVyrobok.resources differ