Here is the programm, i shortened it a bit so only the unneccesary things are out now:
that is Form 4 of three
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Drawing.Text;
using Microsoft.Office.Interop.Excel;
using System.Diagnostics;
using static System.Net.Mime.MediaTypeNames;
using static System.Net.WebRequestMethods;
using System.Reflection;
using System.Drawing;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using GemBox.Spreadsheet;
using Net.Pkcs11Interop.LowLevelAPI40.MechanismParams;
namespace Update_Report
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static void Extract(string nameSpace, string outDirectory, string internalFilePath, string resourceName)
{
Assembly assembly = Assembly.GetCallingAssembly();
using (Stream s = assembly.GetManifestResourceStream(nameSpace + "." + (internalFilePath == "" ? "" : internalFilePath + ".") + resourceName))
using (BinaryReader r = new BinaryReader(s))
using (FileStream fs = new FileStream(outDirectory + @"\" + resourceName, FileMode.OpenOrCreate))
using (BinaryWriter w = new BinaryWriter(fs))
w.Write(r.ReadBytes((int)s.Length));
}
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
DialogResult result = MessageBox.Show("Are you sure you want to Save?\n\nAt the moment there is no possibility to load your saved file in again.\n\nIf you want to get to the next side click 'YES'.", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
if (textBox1.TextLength > 3 & textBox3.TextLength > 3 & textBox6.TextLength > 3 & textBox7.TextLength > 3 & textBox15.TextLength > 3 & comboBox1.Text.Length > 2 & comboBox2.Text.Length > 3 & comboBox3.Text.Length > 3 & comboBox4.Text.Length > 3)
{
try
{
string FirstPagePath = @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp first page.xlsx";
string FirstPagePathEdited = @"C:\ProgramData\UpdateReports\01_MainPage\Software Update Report - temp first page.xlsx";
string NewFirstPagePath = @"C:\ProgramData\UpdateReports\01_MainPage\Software Update Report - " + textBox1.Text + " - " + dateTimePicker1.Text + ".xlsx";
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Workbook wb;
Worksheet ws;
wb = excel.Workbooks.Open(FirstPagePath);
ws = wb.Worksheets[1];
ws.Cells[5, 3] = textBox3.Text; //Customer
ws.Cells[6, 3] = textBox1.Text; //Evatec Asset
ws.Cells[7, 3] = textBox2.Text; //Customer Asset
ws.Cells[8, 3] = comboBox2.Text; //Product Group
ws.Cells[9, 3] = comboBox1.Text; //Software
toolStripProgressBar1.Value = 10;
ws.Cells[11, 3] = textBox5.Text; //Initiate
ws.Cells[12, 3] = comboBox3.Text; //Tool State
ws.Cells[13, 3] = textBox6.Text; //Author
toolStripProgressBar1.Value = 20;
ws.Cells[15, 3] = DateTime.Now; //Document Date
ws.Cells[16, 3] = comboBox4.Text; //Update Period
ws.Cells[17, 3] = comboBox5.Text; //Actual period
ws.Cells[4, 11] = comboBox6.Text; //Status
toolStripProgressBar1.Value = 30;
if (textBox19.TextLength > 8)
{
Microsoft.Office.Interop.Excel.Range excelCell = (Microsoft.Office.Interop.Excel.Range)ws.get_Range("C20", "C20");
ws.Hyperlinks.Add(excelCell, textBox19.Text, Type.Missing, "Click to open", "Click to open"); //SW File Link
}
if (textBox20.TextLength > 8)
{
Microsoft.Office.Interop.Excel.Range excelCell1 = (Microsoft.Office.Interop.Excel.Range)ws.get_Range("C19", "C19");
ws.Hyperlinks.Add(excelCell1, textBox20.Text, Type.Missing, "Click to open", "Click to open"); //Customer file Link
}
toolStripProgressBar1.Value = 40;
ws.Cells[24, 1] = richTextBox1.Text; //Reason Update
ws.Cells[30, 1] = richTextBox2.Text; //Additional Information
ws.Cells[10, 11] = richTextBox3.Text; //Reason for Status
toolStripProgressBar1.Value = 50;
ws.Cells[5, 8] = textBox7.Text; //Software Revision
ws.Cells[6, 8] = textBox8.Text; //Framework/EIB
ws.Cells[7, 8] = textBox9.Text; //GUI/Peer Tool Orchestrator
ws.Cells[8, 8] = textBox10.Text; //PLC Version
ws.Cells[9, 8] = textBox11.Text; //PLC Safety Version
ws.Cells[11, 8] = textBox15.Text; //Software Revision
ws.Cells[12, 8] = textBox14.Text; //Framework/EIB
ws.Cells[13, 8] = textBox16.Text; //GUI/Peer Tool Orchestrator
ws.Cells[14, 8] = textBox13.Text; //PLC Version
ws.Cells[15, 8] = textBox12.Text; //PLC Safety Version
toolStripProgressBar1.Value = 60;
if (comboBox1.Text == "Xperience")
{
ws.Cells[6, 6] = "Framework:"; //Labeling
ws.Cells[7, 6] = "GUI:"; //Labeling
ws.Cells[12, 6] = "Framework:"; //Labeling
ws.Cells[13, 6] = "GUI:"; //Labeling
}
if (comboBox1.Text == "PTO Classic")
{
ws.Cells[6, 6] = "EIB:"; //Labeling
ws.Cells[7, 6] = "Peer Tool Orchestrator:"; //Labeling
ws.Cells[12, 6] = "EIB:"; //Labeling
ws.Cells[13, 6] = "Peer Tool Orchestrator:"; //Labeling
}
if (comboBox1.Text == "Khan")
{
ws.Cells[6, 6] = "Khan Version:"; //Labeling
ws.Cells[7, 6] = "EEC Version:"; //Labeling
ws.Cells[8, 6] = "QCM Version:"; //Labeling
ws.Cells[9, 6] = " "; //Labeling
ws.Cells[12, 6] = "Khan Version:"; //Labeling
ws.Cells[13, 6] = "EEC Version:"; //Labeling
ws.Cells[14, 6] = "QCM Version:"; //Labeling
ws.Cells[15, 6] = " "; //Labeling
}
if (comboBox1.Text == "LLS")
{
ws.Cells[6, 6] = "GUI Version:"; //Labeling
ws.Cells[7, 6] = "PLC Version:"; //Labeling
ws.Cells[8, 6] = " "; //Labeling
ws.Cells[9, 6] = " "; //Labeling
ws.Cells[12, 6] = "GUI Version:"; //Labeling
ws.Cells[13, 6] = "PLC Version:"; //Labeling
ws.Cells[14, 6] = " "; //Labeling
ws.Cells[15, 6] = " "; //Labeling
}
toolStripProgressBar1.Value = 70;
wb.SaveAs(FirstPagePathEdited);
wb.Close();
toolStripProgressBar1.Value = 80;
System.IO.File.Move(FirstPagePathEdited, NewFirstPagePath);
toolStripProgressBar1.Value = 90;
Process[] workers = Process.GetProcessesByName("Excel");
foreach (Process worker in workers)
{
worker.Kill();
worker.WaitForExit();
worker.Dispose();
}
toolStripProgressBar1.Value = 100;
toolStripStatusLabel1.ForeColor = System.Drawing.Color.Green;
toolStripStatusLabel1.Text = "Saved";
MessageBox.Show("Data successfully saved.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
catch (Exception ex)
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
MessageBox.Show("System Error Message:\n\n" + ex.Message + "\n \nMaybe the folder directorys are not wherethey are supposed to be, control the folder directorys and naming of folders.", "Error Message XX", MessageBoxButtons.OK, MessageBoxIcon.Error);
toolStripStatusLabel1.ForeColor = System.Drawing.Color.Red;
toolStripStatusLabel1.Text = "Error X";
toolStripProgressBar1.Visible = false;
return;
}
}
else
{
DialogResult result1 = MessageBox.Show("Make sure all neccessary entries are made.\n\nThe fields required are marked with a star '*'.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (result1 == DialogResult.OK)
{
return;
}
}
var Form2 = new Form2();
Form2.Show();
this.Hide();
}
else if (result == DialogResult.Cancel)
{
return;
}
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
string dir = @"C:\ProgramData\UpdateReports\01_MainPage";
string dir1 = @"C:\ProgramData\UpdateReports\02_Comments";
string dir2 = @"C:\ProgramData\UpdateReports\03_TestResults";
string dir3 = @"C:\ProgramData\UpdateReports\04_Propositons";
string dir4 = @"C:\ProgramData\UpdateReports\05_FinalReport";
string dir5 = @"C:\ProgramData\UpdateReports\06_Templates";
string dir6 = @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp first page.xlsx" + @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp Comment.xlsx" + @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp Test Result.xlsx" + @"C:\ProgramData\UpdateReports\06_Templates\Software Update Report - temp Proposition.xlsx";
string dir7 = @"C:\ProgramData\UpdateReports\07_Single PDFs";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
if (!Directory.Exists(dir1))
{
Directory.CreateDirectory(dir1);
}
if (!Directory.Exists(dir2))
{
Directory.CreateDirectory(dir2);
}
if (!Directory.Exists(dir3))
{
Directory.CreateDirectory(dir3);
}
if (!Directory.Exists(dir4))
{
Directory.CreateDirectory(dir4);
}
if (!Directory.Exists(dir5))
{
Directory.CreateDirectory(dir5);
}
if (!System.IO.File.Exists(dir6))
{
Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp first page.xlsx");
Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp Comment.xlsx");
Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp Test Result.xlsx");
Extract("Update_Report", @"C:\ProgramData\UpdateReports\06_Templates", "Embedded", "Software Update Report - temp Proposition.xlsx");
}
if (!Directory.Exists(dir7))
{
Directory.CreateDirectory(dir7);
}
}
catch (Exception ex)
{
MessageBox.Show("System Error Message:\n\n" + ex.Message + "\n \n Maybe the folder directorys are not wher ethey are supposed to be, control the folder directorys and naming of folders.", "Error Message XX", MessageBoxButtons.OK, MessageBoxIcon.Error);
toolStripStatusLabel1.ForeColor = System.Drawing.Color.Red;
toolStripStatusLabel1.Text = "Error X";
toolStripProgressBar1.Visible = false;
return;
}
}
private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
Process.Start(textBox20.Text);
}
catch (Exception ex)
{
MessageBox.Show("Please check your added link it might not work.\n\n" + ex.Message, "Error XX", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
Process.Start(textBox19.Text);
}
catch (Exception ex)
{
MessageBox.Show("Please check your added link it might not work.\n\n" + ex.Message, "Error XX",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Are you sure you want to skip to the next Page?\n\n All entries made will be deleted.", "Notification", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
var Form2 = new Form2();
Form2.Show();
this.Hide();
}
else if (result == DialogResult.Cancel)
{
return;
}
}
private void comboBox6_TextChanged(object sender, EventArgs e)
{
if(comboBox6.Text == "Rollback")
{
groupBox6.Visible = true;
}
else if (comboBox6.Text == "Canceled")
{
groupBox6.Visible = true;
}
else
{
groupBox6.Visible = false;
}
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
}
private void comboBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox20_TextChanged(object sender, EventArgs e)
{
}
private void textBox19_TextChanged(object sender, EventArgs e)
{
}
public static string SetValueForText1 = "";
public static string SetValueForText2 = "";
private void toolStripMenuItem10_Click(object sender, EventArgs e)
{
String openPDFFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\SW Update Report Instructions.pdf";//PDF DOc name
System.IO.File.WriteAllBytes(openPDFFile, global::Update_Report.Properties.Resources.SW_Update_Report_Instructions);//the resource automatically creates
System.Diagnostics.Process.Start(openPDFFile);
}
private void toolStripMenuItem8_Click(object sender, EventArgs e)
{
var Form3 = new Form3();
Form3.Show();
}
}
}