Esempio n. 1
0
        public void RunReport(string reportID, object param, string newguid)
        {
            SplashScreenManager.ShowForm(typeof(RunReportWait));

            var reportParams = new StringBuilder();
            var stringWriter = new StringWriter(reportParams);

            using (JsonWriter json = new JsonTextWriter(stringWriter))
            {
                json.WriteStartObject();

                var type       = param.GetType();
                var properties = type.GetProperties();

                for (int n = 0; n < properties.Length; n++)
                {
                    var property = properties[n];
                    var name     = property.Name;
                    var value    = property.GetValue(param, null);

                    json.WritePropertyName(name);
                    json.WriteValue(value);
                }

                json.WriteEndObject();
            }

            var query = DataQuery.Create("Reports", "ws_ReportQueue_Push", new
            {
                ReportID     = reportID,
                ReportParams = reportParams.ToString(),
                UserID       = Guid.Empty
            });

            var ds  = this.Execute(query);
            var row = ds.FirstRow();

            if (row != null)
            {
                var seq = row["Seq"].ToString();

                Stopwatch sw = new Stopwatch();
                sw.Start();

                while (sw.Elapsed.TotalSeconds < 60)
                {
                    Thread.Sleep(500);

                    query = DataQuery.Create("Reports", "ws_ReportOutput_Get", new { QueueSeq = seq });
                    ds    = this.Execute(query);
                    row   = ds.FirstRow();

                    if (row != null)
                    {
                        var fileData      = row["FileData"].ToString();
                        var fileExtension = row["FileExtension"].ToString();
                        ReportUtility.Create(fileData, fileExtension, newguid);
                        break;
                    }
                }
            }

            SplashScreenManager.CloseForm();
        }