Пример #1
0
        public string SqlNameCountArray(string title, string sql)
        {
//            var qb = db.PeopleQuery2(s);
//            if (qb == null)
//                return 0;
            var cs = db.CurrentUser.InRole("Finance")
                ? Util.ConnectionStringReadOnlyFinance
                : Util.ConnectionStringReadOnly;
            var cn = new SqlConnection(cs);

            cn.Open();
            string declareqtagid = null;

            if (sql.Contains("@qtagid"))
            {
                var id  = db.FetchLastQuery().Id;
                var tag = db.PopulateSpecialTag(id, DbUtil.TagTypeId_Query);
                declareqtagid = "DECLARE @qtagid INT = {0}\n".Fmt(tag.Id);
            }
            sql = "{0}{1}".Fmt(declareqtagid, sql);
            var q    = cn.Query(sql);
            var list = q.Select(rr => new NameValuePair()
            {
                Name = rr.Name, Value = rr.Cnt
            }).ToList();

            if (list.Count == 0)
            {
                return(@"[ ['No Data', 'Count'], ['Dummy Value 1', 1], ['Dummy Value 2', 2], ['Dummy Value 3', 3], ]");
            }
            return(@"[
  ['{0}', 'Count'],
{1}
]".Fmt(title, string.Join(",\n", list)));
        }
Пример #2
0
        private string RunScriptSql(CMSDataContext db, string parameter, string body, DynamicParameters p)
        {
            if (!CanRunScript(body))
                return "Not Authorized to run this script";
            if (body.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";
            }
            else if (body.Contains("@CurrentOrgId", ignoreCase:true))
            {
                var oid = DbUtil.Db.CurrentOrgId0;
                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.CurrentOrgId0;
                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
                ViewBag.Type = "SqlReport";
            if (body.Contains("@userid", ignoreCase:true))
                p.Add("@userid", Util.UserId);
            p.Add("@p1", parameter ?? "");
            return body;
        }
Пример #3
0
 private string RunScriptSql(CMSDataContext Db, string parameter, string body, DynamicParameters p)
 {
     if (!CanRunScript(body))
         return "Not Authorized to run this script";
     if (body.Contains("@qtagid"))
     {
         var id = Db.FetchLastQuery().Id;
         var tag = Db.PopulateSpecialTag(id, DbUtil.TagTypeId_Query);
         p.Add("@qtagid", tag.Id);
     }
     p.Add("@p1", parameter ?? "");
     return body;
 }