Beispiel #1
0
 /// <summary>
 /// Constructor: When this constructor is used, data will be obtained immediately.
 /// </summary>
 /// <param name="connectionString">Connection string to the SqlServer instance including database name</param>
 /// <param name="storedProcedureName">The stored procedure used to call get the data</param>
 /// <param name="parameters">Any SqlParametrs needed to obtainthe data</param>
 public ReportData(string connectionString, string storedProcedureName, List <SqlParameter> parameters = null, ReportBoolType boolType = ReportBoolType.YesNo, ReportDateType dateType = ReportDateType.ShortDateString)
 {
     ConnectionString    = connectionString;
     StoredProcedureName = storedProcedureName;
     Parameters          = parameters;
     DateType            = dateType;
     BoolType            = boolType;
     Data = new List <List <KeyValuePair <string, string> > >();
     GetData();
 }
Beispiel #2
0
        public static string FixDateValue(this KeyValuePair <string, string> kvp, ReportBoolType boolType = ReportBoolType.YesNo, ReportDateType dateType = ReportDateType.ShortDateString, bool toUTC = false)
        {
            DateTime dt = new DateTime();

            //To avoid calling TryParse on as many values as possible,
            //this will filter out anything that does not start with a number.
            if (!string.IsNullOrEmpty(kvp.Value) && Regex.IsMatch(kvp.Value.Substring(0, 1), @"^\d+$"))
            {
                if (DateTime.TryParse(kvp.Value, out dt))
                {
                    if (toUTC)
                    {
                        dt = dt.ToUniversalTime();
                    }

                    switch (dateType)
                    {
                    case ReportDateType.ShortDateString:
                        return(dt.ToShortDateString());

                    case ReportDateType.LongDateString:
                        return(dt.ToLongDateString());

                    case ReportDateType.ShortTimeString:
                        return(dt.ToShortTimeString());

                    case ReportDateType.LongTimeString:
                        return(dt.ToLongTimeString());
                    }
                }
            }
            else
            {
                bool bl = false;
                if (bool.TryParse(kvp.Value, out bl))
                {
                    switch (boolType)
                    {
                    case ReportBoolType.YesNo:
                        return(bl ? "Yes" : "No");

                    case ReportBoolType.HtmlChecked:
                        string ckd = bl ?"checked=\"checked\"" : "";
                        return(string.Format("<input type=\"checkbox\" {0} readonly=\"readonly\"/>", ckd));

                    default:
                        return(kvp.Value);
                    }
                }
            }
            return(kvp.Value);
        }