示例#1
0
        /// <summary>
        /// Dates diff.
        /// </summary>
        /// <param name="Interval">The interval.</param>
        /// <param name="Date1">The date1.</param>
        /// <param name="Date2">The date2.</param>
        /// <returns>The date diff</returns>
        public long DateDiff(string Interval, DateTime Date1, DateTime Date2)
        {
            try
            {
                TimeSpan span = Date2.Subtract(Date1);
                switch (Interval.ToUpperInvariant())
                {
                case "Y":
                    return(Date2.Year - Date1.Year);

                case "MM":
                    return(((Date2.Year * 12) + Date2.Month) - ((Date1.Year * 12) + Date1.Month));

                case "D":
                    return((long)span.TotalDays);

                case "W":
                    return((long)span.TotalDays / 7);

                case "H":
                    return((long)span.TotalHours);

                case "M":
                    return((long)span.TotalMinutes);

                case "S":
                    return((long)span.TotalSeconds);
                }
            }
            catch (Exception ex)
            {
                SPSDebug.DumpException("DateDiff", ex);
            }
            return(0);
        }
示例#2
0
        /// <summary>
        /// Indents the XML.
        /// </summary>
        /// <param name="xmlText">The XML text.</param>
        /// <returns></returns>
        private static string IndentXml(string xmlText)
        {
            StringBuilder stringBuilder;

            try
            {
                if (!string.IsNullOrEmpty(xmlText))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(xmlText);
                    stringBuilder = new StringBuilder();
                    XmlTextWriter xtw = new XmlTextWriter(new StringWriter(stringBuilder))
                    {
                        Formatting = Formatting.Indented
                    };
                    xmlDocument.WriteTo(xtw);
                    xtw.Close();
                    return(stringBuilder.ToString());
                }
            }
            catch (XmlException ex)
            {
                SPSDebug.DumpException(ex);
            }

            return(xmlText);
        }
示例#3
0
 /// <summary>
 /// Roots the param.
 /// </summary>
 /// <returns></returns>
 public string RootWebUrl(string url)
 {
     try
     {
         return(RootWebUrl() + url + SourceParam());
     }
     catch (Exception ex)
     {
         SPSDebug.DumpException("RootWebUrl", ex);
     }
     return(string.Empty);
 }
示例#4
0
 /// <summary>
 /// Roots the param.
 /// </summary>
 /// <returns></returns>
 public string RootWebUrl()
 {
     try
     {
         return(SPContext.Current.Web.Url);
     }
     catch (Exception ex)
     {
         SPSDebug.DumpException("RootWebUrl", ex);
     }
     return(string.Empty);
 }
示例#5
0
 /// <summary>
 /// Roots the param.
 /// </summary>
 /// <returns></returns>
 public string SourceParam()
 {
     try
     {
         return("&Source=" + SPHttpUtility.UrlKeyValueEncode(_page.Request.Url.AbsoluteUri));
     }
     catch (Exception ex)
     {
         SPSDebug.DumpException("SourceParam", ex);
     }
     return(string.Empty);
 }
示例#6
0
 ///<summary>
 ///Maps to icon.
 ///</summary>
 ///<param name="fileName">Name of the file.</param>
 ///<param name="programId">The program id.</param>
 ///<returns>The icon file</returns>
 public string MapToIcon(string fileName, string programId)
 {
     try
     {
         return(SPUtility.MapToIcon(SPContext.Current.Web, fileName, programId));
     }
     catch (Exception ex)
     {
         SPSDebug.DumpException("MapToIcon", ex);
     }
     return(string.Empty);
 }
示例#7
0
 /// <summary>
 /// URLs the name of the dir.
 /// </summary>
 /// <param name="targetUrl">The target URL.</param>
 /// <returns>The Url</returns>
 public string UrlDirName(string targetUrl)
 {
     try
     {
         int index = targetUrl.IndexOf('/');
         int num2  = targetUrl.LastIndexOf('/');
         if (index < num2)
         {
             return(targetUrl.Substring(index, num2 - index));
         }
     }
     catch (Exception ex)
     {
         SPSDebug.DumpException("UrlDirName", ex);
     }
     return(string.Empty);
 }
示例#8
0
        /// <summary>
        /// Dates diff.
        /// </summary>
        /// <param name="Interval">The interval.</param>
        /// <param name="Date1">The date1.</param>
        /// <param name="Date2">The date2.</param>
        /// <returns>The date diff</returns>
        public string DateDiff(string Interval, DateTime Date1, DateTime Date2)
        {
            long result = 0;

            try
            {
                TimeSpan span = Date2.Subtract(Date1);
                switch (Interval.ToUpperInvariant())
                {
                case "Y":
                    result = Date2.Year - Date1.Year;
                    break;

                case "MM":
                    result = ((Date2.Year * 12) + Date2.Month) - ((Date1.Year * 12) + Date1.Month);
                    break;

                case "D":
                    result = (long)span.TotalDays;
                    break;

                case "W":
                    result = (long)span.TotalDays / 7;
                    break;

                case "H":
                    result = (long)span.TotalHours;
                    break;

                case "M":
                    result = (long)span.TotalMinutes;
                    break;

                case "S":
                    result = (long)span.TotalSeconds;
                    break;
                }
            }
            catch (Exception ex)
            {
                SPSDebug.DumpException("DateDiff", ex);
            }
            return(result.ToString());
        }