08 Formulare


01 Vorlage
using System.Windows.Forms;
using Eplan.EplApi.Scripting;

public partial class FormVorlage : Form
{
  #region Windows Form Designer generated code
  public FormVorlage()
  {
    InitializeComponent();
  }

  private System.ComponentModel.IContainer components = null;

  protected override void Dispose(bool disposing)
  {
    if (disposing && (components != null))
    {
      components.Dispose();
    }
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
      this.SuspendLayout();
      // 
      // FormVorlage
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(284, 261);
      this.Name = "FormVorlage";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "Vorlage";
      this.ResumeLayout(false);

  }
  #endregion

  [Start]
  public void Function()
  {
    FormVorlage form = new FormVorlage();
    form.ShowDialog();

    return;
  }
}


02 Formularbeispiel
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

public partial class FormularBeispiel : System.Windows.Forms.Form
{
  private Button ButtonCancel;
  private Button ButtonOk;
  private CheckBox CheckBoxProjectCheck;
  private CheckBox CheckBoxReport;
  private CheckBox chkCheckall;
  private Label LabelProject;
  private ProgressBar ProgressBarFull;

  #region Vom Windows Form-Designer generierter Code

  /// <summary>
  /// Erforderliche Designervariable.
  /// </summary>
  private System.ComponentModel.IContainer components = null;

  /// <summary>
  /// Verwendete Ressourcen bereinigen.
  /// </summary>
  /// <param name="disposing">True, wenn verwaltete Ressourcen
  /// gelöscht werden sollen; andernfalls False.</param>
  protected override void Dispose(bool disposing)
  {
    if (disposing && (components != null))
    {
      components.Dispose();
    }
    base.Dispose(disposing);
  }

