using System.Windows.Forms;
using Eplan.EplApi.Scripting;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using System;
using System.IO;
using System.Diagnostics;
using System.Drawing;
public partial class BackupOnClosingProject_Form : System.Windows.Forms.Form
{
private FolderBrowserDialog folderBrowserDialog1;
private CheckBox checkBoxOverwriting;
private CheckBox checkBoxDate;
private CheckBox checkBoxDateTime;
private Label labelProjectName;
private Label labelNewFileName;
private Button buttonNo;
private Button buttonYes;
private string GeneratedNameBackup = "";
private string strProjectname = "";
private string myDate = "";
private string hour = "";
private string minute = "";
private string DestinationPath = "";
private PictureBox ImageLogo;
private ToolTip toolTip1;
//public int PatchIndicator = 0;
#region Vom Windows Form-Designer generierter Code
///
/// Erforderliche Designervariable.
///
private System.ComponentModel.IContainer components = null;
///
/// Verwendete Ressourcen bereinigen.
///
/// True, wenn verwaltete Ressourcen
/// gelöscht werden sollen; andernfalls False.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
///
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor
/// geändert werden.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.checkBoxOverwriting = new System.Windows.Forms.CheckBox();
this.checkBoxDate = new System.Windows.Forms.CheckBox();
this.checkBoxDateTime = new System.Windows.Forms.CheckBox();
this.labelProjectName = new System.Windows.Forms.Label();
this.labelNewFileName = new System.Windows.Forms.Label();
this.buttonNo = new System.Windows.Forms.Button();
this.buttonYes = new System.Windows.Forms.Button();
this.ImageLogo = new System.Windows.Forms.PictureBox();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
((System.ComponentModel.ISupportInitialize)(this.ImageLogo)).BeginInit();
this.SuspendLayout();
//
// checkBoxOverwriting
//
this.checkBoxOverwriting.AutoSize = true;
this.checkBoxOverwriting.Checked = true;
this.checkBoxOverwriting.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxOverwriting.Location = new System.Drawing.Point(17, 227);
this.checkBoxOverwriting.Name = "checkBoxOverwriting";
this.checkBoxOverwriting.Size = new System.Drawing.Size(139, 17);
this.checkBoxOverwriting.TabIndex = 0;
this.checkBoxOverwriting.Text = "Überschreiben erlauben";
this.checkBoxOverwriting.UseVisualStyleBackColor = true;
//
// checkBoxDate
//
this.checkBoxDate.AutoSize = true;
this.checkBoxDate.Location = new System.Drawing.Point(17, 181);
this.checkBoxDate.Name = "checkBoxDate";
this.checkBoxDate.Size = new System.Drawing.Size(108, 17);
this.checkBoxDate.TabIndex = 1;
this.checkBoxDate.Text = "Datum anhängen";
this.checkBoxDate.UseVisualStyleBackColor = true;
this.checkBoxDate.CheckedChanged += new System.EventHandler(this.checkBoxDate_CheckedChanged);
//
// checkBoxDateTime
//
this.checkBoxDateTime.AutoSize = true;
this.checkBoxDateTime.Location = new System.Drawing.Point(131, 181);
this.checkBoxDateTime.Name = "checkBoxDateTime";
this.checkBoxDateTime.Size = new System.Drawing.Size(165, 17);
this.checkBoxDateTime.TabIndex = 2;
this.checkBoxDateTime.Text = "Datum und Uhrzeit anhängen";
this.checkBoxDateTime.UseVisualStyleBackColor = true;
this.checkBoxDateTime.CheckedChanged += new System.EventHandler(this.checkBoxDateTime_CheckedChanged);
//
// labelProjectName
//
this.labelProjectName.AutoSize = true;
this.labelProjectName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelProjectName.Location = new System.Drawing.Point(13, 120);
this.labelProjectName.Name = "labelProjectName";
this.labelProjectName.Size = new System.Drawing.Size(109, 20);
this.labelProjectName.TabIndex = 3;
this.labelProjectName.Text = "Projektname";
//
// labelNewFileName
//
this.labelNewFileName.AutoSize = true;
this.labelNewFileName.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelNewFileName.Location = new System.Drawing.Point(13, 153);
this.labelNewFileName.Name = "labelNewFileName";
this.labelNewFileName.Size = new System.Drawing.Size(203, 16);
this.labelNewFileName.TabIndex = 4;
this.labelNewFileName.Text = "Dateiname für die Sicherung";
//
// buttonNo
//
this.buttonNo.Location = new System.Drawing.Point(296, 210);
this.buttonNo.Name = "buttonNo";
this.buttonNo.Size = new System.Drawing.Size(110, 48);
this.buttonNo.TabIndex = 5;
this.buttonNo.Text = "schließen ohne Sicherung";
this.buttonNo.UseVisualStyleBackColor = true;
this.buttonNo.Click += new System.EventHandler(this.buttonNo_Click);
//
// buttonYes
//
this.buttonYes.Location = new System.Drawing.Point(412, 210);
this.buttonYes.Name = "buttonYes";
this.buttonYes.Size = new System.Drawing.Size(110, 48);
this.buttonYes.TabIndex = 6;
this.buttonYes.Text = "schließen mit Sicherung";
this.buttonYes.UseVisualStyleBackColor = true;
this.buttonYes.Click += new System.EventHandler(this.buttonYes_Click);
//
// ImageLogo
//
this.ImageLogo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ImageLogo.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.ImageLogo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.ImageLogo.Location = new System.Drawing.Point(16, 12);
this.ImageLogo.Name = "ImageLogo";
this.ImageLogo.Size = new System.Drawing.Size(506, 93);
this.ImageLogo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.ImageLogo.TabIndex = 60;
this.ImageLogo.TabStop = false;
//
// BackupOnClosingProject_Form
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.AutoValidate = System.Windows.Forms.AutoValidate.Disable;
this.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.ClientSize = new System.Drawing.Size(541, 279);
this.Controls.Add(this.ImageLogo);
this.Controls.Add(this.buttonYes);
this.Controls.Add(this.buttonNo);
this.Controls.Add(this.labelNewFileName);
this.Controls.Add(this.labelProjectName);
this.Controls.Add(this.checkBoxDateTime);
this.Controls.Add(this.checkBoxDate);
this.Controls.Add(this.checkBoxOverwriting);
this.Name = "BackupOnClosingProject_Form";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "BackupOnClosingProject";
this.Load += new System.EventHandler(this.BackupOnClosingProject_Form_Load);
((System.ComponentModel.ISupportInitialize)(this.ImageLogo)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
public BackupOnClosingProject_Form()
{
InitializeComponent();
}
#endregion
#region Function Start der Anwendung bestimmen
[DeclareEventHandler("onActionStart.String.XPrjActionProjectClose")]
//[Start]
public void Function()
{
BackupOnClosingProject_Form frm = new BackupOnClosingProject_Form();
frm.ShowDialog();
return;
}
#endregion
#region Eingabemaske BackupOnClosingProject_Form / Form
private void BackupOnClosingProject_Form_Load(object sender, EventArgs e)
{
DestinationPath = PathMap.SubstitutePath("$(EPLAN_DATA)" + @"\Tagessicherung_zw1");
strProjectname = PathMap.SubstitutePath("$(PROJECTNAME)");
myDate = System.DateTime.Now.ToString("yyMMdd");
//string myDate = System.DateTime.Now.ToString("yyyy.MM.dd");
this.labelProjectName.Text = strProjectname;
if (!checkBoxDate.Checked && !checkBoxDateTime.Checked)
{
GeneratedNameBackup = strProjectname;
this.labelNewFileName.Text = GeneratedNameBackup;
}
#region Logo laden und anzeigen ggf. Meldung kein Logo vorhanden! / Version anzeigen
string strLogoPath = @""; // hier Link zum LOGO
if (File.Exists(strLogoPath))
{
try
{
ImageLogo.Image = LoadImageFromFile(strLogoPath);
toolTip1.SetToolTip(this.ImageLogo, "Logo: " + strLogoPath);
}
catch
{
}
}
else
{
if (String.IsNullOrEmpty(strLogoPath))
{
strLogoPath = "kein Logo vorhanden! Pfad: " + strLogoPath; // Meldung anzeigen?
}
toolTip1.SetToolTip(this.ImageLogo, strLogoPath);
ImageLogo.Image = null;
}
return;
#endregion
}
#endregion
#region Button schließen ohne Sicherung
private void buttonNo_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region Button schließen mit Sicherung
private void buttonYes_Click(object sender, EventArgs e)
{
string DubblingTest = DestinationPath + @"\" + GeneratedNameBackup + @".zw1";
if (Directory.Exists(DestinationPath))
{
if (File.Exists(DubblingTest))
{
if (checkBoxOverwriting.Checked)
{
Backup();
}
else
{
DialogResult Result = MessageBox.Show("Dateiname existiert!\nBeenden?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (Result == DialogResult.No)
{
return;
}
this.Close();
}
}
else
{
Backup();
}
}
else
{
CreateOrderPath();
}
}
#endregion
#region Pfadgenerieren und Backup erstellen
private void CreateOrderPath()
{
DialogResult Result = MessageBox.Show("Pfad exestiert nicht!\nAnlegen?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (Result == DialogResult.No) // bei No zurück
{
this.Close();
}
else
{
Directory.CreateDirectory(DestinationPath);
}
}
private void Backup()
{
string strFullProjectname = PathMap.SubstitutePath("$(P)");
Progress progress = new Progress("SimpleProgress");
progress.BeginPart(100, "");
progress.SetAllowCancel(true);
if (!progress.Canceled())
{
progress.BeginPart(33, "Backup");
ActionCallingContext backupContext = new ActionCallingContext();
backupContext.AddParameter("BACKUPMEDIA", "DISK");
backupContext.AddParameter("BACKUPMETHOD", "BACKUP");
backupContext.AddParameter("COMPRESSPRJ", "0");
backupContext.AddParameter("INCLEXTDOCS", "1");
backupContext.AddParameter("BACKUPAMOUNT", "BACKUPAMOUNT_ALL");
backupContext.AddParameter("INCLIMAGES", "1");
backupContext.AddParameter("LogMsgActionDone", "true");
backupContext.AddParameter("DESTINATIONPATH", DestinationPath);
backupContext.AddParameter("PROJECTNAME", strFullProjectname);
backupContext.AddParameter("TYPE", "PROJECT");
backupContext.AddParameter("ARCHIVENAME", GeneratedNameBackup);
new CommandLineInterpreter().Execute("backup", backupContext);
bool bRetVal = new CommandLineInterpreter().Execute("backup", backupContext);
if (!bRetVal)
{
MessageBox.Show("Sicherung nicht möglich.\nMultiuser Konflikt!", "Fehler");
}
//bool bRetVal = new CommandLineInterpreter().Execute("CurrentUsers", backupContext);
//if (!bRetVal)
//{
// MessageBox.Show("Sicherung nicht möglich.\nMultiuser Konflikt!", "Fehler");
//}
progress.EndPart();
}
progress.EndPart(true);
this.Close();
}
#endregion
#region Anzeige und Generierung Dateiname
private void checkBoxDate_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxDate.Checked)
{
checkBoxDateTime.Checked = false;
checkBoxDate.Checked = true;
GeneratedNameBackup = strProjectname + "_" + myDate;
this.labelNewFileName.Text = GeneratedNameBackup;
}
else
{
GeneratedNameBackup = strProjectname;
this.labelNewFileName.Text = GeneratedNameBackup;
}
}
private void checkBoxDateTime_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxDateTime.Checked)
{
checkBoxDate.Checked = false;
checkBoxDateTime.Checked = true;
hour = System.DateTime.Now.Hour.ToString();
minute = System.DateTime.Now.Minute.ToString();
GeneratedNameBackup = strProjectname + "_" + myDate + "_TIME_" + hour + "." + minute;
this.labelNewFileName.Text = GeneratedNameBackup;
}
else
{
GeneratedNameBackup = strProjectname;
this.labelNewFileName.Text = GeneratedNameBackup;
}
}
#endregion
#region Logo anzeigen
private Image LoadImageFromFile(string sImageFullFilename)
{
if (File.Exists(sImageFullFilename))
{
FileStream fstream = new FileStream(sImageFullFilename, FileMode.Open, FileAccess.Read);
Image oIMG = Image.FromStream(fstream);
fstream.Close();
fstream.Dispose();
return oIMG;
}
else
{
return null;
}
}
#endregion
}