203 lines
6.5 KiB
C#
203 lines
6.5 KiB
C#
|
using System.Windows.Forms;
|
||
|
using nsoftware.SecureBlackbox;
|
||
|
|
||
|
namespace nsoftware.Demos
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Summary description for ReferencesForm.
|
||
|
/// </summary>
|
||
|
public class ReferencesForm : System.Windows.Forms.Form
|
||
|
{
|
||
|
private System.Windows.Forms.ListBox lbReferences;
|
||
|
private System.Windows.Forms.Button btnAdd;
|
||
|
private System.Windows.Forms.Button btnDelete;
|
||
|
private System.Windows.Forms.Button btnEdit;
|
||
|
private System.Windows.Forms.Button btnClose;
|
||
|
/// <summary>
|
||
|
/// Required designer variable.
|
||
|
/// </summary>
|
||
|
private System.ComponentModel.Container components = null;
|
||
|
|
||
|
public ReferenceForm frmReference;
|
||
|
|
||
|
private XMLReferenceList FReferences = null;
|
||
|
|
||
|
public ReferencesForm(XMLReferenceList references)
|
||
|
{
|
||
|
//
|
||
|
// Required for Windows Form Designer support
|
||
|
//
|
||
|
InitializeComponent();
|
||
|
|
||
|
//
|
||
|
// TODO: Add any constructor code after InitializeComponent call
|
||
|
//
|
||
|
frmReference = new ReferenceForm();
|
||
|
|
||
|
FReferences = references;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Clean up any resources being used.
|
||
|
/// </summary>
|
||
|
protected override void Dispose( bool disposing )
|
||
|
{
|
||
|
if( disposing )
|
||
|
{
|
||
|
if(components != null)
|
||
|
{
|
||
|
components.Dispose();
|
||
|
frmReference.Dispose();
|
||
|
}
|
||
|
}
|
||
|
base.Dispose( disposing );
|
||
|
}
|
||
|
|
||
|
#region Windows Form Designer generated code
|
||
|
/// <summary>
|
||
|
/// Required method for Designer support - do not modify
|
||
|
/// the contents of this method with the code editor.
|
||
|
/// </summary>
|
||
|
private void InitializeComponent()
|
||
|
{
|
||
|
this.lbReferences = new System.Windows.Forms.ListBox();
|
||
|
this.btnAdd = new System.Windows.Forms.Button();
|
||
|
this.btnDelete = new System.Windows.Forms.Button();
|
||
|
this.btnEdit = new System.Windows.Forms.Button();
|
||
|
this.btnClose = new System.Windows.Forms.Button();
|
||
|
this.SuspendLayout();
|
||
|
//
|
||
|
// lbReferences
|
||
|
//
|
||
|
this.lbReferences.Location = new System.Drawing.Point(10, 10);
|
||
|
this.lbReferences.Name = "lbReferences";
|
||
|
this.lbReferences.Size = new System.Drawing.Size(188, 212);
|
||
|
this.lbReferences.TabIndex = 0;
|
||
|
//
|
||
|
// btnAdd
|
||
|
//
|
||
|
this.btnAdd.Location = new System.Drawing.Point(210, 10);
|
||
|
this.btnAdd.Name = "btnAdd";
|
||
|
this.btnAdd.Size = new System.Drawing.Size(75, 25);
|
||
|
this.btnAdd.TabIndex = 1;
|
||
|
this.btnAdd.Text = "Add";
|
||
|
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
|
||
|
//
|
||
|
// btnDelete
|
||
|
//
|
||
|
this.btnDelete.Location = new System.Drawing.Point(210, 80);
|
||
|
this.btnDelete.Name = "btnDelete";
|
||
|
this.btnDelete.Size = new System.Drawing.Size(75, 25);
|
||
|
this.btnDelete.TabIndex = 2;
|
||
|
this.btnDelete.Text = "Delete";
|
||
|
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
|
||
|
//
|
||
|
// btnEdit
|
||
|
//
|
||
|
this.btnEdit.Location = new System.Drawing.Point(210, 45);
|
||
|
this.btnEdit.Name = "btnEdit";
|
||
|
this.btnEdit.Size = new System.Drawing.Size(75, 25);
|
||
|
this.btnEdit.TabIndex = 3;
|
||
|
this.btnEdit.Text = "Edit";
|
||
|
this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
|
||
|
//
|
||
|
// btnClose
|
||
|
//
|
||
|
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.OK;
|
||
|
this.btnClose.Location = new System.Drawing.Point(210, 197);
|
||
|
this.btnClose.Name = "btnClose";
|
||
|
this.btnClose.Size = new System.Drawing.Size(75, 25);
|
||
|
this.btnClose.TabIndex = 4;
|
||
|
this.btnClose.Text = "Close";
|
||
|
//
|
||
|
// ReferencesForm
|
||
|
//
|
||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||
|
this.CancelButton = this.btnClose;
|
||
|
this.ClientSize = new System.Drawing.Size(294, 231);
|
||
|
this.Controls.Add(this.btnClose);
|
||
|
this.Controls.Add(this.btnEdit);
|
||
|
this.Controls.Add(this.btnDelete);
|
||
|
this.Controls.Add(this.btnAdd);
|
||
|
this.Controls.Add(this.lbReferences);
|
||
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||
|
this.MaximizeBox = false;
|
||
|
this.Name = "ReferencesForm";
|
||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||
|
this.Text = "References";
|
||
|
this.ResumeLayout(false);
|
||
|
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
private void btnEdit_Click(object sender, System.EventArgs e)
|
||
|
{
|
||
|
if (lbReferences.SelectedIndex >= 0)
|
||
|
{
|
||
|
frmReference.Initialize(FReferences[lbReferences.SelectedIndex]);
|
||
|
if (frmReference.ShowDialog() == DialogResult.OK)
|
||
|
{
|
||
|
int k = lbReferences.SelectedIndex;
|
||
|
// recreating a reference, to completely clear it
|
||
|
FReferences.RemoveAt(k);
|
||
|
FReferences.Insert(k, new XMLReference());
|
||
|
|
||
|
frmReference.UpdateReference(FReferences[k]);
|
||
|
|
||
|
UpdateReferences();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void UpdateReferences()
|
||
|
{
|
||
|
lbReferences.Items.Clear();
|
||
|
for (int i = 0; i < FReferences.Count; i++)
|
||
|
{
|
||
|
string Id = FReferences[i].ID;
|
||
|
string s = FReferences[i].URI;
|
||
|
if (string.IsNullOrEmpty(s))
|
||
|
s = FReferences[i].TargetXMLElement;
|
||
|
|
||
|
if (string.IsNullOrEmpty(s))
|
||
|
{
|
||
|
if ((FReferences[i].TargetData == null) || (FReferences[i].TargetData.Length == 0))
|
||
|
s = "#document";
|
||
|
else
|
||
|
s = "#data";
|
||
|
}
|
||
|
|
||
|
if (!string.IsNullOrEmpty(Id))
|
||
|
s = Id + " - " + s;
|
||
|
|
||
|
lbReferences.Items.Add(s);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void btnAdd_Click(object sender, System.EventArgs e)
|
||
|
{
|
||
|
XMLReference Ref = new XMLReference();
|
||
|
|
||
|
frmReference.Initialize(Ref);
|
||
|
if (frmReference.ShowDialog() == DialogResult.OK)
|
||
|
{
|
||
|
frmReference.UpdateReference(Ref);
|
||
|
FReferences.Add(Ref);
|
||
|
|
||
|
UpdateReferences();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void btnDelete_Click(object sender, System.EventArgs e)
|
||
|
{
|
||
|
if (lbReferences.SelectedIndex >= 0)
|
||
|
{
|
||
|
FReferences.RemoveAt(lbReferences.SelectedIndex);
|
||
|
|
||
|
UpdateReferences();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|