  /// <summary>
  /// Erforderliche Methode für die Designerunterstützung.
  /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert
  /// werden.
  /// </summary>
  private void InitializeComponent()
  {
      this.ButtonCancel = new System.Windows.Forms.Button();
      this.ButtonOk = new System.Windows.Forms.Button();
      this.CheckBoxProjectCheck = new System.Windows.Forms.CheckBox();
      this.CheckBoxReport = new System.Windows.Forms.CheckBox();
      this.chkCheckall = new System.Windows.Forms.CheckBox();
      this.LabelProject = new System.Windows.Forms.Label();
      this.ProgressBarFull = new System.Windows.Forms.ProgressBar();
      this.SuspendLayout();
      // 
      // ButtonCancel
      // 
      this.ButtonCancel.Location = new System.Drawing.Point(207, 240);
      this.ButtonCancel.Name = "ButtonCancel";
      this.ButtonCancel.Size = new System.Drawing.Size(75, 23);
      this.ButtonCancel.TabIndex = 5;
      this.ButtonCancel.Text = "Abbrechen";
      this.ButtonCancel.UseVisualStyleBackColor = true;
      this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
      // 
      // ButtonOk
      // 
      this.ButtonOk.Location = new System.Drawing.Point(126, 240);
      this.ButtonOk.Name = "ButtonOk";
      this.ButtonOk.Size = new System.Drawing.Size(75, 23);
      this.ButtonOk.TabIndex = 4;
      this.ButtonOk.Text = "OK";
      this.ButtonOk.UseVisualStyleBackColor = true;
      this.ButtonOk.Click += new System.EventHandler(this.ButtonOk_Click);
      // 
      // CheckBoxProjectCheck
      // 
      this.CheckBoxProjectCheck.AutoSize = true;
      this.CheckBoxProjectCheck.Checked = true;
      this.CheckBoxProjectCheck.CheckState = System.Windows.Forms.CheckState.Checked;
      this.CheckBoxProjectCheck.Location = new System.Drawing.Point(12, 25);
      this.CheckBoxProjectCheck.Name = "CheckBoxProjectCheck";
      this.CheckBoxProjectCheck.Size = new System.Drawing.Size(62, 17);
      this.CheckBoxProjectCheck.TabIndex = 1;
      this.CheckBoxProjectCheck.Text = "Prüflauf";
      this.CheckBoxProjectCheck.UseVisualStyleBackColor = true;
      // 
      // CheckBoxReport
      // 
      this.CheckBoxReport.AutoSize = true;
      this.CheckBoxReport.Checked = true;
      this.CheckBoxReport.CheckState = System.Windows.Forms.CheckState.Checked;
      this.CheckBoxReport.Location = new System.Drawing.Point(12, 48);
      this.CheckBoxReport.Name = "CheckBoxReport";
      this.CheckBoxReport.Size = new System.Drawing.Size(129, 17);
      this.CheckBoxReport.TabIndex = 2;
      this.CheckBoxReport.Text = "Auswertung erzeugen";
      this.CheckBoxReport.UseVisualStyleBackColor = true;
      // 
      // chkCheckall
      // 
      this.chkCheckall.AutoSize = true;
      this.chkCheckall.Checked = true;
      this.chkCheckall.CheckState = System.Windows.Forms.CheckState.Checked;
      this.chkCheckall.Location = new System.Drawing.Point(12, 244);
      this.chkCheckall.Name = "chkCheckall";
      this.chkCheckall.Size = new System.Drawing.Size(92, 17);
      this.chkCheckall.TabIndex = 3;
      this.chkCheckall.Text = "Alle aktivieren";
      this.chkCheckall.UseVisualStyleBackColor = true;
      this.chkCheckall.CheckedChanged += new System.EventHandler(this.chbCheckall_CheckedChanged);
      // 
      // LabelProject
      // 
      this.LabelProject.AutoSize = true;
      this.LabelProject.Location = new System.Drawing.Point(9, 9);
      this.LabelProject.Name = "LabelProject";
      this.LabelProject.Size = new System.Drawing.Size(66, 13);
      this.LabelProject.TabIndex = 5;
      this.LabelProject.Text = "Projektname";
      // 
      // ProgressBarFull
      // 
      this.ProgressBarFull.Location = new System.Drawing.Point(12, 224);
      this.ProgressBarFull.Maximum = 3;
      this.ProgressBarFull.Name = "ProgressBarFull";
      this.ProgressBarFull.Size = new System.Drawing.Size(270, 10);
      this.ProgressBarFull.Step = 1;
      this.ProgressBarFull.TabIndex = 6;
      // 
      // FormularBeispiel
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Controls.Add(this.ProgressBarFull);
      this.Controls.Add(this.LabelProject);
      this.Controls.Add(this.chkCheckall);
      this.Controls.Add(this.CheckBoxReport);
      this.Controls.Add(this.CheckBoxProjectCheck);
      this.Controls.Add(this.ButtonOk);
      this.Controls.Add(this.ButtonCancel);
      this.Name = "FormularBeispiel";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "Formularbeispiel";
      this.Load += new System.EventHandler(this.FormularBeispiel_Load);
      this.ResumeLayout(false);
      this.PerformLayout();

  }

  public FormularBeispiel()
  {
    InitializeComponent();
  }

  #endregion

  [Start]
  public void Function()
  {
    FormularBeispiel form = new FormularBeispiel();
    form.ShowDialog();

    return;
  }

  private void ButtonCancel_Click(object sender, System.EventArgs e)
  {
    this.Close();

    return;
  }

  private void ButtonOk_Click(object sender, System.EventArgs e)
  {
    CommandLineInterpreter cli = new CommandLineInterpreter();

    ProgressBarFull.PerformStep();
    if (CheckBoxProjectCheck.Checked)
    {
      cli.Execute("XMsgActionStartVerification");
    }

    ProgressBarFull.PerformStep();
    if (CheckBoxReport.Checked)
    {
      cli.Execute("reports");
    }

    ProgressBarFull.PerformStep();   
    ProgressBarFull.Value = 0;

    this.Close();

    return;
  }

