using System;
namespace ZXReport
{
/// <summary>
/// 报表共用方法
/// </summary>
public class ReportTool
{
public const double INIT_DATA = -999.00;
public const double INIT_ABS_DATA1 = 998.99;
public const double INIT_ABS_DATA2 = 999.01;
/// <summary>
/// 显示异常信息
/// </summary>
/// <param name="message"></param>
/// <param name="page"></param>
public static void Message(string message, System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript> ";
scriptString += " alert('" + message + "') ; ";
scriptString += " function Page_Load() ";
scriptString += " { alert('" + message + "') ; } ";
scriptString += " </script> ";
if (!page.IsStartupScriptRegistered("Startup"))
{
page.RegisterStartupScript("Startup", scriptString);
}
}
public static string BlankString(int len)
{
string str = "";
return str.PadRight(len);
}
/// <summary>
/// 获得日期时间
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static DateTime GetDateTime(string str)
{
int i = str.IndexOf("-");
int j = str.LastIndexOf("-");
if (!(i >0 && j > 0 && i < j))
return DateTime.Now;
string year = str.Substring(0, i);
string month = str.Substring(i + 1, j - i - 1);
string day = str.Substring(j + 1);
return new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day));
}
/// <summary>
/// 得到当前月的第一天
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static DateTime GetFirstDayOfMonth(ref DateTime dt)
{
//DateTime now = DateTime.Now;
return new DateTime(dt.Year, dt.Month, 1);
}
/* INIT_DATA */
//无效数据值
public static bool InvalidDBValue(double d)
{
return (d < 0 && Math.Abs(d) >= INIT_ABS_DATA1 && Math.Abs(d) <= INIT_ABS_DATA2);
}
/// <summary>
/// 加法计算
/// </summary>
/// <param name="d1">被加数</param>
/// <param name="d2">加数</param>
/// <returns></returns>
public static double Add(double d1, double d2)
{
double t = 0.00;
if (InvalidDBValue(d1) && InvalidDBValue(d2))
return INIT_DATA;
if (!InvalidDBValue(d1))
t += d1;
if (!InvalidDBValue(d2))
t += d2;
return (t);
}
/// <summary>
/// 减法计算
/// </summary>
/// <param name="d1">被减数</param>
/// <param name="d2">减数</param>
/// <returns></returns>
public static double Subtract(double d1, double d2)
{
if (InvalidDBValue(d1) || InvalidDBValue(d2))
return INIT_DATA;
return (d1 - d2);
}
}
}