535 lines
53 KiB
HTML
535 lines
53 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<title>Add Users 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,users">
|
|
<meta name=MS-HKWD content="C# examples,XmlSerializer class ">
|
|
<meta name=MS-HKWD content="C# examples,StreamReader class">
|
|
<meta name=MS-HKWD content="C# examples,permissions">
|
|
|
|
<body>
|
|
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
|
<h1>Add Users Example (C#)</h1>
|
|
<p><a name="top"></a>This example shows how to add users to a vault by
|
|
deserializing an XML file containing user data.</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="AddUsers.gif" width="320" height="275"></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>User.xml</b> and remember where you save the file.</span>
|
|
<span style="color:green;">// 2. 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>AddUsersCSharp</b> in Name.</span>
|
|
<span style="color:green;">// c. Click <b>Browse</b> and navigate to the folder where to
|
|
// create the project.</span>
|
|
<span style="color:green;">// d. Click <b>OK</b>. </span>
|
|
<span style="color:green;">// e. Click <b>Show All Files</b> in the Solution Explorer toolbar and
|
|
// expand <b>Form1.cs </b>in the Solution Explorer.</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. <b>Browse</b> button to <b>BrowseButton</b>.</span>
|
|
<span style="color:green;">// 6. <b>Add users</b> button to <b>AddUsersButton</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>AddUsersCSharp</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>AddUsersCSharp</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>User.cs</b> in Name.</span>
|
|
<span style="color:green;">// 3. Click <b>Add</b>.</span>
|
|
<span style="color:green;">// 4. Replace the code in <b>User.cs</b> with <a href="#User">this code</a>.</span>
|
|
<span style="color:green;">// 3. 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;">// 4. Right-click <b>EPDM.Interop.epdm</b> in <b>References</b>, </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;">// 5. 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 <b>Browse</b>, locate and select<b> User.xml</b>, and click <b>Open</b>.</span>
|
|
<span style="color:green;">// 4. Click <b>Add users</b>.</span>
|
|
<span style="color:green;">// A message box is displayed showing the names of the new users added</span>
|
|
<span style="color:green;">// to the vault.</span>
|
|
<span style="color:green;">// 5. Click <b>OK</b> to close the message box.</span>
|
|
<span style="color:green;">// 6. Close the dialog.</span>
|
|
<span style="color:green;">// 7. Start and log into the SOLIDWORKS PDM Professional Administration </span>
|
|
<span style="color:green;">// </span><span style="color:green;">tool </span><span style="color:green;">as Admin.</span>
|
|
<span style="color:green;">// 8. Expand the vault where the new users were added. </span>
|
|
<span style="color:green;">// 9. Expand <b>Users</b> to see the names of the new users. </span>
|
|
<span style="color:green;">// 10. Double-click <b>jdoe</b>.</span>
|
|
<span style="color:green;">// a. Examine the properties.</span>
|
|
<span style="color:green;">// b. Click <b>Administrative Permission</b>s and examine the permissions.</span>
|
|
<span style="color:green;">// c. Click <b>OK</b>.</span>
|
|
<span style="color:green;">// 11. Double-click <b>jsmith</b> and repeat steps 10a - 10c.</span>
|
|
<span style="color:green;">//----------------------------------------------------------------------------</span>
|
|
<a name="xml"></a><font size="2">
|
|
</font></pre>
|
|
<pre><?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="User">
|
|
<sn>Doe</sn>
|
|
<givenName>John</givenName>
|
|
<title>Designer</title>
|
|
<cn>John Doe</cn>
|
|
<username>jdoe@yourcompany.com</username>
|
|
</anyType>
|
|
<anyType xsi:type="User">
|
|
<sn>Smith</sn>
|
|
<givenName>Jane</givenName>
|
|
<title>Manager</title>
|
|
<cn>Jane Smith</cn>
|
|
<username>jsmith@yourcompany.com</username>
|
|
</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.Collections;
|
|
<span style="color:blue;">using</span> System.Data;
|
|
<span style="color:blue;">using</span> System.Diagnostics;
|
|
<span style="color:blue;">using</span> System.IO;
|
|
<span style="color:blue;">using</span> System.Xml.Serialization;
|
|
<span style="color:blue;">using</span> System.Windows.Forms;
|
|
<span style="color:blue;">using</span> EPDM.Interop.epdm;
|
|
<span style="color:blue;">using</span> System.Xml;
|
|
<span style="color:blue;">using</span> System.Runtime.InteropServices;
|
|
|
|
|
|
<span style="color:blue;">namespace</span> AddUsersCSharp
|
|
{
|
|
<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;">public</span> <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> AddUsersButton_Click(System.<span style="color:#2b91af;">Object</span> sender, System.<span style="color:#2b91af;">EventArgs</span> e)
|
|
{
|
|
<span style="color:#2b91af;">StreamReader</span> StrReader = <span style="color:blue;">null</span>;
|
|
|
|
<span style="color:blue;">try</span>
|
|
{
|
|
<span style="color:green;">//Deserialize users from an XML file</span>
|
|
<span style="color:#2b91af;">Type</span>[] ExtraTypes = { <span style="color:#2b91af;">Type</span>.GetType(<span style="color:#a31515;">"AddUsersCSharp.User"</span>) };
|
|
<span style="color:#2b91af;">XmlSerializer</span> XmlSer = <span style="color:blue;">new</span> <span style="color:#2b91af;">XmlSerializer</span>(<span style="color:#2b91af;">Type</span>.GetType(<span style="color:#a31515;">"System.Collections.ArrayList"</span>), ExtraTypes);
|
|
StrReader = <span style="color:blue;">new</span> <span style="color:#2b91af;">StreamReader</span>(XmlTextBox.Text);
|
|
<span style="color:#2b91af;">ArrayList</span> NewUsers = (<span style="color:#2b91af;">ArrayList</span>)XmlSer.Deserialize(StrReader);
|
|
|
|
<span style="color:green;">//Obtain the only instance of the IEdmVaultObject</span>
|
|
<span style="color:#2b91af;">IEdmVault5</span> vault = <span style="color:#2b91af;">EdmVaultSingleton</span>.Instance;
|
|
|
|
<span style="color:blue;">if</span> (!vault.IsLoggedIn)
|
|
{
|
|
<span style="color:green;">//Log into selected vault as the current user</span>
|
|
vault.LoginAuto(VaultsComboBox.Text, <span style="color:blue;">this</span>.Handle.ToInt32());
|
|
}
|
|
|
|
<span style="color:green;">//Assign IEdmVault object to the IEdmUserMgr7 object</span>
|
|
<span style="color:#2b91af;">IEdmUserMgr7</span> UsrMgr = (<span style="color:#2b91af;">IEdmUserMgr7</span>)vault;
|
|
|
|
<span style="color:green;">//Declare EdmUserData array to hold new user data</span>
|
|
<span style="color:#2b91af;">EdmUserData2</span>[] UserData = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmUserData2</span>[NewUsers.Count];
|
|
|
|
<span style="color:green;">//Set the EdmUserData members for each new user</span>
|
|
<span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 0; i <= NewUsers.Count - 1; i++)
|
|
{
|
|
<span style="color:blue;">if</span> (NewUsers[i] != <span style="color:blue;">null</span>)
|
|
{
|
|
UserData[i].<b>mbsCompleteName</b> = (NewUsers[i] <span style="color:blue;">as</span> <span style="color:#2b91af;">User</span>).cn;
|
|
UserData[i].<b>mbsEmail</b> = (NewUsers[i] <span style="color:blue;">as</span> <span style="color:#2b91af;">User</span>).username;
|
|
UserData[i].<b>mbsInitials</b> = (NewUsers[i] <span style="color:blue;">as</span> <span style="color:#2b91af;">User</span>).givenName.Substring(0, 1) + (NewUsers[i] <span style="color:blue;">as</span> <span style="color:#2b91af;">User</span>).sn.Substring(0, 1);
|
|
UserData[i].<b>mbsUserName</b> = (NewUsers[i] <span style="color:blue;">as</span> <span style="color:#2b91af;">User</span>).username.Split(<span style="color:#a31515;">'@'</span>)[0];
|
|
<span style="color:green;">//Return user's IEdmUser6 interface in mpoUser</span>
|
|
UserData[i].<b>mlFlags</b> = (<span style="color:blue;">int</span>)<span style="color:#2b91af;">EdmUserDataFlags</span>.Edmudf_GetInterface;
|
|
<span style="color:green;">//Add this user even if others cannot be added</span>
|
|
UserData[i].<b>mlFlags</b> += (<span style="color:blue;">int</span>)<span style="color:#2b91af;">EdmUserDataFlags</span>.Edmudf_ForceAdd;
|
|
|
|
<span style="color:green;">//Set permissions </span>
|
|
<span style="color:#2b91af;">EdmSysPerm</span>[] perms = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmSysPerm</span>[3];
|
|
perms[0] = <span style="color:#2b91af;">EdmSysPerm</span>.EdmSysPerm_EditUserMgr;
|
|
perms[1] = <span style="color:#2b91af;">EdmSysPerm</span>.EdmSysPerm_EditReportQuery;
|
|
perms[2] = <span style="color:#2b91af;">EdmSysPerm</span>.EdmSysPerm_MandatoryVersionComments;
|
|
UserData[i].<b>moSysPerms</b> = perms;
|
|
}
|
|
}
|
|
|
|
<span style="color:green;">//Add the users to the vault</span>
|
|
UsrMgr.<b>AddUsers2</b>(<span style="color:blue;">ref</span> UserData);
|
|
|
|
<span style="color:blue;">string</span> msg = <span style="color:#a31515;">""</span>;
|
|
<span style="color:blue;">foreach</span> (<span style="color:#2b91af;">EdmUserData2</span> usr <span style="color:blue;">in</span> UserData)
|
|
{
|
|
<span style="color:blue;">if</span> (usr.mhStatus == 0)
|
|
|
|
{
|
|
msg += <span style="color:#a31515;">"Created user \""</span> + usr.<b>mpoUser</b>.<b>Name</b> + <span style="color:#a31515;">"\" successfully. ID = "</span> + usr.<b>mpoUser</b>.<b>ID</b>.ToString() + <span style="color:#a31515;">"\n"</span>;
|
|
|
|
}
|
|
<span style="color:blue;">else</span>
|
|
{
|
|
<span style="color:#2b91af;">IEdmVault11</span> vault2 = (<span style="color:#2b91af;">IEdmVault11</span>)vault;
|
|
msg += <span style="color:#a31515;">"Error creating user \""</span> + usr.<b>mbsUserName</b> + <span style="color:#a31515;">"\" - "</span> + vault2.<b>GetErrorMessage</b>(usr.mhStatus) + <span style="color:#a31515;">"\n"</span>;
|
|
}
|
|
}
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(msg);
|
|
|
|
|
|
}
|
|
<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;">finally</span>
|
|
{
|
|
<span style="color:blue;">if</span> ((StrReader != <span style="color:blue;">null</span>))
|
|
{
|
|
StrReader.Close();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
<span style="color:blue;">public</span> <span style="color:blue;">void</span> AddUsers_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>
|
|
<div align="left">
|
|
<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></pre>
|
|
</div>
|
|
<div align="left">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:blue;">namespace</span> AddUsersCSharp
|
|
{
|
|
<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>.AddUsersButton = <span style="color:blue;">new</span> System.Windows.Forms.<span style="color:#2b91af;">Button</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;">// </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>(23, 34);
|
|
<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>(26, 62);
|
|
<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>(171, 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>(26, 111);
|
|
<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>(173, 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 users:"</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>(26, 139);
|
|
<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>(203, 135);
|
|
<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>(BrowseButton_Click);
|
|
<span style="color:green;">// </span>
|
|
<span style="color:green;">// AddUsersButton</span>
|
|
<span style="color:green;">// </span>
|
|
<span style="color:blue;">this</span>.AddUsersButton.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(29, 189);
|
|
<span style="color:blue;">this</span>.AddUsersButton.Name = <span style="color:#a31515;">"AddUsersButton"</span>;
|
|
<span style="color:blue;">this</span>.AddUsersButton.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(75, 23);
|
|
<span style="color:blue;">this</span>.AddUsersButton.TabIndex = 5;
|
|
<span style="color:blue;">this</span>.AddUsersButton.Text = <span style="color:#a31515;">"Add users"</span>;
|
|
<span style="color:blue;">this</span>.AddUsersButton.UseVisualStyleBackColor = <span style="color:blue;">true</span>;
|
|
<span style="color:blue;">this</span>.AddUsersButton.Click += <span style="color:blue;">new</span> System.<span style="color:#2b91af;">EventHandler</span>(<span style="color:blue;">this</span>.AddUsersButton_Click);
|
|
<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>(284, 262);
|
|
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.AddUsersButton);
|
|
<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 users"</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>.AddUsers_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> AddUsersButton;
|
|
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">OpenFileDialog</span> XmlOpenFileDialog;
|
|
}
|
|
}
|
|
</pre>
|
|
</div>
|
|
<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>
|
|
<div align="left">
|
|
<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> AddUsersCSharp
|
|
{
|
|
<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>
|
|
<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>
|
|
<div align="left">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:green;"><a name="User"></a>//User.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> AddUsersCSharp
|
|
{
|
|
<span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">User</span>
|
|
{
|
|
<span style="color:green;">//First name</span>
|
|
<span style="color:blue;">private</span> <span style="color:blue;">string</span> mSn;
|
|
<span style="color:green;">//Last name</span>
|
|
<span style="color:blue;">private</span> <span style="color:blue;">string</span> mGivenName;
|
|
<span style="color:green;">//Title</span>
|
|
<span style="color:blue;">private</span> <span style="color:blue;">string</span> mTitle;
|
|
<span style="color:green;">//Complete name</span>
|
|
<span style="color:blue;">private</span> <span style="color:blue;">string</span> mCn;
|
|
<span style="color:green;">//Email address</span>
|
|
<span style="color:blue;">private</span> <span style="color:blue;">string</span> mUsername;
|
|
|
|
<span style="color:blue;">public</span> User()
|
|
{
|
|
|
|
}
|
|
|
|
<span style="color:blue;">public</span> <span style="color:blue;">string</span> sn
|
|
{
|
|
<span style="color:blue;">get</span> { <span style="color:blue;">return</span> mSn; }
|
|
<span style="color:blue;">set</span> { mSn = <span style="color:blue;">value</span>; }
|
|
}
|
|
|
|
<span style="color:blue;">public</span> <span style="color:blue;">string</span> givenName
|
|
{
|
|
<span style="color:blue;">get</span> { <span style="color:blue;">return</span> mGivenName; }
|
|
<span style="color:blue;">set</span> { mGivenName = <span style="color:blue;">value</span>; }
|
|
}
|
|
|
|
<span style="color:blue;">public</span> <span style="color:blue;">string</span> title
|
|
{
|
|
<span style="color:blue;">get</span> { <span style="color:blue;">return</span> mTitle; }
|
|
<span style="color:blue;">set</span> { mTitle = <span style="color:blue;">value</span>; }
|
|
}
|
|
|
|
<span style="color:blue;">public</span> <span style="color:blue;">string</span> cn
|
|
{
|
|
<span style="color:blue;">get</span> { <span style="color:blue;">return</span> mCn; }
|
|
<span style="color:blue;">set</span> { mCn = <span style="color:blue;">value</span>; }
|
|
}
|
|
|
|
<span style="color:blue;">public</span> <span style="color:blue;">string</span> username
|
|
{
|
|
<span style="color:blue;">get</span> { <span style="color:blue;">return</span> mUsername; }
|
|
<span style="color:blue;">set</span> { mUsername = <span style="color:blue;">value</span>; }
|
|
}
|
|
}
|
|
}</pre>
|
|
</div>
|
|
<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>
|