示例#1
0
        public string Output()
        {
            StringBuilder sb = new StringBuilder();

            foreach (var n in Names)
            {
                sb.Append(n);
                sb.Append(",");
            }

            if (Amount1 >= 0)
            {
                sb.Append("$" + Amount1.ToString());
            }
            else
            {
                sb.Append(" ");
            }
            sb.Append(",");

            if (Amount2 >= 0)
            {
                sb.Append("$" + Amount2.ToString());
            }
            else
            {
                sb.Append(" ");
            }
            sb.Append(",");

            sb.Append(Diff);
            sb.Append(System.Environment.NewLine);

            return(sb.ToString());
        }
示例#2
0
        public static bool operator <(Money Amount1, Money Amount2)
        {
            double c        = Amount1.Course(Amount1, Amount2);
            bool   compare2 = Amount1.Amount < (Amount2.Amount * c);

            return(compare2);
        }
示例#3
0
        /// <summary>
        /// Executes the WorkFlow.
        /// </summary>
        /// <param name="crmWorkflowContext">The <see cref="WorkFlowActivityBase.LocalWorkflowContext"/> which contains the
        /// <param name="executionContext" > <see cref="CodeActivityContext"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
        /// The WorkFlow's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the WorkFlow. Also, multiple system threads
        /// could execute the WorkFlow at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in WorkFlows.
        /// </remarks>
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException(nameof(executionContext));
            }

            try
            {
                var tracingService = executionContext.GetExtension <ITracingService>();

                var leftValue  = Amount1.Get <Money>(executionContext) ?? new Money();
                var rightValue = Amount2.Get <Money>(executionContext) ?? new Money();
                var symbol     = Symbol.Get <string>(executionContext);
                tracingService.Trace("Calculating '{0}' {1} '{2}'", leftValue.Value, symbol, rightValue.Value);
                switch (symbol)
                {
                case "+":
                    leftValue.Value += rightValue.Value;
                    break;

                case "-":
                    leftValue.Value -= rightValue.Value;
                    break;

                case "/":
                    leftValue.Value /= rightValue.Value;
                    break;

                case "*":
                    leftValue.Value *= rightValue.Value;
                    break;

                default:
                    throw new ArgumentException($"Symbol {symbol} cannot be processed");
                }

                tracingService.Trace("Result = '{0}'", leftValue.Value);
                Result.Set(executionContext, leftValue);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in Workflow assembly." + ex.Message + ex.StackTrace, ex);
            }
        }
示例#4
0
        public static void TrafficAmount(int type, int amount)
        {
            string file    = Application.StartupPath + "\\traf.dat";
            int    Amount1 = 0;
            int    Amount2 = 0;

            if (File.Exists(file))
            {
                string[] lines = File.ReadAllLines(file);
                int.TryParse(lines[0].Trim(), out Amount1);
                int.TryParse(lines[1].Trim(), out Amount2);
            }
            if (type == 1)
            {
                Amount1 += amount;
            }
            else if (type == 2)
            {
                Amount2 += amount;
            }
            string[] arr = new[] { Amount1.ToString(), Amount2.ToString() };
            File.WriteAllLines(file, arr);
        }
示例#5
0
        // 4) declare overloading of operator + to add 2 objects of Money
        public static Money operator +(Money Amount1, Money Amount2)
        {
            double c = Amount1.Course(Amount1, Amount2);

            return(new Money(Amount1.Amount + Amount2.Amount * c, Amount1.CurrencyType));
        }