public static void InsertFormulaFieldToList(string fieldName, string displayName, SPList list, string formula, SPFieldType type, SPNumberFormatTypes format) { if (list.Fields.ContainsField(fieldName)) { list.Fields.Delete(fieldName); } string temp = list.Fields.Add(displayName, SPFieldType.Calculated, false); SPFieldCalculated f = (SPFieldCalculated)list.Fields[temp]; f.Formula = formula; f.OutputType = type; f.DisplayFormat = format; f.Update(); list.Update(); }
public static bool CompareNumberObject(object x, object y, SPNumberFormatTypes numberFormatTypes) { if (ReferenceEquals(x, y)) { return(true); } if (!(x is double) || !(y is double)) { return(x.ToString() == y.ToString()); } string format; switch (numberFormatTypes) { case SPNumberFormatTypes.NoDecimal: format = "N0"; break; case SPNumberFormatTypes.OneDecimal: format = "N1"; break; case SPNumberFormatTypes.ThreeDecimals: format = "N3"; break; case SPNumberFormatTypes.FourDecimals: format = "N4"; break; case SPNumberFormatTypes.FiveDecimals: format = "N5"; break; default: format = "N2"; break; } var a = (double)x; var b = (double)y; return(a.ToString(format, CultureInfo.InvariantCulture) == b.ToString(format, CultureInfo.InvariantCulture)); }
public static bool CompareNumberObject(object x, object y, SPNumberFormatTypes numberFormatTypes) { if (ReferenceEquals(x, y)) { return true; } if (!(x is double) || !(y is double)) { return x.ToString() == y.ToString(); } string format; switch (numberFormatTypes) { case SPNumberFormatTypes.NoDecimal: format = "N0"; break; case SPNumberFormatTypes.OneDecimal: format = "N1"; break; case SPNumberFormatTypes.ThreeDecimals: format = "N3"; break; case SPNumberFormatTypes.FourDecimals: format = "N4"; break; case SPNumberFormatTypes.FiveDecimals: format = "N5"; break; default: format = "N2"; break; } var a = (double) x; var b = (double) y; return a.ToString(format, CultureInfo.InvariantCulture) == b.ToString(format, CultureInfo.InvariantCulture); }
/// <summary> /// /// </summary> /// <param name="web"></param> /// <param name="group"></param> /// <param name="description"></param> /// <param name="name"></param> /// <param name="displayName"></param> /// <param name="decimals"></param> public static void CreateNumberColumn(this SPWeb web, string group, string description, string name, string displayName, SPNumberFormatTypes decimals = SPNumberFormatTypes.Automatic) { try { if (!web.Fields.ContainsField(name)) { string fieldName = web.Fields.Add(name, SPFieldType.Number, false); SPFieldNumber field = (SPFieldNumber)web.Fields.GetField(name); field.Group = group; field.DisplayFormat = decimals; field.StaticName = name; field.Title = displayName; field.NoCrawl = false; field.Description = description; field.Update(); } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("CORE:HELPERS", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, String.Format("Exception happened in Helpers:CreateNumberColumn. MESSAGE: {0}. EXCEPTION TRACE: {1} ", ex.Message, ex.StackTrace), ex.StackTrace); } }