Initial Commit of the PDM project (ready for DWS migration)
This commit is contained in:
601
documentation/api_extracted/Add_Items_Example_CSharp.htm
Normal file
601
documentation/api_extracted/Add_Items_Example_CSharp.htm
Normal file
@@ -0,0 +1,601 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Add Items Example (C#)</title>
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
|
||||
</head>
|
||||
<meta name=MS-HKWD content="C# examples,items">
|
||||
<meta name=MS-HKWD content="C# examples,XmlReader class">
|
||||
|
||||
<body>
|
||||
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
||||
<h1>Add Items Example (C#)</h1>
|
||||
<p><a name="Top"></a>This example shows how to add items to a vault. The data
|
||||
for the items is imported from an XML file, which is read by the .NET XmlReader.</p>
|
||||
<p><b>NOTE</b>: If using the primary interop assembly
|
||||
provided with SOLIDWORKS PDM Professional, see
|
||||
<a href="Using_NET_Framework_in_Applications.htm">Using .NET Framework 4.0 in
|
||||
Stand-alone Applications</a>.</p>
|
||||
<p><img border="0" src="AddItems.gif" width="315" height="358"></p>
|
||||
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: green">//----------------------------------------------------------------------------</span>
|
||||
<span style="color: green">// Preconditions:</span>
|
||||
<span style="color: green">// 1. Create an XML file for this example.</span>
|
||||
<span style="color: green">// a. Open a text editor like Notepad and copy and paste <a href="#XML">this code</a> </span>
|
||||
<span style="color: green">// into the editor.</span>
|
||||
<span style="color: green">// b. Save the file as <b>Items.xml</b> and remember where you save the file.</span>
|
||||
<span style="color: green">// 2. Open the SOLIDWORKS PDM Professional Administration tool.</span>
|
||||
<span style="color: green">// 3. Log into the vault where to add a new serial number.</span>
|
||||
<span style="color: green">// a. Right-click <b>Serial Numbers</b> and </span><font size="1"><span style="color:green;">click </span></font><span style="color: green"><b>New Serial Number</b>.</span>
|
||||
<span style="color: green">// 1. Type <b>AddItems</b> in <b>Name</b>.</span>
|
||||
<span style="color: green">// 2. For <b>Format string</b>, click the right-arrow button and select <b>Counter value</b> > <b>00001</b>.</span>
|
||||
<span style="color: green">// 3. Click <b>OK</b>.</span>
|
||||
<span style="color: green">// b. Right-click <b>Items</b> and select <b>Open</b>.</span>
|
||||
<span style="color: green">// 1. Click <b>AddItems</b> in <b>Item Serial Number</b>.</span>
|
||||
<span style="color: green">// 2. Click <b>OK</b>.</span>
|
||||
<span style="color: green">// 4. Start Microsoft Visual Studio.</span>
|
||||
<span style="color: green">// a. Click <b>File > New > Project > C# > Windows Forms Application</b>.</span>
|
||||
<span style="color: green">// b. Type <b>AddItems</b> in <b>Name</b>.</span>
|
||||
<span style="color: green">// c. Click the <b>Browse</b> button and browse to the folder where to create the project.</span>
|
||||
<span style="color: green">// d. Click <b>OK</b>.
|
||||
// e. Click <b>Show All Files </b>in the Solution Explorer toolbar.</span>
|
||||
<span style="color: green">// f. Create a form similar to the form shown above and change:</span>
|
||||
<span style="color: green">// 1. Top label to <b>VaultsLabel</b>.</span>
|
||||
<span style="color: green">// 2. Combo box to <b>VaultsComboBox</b>.</span>
|
||||
<span style="color: green">// 3. Second label to <b>XmlLabel</b>.</span>
|
||||
<span style="color: green">// 4. Text box to <b>XmlTextBox</b>.</span>
|
||||
<span style="color: green">// 5. Browse button to <b>BrowseButton</b>.</span>
|
||||
<span style="color: green">// 6. Add items button to <b>AddItemsButton</b>.</span>
|
||||
<span style="color: green">// 7. List box to <b>ItemsListBox</b>.</span>
|
||||
<span style="color: green">// g. Replace the code in <b>Form1.cs</b> with <a href="#Form1">this code</a>.</span>
|
||||
<span style="color: green">// h. Replace the code in <b>Form1.Designer.cs</b> with <a href="#Designer">this code</a>.</span>
|
||||
<span style="color: green">// i. Right-click the <b>AddItemsCSharp</b> project name in the Solution Explorer.</span>
|
||||
<span style="color: green">// 1. Click <b>Add > Class > Class</b>.</span>
|
||||
<span style="color: green">// 2. Type <b>EdmVaultSingleton.cs </b>in<b> Name.</b></span>
|
||||
<span style="color: green">// 3. Click <b>Add</b>.</span>
|
||||
<span style="color: green">// 4. Replace the code in <b>EdmVaultSingleton.cs</b> with <a href="#EdmVaultSingleton">this code</a>.</span>
|
||||
<span style="color: green">// j. Right-click the <b>AddItems</b> project name in the Solution Explorer.</span>
|
||||
<span style="color: green">// 1. Click <b>Add > Class > Class</b>.</span>
|
||||
<span style="color: green">// 2. Type <b>NewItem.cs</b> in <b>Name</b>.</span>
|
||||
<span style="color: green">// 3. Click <b>Add</b>.</span>
|
||||
<span style="color: green">// 4. Replace the code in <b>NewItem.cs</b> with <a href="#NewItem">this code</a>.</span>
|
||||
<span style="color: green">// 5. Add <b>EPDM.Interop.epdm.dll</b> as a reference (right-click the project</span>
|
||||
<span style="color: green">// name in the Solution Explorer, </span><font size="1"><span style="color:green;">click </span></font><span style="color: green"><b>Add Reference</b>, </span><font size="1"><span style="color:green;">click </span></font>
|
||||
<span style="color: green">// <b>Assemblies > Framework</b> in the left-side panel, browse to the top folder of your </span>
|
||||
<span style="color: green">// SOLIDWORKS PDM Professional installation, locate and </span><font size="1"><span style="color:green;">click </span></font>
|
||||
<span style="color: green">// <b>EPDM.Interop.epdm.dll</b>, click <b>Open</b>, click <b>Add</b>, and click <b>Close</b>).</span>
|
||||
<span style="color: green">// 6. Right-click <b>EPDM.Interop.epdm</b> in References, </span><font size="1"><span style="color:green;">click </span></font><span style="color: green"><b>Properties</b>, and set </span>
|
||||
<span style="color: green">// <b>Embed Interop Types</b> to <b>False</b> to handle methods that pass arrays of </span>
|
||||
<span style="color: green">// structures.</span>
|
||||
<span style="color: green">// 7. Click <b>Debug > Start Debugging</b> or press F5.</span>
|
||||
<span style="color: green">//</span>
|
||||
<span style="color: green">// Postconditions: </span>
|
||||
<span style="color: green">// 1. Displays a dialog.</span>
|
||||
<span style="color: green">// 2. Select a vault.</span>
|
||||
<span style="color: green">// 3. Click the <b>Browse</b> button, locate and select <b>Items.xml</b>,<b> </b>and click <b>Open</b>.</span>
|
||||
<span style="color: green">// 4. Click the <b>Add items</b> button.</span>
|
||||
<span style="color: green">// The new items are printed in the dialog's list.</span>
|
||||
<span style="color: green">// 5. Close the dialog.</span>
|
||||
<span style="color: green">// 6. Open the SOLIDWORKS PDM Professional Item Explorer tool. </span>
|
||||
<span style="color: green">// (In Windows 7, click <b>Start > All Programs > SOLIDWORKS PDM Professional >
|
||||
// Item Explorer</b>.)</span>
|
||||
<span style="color: green">// 7. Expand the vault where the new items were added. </span>
|
||||
<span style="color: green">// The new items are listed below the name of the expanded vault. </span>
|
||||
<span style="color: green">//----------------------------------------------------------------------------</span></pre>
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><font size="1"><a name="XML"></a></font><?xml version="1.0" encoding="utf-8"?>
|
||||
<ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<anyType xsi:type="Item">
|
||||
<Description>First Item</Description>
|
||||
<ProjectName>Project 1</ProjectName>
|
||||
<ProjectNumber>1</ProjectNumber>
|
||||
<PartType>Purchased</PartType>
|
||||
<ItemName>Item 1</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Second Item</Description>
|
||||
<ProjectName>Project 2</ProjectName>
|
||||
<ProjectNumber>2</ProjectNumber>
|
||||
<PartType>Built</PartType>
|
||||
<ItemName>Item 2</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Third Item</Description>
|
||||
<ProjectName>Project 3</ProjectName>
|
||||
<ProjectNumber>3</ProjectNumber>
|
||||
<PartType>Purchased</PartType>
|
||||
<ItemName>Item 3</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Fourth Item</Description>
|
||||
<ProjectName>Project 4</ProjectName>
|
||||
<ProjectNumber>4</ProjectNumber>
|
||||
<PartType>Built</PartType>
|
||||
<ItemName>Item 4</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Fifth Item</Description>
|
||||
<ProjectName>Project 5</ProjectName>
|
||||
<ProjectNumber>5</ProjectNumber>
|
||||
<PartType>Purchased</PartType>
|
||||
<ItemName>Item 5</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Sixth Item</Description>
|
||||
<ProjectName>Project 6</ProjectName>
|
||||
<ProjectNumber>6</ProjectNumber>
|
||||
<PartType>Built</PartType>
|
||||
<ItemName>Item 6</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Seventh Item</Description>
|
||||
<ProjectName>Project 7</ProjectName>
|
||||
<ProjectNumber>7</ProjectNumber>
|
||||
<PartType>Purchased</PartType>
|
||||
<ItemName>Item 7</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Eighth Item</Description>
|
||||
<ProjectName>Project 8</ProjectName>
|
||||
<ProjectNumber>8</ProjectNumber>
|
||||
<PartType>Built</PartType>
|
||||
<ItemName>Item 8</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Ninth Item</Description>
|
||||
<ProjectName>Project 9</ProjectName>
|
||||
<ProjectNumber>9</ProjectNumber>
|
||||
<PartType>Purchased</PartType>
|
||||
<ItemName>Item 9</ItemName>
|
||||
</anyType>
|
||||
<anyType xsi:type="Item">
|
||||
<Description>Tenth Item</Description>
|
||||
<ProjectName>Project 10</ProjectName>
|
||||
<ProjectNumber>10</ProjectNumber>
|
||||
<PartType>Built</PartType>
|
||||
<ItemName>Item 10</ItemName>
|
||||
</anyType>
|
||||
</ArrayOfAnyType></pre>
|
||||
<div align="center">
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><a href="#Top">Back to top</a></pre>
|
||||
</div>
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: green"><a name="Form1"></a>//Form1.cs </span>
|
||||
<span style="color: blue">using</span> System;
|
||||
<span style="color: blue">using</span> System.IO;
|
||||
<span style="color: blue">using</span> EPDM.Interop.epdm;
|
||||
<span style="color: blue">using</span> System.Collections;
|
||||
<span style="color: blue">using</span> System.Diagnostics;
|
||||
<span style="color: blue">using</span> System.Runtime.InteropServices;
|
||||
<span style="color: blue">using</span> System.Windows.Forms;
|
||||
|
||||
<span style="color: blue">namespace</span> AddItemsCSharp
|
||||
{
|
||||
<span style="color: blue">public</span> <span style="color: blue">partial</span> <span style="color: blue">class</span> <span style="color: #2b91af">Form1</span> : <span style="color: #2b91af">Form</span>
|
||||
{
|
||||
<span style="color: blue">public</span> Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
<span style="color: blue">void</span> BrowseButton_Click(System.<span style="color: #2b91af">Object</span> sender, System.<span style="color: #2b91af">EventArgs</span> e)
|
||||
{
|
||||
<span style="color: blue">try</span>
|
||||
{
|
||||
<span style="color: #2b91af">DialogResult</span> dlgResult = XmlOpenFileDialog.ShowDialog();
|
||||
<span style="color: blue">if</span> (dlgResult == <span style="color: #2b91af">DialogResult</span>.Cancel)
|
||||
{
|
||||
<span style="color: blue">return</span>;
|
||||
}
|
||||
XmlTextBox.Text = XmlOpenFileDialog.FileName;
|
||||
}
|
||||
<span style="color: blue">catch</span> (System.Runtime.InteropServices.<span style="color: #2b91af">COMException</span> ex)
|
||||
{
|
||||
<span style="color: #2b91af">MessageBox</span>.Show(<span style="color: #a31515">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color: #a31515">"X"</span>) + <span style="color: #a31515">" "</span> + ex.Message);
|
||||
}
|
||||
<span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)
|
||||
{
|
||||
<span style="color: #2b91af">MessageBox</span>.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">void</span> AddItemsButton_Click(System.<span style="color: #2b91af">Object</span> sender, System.<span style="color: #2b91af">EventArgs</span> e)
|
||||
{
|
||||
|
||||
<span style="color: blue">try</span>
|
||||
{
|
||||
ItemsListBox.Items.Clear();
|
||||
<span style="color: #2b91af">ArrayList</span> NewItems = <span style="color: blue">new</span> <span style="color: #2b91af">ArrayList</span>();
|
||||
|
||||
<span style="color: blue">using</span> (System.Xml.<span style="color: #2b91af">XmlReader</span> XmlReader = System.Xml.<span style="color: #2b91af">XmlReader</span>.Create(XmlTextBox.Text))
|
||||
{
|
||||
|
||||
XmlReader.Read();
|
||||
XmlReader.ReadToNextSibling(<span style="color: #a31515">"ArrayOfAnyType"</span>);
|
||||
XmlReader.ReadToDescendant(<span style="color: #a31515">"anyType"</span>);
|
||||
<span style="color: blue">do</span>
|
||||
{
|
||||
<span style="color: #2b91af">NewItem</span> CurItem = <span style="color: blue">new</span> <span style="color: #2b91af">NewItem</span>();
|
||||
XmlReader.ReadToDescendant(<span style="color: #a31515">"Description"</span>);
|
||||
CurItem.Description = XmlReader.ReadString();
|
||||
XmlReader.ReadToNextSibling(<span style="color: #a31515">"ProjectName"</span>);
|
||||
CurItem.ProjectName = XmlReader.ReadString();
|
||||
XmlReader.ReadToNextSibling(<span style="color: #a31515">"ProjectNumber"</span>);
|
||||
CurItem.ProjectNumber = XmlReader.ReadString();
|
||||
XmlReader.ReadToNextSibling(<span style="color: #a31515">"PartType"</span>);
|
||||
CurItem.PartType = XmlReader.ReadString();
|
||||
XmlReader.ReadToNextSibling(<span style="color: #a31515">"ItemName"</span>);
|
||||
CurItem.ItemName = XmlReader.ReadString();
|
||||
NewItems.Add(CurItem);
|
||||
} <span style="color: blue">while</span> (XmlReader.ReadToFollowing(<span style="color: #a31515">"anyType"</span>));
|
||||
}
|
||||
|
||||
<span style="color: green">//Obtain the only instance of the IEdmVault5 object</span>
|
||||
<span style="color: #2b91af">IEdmVault5</span> vault = <span style="color: #2b91af">EdmVaultSingleton</span>.Instance;
|
||||
|
||||
<span style="color: blue">if</span> (!vault.<b>IsLoggedIn</b>)
|
||||
{
|
||||
<span style="color: green">//Log into selected vault as the current user</span>
|
||||
vault.<b>LoginAuto</b>(VaultsComboBox.Text, <span style="color: blue">this</span>.Handle.ToInt32());
|
||||
}
|
||||
|
||||
<span style="color: green">//Create the batch interface</span>
|
||||
<span style="color: #2b91af">IEdmBatchItemGeneration2</span> BatchItemGen = <span style="color: blue">default</span>(<span style="color: #2b91af">IEdmBatchItemGeneration2</span>);
|
||||
|
||||
<span style="color: #2b91af">IEdmVault7</span> vault1 = (<span style="color: #2b91af">IEdmVault7</span>)vault;
|
||||
BatchItemGen = (<span style="color: #2b91af">IEdmBatchItemGeneration2</span>)vault1.<b>CreateUtility</b>(<span style="color: #2b91af">EdmUtility</span>.EdmUtil_BatchItemGeneration);
|
||||
<span style="color: #2b91af">EdmVarVal</span>[] VarVals = <span style="color: blue">new</span> <span style="color: #2b91af">EdmVarVal</span>[4];
|
||||
VarVals[0].<b>mlEdmVarValFlags</b> = 0;
|
||||
VarVals[0].<b>moVarIDorName</b> = <span style="color: #a31515">"Description"</span>;
|
||||
VarVals[1].<b>mlEdmVarValFlags</b> = 0;
|
||||
VarVals[1].<b>moVarIDorName</b> = <span style="color: #a31515">"Project Name"</span>;
|
||||
VarVals[2].<b>mlEdmVarValFlags</b> = 0;
|
||||
VarVals[2].<b>moVarIDorName</b> = <span style="color: #a31515">"Project number"</span>;
|
||||
VarVals[3].<b>mlEdmVarValFlags</b> = 0;
|
||||
VarVals[3].<b>moVarIDorName</b> = <span style="color: #a31515">"Part Type"</span>;
|
||||
<span style="color: blue">for</span> (<span style="color: blue">int</span> i = 0; i <= NewItems.Count - 1; i++)
|
||||
{
|
||||
VarVals[0].<b>moValue</b> = (NewItems[i] <span style="color: blue">as</span> <span style="color: #2b91af">NewItem</span>).Description;
|
||||
VarVals[1].<b>moValue</b> = (NewItems[i] <span style="color: blue">as</span> <span style="color: #2b91af">NewItem</span>).ProjectName;
|
||||
VarVals[2].<b>moValue</b> = (NewItems[i] <span style="color: blue">as</span> <span style="color: #2b91af">NewItem</span>).ProjectNumber;
|
||||
VarVals[3].<b>moValue</b> = (NewItems[i] <span style="color: blue">as</span> <span style="color: #2b91af">NewItem</span>).PartType;
|
||||
BatchItemGen.<b>AddSelection2</b>((<span style="color: #2b91af">EdmVault5</span>)vault, VarVals, ((NewItems[i] <span style="color: blue">as</span> <span style="color: #2b91af">NewItem</span>).ItemName),0, 0, 0,<span style="color: #a31515">""</span>, (<span style="color: blue">int</span>)<span style="color: #2b91af">EdmRefFlags</span>.EdmRef_Dynamic);
|
||||
|
||||
}
|
||||
|
||||
<span style="color: green">//Build the item tree</span>
|
||||
<span style="color: blue">bool</span> CreateSuccess = <span style="color: blue">false</span>;
|
||||
CreateSuccess = BatchItemGen.<b>CreateTree</b>(((<span style="color: blue">int</span>)(<span style="color: blue">this</span>.Handle.ToInt32())), (<span style="color: blue">int</span>)<span style="color: #2b91af">EdmItemGenerationFlags</span>.Eigcf_Nothing);
|
||||
<span style="color: blue">if</span> ((CreateSuccess == <span style="color: blue">false</span>))
|
||||
<span style="color: blue">return</span>;
|
||||
|
||||
|
||||
<span style="color: green">//Generate the items</span>
|
||||
<span style="color: #2b91af">EdmGenItemInfo</span>[] ReturnedItems = <span style="color: blue">null</span>;
|
||||
<span style="color: blue">bool</span> bOpenExplorer = <span style="color: blue">false</span>;
|
||||
BatchItemGen.<b>GenerateItems</b>(<span style="color: blue">this</span>.Handle.ToInt32(), <span style="color: blue">out</span> ReturnedItems, <span style="color: blue">out</span> bOpenExplorer, <span style="color: blue">null</span>);
|
||||
|
||||
<span style="color: green">//Display the new item information in the list box</span>
|
||||
<span style="color: blue">string</span> msg = <span style="color: #a31515">""</span>;
|
||||
<span style="color: blue">if</span> (ReturnedItems.Length == 0)
|
||||
{
|
||||
msg = <span style="color: #a31515">"No items were added."</span>;
|
||||
ItemsListBox.Items.Add(<span style="color: #a31515">"No items were added."</span>);
|
||||
}
|
||||
<span style="color: blue">else</span>
|
||||
{
|
||||
<span style="color: blue">foreach</span> (<span style="color: #2b91af">EdmGenItemInfo</span> ItemInfo <span style="color: blue">in</span> ReturnedItems)
|
||||
{
|
||||
|
||||
ItemsListBox.Items.Add(<span style="color: #a31515">"Item name: "</span> + ItemInfo.<b>mbsItemName</b>);
|
||||
ItemsListBox.Items.Add(<span style="color: #a31515">"Alternate name: "</span> + ItemInfo.<b>mbsItemAlternativeName</b>);
|
||||
|
||||
<span style="color: #2b91af">IEdmVault11</span> vault2 = (<span style="color: #2b91af">IEdmVault11</span>)vault;
|
||||
ItemsListBox.Items.Add(<span style="color: #a31515">"Status: "</span> + vault2.<b>GetErrorMessage</b>(ItemInfo.mhResult));
|
||||
ItemsListBox.Items.Add(<span style="color: #a31515">""</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
<span style="color: blue">catch</span> (System.Runtime.InteropServices.<span style="color: #2b91af">COMException</span> ex)
|
||||
{
|
||||
<span style="color: #2b91af">MessageBox</span>.Show(<span style="color: #a31515">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color: #a31515">"X"</span>) + <span style="color: #a31515">" "</span> + ex.Message);
|
||||
}
|
||||
<span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)
|
||||
{
|
||||
<span style="color: #2b91af">MessageBox</span>.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">void</span> AddItems_Load(System.<span style="color: #2b91af">Object</span> sender, System.<span style="color: #2b91af">EventArgs</span> e)
|
||||
{
|
||||
<span style="color: blue">try</span>
|
||||
{
|
||||
<span style="color: green">//Obtain the only instance of the IEdmVault object</span>
|
||||
<span style="color: #2b91af">IEdmVault8</span> vault = (<span style="color: #2b91af">IEdmVault8</span>)<span style="color: #2b91af">EdmVaultSingleton</span>.Instance;
|
||||
<span style="color: #2b91af">EdmViewInfo</span>[] Views = <span style="color: blue">null</span>;
|
||||
|
||||
vault.<b>GetVaultViews</b>(<span style="color: blue">out</span> Views, <span style="color: blue">false</span>);
|
||||
VaultsComboBox.Items.Clear();
|
||||
<span style="color: blue">foreach</span> (<span style="color: #2b91af">EdmViewInfo</span> View <span style="color: blue">in</span> Views)
|
||||
{
|
||||
VaultsComboBox.Items.Add(View.<b>mbsVaultName</b>);
|
||||
}
|
||||
<span style="color: blue">if</span> (VaultsComboBox.Items.Count > 0)
|
||||
{
|
||||
VaultsComboBox.Text = (<span style="color: blue">string</span>)VaultsComboBox.Items[0];
|
||||
}
|
||||
}
|
||||
<span style="color: blue">catch</span> (System.Runtime.InteropServices.<span style="color: #2b91af">COMException</span> ex)
|
||||
{
|
||||
<span style="color: #2b91af">MessageBox</span>.Show(<span style="color: #a31515">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color: #a31515">"X"</span>) + <span style="color: #a31515">" "</span> + ex.Message);
|
||||
}
|
||||
<span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)
|
||||
{
|
||||
<span style="color: #2b91af">MessageBox</span>.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}</pre>
|
||||
<div align="center">
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><a href="#Top">Back to top</a></pre>
|
||||
</div>
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: green"><a name="Designer"></a>//Form1.Designer.cs</span>
|
||||
<span style="color: blue">namespace</span> AddItemsCSharp
|
||||
{
|
||||
<span style="color: blue">partial</span> <span style="color: blue">class</span> <span style="color: #2b91af">Form1</span>
|
||||
{
|
||||
<span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span>
|
||||
<span style="color: gray">///</span><span style="color: green"> Required designer variable.</span>
|
||||
<span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span>
|
||||
<span style="color: blue">private</span> System.ComponentModel.<span style="color: #2b91af">IContainer</span> components = <span style="color: blue">null</span>;
|
||||
|
||||
<span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span>
|
||||
<span style="color: gray">///</span><span style="color: green"> Clean up any resources being used.</span>
|
||||
<span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span>
|
||||
<span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><param name="disposing"></span><span style="color: green">true if managed resources should be disposed; otherwise, false.</span><span style="color: gray"></param></span>
|
||||
<span style="color: blue">protected</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Dispose(<span style="color: blue">bool</span> disposing)
|
||||
{
|
||||
<span style="color: blue">if</span> (disposing && (components != <span style="color: blue">null</span>))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
<span style="color: blue">base</span>.Dispose(disposing);
|
||||
}
|
||||
|
||||
<span style="color: blue"> #region</span> Windows Form Designer generated code
|
||||
|
||||
<span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span>
|
||||
<span style="color: gray">///</span><span style="color: green"> Required method for Designer support - do not modify</span>
|
||||
<span style="color: gray">///</span><span style="color: green"> the contents of this method with the code editor.</span>
|
||||
<span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span>
|
||||
<span style="color: blue">private</span> <span style="color: blue">void</span> InitializeComponent()
|
||||
{
|
||||
<span style="color: blue">this</span>.VaultsLabel = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">Label</span>();
|
||||
<span style="color: blue">this</span>.VaultsComboBox = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">ComboBox</span>();
|
||||
<span style="color: blue">this</span>.XmlLabel = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">Label</span>();
|
||||
<span style="color: blue">this</span>.XmlTextBox = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">TextBox</span>();
|
||||
<span style="color: blue">this</span>.BrowseButton = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">Button</span>();
|
||||
<span style="color: blue">this</span>.AddItemsButton = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">Button</span>();
|
||||
<span style="color: blue">this</span>.ItemsListBox = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">ListBox</span>();
|
||||
<span style="color: blue">this</span>.XmlOpenFileDialog = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">OpenFileDialog</span>();
|
||||
<span style="color: blue">this</span>.SuspendLayout();
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">//XmlOpenFileDialog</span>
|
||||
<span style="color: green">//</span>
|
||||
<span style="color: blue">this</span>.XmlOpenFileDialog.Filter = <span style="color: #a31515">"XML files|*.XML"</span>;
|
||||
<span style="color: green">//</span>
|
||||
|
||||
<span style="color: green">// VaultsLabel</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.VaultsLabel.AutoSize = <span style="color: blue">true</span>;
|
||||
<span style="color: blue">this</span>.VaultsLabel.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(22, 22);
|
||||
<span style="color: blue">this</span>.VaultsLabel.Name = <span style="color: #a31515">"VaultsLabel"</span>;
|
||||
<span style="color: blue">this</span>.VaultsLabel.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(91, 13);
|
||||
<span style="color: blue">this</span>.VaultsLabel.TabIndex = 0;
|
||||
<span style="color: blue">this</span>.VaultsLabel.Text = <span style="color: #a31515">"Select vault view:"</span>;
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// VaultsComboBox</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.VaultsComboBox.FormattingEnabled = <span style="color: blue">true</span>;
|
||||
<span style="color: blue">this</span>.VaultsComboBox.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(25, 38);
|
||||
<span style="color: blue">this</span>.VaultsComboBox.Name = <span style="color: #a31515">"VaultsComboBox"</span>;
|
||||
<span style="color: blue">this</span>.VaultsComboBox.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(174, 21);
|
||||
<span style="color: blue">this</span>.VaultsComboBox.TabIndex = 1;
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// XmlLabel</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.XmlLabel.AutoSize = <span style="color: blue">true</span>;
|
||||
<span style="color: blue">this</span>.XmlLabel.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(25, 91);
|
||||
<span style="color: blue">this</span>.XmlLabel.Name = <span style="color: #a31515">"XmlLabel"</span>;
|
||||
<span style="color: blue">this</span>.XmlLabel.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(172, 13);
|
||||
<span style="color: blue">this</span>.XmlLabel.TabIndex = 2;
|
||||
<span style="color: blue">this</span>.XmlLabel.Text = <span style="color: #a31515">"XML file from which to import items:"</span>;
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// XmlTextBox</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.XmlTextBox.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(28, 107);
|
||||
<span style="color: blue">this</span>.XmlTextBox.Name = <span style="color: #a31515">"XmlTextBox"</span>;
|
||||
<span style="color: blue">this</span>.XmlTextBox.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(171, 20);
|
||||
<span style="color: blue">this</span>.XmlTextBox.TabIndex = 3;
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// BrowseButton</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.BrowseButton.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(216, 107);
|
||||
<span style="color: blue">this</span>.BrowseButton.Name = <span style="color: #a31515">"BrowseButton"</span>;
|
||||
<span style="color: blue">this</span>.BrowseButton.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(75, 23);
|
||||
<span style="color: blue">this</span>.BrowseButton.TabIndex = 4;
|
||||
<span style="color: blue">this</span>.BrowseButton.Text = <span style="color: #a31515">"Browse..."</span>;
|
||||
<span style="color: blue">this</span>.BrowseButton.UseVisualStyleBackColor = <span style="color: blue">true</span>;
|
||||
<span style="color: blue">this</span>.BrowseButton.Click += <span style="color: blue">new</span> System.<span style="color: #2b91af">EventHandler</span>(<span style="color: blue">this</span>.BrowseButton_Click);
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// AddItemsButton</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.AddItemsButton.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(28, 149);
|
||||
<span style="color: blue">this</span>.AddItemsButton.Name = <span style="color: #a31515">"AddItemsButton"</span>;
|
||||
<span style="color: blue">this</span>.AddItemsButton.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(75, 23);
|
||||
<span style="color: blue">this</span>.AddItemsButton.TabIndex = 5;
|
||||
<span style="color: blue">this</span>.AddItemsButton.Text = <span style="color: #a31515">"Add items"</span>;
|
||||
<span style="color: blue">this</span>.AddItemsButton.UseVisualStyleBackColor = <span style="color: blue">true</span>;
|
||||
<span style="color: blue">this</span>.AddItemsButton.Click += <span style="color: blue">new</span> System.<span style="color: #2b91af">EventHandler</span>(<span style="color: blue">this</span>.AddItemsButton_Click);
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// ItemListBox</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.ItemsListBox.FormattingEnabled = <span style="color: blue">true</span>;
|
||||
<span style="color: blue">this</span>.ItemsListBox.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(28, 196);
|
||||
<span style="color: blue">this</span>.ItemsListBox.Name = <span style="color: #a31515">"ItemsListBox"</span>;
|
||||
<span style="color: blue">this</span>.ItemsListBox.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(263, 95);
|
||||
<span style="color: blue">this</span>.ItemsListBox.TabIndex = 6;
|
||||
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// Form1</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.AutoScaleDimensions = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">SizeF</span>(6F, 13F);
|
||||
<span style="color: blue">this</span>.AutoScaleMode = System.Windows.Forms.<span style="color: #2b91af">AutoScaleMode</span>.Font;
|
||||
<span style="color: blue">this</span>.ClientSize = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(334, 311);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.ItemsListBox);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.AddItemsButton);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.BrowseButton);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.XmlTextBox);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.XmlLabel);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.VaultsComboBox);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.VaultsLabel);
|
||||
<span style="color: blue">this</span>.Name = <span style="color: #a31515">"Form1"</span>;
|
||||
<span style="color: blue">this</span>.Text = <span style="color: #a31515">"Add new items"</span>;
|
||||
<span style="color: blue">this</span>.Load += <span style="color: blue">new</span> System.<span style="color: #2b91af">EventHandler</span>(<span style="color: blue">this</span>.AddItems_Load);
|
||||
<span style="color: blue">this</span>.ResumeLayout(<span style="color: blue">false</span>);
|
||||
<span style="color: blue">this</span>.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
<span style="color: blue"> #endregion</span>
|
||||
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">Label</span> VaultsLabel;
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">ComboBox</span> VaultsComboBox;
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">Label</span> XmlLabel;
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">TextBox</span> XmlTextBox;
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">Button</span> BrowseButton;
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">Button</span> AddItemsButton;
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">ListBox</span> ItemsListBox;
|
||||
<span style="color: blue">private</span> System.Windows.Forms.<span style="color: #2b91af">OpenFileDialog</span> XmlOpenFileDialog;
|
||||
}
|
||||
}</pre>
|
||||
<div align="center">
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white">
|
||||
<a href="#Top">Back to top</a></pre>
|
||||
</div>
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: green"><a name="EdmVaultSingleton"></a>//EdmVaultSingleton.cs</span>
|
||||
<span style="color: blue">using</span> System;
|
||||
<span style="color: blue">using</span> System.Collections;
|
||||
<span style="color: blue">using</span> System.Diagnostics;
|
||||
<span style="color: blue">using</span> System.Threading;
|
||||
<span style="color: blue">using</span> EPDM.Interop.epdm;
|
||||
|
||||
<span style="color: blue">namespace</span> AddItemsCSharp
|
||||
{
|
||||
<span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">EdmVaultSingleton</span>
|
||||
{
|
||||
<span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: #2b91af">EdmVault5</span> mInstance = <span style="color: blue">null</span>;
|
||||
<span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">object</span> mLockObj = <span style="color: blue">new</span> <span style="color: blue">object</span>();
|
||||
|
||||
<span style="color: blue">private</span> EdmVaultSingleton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">EdmVault5</span> Instance
|
||||
{
|
||||
<span style="color: blue">get</span>
|
||||
{
|
||||
<span style="color: blue">try</span>
|
||||
{
|
||||
<span style="color: blue">if</span> (mInstance == <span style="color: blue">null</span>)
|
||||
{
|
||||
<span style="color: #2b91af">Monitor</span>.Enter(mLockObj);
|
||||
<span style="color: blue">if</span> (mInstance == <span style="color: blue">null</span>)
|
||||
{
|
||||
mInstance = <span style="color: blue">new</span> <span style="color: #2b91af">EdmVault5</span>();
|
||||
}
|
||||
<span style="color: #2b91af">Monitor</span>.Exit(mLockObj);
|
||||
}
|
||||
}
|
||||
<span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)
|
||||
{
|
||||
<span style="color: #2b91af">Monitor</span>.Exit(mLockObj);
|
||||
}
|
||||
|
||||
<span style="color: blue">return</span> mInstance;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}</pre>
|
||||
<div align="center">
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><a href="#Top">Back to top</a>
|
||||
</pre>
|
||||
</div>
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: green"><a name="NewItem"></a>//NewItem.cs</span>
|
||||
<span style="color: blue">using</span> System;
|
||||
<span style="color: blue">using</span> System.Collections;
|
||||
<span style="color: blue">using</span> System.Diagnostics;
|
||||
|
||||
<span style="color: blue">namespace</span> AddItemsCSharp
|
||||
{
|
||||
<span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">NewItem</span>
|
||||
{
|
||||
<span style="color: green">//Value of "Description" variable</span>
|
||||
<span style="color: blue">private</span> <span style="color: blue">string</span> mDescription;
|
||||
<span style="color: green">//Value of "Project Name" variable</span>
|
||||
<span style="color: blue">private</span> <span style="color: blue">string</span> mProjectName;
|
||||
<span style="color: green">//Value of "Project number" variable</span>
|
||||
<span style="color: blue">private</span> <span style="color: blue">string</span> mProjectNumber;
|
||||
<span style="color: green">//Value of "Part Type" variable</span>
|
||||
<span style="color: blue">private</span> <span style="color: blue">string</span> mPartType;
|
||||
<span style="color: green">//Item name</span>
|
||||
<span style="color: blue">private</span> <span style="color: blue">string</span> mItemName;
|
||||
|
||||
<span style="color: blue">public</span> NewItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">string</span> Description
|
||||
{
|
||||
<span style="color: blue">get</span> { <span style="color: blue">return</span> mDescription; }
|
||||
<span style="color: blue">set</span> { mDescription = <span style="color: blue">value</span>; }
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">string</span> ProjectName
|
||||
{
|
||||
<span style="color: blue">get</span> { <span style="color: blue">return</span> mProjectName; }
|
||||
<span style="color: blue">set</span> { mProjectName = <span style="color: blue">value</span>; }
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">string</span> ProjectNumber
|
||||
{
|
||||
<span style="color: blue">get</span> { <span style="color: blue">return</span> mProjectNumber; }
|
||||
<span style="color: blue">set</span> { mProjectNumber = <span style="color: blue">value</span>; }
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">string</span> PartType
|
||||
{
|
||||
<span style="color: blue">get</span> { <span style="color: blue">return</span> mPartType; }
|
||||
<span style="color: blue">set</span> { mPartType = <span style="color: blue">value</span>; }
|
||||
}
|
||||
|
||||
<span style="color: blue">public</span> <span style="color: blue">string</span> ItemName
|
||||
{
|
||||
<span style="color: blue">get</span> { <span style="color: blue">return</span> mItemName; }
|
||||
<span style="color: blue">set</span> { mItemName = <span style="color: blue">value</span>; }
|
||||
}
|
||||
|
||||
}
|
||||
}</pre>
|
||||
<div align="center">
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><a href="#Top">Back to top</a>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user