148 lines
4.8 KiB
C#
148 lines
4.8 KiB
C#
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 ScriptHeader : Form
|
|
{
|
|
public string Script { get; set; }
|
|
public ScriptHeader()
|
|
{
|
|
InitializeComponent();
|
|
cklBizObjects.DataSource = Enum.GetValues(typeof(RootObjectTypes));
|
|
}
|
|
|
|
private void ScriptHeader_Load(object sender, EventArgs e)
|
|
{
|
|
this.Icon = Resource.ScriptIco;
|
|
this.btnOK.Image = (System.Drawing.Image)Util.AYS.AyaNovaResourceManager.GetObject("OK24");
|
|
this.btnCancel.Image = (System.Drawing.Image)Util.AYS.AyaNovaResourceManager.GetObject("Cancel24");
|
|
ParseScript();
|
|
}
|
|
|
|
|
|
#region parse
|
|
/// <summary>
|
|
/// Read settings from script and update form controls
|
|
/// </summary>
|
|
private void ParseScript()
|
|
{
|
|
|
|
Util.ScriptItem si = new Util.ScriptItem(Script);
|
|
//set controls
|
|
edName.Text = si.ScriptName;
|
|
cbShowFor.SelectedItem = si.ScriptShowInMenuFor;
|
|
|
|
for (int x = 0; x < cklBizObjects.Items.Count; x++)
|
|
{
|
|
if (si.ScriptHandlesTypes.Contains((RootObjectTypes)Enum.Parse(typeof(RootObjectTypes), cklBizObjects.Items[x].ToString(), true)))
|
|
cklBizObjects.SetItemChecked(x, true);
|
|
else
|
|
cklBizObjects.SetItemChecked(x, false);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update settings from form controls to script
|
|
/// </summary>
|
|
private void UpdateScript()
|
|
{
|
|
//Name
|
|
string sNewName = "//Name: " + edName.Text;
|
|
string sOldName = Util.rxName.Match(Script).Value;
|
|
if (string.IsNullOrEmpty(sOldName))
|
|
Script = sNewName + Script;
|
|
else
|
|
Script = Script.Replace(sOldName, sNewName);
|
|
|
|
//Show in menu for
|
|
string sNewShowInMenuFor = "//ShowInMenuFor: " + cbShowFor.SelectedItem.ToString();
|
|
string sOldShowInMenuFor = Util.rxShowInMenuFor.Match(Script).Value;
|
|
if (string.IsNullOrEmpty(sOldShowInMenuFor))
|
|
Script = sNewShowInMenuFor + "\r\n" + Script;
|
|
else
|
|
Script = Script.Replace(sOldShowInMenuFor, sNewShowInMenuFor);
|
|
|
|
|
|
|
|
//Object types
|
|
string sOldObjectTypes=Util.rxHandlesAyaNovaTypes.Match(Script).Value;
|
|
System.Text.StringBuilder sbNew = new StringBuilder();
|
|
|
|
for (int x = 0; x < cklBizObjects.Items.Count; x++)
|
|
{
|
|
if (cklBizObjects.GetItemChecked(x))
|
|
{
|
|
sbNew.Append(cklBizObjects.Items[x].ToString());
|
|
sbNew.Append(", ");
|
|
}
|
|
}
|
|
|
|
if (sbNew.Length > 2)
|
|
sbNew.Length = sbNew.Length - 2;
|
|
else
|
|
sbNew.Append("Nothing");
|
|
|
|
|
|
if (string.IsNullOrEmpty(sOldObjectTypes))
|
|
Script = "//HandlesAyaNovaTypes: " + sbNew.ToString() + "\r\n" + Script;
|
|
else
|
|
Script = Script.Replace(sOldObjectTypes, "//HandlesAyaNovaTypes: " + sbNew.ToString());
|
|
|
|
}
|
|
#endregion parse
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
//Sanity check
|
|
if (string.IsNullOrEmpty(edName.Text))
|
|
{
|
|
MessageBox.Show("Name is a required field!");
|
|
return;
|
|
}
|
|
|
|
if (cbShowFor.SelectedIndex==-1)
|
|
{
|
|
MessageBox.Show("Show for selection is required!");
|
|
return;
|
|
}
|
|
|
|
if (cklBizObjects.CheckedItems.Count == 0)
|
|
{
|
|
if (cbShowFor.SelectedItem.ToString().Contains("Single AyaNova object") || cbShowFor.SelectedItem.ToString().Contains("List of AyaNova objects"))
|
|
{
|
|
MessageBox.Show("AyaNova type(s) must be selected when single or list show for is selected");
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
//ok safe to proceed
|
|
UpdateScript();
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//======================================
|
|
}
|
|
}
|