public IActionResult Index(string refid)
        {
            var resultlist = this.ServiceClient.Get <EbObjectParticularVersionResponse>(new EbObjectParticularVersionRequest {
                RefId = refid
            });

            Report                 = EbSerializers.Json_Deserialize <EbReport>(resultlist.Data[0].Json);
            Report.IsLastpage      = false;
            Report.watermarkImages = new Dictionary <string, byte[]>();
            Report.WaterMarkList   = new List <object>();
            if (Report.DataSourceRefId != string.Empty)
            {
                cresp = this.Redis.Get <DataSourceColumnsResponse>(string.Format("{0}_columns", Report.DataSourceRefId));
                if (cresp.IsNull)
                {
                    cresp = this.ServiceClient.Get <DataSourceColumnsResponse>(new DataSourceColumnsRequest {
                        RefId = Report.DataSourceRefId
                    });
                }

                Report.DataColumns = (cresp.Columns.Count > 1) ? cresp.Columns[1] : cresp.Columns[0];

                dresp = this.ServiceClient.Get <DataSourceDataResponse>(new DataSourceDataRequest {
                    RefId = Report.DataSourceRefId, Draw = 1, Start = 0, Length = 100
                });
                Report.DataRow = dresp.Data;
            }

            iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(Report.Width, Report.Height);

            d      = new Document(rec);
            ms1    = new MemoryStream();
            writer = PdfWriter.GetInstance(d, ms1);
            writer.Open();
            d.Open();
            writer.PageEvent   = new HeaderFooter(this);
            writer.CloseStream = true;//important
            canvas             = writer.DirectContent;
            Report.PageNumber  = writer.PageNumber;
            //Report.DataRow = __datarows;
            Report.InitializeSummaryFields();
            GetWatermarkImages();
            d.NewPage();

            DrawReportHeader();
            DrawDetail();
            d.Close();
            ms1.Position = 0;//important
            return(new FileStreamResult(ms1, "application/pdf"));
        }
        public IActionResult Index(string refid)
        {
            var resultlist = this.ServiceClient.Get <EbObjectParticularVersionResponse>(new EbObjectParticularVersionRequest {
                RefId = refid
            });

            Report = EbSerializers.Json_Deserialize <EbReport>(resultlist.Data[0].Json);

            if (Report.DataSourceRefId != string.Empty)
            {
                cresp = this.Redis.Get <DataSourceColumnsResponse>(string.Format("{0}_columns", Report.DataSourceRefId));
                if (cresp.IsNull)
                {
                    cresp = this.ServiceClient.Get <DataSourceColumnsResponse>(new DataSourceColumnsRequest {
                        RefId = Report.DataSourceRefId
                    });
                }

                __columns = (cresp.Columns.Count > 1) ? cresp.Columns[1] : cresp.Columns[0];

                dresp = this.ServiceClient.Get <DataSourceDataResponse>(new DataSourceDataRequest {
                    RefId = Report.DataSourceRefId, Draw = 1, Start = 0, Length = 100
                });
                dt = dresp.Data;
            }

            iTextSharp.text.Rectangle rec = (Report.IsLandscape) ?
                                            new iTextSharp.text.Rectangle(Report.Height, Report.Width) : new iTextSharp.text.Rectangle(Report.Width, Report.Height);

            d = new Document(rec);
            MemoryStream ms1 = new MemoryStream();

            writer = PdfWriter.GetInstance(d, ms1);
            writer.Open();
            d.Open();
            writer.PageEvent   = new HeaderFooter(this);
            writer.CloseStream = true;//important
            cb = writer.DirectContent;
            CalculateSectionHeights();
            d.NewPage();

            DrawReportHeader();
            DrawDetail();
            DrawReportFooter();
            d.Close();
            ms1.Position = 0;
            return(new FileStreamResult(ms1, "application/pdf"));
        }
        public DataSourceDataResponse Any(DataSourceDataRequest request)
        {
            this.Log.Info("data request");

            //var dt = this.DatabaseFactory.ObjectsDB.DoQuery(string.Format("SELECT obj_bytea FROM eb_objects_ver WHERE id={0}", request.Id));
            //var dt = this.DatabaseFactory.ObjectsDB.DoQuery(string.Format(@"
            //    SELECT EOV.obj_json FROM eb_objects_ver EOV
            //    INNER JOIN eb_objects EO
            //    ON EO.id = EOV.eb_objects_id  AND EO.obj_last_ver_id =EOV.ver_num AND EOV.eb_objects_id={0}", request.RefId)
            //   );

            //var dt = this.DatabaseFactory.ObjectsDB.DoQuery(string.Format(@"
            //    SELECT EOV.obj_bytea FROM eb_objects_ver EOV
            //    INNER JOIN eb_objects EO
            //    ON EO.id = EOV.eb_objects_id  AND EOV.ver_num={0} AND EOV.eb_objects_id={1}", request.VersionId, request.Id)
            //    );

            //this.Log.Info("dt.Rows.Count *****" + dt.Rows.Count);
            //this.Log.Info("ProtoBuf_DeSerialize *****" + EbSerializers.ProtoBuf_DeSerialize<EbDataSource>((byte[])dt.Rows[0][0]));
            DataSourceDataResponse dsresponse = null;

            //if (dt.Rows.Count > 0)
            //{
            var _ds = this.Redis.Get <EbDataSource>(request.RefId);    //EbSerializers.Json_Deserialize<EbDataSource>(dt.Rows[0][0].ToString());

            this.Log.Info("_ds *****" + _ds /*.SqlDecoded()*/);
            string _sql = string.Empty;

            if (_ds != null)
            {
                string _c = string.Empty;

                if (request.TFilters != null)
                {
                    foreach (Dictionary <string, string> _dic in request.TFilters)
                    {
                        var op = _dic["o"]; var col = _dic["c"]; var val = _dic["v"];

                        if (op == "x*")
                        {
                            _c += string.Format("AND LOWER({0})::text LIKE LOWER('{1}%') ", col, val);
                        }
                        else if (op == "*x")
                        {
                            _c += string.Format("AND LOWER({0})::text LIKE LOWER('%{1}') ", col, val);
                        }
                        else if (op == "*x*")
                        {
                            _c += string.Format("AND LOWER({0})::text LIKE LOWER('%{1}%') ", col, val);
                        }
                        else if (op == "=")
                        {
                            _c += string.Format("AND LOWER({0}::text) = LOWER('{1}') ", col, val);
                        }
                        else
                        {
                            _c += string.Format("AND {0} {1} '{2}' ", col, op, val);
                        }
                    }
                }

                _sql = _ds.Sql /*Decoded()*/.Replace("@and_search", _c);
            }
            this.Log.Info("search ok");
            _sql = _sql.Replace("@orderby",
                                (string.IsNullOrEmpty(request.OrderByCol)) ? "id" : string.Format("{0} {1}", request.OrderByCol, ((request.OrderByDir == 2) ? "DESC" : "ASC")));
            this.Log.Info("order ok");
            var parameters = new List <System.Data.Common.DbParameter>();

            bool _isPaged = (_sql.ToLower().Contains("@offset") && _sql.ToLower().Contains("@limit"));

            if (_isPaged)
            {
                parameters.AddRange(new System.Data.Common.DbParameter[]
                {
                    this.TenantDbFactory.ObjectsDB.GetNewParameter("@limit", System.Data.DbType.Int32, request.Length),
                    this.TenantDbFactory.ObjectsDB.GetNewParameter("@offset", System.Data.DbType.Int32, request.Start),
                });
            }

            if (request.Params != null && request.Params.Count != 0)
            {
                foreach (Dictionary <string, string> param in request.Params)
                {
                    parameters.Add(this.TenantDbFactory.ObjectsDB.GetNewParameter(string.Format("@{0}", param["name"]), (System.Data.DbType)Convert.ToInt32(param["type"]), param["value"]));
                }
            }
            this.Log.Info("GO**********************" + _sql);
            var _dataset = this.TenantDbFactory.ObjectsDB.DoQueries(_sql, parameters.ToArray());

            this.Log.Info(">>>>>> _dataset.Tables.Count: " + _dataset.Tables.Count + ", " + _dataset.ToJson());

            //--
            int _recordsTotal = 0, _recordsFiltered = 0;

            if (_isPaged)
            {
                Int32.TryParse(_dataset.Tables[0].Rows[0][0].ToString(), out _recordsTotal);
                Int32.TryParse(_dataset.Tables[0].Rows[0][0].ToString(), out _recordsFiltered);
            }
            _recordsTotal    = (_recordsTotal > 0) ? _recordsTotal : _dataset.Tables[0].Rows.Count;
            _recordsFiltered = (_recordsFiltered > 0) ? _recordsFiltered : _dataset.Tables[0].Rows.Count;
            //--

            dsresponse = new DataSourceDataResponse
            {
                Draw            = request.Draw,
                Data            = (_dataset.Tables.Count > 1) ? _dataset.Tables[1].Rows : _dataset.Tables[0].Rows,
                RecordsTotal    = _recordsTotal,
                RecordsFiltered = _recordsFiltered
            };
            this.Log.Info("dsresponse*****" + dsresponse.Data);
            //}

            //return this.Request.ToOptimizedResult<DataSourceDataResponse>(dsresponse);
            return(dsresponse);
        }
