public string Format(string data, DataManager manager, TemplateFunctions function) { Match m = Regex.Match(data, quoted); string format = m.ToString().Replace("\"", string.Empty); if (m != null) { try { if (m.Index >= data.IndexOf(",")) //Make sure parameters came in the correct order. { throw new Exception(String.Format(invalidarguments, GetFunctionName(function))); } switch (function) { case TemplateFunctions.DateFormat: { return(DataManager.GetRtfText(DateTime.Parse(GetStringData(data, manager, m, function)).ToString(format), Encoding.GetEncoding(1252))); } case TemplateFunctions.DoubleFormat: { return(DataManager.GetRtfText(Double.Parse(GetStringData(data, manager, m, function)).ToString(format), Encoding.GetEncoding(1252))); } } } catch { //Just a patch. If a variable wasn't added to the datamanager it can't be formatted!! } } else { throw new Exception(String.Format(invalidarguments, GetFunctionName(function))); } return(data); //Invalid case, not expected to happen. }
private static string GetFunctionName(TemplateFunctions function) { switch (function) { case TemplateFunctions.DateFormat: { return("Dtfmt"); } case TemplateFunctions.DoubleFormat: { return("Dbfmt"); } case TemplateFunctions.Hyperlink: { return("Hlnk"); } default: return(""); } }
private static string GetStringData(string data, DataManager manager, Match m, TemplateFunctions func) { string varName = data.Replace(m.ToString(), string.Empty).Replace("(", string.Empty).Replace(")", string.Empty).Replace(",", string.Empty).Replace(GetFunctionName(func), string.Empty).Replace(manager.Parser._d, string.Empty); string varValue = manager.GetCurrentValueForPlaceHolder(new CommonMethods(manager.Parser).Prepare(varName)).ToString(); return(varValue); }