Files
ayanova7/Installs/AyaScript/AyaScripts.xml
2018-06-29 19:47:36 +00:00

336 lines
11 KiB
XML

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Scripts" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Scripts">
<xs:complexType>
<xs:sequence>
<xs:element name="script" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Scripts>
<script>//Name: Screenshot
//ShowInMenuFor: Everywhere
//HandlesAyaNovaTypes: Nothing
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List&lt;Guid&gt; objectIDList)
{
try
{
Bitmap capture = GetDesktopImage();
SaveFileDialog d = new SaveFileDialog();
d.Filter = "Png Image|*.png";
d.Title = "Save screenshot";
d.ShowDialog();
if (!string.IsNullOrEmpty(d.FileName))
{
capture.Save(d.FileName, ImageFormat.Png);
}
}
catch (Exception e)
{
MessageBox.Show("Error saving screenshot: \r\n" + e.Message);
}
}
public static Bitmap GetDesktopImage()
{
WIN32_API.SIZE size;
IntPtr hDC = WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
IntPtr hMemDC = WIN32_API.CreateCompatibleDC(hDC);
size.cx = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
size.cy = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);
m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, size.cx, size.cy);
if (m_HBitmap!=IntPtr.Zero)
{
IntPtr hOld = (IntPtr) WIN32_API.SelectObject(hMemDC, m_HBitmap);
WIN32_API.BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC, 0, 0, WIN32_API.SRCCOPY);
WIN32_API.SelectObject(hMemDC, hOld);
WIN32_API.DeleteDC(hMemDC);
WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(), hDC);
return System.Drawing.Image.FromHbitmap(m_HBitmap);
}
return null;
}
protected static IntPtr m_HBitmap;
public class WIN32_API
{
public struct SIZE
{
public int cx;
public int cy;
}
public const int SRCCOPY = 13369376;
public const int SM_CXSCREEN=0;
public const int SM_CYSCREEN=1;
[DllImport("gdi32.dll",EntryPoint="DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);
[DllImport("gdi32.dll",EntryPoint="DeleteObject")]
public static extern IntPtr DeleteObject(IntPtr hDc);
[DllImport("gdi32.dll",EntryPoint="BitBlt")]
public static extern bool BitBlt(IntPtr hdcDest,int xDest,int yDest,int wDest,int hDest,IntPtr hdcSource,int xSrc,int ySrc,int RasterOp);
[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleBitmap")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport ("gdi32.dll",EntryPoint="CreateCompatibleDC")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport ("gdi32.dll",EntryPoint="SelectObject")]
public static extern IntPtr SelectObject(IntPtr hdc,IntPtr bmp);
[DllImport("user32.dll", EntryPoint="GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll",EntryPoint="GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);
[DllImport("user32.dll",EntryPoint="GetWindowDC")]
public static extern IntPtr GetWindowDC(Int32 ptr);
[DllImport("user32.dll",EntryPoint="ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDc);
}
</script>
</Scripts>
<Scripts>
<script>//Name: zSample - Hello AyaScript!
//ShowInMenuFor: Everywhere
//HandlesAyaNovaTypes: Nothing
//This is a bare minimum script. The comments above are required and the AyaScriptMain method and it's signature below are required
//the rest is up to you.
public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List&lt;Guid&gt; objectIDList)
{
MessageBox.Show("Hello from AyaScript!");
}
</script>
</Scripts>
<Scripts>
<script>//Script created: 1/29/2010 12:33:49 PM
//Name: zSample - winform
//ShowInMenuFor: Everywhere
//HandlesAyaNovaTypes: Client
//You can define your own Forms in scripts as well as this example shows
public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List&lt;Guid&gt; objectIDList)
{
MyForm d=new MyForm();
d.ShowDialog();
}
public class MyForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
public MyForm()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ClientSize = new System.Drawing.Size(435, 264);
this.Name = "MyForm";
this.Text = "My form defined in AyaScript";
this.ResumeLayout(false);
}
}</script>
</Scripts>
<Scripts>
<script>//Name: zSample - copyable message box
//ShowInMenuFor: Everywhere
//HandlesAyaNovaTypes: Nothing
//This example shows useage of the built in Copyable message box which you can use with your scripts that return a lot of data or log something that
//the end user might want to copy and paste elsewhere
public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List&lt;Guid&gt; objectIDList)
{
ASCopyableMessageBox d = new ASCopyableMessageBox("This is a copyable message box you can use with your scripts, see source code for details.\r\nYour text here.\r\nLine two\r\nLine three\r\nLast line!");
d.ShowDialog();
d.Dispose();
}
</script>
</Scripts>
<Scripts>
<script>//Name: zSample - Single client modify fields
//ShowInMenuFor: Single AyaNova object
//HandlesAyaNovaTypes: Client
//This sample shows how to deal with a single object, in this case a client but the concept is the same for other objects
//For more information on using the AyaNova API see the API reference at http://api.ayanova.com/
//and the "Development / SDK / API" area of the AyaNova support forum at http://forum.ayanova.com/
public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List&lt;Guid&gt; objectIDList)
{
//Ignore if we don't have an object
if(ayaNovaObject==null || ayaNovaObject is DBNull) return;
Client c=ayaNovaObject as Client;
if (MessageBox.Show("Warning: this will modify the account number and notes fields of current client " + c.Name +
"\r\nAre you sure?", "About to modify client", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;
c.AccountNumber="123456";
c.Notes = "These notes were set by AyaScript on " + DateTime.Now.ToString();
}
</script>
</Scripts>
<Scripts>
<script>//Name: zSample - parameter usage
//ShowInMenuFor: Everywhere
//HandlesAyaNovaTypes: Client, HeadOffice, Part, Project, Unit, Vendor, WikiPage, Workorder
public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List&lt;Guid&gt; objectIDList)
{
StringBuilder sb = new StringBuilder();
sb.Append("Script was called with these parameters:\r\n");
//Was script called from a list form or a single object editing form?
sb.Append("IsList: ");
sb.Append(IsList.ToString());
sb.Append("\r\n");
//What type of AyaNova RootObjectType was the script called from?
sb.Append("objectType: ");
sb.Append(objectType.ToString());
sb.Append("\r\n");
//ayaNovaObject parameter
if (ayaNovaObject is DBNull)
sb.Append("ayaNovaObject: is a DBNull (script was called from main menu)\r\n");
else
{
sb.Append("ayaNovaObject type: ");
sb.Append(ayaNovaObject.GetType().ToString());
sb.Append("\r\n");
}
//List parameter
sb.Append("objectIDList:");
sb.Append(" list contains ");
sb.Append(objectIDList.Count.ToString());
sb.Append(" Guid values");
//Did user select any items in the list?
if (IsList &amp;&amp; objectIDList.Count == 0)
sb.Append(" (User didn't select any items in list)");
//Show the info
MessageBox.Show(sb.ToString());
}
</script>
</Scripts>
<Scripts>
<script>//Name: zSample - Set Client notification off
//ShowInMenuFor: Everywhere
//HandlesAyaNovaTypes: Client
//This sample shows a script that can work with both a list or a single object of type client
//Note that this script will display everywhere as it needs to support both lists and single objects
//If you only want a script to display for client list or single object you need to make
//two separate scripts
//This script is based on a real world requirement a user had to turn off client notifications
//The principles for working with lists and single objects are the same regardless of object type
public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List&lt;Guid&gt; objectIDList)
{
if (IsList)
{
if (objectIDList.Count == 0)
{
MessageBox.Show("No clients selected in list. Nothing to process.");
return;
}
else
{
if (MessageBox.Show("Warning: You are about to turn off client notifications for " + objectIDList.Count.ToString() +
" clients\r\nAre you sure?", "Modify clients", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;
foreach (Guid clientID in objectIDList)
{
Client c = Client.GetItem(clientID);
c.SendNotifications = false;
c.Save();
}
}
}
else
{
//single object
//Ignore if we don't have an object
if (ayaNovaObject == null || ayaNovaObject is DBNull) return;
Client c = ayaNovaObject as Client;
if (MessageBox.Show("Warning: You are about to turn off client notifications for " + c.Name +
"\r\nAre you sure?", "Modify client", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;
c.SendNotifications = false;
//Note: we dont' call save here because we know we're in an edit form for a single client
//by not calling save we give the user the opportunity to cancel the change when they close the client
//editing form.
return;
}
}
</script>
</Scripts>
</NewDataSet>