Initial Commit of the PDM project (ready for DWS migration)
This commit is contained in:
@@ -0,0 +1,255 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Send Message to 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,categories">
|
||||
<meta name=MS-HKWD content="C# examples,notifications">
|
||||
<meta name=MS-HKWD content="C# examples,users">
|
||||
<meta name=MS-HKWD content="C# examples,messages">
|
||||
|
||||
<body>
|
||||
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
||||
<h1>Send Message to Users Example (C#)</h1>
|
||||
<p><a name="TOP"></a>This example shows how to send a message, also called a notification, to logged-in users who have
|
||||
permission to modify Categories.</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>
|
||||
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><img border="0" src="SendMessage.gif" width="268" height="206">
|
||||
|
||||
<span style="color: green">//----------------------------------------------------------------------------</span>
|
||||
<span style="color: green">// Preconditions:</span>
|
||||
<span style="color: green">// 1. Start Microsoft Visual Studio.</span>
|
||||
<span style="color: green">// 2. Click <b>File > New > Project > C# > Windows Forms Application</b>.</span>
|
||||
<span style="color: green">// 3. Type <b>SendMessageCSharp</b> in Name.</span>
|
||||
<span style="color: green">// 4. Click the <b>Browse</b> button and browse to the folder where to create the project.</span>
|
||||
<span style="color: green">// 5. Click <b>OK</b>. </span>
|
||||
<span style="color: green">// 6. Create a form similar to the form shown above and change: </span>
|
||||
<span style="color: green">// a. Label to <b>VaultsLabel</b>.</span>
|
||||
<span style="color: green">// b. Combo box to <b>VaultsComboBox</b>. </span>
|
||||
<span style="color: green">// c. Button to <b>TraverseUsersButton</b>. </span>
|
||||
<span style="color: green">// 7. Replace the code in <b>Form1.cs</b> with <a href="#Form1">this code</a>.</span>
|
||||
<span style="color: green">// 8. Replace the code in Form1.Designer.cs with <a href="#Form1.Designer">this code</a>.</span>
|
||||
<span style="color: green">// 9. Add <b>EPDM.Interop.epdm.dll </b>as a reference (right-click the project</span>
|
||||
<span style="color: green">// name in the Solution Explorer, click <b>Add Reference</b>, click </span>
|
||||
<span style="color: green">// <b>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 click </span>
|
||||
<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">// 10. Right-click <b>EPDM.Interop.epdm</b> in References, click <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">// 11. Switch back to the <b>Form1.cs</b> code window.</span>
|
||||
<span style="color: green">// 12. 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>Send message to users who can modify Categories</b> button.</span>
|
||||
<span style="color: green">// 4. After several minutes, a SOLIDWORKS PDM Professional notification </span>
|
||||
<span style="color: green">// is displayed only to logged-in users who have
|
||||
// permission to modify Categories. </span>
|
||||
<span style="COLOR: green">// 5. To open the the message, click:
|
||||
// * either the notification while it is displayed or</span>
|
||||
<span style="COLOR: green">// the SOLIDWORKS PDM Professional tray icon.
|
||||
// - or - </span>
|
||||
<span style="COLOR: green">// * <b>Tools > Inbox</b> in File Explorer.</span>
|
||||
<span style="color: green">// 6. Close the dialog.</span>
|
||||
<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.Windows.Forms;
|
||||
<span style="color: blue">using</span> System.Diagnostics;
|
||||
<span style="color: blue">using</span> System.Runtime.InteropServices;
|
||||
<span style="color: blue">using</span> EPDM.Interop.epdm;
|
||||
|
||||
<span style="color: blue">namespace</span> SendMessageCSharp
|
||||
{
|
||||
<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> SendMessageCSharp_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">//Declare and create an instance of IEdmVault5</span>
|
||||
<span style="color: #2b91af">IEdmVault5</span> vault1 = <span style="color: blue">new</span> <span style="color: #2b91af">EdmVault5</span>();
|
||||
|
||||
<span style="color: green">//Cast IEdmVault5 to IEdmVault8</span>
|
||||
<span style="color: #2b91af">IEdmVault8</span> vault = (<span style="color: #2b91af">IEdmVault8</span>)vault1;
|
||||
|
||||
<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);
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color: blue">private</span> <span style="color: blue">void</span> TraverseUsersButton_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: green">//Declare and create an instance of IEdmVault5 object</span>
|
||||
<span style="color: #2b91af">IEdmVault5</span> vault = <span style="color: blue">new</span> <span style="color: #2b91af">EdmVault5</span>();
|
||||
<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">//Declare an IEdmUserMgr5 object</span>
|
||||
<span style="color: #2b91af">IEdmUserMgr5</span> UserMgr = <span style="color: blue">default</span>(<span style="color: #2b91af">IEdmUserMgr5</span>);
|
||||
UserMgr = (<span style="color: #2b91af">IEdmUserMgr5</span>)vault;
|
||||
|
||||
<span style="color: #2b91af">IEdmPos5</span> UserPos = <span style="color: blue">default</span>(<span style="color: #2b91af">IEdmPos5</span>);
|
||||
UserPos = UserMgr.<b>GetFirstUserPosition</b>();
|
||||
<span style="color: blue">while</span> (!UserPos.<b>IsNull</b>)
|
||||
{
|
||||
<span style="color:#2b91af;">IEdmUser5</span> User = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmUser5</span>);
|
||||
<span style="color:#2b91af;">IEdmUser7</span> User1 = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmUser7</span>);
|
||||
User = UserMgr.<b>GetNextUser</b>(UserPos);
|
||||
User1 = (<span style="color:#2b91af;">IEdmUser7</span>)User;
|
||||
<span style="color:blue;">if</span> (User.<b>IsLoggedIn</b>)
|
||||
{
|
||||
<span style="color:blue;">if</span> (User1.<b>HasSysRightEx</b>(<span style="color:#2b91af;">EdmSysPerm</span>.EdmSysPerm_ModifyCategories))
|
||||
{
|
||||
User.<b>SendMsg</b>(<span style="color: #a31515">"Category request"</span>, <span style="color: #a31515">"Please stop by my office sometime "</span> + <span style="color: #a31515">"this morning to discuss adding "</span> + <span style="color: #a31515">"a new file type to a Category."</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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}</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: #008000; background: white"><a name="Form1.Designer"></a>//Form1.Designer.cs</pre>
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: blue">namespace</span> SendMessageCSharp
|
||||
{
|
||||
<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>.TraverseUsersButton = <span style="color: blue">new</span> System.Windows.Forms.<span style="color: #2b91af">Button</span>();
|
||||
<span style="color: blue">this</span>.SuspendLayout();
|
||||
<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>(80, 27);
|
||||
<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>(67, 67);
|
||||
<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>(121, 21);
|
||||
<span style="color: blue">this</span>.VaultsComboBox.TabIndex = 1;
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: green">// TraverseUsersButton</span>
|
||||
<span style="color: green">// </span>
|
||||
<span style="color: blue">this</span>.TraverseUsersButton.Location = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Point</span>(67, 110);
|
||||
<span style="color: blue">this</span>.TraverseUsersButton.Name = <span style="color: #a31515">"TraverseUsersButton"</span>;
|
||||
<span style="color: blue">this</span>.TraverseUsersButton.Size = <span style="color: blue">new</span> System.Drawing.<span style="color: #2b91af">Size</span>(121, 53);
|
||||
<span style="color: blue">this</span>.TraverseUsersButton.TabIndex = 2;
|
||||
<span style="color: blue">this</span>.TraverseUsersButton.Text = <span style="color: #a31515">"Send message to users who can modify Categories"</span>;
|
||||
<span style="color: blue">this</span>.TraverseUsersButton.UseVisualStyleBackColor = <span style="color: blue">true</span>;
|
||||
<span style="color: blue">this</span>.TraverseUsersButton.Click += <span style="color: blue">new</span> System.<span style="color: #2b91af">EventHandler</span>(<span style="color: blue">this</span>.TraverseUsersButton_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>(268, 200);
|
||||
<span style="color: blue">this</span>.Controls.Add(<span style="color: blue">this</span>.TraverseUsersButton);
|
||||
<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">"Send Message to 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>.SendMessageCSharp_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">Button</span> TraverseUsersButton;
|
||||
}
|
||||
}</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