Example #1
0
 public void RegisterFormEvents()
 {
     TWM_3D_IntegrationEvent = eCommon.SBO_Application.Forms.GetEventForm("TWM_3D_Integration");
     //twmB2B_IMPEvent.CloseBefore += new SAPbouiCOM._IEventFormEvents_CloseBeforeEventHandler(twmB2B_IMP.OnBeforeFormClose);
     //twmB2B_IMPEvent.ResizeAfter += new _IEventFormEvents_ResizeAfterEventHandler(twmB2B_IMP.OnAfterFormResize);
 }
Example #2
0
        /// <summary>
        /// Get the form events based on the Form Event attribute declared on the methods in each of the class
        /// </summary>
        public void RegisterFormEvents()
        {
            string NameSpace         = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            Type   FormEventAttrType = Type.GetType(string.Format("{0}.FormEventAttribute", NameSpace));

            foreach (System.Reflection.Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (asm.FullName.StartsWith("mscorlib"))
                {
                    continue;
                }
                if (asm.FullName.StartsWith("Interop"))
                {
                    continue;
                }
                if (asm.FullName.StartsWith("System"))
                {
                    continue;
                }
                if (asm.FullName.StartsWith("Microsoft"))
                {
                    continue;
                }

                foreach (Type type in asm.GetTypes())
                {
                    Type          FormAttr = Type.GetType(string.Format("{0}.FormAttribute", NameSpace));
                    FormAttribute frmAttr  = null;
                    foreach (System.Attribute Attr in type.GetCustomAttributes(FormAttr, false))
                    {
                        frmAttr = (FormAttribute)Attr;
                    }
                    //Get the methods attribute
                    foreach (System.Reflection.MethodInfo method in type.GetMethods())
                    {
                        foreach (System.Attribute Attr in method.GetCustomAttributes(FormEventAttrType, false))
                        {
                            SAPbouiCOM.EventForm oEvent       = null;
                            FormEventAttribute   frmEventAttr = (FormEventAttribute)Attr;
                            String sKey = string.Format("{0}_{1}", frmAttr.FormType, frmEventAttr.oEventType.ToString());
                            if (!SBOAddon.oFormEvents.Contains(frmAttr.FormType))
                            {
                                oEvent = eCommon.SBO_Application.Forms.GetEventForm(frmAttr.FormType);
                                SBOAddon.oFormEvents.Add(frmAttr.FormType, oEvent);
                            }
                            else
                            {
                                oEvent = (SAPbouiCOM.EventForm)SBOAddon.oFormEvents[frmAttr.FormType];
                            }

                            if (SBOAddon.oRegisteredFormEvents.Contains(sKey))
                            {
                                throw new Exception(string.Format("The form event method type [{0}] can not be registered twice", sKey));
                            }
                            else
                            {
                                SBOAddon.oRegisteredFormEvents.Add(sKey, "");
                            }

                            Type EventClass = oEvent.GetType();
                            System.Reflection.EventInfo oInfo = EventClass.GetEvent(frmEventAttr.oEventType.ToString());
                            if (oInfo == null)
                            {
                                throw new Exception(string.Format("Invalid method info name. [{0}]", frmEventAttr.oEventType.ToString()));
                            }
                            Delegate d = Delegate.CreateDelegate(oInfo.EventHandlerType, method);

                            oInfo.AddEventHandler(oEvent, d);
                        }
                    }
                }
            }
        }