Beispiel #4
0
        public DataSourceDataResponse Any(DataVisDataRequest request)
        {
            this.Log.Info("data request");

            DataSourceDataResponse dsresponse = null;

            EbDataVisualization _dV = request.EbDataVisualization;

            //if (request.WhichConsole == "uc")
            //    _dVSet = this.Redis.Get<EbDataVisualizationSet>(request.RefId + request.UserId.ToString());
            //else //dc
            //    _dVSet = this.Redis.Get<EbDataVisualizationSet>(request.RefId);

            _dV.AfterRedisGet(this.Redis as RedisClient);

            string _sql = null;

            if (_dV.EbDataSource != null)
            {
                StringBuilder _sb = new StringBuilder();

                if (request.TFilters != null)
                {
                    foreach (Dictionary <string, string> _dic in request.TFilters)
                    {
                        var op = _dic["o"]; var col = _dic["c"]; var val = _dic["v"];

                        if (op == "x*")
                        {
                            _sb.Append(string.Format("LOWER({0})::text LIKE LOWER('{1}%') ", col, val));
                        }
                        else if (op == "*x")
                        {
                            _sb.Append(string.Format("LOWER({0})::text LIKE LOWER('%{1}') ", col, val));
                        }
                        else if (op == "*x*")
                        {
                            _sb.Append(string.Format("LOWER({0})::text LIKE LOWER('%{1}%') ", col, val));
                        }
                        else if (op == "=")
                        {
                            _sb.Append(string.Format("LOWER({0}::text) = LOWER('{1}') ", col, val));
                        }
                        else
                        {
                            _sb.Append(string.Format("{0} {1} '{2}' ", col, op, val));
                        }
                    }
                }

                string __innerSql = _dV.EbDataSource.SqlDecoded();
                string _where     = (_sb.Length > 0) ? "WHERE " + string.Join(" AND ", _sb) : string.Empty;
                string _orderby   = (string.IsNullOrEmpty(request.OrderByCol)) ? "1" : string.Format("{0} {1}", request.OrderByCol, ((request.OrderByDir == 2) ? "DESC" : "ASC"));
                _sql = string.Format("WITH __OUTER99 AS ({0}) SELECT * FROM __OUTER99 {1} {2}", __innerSql, _where, _orderby);

                this.Log.Info("_ds *****" + _sql);
            }

            var  parameters = new List <System.Data.Common.DbParameter>();
            bool _isPaged   = (_sql.ToLower().Contains("@offset") && _sql.ToLower().Contains("@limit"));

            if (_isPaged)
            {
                parameters.AddRange(new System.Data.Common.DbParameter[]
                {
                    this.TenantDbFactory.ObjectsDB.GetNewParameter("@limit", System.Data.DbType.Int32, request.Length),
                    this.TenantDbFactory.ObjectsDB.GetNewParameter("@offset", System.Data.DbType.Int32, request.Start),
                });
            }

            if (request.Params != null)
            {
                foreach (Dictionary <string, string> param in request.Params)
                {
                    parameters.Add(this.TenantDbFactory.ObjectsDB.GetNewParameter(string.Format("@{0}", param["name"]), (System.Data.DbType)Convert.ToInt32(param["type"]), param["value"]));
                }
            }

            var _dataset = _dV.DoQueries4DataVis(_sql, this.TenantDbFactory, parameters.ToArray());

            //--
            int _recordsTotal = 0, _recordsFiltered = 0;

            if (_isPaged)
            {
                Int32.TryParse(_dataset.Tables[0].Rows[0][0].ToString(), out _recordsTotal);
                Int32.TryParse(_dataset.Tables[0].Rows[0][0].ToString(), out _recordsFiltered);
            }
            _recordsTotal    = (_recordsTotal > 0) ? _recordsTotal : _dataset.Tables[0].Rows.Count;
            _recordsFiltered = (_recordsFiltered > 0) ? _recordsFiltered : _dataset.Tables[0].Rows.Count;
            //--

            dsresponse = new DataSourceDataResponse
            {
                Draw            = request.Draw,
                Data            = (_dataset.Tables.Count > 1) ? _dataset.Tables[1].Rows : _dataset.Tables[0].Rows,
                RecordsTotal    = _recordsTotal,
                RecordsFiltered = _recordsFiltered
            };
            this.Log.Info("dsresponse*****" + dsresponse.Data);

            return(dsresponse);
        }