Пример #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public SBOAddon()
        {
            try
            {
                //Application forms
                Forms = eCommon.CollectFormsAttribute();

                //--------------- remove and load menus -----------
                // Change if needed ---------------------------
                if (eCommon.SBO_Application.Menus.Exists(SBOAddon.gcAddOnName))
                {
                    eCommon.SBO_Application.Menus.RemoveEx(SBOAddon.gcAddOnName);
                }

                eCommon.SBO_Application.Menus.Item("43520").SubMenus.Add(SBOAddon.gcAddOnName, gcAddonText, BoMenuType.mt_POPUP, 99);
                // Change if needed ---------------------------

                foreach (string Key in Forms.Keys)
                {
                    FormAttribute oAttr = (FormAttribute)Forms[Key];
                    if (oAttr.HasMenu)
                    {
                        if (eCommon.SBO_Application.Menus.Exists(oAttr.FormType))
                        {
                            eCommon.SBO_Application.Menus.RemoveEx(oAttr.FormType);
                        }
                        eCommon.SBO_Application.Menus.Item(oAttr.ParentMenu).SubMenus.Add(oAttr.FormType, oAttr.MenuName, BoMenuType.mt_STRING, oAttr.Position);
                    }
                }

                try
                {
                    eCommon.SBO_Application.Menus.Item(SBOAddon.gcAddOnName).Image = Environment.CurrentDirectory + "\\Logo.JPG";
                }
                catch { }

                //Register Events
                RegisterAppEvents();
                RegisterFormEvents();

                //Register currently opened forms - initialized opened forms so it is ready to use.
                RegisterForms();

                //Create Authorization
                AddAuthorizationTree();

                //Notify the users the addon is ready to use.
                eCommon.SBO_Application.StatusBar.SetText("Addon " + SBOAddon.gcAddOnName + " is ready.", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
            }
            catch (Exception ex)
            {
                Connected = false;
                MessageBox.Show("Failed initializing addon. " + ex.Message);
            }
            finally
            {
            }
        }
Пример #2
0
        public void OnMenuEvent(ref SAPbouiCOM.MenuEvent pVal, out bool Bubble)
        {
            Bubble = true;
            try
            {
                if (pVal.BeforeAction == true)
                {
                    SAPbouiCOM.Form oForm = null;

                    oForm = eCommon.SBO_Application.Forms.ActiveForm;
                    String sXML = oForm.GetAsXML();
                    switch (pVal.MenuUID)
                    {
                    case "1293":
                        break;

                    case "1285":
                        break;
                    }
                }
                else
                {
                    switch (pVal.MenuUID)
                    {
                    default:
                        FormAttribute oAttrib = Forms[pVal.MenuUID] as FormAttribute;
                        if (oAttrib != null)
                        {
                            try
                            {
                                //Execute the constructor
                                System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
                                Type oType = asm.GetType(oAttrib.TypeName);
                                System.Reflection.ConstructorInfo ctor = oType.GetConstructor(new Type[0]);
                                if (ctor != null)
                                {
                                    object oForm = ctor.Invoke(new Object[0]);
                                }
                                else
                                {
                                    throw new Exception("No default constructor found for form type - " + oAttrib.FormType);
                                }
                            }
                            catch (Exception Ex)
                            {
                                eCommon.SBO_Application.MessageBox(Ex.Message);
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception Ex)
            {
                eCommon.SBO_Application.StatusBar.SetText(Ex.Message, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
            }
        }
Пример #3
0
 private void RegisterForms()
 {
     for (int i = 0; i < eCommon.SBO_Application.Forms.Count; i++)
     {
         if (!oOpenForms.Contains(eCommon.SBO_Application.Forms.Item(i).UniqueID))
         {
             FormAttribute oAttrib = Forms[eCommon.SBO_Application.Forms.Item(i).TypeEx] as FormAttribute;
             if (oAttrib != null)
             {
                 try
                 {
                     //Execute the constructor
                     System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
                     Type oType = asm.GetType(oAttrib.TypeName);
                     System.Reflection.ConstructorInfo ctor = oType.GetConstructor(new Type[1] {
                         typeof(String)
                     });
                     if (ctor != null)
                     {
                         object oForm = ctor.Invoke(new Object[1] {
                             eCommon.SBO_Application.Forms.Item(i).UniqueID
                         });
                     }
                     else
                     {
                         throw new Exception("No constructor which accepts the formUID found for form type - " + oAttrib.FormType);
                     }
                 }
                 catch (Exception ex)
                 {
                     eCommon.SBO_Application.MessageBox(ex.Message);
                 }
             }
         }
     }
 }