  private void chbCheckall_CheckedChanged(object sender, System.EventArgs e)
  {
    if (chkCheckall.Checked)
    {
      CheckBoxProjectCheck.Checked = true;
      CheckBoxReport.Checked = true;
    }
    else
    {
      CheckBoxProjectCheck.Checked = false;
      CheckBoxReport.Checked = false;
    }

    return;
  }

  private void FormularBeispiel_Load(object sender, System.EventArgs e)
  {
    LabelProject.Text = PathMap.SubstitutePath("$(PROJECTNAME)");
  }
}


03 Cursor
using Eplan.EplApi.Scripting;
using System.Threading;
using System.Windows.Forms;

public class _08_Formulare_03_Cursor
{
  [Start]
  public void Function()
  {
    Cursor.Current = Cursors.AppStarting;
    Thread.Sleep(3000);
    Cursor.Current = Cursors.WaitCursor;
    Thread.Sleep(3000);

    return;
  }
}


04 Projektsuche
using System;
using System.IO;
using System.Windows.Forms;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.Base;
using Eplan.EplApi.Scripting;

public class Projektsuche : System.Windows.Forms.Form
{
  public string ProjectPath = string.Empty;

  #region Formular
  public Projektsuche()
  {
    InitializeComponent();
  }

  private System.Windows.Forms.Button ButtonOK;
  private System.Windows.Forms.ListView ListViewResult;
  private System.Windows.Forms.ColumnHeader columnHeader1;
  private System.Windows.Forms.ColumnHeader columnHeader2;
  private System.Windows.Forms.ColumnHeader columnHeader3;
  private System.Windows.Forms.Button ButtonSearch;
  private System.Windows.Forms.TextBox TextBoxSearch;
  private System.Windows.Forms.StatusStrip StatusStipMain;
  private System.Windows.Forms.Button ButtonCancel;
  private ToolStripStatusLabel ToolStripLabel;

