using System.Windows.Forms;
using Eplan.EplApi.Scripting;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using System;
using System.IO;
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 = "";
//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.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.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(16, 129);
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(16, 83);
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(130, 83);
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(12, 22);
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(12, 55);
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(191, 123);
this.buttonNo.Name = "buttonNo";
this.buttonNo.Size = new System.Drawing.Size(74, 27);
this.buttonNo.TabIndex = 5;
this.buttonNo.Text = "Abbruch";
this.buttonNo.UseVisualStyleBackColor = true;
this.buttonNo.Click += new System.EventHandler(this.buttonNo_Click);
//
// buttonYes
//
this.buttonYes.Location = new System.Drawing.Point(271, 112);
this.buttonYes.Name = "buttonYes";
this.buttonYes.Size = new System.Drawing.Size(110, 48);
this.buttonYes.TabIndex = 6;
this.buttonYes.Text = "Erstellen";
this.buttonYes.UseVisualStyleBackColor = true;
this.buttonYes.Click += new System.EventHandler(this.buttonYes_Click);
//
// 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(404, 177);
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);
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;
}
return;
}
#endregion
#region Button Abbruch
private void buttonNo_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region Button Erstellen
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();
return;
}
return;
}
#endregion
#region Unterprogrmme 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);
return;
}
}
private void Backup()
{
string strFullProjectname = PathMap.SubstitutePath("$(P)");
//try
//{
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("P8 command does not work", "backup");
}
progress.EndPart();
}
progress.EndPart(true);
this.Close();
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
#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
}