using System; using System.Collections.Generic; using System.Linq; using System.Text; using AyaNova.PlugIn; using System.Windows.Forms; using GZTW.AyaNova.BLL; using System.Threading; namespace AyaNova.PlugIn.PTI { class PTIPlugin : IAyaNovaPlugin { private static bool bLicensed = false; private static bool bPFCDone = false; private static List ObjectsWeCanDealWith = null; #region IAyaNovaPlugin Members #region Interface Properties public string PluginName { get { return "AyaNova PTI"; } } public Guid PluginID { get { return new Guid("{0B937F64-7BC4-4b7d-A1CF-46BD14F49918}"); } } public System.Drawing.Image PluginSmallIcon { get { return Resource.PTI16; } } public System.Drawing.Image PluginLargeIcon { get { return Resource.PTI32; } } public string PluginVersion { get { return "7.6"; } } public string About { get { return "AyaNova PTI plugin"; } } public System.Resources.ResourceManager AyaNovaResourceManager { set { Util.AyaResource = value; } } #endregion interface props #region Initialization and close public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText) { Util.LocaleText = localizedText; //case 1841 //if (AyaBizUtils.Trial) //{ // //case 1031 // //MessageBox.Show("AyaNova PTI can not be used with a trial AyaNova database"); // return false; //} //case 1590 // bLicensed = (!string.IsNullOrEmpty(AyaBizUtils.PluginLicensedVersion("PTI - Peachtree interface"))); //case 2094 //First, handle fuckery related to having two different licensed plugin names for this one plugin //Old style name by default string sPluginKeyName = "PTI - Peachtree interface"; //if the old name doesn't exist then assume new name, //if it doesn't either then no worries it's not licensed either way if (!AyaBizUtils.PluginSubscriptionExists(sPluginKeyName)) sPluginKeyName = "PTI - US Sage 50/Peachtree interface"; bLicensed = AyaBizUtils.PluginAllowed(sPluginKeyName, AyaNova.PlugIn.PTI.Timestamp.BuildAt); if (!bLicensed && AyaBizUtils.PluginTooNew(sPluginKeyName, AyaNova.PlugIn.PTI.Timestamp.BuildAt)) { MessageBox.Show( "NOT LICENSED!\r\n\r\nThis PTI plugin was built " + AyaNova.PlugIn.PTI.Timestamp.BuildAt.ToString() + "\r\n" + "but your license subscription for it ended " + AyaBizUtils.PluginSubscriptionDate(sPluginKeyName).ToString() + "\r\n" + "\r\nDowngrade back to your previous version or purchase a subscription to use this plugin."); return false; } if (AyaNovaVersion.Major != 7) { MessageBox.Show("This AyaNovaPTI plugin requires AyaNova version 7"); return false; } Util.GlobalSettings = AyaBizUtils.GlobalSettings; ObjectsWeCanDealWith = new List(); ObjectsWeCanDealWith.Add(RootObjectTypes.Nothing); // ObjectsWeCanDealWith.Add(RootObjectTypes.Client); return true; } public void Close() { ; } #endregion init and close #region Show menu? public bool SingleObjectMenuShow(RootObjectTypes objectType) { return (ObjectsWeCanDealWith.Contains(objectType)); } public bool MultipleObjectsMenuShow(RootObjectTypes objectType) { return (ObjectsWeCanDealWith.Contains(objectType)); } #endregion Show menu #region menu options public List SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject) { if (!ObjectsWeCanDealWith.Contains(objectType)) return null; if (!bLicensed) { MessageBox.Show("An AyaNova PTI license is required to use this Peachtree integration plugin\r\n"); return null; } if (!DoPFC()) return null; List list = new List(); switch (objectType) { case RootObjectTypes.Nothing: list.Add(new AyaNovaPluginMenuItem("MAIN", "PTI Main", Resource.PTI32, Resource.PTI16)); if(bPFCDone) list.Add(new AyaNovaPluginMenuItem("RESCANQB", "Refresh Peachtree connection", null,null)); break; //case RootObjectTypes.Client: // list.Add(new AyaNovaPluginMenuItem("CLIENTLINKREFRESH", "Link / Refresh", null, null)); // break; } return list; //if (objectType == RootObjectTypes.Client) //{ //List list = new List(); //list.Add(new AyaNovaPluginMenuItem("KEY1", "Command1 for " + ayaNovaObject.ToString(), Resource.UnLink32, Resource.OK16)); //list.Add(new AyaNovaPluginMenuItem("KEY2", "My command 2 no icon", null, null)); //return list; ////} //else // return null; } public List MultipleObjectsMenuOptions(RootObjectTypes objectType) { return null; //if (!ObjectsWeCanDealWith.Contains(objectType)) return null; //if (!bLicensed) //{ // MessageBox.Show("An AyaNova PTI license is required to use this Peachtree integration plugin\r\n"); // return null; //} //if (!DoPFC()) return null; //List list = new List(); //list.Add(new AyaNovaPluginMenuItem("KEY1", "List Command1 for " + objectType.ToString(), null,null)); //list.Add(new AyaNovaPluginMenuItem("KEY2", "Multiple command 2 no icon", null, null)); //return list; } #endregion menu options #region Commands public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List objectIDList, object listObject) { return false; //if (!ObjectsWeCanDealWith.Contains(objectType)) return false; //MessageBox.Show("Command for list:" + commandKey + " ObjectType:" + objectType.ToString() + " Count selected: " + objectIDList.Count.ToString()); //return true; } public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject) { if (!ObjectsWeCanDealWith.Contains(objectType)) return; switch (commandKey) { case "MAIN": MainForm mf = new MainForm(); mf.Show(); break; case "RESCANQB": Util.PopulatePTListCache(); Util.PopulateAyaListCache(); break; } //string sObject = "NULL"; //if (ayaNovaObject != null) // sObject = ayaNovaObject.ToString(); //MessageBox.Show("Command:" + commandKey + " ObjectType:" + objectType.ToString() + " Object: " + sObject); } #endregion commands #endregion #region Pre flight check private bool DoPFC() { if (bPFCDone) return true; if (Util.PreFlightCheck() != Util.pfstat.OK) { IntegrationLog.Log(Util.PTID, "PTI Preflight check failed, shutting down"); bPFCDone = false; return false; } bPFCDone = true; return true; } #endregion } }