  ///
  /// 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.ButtonOK = new System.Windows.Forms.Button();
      this.ListViewResult = new System.Windows.Forms.ListView();
      this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
      this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
      this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
      this.ButtonSearch = new System.Windows.Forms.Button();
      this.TextBoxSearch = new System.Windows.Forms.TextBox();
      this.StatusStipMain = new System.Windows.Forms.StatusStrip();
      this.ToolStripLabel = new System.Windows.Forms.ToolStripStatusLabel();
      this.ButtonCancel = new System.Windows.Forms.Button();
      this.StatusStipMain.SuspendLayout();
      this.SuspendLayout();
      // 
      // ButtonOK
      // 
      this.ButtonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
      this.ButtonOK.Location = new System.Drawing.Point(474, 274);
      this.ButtonOK.Name = "ButtonOK";
      this.ButtonOK.Size = new System.Drawing.Size(75, 23);
      this.ButtonOK.TabIndex = 6;
      this.ButtonOK.Text = "OK";
      this.ButtonOK.UseVisualStyleBackColor = true;
      this.ButtonOK.Click += new System.EventHandler(this.ButtonOK_Click);
      // 
      // ListViewResult
      // 
      this.ListViewResult.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.ListViewResult.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1,
            this.columnHeader2,
            this.columnHeader3});
      this.ListViewResult.FullRowSelect = true;
      this.ListViewResult.GridLines = true;
      this.ListViewResult.HideSelection = false;
      this.ListViewResult.Location = new System.Drawing.Point(12, 39);
      this.ListViewResult.Name = "ListViewResult";
      this.ListViewResult.Size = new System.Drawing.Size(618, 229);
      this.ListViewResult.Sorting = System.Windows.Forms.SortOrder.Ascending;
      this.ListViewResult.TabIndex = 10;
      this.ListViewResult.UseCompatibleStateImageBehavior = false;
      this.ListViewResult.View = System.Windows.Forms.View.Details;
      this.ListViewResult.DoubleClick += new System.EventHandler(this.ListViewResult_DoubleClick);
      // 
      // columnHeader1
      // 
      this.columnHeader1.Text = "Projektname";
      this.columnHeader1.Width = 76;
      // 
      // columnHeader2
      // 
      this.columnHeader2.Text = "Pfad";
      this.columnHeader2.Width = 89;
      // 
      // columnHeader3
      // 
      this.columnHeader3.Text = "Erweiterung";
      this.columnHeader3.Width = 223;
      // 
      // ButtonSearch
      // 
      this.ButtonSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.ButtonSearch.Enabled = false;
      this.ButtonSearch.Location = new System.Drawing.Point(530, 9);
      this.ButtonSearch.Name = "ButtonSearch";
      this.ButtonSearch.Size = new System.Drawing.Size(100, 23);
      this.ButtonSearch.TabIndex = 9;
      this.ButtonSearch.Text = "Suchen";
      this.ButtonSearch.UseVisualStyleBackColor = true;
      this.ButtonSearch.Click += new System.EventHandler(this.ButtonSearch_Click);
      // 
      // TextBoxSearch
      // 
      this.TextBoxSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
      this.TextBoxSearch.Location = new System.Drawing.Point(12, 11);
      this.TextBoxSearch.Name = "TextBoxSearch";
      this.TextBoxSearch.Size = new System.Drawing.Size(512, 20);
      this.TextBoxSearch.TabIndex = 8;
      this.TextBoxSearch.TextChanged += new System.EventHandler(this.TextBoxSearch_TextChanged);
      // 
      // StatusStipMain
      // 
      this.StatusStipMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.ToolStripLabel});
      this.StatusStipMain.Location = new System.Drawing.Point(0, 301);
      this.StatusStipMain.Name = "StatusStipMain";
      this.StatusStipMain.Size = new System.Drawing.Size(642, 22);
      this.StatusStipMain.TabIndex = 13;
      this.StatusStipMain.Text = "statusStrip1";
      // 
      // ToolStripLabel
      // 
      this.ToolStripLabel.Name = "ToolStripLabel";
      this.ToolStripLabel.Size = new System.Drawing.Size(627, 17);
      this.ToolStripLabel.Spring = true;
      this.ToolStripLabel.Text = "Suchbegriff eingeben...";
      this.ToolStripLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
      // 
      // ButtonCancel
      // 
      this.ButtonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
      this.ButtonCancel.Location = new System.Drawing.Point(555, 274);
      this.ButtonCancel.Name = "ButtonCancel";
      this.ButtonCancel.Size = new System.Drawing.Size(75, 23);
      this.ButtonCancel.TabIndex = 15;
      this.ButtonCancel.Text = "Abbrechen";
      this.ButtonCancel.UseVisualStyleBackColor = true;
      this.ButtonCancel.Click += new System.EventHandler(this.btnCancel_Click);
      // 
      // Projektsuche
      // 
      this.AcceptButton = this.ButtonSearch;
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.BackColor = System.Drawing.SystemColors.Control;
      this.ClientSize = new System.Drawing.Size(642, 323);
      this.Controls.Add(this.ButtonCancel);
      this.Controls.Add(this.StatusStipMain);
      this.Controls.Add(this.ListViewResult);
      this.Controls.Add(this.ButtonSearch);
      this.Controls.Add(this.TextBoxSearch);
      this.Controls.Add(this.ButtonOK);
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.MinimumSize = new System.Drawing.Size(450, 200);
      this.Name = "Projektsuche";
      this.ShowIcon = false;
      this.ShowInTaskbar = false;
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "Projektsuche";
      this.Load += new System.EventHandler(this.Projektsuche_Load);
      this.StatusStipMain.ResumeLayout(false);
      this.StatusStipMain.PerformLayout();
      this.ResumeLayout(false);
      this.PerformLayout();

  }

  #endregion

  [DeclareMenu]
  public void MenuFunction()
  {
    Eplan.EplApi.Gui.Menu menu = new Eplan.EplApi.Gui.Menu();
    menu.AddMenuItem
        (
        "Projektsuche...",
        "Projektsuche",
        "Projekt(e) suchen und öffnen",
        35002,
        1,
        false,
        false
        );

    return;
  }

  [DeclareAction("Projektsuche")]
  public void SearchMacrosVoid()
  {
    Projektsuche form = new Projektsuche();
    form.ShowDialog();

    return;
  }

  private void Projektsuche_Load(object sender, System.EventArgs e)
  {
    ProjectPath = PathMap.SubstitutePath("$(MD_PROJECTS)");
    TextBoxSearch.Select();

    return;
  }

  private void btnCancel_Click(object sender, System.EventArgs e)
  {
    this.Close();

    return;
  }


  private void OpenProject(string fullProjectPath)
  {
    Cursor.Current = Cursors.WaitCursor;

    ToolStripLabel.Text = "Projekt '"
        + Path.GetFileNameWithoutExtension(fullProjectPath)
        + "' wird geöffnet...";

    this.Update();

    CommandLineInterpreter cli = new CommandLineInterpreter();
    ActionCallingContext acc = new ActionCallingContext();
    acc.AddParameter("Project", fullProjectPath);
    cli.Execute("ProjectOpen", acc);

    Cursor.Current = Cursors.Default;

    return;
  }

  private void ButtonSearch_Click(object sender, System.EventArgs e)
  {
    Cursor.Current = Cursors.WaitCursor;

    ToolStripLabel.Text = "Projekt(e) werden gesucht...";

    ListViewResult.BeginUpdate();

    GetProjects();

    ListViewResult.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);

    ListViewResult.EndUpdate();

    Cursor.Current = Cursors.Default;

    return;
  }

  private void GetProjects()
  {
    ListViewResult.Items.Clear();

    string[] result = Directory.GetFiles(ProjectPath,
        "*" + TextBoxSearch.Text + "*.el*",
        SearchOption.TopDirectoryOnly
        );

    foreach (string project in result)
    {
      FillListView(project);
    }

    ToolStripLabel.Text = "Projekte gefunden: "
        + ListViewResult.Items.Count.ToString();

    return;
  }

  private void FillListView(string fullPath)
  {
    FileInfo fileInfo = new FileInfo(fullPath);

    string fileNameWithoutExtension =
        Path.GetFileNameWithoutExtension(fileInfo.FullName);
    string directory = fileInfo.Directory.ToString() + @"\";
    string extension = fileInfo.Extension;

    ListViewItem listViewItem = new ListViewItem();
    listViewItem.Text = fileNameWithoutExtension;
    listViewItem.SubItems.Add(directory);
    listViewItem.SubItems.Add(extension);
    ListViewResult.Items.Add(listViewItem);

    return;
  }

  private void ButtonOK_Click(object sender, System.EventArgs e)
  {
    GetFileNameAndOpen();

    return;
  }

  private void ListViewResult_DoubleClick(object sender, EventArgs e)
  {
    GetFileNameAndOpen();

    return;
  }

  private void GetFileNameAndOpen()
  {
    if (ListViewResult.SelectedItems.Count > 0)
    {
      string project =
            ListViewResult.SelectedItems[0].SubItems[1].Text
          + ListViewResult.SelectedItems[0].SubItems[0].Text
          + ListViewResult.SelectedItems[0].SubItems[2].Text;

      OpenProject(project);
    }

    this.Close();

    return;
  }

  private void TextBoxSearch_TextChanged(object sender, System.EventArgs e)
  {
    if (TextBoxSearch.Text == "")
    {
      ButtonSearch.Enabled = false;
    }
    else
    {
      ButtonSearch.Enabled = true;
    }

    return;
  }

}