Exemplo n.º 1
0
        /// <summary>
        /// Rate - set Multiply Rate from Divide Rate and vice versa
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="windowNo">window no</param>
        /// <param name="tab">tab</param>
        /// <param name="field">field</param>
        /// <param name="value">value</param>
        /// <returns>null or error message</returns>
        public String Rate(Ctx ctx, int windowNo, GridTab tab, GridField field, Object value)
        {
            if (IsCalloutActive() || value == null)             //	assuming it is Conversion_Rate
            {
                return("");
            }
            SetCalloutActive(true);

            Decimal rate1 = (Decimal)value;
            Decimal rate2 = Utility.Env.ZERO;
            Decimal one   = new Decimal(1.0);

            if (System.Convert.ToDouble(rate1) != 0.0)  //	no divide by zero
            {
                rate2 = Decimal.Round(Decimal.Divide(one, rate1), 12, MidpointRounding.AwayFromZero);
            }
            //
            if (field.GetColumnName().Equals("MultiplyRate"))
            {
                tab.SetValue("DivideRate", rate2);
            }
            else
            {
                tab.SetValue("MultiplyRate", rate2);
            }
            log.Info(field.GetColumnName() + "=" + rate1 + " => " + rate2);
            SetCalloutActive(false);
            return("");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Start Callout.
        ///	Callout's are used for cross field validation and setting values in other fields
        ///	when returning a non empty (error message) string, an exception is raised
        ///	When invoked, the Tab model has the new value!
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="methodName">method name</param>
        /// <param name="windowNo">current window number</param>
        /// <param name="tab">model Tab</param>
        /// <param name="field">modal field</param>
        /// <param name="newValue">new value</param>
        /// <param name="oldValue">old value</param>
        /// <returns>Error message or ""</returns>
        public String Start(Ctx ctx, String methodName, int windowNo, GridTab tab,
                            GridField field, Object newValue, Object oldValue)
        {
            if (methodName == null || methodName.Length == 0)
            {
                throw new ArgumentException("No Method Name");
            }
            //
            String        retValue = "";
            StringBuilder msg      = new StringBuilder(methodName).Append(" - ")
                                     .Append(field.GetColumnName())
                                     .Append("=").Append(newValue)
                                     .Append(" (old=").Append(oldValue)
                                     .Append(") {active=").Append(IsCalloutActive()).Append("}");

            if (!IsCalloutActive())
            {
                log.Info(msg.ToString());
            }

            //	Find Method
            MethodInfo method = GetMethod(methodName);

            if (method == null)
            {
                throw new ArgumentException("Method not found: " + methodName);
            }
            int argLength = method.GetParameters().Length;

            if (!(argLength == 5 || argLength == 6))
            {
                throw new ArgumentException("Method " + methodName + " has invalid no of arguments: " + argLength);
            }

            //	Call Method
            try
            {
                Object[] args = null;
                if (argLength == 6)
                {
                    args = new Object[] { ctx, windowNo, tab, field, newValue, oldValue }
                }
                ;
                else
                {
                    args = new Object[] { ctx, windowNo, tab, field, newValue }
                };
                retValue = (String)method.Invoke(this, args);
            }
            catch (Exception e)
            {
                SetCalloutActive(false);
                //Throwable ex = e.getCause();	//	InvocationTargetException
                //if (ex == null)
                //    ex = e;
                ////log.log(Level.SEVERE, "start: " + methodName, ex);
                //ex.printStackTrace(System.err);
                //retValue = ex.getLocalizedMessage();

                retValue = e.Message;
            }
            return(retValue);
        }