Ejemplo n.º 1
0
        internal string AddParametersForSql(string parameter, string sql, DynamicParameters p, dynamic ViewBag)
        {
            if (sql.Contains("@qtagid", ignoreCase: true))
            {
                var id     = Db.FetchLastQuery().Id;
                var tag    = Db.PopulateSpecialTag(id, DbUtil.TagTypeId_Query);
                int?qtagid = tag.Id;
                p.Add("@qtagid", qtagid);
                ViewBag.Type = "SqlReport";
            }

            if (sql.Contains("@BlueToolbarTagId", ignoreCase: true))
            {
                var id     = Db.FetchLastQuery().Id;
                var tag    = Db.PopulateSpecialTag(id, DbUtil.TagTypeId_Query);
                int?qtagid = tag.Id;
                p.Add("@BlueToolbarTagId", qtagid);
                ViewBag.Type = "SqlReport";
            }
            else if (sql.Contains("@CurrentOrgId", ignoreCase: true))
            {
                var oid = Db.CurrentSessionOrgId;
                p.Add("@CurrentOrgId", oid);
                if (oid > 0)
                {
                    var name = Db.LoadOrganizationById(oid).FullName2;
                    ViewBag.Name2 = name;
                    ViewBag.Type  = "SqlReport";
                }
            }
            else if (sql.Contains("@OrgIds", ignoreCase: true))
            {
                var oid = Db.CurrentSessionOrgId;
                if (oid != 0 || !p.Contains("@OrgIds"))
                {
                    p.Add("@OrgIds", oid.ToString());
                }

                ViewBag.Type = "OrgSearchSqlReport";
                if (sql.Contains("--class=StartEndReport"))
                {
                    p.Add("@MeetingDate1", DateTime.Now.AddDays(-90));
                    p.Add("@MeetingDate2", DateTime.Now);
                }
            }
            else if (sql.Contains("--class=TotalsByFund"))
            {
                ViewBag.Type = "TotalsByFundSqlReport";
                p.Add("@StartDate", dbType: DbType.DateTime);
                p.Add("@EndDate", dbType: DbType.DateTime);
                p.Add("@CampusId", dbType: DbType.Int32);
                p.Add("@Online", dbType: DbType.Boolean);
                p.Add("@TaxNonTax", dbType: DbType.Boolean);
                p.Add("@FundSet", dbType: DbType.String);
                p.Add("@IncludeUnclosedBundles", dbType: DbType.Boolean);
                p.Add("@ActiveTagFilter", dbType: DbType.Int64);
            }
            else
            {
                ViewBag.Type = "SqlReport";
            }

            if (sql.Contains("@StartDt"))
            {
                p.Add("@StartDt", new DateTime(DateTime.Now.Year, 1, 1));
            }

            if (sql.Contains("@EndDt"))
            {
                p.Add("@EndDt", DateTime.Today);
            }

            if (sql.Contains("@userid", ignoreCase: true))
            {
                p.Add("@userid", Util.UserId);
            }
#if DEBUG
            foreach (var name in p.ParameterNames)
            {
                sql = QueryFunctions.RemoveDeclaration(name, sql);
            }
#endif

            sql = QueryFunctions.AddP1Parameter(sql, parameter, p);

            return(sql);
        }
Ejemplo n.º 2
0
        internal static string RunScriptSql(string parameter, string body, DynamicParameters p, dynamic ViewBag)
        {
            if (!CanRunScript(body))
            {
                return("Not Authorized to run this script");
            }

            if (body.Contains("@qtagid", ignoreCase: true))
            {
                var id     = DbUtil.Db.FetchLastQuery().Id;
                var tag    = DbUtil.Db.PopulateSpecialTag(id, DbUtil.TagTypeId_Query);
                int?qtagid = tag.Id;
                p.Add("@qtagid", qtagid);
                ViewBag.Type = "SqlReport";
            }
            if (body.Contains("@BlueToolbarTagId", ignoreCase: true))
            {
                var id     = DbUtil.Db.FetchLastQuery().Id;
                var tag    = DbUtil.Db.PopulateSpecialTag(id, DbUtil.TagTypeId_Query);
                int?qtagid = tag.Id;
                p.Add("@BlueToolbarTagId", qtagid);
                ViewBag.Type = "SqlReport";
            }
            else if (body.Contains("@CurrentOrgId", ignoreCase: true))
            {
                var oid = DbUtil.Db.CurrentSessionOrgId;
                p.Add("@CurrentOrgId", oid);
                if (oid > 0)
                {
                    var name = DbUtil.Db.LoadOrganizationById(oid).FullName2;
                    ViewBag.Name2 = name;
                    ViewBag.Type  = "SqlReport";
                }
            }
            else if (body.Contains("@OrgIds", ignoreCase: true))
            {
                var oid = DbUtil.Db.CurrentSessionOrgId;
                p.Add("@OrgIds", oid.ToString());
                ViewBag.Type = "OrgSearchSqlReport";
                if (body.Contains("--class=StartEndReport"))
                {
                    p.Add("@MeetingDate1", DateTime.Now.AddDays(-90));
                    p.Add("@MeetingDate2", DateTime.Now);
                }
            }
            else if (body.Contains("--class=TotalsByFund"))
            {
                ViewBag.Type = "TotalsByFundSqlReport";
                p.Add("@StartDate", dbType: DbType.DateTime);
                p.Add("@EndDate", dbType: DbType.DateTime);
                p.Add("@CampusId", dbType: DbType.Int32);
                p.Add("@Online", dbType: DbType.Boolean);
                p.Add("@TaxNonTax", dbType: DbType.Boolean);
                p.Add("@FundSet", dbType: DbType.String);
                p.Add("@IncludeUnclosedBundles", dbType: DbType.Boolean);
                p.Add("@ActiveTagFilter", dbType: DbType.Int64);
            }
            else
            {
                ViewBag.Type = "SqlReport";
            }

            if (body.Contains("@StartDt"))
            {
                p.Add("@StartDt", new DateTime(DateTime.Now.Year, 1, 1));
            }

            if (body.Contains("@EndDt"))
            {
                p.Add("@EndDt", DateTime.Today);
            }

            if (body.Contains("@userid", ignoreCase: true))
            {
                p.Add("@userid", Util.UserId);
            }

            body = QueryFunctions.AddP1Parameter(body, parameter, p);

            return(body);
        }