Esempio n. 1
0
 void QuoteProduct_PropertyChanged(object sender, Xrm.ComponentModel.PropertyChangedEventArgs e)
 {
     if (Quantity != null && PricePerUnit != null)
     {
         this.ExtendedAmount = new Money(Quantity.Value * PricePerUnit.Value);
     }
     this.IsProductOverridden = !String.IsNullOrEmpty(ProductDescription);
 }
Esempio n. 2
0
 private static string FormatNumber(Money value, NumberFormatInfo format)
 {
     if (value != null)
     {
         return NumberEx.Format(value.Value,format);
     }
     else
     {
         return String.Empty;
     }
 }
Esempio n. 3
0
        private static void TrySetObservable(Func<object> valueAccessor, jQueryObject inputField, string value, NumberFormatInfo format)
        {

            Observable<Money> observable = (Observable<Money>)valueAccessor();
            bool isValid = true;


            Number numericValue = NumberEx.Parse(value, format);

            if (!Number.IsNaN(numericValue) && numericValue>=format.MinValue && numericValue<=format.MaxValue)
            {
                // Set to precision
                numericValue = NumberEx.Round(numericValue, format.Precision);
                Money newValue = new Money((decimal)numericValue);
                
                observable.SetValue(newValue);

                if (((string)Script.Literal("typeof({0}.isValid)", observable)) != "undefined")
                {
                    isValid = ((IValidatedObservable)observable).IsValid() == true;
                }

                if (isValid)
                {
                    string formattedNumber = FormatNumber(newValue, format);
                    inputField.Value(formattedNumber);
                    inputField.Blur();
                }
            }
            else
            {
                Script.Alert(String.Format("You must enter a number between {0} and {1}",format.MinValue,format.MaxValue));
                Money currentValue = observable.GetValue();
              
                string formattedNumber = FormatNumber(currentValue, format);
                inputField.Value(formattedNumber);
                inputField.Focus();
            }

        }
Esempio n. 4
0
        public static object DeSerialise(XmlNode node,string overrideType)
        {
            // Check if the value is null
            bool isNil = (XmlHelper.GetAttributeValue(node, "i:nil") == "true");
            object value = null;
            if (!isNil)
            {

                string typeName = overrideType;
                if (typeName==null) typeName = _removeNsPrefix(XmlHelper.GetAttributeValue(node, "i:type"));

                string stringValue = XmlHelper.GetNodeTextValue(node);
                switch (typeName)
                {
                    case AttributeTypes.EntityReference:
                        EntityReference entityReferenceValue = new EntityReference(
                            new Guid(XmlHelper.SelectSingleNodeValue(node, "Id")),
                            XmlHelper.SelectSingleNodeValue(node, "LogicalName"),
                            XmlHelper.SelectSingleNodeValue(node, "Name"));

                        value = entityReferenceValue;
                        break;
                    case AttributeTypes.AliasedValue:
                        value = DeSerialise(XmlHelper.SelectSingleNode(node, "Value"),null);
                        break;
                    case AttributeTypes.Boolean_:
                        value = (stringValue == "true");
                        break;
                    case AttributeTypes.Decimal_:
                        value = decimal.Parse(stringValue);
                        break;
                    case AttributeTypes.DateTime_:
                        DateTime dateValue = DateTimeEx.Parse(stringValue);

                        // We need it in the CRM Users timezone
                        UserSettings settings = OrganizationServiceProxy.UserSettings;
                        if (settings != null)
                        {
                            // Remove the local date formating so that it is in UTC irrespective of the local timezone
                            dateValue.SetTime(dateValue.GetTime() + (dateValue.GetTimezoneOffset() * 60 * 1000));

                            DateTime localDateValue = DateTimeEx.UTCToLocalTimeFromSettings(dateValue, settings);
                            value = localDateValue;
                        }
                        else
                            value = dateValue;

                        break;
                    case "guid":
                        value = new Guid(stringValue);
                        break;
                    case AttributeTypes.Int_:
                        value = int.Parse(stringValue);
                        break;
                    case AttributeTypes.OptionSetValue:
                        value = OptionSetValue.Parse(XmlHelper.SelectSingleNodeValue(node, "Value"));
                        break;
                    case AttributeTypes.Money:
                        value = new Money(decimal.Parse(XmlHelper.SelectSingleNodeValue(node, "Value")));
                        break;
                    default:
                        value = stringValue;
                        break;

                }
            }
            return value;
        }
Esempio n. 5
0
 public override void ApplyValue(Dictionary<string, object> item, object state)
 {
     Money money = new Money((decimal)NumberEx.Parse((string)state, numberFormatInfo));
     item[_args.Column.Field] = money;
     this.RaiseOnChange(item);
 }