AyaNova service management & work order software
AyaNova Support Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



AyaScript plugin - Sample scripts Expand / Collapse
Author
Message
Posted 2/1/2010 4:21:11 PM
AyaNova Development & Support

AyaNova Development & SupportAyaNova Development & SupportAyaNova Development & SupportAyaNova Development & SupportAyaNova Development & SupportAyaNova Development & SupportAyaNova Development & SupportAyaNova Development & Support

Group: Administrators
Last Login: 2/11/2010 12:27:00 PM
Posts: 140, Visits: 493
I'm posting the stock scripts that come with the AyaScript plugin here in case anyone needs to refer back to them because they accidentally (or on purpose) deleted the stock scripts in the AyaScript plugin.

Remember one AyaScriptMain per script, don't copy and paste all this in one 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 objectIDList)
{
MessageBox.Show("Hello from AyaScript!");
}

---------------------------------------------------
//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 objectIDList)
{
ASCopyableMessageBox d = new ASCopyableMessageBox("This is a copyable message box you can use with your scripts, see source code for details.\rYour text here.\rLine two\rLine three\rLast line!");
d.ShowDialog();
d.Dispose();
}

----------------------------------------------------------
//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 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 +
"\rAre 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();

}

---------------------------------------------------------
//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 objectIDList)
{
StringBuilder sb = new StringBuilder();
sb.Append("Script was called with these parameters:\r");

//Was script called from a list form or a single object editing form?
sb.Append("IsList: ");
sb.Append(IsList.ToString());
sb.Append("\r");

//What type of AyaNova RootObjectType was the script called from?
sb.Append("objectType: ");
sb.Append(objectType.ToString());
sb.Append("\r");

//ayaNovaObject parameter
if (ayaNovaObject is DBNull)
sb.Append("ayaNovaObject: is a DBNull (script was called from main menu)\r");
else
{
sb.Append("ayaNovaObject type: ");
sb.Append(ayaNovaObject.GetType().ToString());
sb.Append("\r");
}

//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 && objectIDList.Count == 0)
sb.Append(" (User didn't select any items in list)");


//Show the info
MessageBox.Show(sb.ToString());


}

-----------------------------------------------------
//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 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\rAre 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 +
"\rAre 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;

}
}

--------------------------------------------------------
//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 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);

}

}

--------------------------------------------------------
//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 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" + 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);
}
Post #5019
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: AyaNova Sales & Support, John

Permissions Expand / Collapse

All times are GMT -8:00, Time now is 2:28am

Powered by InstantForum.NET v4.1.4 © 2010
Execution: 0.031. 9 queries. Compression Disabled.