This commit is contained in:
254
source/Plugins/AyaNova.PlugIn.AyaScript/ScriptDesigner.cs
Normal file
254
source/Plugins/AyaNova.PlugIn.AyaScript/ScriptDesigner.cs
Normal file
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using GZTW.AyaNova.BLL;
|
||||
|
||||
namespace AyaNova.PlugIn.AyaScript
|
||||
{
|
||||
public partial class ScriptDesigner : Form
|
||||
{
|
||||
//string mScript = "";
|
||||
|
||||
//public string Script
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return mScript;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// if (mScript != value)
|
||||
// {
|
||||
// mScript = value;
|
||||
// IsDirty = true;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
public Guid ScriptID { get; set; }
|
||||
private bool IsDirty { get; set; }
|
||||
private bool IsNew { get; set; }
|
||||
//private bool IsEmpty
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return string.IsNullOrEmpty(Script);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
public ScriptDesigner()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
private void ScriptDesigner_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.Icon = Resource.ScriptIco;
|
||||
IsDirty = false;
|
||||
IsNew = true;
|
||||
ScriptID = Guid.NewGuid();
|
||||
PopulateOpenMenu();
|
||||
}
|
||||
|
||||
private void ScriptDesigner_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (!SaveChanges()) e.Cancel = true;
|
||||
Util.WriteScripts();
|
||||
}
|
||||
|
||||
|
||||
private void PopulateOpenMenu()
|
||||
{
|
||||
openToolStripMenuItem.DropDownItems.Clear();
|
||||
foreach (Util.ScriptItem si in Util.ScriptList)
|
||||
{
|
||||
ToolStripMenuItem tsi = new ToolStripMenuItem();
|
||||
tsi.Text = si.ScriptName;
|
||||
tsi.Tag = si.ScriptID;
|
||||
openToolStripMenuItem.DropDownItems.Add(tsi);
|
||||
}
|
||||
}
|
||||
|
||||
private void openToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
if (!SaveChanges()) return;
|
||||
//load selected script into editor
|
||||
Guid g = (Guid)e.ClickedItem.Tag;
|
||||
edScript.Text = Util.GetScript(g);
|
||||
ScriptID = g;
|
||||
IsDirty = false;
|
||||
IsNew = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns false if should cancel operation
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool SaveChanges()
|
||||
{
|
||||
if (!IsDirty) return true;
|
||||
DialogResult dr=MessageBox.Show("Save changes?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
|
||||
if (dr == DialogResult.Cancel) return false;
|
||||
if (dr == DialogResult.No) return true;
|
||||
Util.SaveScript(edScript.Text,ScriptID);
|
||||
IsDirty = false;
|
||||
IsNew = false;
|
||||
PopulateOpenMenu();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Main entry point for script
|
||||
///// This method must be present and it's definition and parameters unmodified
|
||||
///// to work with AyaScript
|
||||
/////
|
||||
///// Other methods can be defined separately but this one must be present
|
||||
///// </summary>
|
||||
///// <param name="objectType">AyaNova RootObjectType of passed ayaNovaObject or the type of object in the list if it's a list object</param>
|
||||
///// <param name="ayaNovaObject">If a single object then this is the AyaNova business object, if a list then this is the list object</param>
|
||||
///// <param name="objectIDList">If a list, this contains the id's of the AyaNova objects in the list. Null if not called from a list.</param>
|
||||
//public static void AyaScriptMain(RootObjectTypes objectType, Object ayaNovaObject, List<Guid> objectIDList)
|
||||
//{
|
||||
//}
|
||||
|
||||
|
||||
private void newScriptToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!SaveChanges()) return;
|
||||
System.Text.StringBuilder sb = new StringBuilder();
|
||||
ScriptID = Guid.NewGuid();
|
||||
//Header
|
||||
sb.Append("//Script created: ");
|
||||
sb.Append(System.DateTime.Now.ToString());
|
||||
sb.Append("\r\n");
|
||||
sb.Append("//Name: Script ");
|
||||
sb.Append(System.DateTime.Now.ToString());
|
||||
sb.Append("\r\n");
|
||||
sb.Append("//ShowInMenuFor: Everywhere\r\n");
|
||||
sb.Append("//HandlesAyaNovaTypes: Client\r\n");
|
||||
sb.Append("\r\n");
|
||||
sb.Append("\r\n");
|
||||
sb.Append("\r\n");
|
||||
sb.Append("\r\n");
|
||||
sb.Append("\r\n");
|
||||
//Main method
|
||||
sb.Append("/// <summary> \r\n" +
|
||||
"/// Main entry point for script \r\n" +
|
||||
"/// This method must be present and it's definition and parameters unmodified \r\n" +
|
||||
"/// to work with AyaScript \r\n" +
|
||||
"/// \r\n" +
|
||||
"/// Other methods can be defined separately but this one must be present \r\n" +
|
||||
"/// </summary> \r\n" +
|
||||
"/// <param name=IsList>true if called from a list object, false if called from a single object edit form</param> \r\n" +
|
||||
"/// <param name=objectType>AyaNova RootObjectType of passed ayaNovaObject or the type of object in the list if it's a list object</param> \r\n" +
|
||||
"/// <param name=ayaNovaObject>If a single object then this is the AyaNova business object, if a list then this is the list object, if called from the main menu where there is no object this is DBNull.Value</param> \r\n" +
|
||||
"/// <param name=objectIDList>If a list, this contains the id's of the AyaNova objects in the list, otherwise it's an empty list.</param>\r\n" );
|
||||
sb.Append("public static void AyaScriptMain(bool IsList, RootObjectTypes objectType, Object ayaNovaObject, List<Guid> objectIDList)\r\n");
|
||||
sb.Append("{\r\n");
|
||||
sb.Append("\tMessageBox.Show(\"Hello from AyaScript!\");\r\n");
|
||||
sb.Append("}\r\n");
|
||||
|
||||
|
||||
edScript.Text = sb.ToString();
|
||||
IsNew = true;
|
||||
|
||||
|
||||
ScriptHeader sh = new ScriptHeader();
|
||||
sh.Script = edScript.Text;
|
||||
|
||||
if (sh.ShowDialog() == DialogResult.Cancel)
|
||||
{
|
||||
sh.Dispose();
|
||||
return;
|
||||
}
|
||||
sh.Dispose();
|
||||
edScript.Text = sh.Script;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set header values
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void headerToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ScriptHeader sh = new ScriptHeader();
|
||||
sh.Script = edScript.Text;
|
||||
if (sh.ShowDialog() == DialogResult.OK)
|
||||
edScript.Text = sh.Script;
|
||||
sh.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save script
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void saveScriptToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsDirty) return;
|
||||
Util.SaveScript(edScript.Text, ScriptID);
|
||||
IsDirty = false;
|
||||
IsNew = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void deleteScriptToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (MessageBox.Show("Are you sure?", "Delete script permanently?", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
||||
return;
|
||||
if(!IsNew)
|
||||
Util.DeleteScript(ScriptID);
|
||||
edScript.Text = "";
|
||||
ScriptID = Guid.NewGuid();
|
||||
PopulateOpenMenu();
|
||||
edScript.Text = "";
|
||||
IsDirty = false;
|
||||
IsNew = true;
|
||||
}
|
||||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!SaveChanges()) return;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void edScript_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show(Util.AYS.About + "\r\nVersion " + Util.AYS.PluginVersion);
|
||||
}
|
||||
|
||||
private void helpContentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Diagnostics.Process.Start("http://api.ayanova.com/AyaScript/index.htm");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user